Commit a1745fca authored by Ivan Tyagov's avatar Ivan Tyagov

Factorize Analog In.

parent 2d6699e8
...@@ -99,15 +99,14 @@ static void beforeReadTime(UA_Server *server, ...@@ -99,15 +99,14 @@ static void beforeReadTime(UA_Server *server,
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 needed.
} }
static void beforeReadTimeI2C0Ain0(UA_Server *server,
const UA_NodeId *sessionId, void *sessionContext, static void beforeReadTimeAnalongIn(int addr,uint8_t read_addr, const UA_DataValue *data) {
const UA_NodeId *nodeid, void *nodeContext, /*
const UA_NumericRange *range, const UA_DataValue *data) * Generic handler for reading from physicall analong input.
{ */
int addr = I2C_SLAVE_ADDR_LIST[0];
int *data_input = 0; int *data_input = 0;
uint8_t read_addr =0x30;
if (!I2C_VIRTUAL_MODE) { if (!I2C_VIRTUAL_MODE) {
getAnalogInputStateAIN(addr, &data_input, read_addr); getAnalogInputStateAIN(addr, &data_input, read_addr);
if (data->value.type == &UA_TYPES[UA_TYPES_UINT32]) if (data->value.type == &UA_TYPES[UA_TYPES_UINT32])
...@@ -117,21 +116,20 @@ static void beforeReadTimeI2C0Ain0(UA_Server *server, ...@@ -117,21 +116,20 @@ static void beforeReadTimeI2C0Ain0(UA_Server *server,
} }
} }
static void beforeReadTimeI2C0Ain0(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], 0x30, data);
}
static void beforeReadTimeI2C0Ain1(UA_Server *server, static void beforeReadTimeI2C0Ain1(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]; beforeReadTimeAnalongIn(I2C_SLAVE_ADDR_LIST[0], 0x31, data);
int *data_input = 0;
uint8_t read_addr =0x31;
if (!I2C_VIRTUAL_MODE) {
getAnalogInputStateAIN(addr, &data_input, read_addr);
if (data->value.type == &UA_TYPES[UA_TYPES_UINT32])
{
*(UA_UInt32 *)data->value.data = *data_input;
}
}
} }
static void beforeReadTimeI2C0Ain2(UA_Server *server, static void beforeReadTimeI2C0Ain2(UA_Server *server,
...@@ -139,16 +137,7 @@ static void beforeReadTimeI2C0Ain2(UA_Server *server, ...@@ -139,16 +137,7 @@ static void beforeReadTimeI2C0Ain2(UA_Server *server,
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]; beforeReadTimeAnalongIn(I2C_SLAVE_ADDR_LIST[0], 0x32, data);
int *data_input = 0;
uint8_t read_addr =0x32;
if (!I2C_VIRTUAL_MODE) {
getAnalogInputStateAIN(addr, &data_input, read_addr);
if (data->value.type == &UA_TYPES[UA_TYPES_UINT32])
{
*(UA_UInt32 *)data->value.data = *data_input;
}
}
} }
static void beforeReadTimeI2C0Ain3(UA_Server *server, static void beforeReadTimeI2C0Ain3(UA_Server *server,
...@@ -156,32 +145,15 @@ static void beforeReadTimeI2C0Ain3(UA_Server *server, ...@@ -156,32 +145,15 @@ static void beforeReadTimeI2C0Ain3(UA_Server *server,
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]; beforeReadTimeAnalongIn(I2C_SLAVE_ADDR_LIST[0], 0x33, data);
int *data_input = 0;
uint8_t read_addr =0x33;
if (!I2C_VIRTUAL_MODE) {
getAnalogInputStateAIN(addr, &data_input, read_addr);
if (data->value.type == &UA_TYPES[UA_TYPES_UINT32])
{
*(UA_UInt32 *)data->value.data = *data_input;
}
}
} }
static void beforeReadTimeI2C1Ain0(UA_Server *server, static void beforeReadTimeI2C1Ain0(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[1]; beforeReadTimeAnalongIn(I2C_SLAVE_ADDR_LIST[1], 0x30, data);
int *data_input = 0;
uint8_t read_addr =0x30;
if (!I2C_VIRTUAL_MODE) {
getAnalogInputStateAIN(addr, &data_input, read_addr);
if (data->value.type == &UA_TYPES[UA_TYPES_UINT32])
{
*(UA_UInt32 *)data->value.data = *data_input;
}
}
} }
static void beforeReadTimeI2C1Ain1(UA_Server *server, static void beforeReadTimeI2C1Ain1(UA_Server *server,
...@@ -189,16 +161,7 @@ static void beforeReadTimeI2C1Ain1(UA_Server *server, ...@@ -189,16 +161,7 @@ static void beforeReadTimeI2C1Ain1(UA_Server *server,
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[1]; beforeReadTimeAnalongIn(I2C_SLAVE_ADDR_LIST[1], 0x31, data);
int *data_input = 0;
uint8_t read_addr =0x31;
if (!I2C_VIRTUAL_MODE) {
getAnalogInputStateAIN(addr, &data_input, read_addr);
if (data->value.type == &UA_TYPES[UA_TYPES_UINT32])
{
*(UA_UInt32 *)data->value.data = *data_input;
}
}
} }
static void beforeReadTimeI2C1Ain2(UA_Server *server, static void beforeReadTimeI2C1Ain2(UA_Server *server,
...@@ -206,16 +169,7 @@ static void beforeReadTimeI2C1Ain2(UA_Server *server, ...@@ -206,16 +169,7 @@ static void beforeReadTimeI2C1Ain2(UA_Server *server,
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[1]; beforeReadTimeAnalongIn(I2C_SLAVE_ADDR_LIST[1], 0x32, data);
int *data_input = 0;
uint8_t read_addr =0x32;
if (!I2C_VIRTUAL_MODE) {
getAnalogInputStateAIN(addr, &data_input, read_addr);
if (data->value.type == &UA_TYPES[UA_TYPES_UINT32])
{
*(UA_UInt32 *)data->value.data = *data_input;
}
}
} }
static void beforeReadTimeI2C1Ain3(UA_Server *server, static void beforeReadTimeI2C1Ain3(UA_Server *server,
...@@ -223,16 +177,7 @@ static void beforeReadTimeI2C1Ain3(UA_Server *server, ...@@ -223,16 +177,7 @@ static void beforeReadTimeI2C1Ain3(UA_Server *server,
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[1]; beforeReadTimeAnalongIn(I2C_SLAVE_ADDR_LIST[1], 0x33, data);
int *data_input = 0;
uint8_t read_addr =0x33;
if (!I2C_VIRTUAL_MODE) {
getAnalogInputStateAIN(addr, &data_input, read_addr);
if (data->value.type == &UA_TYPES[UA_TYPES_UINT32])
{
*(UA_UInt32 *)data->value.data = *data_input;
}
}
} }
static void beforeReadTimeI2C0In0(UA_Server *server, static void beforeReadTimeI2C0In0(UA_Server *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