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 @@
#include "common.h"
#include "mod_io_i2c.h"
#include "mod_io_opc_ua.h"
#include <time.h>
// The default port of OPC-UA server
const int DEFAULT_OPC_UA_PORT = 4840;
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
const char *argp_program_version = "OSIE OPC-UA coupler 0.0.1";
const char *argp_program_bug_address = "ivan@nexedi.com";
......@@ -47,6 +66,7 @@ static struct argp_option options[] = {
{"password", 'w', "", 0, "Password."},
{"key", 'k', "", 0, "x509 key."},
{"certificate", 'c', "", 0, "X509 certificate."},
{"uuid", 'i', "", 0, "UUID of coupler"},
{0}
};
......@@ -60,6 +80,7 @@ struct arguments
char *password;
char *key;
char *certificate;
char *uuid;
};
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':
arguments->key = arg;
break;
case 'i':
arguments->uuid = arg;
break;
case ARGP_KEY_ARG:
return 0;
default:
......@@ -125,13 +149,22 @@ int main(int argc, char **argv)
arguments.password = "";
arguments.key = "";
arguments.certificate = "";
arguments.uuid = "";
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("Listening port=%d\n", arguments.port);
printf("Block device=%s\n", arguments.device);
printf("Slave address list=%s\n", arguments.slave_address_list);
printf("key=%s\n", arguments.key);
printf("certificate=%s\n", arguments.certificate);
printf("UUID=%s\n", arguments.uuid);
// transfer to global variables (CLI input)
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