Commit 56dd3ffd authored by Ivan Tyagov's avatar Ivan Tyagov

Support the maximal amount of Analon Ins (2).

parent cc96c967
...@@ -113,12 +113,14 @@ static void addVariable(UA_Server *server) ...@@ -113,12 +113,14 @@ static void addVariable(UA_Server *server)
sprintf(node_id, "i2c%d.in%d", i, n); sprintf(node_id, "i2c%d.in%d", i, n);
sprintf(node_title, "I2C%d / Digital Input %d", i, n); sprintf(node_title, "I2C%d / Digital Input %d", i, n);
addBooleanVariableReadNode(server, node_id, node_title); addBooleanVariableReadNode(server, node_id, node_title);
// add analog in // add analog in (board has only 2 thus do not all all)
if ( n < 2) {
sprintf(node_id, "i2c%d.ain%d", i, n); sprintf(node_id, "i2c%d.ain%d", i, n);
sprintf(node_title, "I2C%d / Analog Input %d", i, n); sprintf(node_title, "I2C%d / Analog Input %d", i, n);
addUIntegerVariableReadNode(server, node_id, node_title); addUIntegerVariableReadNode(server, node_id, node_title);
} }
} }
}
} }
/* Connect to variables to physical relays, analog and digital inputs. /* Connect to variables to physical relays, analog and digital inputs.
...@@ -160,18 +162,6 @@ static void beforeReadTimeI2C0Ain1(UA_Server *server, ...@@ -160,18 +162,6 @@ static void beforeReadTimeI2C0Ain1(UA_Server *server,
const UA_NumericRange *range, const UA_DataValue *data){ const UA_NumericRange *range, const UA_DataValue *data){
beforeReadTimeAnalongIn(I2C_SLAVE_ADDR_LIST[0], 0x31, data);} beforeReadTimeAnalongIn(I2C_SLAVE_ADDR_LIST[0], 0x31, data);}
static void beforeReadTimeI2C0Ain2(UA_Server *server,
const UA_NodeId *sessionId, void *sessionContext,
const UA_NodeId *nodeid, void *nodeContext,
const UA_NumericRange *range, const UA_DataValue *data){
beforeReadTimeAnalongIn(I2C_SLAVE_ADDR_LIST[0], 0x32, data);}
static void beforeReadTimeI2C0Ain3(UA_Server *server,
const UA_NodeId *sessionId, void *sessionContext,
const UA_NodeId *nodeid, void *nodeContext,
const UA_NumericRange *range, const UA_DataValue *data){
beforeReadTimeAnalongIn(I2C_SLAVE_ADDR_LIST[0], 0x33, data);}
// I2C1 // I2C1
static void beforeReadTimeI2C1Ain0(UA_Server *server, static void beforeReadTimeI2C1Ain0(UA_Server *server,
const UA_NodeId *sessionId, void *sessionContext, const UA_NodeId *sessionId, void *sessionContext,
...@@ -185,18 +175,6 @@ static void beforeReadTimeI2C1Ain1(UA_Server *server, ...@@ -185,18 +175,6 @@ static void beforeReadTimeI2C1Ain1(UA_Server *server,
const UA_NumericRange *range, const UA_DataValue *data){ const UA_NumericRange *range, const UA_DataValue *data){
beforeReadTimeAnalongIn(I2C_SLAVE_ADDR_LIST[1], 0x31, data);} beforeReadTimeAnalongIn(I2C_SLAVE_ADDR_LIST[1], 0x31, data);}
static void beforeReadTimeI2C1Ain2(UA_Server *server,
const UA_NodeId *sessionId, void *sessionContext,
const UA_NodeId *nodeid, void *nodeContext,
const UA_NumericRange *range, const UA_DataValue *data){
beforeReadTimeAnalongIn(I2C_SLAVE_ADDR_LIST[1], 0x32, data);}
static void beforeReadTimeI2C1Ain3(UA_Server *server,
const UA_NodeId *sessionId, void *sessionContext,
const UA_NodeId *nodeid, void *nodeContext,
const UA_NumericRange *range, const UA_DataValue *data){
beforeReadTimeAnalongIn(I2C_SLAVE_ADDR_LIST[1], 0x33, data);}
// I2C2 // I2C2
static void beforeReadTimeI2C2Ain0(UA_Server *server, static void beforeReadTimeI2C2Ain0(UA_Server *server,
const UA_NodeId *sessionId, void *sessionContext, const UA_NodeId *sessionId, void *sessionContext,
...@@ -210,18 +188,6 @@ static void beforeReadTimeI2C2Ain1(UA_Server *server, ...@@ -210,18 +188,6 @@ static void beforeReadTimeI2C2Ain1(UA_Server *server,
const UA_NumericRange *range, const UA_DataValue *data){ const UA_NumericRange *range, const UA_DataValue *data){
beforeReadTimeAnalongIn(I2C_SLAVE_ADDR_LIST[2], 0x31, data);} beforeReadTimeAnalongIn(I2C_SLAVE_ADDR_LIST[2], 0x31, data);}
static void beforeReadTimeI2C2Ain2(UA_Server *server,
const UA_NodeId *sessionId, void *sessionContext,
const UA_NodeId *nodeid, void *nodeContext,
const UA_NumericRange *range, const UA_DataValue *data){
beforeReadTimeAnalongIn(I2C_SLAVE_ADDR_LIST[2], 0x32, data);}
static void beforeReadTimeI2C2Ain3(UA_Server *server,
const UA_NodeId *sessionId, void *sessionContext,
const UA_NodeId *nodeid, void *nodeContext,
const UA_NumericRange *range, const UA_DataValue *data){
beforeReadTimeAnalongIn(I2C_SLAVE_ADDR_LIST[2], 0x33, data);}
// I2C3 // I2C3
static void beforeReadTimeI2C3Ain0(UA_Server *server, static void beforeReadTimeI2C3Ain0(UA_Server *server,
const UA_NodeId *sessionId, void *sessionContext, const UA_NodeId *sessionId, void *sessionContext,
...@@ -235,18 +201,6 @@ static void beforeReadTimeI2C3Ain1(UA_Server *server, ...@@ -235,18 +201,6 @@ static void beforeReadTimeI2C3Ain1(UA_Server *server,
const UA_NumericRange *range, const UA_DataValue *data){ const UA_NumericRange *range, const UA_DataValue *data){
beforeReadTimeAnalongIn(I2C_SLAVE_ADDR_LIST[3], 0x31, data);} beforeReadTimeAnalongIn(I2C_SLAVE_ADDR_LIST[3], 0x31, data);}
static void beforeReadTimeI2C3Ain2(UA_Server *server,
const UA_NodeId *sessionId, void *sessionContext,
const UA_NodeId *nodeid, void *nodeContext,
const UA_NumericRange *range, const UA_DataValue *data){
beforeReadTimeAnalongIn(I2C_SLAVE_ADDR_LIST[3], 0x32, data);}
static void beforeReadTimeI2C3Ain3(UA_Server *server,
const UA_NodeId *sessionId, void *sessionContext,
const UA_NodeId *nodeid, void *nodeContext,
const UA_NumericRange *range, const UA_DataValue *data){
beforeReadTimeAnalongIn(I2C_SLAVE_ADDR_LIST[3], 0x33, data);}
// Digital Inputs // Digital Inputs
static void beforeReadTimeDigitalIn(int addr, static void beforeReadTimeDigitalIn(int addr,
...@@ -517,8 +471,8 @@ static void addValueCallbackToCurrentTimeVariable(UA_Server *server) ...@@ -517,8 +471,8 @@ static void addValueCallbackToCurrentTimeVariable(UA_Server *server)
int device_number, offset_number; int device_number, offset_number;
char *node_id = malloc(sizeof(char) * 10); char *node_id = malloc(sizeof(char) * 10);
// list of relays, digital and analog callbacks for all devices (XXX: for now only 4 outof 127 possible!) // list of relays, digital and analog callbacks for all devices (XXX: for now only 4 out of 127 possible!)
static void (*callables[48]) static void (*callables[40])
(UA_Server *server, const UA_NodeId *sessionId, void *sessionContext, (UA_Server *server, const UA_NodeId *sessionId, void *sessionContext,
const UA_NodeId *nodeId, void *nodeContext, const UA_NumericRange *range, const UA_NodeId *nodeId, void *nodeContext, const UA_NumericRange *range,
const UA_DataValue *data) = {// relays - IC0 const UA_DataValue *data) = {// relays - IC0
...@@ -534,8 +488,6 @@ static void addValueCallbackToCurrentTimeVariable(UA_Server *server) ...@@ -534,8 +488,6 @@ static void addValueCallbackToCurrentTimeVariable(UA_Server *server)
// analong - IC0 // analong - IC0
beforeReadTimeI2C0Ain0, beforeReadTimeI2C0Ain0,
beforeReadTimeI2C0Ain1, beforeReadTimeI2C0Ain1,
beforeReadTimeI2C0Ain2,
beforeReadTimeI2C0Ain3,
// relays - IC1 // relays - IC1
afterWriteTimeI2C1_0, afterWriteTimeI2C1_0,
...@@ -550,8 +502,6 @@ static void addValueCallbackToCurrentTimeVariable(UA_Server *server) ...@@ -550,8 +502,6 @@ static void addValueCallbackToCurrentTimeVariable(UA_Server *server)
// analog - IC1 // analog - IC1
beforeReadTimeI2C1Ain0, beforeReadTimeI2C1Ain0,
beforeReadTimeI2C1Ain1, beforeReadTimeI2C1Ain1,
beforeReadTimeI2C1Ain2,
beforeReadTimeI2C1Ain3,
// relays - IC2 // relays - IC2
afterWriteTimeI2C2_0, afterWriteTimeI2C2_0,
...@@ -566,8 +516,6 @@ static void addValueCallbackToCurrentTimeVariable(UA_Server *server) ...@@ -566,8 +516,6 @@ static void addValueCallbackToCurrentTimeVariable(UA_Server *server)
// analong - IC2 // analong - IC2
beforeReadTimeI2C2Ain0, beforeReadTimeI2C2Ain0,
beforeReadTimeI2C2Ain1, beforeReadTimeI2C2Ain1,
beforeReadTimeI2C2Ain2,
beforeReadTimeI2C2Ain3,
// relays - IC3 // relays - IC3
afterWriteTimeI2C3_0, afterWriteTimeI2C3_0,
...@@ -579,11 +527,9 @@ static void addValueCallbackToCurrentTimeVariable(UA_Server *server) ...@@ -579,11 +527,9 @@ static void addValueCallbackToCurrentTimeVariable(UA_Server *server)
beforeReadTimeI2C3In1, beforeReadTimeI2C3In1,
beforeReadTimeI2C3In2, beforeReadTimeI2C3In2,
beforeReadTimeI2C3In3, beforeReadTimeI2C3In3,
// analog - IC1 // analog - IC3
beforeReadTimeI2C3Ain0, beforeReadTimeI2C3Ain0,
beforeReadTimeI2C3Ain1, beforeReadTimeI2C3Ain1,
beforeReadTimeI2C3Ain2,
beforeReadTimeI2C3Ain3,
}; };
// set proper callbacks from list of all // set proper callbacks from list of all
...@@ -594,24 +540,26 @@ static void addValueCallbackToCurrentTimeVariable(UA_Server *server) ...@@ -594,24 +540,26 @@ static void addValueCallbackToCurrentTimeVariable(UA_Server *server)
UA_NodeId currentNodeId = UA_NODEID_STRING(1, node_id); UA_NodeId currentNodeId = UA_NODEID_STRING(1, node_id);
UA_ValueCallback callback; UA_ValueCallback callback;
callback.onRead = beforeReadTime; callback.onRead = beforeReadTime;
callback.onWrite = callables[device_number * 12 + offset_number]; callback.onWrite = callables[device_number * 10 + offset_number];
UA_Server_setVariableNode_valueCallback(server, currentNodeId, callback); UA_Server_setVariableNode_valueCallback(server, currentNodeId, callback);
// digital inputs // digital inputs
sprintf(node_id, "i2c%d.in%d", device_number, offset_number); sprintf(node_id, "i2c%d.in%d", device_number, offset_number);
UA_NodeId currentNodeId1 = UA_NODEID_STRING(1, node_id); UA_NodeId currentNodeId1 = UA_NODEID_STRING(1, node_id);
UA_ValueCallback callback1; UA_ValueCallback callback1;
callback1.onRead = callables[device_number * 12 + offset_number + 4]; callback1.onRead = callables[device_number * 10 + offset_number + 4];
callback1.onWrite = afterWriteTime; callback1.onWrite = afterWriteTime;
UA_Server_setVariableNode_valueCallback(server, currentNodeId1, callback1); UA_Server_setVariableNode_valueCallback(server, currentNodeId1, callback1);
// analog inputs // analog inputs
if (offset_number < 2) {
sprintf(node_id, "i2c%d.ain%d", device_number, offset_number); sprintf(node_id, "i2c%d.ain%d", device_number, offset_number);
UA_NodeId currentNodeId2 = UA_NODEID_STRING(1, node_id); UA_NodeId currentNodeId2 = UA_NODEID_STRING(1, node_id);
UA_ValueCallback callback2; UA_ValueCallback callback2;
callback2.onRead = callables[device_number * 12 + offset_number + 8]; callback2.onRead = callables[device_number * 10 + offset_number + 8];
callback2.onWrite = afterWriteTime; callback2.onWrite = afterWriteTime;
UA_Server_setVariableNode_valueCallback(server, currentNodeId2, callback2); UA_Server_setVariableNode_valueCallback(server, currentNodeId2, callback2);
} }
} }
}
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment