Commit 4ac38223 authored by Ivan Tyagov's avatar Ivan Tyagov

Each coupler is now identified by a 12 bytest long UUID.

parent e9c18213
...@@ -26,12 +26,31 @@ ...@@ -26,12 +26,31 @@
#include "common.h" #include "common.h"
#include "mod_io_i2c.h" #include "mod_io_i2c.h"
#include "mod_io_opc_ua.h" #include "mod_io_opc_ua.h"
#include <time.h>
// The default port of OPC-UA server // The default port of OPC-UA server
const int DEFAULT_OPC_UA_PORT = 4840; const int DEFAULT_OPC_UA_PORT = 4840;
const int DEFAULT_MODE = 0; const int DEFAULT_MODE = 0;
char *randomString(size_t length)
{
static char charset[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
char *randomString = NULL;
if (length) {
randomString = malloc(sizeof(char) * (length +1));
if (randomString) {
for (int n = 0;n < length;n++) {
int key = rand() % (int)(sizeof(charset) -1);
randomString[n] = charset[key];
}
randomString[length] = '\0';
}
}
return randomString;
}
// CLI arguments handling // CLI arguments handling
const char *argp_program_version = "OSIE OPC-UA coupler 0.0.1"; const char *argp_program_version = "OSIE OPC-UA coupler 0.0.1";
const char *argp_program_bug_address = "ivan@nexedi.com"; const char *argp_program_bug_address = "ivan@nexedi.com";
...@@ -47,6 +66,7 @@ static struct argp_option options[] = { ...@@ -47,6 +66,7 @@ static struct argp_option options[] = {
{"password", 'w', "", 0, "Password."}, {"password", 'w', "", 0, "Password."},
{"key", 'k', "", 0, "x509 key."}, {"key", 'k', "", 0, "x509 key."},
{"certificate", 'c', "", 0, "X509 certificate."}, {"certificate", 'c', "", 0, "X509 certificate."},
{"uuid", 'i', "", 0, "UUID of coupler"},
{0} {0}
}; };
...@@ -60,6 +80,7 @@ struct arguments ...@@ -60,6 +80,7 @@ struct arguments
char *password; char *password;
char *key; char *key;
char *certificate; char *certificate;
char *uuid;
}; };
static error_t parse_opt(int key, char *arg, struct argp_state *state) static error_t parse_opt(int key, char *arg, struct argp_state *state)
...@@ -90,6 +111,9 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) ...@@ -90,6 +111,9 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state)
case 'k': case 'k':
arguments->key = arg; arguments->key = arg;
break; break;
case 'i':
arguments->uuid = arg;
break;
case ARGP_KEY_ARG: case ARGP_KEY_ARG:
return 0; return 0;
default: default:
...@@ -125,13 +149,22 @@ int main(int argc, char **argv) ...@@ -125,13 +149,22 @@ int main(int argc, char **argv)
arguments.password = ""; arguments.password = "";
arguments.key = ""; arguments.key = "";
arguments.certificate = ""; arguments.certificate = "";
arguments.uuid = "";
argp_parse(&argp, argc, argv, 0, 0, &arguments); argp_parse(&argp, argc, argv, 0, 0, &arguments);
// if no uuid define, generate a random one
if (!strlen(arguments.uuid)) {
arguments.uuid = randomString(12);
}
printf("Mode=%d\n", arguments.mode); printf("Mode=%d\n", arguments.mode);
printf("Listening port=%d\n", arguments.port); printf("Listening port=%d\n", arguments.port);
printf("Block device=%s\n", arguments.device); printf("Block device=%s\n", arguments.device);
printf("Slave address list=%s\n", arguments.slave_address_list); printf("Slave address list=%s\n", arguments.slave_address_list);
printf("key=%s\n", arguments.key); printf("key=%s\n", arguments.key);
printf("certificate=%s\n", arguments.certificate); printf("certificate=%s\n", arguments.certificate);
printf("UUID=%s\n", arguments.uuid);
// transfer to global variables (CLI input) // transfer to global variables (CLI input)
I2C_VIRTUAL_MODE = arguments.mode; I2C_VIRTUAL_MODE = arguments.mode;
......
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