Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
osie
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nikola Balog
osie
Commits
c3d5e53a
Commit
c3d5e53a
authored
Sep 01, 2022
by
Ivan Tyagov
Browse files
Options
Browse Files
Download
Plain Diff
Inclusion of custom server bind address
See merge request
!18
parents
7bf2d914
ab7e2c6f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
115 additions
and
79 deletions
+115
-79
coupler/opc-ua-server/cli.h
coupler/opc-ua-server/cli.h
+8
-0
coupler/opc-ua-server/server.c
coupler/opc-ua-server/server.c
+107
-79
No files found.
coupler/opc-ua-server/cli.h
View file @
c3d5e53a
...
...
@@ -7,6 +7,7 @@ static char doc[] = "OPC-UA server which controls MOD-IO's relays' state over OP
static
char
args_doc
[]
=
"..."
;
static
struct
argp_option
options
[]
=
{
{
"port"
,
'p'
,
"4840"
,
0
,
"Port to bind to."
},
{
"server-ip-address"
,
'a'
,
""
,
0
,
"Server address to bind to."
},
{
"device"
,
'd'
,
"/dev/i2c-1"
,
0
,
"Linux block device path."
},
{
"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 \
...
...
@@ -30,6 +31,7 @@ struct arguments
{
int
mode
;
int
port
;
char
*
server_ip_address
;
char
*
device
;
char
*
slave_address_list
;
char
*
username
;
...
...
@@ -51,6 +53,9 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state)
case
'p'
:
arguments
->
port
=
arg
?
atoi
(
arg
)
:
DEFAULT_OPC_UA_PORT
;
break
;
case
'a'
:
arguments
->
server_ip_address
=
arg
;
break
;
case
'd'
:
arguments
->
device
=
arg
;
break
;
...
...
@@ -110,6 +115,7 @@ void handleCLI(int argc, char **argv) {
struct
arguments
arguments
;
arguments
.
port
=
DEFAULT_OPC_UA_PORT
;
arguments
.
server_ip_address
=
""
;
arguments
.
mode
=
DEFAULT_MODE
;
arguments
.
device
=
DEFAULT_I2C_BLOCK_DEVICE_NAME
;
arguments
.
slave_address_list
=
DEFAULT_I2C_0_ADDR
;
...
...
@@ -126,6 +132,7 @@ void handleCLI(int argc, char **argv) {
printf
(
"Mode=%d
\n
"
,
arguments
.
mode
);
printf
(
"Listening port=%d
\n
"
,
arguments
.
port
);
printf
(
"server_ip_address=%s
\n
"
,
arguments
.
server_ip_address
);
printf
(
"Block device=%s
\n
"
,
arguments
.
device
);
printf
(
"Slave address list=%s
\n
"
,
arguments
.
slave_address_list
);
printf
(
"Key=%s
\n
"
,
arguments
.
key
);
...
...
@@ -147,6 +154,7 @@ void handleCLI(int argc, char **argv) {
USERNAME
=
arguments
.
username
;
PASSWORD
=
arguments
.
password
;
OPC_UA_PORT
=
arguments
.
port
;
OPC_UA_ADDRESS
=
arguments
.
server_ip_address
;
ENABLE_X509
=
strlen
(
arguments
.
key
)
>
0
&&
strlen
(
arguments
.
certificate
);
ENABLE_USERNAME_PASSWORD_AUTHENTICATION
=
strlen
(
arguments
.
username
)
>
0
&&
strlen
(
arguments
.
password
)
>
0
;
ENABLE_HEART_BEAT
=
arguments
.
heart_beat
;
...
...
coupler/opc-ua-server/server.c
View file @
c3d5e53a
...
...
@@ -48,6 +48,7 @@ const int DEFAULT_MODE = 0;
const
int
DEFAULT_COUPLER_ID
=
0
;
int
OPC_UA_PORT
;
char
*
OPC_UA_ADDRESS
;
bool
ENABLE_HEART_BEAT
=
false
;
bool
ENABLE_HEART_BEAT_CHECK
=
false
;
bool
ENABLE_X509
=
false
;
...
...
@@ -85,10 +86,37 @@ int main(int argc, char **argv)
signal
(
SIGINT
,
stopHandler
);
signal
(
SIGTERM
,
stopHandler
);
UA_String
serverUrls
[
1
];
size_t
serverUrlsSize
=
0
;
char
serverUrlBuffer
[
1
][
512
];
server
=
UA_Server_new
();
UA_ServerConfig_setMinimal
(
UA_Server_getConfig
(
server
),
OPC_UA_PORT
,
NULL
);
UA_ServerConfig
*
config
=
UA_Server_getConfig
(
server
);
// opc_ua server is listening to user input address else on all interfaces
// user input ip address should be added to any of the interface else no server socket will be created
if
(
OPC_UA_ADDRESS
!=
NULL
){
// check whether the default url is already set
if
(
config
->
serverUrlsSize
>
0
)
{
UA_LOG_WARNING
(
&
config
->
logger
,
UA_LOGCATEGORY_USERLAND
,
"ServerUrls already set. Overriding."
);
UA_Array_delete
(
config
->
serverUrls
,
config
->
serverUrlsSize
,
&
UA_TYPES
[
UA_TYPES_STRING
]);
config
->
serverUrls
=
NULL
;
config
->
serverUrlsSize
=
0
;
}
// construct opc_ua server url based on input ip address
UA_snprintf
(
serverUrlBuffer
[
0
],
sizeof
(
serverUrlBuffer
[
0
]),
"opc.tcp://%s:%u"
,
OPC_UA_ADDRESS
,
OPC_UA_PORT
);
serverUrls
[
serverUrlsSize
]
=
UA_STRING
(
serverUrlBuffer
[
0
]);
serverUrlsSize
++
;
// add the url into the config
UA_StatusCode
ret_val
=
UA_Array_copy
(
serverUrls
,
serverUrlsSize
,
(
void
**
)
&
config
->
serverUrls
,
&
UA_TYPES
[
UA_TYPES_STRING
]);
if
(
ret_val
!=
UA_STATUSCODE_GOOD
){
return
ret_val
;
}
config
->
serverUrlsSize
=
serverUrlsSize
;
}
config
->
verifyRequestTimestamp
=
UA_RULEHANDLING_ACCEPT
;
// add variables representing physical relays / inputs, etc
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment