Commit 6db7a93e authored by Ivan Tyagov's avatar Ivan Tyagov

Handle properly CLI arguments.

parent d35cd949
...@@ -358,33 +358,36 @@ int main(int argc, char **argv) { ...@@ -358,33 +358,36 @@ int main(int argc, char **argv) {
char *eptr; char *eptr;
// handle comand line arguments // handle comand line arguments
if (argc >= 2) { if (argc == 1) {
// override default i2c block device from first cmd line argument // no paramaters at all
I2C_BLOCK_DEVICE_NAME = argv[1]; I2C_BLOCK_DEVICE_NAME = DEFAULT_I2C_BLOCK_DEVICE_NAME;
I2C_SLAVE_ADDR_LIST[0] = DEFAULT_I2C_0_ADDR;
// if nothing specified on CLI set a default one }
if (argc<= 2){ if (argc == 2) {
I2C_SLAVE_ADDR_LIST[0] = DEFAULT_I2C_0_ADDR; // only block device specified
printf("I2C_slave=0x%x\n", DEFAULT_I2C_0_ADDR); I2C_BLOCK_DEVICE_NAME = argv[1];
} I2C_SLAVE_ADDR_LIST[0] = DEFAULT_I2C_0_ADDR;
else { }
// override list of I2C slaves addresses from CLI if (argc > 2) {
for(i=2; i < argc; i++) // both block device and I2C slave(s) specified
{ I2C_BLOCK_DEVICE_NAME = argv[1];
// from CLI we get a hexidecimal string as a char (0x58 for example), convert to decimal for(i=2; i < argc; i++){
result = strtol(argv[i], &eptr, 16); // from CLI we get a hexidecimal string as a char (0x58 for example), convert to decimal
printf("I2C_slave=0x%lx\n", result); result = strtol(argv[i], &eptr, 16);
I2C_SLAVE_ADDR_LIST[i -2] = result; I2C_SLAVE_ADDR_LIST[i - 2] = result;
} }
}
}
else {
I2C_BLOCK_DEVICE_NAME = DEFAULT_I2C_BLOCK_DEVICE_NAME;
} }
// debug info
printf("Block device=%s\n", I2C_BLOCK_DEVICE_NAME); printf("Block device=%s\n", I2C_BLOCK_DEVICE_NAME);
length = sizeof(I2C_SLAVE_ADDR_LIST) / sizeof(int);
for(i=0; i < length; i++){
if (I2C_SLAVE_ADDR_LIST[i] !=0) {
printf("I2C_slave=0x%x\n", I2C_SLAVE_ADDR_LIST[i]);
}
}
// always start attached slaves from a know safe shutdown state // always start attached slaves from a know safe shutdown state
safeShutdownI2CSlaveList(); safeShutdownI2CSlaveList();
......
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