-
Notifications
You must be signed in to change notification settings - Fork 33
Description
There are a number of issues related to the parsing of numeric arguments which would benefit from fixing and/or documenting:
- Incorrect documentation
- Inconsistent parsing
- Lack of documentation
Incorrect documentation
The rs-canopen-ds401 tool has useful documentation here and it would be helpful to replicate for the other tools:
libcanopen/bin/rs-canopen-ds401.c
Lines 39 to 45 in 6e4758b
| fprintf(stderr, "usage: rs-canopen-ds401 INTERFACE NODE COMMAND DEVICE ADDRESS [VALUE]\n"); | |
| fprintf(stderr, "\tINTERFACE = can0 | can1 | ...\n"); | |
| fprintf(stderr, "\tNODE\t = 0 .. 127\n"); | |
| fprintf(stderr, "\tCOMMAND\t = read | write\n"); | |
| fprintf(stderr, "\tDEVICE\t = di | do\n"); | |
| fprintf(stderr, "\tADDRESS\t = 0 .. 3\n"); | |
| fprintf(stderr, "\tVALUE\t = 0 | 1 [only for COMMAND = write]\n"); |
Except that it gives the NODE ID range as 0 .. 127 (implied to be a decimal/base 10 number) when the argument is actually parsed as hexadecimal:
libcanopen/bin/rs-canopen-ds401.c
Lines 81 to 82 in 6e4758b
| node = strtol(argv[2], NULL, 16); | |
| address = atoi(argv[5]); |
Inconsistent parsing
The rs-canopen-nmt tool uses atoi() to parse the Node ID argument as a decimal/base 10 number:
libcanopen/bin/rs-canopen-nmt.c
Line 116 in 6e4758b
| node = atoi(argv[3]); |
But all the other tools use strol() to parse the Node ID (and other numeric arguments) as a hexadecimal/base 16 number:
libcanopen/bin/rs-canopen-node-info.c
Line 77 in 6e4758b
| node = strtol(argv[2], NULL, 16); |
libcanopen/bin/rs-canopen-pdo-download.c
Lines 71 to 75 in 6e4758b
| node = strtol(argv[2], NULL, 16); | |
| index = strtol(argv[3], NULL, 16); | |
| subindex = strtol(argv[4], NULL, 16); | |
| data = strtol(argv[5], NULL, 16); | |
| len = strlen(argv[5])/2; |
libcanopen/bin/rs-canopen-pdo-upload.c
Lines 69 to 71 in 6e4758b
| node = strtol(argv[2], NULL, 16); | |
| index = strtol(argv[3], NULL, 16); | |
| subindex = strtol(argv[4], NULL, 16); |
libcanopen/bin/rs-canopen-sdo-download.c
Lines 71 to 74 in 6e4758b
| node = strtol(argv[2], NULL, 16); | |
| index = strtol(argv[3], NULL, 16); | |
| subindex = strtol(argv[4], NULL, 16); | |
| len = strlen(argv[5])/2; |
libcanopen/bin/rs-canopen-sdo-upload.c
Lines 72 to 74 in 6e4758b
| node = strtol(argv[2], NULL, 16); | |
| index = strtol(argv[3], NULL, 16); | |
| subindex = strtol(argv[4], NULL, 16); |
Lack of documentation
With the exception of rs-canopen-ds401 all the other tools don't document the format/range of their numeric arguments in their usage message. It would be helpful to document this.
Related:
- "Document/improve how data argument length/size is calculated #9"
- "Need to document that
SEGmode argument is available for SDO upload tool. #6"
In part I've created this issue to document these details for people until any changes are added to the code base.