New work version with additional functions
Dependencies: 4DGL-UC ConfigFile MODSERIAL mbed mbos
Fork of CDU_Mbed_35 by
Revision 4:c23c570e4454, committed 2012-12-01
- Comitter:
- LvdK
- Date:
- Sat Dec 01 20:53:05 2012 +0000
- Parent:
- 3:58382fa6e555
- Child:
- 5:99594f4ab659
- Commit message:
- eerste datastructure filling (met bug)
Changed in this revision
--- a/USB_receive.cpp Wed Nov 28 14:24:08 2012 +0000 +++ b/USB_receive.cpp Sat Dec 01 20:53:05 2012 +0000 @@ -4,6 +4,7 @@ #define TRUE 1 #define FALSE 0 + #define max_rx_buffer 500 // : length of main receiving cyclic buffer #define max_string_length 80 // : max length of string starting with $ and ending with CR/LF #define min_string_length 10 // : min length of string starting with $ and ending with CR/LF @@ -24,6 +25,7 @@ char string_received[max_string_length + 1]; // : contains a string starting with $ and ending with CR/LF +int nr_of_received_char = 0; int string_complete = FALSE; // : no complete string with $ and CR/LF void char_received() { @@ -81,18 +83,23 @@ // it starts with '$' AND // it ends on new-line AND // it has at least min_string_length - + USB.printf("string_received : %s\n",string_received ); // show string >>>>>>>>>>>>>>>>( TEST !) string_complete = TRUE; // : set flag for decoder ! <<<<<<<<<<<<<<<<< NODIG ???????????? - decode_string(); // : call decoder to proces complete string received + nr_of_received_char = string_pntr; + decode_string(); // : call decoder to check complete string received // Make ready for receiving new command: $_detected = FALSE; string_pntr = 0; // : set pointer to begin of string_received[] buffer again + nr_of_received_char = 0; } - else string_pntr = 0; // : set pointer to begin of string_received[] buffer again + else { + string_pntr = 0; // : set pointer to begin of string_received[] buffer again + nr_of_received_char = 0; + } } }
--- a/data_structures.cpp Wed Nov 28 14:24:08 2012 +0000 +++ b/data_structures.cpp Sat Dec 01 20:53:05 2012 +0000 @@ -4,85 +4,91 @@ #define TRUE 1 #define FALSE 0 +#define max_text_length 40 + +extern char string_received[]; // : complete string starting with $ and ending with CR/LF +extern int nr_of_received_char; // : number of chars in string_receved[]; +extern int comma[]; // : array with pointers to all found commas +extern Serial USB; // >>>>>>>>>>> alleen t.b.v TEST output !! // ---------- Data structures of received FS data--------------------------------------------------------- -struct { char text[40]; // : maintext max. 40 ? chars - int text_font; // : font can be 1 – 8 - char font_style; // : can be S,B,I,U,N - int text_colour; // : colour number - int updated; // : update flag, TRUE/FALSE - int locked; // : locked flag, TRUE/FALSE - } KEY_LEFT_MAINTEXT[10]; // : keys can be 0 - 9 +struct { char text[max_text_length];// : maintext with max_text_length chars + int font_size; // : fontsize can be 1 – 8 + char font_style; // : can be S,B,I,U,N + int text_colour; // : colour number + int updated; // : update flag, TRUE/FALSE + int locked; // : locked flag, TRUE/FALSE + } KEY_LEFT_MAINTEXT[10]; // : keys can be 0 - 9 -struct { char text[40]; // : subtext max. 40 ? chars - int text_font; // : font can be 1 – 8 - char font_style; // : can be S,B,I,U,N - int text_colour; // : colour number - int updated; // : update flag, TRUE/FALSE - int locked; // : locked flag, TRUE/FALSE - } KEY_LEFT_SUBTEXT[10]; // : keys can be 0 - 9 +struct { char text[max_text_length];// : subtext with max_text_length chars + int font_size; // : fontsize can be 1 – 8 + char font_style; // : can be S,B,I,U,N + int text_colour; // : colour number + int updated; // : update flag, TRUE/FALSE + int locked; // : locked flag, TRUE/FALSE + } KEY_LEFT_SUBTEXT[10]; // : keys can be 0 - 9 -struct { char text[40]; // : maintext max. 40 ? chars - int text_font; // : font can be 1 – 8 - char font_style; // : can be S,B,I,U,N - int text_colour; // : colour number - int updated; // : update flag, TRUE/FALSE - int locked; // : locked flag, TRUE/FALSE - } KEY_RIGHT_MAINTEXT[10]; // : keys can be 0 - 9 +struct { char text[max_text_length];// : maintext with max_text_length chars + int font_size; // : fontsize can be 1 – 8 + char font_style; // : can be S,B,I,U,N + int text_colour; // : colour number + int updated; // : update flag, TRUE/FALSE + int locked; // : locked flag, TRUE/FALSE + } KEY_RIGHT_MAINTEXT[10]; // : keys can be 0 - 9 -struct { char text[40]; // : subtext max. 40 ? chars - int text_font; // : font can be 1 – 8 - char font_style; // : can be S,B,I,U,N - int text_colour; // : colour number - int updated; // : update flag, TRUE/FALSE - int locked; // : locked flag, TRUE/FALSE - } KEY_RIGHT_SUBTEXT[10]; // : keys can be 0 - 9 +struct { char text[max_text_length];// : subtext with max_text_length chars + int font_size; // : fontsize can be 1 – 8 + char font_style; // : can be S,B,I,U,N + int text_colour; // : colour number + int updated; // : update flag, TRUE/FALSE + int locked; // : locked flag, TRUE/FALSE + } KEY_RIGHT_SUBTEXT[10]; // : keys can be 0 - 9 -struct { char text[40]; // : text max. 40 ? chars - int text_font; // : font can be 1 – 8 - char font_style; // : can be S,B,I,U,N - int text_colour; // : colour number - int updated; // : update flag, TRUE/FALSE - int locked; // : locked flag, TRUE/FALSE +struct { char text[max_text_length];// : text with max_text_length chars + int font_size; // : fontsize can be 1 – 8 + char font_style; // : can be S,B,I,U,N + int text_colour; // : colour number + int updated; // : update flag, TRUE/FALSE + int locked; // : locked flag, TRUE/FALSE } DBS_MESSAGE; -struct { char text[40]; // : text max. 40 ? chars - int text_font; // : font can be 1 – 8 - char font_style; // : can be S,B,I,U,N - int text_colour; // : colour number - int updated; // : update flag, TRUE/FALSE - int locked; // : locked flag, TRUE/FALSE +struct { char text[max_text_length];// : Title text with max_text_length chars + int font_size; // : fontsize can be 1 – 8 + char font_style; // : can be S,B,I,U,N + int text_colour; // : colour number + int updated; // : update flag, TRUE/FALSE + int locked; // : locked flag, TRUE/FALSE } TITLE_MESSAGE; -struct { char text[4]; // : text max. 4 ? chars - int text_font; // : font can be 1 – 8 - char font_style; // : can be S,B,I,U,N - int text_colour; // : colour number - int updated; // : update flag, TRUE/FALSE - int locked; // : locked flag, TRUE/FALSE +struct { char text[10]; // : text max. 10 ? chars + int font_size; // : fontsize can be 1 – 8 + char font_style; // : can be S,B,I,U,N + int text_colour; // : colour number + int updated; // : update flag, TRUE/FALSE + int locked; // : locked flag, TRUE/FALSE } PAGE_NR_MESSAGE; -struct { char text[40]; // : text max. 40 ? chars - int text_font; // : font can be 1 – 8 - char font_style; // : can be S,B,I,U,N - int text_colour; // : colour number - int updated; // : update flag, TRUE/FALSE - int locked; // : locked flag, TRUE/FALSE +struct { char text[max_text_length];// : text with max_text_length chars + int font_size; // : fontsize can be 1 – 8 + char font_style; // : can be S,B,I,U,N + int text_colour; // : colour number + int updated; // : update flag, TRUE/FALSE + int locked; // : locked flag, TRUE/FALSE } SCRATCH_MESSAGE; -struct { char text[40]; // : text max. 40 ? chars +struct { char text[max_text_length];// : text with max_text_length chars int x_pos; // : int y_pos; // : - int text_font; // : font can be 1 – 8 + int text_size; // : fontsize can be 1 – 8 char font_style; // : can be S,B,I,U,N int text_colour; // : colour number int updated; // : update flag, TRUE/FALSE int locked; // : locked flag, TRUE/FALSE } PUT_STRING_MESSAGE; -struct { char text[8]; // : text max. 8 ? chars +struct { char text[8]; // : text max. 8 chars int status_id; // : can be 0 or 1 int updated; // : update flag, TRUE/FALSE int locked; // : locked flag, TRUE/FALSE @@ -101,17 +107,62 @@ void (read_datafields(int command_number)) { + int char_pntr, a; + char textchar, textfield[max_text_length]; + switch ( command_number ) { case 0: - { + { // this is no valid commndnumber break; } case 1: - { // DSB command: - + { + while (DBS_MESSAGE.locked == TRUE) { + // --- DO NOTHING, WAIT FOR UNLOCKING !! --- + // TAKE CARE : Program can HANG if not unlocked !! + } + + DBS_MESSAGE.locked = TRUE; // : lock datastructure to prevent reading from it + + // Read fontsize F0 - F9: + char_pntr = comma[1] + 2; // : set char pointer to digit after 'F' + DBS_MESSAGE.font_size = atoi(&string_received[char_pntr]); + + // Read fontstyle : + char_pntr = comma[2] + 1; // : set char pointer to fontstyle + DBS_MESSAGE.font_style = string_received[char_pntr]; + + // Read text colour : + char_pntr = comma[3] + 1; // : set char pointer to textcolour + if (string_received[char_pntr] != ',' ) { // : colour field not empty + DBS_MESSAGE.text_colour = atoi(&string_received[char_pntr]); + } + else DBS_MESSAGE.text_colour = 0; // : empty field means colour 0 + + // Read textfield : + a = 0; + char_pntr = comma[4] + 1; // : set char pointer to textfield + do { textchar = string_received[char_pntr]; + if (textchar == '*') break; // : do not include * in text + textfield[a] = textchar; + a++; + char_pntr++; + } while ( a < max_text_length ); + strncpy(DBS_MESSAGE.text,textfield,a); // : copy chars to structure member, is a OK??? << + + // Print all for TESTING : ------------------------------------- <<<<<<<<<<<<<<<<< + USB.printf("text is : %s\n",DBS_MESSAGE.text ); // show text + USB.printf("fontsize is : %d\n",DBS_MESSAGE.font_size ); // show fontsize + USB.printf("fontstyle is : %c\n",DBS_MESSAGE.font_style ); // show fontstyle ) + USB.printf("textcolour is : %d\n",DBS_MESSAGE.text_colour ); // show textcolour + // END of TEST printing ---------------------------------------- <<<<<<<<<<<<<<<<< + + DBS_MESSAGE.updated = TRUE; // : tell update of datastructure has been done + DBS_MESSAGE.locked = FALSE; // : FREE datastructure for reading from it + break; } @@ -121,6 +172,14 @@ break; } + + + + + + + + default: {
--- a/decode_1.cpp Wed Nov 28 14:24:08 2012 +0000 +++ b/decode_1.cpp Sat Dec 01 20:53:05 2012 +0000 @@ -4,26 +4,29 @@ #define TRUE 1 #define FALSE 0 -//#define command_header "$PCDU" - - DigitalOut led4(LED4); // TEST Led4 -extern char string_received[]; // : complete string starting with $ and ending with CR/LF +extern char string_received[]; // : complete string starting with $ and ending with CR/LF +extern int nr_of_received_char; // : number of chars in string_receved[]; extern int string_complete; extern Serial USB; // >>>>>>>>>>> alleen t.b.v TEST output !! +void read_datafields(int command_number); + int command_valid; int checksum_error; char command_string[20]; // <<<<<<<<<< ? int command_number; int select_key_nr; +int comma[8]; // : array with pointers to all found commas -// Commands are defined in an array command[] of command structures : + + +// Command headers are defined in an array command[] of command structures : struct command_struct { char *name_string; // : name of command - int data_fields; // : number of following data fields after command seperated by commas + int data_fields; // : number of following data fields after commandheader seperated by commas } command[20] = { // laat aantal weg ??? <<<<<<<<<<<<<<<<<<<< ? "123",0, // : no serious command nr. 0 "DSB",4, // : command nr. 1 @@ -45,22 +48,46 @@ void decode_string() { - // -- This function checks a received string -- + // -- This decodes a received string in string_received[] -- // char *first_comma_pntr; - int char_cntr,i = 0; - int equal; - char key_id; - - if (string_complete == TRUE) { // : check flag - led4 = 1; + int char_cntr,i,c; + int equal; + char key_id, byte_read; + char checksum[2], exor_byte; + + + if (string_complete == TRUE) { // : check flag first <<<<<<<<<<<<<<<<<<< niet meer nodig ? + led4 = 1; command_valid = FALSE; key_id = '0'; select_key_nr = 0; - - // Check checksum: - // ---- komt nog -------------------------- + + // Get checksum and number of comma seperated datafields : ----------------------------- + exor_byte = 0; + i = 1; // : i points to first char after $ + c = 1; + //USB.printf("eerste kar is : %c\n",string_received[i] ); // >>>>>>>>>>>>>>>>>>>>> ( TEST !) + do { + byte_read = string_received[i]; + if (byte_read == ',' && c < 8) { + comma[c] = i; + c++; + } + if (byte_read == '*') break; + exor_byte = exor_byte ^ byte_read; + i++; + } while ( i < nr_of_received_char ); + i++; // : i points now to checksum after * char + // USB.printf("pointer i staat op : %c\n",string_received[i] ); // >>>>>>>>>>>>>>>>>>>>> ( TEST ! + strncpy(checksum,&string_received[i],2); // : copy 2 char checksum after * + // if ( exor_byte == atoi(checksum) ) + USB.printf("exor_byte, checksum, aantal kar is : %02x, %s, %d\n",exor_byte, checksum, nr_of_received_char ); // >>>>>>>>>>>>>>>>>>>>> ( TEST !) + USB.printf("aantal comma's is : %d\n",c-1 ); // >>>>>>>>>>>>>>>>>>>>> ( TEST !) + + + // ---------------------------------------------------------------------------------- // Check on 5 char "$PCDU" header: equal = strncmp(string_received,"$PCDU",5); @@ -156,7 +183,7 @@ // --------------------------------------------------- // call function to get the rest of the data fields : // --------------------------------------------------- - // read_datafields(command_number); + read_datafields(command_number); } } // end of string complete test