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
4ac38223
Commit
4ac38223
authored
Mar 18, 2022
by
Ivan Tyagov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Each coupler is now identified by a 12 bytest long UUID.
parent
e9c18213
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
63 additions
and
30 deletions
+63
-30
coupler/opc-ua-server/server.c
coupler/opc-ua-server/server.c
+63
-30
No files found.
coupler/opc-ua-server/server.c
View file @
4ac38223
...
@@ -26,28 +26,48 @@
...
@@ -26,28 +26,48 @@
#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"
;
static
char
doc
[]
=
"OPC-UA server which controls MOD-IO's relays' state over OPC-UA protocol."
;
static
char
doc
[]
=
"OPC-UA server which controls MOD-IO's relays' state over OPC-UA protocol."
;
static
char
args_doc
[]
=
"..."
;
static
char
args_doc
[]
=
"..."
;
static
struct
argp_option
options
[]
=
{
static
struct
argp_option
options
[]
=
{
{
"port"
,
'p'
,
"4840"
,
0
,
"Port to bind to."
},
{
"port"
,
'p'
,
"4840"
,
0
,
"Port to bind to."
},
{
"device"
,
'd'
,
"/dev/i2c-1"
,
0
,
"Linux block device path."
},
{
"device"
,
'd'
,
"/dev/i2c-1"
,
0
,
"Linux block device path."
},
{
"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."
},
{
"username"
,
'u'
,
""
,
0
,
"Username."
},
{
"username"
,
'u'
,
""
,
0
,
"Username."
},
{
"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."
},
{
0
}
{
"uuid"
,
'i'
,
""
,
0
,
"UUID of coupler"
},
{
0
}
};
};
struct
arguments
struct
arguments
...
@@ -60,41 +80,45 @@ struct arguments
...
@@ -60,41 +80,45 @@ 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
)
{
{
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
;
case
'd'
:
arguments
->
device
=
arg
;
break
;
case
's'
:
arguments
->
slave_address_list
=
arg
;
break
;
break
;
case
'
d'
:
case
'
m'
:
arguments
->
device
=
arg
;
arguments
->
mode
=
arg
?
atoi
(
arg
)
:
DEFAULT_MODE
;
break
;
break
;
case
'
s'
:
case
'
u'
:
arguments
->
slave_address_list
=
arg
;
arguments
->
username
=
arg
;
break
;
break
;
case
'
m'
:
case
'
w'
:
arguments
->
mode
=
arg
?
atoi
(
arg
)
:
DEFAULT_MODE
;
arguments
->
password
=
arg
;
break
;
break
;
case
'
u'
:
case
'
c'
:
arguments
->
username
=
arg
;
arguments
->
certificate
=
arg
;
break
;
break
;
case
'w'
:
case
'k'
:
arguments
->
password
=
arg
;
arguments
->
key
=
arg
;
break
;
break
;
case
'c'
:
case
'i'
:
arguments
->
certificate
=
arg
;
arguments
->
uuid
=
arg
;
break
;
break
;
case
'k'
:
case
ARGP_KEY_ARG
:
arguments
->
key
=
arg
;
break
;
case
ARGP_KEY_ARG
:
return
0
;
return
0
;
default:
default:
return
ARGP_ERR_UNKNOWN
;
return
ARGP_ERR_UNKNOWN
;
}
}
return
0
;
return
0
;
}
}
...
@@ -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
;
...
...
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