Commit 70f3a710 authored by Ivan Tyagov's avatar Ivan Tyagov

Network interface

parent dc273b64
......@@ -23,7 +23,7 @@ static struct argp_option options[] = {
{"heart-beat-id-list", 'l', "", 0, "Comma separated list of IDs of couplers to watch for heart beats. \
If a heart beat is missing coupler goes to safe mode."},
{"network-address-url-data-type", 'n', "opc.udp://224.0.0.22:4840/", 0, "Network address URL type used for Pub/Sub."},
{"network-interface", 'j', "", 0, "Network interface to use for Pub/Sub."},
{0}
};
......@@ -44,6 +44,7 @@ struct arguments
int heart_beat_timeout_interval;
char *heart_beat_id_list;
char *network_address_url_data_type;
char *network_interface;
};
static error_t parse_opt(int key, char *arg, struct argp_state *state)
......@@ -95,6 +96,9 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state)
case 'n':
arguments->network_address_url_data_type = arg;
break;
case 'j':
arguments->network_interface = arg;
break;
case ARGP_KEY_ARG:
return 0;
default:
......@@ -128,6 +132,7 @@ void handleCLI(int argc, char **argv) {
arguments.heart_beat_timeout_interval = DEFAULT_HEART_BEAT_TIMEOUT_INTERVAL;
arguments.heart_beat_id_list = "";
arguments.network_address_url_data_type = NETWORK_ADDRESS_URL_DATA_TYPE;
arguments.network_interface = "";
argp_parse(&argp, argc, argv, 0, 0, &arguments);
printf("Mode=%d\n", arguments.mode);
......@@ -143,6 +148,7 @@ void handleCLI(int argc, char **argv) {
printf("Heart beat timeout interval=%d ms\n", arguments.heart_beat_timeout_interval);
printf("Heart beat ID list=%s\n", arguments.heart_beat_id_list);
printf("Network address URL data type=%s\n", arguments.network_address_url_data_type);
printf("Network interface=%s\n", arguments.network_interface);
// transfer to global variables (CLI input)
COUPLER_ID = arguments.id;
......@@ -152,6 +158,7 @@ void handleCLI(int argc, char **argv) {
PUBLISHING_INTERVAL = HEART_BEAT_INTERVAL; // we assume that each heart_beat leads to a publish event
HEART_BEAT_TIMEOUT_INTERVAL = arguments.heart_beat_timeout_interval;
NETWORK_ADDRESS_URL_DATA_TYPE = arguments.network_address_url_data_type;
NETWORK_INTERFACE = arguments.network_interface;
USERNAME = arguments.username;
PASSWORD = arguments.password;
OPC_UA_PORT = arguments.port;
......
......@@ -2,6 +2,9 @@
char *DEFAULT_TRANSPORT_PROFILE = "http://opcfoundation.org/UA-Profile/Transport/pubsub-udp-uadp";
char *NETWORK_ADDRESS_URL_DATA_TYPE = "opc.udp://224.0.0.22:4840/";
//network interface to use for Pub / Sub
char *NETWORK_INTERFACE = "";
// global HEART BEATs of coupler
static unsigned int HEART_BEATS = 0;
......
......@@ -15,6 +15,10 @@ static void addPubSubConnection(UA_Server *server, UA_String *transportProfile,
connectionConfig.name = UA_STRING("UADP Connection 1");
connectionConfig.transportProfileUri = *transportProfile;
connectionConfig.enabled = UA_TRUE;
if (strlen(NETWORK_INTERFACE) > 0){
// set preferred network interface for Pub / Sub
networkAddressUrl->networkInterface = UA_STRING(NETWORK_INTERFACE);
}
UA_Variant_setScalar(&connectionConfig.address, networkAddressUrl,
&UA_TYPES[UA_TYPES_NETWORKADDRESSURLDATATYPE]);
/* Changed to static publisherId from random generation to identify
......
......@@ -89,6 +89,10 @@ static UA_StatusCode addPubSubConnectionSubscriber(UA_Server *server, UA_String
connectionConfig.name = UA_STRING("UDPMC Connection 1");
connectionConfig.transportProfileUri = *transportProfile;
connectionConfig.enabled = UA_TRUE;
if (strlen(NETWORK_INTERFACE) > 0){
// set preferred network interface for Pub / Sub
networkAddressUrl->networkInterface = UA_STRING(NETWORK_INTERFACE);
}
UA_Variant_setScalar(&connectionConfig.address, networkAddressUrl,
&UA_TYPES[UA_TYPES_NETWORKADDRESSURLDATATYPE]);
connectionConfig.publisherId.numeric = UA_UInt32_random ();
......
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