Commit 8eb23358 authored by Ivan Tyagov's avatar Ivan Tyagov

Allow to run OPC_Ua serer in a virtual mode without real read / writes over...

Allow to run OPC_Ua serer in a virtual mode without real read / writes over I2C to MOD-IOs. Usefull for pure testing on x86 platform where I2C support is missing or simple not needed.
parent 1c700ff8
...@@ -30,12 +30,20 @@ int I2C_SLAVE_ADDR_LIST[] = {0, 0, 0, 0, 0}; // XXX: make dynamic array ...@@ -30,12 +30,20 @@ int I2C_SLAVE_ADDR_LIST[] = {0, 0, 0, 0, 0}; // XXX: make dynamic array
static char *DEFAULT_I2C_BLOCK_DEVICE_NAME = "/dev/i2c-1"; static char *DEFAULT_I2C_BLOCK_DEVICE_NAME = "/dev/i2c-1";
char *I2C_BLOCK_DEVICE_NAME; char *I2C_BLOCK_DEVICE_NAME;
// global virtual mode needed for testing on x86 platform
bool I2C_VIRTUAL_MODE = 0;
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){
// we're in a virtual mode, likely on x86 platform or without I2C support
// simply do nothing
return 0;
}
// step 1: open device // step 1: open device
file = open(I2C_BLOCK_DEVICE_NAME, O_RDWR); file = open(I2C_BLOCK_DEVICE_NAME, O_RDWR);
...@@ -357,6 +365,13 @@ int main(int argc, char **argv) { ...@@ -357,6 +365,13 @@ int main(int argc, char **argv) {
long result; long result;
char *eptr; char *eptr;
// read environment to see if we run daemon in real or virtual mode (usable for testing on x86)
const char* s = getenv("I2C_VIRTUAL_MODE");
if(s!=NULL){
I2C_VIRTUAL_MODE = atoi(s);
}
printf("I2C_VIRTUAL_MODE=%d\n", I2C_VIRTUAL_MODE);
// handle comand line arguments // handle comand line arguments
if (argc == 1) { if (argc == 1) {
// no paramaters at all // no paramaters at all
......
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