Modification of MOD IO digital input from UA_INT_32 to UA_Boolean type

Test: Program is tested locally with laptop.

        modified:   server.c
parent c6c28acc
...@@ -33,26 +33,28 @@ const char *argp_program_bug_address = "ivan@nexedi.com"; ...@@ -33,26 +33,28 @@ const char *argp_program_bug_address = "ivan@nexedi.com";
static char doc[] = "OPC-UA server which controls MOD-IO's relays' state over OPC-UA protocol."; static char doc[] = "OPC-UA server which controls MOD-IO's relays' state over OPC-UA protocol.";
static char args_doc[] = "..."; 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, "Comma separated 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}};
};
struct arguments { struct arguments
{
int mode; int mode;
int port; int port;
char *device; char *device;
char *slave_address_list; char *slave_address_list;
}; };
static error_t parse_opt(int key, char *arg, struct argp_state *state) { static error_t parse_opt(int key, char *arg, struct argp_state *state)
{
struct arguments *arguments = state->input; struct arguments *arguments = state->input;
switch (key) { switch (key)
{
case 'p': case 'p':
arguments->port = arg ? atoi (arg) : DEFAULT_OPC_UA_PORT; arguments->port = arg ? atoi(arg) : DEFAULT_OPC_UA_PORT;
//printf("got arg port=%s\n", arg); //printf("got arg port=%s\n", arg);
break; break;
case 'd': case 'd':
...@@ -64,7 +66,7 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) { ...@@ -64,7 +66,7 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
//printf("got arg slave_address_list=%s\n", arg); //printf("got arg slave_address_list=%s\n", arg);
break; break;
case 'm': case 'm':
arguments->mode = arg ? atoi (arg) : DEFAULT_MODE; arguments->mode = arg ? atoi(arg) : DEFAULT_MODE;
break; break;
case ARGP_KEY_ARG: case ARGP_KEY_ARG:
return 0; return 0;
...@@ -74,7 +76,7 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) { ...@@ -74,7 +76,7 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
return 0; return 0;
} }
static struct argp argp = { options, parse_opt, args_doc, doc, 0, 0, 0 }; static struct argp argp = {options, parse_opt, args_doc, doc, 0, 0, 0};
// global relay state // global relay state
uint8_t I2C_0_RELAYS_STATE = 0; // state of 4 relays at I2C slave 0 uint8_t I2C_0_RELAYS_STATE = 0; // state of 4 relays at I2C slave 0
...@@ -96,7 +98,8 @@ char *I2C_BLOCK_DEVICE_NAME; ...@@ -96,7 +98,8 @@ 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() { static int getI2CSlaveListLength()
{
/* /*
* Return ONLY registred I2C slaves * Return ONLY registred I2C slaves
*/ */
...@@ -105,23 +108,26 @@ static int getI2CSlaveListLength() { ...@@ -105,23 +108,26 @@ static int getI2CSlaveListLength() {
int counter = 0; int counter = 0;
int length = sizeof(I2C_SLAVE_ADDR_LIST) / sizeof(int); int length = sizeof(I2C_SLAVE_ADDR_LIST) / sizeof(int);
for(i = 0; i < length; i++) for (i = 0; i < length; i++)
{ {
addr = I2C_SLAVE_ADDR_LIST[i]; addr = I2C_SLAVE_ADDR_LIST[i];
if (addr!= 0) { if (addr != 0)
{
counter++; counter++;
} }
} }
return 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
*/ */
int file; int file;
char filename[20]; char filename[20];
if(I2C_VIRTUAL_MODE){ if (I2C_VIRTUAL_MODE)
{
// we're in a virtual mode, likely on x86 platform or without I2C support // we're in a virtual mode, likely on x86 platform or without I2C support
// simply do nothing // simply do nothing
return 0; return 0;
...@@ -129,14 +135,16 @@ static int setRelayState(int command, int i2c_addr) { ...@@ -129,14 +135,16 @@ static int setRelayState(int command, int i2c_addr) {
// step 1: open device // step 1: open device
file = open(I2C_BLOCK_DEVICE_NAME, O_RDWR); file = open(I2C_BLOCK_DEVICE_NAME, O_RDWR);
if (file < 0) { if (file < 0)
{
/* ERROR HANDLING; you can check errno to see what went wrong */ /* ERROR HANDLING; you can check errno to see what went wrong */
printf("Error opening i2c device (0x%x).\n", i2c_addr); printf("Error opening i2c device (0x%x).\n", i2c_addr);
exit(1); exit(1);
} }
// step 2: address the slave by its address // step 2: address the slave by its address
if (ioctl(file, I2C_SLAVE, i2c_addr) < 0) { if (ioctl(file, I2C_SLAVE, i2c_addr) < 0)
{
/* ERROR HANDLING; you can check errno to see what went wrong */ /* ERROR HANDLING; you can check errno to see what went wrong */
printf("Error addressing i2c slave (0x%x).\n", i2c_addr); printf("Error addressing i2c slave (0x%x).\n", i2c_addr);
exit(1); exit(1);
...@@ -147,20 +155,23 @@ static int setRelayState(int command, int i2c_addr) { ...@@ -147,20 +155,23 @@ static int setRelayState(int command, int i2c_addr) {
char buf[10]; char buf[10];
buf[0] = reg; buf[0] = reg;
buf[1] = command; //0x00 -all off, 0x0F - all 4 on buf[1] = command; //0x00 -all off, 0x0F - all 4 on
if (write(file, buf, 3) != 3) { if (write(file, buf, 3) != 3)
{
/* ERROR HANDLING: i2c transaction failed */ /* ERROR HANDLING: i2c transaction failed */
printf("Error writing to i2c slave (0x%x).\n", i2c_addr); printf("Error writing to i2c slave (0x%x).\n", i2c_addr);
} }
close(file); close(file);
} }
static int getDigitalInputState( int i2c_addr, char **digital_input) { static int getDigitalInputState(int i2c_addr, char **digital_input)
{
/* /*
* get digital input state over I2C * get digital input state over I2C
*/ */
int file; int file;
char filename[20]; char filename[20];
if(I2C_VIRTUAL_MODE){ if (I2C_VIRTUAL_MODE)
{
// we're in a virtual mode, likely on x86 platform or without I2C support // we're in a virtual mode, likely on x86 platform or without I2C support
// simply do nothing // simply do nothing
return 0; return 0;
...@@ -168,14 +179,16 @@ static int getDigitalInputState( int i2c_addr, char **digital_input) { ...@@ -168,14 +179,16 @@ static int getDigitalInputState( int i2c_addr, char **digital_input) {
// step 1: open device // step 1: open device
file = open(I2C_BLOCK_DEVICE_NAME, O_RDWR); file = open(I2C_BLOCK_DEVICE_NAME, O_RDWR);
if (file < 0) { if (file < 0)
{
/* ERROR HANDLING; you can check errno to see what went wrong */ /* ERROR HANDLING; you can check errno to see what went wrong */
printf("Error opening i2c device (0x%x).\n", i2c_addr); printf("Error opening i2c device (0x%x).\n", i2c_addr);
exit(1); exit(1);
} }
// step 2: address the slave by its address // step 2: address the slave by its address
if (ioctl(file, I2C_SLAVE, i2c_addr) < 0) { if (ioctl(file, I2C_SLAVE, i2c_addr) < 0)
{
/* ERROR HANDLING; you can check errno to see what went wrong */ /* ERROR HANDLING; you can check errno to see what went wrong */
printf("Error addressing i2c slave (0x%x).\n", i2c_addr); printf("Error addressing i2c slave (0x%x).\n", i2c_addr);
exit(1); exit(1);
...@@ -185,21 +198,26 @@ static int getDigitalInputState( int i2c_addr, char **digital_input) { ...@@ -185,21 +198,26 @@ static int getDigitalInputState( int i2c_addr, char **digital_input) {
__u8 read_reg = 0x20; /* Device register to access */ __u8 read_reg = 0x20; /* Device register to access */
char read_buf[2]; char read_buf[2];
read_buf[0] = read_reg; read_buf[0] = read_reg;
if (write(file, read_buf, 1) != 1) { if (write(file, read_buf, 1) != 1)
{
/* ERROR HANDLING: i2c transaction failed */ /* ERROR HANDLING: i2c transaction failed */
printf("Error writing to i2c slave (0x%x).\n", i2c_addr); printf("Error writing to i2c slave (0x%x).\n", i2c_addr);
} }
if (read(file, read_buf, 1) != 1) { if (read(file, read_buf, 1) != 1)
{
/* ERROR HANDLING: i2c transaction failed */ /* ERROR HANDLING: i2c transaction failed */
printf("Error reading digital input from i2c slave (0x%x).\n", i2c_addr); printf("Error reading digital input from i2c slave (0x%x).\n", i2c_addr);
} else { }
else
{
/* read_buf[0] contains the read byte */ /* read_buf[0] contains the read byte */
*digital_input=&read_buf[0]; *digital_input = &read_buf[0];
} }
close(file); close(file);
} }
void addIntegerVariableNode(UA_Server *server, char *node_id, char *node_description) { void addIntegerVariableNode(UA_Server *server, char *node_id, char *node_description)
{
UA_Int32 myInteger = 0; UA_Int32 myInteger = 0;
UA_NodeId parentNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER); UA_NodeId parentNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER);
UA_NodeId parentReferenceNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES); UA_NodeId parentReferenceNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES);
...@@ -215,54 +233,56 @@ void addIntegerVariableNode(UA_Server *server, char *node_id, char *node_descrip ...@@ -215,54 +233,56 @@ void addIntegerVariableNode(UA_Server *server, char *node_id, char *node_descrip
UA_Server_addVariableNode(server, myIntegerNodeId0, parentNodeId, UA_Server_addVariableNode(server, myIntegerNodeId0, parentNodeId,
parentReferenceNodeId, myIntegerName0, parentReferenceNodeId, myIntegerName0,
UA_NODEID_NUMERIC(0, UA_NS0ID_BASEDATAVARIABLETYPE), attr0, NULL, NULL); UA_NODEID_NUMERIC(0, UA_NS0ID_BASEDATAVARIABLETYPE), attr0, NULL, NULL);
} }
void addIntegerVariableReadNode(UA_Server *server, char *node_id, char *node_description) { void addBooleanVariableReadNode(UA_Server *server, char *node_id, char *node_description)
UA_Int32 myInteger = 0; {
UA_Boolean myBoolean = false;
UA_NodeId parentNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER); UA_NodeId parentNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER);
UA_NodeId parentReferenceNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES); UA_NodeId parentReferenceNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES);
UA_VariableAttributes attr0 = UA_VariableAttributes_default; UA_VariableAttributes attr0 = UA_VariableAttributes_default;
UA_Variant_setScalar(&attr0.value, &myInteger, &UA_TYPES[UA_TYPES_INT32]); UA_Variant_setScalar(&attr0.value, &myBoolean, &UA_TYPES[UA_TYPES_BOOLEAN]);
attr0.description = UA_LOCALIZEDTEXT("en-US", node_description); attr0.description = UA_LOCALIZEDTEXT("en-US", node_description);
attr0.displayName = UA_LOCALIZEDTEXT("en-US", node_description); attr0.displayName = UA_LOCALIZEDTEXT("en-US", node_description);
attr0.dataType = UA_TYPES[UA_TYPES_INT32].typeId; attr0.dataType = UA_TYPES[UA_TYPES_BOOLEAN].typeId;
attr0.accessLevel = UA_ACCESSLEVELMASK_READ; attr0.accessLevel = UA_ACCESSLEVELMASK_READ;
UA_NodeId myIntegerNodeId0 = UA_NODEID_STRING(1, node_id); UA_NodeId myIntegerNodeId0 = UA_NODEID_STRING(1, node_id);
UA_QualifiedName myIntegerName0 = UA_QUALIFIEDNAME(1, node_description); UA_QualifiedName myIntegerName0 = UA_QUALIFIEDNAME(1, node_description);
UA_Server_addVariableNode(server, myIntegerNodeId0, parentNodeId, UA_Server_addVariableNode(server, myIntegerNodeId0, parentNodeId,
parentReferenceNodeId, myIntegerName0, parentReferenceNodeId, myIntegerName0,
UA_NODEID_NUMERIC(0, UA_NS0ID_BASEDATAVARIABLETYPE), attr0, NULL, NULL); UA_NODEID_NUMERIC(0, UA_NS0ID_BASEDATAVARIABLETYPE), attr0, NULL, NULL);
} }
static void addVariable(UA_Server *server) { static void addVariable(UA_Server *server)
{
/* /*
* Create all variables representing MOD-IO's relays * Create all variables representing MOD-IO's relays
*/ */
int length = getI2CSlaveListLength(); 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");
addIntegerVariableNode(server, "i2c0.relay1", "I2C0 / Relay 1"); addIntegerVariableNode(server, "i2c0.relay1", "I2C0 / Relay 1");
addIntegerVariableNode(server, "i2c0.relay2", "I2C0 / Relay 2"); addIntegerVariableNode(server, "i2c0.relay2", "I2C0 / Relay 2");
addIntegerVariableNode(server, "i2c0.relay3", "I2C0 / Relay 3"); addIntegerVariableNode(server, "i2c0.relay3", "I2C0 / Relay 3");
addIntegerVariableReadNode(server, "i2c0.in0", "I2C0 / Digital Input 0"); addBooleanVariableReadNode(server, "i2c0.in0", "I2C0 / Digital Input 0");
addIntegerVariableReadNode(server, "i2c0.in1", "I2C0 / Digital Input 1"); addBooleanVariableReadNode(server, "i2c0.in1", "I2C0 / Digital Input 1");
addIntegerVariableReadNode(server, "i2c0.in2", "I2C0 / Digital Input 2"); addBooleanVariableReadNode(server, "i2c0.in2", "I2C0 / Digital Input 2");
addIntegerVariableReadNode(server, "i2c0.in3", "I2C0 / Digital Input 3"); addBooleanVariableReadNode(server, "i2c0.in3", "I2C0 / Digital Input 3");
} }
if (length>=2) { if (length >= 2)
{
// IC2-1 // IC2-1
addIntegerVariableNode(server, "i2c1.relay0", "I2C1 / Relay 0"); addIntegerVariableNode(server, "i2c1.relay0", "I2C1 / Relay 0");
addIntegerVariableNode(server, "i2c1.relay1", "I2C1 / Relay 1"); addIntegerVariableNode(server, "i2c1.relay1", "I2C1 / Relay 1");
addIntegerVariableNode(server, "i2c1.relay2", "I2C1 / Relay 2"); addIntegerVariableNode(server, "i2c1.relay2", "I2C1 / Relay 2");
addIntegerVariableNode(server, "i2c1.relay3", "I2C1 / Relay 3"); addIntegerVariableNode(server, "i2c1.relay3", "I2C1 / Relay 3");
addIntegerVariableReadNode(server, "i2c1.in0", "I2C1 / Digital Input 0"); addBooleanVariableReadNode(server, "i2c1.in0", "I2C1 / Digital Input 0");
addIntegerVariableReadNode(server, "i2c1.in1", "I2C1 / Digital Input 1"); addBooleanVariableReadNode(server, "i2c1.in1", "I2C1 / Digital Input 1");
addIntegerVariableReadNode(server, "i2c1.in2", "I2C1 / Digital Input 2"); addBooleanVariableReadNode(server, "i2c1.in2", "I2C1 / Digital Input 2");
addIntegerVariableReadNode(server, "i2c1.in3", "I2C1 / Digital Input 3"); addBooleanVariableReadNode(server, "i2c1.in3", "I2C1 / Digital Input 3");
} }
} }
...@@ -272,23 +292,29 @@ static void addVariable(UA_Server *server) { ...@@ -272,23 +292,29 @@ static void addVariable(UA_Server *server) {
static void beforeReadTime(UA_Server *server, static void beforeReadTime(UA_Server *server,
const UA_NodeId *sessionId, void *sessionContext, const UA_NodeId *sessionId, void *sessionContext,
const UA_NodeId *nodeid, void *nodeContext, const UA_NodeId *nodeid, void *nodeContext,
const UA_NumericRange *range, const UA_DataValue *data) { const UA_NumericRange *range, const UA_DataValue *data)
{
} }
static void beforeReadTimeI2C0In0(UA_Server *server, static void beforeReadTimeI2C0In0(UA_Server *server,
const UA_NodeId *sessionId, void *sessionContext, const UA_NodeId *sessionId, void *sessionContext,
const UA_NodeId *nodeid, void *nodeContext, const UA_NodeId *nodeid, void *nodeContext,
const UA_NumericRange *range, const UA_DataValue *data) { const UA_NumericRange *range, const UA_DataValue *data)
{
int addr = I2C_SLAVE_ADDR_LIST[0]; int addr = I2C_SLAVE_ADDR_LIST[0];
char *data_input=0; char *data_input = 0;
getDigitalInputState( addr, &data_input); getDigitalInputState(addr, &data_input);
if ((*data_input) & (1UL << 0)){ if ((*data_input) & (1UL << 0))
if (data->value.type == &UA_TYPES[UA_TYPES_INT32]) { {
*(UA_Int32 *)data->value.data = 1; if (data->value.type == &UA_TYPES[UA_TYPES_BOOLEAN])
{
*(UA_Boolean *)data->value.data = true;
}
} }
} else { else
if (data->value.type == &UA_TYPES[UA_TYPES_INT32]) { {
*(UA_Int32 *)data->value.data = 0; if (data->value.type == &UA_TYPES[UA_TYPES_BOOLEAN])
{
*(UA_Boolean *)data->value.data = false;
} }
} }
} }
...@@ -296,17 +322,23 @@ static void beforeReadTimeI2C0In0(UA_Server *server, ...@@ -296,17 +322,23 @@ static void beforeReadTimeI2C0In0(UA_Server *server,
static void beforeReadTimeI2C0In1(UA_Server *server, static void beforeReadTimeI2C0In1(UA_Server *server,
const UA_NodeId *sessionId, void *sessionContext, const UA_NodeId *sessionId, void *sessionContext,
const UA_NodeId *nodeid, void *nodeContext, const UA_NodeId *nodeid, void *nodeContext,
const UA_NumericRange *range, const UA_DataValue *data) { const UA_NumericRange *range, const UA_DataValue *data)
{
int addr = I2C_SLAVE_ADDR_LIST[0]; int addr = I2C_SLAVE_ADDR_LIST[0];
char *data_input=0; char *data_input = 0;
getDigitalInputState( addr, &data_input); getDigitalInputState(addr, &data_input);
if ((*data_input) & (1UL << 1)){ if ((*data_input) & (1UL << 1))
if (data->value.type == &UA_TYPES[UA_TYPES_INT32]) { {
*(UA_Int32 *)data->value.data = 1; if (data->value.type == &UA_TYPES[UA_TYPES_BOOLEAN])
{
*(UA_Boolean *)data->value.data = true;
} }
} else { }
if (data->value.type == &UA_TYPES[UA_TYPES_INT32]) { else
*(UA_Int32 *)data->value.data = 0; {
if (data->value.type == &UA_TYPES[UA_TYPES_BOOLEAN])
{
*(UA_Boolean *)data->value.data = false;
} }
} }
} }
...@@ -314,17 +346,23 @@ static void beforeReadTimeI2C0In1(UA_Server *server, ...@@ -314,17 +346,23 @@ static void beforeReadTimeI2C0In1(UA_Server *server,
static void beforeReadTimeI2C0In2(UA_Server *server, static void beforeReadTimeI2C0In2(UA_Server *server,
const UA_NodeId *sessionId, void *sessionContext, const UA_NodeId *sessionId, void *sessionContext,
const UA_NodeId *nodeid, void *nodeContext, const UA_NodeId *nodeid, void *nodeContext,
const UA_NumericRange *range, const UA_DataValue *data) { const UA_NumericRange *range, const UA_DataValue *data)
{
int addr = I2C_SLAVE_ADDR_LIST[0]; int addr = I2C_SLAVE_ADDR_LIST[0];
char *data_input=0; char *data_input = 0;
getDigitalInputState( addr, &data_input); getDigitalInputState(addr, &data_input);
if ((*data_input) & (1UL << 2)){ if ((*data_input) & (1UL << 2))
if (data->value.type == &UA_TYPES[UA_TYPES_INT32]) { {
*(UA_Int32 *)data->value.data = 1; if (data->value.type == &UA_TYPES[UA_TYPES_BOOLEAN])
{
*(UA_Boolean *)data->value.data = true;
} }
} else { }
if (data->value.type == &UA_TYPES[UA_TYPES_INT32]) { else
*(UA_Int32 *)data->value.data = 0; {
if (data->value.type == &UA_TYPES[UA_TYPES_BOOLEAN])
{
*(UA_Boolean *)data->value.data = false;
} }
} }
} }
...@@ -332,34 +370,46 @@ static void beforeReadTimeI2C0In2(UA_Server *server, ...@@ -332,34 +370,46 @@ static void beforeReadTimeI2C0In2(UA_Server *server,
static void beforeReadTimeI2C0In3(UA_Server *server, static void beforeReadTimeI2C0In3(UA_Server *server,
const UA_NodeId *sessionId, void *sessionContext, const UA_NodeId *sessionId, void *sessionContext,
const UA_NodeId *nodeid, void *nodeContext, const UA_NodeId *nodeid, void *nodeContext,
const UA_NumericRange *range, const UA_DataValue *data) { const UA_NumericRange *range, const UA_DataValue *data)
{
int addr = I2C_SLAVE_ADDR_LIST[0]; int addr = I2C_SLAVE_ADDR_LIST[0];
char *data_input=0; char *data_input = 0;
getDigitalInputState( addr, &data_input); getDigitalInputState(addr, &data_input);
if ((*data_input) & (1UL << 3)){ if ((*data_input) & (1UL << 3))
if (data->value.type == &UA_TYPES[UA_TYPES_INT32]) { {
*(UA_Int32 *)data->value.data = 1; if (data->value.type == &UA_TYPES[UA_TYPES_BOOLEAN])
{
*(UA_Boolean *)data->value.data = true;
} }
} else { }
if (data->value.type == &UA_TYPES[UA_TYPES_INT32]) { else
*(UA_Int32 *)data->value.data = 0; {
if (data->value.type == &UA_TYPES[UA_TYPES_BOOLEAN])
{
*(UA_Boolean *)data->value.data = false;
} }
} }
} }
static void beforeReadTimeI2C1In0(UA_Server *server, static void beforeReadTimeI2C1In0(UA_Server *server,
const UA_NodeId *sessionId, void *sessionContext, const UA_NodeId *sessionId, void *sessionContext,
const UA_NodeId *nodeid, void *nodeContext, const UA_NodeId *nodeid, void *nodeContext,
const UA_NumericRange *range, const UA_DataValue *data) { const UA_NumericRange *range, const UA_DataValue *data)
{
int addr = I2C_SLAVE_ADDR_LIST[0]; int addr = I2C_SLAVE_ADDR_LIST[0];
char *data_input=0; char *data_input = 0;
getDigitalInputState( addr, &data_input); getDigitalInputState(addr, &data_input);
if ((*data_input) & (1UL << 0)){ if ((*data_input) & (1UL << 0))
if (data->value.type == &UA_TYPES[UA_TYPES_INT32]) { {
*(UA_Int32 *)data->value.data = 1; if (data->value.type == &UA_TYPES[UA_TYPES_BOOLEAN])
{
*(UA_Boolean *)data->value.data = true;
} }
} else { }
if (data->value.type == &UA_TYPES[UA_TYPES_INT32]) { else
*(UA_Int32 *)data->value.data = 0; {
if (data->value.type == &UA_TYPES[UA_TYPES_BOOLEAN])
{
*(UA_Boolean *)data->value.data = false;
} }
} }
} }
...@@ -367,17 +417,23 @@ static void beforeReadTimeI2C1In0(UA_Server *server, ...@@ -367,17 +417,23 @@ static void beforeReadTimeI2C1In0(UA_Server *server,
static void beforeReadTimeI2C1In1(UA_Server *server, static void beforeReadTimeI2C1In1(UA_Server *server,
const UA_NodeId *sessionId, void *sessionContext, const UA_NodeId *sessionId, void *sessionContext,
const UA_NodeId *nodeid, void *nodeContext, const UA_NodeId *nodeid, void *nodeContext,
const UA_NumericRange *range, const UA_DataValue *data) { const UA_NumericRange *range, const UA_DataValue *data)
{
int addr = I2C_SLAVE_ADDR_LIST[0]; int addr = I2C_SLAVE_ADDR_LIST[0];
char *data_input=0; char *data_input = 0;
getDigitalInputState( addr, &data_input); getDigitalInputState(addr, &data_input);
if ((*data_input) & (1UL << 1)){ if ((*data_input) & (1UL << 1))
if (data->value.type == &UA_TYPES[UA_TYPES_INT32]) { {
*(UA_Int32 *)data->value.data = 1; if (data->value.type == &UA_TYPES[UA_TYPES_BOOLEAN])
{
*(UA_Boolean *)data->value.data = true;
} }
} else { }
if (data->value.type == &UA_TYPES[UA_TYPES_INT32]) { else
*(UA_Int32 *)data->value.data = 0; {
if (data->value.type == &UA_TYPES[UA_TYPES_BOOLEAN])
{
*(UA_Boolean *)data->value.data = false;
} }
} }
} }
...@@ -385,17 +441,23 @@ static void beforeReadTimeI2C1In1(UA_Server *server, ...@@ -385,17 +441,23 @@ static void beforeReadTimeI2C1In1(UA_Server *server,
static void beforeReadTimeI2C1In2(UA_Server *server, static void beforeReadTimeI2C1In2(UA_Server *server,
const UA_NodeId *sessionId, void *sessionContext, const UA_NodeId *sessionId, void *sessionContext,
const UA_NodeId *nodeid, void *nodeContext, const UA_NodeId *nodeid, void *nodeContext,
const UA_NumericRange *range, const UA_DataValue *data) { const UA_NumericRange *range, const UA_DataValue *data)
{
int addr = I2C_SLAVE_ADDR_LIST[0]; int addr = I2C_SLAVE_ADDR_LIST[0];
char *data_input=0; char *data_input = 0;
getDigitalInputState( addr, &data_input); getDigitalInputState(addr, &data_input);
if ((*data_input) & (1UL << 2)){ if ((*data_input) & (1UL << 2))
if (data->value.type == &UA_TYPES[UA_TYPES_INT32]) { {
*(UA_Int32 *)data->value.data = 1; if (data->value.type == &UA_TYPES[UA_TYPES_BOOLEAN])
{
*(UA_Boolean *)data->value.data = true;
}
} }
} else { else
if (data->value.type == &UA_TYPES[UA_TYPES_INT32]) { {
*(UA_Int32 *)data->value.data = 0; if (data->value.type == &UA_TYPES[UA_TYPES_BOOLEAN])
{
*(UA_Boolean *)data->value.data = false;
} }
} }
} }
...@@ -403,17 +465,23 @@ static void beforeReadTimeI2C1In2(UA_Server *server, ...@@ -403,17 +465,23 @@ static void beforeReadTimeI2C1In2(UA_Server *server,
static void beforeReadTimeI2C1In3(UA_Server *server, static void beforeReadTimeI2C1In3(UA_Server *server,
const UA_NodeId *sessionId, void *sessionContext, const UA_NodeId *sessionId, void *sessionContext,
const UA_NodeId *nodeid, void *nodeContext, const UA_NodeId *nodeid, void *nodeContext,
const UA_NumericRange *range, const UA_DataValue *data) { const UA_NumericRange *range, const UA_DataValue *data)
{
int addr = I2C_SLAVE_ADDR_LIST[0]; int addr = I2C_SLAVE_ADDR_LIST[0];
char *data_input=0; char *data_input = 0;
getDigitalInputState( addr, &data_input); getDigitalInputState(addr, &data_input);
if ((*data_input) & (1UL << 3)){ if ((*data_input) & (1UL << 3))
if (data->value.type == &UA_TYPES[UA_TYPES_INT32]) { {
*(UA_Int32 *)data->value.data = 1; if (data->value.type == &UA_TYPES[UA_TYPES_BOOLEAN])
{
*(UA_Boolean *)data->value.data = true;
}
} }
} else { else
if (data->value.type == &UA_TYPES[UA_TYPES_INT32]) { {
*(UA_Int32 *)data->value.data = 0; if (data->value.type == &UA_TYPES[UA_TYPES_BOOLEAN])
{
*(UA_Boolean *)data->value.data = false;
} }
} }
} }
...@@ -421,7 +489,8 @@ static void beforeReadTimeI2C1In3(UA_Server *server, ...@@ -421,7 +489,8 @@ static void beforeReadTimeI2C1In3(UA_Server *server,
static void afterWriteTime(UA_Server *server, static void afterWriteTime(UA_Server *server,
const UA_NodeId *sessionId, void *sessionContext, const UA_NodeId *sessionId, void *sessionContext,
const UA_NodeId *nodeId, void *nodeContext, const UA_NodeId *nodeId, void *nodeContext,
const UA_NumericRange *range, const UA_DataValue *data) { const UA_NumericRange *range, const UA_DataValue *data)
{
// nothing to do as not yet needed. // nothing to do as not yet needed.
} }
...@@ -430,15 +499,19 @@ static void afterWriteTime(UA_Server *server, ...@@ -430,15 +499,19 @@ static void afterWriteTime(UA_Server *server,
static void afterWriteTimeI2C0_0(UA_Server *server, static void afterWriteTimeI2C0_0(UA_Server *server,
const UA_NodeId *sessionId, void *sessionContext, const UA_NodeId *sessionId, void *sessionContext,
const UA_NodeId *nodeId, void *nodeContext, const UA_NodeId *nodeId, void *nodeContext,
const UA_NumericRange *range, const UA_DataValue *data) { const UA_NumericRange *range, const UA_DataValue *data)
if (data->value.type == &UA_TYPES[UA_TYPES_INT32]) { {
if (data->value.type == &UA_TYPES[UA_TYPES_INT32])
{
UA_Int32 hrValue = *(UA_Int32 *)data->value.data; UA_Int32 hrValue = *(UA_Int32 *)data->value.data;
int addr = I2C_SLAVE_ADDR_LIST[0]; int addr = I2C_SLAVE_ADDR_LIST[0];
if (hrValue > 0){ if (hrValue > 0)
{
I2C_0_RELAYS_STATE |= 1UL << 0; I2C_0_RELAYS_STATE |= 1UL << 0;
setRelayState(I2C_0_RELAYS_STATE, addr); setRelayState(I2C_0_RELAYS_STATE, addr);
} }
else { else
{
I2C_0_RELAYS_STATE &= ~(1UL << 0); I2C_0_RELAYS_STATE &= ~(1UL << 0);
setRelayState(I2C_0_RELAYS_STATE, addr); setRelayState(I2C_0_RELAYS_STATE, addr);
} }
...@@ -448,15 +521,19 @@ static void afterWriteTimeI2C0_0(UA_Server *server, ...@@ -448,15 +521,19 @@ static void afterWriteTimeI2C0_0(UA_Server *server,
static void afterWriteTimeI2C0_1(UA_Server *server, static void afterWriteTimeI2C0_1(UA_Server *server,
const UA_NodeId *sessionId, void *sessionContext, const UA_NodeId *sessionId, void *sessionContext,
const UA_NodeId *nodeId, void *nodeContext, const UA_NodeId *nodeId, void *nodeContext,
const UA_NumericRange *range, const UA_DataValue *data) { const UA_NumericRange *range, const UA_DataValue *data)
if (data->value.type == &UA_TYPES[UA_TYPES_INT32]) { {
if (data->value.type == &UA_TYPES[UA_TYPES_INT32])
{
UA_Int32 hrValue = *(UA_Int32 *)data->value.data; UA_Int32 hrValue = *(UA_Int32 *)data->value.data;
int addr = I2C_SLAVE_ADDR_LIST[0]; int addr = I2C_SLAVE_ADDR_LIST[0];
if (hrValue > 0){ if (hrValue > 0)
{
I2C_0_RELAYS_STATE |= 1UL << 1; I2C_0_RELAYS_STATE |= 1UL << 1;
setRelayState(I2C_0_RELAYS_STATE, addr); setRelayState(I2C_0_RELAYS_STATE, addr);
} }
else { else
{
I2C_0_RELAYS_STATE &= ~(1UL << 1); I2C_0_RELAYS_STATE &= ~(1UL << 1);
setRelayState(I2C_0_RELAYS_STATE, addr); setRelayState(I2C_0_RELAYS_STATE, addr);
} }
...@@ -466,15 +543,19 @@ static void afterWriteTimeI2C0_1(UA_Server *server, ...@@ -466,15 +543,19 @@ static void afterWriteTimeI2C0_1(UA_Server *server,
static void afterWriteTimeI2C0_2(UA_Server *server, static void afterWriteTimeI2C0_2(UA_Server *server,
const UA_NodeId *sessionId, void *sessionContext, const UA_NodeId *sessionId, void *sessionContext,
const UA_NodeId *nodeId, void *nodeContext, const UA_NodeId *nodeId, void *nodeContext,
const UA_NumericRange *range, const UA_DataValue *data) { const UA_NumericRange *range, const UA_DataValue *data)
if (data->value.type == &UA_TYPES[UA_TYPES_INT32]) { {
if (data->value.type == &UA_TYPES[UA_TYPES_INT32])
{
UA_Int32 hrValue = *(UA_Int32 *)data->value.data; UA_Int32 hrValue = *(UA_Int32 *)data->value.data;
int addr = I2C_SLAVE_ADDR_LIST[0]; int addr = I2C_SLAVE_ADDR_LIST[0];
if (hrValue > 0){ if (hrValue > 0)
{
I2C_0_RELAYS_STATE |= 1UL << 2; I2C_0_RELAYS_STATE |= 1UL << 2;
setRelayState(I2C_0_RELAYS_STATE, addr); setRelayState(I2C_0_RELAYS_STATE, addr);
} }
else { else
{
I2C_0_RELAYS_STATE &= ~(1UL << 2); I2C_0_RELAYS_STATE &= ~(1UL << 2);
setRelayState(I2C_0_RELAYS_STATE, addr); setRelayState(I2C_0_RELAYS_STATE, addr);
} }
...@@ -484,35 +565,42 @@ static void afterWriteTimeI2C0_2(UA_Server *server, ...@@ -484,35 +565,42 @@ static void afterWriteTimeI2C0_2(UA_Server *server,
static void afterWriteTimeI2C0_3(UA_Server *server, static void afterWriteTimeI2C0_3(UA_Server *server,
const UA_NodeId *sessionId, void *sessionContext, const UA_NodeId *sessionId, void *sessionContext,
const UA_NodeId *nodeId, void *nodeContext, const UA_NodeId *nodeId, void *nodeContext,
const UA_NumericRange *range, const UA_DataValue *data) { const UA_NumericRange *range, const UA_DataValue *data)
if (data->value.type == &UA_TYPES[UA_TYPES_INT32]) { {
if (data->value.type == &UA_TYPES[UA_TYPES_INT32])
{
UA_Int32 hrValue = *(UA_Int32 *)data->value.data; UA_Int32 hrValue = *(UA_Int32 *)data->value.data;
int addr = I2C_SLAVE_ADDR_LIST[0]; int addr = I2C_SLAVE_ADDR_LIST[0];
if (hrValue > 0){ if (hrValue > 0)
{
I2C_0_RELAYS_STATE |= 1UL << 3; I2C_0_RELAYS_STATE |= 1UL << 3;
setRelayState(I2C_0_RELAYS_STATE, addr); setRelayState(I2C_0_RELAYS_STATE, addr);
} }
else { else
{
I2C_0_RELAYS_STATE &= ~(1UL << 3); I2C_0_RELAYS_STATE &= ~(1UL << 3);
setRelayState(I2C_0_RELAYS_STATE, addr); setRelayState(I2C_0_RELAYS_STATE, addr);
} }
} }
} }
// I2C1 // I2C1
static void afterWriteTimeI2C1_0(UA_Server *server, static void afterWriteTimeI2C1_0(UA_Server *server,
const UA_NodeId *sessionId, void *sessionContext, const UA_NodeId *sessionId, void *sessionContext,
const UA_NodeId *nodeId, void *nodeContext, const UA_NodeId *nodeId, void *nodeContext,
const UA_NumericRange *range, const UA_DataValue *data) { const UA_NumericRange *range, const UA_DataValue *data)
if (data->value.type == &UA_TYPES[UA_TYPES_INT32]) { {
if (data->value.type == &UA_TYPES[UA_TYPES_INT32])
{
UA_Int32 hrValue = *(UA_Int32 *)data->value.data; UA_Int32 hrValue = *(UA_Int32 *)data->value.data;
int addr = I2C_SLAVE_ADDR_LIST[1]; int addr = I2C_SLAVE_ADDR_LIST[1];
if (hrValue > 0){ if (hrValue > 0)
{
I2C_1_RELAYS_STATE |= 1UL << 0; I2C_1_RELAYS_STATE |= 1UL << 0;
setRelayState(I2C_1_RELAYS_STATE, addr); setRelayState(I2C_1_RELAYS_STATE, addr);
} }
else { else
{
I2C_1_RELAYS_STATE &= ~(1UL << 0); I2C_1_RELAYS_STATE &= ~(1UL << 0);
setRelayState(I2C_1_RELAYS_STATE, addr); setRelayState(I2C_1_RELAYS_STATE, addr);
} }
...@@ -522,15 +610,19 @@ static void afterWriteTimeI2C1_0(UA_Server *server, ...@@ -522,15 +610,19 @@ static void afterWriteTimeI2C1_0(UA_Server *server,
static void afterWriteTimeI2C1_1(UA_Server *server, static void afterWriteTimeI2C1_1(UA_Server *server,
const UA_NodeId *sessionId, void *sessionContext, const UA_NodeId *sessionId, void *sessionContext,
const UA_NodeId *nodeId, void *nodeContext, const UA_NodeId *nodeId, void *nodeContext,
const UA_NumericRange *range, const UA_DataValue *data) { const UA_NumericRange *range, const UA_DataValue *data)
if (data->value.type == &UA_TYPES[UA_TYPES_INT32]) { {
if (data->value.type == &UA_TYPES[UA_TYPES_INT32])
{
UA_Int32 hrValue = *(UA_Int32 *)data->value.data; UA_Int32 hrValue = *(UA_Int32 *)data->value.data;
int addr = I2C_SLAVE_ADDR_LIST[1]; int addr = I2C_SLAVE_ADDR_LIST[1];
if (hrValue > 0){ if (hrValue > 0)
{
I2C_1_RELAYS_STATE |= 1UL << 1; I2C_1_RELAYS_STATE |= 1UL << 1;
setRelayState(I2C_1_RELAYS_STATE, addr); setRelayState(I2C_1_RELAYS_STATE, addr);
} }
else { else
{
I2C_1_RELAYS_STATE &= ~(1UL << 1); I2C_1_RELAYS_STATE &= ~(1UL << 1);
setRelayState(I2C_1_RELAYS_STATE, addr); setRelayState(I2C_1_RELAYS_STATE, addr);
} }
...@@ -540,15 +632,19 @@ static void afterWriteTimeI2C1_1(UA_Server *server, ...@@ -540,15 +632,19 @@ static void afterWriteTimeI2C1_1(UA_Server *server,
static void afterWriteTimeI2C1_2(UA_Server *server, static void afterWriteTimeI2C1_2(UA_Server *server,
const UA_NodeId *sessionId, void *sessionContext, const UA_NodeId *sessionId, void *sessionContext,
const UA_NodeId *nodeId, void *nodeContext, const UA_NodeId *nodeId, void *nodeContext,
const UA_NumericRange *range, const UA_DataValue *data) { const UA_NumericRange *range, const UA_DataValue *data)
if (data->value.type == &UA_TYPES[UA_TYPES_INT32]) { {
if (data->value.type == &UA_TYPES[UA_TYPES_INT32])
{
UA_Int32 hrValue = *(UA_Int32 *)data->value.data; UA_Int32 hrValue = *(UA_Int32 *)data->value.data;
int addr = I2C_SLAVE_ADDR_LIST[1]; int addr = I2C_SLAVE_ADDR_LIST[1];
if (hrValue > 0){ if (hrValue > 0)
{
I2C_1_RELAYS_STATE |= 1UL << 2; I2C_1_RELAYS_STATE |= 1UL << 2;
setRelayState(I2C_1_RELAYS_STATE, addr); setRelayState(I2C_1_RELAYS_STATE, addr);
} }
else { else
{
I2C_1_RELAYS_STATE &= ~(1UL << 2); I2C_1_RELAYS_STATE &= ~(1UL << 2);
setRelayState(I2C_1_RELAYS_STATE, addr); setRelayState(I2C_1_RELAYS_STATE, addr);
} }
...@@ -558,49 +654,53 @@ static void afterWriteTimeI2C1_2(UA_Server *server, ...@@ -558,49 +654,53 @@ static void afterWriteTimeI2C1_2(UA_Server *server,
static void afterWriteTimeI2C1_3(UA_Server *server, static void afterWriteTimeI2C1_3(UA_Server *server,
const UA_NodeId *sessionId, void *sessionContext, const UA_NodeId *sessionId, void *sessionContext,
const UA_NodeId *nodeId, void *nodeContext, const UA_NodeId *nodeId, void *nodeContext,
const UA_NumericRange *range, const UA_DataValue *data) { const UA_NumericRange *range, const UA_DataValue *data)
if (data->value.type == &UA_TYPES[UA_TYPES_INT32]) { {
if (data->value.type == &UA_TYPES[UA_TYPES_INT32])
{
UA_Int32 hrValue = *(UA_Int32 *)data->value.data; UA_Int32 hrValue = *(UA_Int32 *)data->value.data;
int addr = I2C_SLAVE_ADDR_LIST[1]; int addr = I2C_SLAVE_ADDR_LIST[1];
if (hrValue > 0){ if (hrValue > 0)
{
I2C_1_RELAYS_STATE |= 1UL << 3; I2C_1_RELAYS_STATE |= 1UL << 3;
setRelayState(I2C_1_RELAYS_STATE, addr); setRelayState(I2C_1_RELAYS_STATE, addr);
} }
else { else
{
I2C_1_RELAYS_STATE &= ~(1UL << 3); I2C_1_RELAYS_STATE &= ~(1UL << 3);
setRelayState(I2C_1_RELAYS_STATE, addr); setRelayState(I2C_1_RELAYS_STATE, addr);
} }
} }
} }
static void addValueCallbackToCurrentTimeVariable(UA_Server *server)
static void addValueCallbackToCurrentTimeVariable(UA_Server *server) { {
int length = getI2CSlaveListLength(); 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");
UA_ValueCallback callback0 ; UA_ValueCallback callback0;
callback0.onRead = beforeReadTime; callback0.onRead = beforeReadTime;
callback0.onWrite = afterWriteTimeI2C0_0; callback0.onWrite = afterWriteTimeI2C0_0;
UA_Server_setVariableNode_valueCallback(server, currentNodeId0, callback0); UA_Server_setVariableNode_valueCallback(server, currentNodeId0, callback0);
// relay 1 // relay 1
UA_NodeId currentNodeId1 = UA_NODEID_STRING(1, "i2c0.relay1"); UA_NodeId currentNodeId1 = UA_NODEID_STRING(1, "i2c0.relay1");
UA_ValueCallback callback1 ; UA_ValueCallback callback1;
callback1.onRead = beforeReadTime; callback1.onRead = beforeReadTime;
callback1.onWrite = afterWriteTimeI2C0_1; callback1.onWrite = afterWriteTimeI2C0_1;
UA_Server_setVariableNode_valueCallback(server, currentNodeId1, callback1); UA_Server_setVariableNode_valueCallback(server, currentNodeId1, callback1);
// relay 2 // relay 2
UA_NodeId currentNodeId2 = UA_NODEID_STRING(1, "i2c0.relay2"); UA_NodeId currentNodeId2 = UA_NODEID_STRING(1, "i2c0.relay2");
UA_ValueCallback callback2 ; UA_ValueCallback callback2;
callback2.onRead = beforeReadTime; callback2.onRead = beforeReadTime;
callback2.onWrite = afterWriteTimeI2C0_2; callback2.onWrite = afterWriteTimeI2C0_2;
UA_Server_setVariableNode_valueCallback(server, currentNodeId2, callback2); UA_Server_setVariableNode_valueCallback(server, currentNodeId2, callback2);
// relay 3 // relay 3
UA_NodeId currentNodeId3 = UA_NODEID_STRING(1, "i2c0.relay3"); UA_NodeId currentNodeId3 = UA_NODEID_STRING(1, "i2c0.relay3");
UA_ValueCallback callback3 ; UA_ValueCallback callback3;
callback3.onRead = beforeReadTime; callback3.onRead = beforeReadTime;
callback3.onWrite = afterWriteTimeI2C0_3; callback3.onWrite = afterWriteTimeI2C0_3;
UA_Server_setVariableNode_valueCallback(server, currentNodeId3, callback3); UA_Server_setVariableNode_valueCallback(server, currentNodeId3, callback3);
...@@ -633,7 +733,8 @@ static void addValueCallbackToCurrentTimeVariable(UA_Server *server) { ...@@ -633,7 +733,8 @@ static void addValueCallbackToCurrentTimeVariable(UA_Server *server) {
callback7.onWrite = afterWriteTime; callback7.onWrite = afterWriteTime;
UA_Server_setVariableNode_valueCallback(server, currentNodeId7, callback7); UA_Server_setVariableNode_valueCallback(server, currentNodeId7, callback7);
if(length > 1){ if (length > 1)
{
// I2C1 // I2C1
// relay 0 // relay 0
UA_NodeId currentNodeId8 = UA_NODEID_STRING(1, "i2c1.relay0"); UA_NodeId currentNodeId8 = UA_NODEID_STRING(1, "i2c1.relay0");
...@@ -691,10 +792,10 @@ static void addValueCallbackToCurrentTimeVariable(UA_Server *server) { ...@@ -691,10 +792,10 @@ static void addValueCallbackToCurrentTimeVariable(UA_Server *server) {
callback15.onWrite = afterWriteTime; callback15.onWrite = afterWriteTime;
UA_Server_setVariableNode_valueCallback(server, currentNodeId15, callback15); UA_Server_setVariableNode_valueCallback(server, currentNodeId15, callback15);
} }
} }
void safeShutdownI2CSlaveList() { void safeShutdownI2CSlaveList()
{
/* /*
* Perform a safe shutdown of all known I2C slaves * Perform a safe shutdown of all known I2C slaves
*/ */
...@@ -703,10 +804,11 @@ void safeShutdownI2CSlaveList() { ...@@ -703,10 +804,11 @@ void safeShutdownI2CSlaveList() {
int addr; int addr;
length = sizeof(I2C_SLAVE_ADDR_LIST) / sizeof(int); length = sizeof(I2C_SLAVE_ADDR_LIST) / sizeof(int);
for(i = 0; i < length; i++) for (i = 0; i < length; i++)
{ {
addr = I2C_SLAVE_ADDR_LIST[i]; addr = I2C_SLAVE_ADDR_LIST[i];
if (addr!= 0) { if (addr != 0)
{
// properly initialized from CLI // properly initialized from CLI
setRelayState(0x00, addr); setRelayState(0x00, addr);
} }
...@@ -715,12 +817,14 @@ void safeShutdownI2CSlaveList() { ...@@ -715,12 +817,14 @@ void safeShutdownI2CSlaveList() {
static volatile UA_Boolean running = true; static volatile UA_Boolean running = true;
static void stopHandler(int sign) { static void stopHandler(int sign)
{
UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "received ctrl-c"); UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "received ctrl-c");
running = false; running = false;
} }
int main(int argc, char **argv) { int main(int argc, char **argv)
{
int i; int i;
int length; int length;
long result; long result;
...@@ -750,7 +854,7 @@ int main(int argc, char **argv) { ...@@ -750,7 +854,7 @@ int main(int argc, char **argv) {
// from CLI we get a hexidecimal string as a char (0x58 for example), convert to decimal // from CLI we get a hexidecimal string as a char (0x58 for example), convert to decimal
result = strtol(token, &eptr, 16); result = strtol(token, &eptr, 16);
I2C_SLAVE_ADDR_LIST[i++] = result; I2C_SLAVE_ADDR_LIST[i++] = result;
token = strtok (NULL, ","); token = strtok(NULL, ",");
} }
// always start attached slaves from a know safe shutdown state // always start attached slaves from a know safe shutdown state
...@@ -761,7 +865,7 @@ int main(int argc, char **argv) { ...@@ -761,7 +865,7 @@ int main(int argc, char **argv) {
UA_Server *server = UA_Server_new(); UA_Server *server = UA_Server_new();
UA_ServerConfig_setMinimal(UA_Server_getConfig(server), arguments.port, NULL); UA_ServerConfig_setMinimal(UA_Server_getConfig(server), arguments.port, NULL);
UA_ServerConfig* config = UA_Server_getConfig(server); UA_ServerConfig *config = UA_Server_getConfig(server);
config->verifyRequestTimestamp = UA_RULEHANDLING_ACCEPT; config->verifyRequestTimestamp = UA_RULEHANDLING_ACCEPT;
addVariable(server); addVariable(server);
......
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