Arduino-CommandParser icon indicating copy to clipboard operation
Arduino-CommandParser copied to clipboard

Negative Values for int64 not working

Open dcbo opened this issue 3 years ago • 3 comments

When I register the example parser.registerCommand("test", "sdiu", &cmd_test); and parse the following Message: test "Hello World" 13.23 -45 85 I get 45 for the interger instead of -45 Serial.print("int64: "); Serial.println(args[2].asInt64); gives int64: 45

It seems that the negative value is parsed, because when i submit a negative value for uint64 test "Hallo Welt" 13.23 -45 -85 then i get the Error; parse error: invalid uint64_t for arg 4

dcbo avatar Dec 15 '21 10:12 dcbo

Same problem. I fixed it substituing the end of strToInt function

    return digit == -1 ? 0 : position; // ensure that there is at least one digit

with

   if (digit == -1) {
      return 0;
    }
    if (isNegative) {
      *value = -*value;
    }
    return position; // ensure that there is at least one digit

m-marini avatar Feb 08 '22 15:02 m-marini

I have the same issue. Would it be possible to merge #7 which, I believe, fixes this. Meanwhile, I jerry-rigged the code with the suggestion from @m-marini (thanks for that!).

Thank you!

djipco avatar Nov 20 '22 02:11 djipco