Commit ecec87a5 authored by Ivan Tyagov's avatar Ivan Tyagov

In virtual mode we can NOT read digital / analog IN at all. Thus prevent...

In virtual mode we can NOT read digital / analog IN at all. Thus prevent segfault from reading from uninitialized address.
parent 1137aec8
......@@ -414,11 +414,13 @@ static void beforeReadTimeI2C0Ain0(UA_Server *server,
int addr = I2C_SLAVE_ADDR_LIST[0];
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 beforeReadTimeI2C0Ain1(UA_Server *server,
......@@ -429,11 +431,13 @@ static void beforeReadTimeI2C0Ain1(UA_Server *server,
int addr = I2C_SLAVE_ADDR_LIST[0];
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,
......@@ -444,11 +448,13 @@ static void beforeReadTimeI2C0Ain2(UA_Server *server,
int addr = I2C_SLAVE_ADDR_LIST[0];
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,
......@@ -459,11 +465,13 @@ static void beforeReadTimeI2C0Ain3(UA_Server *server,
int addr = I2C_SLAVE_ADDR_LIST[0];
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,
const UA_NodeId *sessionId, void *sessionContext,
......@@ -473,11 +481,13 @@ static void beforeReadTimeI2C1Ain0(UA_Server *server,
int addr = I2C_SLAVE_ADDR_LIST[1];
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,
......@@ -488,11 +498,13 @@ static void beforeReadTimeI2C1Ain1(UA_Server *server,
int addr = I2C_SLAVE_ADDR_LIST[1];
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,
......@@ -503,11 +515,13 @@ static void beforeReadTimeI2C1Ain2(UA_Server *server,
int addr = I2C_SLAVE_ADDR_LIST[1];
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,
......@@ -518,12 +532,15 @@ static void beforeReadTimeI2C1Ain3(UA_Server *server,
int addr = I2C_SLAVE_ADDR_LIST[1];
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,
const UA_NodeId *sessionId, void *sessionContext,
const UA_NodeId *nodeid, void *nodeContext,
......@@ -531,6 +548,7 @@ static void beforeReadTimeI2C0In0(UA_Server *server,
{
int addr = I2C_SLAVE_ADDR_LIST[0];
char *data_input = 0;
if (!I2C_VIRTUAL_MODE) {
getDigitalInputState(addr, &data_input);
if ((*data_input) & (1UL << 0))
{
......@@ -546,6 +564,7 @@ static void beforeReadTimeI2C0In0(UA_Server *server,
*(UA_Boolean *)data->value.data = false;
}
}
}
}
static void beforeReadTimeI2C0In1(UA_Server *server,
......@@ -555,6 +574,7 @@ static void beforeReadTimeI2C0In1(UA_Server *server,
{
int addr = I2C_SLAVE_ADDR_LIST[0];
char *data_input = 0;
if (!I2C_VIRTUAL_MODE) {
getDigitalInputState(addr, &data_input);
if ((*data_input) & (1UL << 1))
{
......@@ -570,6 +590,7 @@ static void beforeReadTimeI2C0In1(UA_Server *server,
*(UA_Boolean *)data->value.data = false;
}
}
}
}
static void beforeReadTimeI2C0In2(UA_Server *server,
......@@ -579,6 +600,7 @@ static void beforeReadTimeI2C0In2(UA_Server *server,
{
int addr = I2C_SLAVE_ADDR_LIST[0];
char *data_input = 0;
if (!I2C_VIRTUAL_MODE) {
getDigitalInputState(addr, &data_input);
if ((*data_input) & (1UL << 2))
{
......@@ -594,6 +616,7 @@ static void beforeReadTimeI2C0In2(UA_Server *server,
*(UA_Boolean *)data->value.data = false;
}
}
}
}
static void beforeReadTimeI2C0In3(UA_Server *server,
......@@ -603,6 +626,7 @@ static void beforeReadTimeI2C0In3(UA_Server *server,
{
int addr = I2C_SLAVE_ADDR_LIST[0];
char *data_input = 0;
if (!I2C_VIRTUAL_MODE) {
getDigitalInputState(addr, &data_input);
if ((*data_input) & (1UL << 3))
{
......@@ -618,6 +642,7 @@ static void beforeReadTimeI2C0In3(UA_Server *server,
*(UA_Boolean *)data->value.data = false;
}
}
}
}
static void beforeReadTimeI2C1In0(UA_Server *server,
const UA_NodeId *sessionId, void *sessionContext,
......@@ -626,6 +651,7 @@ static void beforeReadTimeI2C1In0(UA_Server *server,
{
int addr = I2C_SLAVE_ADDR_LIST[1];
char *data_input = 0;
if (!I2C_VIRTUAL_MODE) {
getDigitalInputState(addr, &data_input);
if ((*data_input) & (1UL << 0))
{
......@@ -641,6 +667,7 @@ static void beforeReadTimeI2C1In0(UA_Server *server,
*(UA_Boolean *)data->value.data = false;
}
}
}
}
static void beforeReadTimeI2C1In1(UA_Server *server,
......@@ -650,6 +677,7 @@ static void beforeReadTimeI2C1In1(UA_Server *server,
{
int addr = I2C_SLAVE_ADDR_LIST[1];
char *data_input = 0;
if (!I2C_VIRTUAL_MODE) {
getDigitalInputState(addr, &data_input);
if ((*data_input) & (1UL << 1))
{
......@@ -665,6 +693,7 @@ static void beforeReadTimeI2C1In1(UA_Server *server,
*(UA_Boolean *)data->value.data = false;
}
}
}
}
static void beforeReadTimeI2C1In2(UA_Server *server,
......@@ -674,6 +703,7 @@ static void beforeReadTimeI2C1In2(UA_Server *server,
{
int addr = I2C_SLAVE_ADDR_LIST[1];
char *data_input = 0;
if (!I2C_VIRTUAL_MODE) {
getDigitalInputState(addr, &data_input);
if ((*data_input) & (1UL << 2))
{
......@@ -689,6 +719,7 @@ static void beforeReadTimeI2C1In2(UA_Server *server,
*(UA_Boolean *)data->value.data = false;
}
}
}
}
static void beforeReadTimeI2C1In3(UA_Server *server,
......@@ -698,6 +729,7 @@ static void beforeReadTimeI2C1In3(UA_Server *server,
{
int addr = I2C_SLAVE_ADDR_LIST[1];
char *data_input = 0;
if (!I2C_VIRTUAL_MODE) {
getDigitalInputState(addr, &data_input);
if ((*data_input) & (1UL << 3))
{
......@@ -713,6 +745,7 @@ static void beforeReadTimeI2C1In3(UA_Server *server,
*(UA_Boolean *)data->value.data = false;
}
}
}
}
static void afterWriteTime(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