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

Support the maximal amount of Analon Ins (2).

parent cc96c967
......@@ -113,10 +113,12 @@ static void addVariable(UA_Server *server)
sprintf(node_id, "i2c%d.in%d", i, n);
sprintf(node_title, "I2C%d / Digital Input %d", i, n);
addBooleanVariableReadNode(server, node_id, node_title);
// add analog in
sprintf(node_id, "i2c%d.ain%d", i, n);
sprintf(node_title, "I2C%d / Analog Input %d", i, n);
addUIntegerVariableReadNode(server, node_id, node_title);
// 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_title, "I2C%d / Analog Input %d", i, n);
addUIntegerVariableReadNode(server, node_id, node_title);
}
}
}
}
......@@ -160,18 +162,6 @@ static void beforeReadTimeI2C0Ain1(UA_Server *server,
const UA_NumericRange *range, const UA_DataValue *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
static void beforeReadTimeI2C1Ain0(UA_Server *server,
const UA_NodeId *sessionId, void *sessionContext,
......@@ -185,18 +175,6 @@ static void beforeReadTimeI2C1Ain1(UA_Server *server,
const UA_NumericRange *range, const UA_DataValue *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
static void beforeReadTimeI2C2Ain0(UA_Server *server,
const UA_NodeId *sessionId, void *sessionContext,
......@@ -210,18 +188,6 @@ static void beforeReadTimeI2C2Ain1(UA_Server *server,
const UA_NumericRange *range, const UA_DataValue *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
static void beforeReadTimeI2C3Ain0(UA_Server *server,
const UA_NodeId *sessionId, void *sessionContext,
......@@ -235,18 +201,6 @@ static void beforeReadTimeI2C3Ain1(UA_Server *server,
const UA_NumericRange *range, const UA_DataValue *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
static void beforeReadTimeDigitalIn(int addr,
......@@ -517,8 +471,8 @@ static void addValueCallbackToCurrentTimeVariable(UA_Server *server)
int device_number, offset_number;
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!)
static void (*callables[48])
// list of relays, digital and analog callbacks for all devices (XXX: for now only 4 out of 127 possible!)
static void (*callables[40])
(UA_Server *server, const UA_NodeId *sessionId, void *sessionContext,
const UA_NodeId *nodeId, void *nodeContext, const UA_NumericRange *range,
const UA_DataValue *data) = {// relays - IC0
......@@ -534,8 +488,6 @@ static void addValueCallbackToCurrentTimeVariable(UA_Server *server)
// analong - IC0
beforeReadTimeI2C0Ain0,
beforeReadTimeI2C0Ain1,
beforeReadTimeI2C0Ain2,
beforeReadTimeI2C0Ain3,
// relays - IC1
afterWriteTimeI2C1_0,
......@@ -550,8 +502,6 @@ static void addValueCallbackToCurrentTimeVariable(UA_Server *server)
// analog - IC1
beforeReadTimeI2C1Ain0,
beforeReadTimeI2C1Ain1,
beforeReadTimeI2C1Ain2,
beforeReadTimeI2C1Ain3,
// relays - IC2
afterWriteTimeI2C2_0,
......@@ -566,8 +516,6 @@ static void addValueCallbackToCurrentTimeVariable(UA_Server *server)
// analong - IC2
beforeReadTimeI2C2Ain0,
beforeReadTimeI2C2Ain1,
beforeReadTimeI2C2Ain2,
beforeReadTimeI2C2Ain3,
// relays - IC3
afterWriteTimeI2C3_0,
......@@ -579,11 +527,9 @@ static void addValueCallbackToCurrentTimeVariable(UA_Server *server)
beforeReadTimeI2C3In1,
beforeReadTimeI2C3In2,
beforeReadTimeI2C3In3,
// analog - IC1
// analog - IC3
beforeReadTimeI2C3Ain0,
beforeReadTimeI2C3Ain1,
beforeReadTimeI2C3Ain2,
beforeReadTimeI2C3Ain3,
};
// set proper callbacks from list of all
......@@ -594,24 +540,26 @@ static void addValueCallbackToCurrentTimeVariable(UA_Server *server)
UA_NodeId currentNodeId = UA_NODEID_STRING(1, node_id);
UA_ValueCallback callback;
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);
// digital inputs
sprintf(node_id, "i2c%d.in%d", device_number, offset_number);
UA_NodeId currentNodeId1 = UA_NODEID_STRING(1, node_id);
UA_ValueCallback callback1;
callback1.onRead = callables[device_number * 12 + offset_number + 4];
callback1.onRead = callables[device_number * 10 + offset_number + 4];
callback1.onWrite = afterWriteTime;
UA_Server_setVariableNode_valueCallback(server, currentNodeId1, callback1);
// analog inputs
sprintf(node_id, "i2c%d.ain%d", device_number, offset_number);
UA_NodeId currentNodeId2 = UA_NODEID_STRING(1, node_id);
UA_ValueCallback callback2;
callback2.onRead = callables[device_number * 12 + offset_number + 8];
callback2.onWrite = afterWriteTime;
UA_Server_setVariableNode_valueCallback(server, currentNodeId2, callback2);
if (offset_number < 2) {
sprintf(node_id, "i2c%d.ain%d", device_number, offset_number);
UA_NodeId currentNodeId2 = UA_NODEID_STRING(1, node_id);
UA_ValueCallback callback2;
callback2.onRead = callables[device_number * 10 + offset_number + 8];
callback2.onWrite = afterWriteTime;
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