Commit 85c14244 authored by Ivan Tyagov's avatar Ivan Tyagov

Factorize Digital In.

parent a1745fca
...@@ -102,6 +102,7 @@ static void beforeReadTime(UA_Server *server, ...@@ -102,6 +102,7 @@ static void beforeReadTime(UA_Server *server,
// nothing to do as not needed. // nothing to do as not needed.
} }
// Analong Inputs
static void beforeReadTimeAnalongIn(int addr,uint8_t read_addr, const UA_DataValue *data) { static void beforeReadTimeAnalongIn(int addr,uint8_t read_addr, const UA_DataValue *data) {
/* /*
* Generic handler for reading from physicall analong input. * Generic handler for reading from physicall analong input.
...@@ -180,16 +181,17 @@ static void beforeReadTimeI2C1Ain3(UA_Server *server, ...@@ -180,16 +181,17 @@ static void beforeReadTimeI2C1Ain3(UA_Server *server,
beforeReadTimeAnalongIn(I2C_SLAVE_ADDR_LIST[1], 0x33, data); beforeReadTimeAnalongIn(I2C_SLAVE_ADDR_LIST[1], 0x33, data);
} }
static void beforeReadTimeI2C0In0(UA_Server *server, // Digital Inputs
const UA_NodeId *sessionId, void *sessionContext, static void beforeReadTimeDigitalIn(int addr,
const UA_NodeId *nodeid, void *nodeContext, int input_number,
const UA_NumericRange *range, const UA_DataValue *data) const UA_DataValue *data){
{ /*
int addr = I2C_SLAVE_ADDR_LIST[0]; * Generic handler for reading and updating a Digital In.
*/
char *data_input = 0; char *data_input = 0;
if (!I2C_VIRTUAL_MODE) { if (!I2C_VIRTUAL_MODE) {
getDigitalInputState(addr, &data_input); getDigitalInputState(addr, &data_input);
if ((*data_input) & (1UL << 0)) if ((*data_input) & (1UL << input_number))
{ {
if (data->value.type == &UA_TYPES[UA_TYPES_BOOLEAN]) if (data->value.type == &UA_TYPES[UA_TYPES_BOOLEAN])
{ {
...@@ -206,30 +208,20 @@ static void beforeReadTimeI2C0In0(UA_Server *server, ...@@ -206,30 +208,20 @@ static void beforeReadTimeI2C0In0(UA_Server *server,
} }
} }
static void beforeReadTimeI2C0In0(UA_Server *server,
const UA_NodeId *sessionId, void *sessionContext,
const UA_NodeId *nodeid, void *nodeContext,
const UA_NumericRange *range, const UA_DataValue *data)
{
beforeReadTimeDigitalIn(I2C_SLAVE_ADDR_LIST[0], 0, data);
}
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]; beforeReadTimeDigitalIn(I2C_SLAVE_ADDR_LIST[0], 1, data);
char *data_input = 0;
if (!I2C_VIRTUAL_MODE) {
getDigitalInputState(addr, &data_input);
if ((*data_input) & (1UL << 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_BOOLEAN])
{
*(UA_Boolean *)data->value.data = false;
}
}
}
} }
static void beforeReadTimeI2C0In2(UA_Server *server, static void beforeReadTimeI2C0In2(UA_Server *server,
...@@ -237,25 +229,7 @@ static void beforeReadTimeI2C0In2(UA_Server *server, ...@@ -237,25 +229,7 @@ static void beforeReadTimeI2C0In2(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]; beforeReadTimeDigitalIn(I2C_SLAVE_ADDR_LIST[0], 2, data);
char *data_input = 0;
if (!I2C_VIRTUAL_MODE) {
getDigitalInputState(addr, &data_input);
if ((*data_input) & (1UL << 2))
{
if (data->value.type == &UA_TYPES[UA_TYPES_BOOLEAN])
{
*(UA_Boolean *)data->value.data = true;
}
}
else
{
if (data->value.type == &UA_TYPES[UA_TYPES_BOOLEAN])
{
*(UA_Boolean *)data->value.data = false;
}
}
}
} }
static void beforeReadTimeI2C0In3(UA_Server *server, static void beforeReadTimeI2C0In3(UA_Server *server,
...@@ -263,50 +237,16 @@ static void beforeReadTimeI2C0In3(UA_Server *server, ...@@ -263,50 +237,16 @@ static void beforeReadTimeI2C0In3(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]; beforeReadTimeDigitalIn(I2C_SLAVE_ADDR_LIST[0], 3, data);
char *data_input = 0;
if (!I2C_VIRTUAL_MODE) {
getDigitalInputState(addr, &data_input);
if ((*data_input) & (1UL << 3))
{
if (data->value.type == &UA_TYPES[UA_TYPES_BOOLEAN])
{
*(UA_Boolean *)data->value.data = true;
}
}
else
{
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[1]; beforeReadTimeDigitalIn(I2C_SLAVE_ADDR_LIST[1], 0, data);
char *data_input = 0;
if (!I2C_VIRTUAL_MODE) {
getDigitalInputState(addr, &data_input);
if ((*data_input) & (1UL << 0))
{
if (data->value.type == &UA_TYPES[UA_TYPES_BOOLEAN])
{
*(UA_Boolean *)data->value.data = true;
}
}
else
{
if (data->value.type == &UA_TYPES[UA_TYPES_BOOLEAN])
{
*(UA_Boolean *)data->value.data = false;
}
}
}
} }
static void beforeReadTimeI2C1In1(UA_Server *server, static void beforeReadTimeI2C1In1(UA_Server *server,
...@@ -314,25 +254,7 @@ static void beforeReadTimeI2C1In1(UA_Server *server, ...@@ -314,25 +254,7 @@ static void beforeReadTimeI2C1In1(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]; beforeReadTimeDigitalIn(I2C_SLAVE_ADDR_LIST[1], 1, data);
char *data_input = 0;
if (!I2C_VIRTUAL_MODE) {
getDigitalInputState(addr, &data_input);
if ((*data_input) & (1UL << 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_BOOLEAN])
{
*(UA_Boolean *)data->value.data = false;
}
}
}
} }
static void beforeReadTimeI2C1In2(UA_Server *server, static void beforeReadTimeI2C1In2(UA_Server *server,
...@@ -340,25 +262,7 @@ static void beforeReadTimeI2C1In2(UA_Server *server, ...@@ -340,25 +262,7 @@ static void beforeReadTimeI2C1In2(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]; beforeReadTimeDigitalIn(I2C_SLAVE_ADDR_LIST[1], 2, data);
char *data_input = 0;
if (!I2C_VIRTUAL_MODE) {
getDigitalInputState(addr, &data_input);
if ((*data_input) & (1UL << 2))
{
if (data->value.type == &UA_TYPES[UA_TYPES_BOOLEAN])
{
*(UA_Boolean *)data->value.data = true;
}
}
else
{
if (data->value.type == &UA_TYPES[UA_TYPES_BOOLEAN])
{
*(UA_Boolean *)data->value.data = false;
}
}
}
} }
static void beforeReadTimeI2C1In3(UA_Server *server, static void beforeReadTimeI2C1In3(UA_Server *server,
...@@ -366,27 +270,10 @@ static void beforeReadTimeI2C1In3(UA_Server *server, ...@@ -366,27 +270,10 @@ static void beforeReadTimeI2C1In3(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]; beforeReadTimeDigitalIn(I2C_SLAVE_ADDR_LIST[1], 3, data);
char *data_input = 0;
if (!I2C_VIRTUAL_MODE) {
getDigitalInputState(addr, &data_input);
if ((*data_input) & (1UL << 3))
{
if (data->value.type == &UA_TYPES[UA_TYPES_BOOLEAN])
{
*(UA_Boolean *)data->value.data = true;
}
}
else
{
if (data->value.type == &UA_TYPES[UA_TYPES_BOOLEAN])
{
*(UA_Boolean *)data->value.data = false;
}
}
}
} }
// Relays
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,
......
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