fork download
  1. #include <iostream>
  2. #include <string.h>
  3.  
  4. int main()
  5. {
  6. char reply[] = "$8C82;01C5;0200000000;030025;040035;0500CB;060000;078000;080000;09FFED;0A0439;0B0430;0C046F;0D0079;0E8000;0F0099;100192;1114;1214;2E8000;8C";
  7.  
  8. uint8_t n = 0;
  9. char * p;
  10. while ( p = strtok( n == 0 ? reply : NULL, ";" ) )
  11. {
  12. printf( "%-11s", p );
  13.  
  14. uint8_t id;
  15. int32_t value;
  16. if ( sscanf( p, "%2hhX%X", &id, &value ) == 2 )
  17. {
  18. switch ( id )
  19. {
  20. case 0x03 :
  21. {
  22. printf( "O2 = %d", value );
  23. break;
  24. }
  25. case 0x04 :
  26. {
  27. printf( "C0 = %d", value );
  28. break;
  29. }
  30. default :
  31. {
  32. printf( "ID 0x%02hhX at pos %hhu = %d", id, n, value );
  33. break;
  34. }
  35. }
  36. }
  37.  
  38. printf( "\n" );
  39.  
  40. n++;
  41. }
  42.  
  43. return 0;
  44. }
Success #stdin #stdout 0s 5624KB
stdin
Standard input is empty
stdout
$8C82      
01C5       ID 0x01 at pos 1 = 197
0200000000 ID 0x02 at pos 2 = 0
030025     O2 = 37
040035     C0 = 53
0500CB     ID 0x05 at pos 5 = 203
060000     ID 0x06 at pos 6 = 0
078000     ID 0x07 at pos 7 = 32768
080000     ID 0x08 at pos 8 = 0
09FFED     ID 0x09 at pos 9 = 65517
0A0439     ID 0x0A at pos 10 = 1081
0B0430     ID 0x0B at pos 11 = 1072
0C046F     ID 0x0C at pos 12 = 1135
0D0079     ID 0x0D at pos 13 = 121
0E8000     ID 0x0E at pos 14 = 32768
0F0099     ID 0x0F at pos 15 = 153
100192     ID 0x10 at pos 16 = 402
1114       ID 0x11 at pos 17 = 20
1214       ID 0x12 at pos 18 = 20
2E8000     ID 0x2E at pos 19 = 32768
8C