Skip to content

Document (and/or fix) the different ways tools parse numeric arguments #8

@follower

Description

@follower

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:

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:

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:

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:

node = strtol(argv[2], NULL, 16);

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;

node = strtol(argv[2], NULL, 16);
index = strtol(argv[3], NULL, 16);
subindex = strtol(argv[4], NULL, 16);

node = strtol(argv[2], NULL, 16);
index = strtol(argv[3], NULL, 16);
subindex = strtol(argv[4], NULL, 16);
len = strlen(argv[5])/2;

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:

In part I've created this issue to document these details for people until any changes are added to the code base.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions