Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: 4DGL-UC ConfigFile MODSERIAL mbed mbos
Fork of CDU_Mbed_35 by
Revision 14:5767d651d624, committed 2014-08-14
- Comitter:
- LvdK
- Date:
- Thu Aug 14 20:18:15 2014 +0000
- Parent:
- 13:d60c746c097c
- Child:
- 15:d13786882692
- Commit message:
- 48 char bug solved.
Changed in this revision
--- a/CDU2FS_message_5.cpp Mon Jul 21 14:24:15 2014 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,84 +0,0 @@
-// L. van der Kolk, ELVEDEKA, Holland
-// File: CDU2FS_message_5.cpp
-//
-// -- Message handling from CDU to FS --
-
-#include "mbed.h"
-#include "MODSERIAL.h"
-#include "keys.h"
-//#include "debug_lvdk.h" // : debug mode control
-
-extern MODSERIAL USB;
-extern MODSERIAL SERIAL_DEBUG;
-extern int CDU_FS_interface;
-
-int key_hit_ID = 0; // : number of key that was hit, 0 = no hit of any key. ( global flag ! )
-
-char key_message[25] = "$PCDUKEY,"; // : setup begin of KEY message to FS
-char alive_message[25] = "$PCDUOKE,"; // : setup begin of ALIVE message to FS
-
-void send_message_to_FS(char *message_string) {
- // Common fnction to send a created message string (KEY or OKE) to the FS.
- // Parameter is pointer to char string that has to be sent.
- // Interface can be USB port or Ethernet port.
- int i = 0;
- if ( CDU_FS_interface == 0 ) { // : messages will be sent out by USB port
- while ( message_string[i] != '\0' ) {
- USB.putc(message_string[i]);
- i++;
- }
- }
- if ( CDU_FS_interface == 1 ) {
- // Messages will be sent out by Ehternet interface
- // -- Not implemented --
- }
-}
-
-void Send_ALIVE_message(int seconds){
- int i;
- char byte_read;
- char exor_byte = 0;
- //Create alive message:
- i = 9; // : i points to first place after "$PCDUOKE,"
- // Add seconds in 2 dec digits and a '*' char :
- sprintf(&alive_message[i],"%02d*",seconds);
- // Calculate checksum now :
- i = 1; // : i points to first place after '$'
- do { byte_read = alive_message[i];
- if (byte_read == '*') break; // : exclude '*' from exor calculation
- exor_byte = exor_byte ^ byte_read;
- i++;
- } while ( i < 20 );
- i++; // : i now points to first digit of checksum after '*'
- // Add exor_byte in 2 hex chars (with upper case A-F) and a CR + LF:
- sprintf(&alive_message[i],"%02X\r\n",exor_byte); // : + extra NULL char added by sprintf
- send_message_to_FS(alive_message); // : send message to FS
-}
-
-void Send_KEY_message(int key_nr) {
- // Function creates a valid KEY message out of key_nr parameter.
- // Based on key_nr, a key char string is looked up and added to the message.
- // After adding a checksum, the total KEY message will be sent.
- int i;
- char byte_read;
- char exor_byte = 0;
- // Create key message, starting with "$PCDUKEY," message header
- i = 9; // : i points to first position after "$PCDUKEY," message header
- // Add key string to message string including '*'
- if ( key_nr != 0 && key_nr < max_keys_CDUpanel ) {
- strcpy(&key_message[i],key_value[key_nr]);
- // Calculate checksum now :
- i = 1; // : i points to first place after '$' in message
- do { byte_read = key_message[i];
- if (byte_read == '*') break; // : exclude '*' from calculation
- exor_byte = exor_byte ^ byte_read;
- i++;
- } while ( i < 20 );
- i++; // : i now points to first digit of checksum after '*'
- // Add exor_byte in 2 hex digits and a CR + LF:
- sprintf(&key_message[i],"%02X\r\n",exor_byte); // : extra NULL char added by sprintf
- send_message_to_FS(key_message); // : send message to FS
- }
-}
-
-
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/CDU2FS_message_6.cpp Thu Aug 14 20:18:15 2014 +0000
@@ -0,0 +1,82 @@
+// L. van der Kolk, ELVEDEKA, Holland
+// File: CDU2FS_message_6.cpp
+//
+// -- Message handling from CDU to FS --
+
+#include "mbed.h"
+#include "MODSERIAL.h"
+#include "keys.h"
+
+extern MODSERIAL USB;
+extern int CDU_FS_interface;
+
+int key_hit_ID = 0; // : number of key that was hit, 0 = no hit of any key. ( global flag ! )
+
+char key_message[25] = "$PCDUKEY,"; // : setup begin of KEY message to FS
+char alive_message[25] = "$PCDUOKE,"; // : setup begin of ALIVE message to FS
+
+void send_message_to_FS(char *message_string) {
+ // Common fnction to send a created message string (KEY or OKE) to the FS.
+ // Parameter is pointer to char string that has to be sent.
+ // Interface can be USB port or Ethernet port.
+ int i = 0;
+ if ( CDU_FS_interface == 0 ) { // : messages will be sent out by USB port
+ while ( message_string[i] != '\0' ) {
+ USB.putc(message_string[i]);
+ i++;
+ }
+ }
+ if ( CDU_FS_interface == 1 ) {
+ // Messages will be sent out by Ehternet interface
+ // -- Not implemented --
+ }
+}
+
+void Send_ALIVE_message(int seconds){
+ int i;
+ char byte_read;
+ char exor_byte = 0;
+ //Create alive message:
+ i = 9; // : i points to first place after "$PCDUOKE,"
+ // Add seconds in 2 dec digits and a '*' char :
+ sprintf(&alive_message[i],"%02d*",seconds);
+ // Calculate checksum now :
+ i = 1; // : i points to first place after '$'
+ do { byte_read = alive_message[i];
+ if (byte_read == '*') break; // : exclude '*' from exor calculation
+ exor_byte = exor_byte ^ byte_read;
+ i++;
+ } while ( i < 20 );
+ i++; // : i now points to first digit of checksum after '*'
+ // Add exor_byte in 2 hex chars (with upper case A-F) and a CR + LF:
+ sprintf(&alive_message[i],"%02X\r\n",exor_byte); // : + extra NULL char added by sprintf
+ send_message_to_FS(alive_message); // : send message to FS
+}
+
+void Send_KEY_message(int key_nr) {
+ // Function creates a valid KEY message out of key_nr parameter.
+ // Based on key_nr, a key char string is looked up and added to the message.
+ // After adding a checksum, the total KEY message will be sent.
+ int i;
+ char byte_read;
+ char exor_byte = 0;
+ // Create key message, starting with "$PCDUKEY," message header
+ i = 9; // : i points to first position after "$PCDUKEY," message header
+ // Add key string to message string including '*'
+ if ( key_nr != 0 && key_nr < max_keys_CDUpanel ) {
+ strcpy(&key_message[i],key_value[key_nr]);
+ // Calculate checksum now :
+ i = 1; // : i points to first place after '$' in message
+ do { byte_read = key_message[i];
+ if (byte_read == '*') break; // : exclude '*' from calculation
+ exor_byte = exor_byte ^ byte_read;
+ i++;
+ } while ( i < 20 );
+ i++; // : i now points to first digit of checksum after '*'
+ // Add exor_byte in 2 hex digits and a CR + LF:
+ sprintf(&key_message[i],"%02X\r\n",exor_byte); // : extra NULL char added by sprintf
+ send_message_to_FS(key_message); // : send message to FS
+ }
+}
+
+
\ No newline at end of file
--- a/FS2CDU_data_5.cpp Mon Jul 21 14:24:15 2014 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,577 +0,0 @@
-
-// L. van der Kolk, ELVEDEKA, Holland //
-// File: FS2CDU_data_5.cpp
-// -- Message handling from FS to CDU --
-// Data field analyzing and filling data structures
-
-#include "mbed.h"
-#include "MODSERIAL.h"
-#include "mbos.h"
-#include "mbos_def2.h"
-
-extern mbos CDU_OS;
-
-// ---- FS-to-CDU data structures to be filled with received data ----------------
-#define max_text0 48 // max text position font 0 (pos 0 invalid )
-#define max_text1 24 // max text position font 1 (pos 0 invalid )
-#define max_lines 14 // max nr of screen lines
-#define max_col_nr 255 // highest possible R,G, or B colour number
-#define fstyle_1 'S' // possible font style character 1
-#define fstyle_2 'N' // possible font style character 2
-#define max_keys 100 // max total nr of select keys 0 - 99
-#define max_leftkeys 6 // max nr of used LEFT select keys ( 0 - 49 )
-#define max_rightkeys 6 // max nr of used RIGHT select keys ( 50 - 99 )
-
-// Background colour of CDU display:
-struct { int BG_RED; // : RED value 0 - 255
- int BG_GREEN; // : GREEN value 0 - 255
- int BG_BLUE; // : BLUE value 0 - 255
- } BACKGROUND_COL;
-
-// Maintext lines at selectkeys:
-struct { char text[55]; // : maintext string, ending with '\0'
- int font_size; // : fontsize of textline 0 or 1
- char font_style; // : style character S or N
- int text_RED; // : RED value of textline
- int text_GREEN; // : GREEN value of textline
- int text_BLUE; // : BLUE value of textline
- } SELKEY_MAINTEXT[100]; // : array of selectkey Maintext structures
-
-// Subtext lines at selectkeys:
-struct { char text[55]; // : subtext string, ending with '\0'
- int font_size; // : fontsize of textline 0 or 1
- char font_style; // : style character S or N
- int text_RED; // : RED value of textline
- int text_GREEN; // : GREEN value of textline
- int text_BLUE; // : BLUE value of textline
- } SELKEY_SUBTEXT[100]; // : array of selectkey Subtext structures
-
-// Screen textlines:
-struct { char text[55]; // : text line string, ending with '\0'
- int font_size; // : fontsize of textline 0 or 1
- char font_style; // : style character S or N
- int text_RED; // : RED value of textline
- int text_GREEN; // : GREEN value of textline
- int text_BLUE; // : BLUE value of textline
- } TEXTLINE[16]; // : array of textline structures
-
-// CDU status:
- struct { int msg_indicator; // : MSG 0 = light OFF, 1 = light ON
- int exec_indicator; // : EXEC 0 = indicator OFF, 1 = indicator ON
- int fail_indicator; // : FAIL 0 = indicator OFF, 1 = indicator ON
- int dspy_indicator; // : DSPY 0 = indicator OFF, 1 = indicator ON
- int ofst_indicator; // : OFST 0 = indicator OFF, 1 = indicator ON
- int backlight; // : 0 = light OFF, 1 = light ON
- int stby_mode; // : 0 = operational mode, 1 = standby mode
- } CDU_STATUS;
-
-
-// FS_data_update_ID:
-// These global(!) flags indicate what data has been updated:
- int Background_Col_Update = 0; // : 1 when color was updated, must be reset to 0 when data has been read
- int CDU_Status_Update = 0; // : 1 when status was updated, must be reset to 0 when data has been read
- int DO_CLR_SCREEN = 0; // : 1 when screen should be cleared, must be reset to 0 when done
- int Text_Line_Update = 0; // : equal to line number whose text was updated, must be reset to 0 when text has been read
- int Key_Maintext_Update = -1; // : equal to keynumber whose main text line was updated, must be reset to -1 (!) when text has been read
- int Key_Subtext_Update = -1; // : equal to keynumber whose sub text line was updated, must be reset to -1 (!) when text has been read
- int S_Exec = 0; // WB 20-07-14 if 1 then S+EXEC is pressed together to enter setup mode
- // -->No screen updates allowed
- // -->No key messages sent to FS
- // Setup is exited by pressing EXEC
-
-//------------- debug only ---------------------------
-extern MODSERIAL SERIAL_DEBUG; // : debug serial port
-//----------------------------------------------------
-
-extern MODSERIAL USB;
-extern char string_received[];
-extern int comma[];
-
-// Common flag to signal that an update was stored in the datastructures:
-int FSdata_received_flag = false; // : true when some FS-to-CDU data was updated
-
-void set_initial_data()
-{ // Function to fill all FS-to-CDU datastructures with (dummy) data at initial power-up conditions.
- // Prevents non-printable chars in data structures !
- int key_nr, line_nr;
- // Init background colour of screen :
- BACKGROUND_COL.BG_RED = 128;
- BACKGROUND_COL.BG_GREEN = 128;
- BACKGROUND_COL.BG_BLUE = 128;
-
- // Filling of all select key datastructures:
- // Init Maintext at left selectkeys starting from 0 :
- for ( key_nr = 0; key_nr < max_leftkeys; key_nr++ )
- { SELKEY_MAINTEXT[key_nr].text_RED = 128;
- SELKEY_MAINTEXT[key_nr].text_GREEN = 128;
- SELKEY_MAINTEXT[key_nr].text_BLUE = 128;
- SELKEY_MAINTEXT[key_nr].font_size = 0;
- SELKEY_MAINTEXT[key_nr].font_style = fstyle_1;
- strcpy(SELKEY_MAINTEXT[key_nr].text, " \0"); // some space chars
- }
- // Init Maintext at right selectkeys starting from 50 :
- for ( key_nr = 50; key_nr < (50+max_rightkeys); key_nr++ )
- { SELKEY_MAINTEXT[key_nr].text_RED = 128;
- SELKEY_MAINTEXT[key_nr].text_GREEN = 128;
- SELKEY_MAINTEXT[key_nr].text_BLUE = 128;
- SELKEY_MAINTEXT[key_nr].font_size = 0;
- SELKEY_MAINTEXT[key_nr].font_style = fstyle_1;
- strcpy(SELKEY_MAINTEXT[key_nr].text, " \0"); // some space chars
- }
- // Init Subtext at left selectkeys starting from 0 :
- for ( key_nr = 0; key_nr < max_leftkeys; key_nr++ )
- { SELKEY_SUBTEXT[key_nr].text_RED = 128;
- SELKEY_SUBTEXT[key_nr].text_GREEN = 128;
- SELKEY_SUBTEXT[key_nr].text_BLUE = 128;
- SELKEY_SUBTEXT[key_nr].font_size = 0;
- SELKEY_SUBTEXT[key_nr].font_style = fstyle_1;
- strcpy(SELKEY_SUBTEXT[key_nr].text," \0"); // some space chars
- }
- // Init Subtext at right selectkeys starting from 50 :
- for ( key_nr = 50; key_nr < (50+max_rightkeys); key_nr++ )
- { SELKEY_SUBTEXT[key_nr].text_RED = 128;
- SELKEY_SUBTEXT[key_nr].text_GREEN = 128;
- SELKEY_SUBTEXT[key_nr].text_BLUE = 128;
- SELKEY_SUBTEXT[key_nr].font_size = 0;
- SELKEY_SUBTEXT[key_nr].font_style = fstyle_1;
- strcpy(SELKEY_SUBTEXT[key_nr].text, " \0"); // some space chars
- }
-
- // Init screen text lines with space chars :
- for ( line_nr = 1; line_nr <= 14; line_nr++ )
- { TEXTLINE[line_nr].text_RED = 128;
- TEXTLINE[line_nr].text_GREEN = 128;
- TEXTLINE[line_nr].text_BLUE = 128;
- TEXTLINE[line_nr].font_size = 0;
- TEXTLINE[line_nr].font_style = fstyle_1;
- strcpy(TEXTLINE[line_nr].text, " \0"); // : all space chars
- }
- // Init CDU status items:
- CDU_STATUS.msg_indicator = 0;
- CDU_STATUS.exec_indicator = 0;
- CDU_STATUS.backlight = 0;
- CDU_STATUS.stby_mode = 0;
- CDU_STATUS.dspy_indicator = 0;
- CDU_STATUS.fail_indicator = 0;
- CDU_STATUS.ofst_indicator = 0;
-}
-
-void read_datafields(int command_number) {
- // Function to read all comma seperated datafields in string_received[] from USB
- // and fill in the FS-to-CDU data structures.
- // Parameter is found command_number by decoder.
- int colour, size, pos, line, last, cnt, k_id, a ;
- int modified, char_pntr;
- char ch;
-
- modified = false;
- //CDU_OS.LockResource(FS_DATA_RESOURCE); // : lock FS database <<--- !!
-
- switch ( command_number )
- { case 0:
- { // 0 is no valid commandnumber, do nothing
- break;
- }
-
- case 1: // MSG command, message indicator control CDU
- {
- // Get message indicator status:
- char_pntr = comma[1] + 1; // : set char pointer to char after comma 1
- if (string_received[char_pntr] == '0' || string_received[char_pntr] == '1')
- { CDU_STATUS.msg_indicator = atoi(&string_received[char_pntr]);
- CDU_Status_Update = 1;
- }
- break;
- }
-
- case 2: // EXC command, exec indicator control CDU
- {
- // Get exec indicator status:
- char_pntr = comma[1] + 1; // : set char pointer to char after comma 1
- if (string_received[char_pntr] == '0' || string_received[char_pntr] == '1')
- { CDU_STATUS.exec_indicator = atoi(&string_received[char_pntr]);
- CDU_Status_Update = 1;
- }
- break;
- }
-
- case 3: // BLT command, backlight control CDU
- {
- // Get backlight status:
- char_pntr = comma[1] + 1; // : set char pointer to char after comma 1
- if (string_received[char_pntr] == '0' || string_received[char_pntr] == '1')
- { CDU_STATUS.backlight = atoi(&string_received[char_pntr]);
- CDU_Status_Update = 1;
- }
- break;
- }
-
- case 4: // SBY command, standby control CDU
- {
- // Get standby status:
- char_pntr = comma[1] + 1; // : set char pointer to char after comma 1
- if (string_received[char_pntr] == '0' || string_received[char_pntr] == '1')
- { CDU_STATUS.stby_mode = atoi(&string_received[char_pntr]);
- CDU_Status_Update = 1;
- }
- break;
- }
-
- case 5: // CLS command, CDU clear screen control
- {
- DO_CLR_SCREEN = 1; // : tell to clear the screen
- break;
- }
-
-
- case 6: // SBC command, screen background colour control
- {
- char_pntr = comma[1] + 1; // : set char pointer to char after comma 1
- colour = atoi(&string_received[char_pntr]);
- if ( colour >= 0 && colour <= max_col_nr ) {
- BACKGROUND_COL.BG_RED = colour;
- }
- char_pntr = comma[2] + 1; // : set char pointer to char after comma 2
- colour = atoi(&string_received[char_pntr]);
- if ( colour >= 0 && colour <= max_col_nr ) {
- BACKGROUND_COL.BG_GREEN = colour;
- }
- char_pntr = comma[3] + 1; // : set char pointer to char after comma 3
- colour = atoi(&string_received[char_pntr]);
- if ( colour >= 0 && colour <= max_col_nr ) {
- BACKGROUND_COL.BG_BLUE = colour;
- }
-
- Background_Col_Update = 1; // : set update of background colour
- break;
- }
-
-
- case 7: // WTX command, write textline to CDU screen
- {
- // Read linenumber:
- char_pntr = comma[1] + 1; // : set char pointer to char after comma 1
- line = atoi(&string_received[char_pntr]);
- // Read char position:
- char_pntr = comma[2] + 1; // : set char pointer to char after comma 2
- pos = atoi(&string_received[char_pntr]);
-
- // Test if char X,Y position is within range:
- if ( line >= 1 && line <= max_lines && pos >= 1 && pos <= max_text0 )
- { // Read font size :
- char_pntr = comma[3] + 1; // : set char pointer to char after comma 3
- size = atoi(&string_received[char_pntr]);
- // Test if size is valid:
- if ( size == 0 || size == 1 ) {
- TEXTLINE[line].font_size = atoi(&string_received[char_pntr]);
- modified = true;
- }
- // Read line font style:
- char_pntr = comma[4] + 1; // : set char pointer to char after comma 4
- ch = string_received[char_pntr];
- // !! Font style check disabled:
- //if (ch == fstyle_1 || ch == fstyle_2 ) {
- TEXTLINE[line].font_style = ch;
- modified = true;
- //}
- // Read RGB line colour:
- char_pntr = comma[5] + 1; // : set char pointer to char after comma 5
- colour = atoi(&string_received[char_pntr]);
- if ( colour >= 0 && colour <= max_col_nr ) {
- TEXTLINE[line].text_RED = colour;
- modified = true;
- }
- char_pntr = comma[6] + 1; // : set char pointer to char after comma 6
- colour = atoi(&string_received[char_pntr]);
- if ( colour >= 0 && colour <= max_col_nr ) {
- TEXTLINE[line].text_GREEN = colour;
- modified = true;
- }
- char_pntr = comma[7] + 1; // : set char pointer to char after comma 7
- colour = atoi(&string_received[char_pntr]);
- if ( colour >= 0 && colour <= max_col_nr ) {
- TEXTLINE[line].text_BLUE = colour;
- modified = true;
- }
- // Read textfield :
- char_pntr = comma[8] + 1; // : set char pointer to first char of textfield
- last = 0;
- // read font size to determine last possible position:
- if ( TEXTLINE[line].font_size == 0 ) last = max_text0;
- else if ( TEXTLINE[line].font_size == 1 ) last = max_text1;
-
- if (last > 0 && pos <= last) { // : test for valid area and valid fontsize
- a = pos-1; // : !!!!!!
- while ( a <= last )
- { ch = string_received[char_pntr];
- if (ch == '*') break; // : do not include * in text
- TEXTLINE[line].text[a] = ch;
- a++;
- char_pntr++;
- }
- modified = true;
- TEXTLINE[line].text[a] = '\0'; // : mark end of text
- }
- }
-
- if ( modified == true ) {
- Text_Line_Update = line; // : set update of text line
- }
-
- // --------------- Debug only -----------------------------------------------------------------------
- //SERIAL_DEBUG.printf("\rWTX command received :\r\n");
- //SERIAL_DEBUG.printf("WTX line : %d\r\n",line ); // show line nr
- //SERIAL_DEBUG.printf("WTX begin pos : %d\r\n",pos ); // show begin position
- //SERIAL_DEBUG.printf("WTX fontsize is : %d\r\n",TEXTLINE[line].font_size ); // show fontsize
- //SERIAL_DEBUG.printf("WTX fontstyle is: %c\r\n",TEXTLINE[line].font_style); // show fontstyle
- //SERIAL_DEBUG.printf("WTX R_colour is : %d\r\n",TEXTLINE[line].text_RED ); // show textcolour
- //SERIAL_DEBUG.printf("WTX G_colour is : %d\r\n",TEXTLINE[line].text_GREEN ); // show textcolour
- //SERIAL_DEBUG.printf("WTX B_colour is : %d\r\n",TEXTLINE[line].text_BLUE ); // show textcolour
- //SERIAL_DEBUG.printf("WTX line text is: \r\n" );
- //SERIAL_DEBUG.printf("%s\r\n",TEXTLINE[line].text ); // show line text
- //----------------------------------------------------------------------------------------------------
-
- break;
- }
-
- case 8: // ETX command, erase (part of) textline of CDU screen
- {
- // Read linenumber:
- char_pntr = comma[1] + 1; // : set char pointer to char after comma 1
- line = atoi(&string_received[char_pntr]);
- // Read char position:
- char_pntr = comma[2] + 1; // : set char pointer to char after comma 2
- pos = atoi(&string_received[char_pntr]);
- // Read nr of char to be erased:
- char_pntr = comma[3] + 1; // : set char pointer to char after comma 3
- cnt = atoi(&string_received[char_pntr]);
- // Test if char X,Y position is within range:
- if ( line >= 1 && line <= max_lines && pos >= 1 && pos <= max_text0 )
- {
- last = 0;
- // read font size to determine last possible position:
- if ( TEXTLINE[line].font_size == 0 )last = max_text0;
- else if ( TEXTLINE[line].font_size == 1 )last = max_text1;
-
- if (last > 0 && pos <= last && cnt > 0) { // : test if in valid area and chars > 0
- a = pos-1; //: !!!!!!
- modified = true;
- while ( a <= last && cnt > 0)
- {
- TEXTLINE[line].text[a] = ' '; //: write space
- a++;
- cnt--;
- }
- }
- }
- if ( modified == true ) {
- Text_Line_Update = line; // : set update of text line
- }
-
- // ---------------- Debug only -----------------------------------------------
- //SERIAL_DEBUG.printf("ETX line : %d\r\n",line ); // show line nr
- //SERIAL_DEBUG.printf("ETX first erase pos : %d\r\n",pos ); // show begin pos
- //SERIAL_DEBUG.printf("ETX modified text line :\r\n" );
- //SERIAL_DEBUG.printf("%s\r\n",TEXTLINE[line].text ); // show text line
- // ---------------------------------------------------------------------------
-
- break;
- }
-
- case 9: // KTX command, write textline to select key area
- {
- // Read key ID:
- char_pntr = comma[1] + 1; // : set char pointer to char after comma 1
- k_id = atoi(&string_received[char_pntr]);
-
- // Read text type:
- char_pntr = comma[2] + 1; // : set char pointer to char after comma 2
- ch = string_received[char_pntr];
-
- if (ch == 'M' && k_id < max_keys ) // : text type = MAIN text and keyID valid
- { // Read font size :
- char_pntr = comma[3] + 1; // : set char pointer to char after comma 3
- size = atoi(&string_received[char_pntr]);
- // Test if size is valid:
- if ( size == 0 || size == 1 ) {
- SELKEY_MAINTEXT[k_id].font_size = atoi(&string_received[char_pntr]);
- modified = true;
- }
- // Read line font style:
- char_pntr = comma[4] + 1; // : set char pointer to char after comma 4
- ch = string_received[char_pntr];
- // !! Font style check disabled:
- //if (ch == fstyle_1 || ch == fstyle_2 ) {
- SELKEY_MAINTEXT[k_id].font_style = ch;
- modified = true;
- //}
- // Read RGB line colour:
- char_pntr = comma[5] + 1; // : set char pointer to char after comma 5
- colour = atoi(&string_received[char_pntr]);
- if ( colour >= 0 && colour <= max_col_nr ) {
- SELKEY_MAINTEXT[k_id].text_RED = colour;
- modified = true;
- }
- char_pntr = comma[6] + 1; // : set char pointer to char after comma 5
- colour = atoi(&string_received[char_pntr]);
- if ( colour >= 0 && colour <= max_col_nr ) {
- SELKEY_MAINTEXT[k_id].text_GREEN = colour;
- modified = true;
- }
- char_pntr = comma[7] + 1; // : set char pointer to char after comma 7
- colour = atoi(&string_received[char_pntr]);
- if ( colour >= 0 && colour <= max_col_nr ) {
- SELKEY_MAINTEXT[k_id].text_BLUE = colour;
- modified = true;
- }
- // Read textfield :
- char_pntr = comma[8] + 1; // : set char pointer to first char of textfield
- last = 0;
- // read font size to determine last possible position:
- if ( SELKEY_MAINTEXT[k_id].font_size == 0 )last = max_text0;
- else if ( SELKEY_MAINTEXT[k_id].font_size == 1 )last = max_text1;
-
- if (last > 0) { // : test on valid fontsize
- a = 0; // : !!! pos 0 !!
- modified = true;
- while ( a <= last )
- { ch = string_received[char_pntr];
- if (ch == '*') break; // : do not include * in text
- SELKEY_MAINTEXT[k_id].text[a] = ch;
- a++;
- char_pntr++;
- }
- SELKEY_MAINTEXT[k_id].text[a] = '\0'; // : mark end of text
- }
-
- if ( modified == true ) {
- Key_Maintext_Update = k_id; // : set keynumber whose main text was updated
-
- }
-
- // ----------------------- Debug only -----------------------------------------------------------------
- //SERIAL_DEBUG.printf("KTX decoded key nr is : %d\r\n\n",k_id ); // show key nr
- //SERIAL_DEBUG.printf("KTX MAINTEXT is : %s\r\n",SELKEY_MAINTEXT[k_id].text ); // show text
- //SERIAL_DEBUG.printf("KTX fontsize is : %d\r\n",SELKEY_MAINTEXT[k_id].font_size ); // show fontsize
- //SERIAL_DEBUG.printf("KTX fontstyle is: %c\r\n",SELKEY_MAINTEXT[k_id].font_style); // show fontstyle
- //SERIAL_DEBUG.printf("KTX R_colour is : %d\r\n",SELKEY_MAINTEXT[k_id].text_RED ); // show textcolour
- //SERIAL_DEBUG.printf("KTX G_colour is : %d\r\n",SELKEY_MAINTEXT[k_id].text_GREEN ); // show textcolour
- //SERIAL_DEBUG.printf("KTX B_colour is : %d\r\n",SELKEY_MAINTEXT[k_id].text_BLUE ); // show textcolour
- //----------------------------------------------------------------------------------------------------
- }
-
- else if ( ch == 'S' && k_id < max_keys ) // : text type = SUB text and keyID valid
- { // Read font size 0 - 9:
- char_pntr = comma[3] + 1; // : set char pointer to char after comma 3
- size = atoi(&string_received[char_pntr]);
- // Test if size is valid:
- if ( size == 0 || size == 1 ) {
- SELKEY_SUBTEXT[k_id].font_size = atoi(&string_received[char_pntr]);
- modified = true;
- }
- // Read line font style:
- char_pntr = comma[4] + 1; // : set char pointer to char after comma 4
- ch = string_received[char_pntr];
- if (ch == fstyle_1 || ch == fstyle_2 ) {
- SELKEY_SUBTEXT[k_id].font_style = ch;
- modified = true;
- }
- // Read RGB line colour:
- char_pntr = comma[5] + 1; // : set char pointer to char after comma 5
- colour = atoi(&string_received[char_pntr]);
- if ( colour >= 0 && colour <= max_col_nr ) {
- SELKEY_SUBTEXT[k_id].text_RED = colour;
- modified = true;
- }
- char_pntr = comma[6] + 1; // : set char pointer to char after comma 6
- colour = atoi(&string_received[char_pntr]);
- if ( colour >= 0 && colour <= max_col_nr ) {
- SELKEY_SUBTEXT[k_id].text_GREEN = colour;
- modified = true;
- }
- char_pntr = comma[7] + 1; // : set char pointer to char after comma 7
- colour = atoi(&string_received[char_pntr]);
- if ( colour >= 0 && colour <= max_col_nr ) {
- SELKEY_SUBTEXT[k_id].text_BLUE = colour;
- modified = true;
- }
- // Read textfield :
- char_pntr = comma[8] + 1; // : set char pointer to first char of textfield
- last = 0;
- // read font size to determine last possible position:
- if ( SELKEY_SUBTEXT[k_id].font_size == 0 )last = max_text0;
- else if ( SELKEY_SUBTEXT[k_id].font_size == 1 )last = max_text1;
-
- if (last > 0) { // : test on valid fontsize
- a = 0; // : !!! pos 0 !!
- modified = true;
- while ( a <= last )
- { ch = string_received[char_pntr];
- if (ch == '*') break; // : do not include * in text
- SELKEY_SUBTEXT[k_id].text[a] = ch;
- a++;
- char_pntr++;
- }
- SELKEY_SUBTEXT[k_id].text[a] = '\0'; // : mark end of text
- }
-
- if ( modified == true ) {
- Key_Subtext_Update = k_id; // : set keynumber whose sub text was updated
- }
-
- // ------------------ Debug only ----------------------------------------------------------
- //SERIAL_DEBUG.printf("KTX key nr is : %d\r\n",k_id ); // show key nr
- //SERIAL_DEBUG.printf("KTX SUBTEXT is : %s\r\n",SELKEY_SUBTEXT[k_id].text ); // show text
- //SERIAL_DEBUG.printf("KTX fontsize is : %d\r\n",SELKEY_SUBTEXT[k_id].font_size ); // show fontsize
- //SERIAL_DEBUG.printf("KTX fontstyle is: %c\r\n",SELKEY_SUBTEXT[k_id].font_style); // show fontstyle
- //SERIAL_DEBUG.printf("KTX R_colour is : %d\r\n",SELKEY_SUBTEXT[k_id].text_RED ); // show textcolour
- //SERIAL_DEBUG.printf("KTX G_colour is : %d\r\n",SELKEY_SUBTEXT[k_id].text_GREEN ); // show textcolour
- //SERIAL_DEBUG.printf("KTX B_colour is : %d\r\n",SELKEY_SUBTEXT[k_id].text_BLUE ); // show textcolour
- // -----------------------------------------------------------------------------------------
- }
- break;
- }
-
- case 10: // FAI command, FAIL indicator control CDU
- {
- // Get message indicator status:
- char_pntr = comma[1] + 1; // : set char pointer to char after comma 1
- if (string_received[char_pntr] == '0' || string_received[char_pntr] == '1')
- { CDU_STATUS.fail_indicator = atoi(&string_received[char_pntr]);
- CDU_Status_Update = 1;
- }
- break;
- }
-
- case 11: // DPY command, DISPLAY indicator control CDU
- {
- // Get message indicator status:
- char_pntr = comma[1] + 1; // : set char pointer to char after comma 1
- if (string_received[char_pntr] == '0' || string_received[char_pntr] == '1')
- { CDU_STATUS.dspy_indicator = atoi(&string_received[char_pntr]);
- CDU_Status_Update = 1;
- }
- break;
- }
-
- case 12: // OFS command, OFFSET indicator control CDU
- {
- // Get message indicator status:
- char_pntr = comma[1] + 1; // : set char pointer to char after comma 1
- if (string_received[char_pntr] == '0' || string_received[char_pntr] == '1')
- { CDU_STATUS.ofst_indicator = atoi(&string_received[char_pntr]);
- CDU_Status_Update = 1;
- }
- break;
- }
-
- default:
- {
- // unknown commandnumber !
- break;
- }
-
- }
-
- CDU_OS.SetEvent(FS_DATA_EVENT,CDU_DSP_CSS_TASK_ID); // : set event for CDU screen update task
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/FS2CDU_data_6.cpp Thu Aug 14 20:18:15 2014 +0000
@@ -0,0 +1,576 @@
+
+// L. van der Kolk, ELVEDEKA, Holland //
+// File: FS2CDU_data_6.cpp
+// -- Message handling from FS to CDU --
+// Data field analyzing and filling data structures
+
+#include "mbed.h"
+#include "MODSERIAL.h"
+#include "mbos.h"
+#include "mbos_def2.h"
+
+extern mbos CDU_OS;
+
+// ---- FS-to-CDU data structures to be filled with received data ----------------
+#define max_text0 48 // max text position font 0 (pos 0 invalid )
+#define max_text1 24 // max text position font 1 (pos 0 invalid )
+#define max_lines 14 // max nr of screen lines
+#define max_col_nr 255 // highest possible R,G, or B colour number
+#define fstyle_1 'S' // possible font style character 1
+#define fstyle_2 'N' // possible font style character 2
+#define max_keys 100 // max total nr of select keys 0 - 99
+#define max_leftkeys 6 // max nr of used LEFT select keys ( 0 - 49 )
+#define max_rightkeys 6 // max nr of used RIGHT select keys ( 50 - 99 )
+
+// Background colour of CDU display:
+struct { int BG_RED; // : RED value 0 - 255
+ int BG_GREEN; // : GREEN value 0 - 255
+ int BG_BLUE; // : BLUE value 0 - 255
+ } BACKGROUND_COL;
+
+// Maintext lines at selectkeys:
+struct { char text[55]; // : maintext string, ending with '\0'
+ int font_size; // : fontsize of textline 0 or 1
+ char font_style; // : style character S or N
+ int text_RED; // : RED value of textline
+ int text_GREEN; // : GREEN value of textline
+ int text_BLUE; // : BLUE value of textline
+ } SELKEY_MAINTEXT[100]; // : array of selectkey Maintext structures
+
+// Subtext lines at selectkeys:
+struct { char text[55]; // : subtext string, ending with '\0'
+ int font_size; // : fontsize of textline 0 or 1
+ char font_style; // : style character S or N
+ int text_RED; // : RED value of textline
+ int text_GREEN; // : GREEN value of textline
+ int text_BLUE; // : BLUE value of textline
+ } SELKEY_SUBTEXT[100]; // : array of selectkey Subtext structures
+
+// Screen textlines:
+struct { char text[55]; // : text line string, ending with '\0'
+ int font_size; // : fontsize of textline 0 or 1
+ char font_style; // : style character S or N
+ int text_RED; // : RED value of textline
+ int text_GREEN; // : GREEN value of textline
+ int text_BLUE; // : BLUE value of textline
+ } TEXTLINE[16]; // : array of textline structures
+
+// CDU status:
+ struct { int msg_indicator; // : MSG 0 = light OFF, 1 = light ON
+ int exec_indicator; // : EXEC 0 = indicator OFF, 1 = indicator ON
+ int fail_indicator; // : FAIL 0 = indicator OFF, 1 = indicator ON
+ int dspy_indicator; // : DSPY 0 = indicator OFF, 1 = indicator ON
+ int ofst_indicator; // : OFST 0 = indicator OFF, 1 = indicator ON
+ int backlight; // : 0 = light OFF, 1 = light ON
+ int stby_mode; // : 0 = operational mode, 1 = standby mode
+ } CDU_STATUS;
+
+
+// FS_data_update_ID:
+// These global(!) flags indicate what data has been updated:
+ int Background_Col_Update = 0; // : 1 when color was updated, must be reset to 0 when data has been read
+ int CDU_Status_Update = 0; // : 1 when status was updated, must be reset to 0 when data has been read
+ int DO_CLR_SCREEN = 0; // : 1 when screen should be cleared, must be reset to 0 when done
+ int Text_Line_Update = 0; // : equal to line number whose text was updated, must be reset to 0 when text has been read
+ int Key_Maintext_Update = -1; // : equal to keynumber whose main text line was updated, must be reset to -1 (!) when text has been read
+ int Key_Subtext_Update = -1; // : equal to keynumber whose sub text line was updated, must be reset to -1 (!) when text has been read
+ int S_Exec = 0; // WB 20-07-14 if 1 then S+EXEC is pressed together to enter setup mode
+ // -->No screen updates allowed
+ // -->No key messages sent to FS
+ // Setup is exited by pressing EXEC
+
+//------------- debug only ---------------------------
+//extern MODSERIAL SERIAL_DEBUG; // : debug serial port
+//----------------------------------------------------
+
+extern MODSERIAL USB;
+extern char string_received[];
+extern int comma[];
+
+// Common flag to signal that an update was stored in the datastructures:
+int FSdata_received_flag = false; // : true when some FS-to-CDU data was updated
+
+void set_initial_data()
+{ // Function to fill all FS-to-CDU datastructures with (dummy) data at initial power-up conditions.
+ // Prevents non-printable chars in data structures !
+ int key_nr, line_nr;
+ // Init background colour of screen :
+ BACKGROUND_COL.BG_RED = 128;
+ BACKGROUND_COL.BG_GREEN = 128;
+ BACKGROUND_COL.BG_BLUE = 128;
+
+ // Filling of all select key datastructures:
+ // Init Maintext at left selectkeys starting from 0 :
+ for ( key_nr = 0; key_nr < max_leftkeys; key_nr++ )
+ { SELKEY_MAINTEXT[key_nr].text_RED = 128;
+ SELKEY_MAINTEXT[key_nr].text_GREEN = 128;
+ SELKEY_MAINTEXT[key_nr].text_BLUE = 128;
+ SELKEY_MAINTEXT[key_nr].font_size = 0;
+ SELKEY_MAINTEXT[key_nr].font_style = fstyle_1;
+ strcpy(SELKEY_MAINTEXT[key_nr].text, " \0"); // some space chars
+ }
+ // Init Maintext at right selectkeys starting from 50 :
+ for ( key_nr = 50; key_nr < (50+max_rightkeys); key_nr++ )
+ { SELKEY_MAINTEXT[key_nr].text_RED = 128;
+ SELKEY_MAINTEXT[key_nr].text_GREEN = 128;
+ SELKEY_MAINTEXT[key_nr].text_BLUE = 128;
+ SELKEY_MAINTEXT[key_nr].font_size = 0;
+ SELKEY_MAINTEXT[key_nr].font_style = fstyle_1;
+ strcpy(SELKEY_MAINTEXT[key_nr].text, " \0"); // some space chars
+ }
+ // Init Subtext at left selectkeys starting from 0 :
+ for ( key_nr = 0; key_nr < max_leftkeys; key_nr++ )
+ { SELKEY_SUBTEXT[key_nr].text_RED = 128;
+ SELKEY_SUBTEXT[key_nr].text_GREEN = 128;
+ SELKEY_SUBTEXT[key_nr].text_BLUE = 128;
+ SELKEY_SUBTEXT[key_nr].font_size = 0;
+ SELKEY_SUBTEXT[key_nr].font_style = fstyle_1;
+ strcpy(SELKEY_SUBTEXT[key_nr].text," \0"); // some space chars
+ }
+ // Init Subtext at right selectkeys starting from 50 :
+ for ( key_nr = 50; key_nr < (50+max_rightkeys); key_nr++ )
+ { SELKEY_SUBTEXT[key_nr].text_RED = 128;
+ SELKEY_SUBTEXT[key_nr].text_GREEN = 128;
+ SELKEY_SUBTEXT[key_nr].text_BLUE = 128;
+ SELKEY_SUBTEXT[key_nr].font_size = 0;
+ SELKEY_SUBTEXT[key_nr].font_style = fstyle_1;
+ strcpy(SELKEY_SUBTEXT[key_nr].text, " \0"); // some space chars
+ }
+
+ // Init screen text lines with space chars :
+ for ( line_nr = 1; line_nr <= 14; line_nr++ )
+ { TEXTLINE[line_nr].text_RED = 128;
+ TEXTLINE[line_nr].text_GREEN = 128;
+ TEXTLINE[line_nr].text_BLUE = 128;
+ TEXTLINE[line_nr].font_size = 0;
+ TEXTLINE[line_nr].font_style = fstyle_1;
+ strcpy(TEXTLINE[line_nr].text, " \0"); // : 48 space chars
+ }
+ // Init CDU status items:
+ CDU_STATUS.msg_indicator = 0;
+ CDU_STATUS.exec_indicator = 0;
+ CDU_STATUS.backlight = 0;
+ CDU_STATUS.stby_mode = 0;
+ CDU_STATUS.dspy_indicator = 0;
+ CDU_STATUS.fail_indicator = 0;
+ CDU_STATUS.ofst_indicator = 0;
+}
+
+void read_datafields(int command_number) {
+ // Function to read all comma seperated datafields in string_received[] from USB
+ // and fill in the FS-to-CDU data structures.
+ // Parameter is found command_number by decoder.
+ int colour, size, pos, line, last, cnt, k_id, a ;
+ int modified, char_pntr;
+ char ch;
+
+ modified = false;
+
+ switch ( command_number )
+ { case 0:
+ { // 0 is no valid commandnumber, do nothing
+ break;
+ }
+
+ case 1: // MSG command, message indicator control CDU
+ {
+ // Get message indicator status:
+ char_pntr = comma[1] + 1; // : set char pointer to char after comma 1
+ if (string_received[char_pntr] == '0' || string_received[char_pntr] == '1')
+ { CDU_STATUS.msg_indicator = atoi(&string_received[char_pntr]);
+ CDU_Status_Update = 1;
+ }
+ break;
+ }
+
+ case 2: // EXC command, exec indicator control CDU
+ {
+ // Get exec indicator status:
+ char_pntr = comma[1] + 1; // : set char pointer to char after comma 1
+ if (string_received[char_pntr] == '0' || string_received[char_pntr] == '1')
+ { CDU_STATUS.exec_indicator = atoi(&string_received[char_pntr]);
+ CDU_Status_Update = 1;
+ }
+ break;
+ }
+
+ case 3: // BLT command, backlight control CDU
+ {
+ // Get backlight status:
+ char_pntr = comma[1] + 1; // : set char pointer to char after comma 1
+ if (string_received[char_pntr] == '0' || string_received[char_pntr] == '1')
+ { CDU_STATUS.backlight = atoi(&string_received[char_pntr]);
+ CDU_Status_Update = 1;
+ }
+ break;
+ }
+
+ case 4: // SBY command, standby control CDU
+ {
+ // Get standby status:
+ char_pntr = comma[1] + 1; // : set char pointer to char after comma 1
+ if (string_received[char_pntr] == '0' || string_received[char_pntr] == '1')
+ { CDU_STATUS.stby_mode = atoi(&string_received[char_pntr]);
+ CDU_Status_Update = 1;
+ }
+ break;
+ }
+
+ case 5: // CLS command, CDU clear screen control
+ {
+ DO_CLR_SCREEN = 1; // : tell to clear the screen
+ break;
+ }
+
+
+ case 6: // SBC command, screen background colour control
+ {
+ char_pntr = comma[1] + 1; // : set char pointer to char after comma 1
+ colour = atoi(&string_received[char_pntr]);
+ if ( colour >= 0 && colour <= max_col_nr ) {
+ BACKGROUND_COL.BG_RED = colour;
+ }
+ char_pntr = comma[2] + 1; // : set char pointer to char after comma 2
+ colour = atoi(&string_received[char_pntr]);
+ if ( colour >= 0 && colour <= max_col_nr ) {
+ BACKGROUND_COL.BG_GREEN = colour;
+ }
+ char_pntr = comma[3] + 1; // : set char pointer to char after comma 3
+ colour = atoi(&string_received[char_pntr]);
+ if ( colour >= 0 && colour <= max_col_nr ) {
+ BACKGROUND_COL.BG_BLUE = colour;
+ }
+
+ Background_Col_Update = 1; // : set update of background colour
+ break;
+ }
+
+
+ case 7: // WTX command, write textline to CDU screen
+ {
+ // Read linenumber:
+ char_pntr = comma[1] + 1; // : set char pointer to char after comma 1
+ line = atoi(&string_received[char_pntr]);
+ // Read char position:
+ char_pntr = comma[2] + 1; // : set char pointer to char after comma 2
+ pos = atoi(&string_received[char_pntr]);
+
+ // Test if char X,Y position is within range:
+ if ( line >= 1 && line <= max_lines && pos >= 1 && pos <= max_text0 )
+ { // Read font size :
+ char_pntr = comma[3] + 1; // : set char pointer to char after comma 3
+ size = atoi(&string_received[char_pntr]);
+ // Test if size is valid:
+ if ( size == 0 || size == 1 ) {
+ TEXTLINE[line].font_size = atoi(&string_received[char_pntr]);
+ modified = true;
+ }
+ // Read line font style:
+ char_pntr = comma[4] + 1; // : set char pointer to char after comma 4
+ ch = string_received[char_pntr];
+ // !! Font style check disabled:
+ //if (ch == fstyle_1 || ch == fstyle_2 ) {
+ TEXTLINE[line].font_style = ch;
+ modified = true;
+ //}
+ // Read RGB line colour:
+ char_pntr = comma[5] + 1; // : set char pointer to char after comma 5
+ colour = atoi(&string_received[char_pntr]);
+ if ( colour >= 0 && colour <= max_col_nr ) {
+ TEXTLINE[line].text_RED = colour;
+ modified = true;
+ }
+ char_pntr = comma[6] + 1; // : set char pointer to char after comma 6
+ colour = atoi(&string_received[char_pntr]);
+ if ( colour >= 0 && colour <= max_col_nr ) {
+ TEXTLINE[line].text_GREEN = colour;
+ modified = true;
+ }
+ char_pntr = comma[7] + 1; // : set char pointer to char after comma 7
+ colour = atoi(&string_received[char_pntr]);
+ if ( colour >= 0 && colour <= max_col_nr ) {
+ TEXTLINE[line].text_BLUE = colour;
+ modified = true;
+ }
+ // Read textfield :
+ char_pntr = comma[8] + 1; // : set char pointer to first char of textfield
+ last = 0;
+ // read font size to determine last possible position:
+ if ( TEXTLINE[line].font_size == 0 ) last = max_text0;
+ else if ( TEXTLINE[line].font_size == 1 ) last = max_text1;
+
+ if (last > 0 && pos <= last) { // : test for valid area and valid fontsize
+ a = pos-1; // : !!!!!!
+ while ( a <= last )
+ { ch = string_received[char_pntr];
+ if (ch == '*') break; // : do not include * in text
+ TEXTLINE[line].text[a] = ch;
+ a++;
+ char_pntr++;
+ }
+ modified = true;
+ TEXTLINE[line].text[a] = '\0'; // : mark end of text
+ }
+ }
+
+ if ( modified == true ) {
+ Text_Line_Update = line; // : set update of text line
+ }
+
+ // --------------- Debug only -----------------------------------------------------------------------
+ //SERIAL_DEBUG.printf("\rWTX command received :\r\n");
+ //SERIAL_DEBUG.printf("WTX line : %d\r\n",line ); // show line nr
+ //SERIAL_DEBUG.printf("WTX begin pos : %d\r\n",pos ); // show begin position
+ //SERIAL_DEBUG.printf("WTX fontsize is : %d\r\n",TEXTLINE[line].font_size ); // show fontsize
+ //SERIAL_DEBUG.printf("WTX fontstyle is: %c\r\n",TEXTLINE[line].font_style); // show fontstyle
+ //SERIAL_DEBUG.printf("WTX R_colour is : %d\r\n",TEXTLINE[line].text_RED ); // show textcolour
+ //SERIAL_DEBUG.printf("WTX G_colour is : %d\r\n",TEXTLINE[line].text_GREEN ); // show textcolour
+ //SERIAL_DEBUG.printf("WTX B_colour is : %d\r\n",TEXTLINE[line].text_BLUE ); // show textcolour
+ //SERIAL_DEBUG.printf("WTX line text is: \r\n" );
+ //SERIAL_DEBUG.printf("%s\r\n",TEXTLINE[line].text ); // show line text
+ //----------------------------------------------------------------------------------------------------
+
+ break;
+ }
+
+ case 8: // ETX command, erase (part of) textline of CDU screen
+ {
+ // Read linenumber:
+ char_pntr = comma[1] + 1; // : set char pointer to char after comma 1
+ line = atoi(&string_received[char_pntr]);
+ // Read char position:
+ char_pntr = comma[2] + 1; // : set char pointer to char after comma 2
+ pos = atoi(&string_received[char_pntr]);
+ // Read nr of char to be erased:
+ char_pntr = comma[3] + 1; // : set char pointer to char after comma 3
+ cnt = atoi(&string_received[char_pntr]);
+ // Test if char X,Y position is within range:
+ if ( line >= 1 && line <= max_lines && pos >= 1 && pos <= max_text0 )
+ {
+ last = 0;
+ // read font size to determine last possible position:
+ if ( TEXTLINE[line].font_size == 0 )last = max_text0;
+ else if ( TEXTLINE[line].font_size == 1 )last = max_text1;
+
+ if (last > 0 && pos <= last && cnt > 0) { // : test if in valid area and chars > 0
+ a = pos-1; //: !!!!!!
+ modified = true;
+ while ( a <= last && cnt > 0)
+ {
+ TEXTLINE[line].text[a] = ' '; //: write space
+ a++;
+ cnt--;
+ }
+ }
+ }
+ if ( modified == true ) {
+ Text_Line_Update = line; // : set update of text line
+ }
+
+ // ---------------- Debug only -----------------------------------------------
+ //SERIAL_DEBUG.printf("ETX line : %d\r\n",line ); // show line nr
+ //SERIAL_DEBUG.printf("ETX first erase pos : %d\r\n",pos ); // show begin pos
+ //SERIAL_DEBUG.printf("ETX modified text line :\r\n" );
+ //SERIAL_DEBUG.printf("%s\r\n",TEXTLINE[line].text ); // show text line
+ // ---------------------------------------------------------------------------
+
+ break;
+ }
+
+ case 9: // KTX command, write textline to select key area
+ {
+ // Read key ID:
+ char_pntr = comma[1] + 1; // : set char pointer to char after comma 1
+ k_id = atoi(&string_received[char_pntr]);
+
+ // Read text type:
+ char_pntr = comma[2] + 1; // : set char pointer to char after comma 2
+ ch = string_received[char_pntr];
+
+ if (ch == 'M' && k_id < max_keys ) // : text type = MAIN text and keyID valid
+ { // Read font size :
+ char_pntr = comma[3] + 1; // : set char pointer to char after comma 3
+ size = atoi(&string_received[char_pntr]);
+ // Test if size is valid:
+ if ( size == 0 || size == 1 ) {
+ SELKEY_MAINTEXT[k_id].font_size = atoi(&string_received[char_pntr]);
+ modified = true;
+ }
+ // Read line font style:
+ char_pntr = comma[4] + 1; // : set char pointer to char after comma 4
+ ch = string_received[char_pntr];
+ // !! Font style check disabled:
+ //if (ch == fstyle_1 || ch == fstyle_2 ) {
+ SELKEY_MAINTEXT[k_id].font_style = ch;
+ modified = true;
+ //}
+ // Read RGB line colour:
+ char_pntr = comma[5] + 1; // : set char pointer to char after comma 5
+ colour = atoi(&string_received[char_pntr]);
+ if ( colour >= 0 && colour <= max_col_nr ) {
+ SELKEY_MAINTEXT[k_id].text_RED = colour;
+ modified = true;
+ }
+ char_pntr = comma[6] + 1; // : set char pointer to char after comma 5
+ colour = atoi(&string_received[char_pntr]);
+ if ( colour >= 0 && colour <= max_col_nr ) {
+ SELKEY_MAINTEXT[k_id].text_GREEN = colour;
+ modified = true;
+ }
+ char_pntr = comma[7] + 1; // : set char pointer to char after comma 7
+ colour = atoi(&string_received[char_pntr]);
+ if ( colour >= 0 && colour <= max_col_nr ) {
+ SELKEY_MAINTEXT[k_id].text_BLUE = colour;
+ modified = true;
+ }
+ // Read textfield :
+ char_pntr = comma[8] + 1; // : set char pointer to first char of textfield
+ last = 0;
+ // read font size to determine last possible position:
+ if ( SELKEY_MAINTEXT[k_id].font_size == 0 )last = max_text0;
+ else if ( SELKEY_MAINTEXT[k_id].font_size == 1 )last = max_text1;
+
+ if (last > 0) { // : test on valid fontsize
+ a = 0; // : !!! pos 0 !!
+ modified = true;
+ while ( a <= last )
+ { ch = string_received[char_pntr];
+ if (ch == '*') break; // : do not include * in text
+ SELKEY_MAINTEXT[k_id].text[a] = ch;
+ a++;
+ char_pntr++;
+ }
+ SELKEY_MAINTEXT[k_id].text[a] = '\0'; // : mark end of text
+ }
+
+ if ( modified == true ) {
+ Key_Maintext_Update = k_id; // : set keynumber whose main text was updated
+
+ }
+
+ // ----------------------- Debug only -----------------------------------------------------------------
+ //SERIAL_DEBUG.printf("KTX decoded key nr is : %d\r\n\n",k_id ); // show key nr
+ //SERIAL_DEBUG.printf("KTX MAINTEXT is : %s\r\n",SELKEY_MAINTEXT[k_id].text ); // show text
+ //SERIAL_DEBUG.printf("KTX fontsize is : %d\r\n",SELKEY_MAINTEXT[k_id].font_size ); // show fontsize
+ //SERIAL_DEBUG.printf("KTX fontstyle is: %c\r\n",SELKEY_MAINTEXT[k_id].font_style); // show fontstyle
+ //SERIAL_DEBUG.printf("KTX R_colour is : %d\r\n",SELKEY_MAINTEXT[k_id].text_RED ); // show textcolour
+ //SERIAL_DEBUG.printf("KTX G_colour is : %d\r\n",SELKEY_MAINTEXT[k_id].text_GREEN ); // show textcolour
+ //SERIAL_DEBUG.printf("KTX B_colour is : %d\r\n",SELKEY_MAINTEXT[k_id].text_BLUE ); // show textcolour
+ //----------------------------------------------------------------------------------------------------
+ }
+
+ else if ( ch == 'S' && k_id < max_keys ) // : text type = SUB text and keyID valid
+ { // Read font size 0 - 9:
+ char_pntr = comma[3] + 1; // : set char pointer to char after comma 3
+ size = atoi(&string_received[char_pntr]);
+ // Test if size is valid:
+ if ( size == 0 || size == 1 ) {
+ SELKEY_SUBTEXT[k_id].font_size = atoi(&string_received[char_pntr]);
+ modified = true;
+ }
+ // Read line font style:
+ char_pntr = comma[4] + 1; // : set char pointer to char after comma 4
+ ch = string_received[char_pntr];
+ if (ch == fstyle_1 || ch == fstyle_2 ) {
+ SELKEY_SUBTEXT[k_id].font_style = ch;
+ modified = true;
+ }
+ // Read RGB line colour:
+ char_pntr = comma[5] + 1; // : set char pointer to char after comma 5
+ colour = atoi(&string_received[char_pntr]);
+ if ( colour >= 0 && colour <= max_col_nr ) {
+ SELKEY_SUBTEXT[k_id].text_RED = colour;
+ modified = true;
+ }
+ char_pntr = comma[6] + 1; // : set char pointer to char after comma 6
+ colour = atoi(&string_received[char_pntr]);
+ if ( colour >= 0 && colour <= max_col_nr ) {
+ SELKEY_SUBTEXT[k_id].text_GREEN = colour;
+ modified = true;
+ }
+ char_pntr = comma[7] + 1; // : set char pointer to char after comma 7
+ colour = atoi(&string_received[char_pntr]);
+ if ( colour >= 0 && colour <= max_col_nr ) {
+ SELKEY_SUBTEXT[k_id].text_BLUE = colour;
+ modified = true;
+ }
+ // Read textfield :
+ char_pntr = comma[8] + 1; // : set char pointer to first char of textfield
+ last = 0;
+ // read font size to determine last possible position:
+ if ( SELKEY_SUBTEXT[k_id].font_size == 0 )last = max_text0;
+ else if ( SELKEY_SUBTEXT[k_id].font_size == 1 )last = max_text1;
+
+ if (last > 0) { // : test on valid fontsize
+ a = 0; // : !!! pos 0 !!
+ modified = true;
+ while ( a <= last )
+ { ch = string_received[char_pntr];
+ if (ch == '*') break; // : do not include * in text
+ SELKEY_SUBTEXT[k_id].text[a] = ch;
+ a++;
+ char_pntr++;
+ }
+ SELKEY_SUBTEXT[k_id].text[a] = '\0'; // : mark end of text
+ }
+
+ if ( modified == true ) {
+ Key_Subtext_Update = k_id; // : set keynumber whose sub text was updated
+ }
+
+ // ------------------ Debug only ----------------------------------------------------------
+ //SERIAL_DEBUG.printf("KTX key nr is : %d\r\n",k_id ); // show key nr
+ //SERIAL_DEBUG.printf("KTX SUBTEXT is : %s\r\n",SELKEY_SUBTEXT[k_id].text ); // show text
+ //SERIAL_DEBUG.printf("KTX fontsize is : %d\r\n",SELKEY_SUBTEXT[k_id].font_size ); // show fontsize
+ //SERIAL_DEBUG.printf("KTX fontstyle is: %c\r\n",SELKEY_SUBTEXT[k_id].font_style); // show fontstyle
+ //SERIAL_DEBUG.printf("KTX R_colour is : %d\r\n",SELKEY_SUBTEXT[k_id].text_RED ); // show textcolour
+ //SERIAL_DEBUG.printf("KTX G_colour is : %d\r\n",SELKEY_SUBTEXT[k_id].text_GREEN ); // show textcolour
+ //SERIAL_DEBUG.printf("KTX B_colour is : %d\r\n",SELKEY_SUBTEXT[k_id].text_BLUE ); // show textcolour
+ // -----------------------------------------------------------------------------------------
+ }
+ break;
+ }
+
+ case 10: // FAI command, FAIL indicator control CDU
+ {
+ // Get message indicator status:
+ char_pntr = comma[1] + 1; // : set char pointer to char after comma 1
+ if (string_received[char_pntr] == '0' || string_received[char_pntr] == '1')
+ { CDU_STATUS.fail_indicator = atoi(&string_received[char_pntr]);
+ CDU_Status_Update = 1;
+ }
+ break;
+ }
+
+ case 11: // DPY command, DISPLAY indicator control CDU
+ {
+ // Get message indicator status:
+ char_pntr = comma[1] + 1; // : set char pointer to char after comma 1
+ if (string_received[char_pntr] == '0' || string_received[char_pntr] == '1')
+ { CDU_STATUS.dspy_indicator = atoi(&string_received[char_pntr]);
+ CDU_Status_Update = 1;
+ }
+ break;
+ }
+
+ case 12: // OFS command, OFFSET indicator control CDU
+ {
+ // Get message indicator status:
+ char_pntr = comma[1] + 1; // : set char pointer to char after comma 1
+ if (string_received[char_pntr] == '0' || string_received[char_pntr] == '1')
+ { CDU_STATUS.ofst_indicator = atoi(&string_received[char_pntr]);
+ CDU_Status_Update = 1;
+ }
+ break;
+ }
+
+ default:
+ {
+ // unknown commandnumber !
+ break;
+ }
+
+ }
+
+ CDU_OS.SetEvent(FS_DATA_EVENT,CDU_DSP_CSS_TASK_ID); // : set event for CDU screen update task
+}
--- a/USB_receive_5.cpp Mon Jul 21 14:24:15 2014 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,199 +0,0 @@
-// L. van der Kolk, ELVEDEKA, Holland //
-// File: USB_receive_5.cpp
-
-#include "mbed.h"
-#include "MODSERIAL.h"
-
-extern MODSERIAL USB;
-
-extern int FSdata_received_flag;
-
-//------- debug only ---------------------
-extern MODSERIAL SERIAL_DEBUG;
-//----------------------------------------
-
-void decode_string(int nummer_of_chars);
-void read_datafields(int command_number);
-
-#define max_string_length 80 // : max length of received string starting with $ and ending with CR/LF
-#define min_string_length 10 // : min length of received string starting with $ and ending with CR/LF
-char string_received[max_string_length + 2]; // : holds received string starting with $ and ending with CR/LF
-
-#define message_header "$PCDU" // : common message header in all messages
-#define max_commas 10 // : max. nr of possible field separating commas in a valid message string to CDU
-int comma[max_commas]; // : array with positions of all found commas in string_receved[]
-
-#define max_nr_of_commands 13 // : max nr of possible FS-to-CDU commands
-// Define array of pointers to possible FS-to-CDU commands with 3 characters:
-const char *command[max_nr_of_commands] = {
- "123", // : no valid CDU command nr. 0 , used for debugging only
- "MSG", // : command nr. 1
- "EXC", // : command nr. 2
- "BLT", // : command nr. 3
- "SBY", // : command nr. 4
- "CLS", // : command nr. 5
- "SBC", // : command nr. 6
- "WTX", // : command nr. 7
- "ETX", // : command nr. 8
- "KTX", // : command nr. 9
- "FAI", // : command nr.10
- "DPY", // : command nr.11
- "OFS", // : command nr.12
-};
-
-void collect_FSdata() {
- // Function reads characters from FS written in receive buffer.
- // Wiil be called after each RX receive interrupt, so characters will allways be stored.
- // When analyze_busy is false, function will start reading characters from defined buffer and
- // collects strings starting with $ and ending with CR/LF.
- // Strings shorter than min_string_length or longer than max_string_length will be ignored,
- // others will be analyzed further.
- // After analyzing, flag analyze_busy will be set to false again.
- static int $_detected = false; // : no valid begin of string detected (init only on first call)
- static int string_pntr = 0; // : pointer at begin of string (init only on first call)
- static int nr_of_received_char = 0; // : counter of received characters (init only on first call)
- char rx_char; // : character which is analyzed
-
- if ( FSdata_received_flag == false ) { // : process received chars only if no decoding busy now
- while ( !USB.rxBufferEmpty() ) // : do as long as USB receive buffer is not empty
- { rx_char = USB.getc(); // : get a char from Rx buffer
-
- // ----------- Debug only ! ---------------------------------------------
- //SERIAL_DEBUG.putc(rx_char); // : unprotected immediate echo of char
- // ----------------------------------------------------------------------
-
- // Check for string starting with $ char:
- if ( rx_char == '$' && $_detected == false ){
- $_detected = true; // : begin of string is detected
- string_pntr = 0; // : set pointer to begin of string_received[] buffer
- }
- string_received[string_pntr] = rx_char;
- string_pntr++;
- if (string_pntr >= max_string_length) {
- // command string looks too long, so start all over again:
- string_pntr = 0; // : set pointer back to begin of string_received[] again
- nr_of_received_char = 0; // : reset number of received chars
- $_detected = false;
- FSdata_received_flag = false;
- }
- if ( rx_char == '\r' && $_detected == true ) {
- if ( string_pntr > min_string_length ) { // : check minimum string length
- // Received string can be interesting now because
- // it starts with '$' AND it ends on New-Line AND
- // it has a minimum length AND it is not too long:
- string_received[string_pntr] = '\0'; // : mark end of string
-
- FSdata_received_flag = true;
-
- // ----------- Debug only ! -------------------------------------------
- // SERIAL_DEBUG.printf("string_received from USB: %s",string_received );
- // --------------------------------------------------------------------
-
- nr_of_received_char = string_pntr;
- //Call decoder to analyse this string:
- decode_string(nr_of_received_char);
- // Get ready for receiving new commands:
- $_detected = false;
- string_pntr = 0; // : set pointer back to begin of string_received[] again
- nr_of_received_char = 0; // : reset number of received chars
- }
- else {
- $_detected = false;
- string_pntr = 0; // : set pointer back to begin of string_received[] again
- nr_of_received_char = 0; // : reset number of received chars
- FSdata_received_flag = false;
- }
- }
- }
-
- }
-}
-
-void decode_string(int nummer_of_chars)
-{ // -- This function decodes a received $.....CR/LF string written in string_received[] --
- // First it checks for a valid checksum and reads the positions of commas in the string.
- // If checksum is OK, it will continue to look for valid 3 char FS-to-CDU commands.
- // When a valid command is found, data fields will be analyzed further using the found positions
- // of commas in the string.
- int i,c, equal;
- char byte_read, exor_byte;
- char command_string[6], received_checksum[4], calc_checksum[4];
- // Get checksum and position of commas in string_received[] :
- exor_byte = 0;
- i = 1; // : i points to first char after $
- c = 1; // : position of first comma
- do {
- byte_read = string_received[i];
- if (byte_read == ',' && c < max_commas) {
- comma[c] = i;
- c++;
- }
- if (byte_read == '*') break;
- exor_byte = exor_byte ^ byte_read;
- i++;
- } while ( i < nummer_of_chars );
-
-
- // ----------- Debug only -------------------------------------------
- //SERIAL_DEBUG.printf("commas found : %d\n",c-1 ); // : show commas
- // ------------------------------------------------------------------
-
- i++; // : i points to first checksum char after char *
- strncpy(received_checksum,&string_received[i],2); // : copy 2 char checksum after *
- // Get calculated checksum by transforming exor_byte in 2 hex chars (with upper case A-F) :
- sprintf(calc_checksum,"%02X",exor_byte); // : + extra NULL char added by sprintf
- equal = strncmp(received_checksum,calc_checksum,2);
-
- // ******************************************************************************************
- // -- Force checksum to allways OK : < -- debug only !!
- equal = 0;
- // ******************************************************************************************
-
- if (equal != 0) {
- // ----------- Debug only -------------------------------------------------------
- //SERIAL_DEBUG.printf("checksum is NOT OK ! \n" ); // : show message for debugging
- // ------------------------------------------------------------------------------
- FSdata_received_flag = false;
- }
- else { // checksum is OK, go on:
- // Check for 5 char "$PCDU" header:
- equal = strncmp(string_received,message_header,strlen(message_header));
- if (equal != 0) {
-
- // ----------- Debug only ---------------------------------------------------
- //SERIAL_DEBUG.printf("no $PCDU header in message !\n" ); // : show message
- // --------------------------------------------------------------------------
-
- FSdata_received_flag = false;
- }
- else {
- // Read 3 char command after message_header:
- strncpy(command_string,&string_received[strlen(message_header)],3);
-
- // ----------- Debug only ---------------------------------------------------------------------
- //SERIAL_DEBUG.printf("\ncommand found : %3s\n",command_string ); // : show command for debugging
- //SERIAL_DEBUG.printf("commas found : %d\n",c-1 ); // : show commas for debugging
- // --------------------------------------------------------------------------------------------
-
- // Compare found string with known 3 char command list:
- i = 0;
- do {
- equal = strncmp(&command_string[0],command[i],3);
- if( equal == 0) break;
- i++;
- } while ( i < max_nr_of_commands);
-
- // ----------- Debug only ---------------------------------------------------------------
- //SERIAL_DEBUG.printf("command number is : %d\n",i ); // : show command nr for debugging
- // --------------------------------------------------------------------------------------
-
- if (equal == 0) {
- // Command is known now, so now read all data fields:
- read_datafields(i);
- }
- else FSdata_received_flag = false;
- }
- }
-
- }
-
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/USB_receive_6.cpp Thu Aug 14 20:18:15 2014 +0000
@@ -0,0 +1,198 @@
+// L. van der Kolk, ELVEDEKA, Holland //
+// File: USB_receive_6.cpp
+
+#include "mbed.h"
+#include "MODSERIAL.h"
+
+extern MODSERIAL USB;
+extern int FSdata_received_flag;
+
+//------- debug only ---------------------
+//extern MODSERIAL SERIAL_DEBUG;
+//----------------------------------------
+
+void decode_string(int nummer_of_chars);
+void read_datafields(int command_number);
+
+#define max_string_length 100 // : max length of received string starting with $ and ending with CR/LF
+#define min_string_length 10 // : min length of received string starting with $ and ending with CR/LF
+char string_received[max_string_length + 3]; // : holds received string starting with $ and ending with CR/LF
+
+#define message_header "$PCDU" // : common message header in all messages
+#define max_commas 10 // : max. nr of possible field separating commas in a valid message string to CDU
+int comma[max_commas]; // : array with positions of all found commas in string_receved[]
+
+#define max_nr_of_commands 13 // : max nr of possible FS-to-CDU commands
+// Define array of pointers to possible FS-to-CDU commands with 3 characters:
+const char *command[max_nr_of_commands] = {
+ "123", // : no valid CDU command nr. 0 , used for debugging only
+ "MSG", // : command nr. 1
+ "EXC", // : command nr. 2
+ "BLT", // : command nr. 3
+ "SBY", // : command nr. 4
+ "CLS", // : command nr. 5
+ "SBC", // : command nr. 6
+ "WTX", // : command nr. 7
+ "ETX", // : command nr. 8
+ "KTX", // : command nr. 9
+ "FAI", // : command nr.10
+ "DPY", // : command nr.11
+ "OFS", // : command nr.12
+};
+
+void collect_FSdata() {
+ // Function reads characters from FS written in receive buffer.
+ // Wiil be called after each RX receive interrupt, so characters will allways be stored.
+ // When analyze_busy is false, function will start reading characters from defined buffer and
+ // collects strings starting with $ and ending with CR/LF.
+ // Strings shorter than min_string_length or longer than max_string_length will be ignored,
+ // others will be analyzed further.
+ // After analyzing, flag analyze_busy will be set to false again.
+ static int $_detected = false; // : no valid begin of string detected (init only on first call)
+ static int string_pntr = 0; // : pointer at begin of string (init only on first call)
+ static int nr_of_received_char = 0; // : counter of received characters (init only on first call)
+ char rx_char; // : character which is analyzed
+
+ if ( FSdata_received_flag == false ) { // : process received chars only if no decoding busy now
+ while ( !USB.rxBufferEmpty() ) // : do as long as USB receive buffer is not empty
+ { rx_char = USB.getc(); // : get a char from Rx buffer
+
+ // ----------- Debug only ! ---------------------------------------------
+ //SERIAL_DEBUG.putc(rx_char); // : unprotected immediate echo of char
+ // ----------------------------------------------------------------------
+
+ // Check for string starting with $ char:
+ if ( rx_char == '$' && $_detected == false ){
+ $_detected = true; // : begin of string is detected
+ string_pntr = 0; // : set pointer to begin of string_received[] buffer
+ }
+ string_received[string_pntr] = rx_char;
+ string_pntr++;
+ if (string_pntr >= max_string_length) {
+ // command string looks too long, so start all over again:
+ string_pntr = 0; // : set pointer back to begin of string_received[] again
+ nr_of_received_char = 0; // : reset number of received chars
+ $_detected = false;
+ FSdata_received_flag = false;
+ }
+ if ( rx_char == '\r' && $_detected == true ) {
+ if ( string_pntr > min_string_length ) { // : check minimum string length
+ // Received string can be interesting now because
+ // it starts with '$' AND it ends on New-Line AND
+ // it has a minimum length AND it is not too long:
+ string_received[string_pntr] = '\0'; // : mark end of string
+
+ FSdata_received_flag = true;
+
+ // ----------- Debug only ! -------------------------------------------
+ // SERIAL_DEBUG.printf("string_received from USB: %s",string_received );
+ // --------------------------------------------------------------------
+
+ nr_of_received_char = string_pntr;
+ //Call decoder to analyse this string:
+ decode_string(nr_of_received_char);
+ // Get ready for receiving new commands:
+ $_detected = false;
+ string_pntr = 0; // : set pointer back to begin of string_received[] again
+ nr_of_received_char = 0; // : reset number of received chars
+ }
+ else {
+ $_detected = false;
+ string_pntr = 0; // : set pointer back to begin of string_received[] again
+ nr_of_received_char = 0; // : reset number of received chars
+ FSdata_received_flag = false;
+ }
+ }
+ }
+
+ }
+}
+
+void decode_string(int nummer_of_chars)
+{ // -- This function decodes a received $.....CR/LF string written in string_received[] --
+ // First it checks for a valid checksum and reads the positions of commas in the string.
+ // If checksum is OK, it will continue to look for valid 3 char FS-to-CDU commands.
+ // When a valid command is found, data fields will be analyzed further using the found positions
+ // of commas in the string.
+ int i,c, equal;
+ char byte_read, exor_byte;
+ char command_string[6], received_checksum[4], calc_checksum[4];
+ // Get checksum and position of commas in string_received[] :
+ exor_byte = 0;
+ i = 1; // : i points to first char after $
+ c = 1; // : position of first comma
+ do {
+ byte_read = string_received[i];
+ if (byte_read == ',' && c < max_commas) {
+ comma[c] = i;
+ c++;
+ }
+ if (byte_read == '*') break;
+ exor_byte = exor_byte ^ byte_read;
+ i++;
+ } while ( i < nummer_of_chars );
+
+
+ // ----------- Debug only -------------------------------------------
+ //SERIAL_DEBUG.printf("commas found : %d\n",c-1 ); // : show commas
+ // ------------------------------------------------------------------
+
+ i++; // : i points to first checksum char after char *
+ strncpy(received_checksum,&string_received[i],2); // : copy 2 char checksum after *
+ // Get calculated checksum by transforming exor_byte in 2 hex chars (with upper case A-F) :
+ sprintf(calc_checksum,"%02X",exor_byte); // : + extra NULL char added by sprintf
+ equal = strncmp(received_checksum,calc_checksum,2);
+
+ // ******************************************************************************************
+ // -- Force checksum to allways OK : < -- debug only !!
+ equal = 0;
+ // ******************************************************************************************
+
+ if (equal != 0) {
+ // ----------- Debug only -------------------------------------------------------
+ //SERIAL_DEBUG.printf("checksum is NOT OK ! \n" ); // : show message for debugging
+ // ------------------------------------------------------------------------------
+ FSdata_received_flag = false;
+ }
+ else { // checksum is OK, go on:
+ // Check for 5 char "$PCDU" header:
+ equal = strncmp(string_received,message_header,strlen(message_header));
+ if (equal != 0) {
+
+ // ----------- Debug only ---------------------------------------------------
+ //SERIAL_DEBUG.printf("no $PCDU header in message !\n" ); // : show message
+ // --------------------------------------------------------------------------
+
+ FSdata_received_flag = false;
+ }
+ else {
+ // Read 3 char command after message_header:
+ strncpy(command_string,&string_received[strlen(message_header)],3);
+
+ // ----------- Debug only ---------------------------------------------------------------------
+ //SERIAL_DEBUG.printf("\ncommand found : %3s\n",command_string ); // : show command for debugging
+ //SERIAL_DEBUG.printf("commas found : %d\n",c-1 ); // : show commas for debugging
+ // --------------------------------------------------------------------------------------------
+
+ // Compare found string with known 3 char command list:
+ i = 0;
+ do {
+ equal = strncmp(&command_string[0],command[i],3);
+ if( equal == 0) break;
+ i++;
+ } while ( i < max_nr_of_commands);
+
+ // ----------- Debug only ---------------------------------------------------------------
+ //SERIAL_DEBUG.printf("command number is : %d\n",i ); // : show command nr for debugging
+ // --------------------------------------------------------------------------------------
+
+ if (equal == 0) {
+ // Command is known now, so now read all data fields:
+ read_datafields(i);
+ }
+ else FSdata_received_flag = false;
+ }
+ }
+
+ }
+
--- a/main.cpp Mon Jul 21 14:24:15 2014 +0000
+++ b/main.cpp Thu Aug 14 20:18:15 2014 +0000
@@ -1,6 +1,6 @@
// L. van der Kolk, W.Braat
// File: main.cpp
-// Version 26 --->> other MBOS setup !
+// CDU Mbed version 30
// -----------------------------------------
#include "mbed.h"
@@ -97,7 +97,7 @@
// -- debug only -------------------------------------
SERIAL_DEBUG.baud(38400); // : set baudrate to 38400
- SERIAL_DEBUG.printf("\n--- CDU_Mbed_26 ---\r\n");
+ SERIAL_DEBUG.printf("\n--- CDU_Mbed_30 ---\r\n");
// ---------------------------------------------------
// Create all mbos tasks, timers and resources:
--- a/show_data.cpp Mon Jul 21 14:24:15 2014 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,116 +0,0 @@
-// L. van der Kolk, ELVEDEKA, Holland //
-// File: show_data.cpp
-
-// ----- FOR DEBUG ONLY ----------------------------
-// - Functions to test received and updated CDU data
-// --------------------------------------------------
-
-#include "mbed.h"
-#include "MODSERIAL.h"
-#include "mbos.h"
-#include "mbos_def2.h"
-#include "FS_datastructures.h"
-
-extern mbos CDU_OS;
-extern MODSERIAL SERIAL_DEBUG;
-extern int FSdata_received_flag;
-
-int step_counter = 0;
-
-void test_update_flags()
-{
-// Test if DCU data was updated:
-
-// Background_Col_Update : 1 when color was updated, must be reset to 0 when data has been read
-// CDU_Status_Update : 1 when status was updated, must be reset to 0 when data has been read
-// DO_CLR_SCREEN : 1 when screen should be cleared, must be reset to 0 when done
-// Text_Line_Update : equal to line number whose text was updated, must be reset to 0 when text has been read
-// Key_Maintext_Update : equal to keynumber whose main text line was updated, must be reset to -1 text has been read
-// Key_Subtext_Update : equal to keynumber whose sub text line was updated, must be reset to -1 text has been read
-
- if ( Text_Line_Update != 0 ) { //: textline was updated !
- // read textline data and print:
- SERIAL_DEBUG.printf("\r show data read from datastructure:\r\n");
- SERIAL_DEBUG.printf("line : %d\r\n",Text_Line_Update ); // show line nr
- //SERIAL_DEBUG.printf("WTX begin pos : %d\r\n",pos ); // show begin position
- SERIAL_DEBUG.printf("fontsize is : %d\r\n",TEXTLINE[Text_Line_Update].font_size ); // show fontsize
- SERIAL_DEBUG.printf("fontstyle is: %c\r\n",TEXTLINE[Text_Line_Update].font_style); // show fontstyle
- SERIAL_DEBUG.printf("R_colour is : %d\r\n",TEXTLINE[Text_Line_Update].text_RED ); // show textcolour
- SERIAL_DEBUG.printf("G_colour is : %d\r\n",TEXTLINE[Text_Line_Update].text_GREEN ); // show textcolour
- SERIAL_DEBUG.printf("B_colour is : %d\r\n",TEXTLINE[Text_Line_Update].text_BLUE ); // show textcolour
- SERIAL_DEBUG.printf("line text is: \r\n" );
- SERIAL_DEBUG.printf("%s\r\n",TEXTLINE[Text_Line_Update].text ); // show line text
-
- Text_Line_Update = 0; // : reset FS data update ID flag
- }
-
- if ( Background_Col_Update != 0 ) { // : background colour was updated
- // read new colour data and print:
- SERIAL_DEBUG.printf("\r show data read from datastructure:\r\n");
- SERIAL_DEBUG.printf("background R_colour : %d\r\n",BACKGROUND_COL.BG_RED);
- SERIAL_DEBUG.printf("background G_colour : %d\r\n",BACKGROUND_COL.BG_GREEN);
- SERIAL_DEBUG.printf("background B_colour : %d\r\n",BACKGROUND_COL.BG_BLUE);
-
- Background_Col_Update = 0; // : reset FS data update ID flag
- }
-
- if ( CDU_Status_Update != 0 ) { // : CDU status was updated
- // read new status data and print:
- SERIAL_DEBUG.printf("\r show data read from datastructure:\r\n" );
- SERIAL_DEBUG.printf("Message indicator is : %d \r\n", CDU_STATUS.msg_indicator);
- SERIAL_DEBUG.printf("EXEC indicator is : %d \r\n", CDU_STATUS.exec_indicator);
- SERIAL_DEBUG.printf("Backlight is : %d \r\n", CDU_STATUS.backlight);
- SERIAL_DEBUG.printf("Standby mode is : %d \r\n", CDU_STATUS.stby_mode);
-
- CDU_Status_Update = 0; // : reset FS data update ID flag
- }
-
- if ( DO_CLR_SCREEN != 0 ) { // : clr screen request received
- SERIAL_DEBUG.printf("\r\r CLR screen request read:\r\n" );
- SERIAL_DEBUG.printf("DO_CLR_CSCREEN : %d \r\n", DO_CLR_SCREEN );
-
- DO_CLR_SCREEN = 0;
- }
-
- if (Key_Maintext_Update > -1) { // : key maintext was updated
-
- SERIAL_DEBUG.printf("\r show data read from datastructure:\r\n");
- //SERIAL_DEBUG.printf("Key number is : %d\r\n",Key_Maintext_Update);
-
- SERIAL_DEBUG.printf("Key MAINTEXT is : %s\r\n",SELKEY_MAINTEXT[50].text ); // show text
- SERIAL_DEBUG.printf("Key MAINTEXT is : %s\r\n",SELKEY_MAINTEXT[51].text ); // show text
- SERIAL_DEBUG.printf("Key MAINTEXT is : %s\r\n",SELKEY_MAINTEXT[52].text ); // show text
-
- //SERIAL_DEBUG.printf("Keyfontsize is : %d\r\n",SELKEY_MAINTEXT[Key_Maintext_Update].font_size ); // show fontsize
- //SERIAL_DEBUG.printf("Key fontstyle is: %c\r\n",SELKEY_MAINTEXT[Key_Maintext_Update].font_style); // show fontstyle
- //SERIAL_DEBUG.printf("Key R_colour is : %d\r\n",SELKEY_MAINTEXT[Key_Maintext_Update].text_RED ); // show textcolour
- //SERIAL_DEBUG.printf("Key G_colour is : %d\r\n",SELKEY_MAINTEXT[Key_Maintext_Update].text_GREEN ); // show textcolour
- //SERIAL_DEBUG.printf("Key B_colour is : %d\r\n",SELKEY_MAINTEXT[Key_Maintext_Update].text_BLUE ); // show textcolour
-
- Key_Maintext_Update = -1;
-
- step_counter=5;
- SERIAL_DEBUG.printf("step_counter: %d\r\n", step_counter ); // debug
-
- }
-
- if (Key_Subtext_Update > -1) { // : key subtext was updated
-
- SERIAL_DEBUG.printf("\r show data read from datastructure:\r\n");
- SERIAL_DEBUG.printf("Key number is : %d\r\n",Key_Subtext_Update);
- SERIAL_DEBUG.printf("Key SUBTEXT is : %s\r\n",SELKEY_SUBTEXT[Key_Subtext_Update].text ); // show text
- SERIAL_DEBUG.printf("Key fontsize is : %d\r\n",SELKEY_SUBTEXT[Key_Subtext_Update].font_size ); // show fontsize
- SERIAL_DEBUG.printf("Key fontstyle is: %c\r\n",SELKEY_SUBTEXT[Key_Subtext_Update].font_style); // show fontstyle
- SERIAL_DEBUG.printf("Key R_colour is : %d\r\n",SELKEY_SUBTEXT[Key_Subtext_Update].text_RED ); // show textcolour
- SERIAL_DEBUG.printf("Key G_colour is : %d\r\n",SELKEY_SUBTEXT[Key_Subtext_Update].text_GREEN ); // show textcolour
- SERIAL_DEBUG.printf("Key B_colour is : %d\r\n",SELKEY_SUBTEXT[Key_Subtext_Update].text_BLUE ); // show textcolour
-
- Key_Subtext_Update = -1;
-
- }
-
- FSdata_received_flag = false; // : reset commomn FS data update flag
- step_counter = 10;
- SERIAL_DEBUG.printf("step_counter: %d\r\n", step_counter ); // debug
-
-}
\ No newline at end of file
