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
Martin Manchev
osie
Commits
6db7a93e
Commit
6db7a93e
authored
Nov 09, 2021
by
Ivan Tyagov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle properly CLI arguments.
parent
d35cd949
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
24 deletions
+27
-24
coupler/opc-ua-server/server.c
coupler/opc-ua-server/server.c
+27
-24
No files found.
coupler/opc-ua-server/server.c
View file @
6db7a93e
...
...
@@ -358,33 +358,36 @@ int main(int argc, char **argv) {
char
*
eptr
;
// handle comand line arguments
if
(
argc
>=
2
)
{
// override default i2c block device from first cmd line argument
I2C_BLOCK_DEVICE_NAME
=
argv
[
1
];
// if nothing specified on CLI set a default one
if
(
argc
<=
2
){
I2C_SLAVE_ADDR_LIST
[
0
]
=
DEFAULT_I2C_0_ADDR
;
printf
(
"I2C_slave=0x%x
\n
"
,
DEFAULT_I2C_0_ADDR
);
}
else
{
// override list of I2C slaves addresses from CLI
for
(
i
=
2
;
i
<
argc
;
i
++
)
{
// from CLI we get a hexidecimal string as a char (0x58 for example), convert to decimal
result
=
strtol
(
argv
[
i
],
&
eptr
,
16
);
printf
(
"I2C_slave=0x%lx
\n
"
,
result
);
I2C_SLAVE_ADDR_LIST
[
i
-
2
]
=
result
;
}
}
}
else
{
I2C_BLOCK_DEVICE_NAME
=
DEFAULT_I2C_BLOCK_DEVICE_NAME
;
if
(
argc
==
1
)
{
// no paramaters at all
I2C_BLOCK_DEVICE_NAME
=
DEFAULT_I2C_BLOCK_DEVICE_NAME
;
I2C_SLAVE_ADDR_LIST
[
0
]
=
DEFAULT_I2C_0_ADDR
;
}
if
(
argc
==
2
)
{
// only block device specified
I2C_BLOCK_DEVICE_NAME
=
argv
[
1
];
I2C_SLAVE_ADDR_LIST
[
0
]
=
DEFAULT_I2C_0_ADDR
;
}
if
(
argc
>
2
)
{
// both block device and I2C slave(s) specified
I2C_BLOCK_DEVICE_NAME
=
argv
[
1
];
for
(
i
=
2
;
i
<
argc
;
i
++
){
// from CLI we get a hexidecimal string as a char (0x58 for example), convert to decimal
result
=
strtol
(
argv
[
i
],
&
eptr
,
16
);
I2C_SLAVE_ADDR_LIST
[
i
-
2
]
=
result
;
}
}
// debug info
printf
(
"Block device=%s
\n
"
,
I2C_BLOCK_DEVICE_NAME
);
length
=
sizeof
(
I2C_SLAVE_ADDR_LIST
)
/
sizeof
(
int
);
for
(
i
=
0
;
i
<
length
;
i
++
){
if
(
I2C_SLAVE_ADDR_LIST
[
i
]
!=
0
)
{
printf
(
"I2C_slave=0x%x
\n
"
,
I2C_SLAVE_ADDR_LIST
[
i
]);
}
}
// always start attached slaves from a know safe shutdown state
safeShutdownI2CSlaveList
();
...
...
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