I'm reading OBD2 data and sending via serial to another processor.
The received data is stripped of start and end markers and is formatted with a single character identifier, comma, and int or long. This is what a debug serial print of receivedChars looks like:
r,0
k,0
r,0
k,0
r,0
k,0
r,0
k,0
o,14
r,0
d,248924
c,14
I'm using scanf and switch/case to put the data into variables.
It doesn't work as expected and I'm clueless when it comes to string conversion. Any help would be appreciated.
I can't post all the code for both processors, it's a lot, and everything else works.
char mark;
unsigned long data;
sscanf(receivedChars, "%c,%u", &mark, &data);
switch (mark) {
case 'f':
fuel = data;
break;
case 'r':
rpm = data;
break;
case 'k':
kph = data;
break;
case 'd':
odom = data;
break;
case 'c':
cool = data;
break;
case 'o':
oil = data;
break;
}
works fine. So I wonder where receivedChars comes from and what is actually in it when you hit the sscanf().
I did have to fix it for the one case where you exploit a long variable
sscanf(receivedChars, "%c,%lu", &mark, &data);
a tip off from another compiler.
Got warnings turned up in the IDE? You may have missed
/var/folders/gz/t92bgl156gdf2066kn0xpc7w0000gq/T/arduino_modified_sketch_290204/sketch_jul09a.ino: In function 'void setup()':
/var/folders/gz/t92bgl156gdf2066kn0xpc7w0000gq/T/arduino_modified_sketch_290204/sketch_jul09a.ino:15:46: warning: format '%u' expects argument of type 'unsigned int*', but argument 4 has type 'long unsigned int*' [-Wformat=]
sscanf(receivedChars, "%c,%u", &mark, &data);