epics-modules / opcua

EPICS Device Support for OPC UA
Other
19 stars 13 forks source link

Empty options should be ignored silently #146

Closed dirk-zimoch closed 2 months ago

dirk-zimoch commented 1 year ago

opcuaSession and opcuaSubscription accept a list of options, but empty list elements cause the warning: option '' must follow 'key=value' format - ignored

Empty options are useful in script snippets with macros like: opcuaSession $(OPC_SESS) opc.tcp://$(OPC_HOST):$(OPC_PORT=4840) sec-mode=$(OPC_SEC=None):$(OPC_SESS_OPT=)

When OPC_SESS_OPT is given, the : before is required, but when OPC_SESS_OPT is empty (the default) the terminating : causes a warning.

ralphlange commented 1 year ago

Reasonable.

dirk-zimoch commented 1 year ago

PS: I would have preferred to have the options in an iocshArgArgv instead of using a iocshArgString with separators.

ralphlange commented 1 year ago

That was obviously to keep it consistent with the single argument to the opcuaSession and opcuaSubscription calls.

But we could add the other as an optional format, couldn't we?

ralphlange commented 1 year ago

Oh, you mean in the opcuaSession call?

dirk-zimoch commented 1 year ago

Yes, in the opcuaSession and opcuaSubscription calls. Their last argument is: static const iocshArg opcuaSubscriptionArg3 = {"[options]", iocshArgString}; But for arbitrary length lists of arguments (at the end) we already have iocshArgArgv.

ralphlange commented 1 year ago

I was not aware of iocshArgArgv. I'll have a look. Thanks for the pointer!

dirk-zimoch commented 1 year ago

It is a structure. arg[n].aval.ac contains the number of remaining arguments (from position n on) and arg[n].aval.av is an array of char* with the remaining args as strings, followed by a NULL.

There is only one strangeness with iocshArgArgv. If it is the first (i.e. only argument), element 0 arg[0].aval.av[0] is not the first argument but the command itself. The first argument is in arg[0].aval.av[1].

dirk-zimoch commented 1 year ago

I can do the necessary changes and make a PR.

dirk-zimoch commented 1 year ago

PR #147

dirk-zimoch commented 1 year ago

There is only one strangeness with iocshArgArgv. If it is the first (i.e. only argument), element 0 arg[0].aval.av[0] is not the first argument but the command itself. The first argument is in arg[0].aval.av[1].

I remembered it wrong: arg[n].aval.av[0] always contains a (string) copy of the previous argument arg[n-1] (or the command if n==0). The first optional argument is always in av[1].

ralphlange commented 2 months ago

Closed by merge of PR #147.