c++ - processing a raw hex communication data log into readable values -


i have embedded microcontroller system communicating computer via uart, , @ point of development should sending out valid data on own. have triggered 'scan' of device, role send out data it's read host device autonomously. have text file raw hex data values in there, ready processed. i'm sending out packets start 0x54 , end in 0x55 , come in lots of 4 (4 packets per single 'read' of instrument). packet contains 2 'identifier' bytes after 0x54, bunch of 6 bytes data, totaling 10 bytes per packet. depending on packet identifiers, data within floating point number or integer.

i want to design command line program takes in raw text file data in it, , outputs text file, comma seperated between packets, data converted readable decimal counterpart. new line every 4th converted packet useful. i'd in c (i relatively proficient in coding embedded c, , can convert hex values , forth between types enough) not have experience in writing c executables. getting started on little mini project awesome. need know how create command line controllable executable, read in data file, manipulate data (which think can now) , export data file. i've installed netbeans c/c++. pointers in right direction require (no pun intended =] )

here's raw data file:

http://pastebin.com/dx4hett0

there not variation in data deduce bytes certainty, following should op started.

void db_parse(file *outf, const unsigned char *s) {   fprintf(outf, "%c", *s++);   fprintf(outf, " %3u", *((uint8_t *) s));   s += sizeof(uint8_t);   uint8_t id1 = *((uint8_t *) s);   fprintf(outf, " %3u", *((uint8_t *) s));   s += sizeof(uint8_t);   if (id1 >= 3) {     fprintf(outf, " %13e", *((float *) s));     s += sizeof(float);   } else {     fprintf(outf, " %13u", *((uint32_t *) s));     s += sizeof(uint32_t);   }   fprintf(outf, " %5u", *((uint16_t *) s));   s += sizeof(uint16_t);   fprintf(outf, " %c\n", *s); }  // test code below  const char *h4 =     "54 12 04 00 00 40 c0 00 00 55 54 12 01 02 00 00 00 00 00 55 54 12 02 03 00 00 00 00 00 55 54 12 03 00 00 40 c0 00 00 55 ";  void db_test() {   unsigned char uc[10];   const char *s = h4;   while (*s) {     (int = 0; < 10; i++) {       unsigned x;       sscanf(s, "%x", &x);       uc[i] = x;       s += 3;     }     db_parse(stdout, uc);   } } 

output

t  18   4 -3.000000e+00     0 u t  18   1             2     0 u t  18   2             3     0 u t  18   3 -3.000000e+00     0 u 

Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

php - MySQLi multi_query results for later use -