Commit 88859691 authored by Ivan Tyagov's avatar Ivan Tyagov

Expose only OPC-UA nodes based on configured I2C slave list.

parent 80960f0e
...@@ -35,7 +35,7 @@ static char args_doc[] = "..."; ...@@ -35,7 +35,7 @@ static char args_doc[] = "...";
static struct argp_option options[] = { static struct argp_option options[] = {
{ "port", 'p', "4840", 0, "Port to bind to."}, { "port", 'p', "4840", 0, "Port to bind to."},
{ "device", 'd', "/dev/i2c-1", 0, "Linux block device path."}, { "device", 'd', "/dev/i2c-1", 0, "Linux block device path."},
{ "slave-address-list", 's', "0x58", 0, "List of slave I2C addresses."}, { "slave-address-list", 's', "0x58", 0, "Comma separated list of slave I2C addresses."},
{ "mode", 'm', "0", 0, "Set different modes of operation of coupler. Default (0) is set attached \ { "mode", 'm', "0", 0, "Set different modes of operation of coupler. Default (0) is set attached \
I2C's state state. Virtual (1) which does NOT set any I2C slaves' state."}, I2C's state state. Virtual (1) which does NOT set any I2C slaves' state."},
{ 0 } { 0 }
...@@ -96,6 +96,25 @@ char *I2C_BLOCK_DEVICE_NAME; ...@@ -96,6 +96,25 @@ char *I2C_BLOCK_DEVICE_NAME;
// global virtual mode needed for testing on x86 platform // global virtual mode needed for testing on x86 platform
bool I2C_VIRTUAL_MODE = 0; bool I2C_VIRTUAL_MODE = 0;
static int getI2CSlaveListLength() {
/*
* Return ONLY registred I2C slaves
*/
int i;
int addr;
int counter = 0;
int length = sizeof(I2C_SLAVE_ADDR_LIST) / sizeof(int);
for(i = 0; i < length; i++)
{
addr = I2C_SLAVE_ADDR_LIST[i];
if (addr!= 0) {
counter++;
}
}
return counter;
}
static int setRelayState(int command, int i2c_addr) { static int setRelayState(int command, int i2c_addr) {
/* /*
* Set relays' state over I2C * Set relays' state over I2C
...@@ -160,7 +179,7 @@ static void addVariable(UA_Server *server) { ...@@ -160,7 +179,7 @@ static void addVariable(UA_Server *server) {
/* /*
* Create all variables representing MOD-IO's relays * Create all variables representing MOD-IO's relays
*/ */
int length = sizeof(I2C_SLAVE_ADDR_LIST) / sizeof(int); int length = getI2CSlaveListLength();
if (length>=1) { if (length>=1) {
// IC2-0 // IC2-0
addIntegerVariableNode(server, "i2c0.relay0", "I2C0 / Relay 0"); addIntegerVariableNode(server, "i2c0.relay0", "I2C0 / Relay 0");
...@@ -335,7 +354,9 @@ static void afterWriteTimeI2C1_3(UA_Server *server, ...@@ -335,7 +354,9 @@ static void afterWriteTimeI2C1_3(UA_Server *server,
} }
} }
static void addValueCallbackToCurrentTimeVariable(UA_Server *server) { static void addValueCallbackToCurrentTimeVariable(UA_Server *server) {
int length = getI2CSlaveListLength();
// I2C0 // I2C0
// relay 0 // relay 0
UA_NodeId currentNodeId0 = UA_NODEID_STRING(1, "i2c0.relay0"); UA_NodeId currentNodeId0 = UA_NODEID_STRING(1, "i2c0.relay0");
...@@ -365,6 +386,7 @@ static void addValueCallbackToCurrentTimeVariable(UA_Server *server) { ...@@ -365,6 +386,7 @@ static void addValueCallbackToCurrentTimeVariable(UA_Server *server) {
callback3.onWrite = afterWriteTimeI2C0_3; callback3.onWrite = afterWriteTimeI2C0_3;
UA_Server_setVariableNode_valueCallback(server, currentNodeId3, callback3); UA_Server_setVariableNode_valueCallback(server, currentNodeId3, callback3);
if(length > 1){
// I2C1 // I2C1
// relay 0 // relay 0
UA_NodeId currentNodeId4 = UA_NODEID_STRING(1, "i2c1.relay0"); UA_NodeId currentNodeId4 = UA_NODEID_STRING(1, "i2c1.relay0");
...@@ -393,6 +415,7 @@ static void addValueCallbackToCurrentTimeVariable(UA_Server *server) { ...@@ -393,6 +415,7 @@ static void addValueCallbackToCurrentTimeVariable(UA_Server *server) {
callback7.onRead = beforeReadTime; callback7.onRead = beforeReadTime;
callback7.onWrite = afterWriteTimeI2C1_3; callback7.onWrite = afterWriteTimeI2C1_3;
UA_Server_setVariableNode_valueCallback(server, currentNodeId7, callback7); UA_Server_setVariableNode_valueCallback(server, currentNodeId7, callback7);
}
} }
......
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