Commit 776ee705 authored by Balakrishna Balakrishna's avatar Balakrishna Balakrishna

Merge branch 'master' into feature/coupler_opcua_integration

parents d90af97d ff0f5eb0
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <signal.h> #include <signal.h>
#include "open62541.h" #include "open62541.h"
#include <argp.h> #include <argp.h>
#include <string.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;
...@@ -38,7 +39,10 @@ static struct argp_option options[] = { ...@@ -38,7 +39,10 @@ static struct argp_option options[] = {
{"slave-address-list", 's', "0x58", 0, "Comma separated list of slave I2C addresses."}, {"slave-address-list", 's', "0x58", 0, "Comma separated list of slave I2C addresses."},
{"mode", 'm', "0", 0, "Set different modes of operation of coupler. Default (0) is set attached \ {"mode", 'm', "0", 0, "Set different modes of operation of coupler. Default (0) is set attached \
I2C's state state. Virtual (1) which does NOT set any I2C slaves' state."}, I2C's state state. Virtual (1) which does NOT set any I2C slaves' state."},
{0}}; { "username", 'u', "", 0, "Username."},
{ "password", 'w', "", 0, "Password."},
{ 0 }
};
struct arguments struct arguments
{ {
...@@ -46,33 +50,37 @@ struct arguments ...@@ -46,33 +50,37 @@ struct arguments
int port; int port;
char *device; char *device;
char *slave_address_list; char *slave_address_list;
char *username;
char *password;
}; };
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)
{ {
struct arguments *arguments = state->input; struct arguments *arguments = state->input;
switch (key) switch (key) {
{ case 'p':
case 'p': arguments->port = arg ? atoi (arg) : DEFAULT_OPC_UA_PORT;
arguments->port = arg ? atoi(arg) : DEFAULT_OPC_UA_PORT; break;
//printf("got arg port=%s\n", arg); case 'd':
break; arguments->device = arg;
case 'd': break;
arguments->device = arg; case 's':
//printf("got arg device=%s\n", arg); arguments->slave_address_list = arg;
break; break;
case 's': case 'm':
arguments->slave_address_list = arg; arguments->mode = arg ? atoi (arg) : DEFAULT_MODE;
//printf("got arg slave_address_list=%s\n", arg); break;
break; case 'u':
case 'm': arguments->username = arg;
arguments->mode = arg ? atoi(arg) : DEFAULT_MODE; break;
break; case 'w':
case ARGP_KEY_ARG: arguments->password = arg;
return 0; break;
default: case ARGP_KEY_ARG:
return ARGP_ERR_UNKNOWN; return 0;
} default:
return ARGP_ERR_UNKNOWN;
}
return 0; return 0;
} }
...@@ -1281,6 +1289,8 @@ int main(int argc, char **argv) ...@@ -1281,6 +1289,8 @@ int main(int argc, char **argv)
arguments.mode = DEFAULT_MODE; arguments.mode = DEFAULT_MODE;
arguments.device = DEFAULT_I2C_BLOCK_DEVICE_NAME; arguments.device = DEFAULT_I2C_BLOCK_DEVICE_NAME;
arguments.slave_address_list = DEFAULT_I2C_0_ADDR; arguments.slave_address_list = DEFAULT_I2C_0_ADDR;
arguments.username = "";
arguments.password = "";
argp_parse(&argp, argc, argv, 0, 0, &arguments); argp_parse(&argp, argc, argv, 0, 0, &arguments);
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);
...@@ -1313,11 +1323,24 @@ int main(int argc, char **argv) ...@@ -1313,11 +1323,24 @@ int main(int argc, char **argv)
UA_ServerConfig *config = UA_Server_getConfig(server); UA_ServerConfig *config = UA_Server_getConfig(server);
config->verifyRequestTimestamp = UA_RULEHANDLING_ACCEPT; config->verifyRequestTimestamp = UA_RULEHANDLING_ACCEPT;
// add variables representing physical relarys / inputs, etc
addVariable(server); addVariable(server);
addValueCallbackToCurrentTimeVariable(server); addValueCallbackToCurrentTimeVariable(server);
UA_StatusCode retval = UA_Server_run(server, &running); /* Disable anonymous logins, enable two user/password logins */
if (strlen(arguments.username) > 0 && strlen(arguments.password) > 0){
char *username = arguments.username;
char *password = arguments.password;
UA_UsernamePasswordLogin logins[1] = {
{UA_STRING(arguments.username), UA_STRING(arguments.password)},
};
config->accessControl.clear(&config->accessControl);
UA_StatusCode retval1 = UA_AccessControl_default(config, false, NULL,
&config->securityPolicies[config->securityPoliciesSize-1].policyUri, 1, logins);
}
// run server
UA_StatusCode retval = UA_Server_run(server, &running);
UA_Server_delete(server); UA_Server_delete(server);
// always leave attached slaves to a known safe shutdown state // always leave attached slaves to a known safe shutdown state
......
...@@ -3,7 +3,7 @@ filename = instance-modbus.cfg.in ...@@ -3,7 +3,7 @@ filename = instance-modbus.cfg.in
md5sum = 8637c6b714a0bb9f27c86f3928049b98 md5sum = 8637c6b714a0bb9f27c86f3928049b98
filename = instance-opc-ua.cfg.in filename = instance-opc-ua.cfg.in
md5sum = b6cf47dc85a0c1086cca5e3edcf969ab md5sum = 9edc884287844d3b7182eeebbbe11285
filename = instance-opc-ua-virtual.cfg.in filename = instance-opc-ua-virtual.cfg.in
md5sum = 49f84a499d258771651983dec90e98c1 md5sum = 29ca37d2a24f613a31d9fecdca2dd9a9
...@@ -21,7 +21,7 @@ extends = {{ template_monitor }} ...@@ -21,7 +21,7 @@ extends = {{ template_monitor }}
recipe = slapos.cookbook:wrapper recipe = slapos.cookbook:wrapper
# start with defaults # start with defaults
command-line = command-line =
{{ buildout['bin-directory'] }}/server -d ${instance-parameter:configuration.coupler_block_device} -s ${instance-parameter:configuration.coupler_i2c_slave_list} -m 1 -p ${instance-parameter:configuration.opc_ua_port} {{ buildout['bin-directory'] }}/server -d ${instance-parameter:configuration.coupler_block_device} -s ${instance-parameter:configuration.coupler_i2c_slave_list} -m 1 -p ${instance-parameter:configuration.opc_ua_port} -u ${instance-parameter:configuration.username} -w ${instance-parameter:configuration.password}
wrapper-path = ${directory:service}/coupler-opc-ua-virtual wrapper-path = ${directory:service}/coupler-opc-ua-virtual
...@@ -49,6 +49,8 @@ configuration.coupler_i2c_slave_list = 0x58 ...@@ -49,6 +49,8 @@ configuration.coupler_i2c_slave_list = 0x58
# In our use case, we are expecting from the user to specify one (optional) parameter: "name". We put the default value here if he doesn't specify it, so that it doesn't crash. # In our use case, we are expecting from the user to specify one (optional) parameter: "name". We put the default value here if he doesn't specify it, so that it doesn't crash.
configuration.interface = 0.0.0.0 configuration.interface = 0.0.0.0
configuration.opc_ua_port = 4840 configuration.opc_ua_port = 4840
configuration.username =
configuration.password =
# If our use case requires that the user can specify a mail address so that his instance can mail to him (for example), we can do: # If our use case requires that the user can specify a mail address so that his instance can mail to him (for example), we can do:
# configuration.mail-address = # configuration.mail-address =
# If the user doesn't specify it, it won't break and the recipe can handle it (i.e don't send any mail for example). # If the user doesn't specify it, it won't break and the recipe can handle it (i.e don't send any mail for example).
......
...@@ -21,7 +21,7 @@ extends = {{ template_monitor }} ...@@ -21,7 +21,7 @@ extends = {{ template_monitor }}
recipe = slapos.cookbook:wrapper recipe = slapos.cookbook:wrapper
# start with defaults # start with defaults
command-line = command-line =
{{ buildout['bin-directory'] }}/server -d ${instance-parameter:configuration.coupler_block_device} -s ${instance-parameter:configuration.coupler_i2c_slave_list} -p ${instance-parameter:configuration.opc_ua_port} {{ buildout['bin-directory'] }}/server -d ${instance-parameter:configuration.coupler_block_device} -s ${instance-parameter:configuration.coupler_i2c_slave_list} -p ${instance-parameter:configuration.opc_ua_port} -u ${instance-parameter:configuration.username} -w ${instance-parameter:configuration.password}
wrapper-path = ${directory:service}/coupler-opc-ua wrapper-path = ${directory:service}/coupler-opc-ua
...@@ -42,6 +42,8 @@ cert = ${slap-connection:cert-file} ...@@ -42,6 +42,8 @@ cert = ${slap-connection:cert-file}
configuration.coupler_block_device = /dev/i2c-1 configuration.coupler_block_device = /dev/i2c-1
configuration.coupler_i2c_slave_list = 0x58 configuration.coupler_i2c_slave_list = 0x58
configuration.username =
configuration.password =
# Define default parameter(s) that will be used later, in case user didn't # Define default parameter(s) that will be used later, in case user didn't
# specify it. # specify it.
......
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