voor willem test

Dependencies:   4DGL MODSERIAL mbed mbos

FS2CDU_data_2.cpp

Committer:
LvdK
Date:
2013-01-29
Revision:
6:e0bf3b244d7c

File content as of revision 6:e0bf3b244d7c:

// L. van der Kolk, ELVEDEKA, Holland //
// File:  FS2CDU_data_2.cpp  

#include "mbed.h"
#include "MODSERIAL.h"  

// ---- FS-to-CDU data structures filled with received data ---------------------------------------
#define max_text0    48   //  max text length font 0      
#define max_text1    24   //  max text length font 1  
#define max_lines    14   //  max nr of screen lines 
#define max_font      1   //  possible fonts are 0 to max_font, so now 0 and 1 possible
#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 display:
struct { int   RED;                 //  : RED value 
         int   GREEN;               //  : GREEN value 
         int   BLUE;                //  : BLUE value     
         int   updated;             //  : update flag, true when background colour was updated
         } BACKGROUND_COL;

// Maintext lines at selectkeys:
struct { char  text[max_text0+2];    //  : maintext string, ending with '\0'   
         int   font_size;            //  : fontsize             
         char  font_style;           //  : style character                          
         int   text_RED;             //  : RED value of textline
         int   text_GREEN;           //  : GREEN value of textline
         int   text_BLUE;            //  : BLUE value of textline
         int   updated;              //  : update flag, true when a selectkey maintext was updated
         } SELKEY_MAINTEXT[max_keys];//  : array of selectkey Maintext structures
        
// Subtext lines at selectkeys:
struct { char  text[max_text0+2];    //  : subtext string, ending with '\0'   
         int   font_size;            //  : fontsize                                
         char  font_style;           //  : style character                          
         int   text_RED;             //  : RED value of textline
         int   text_GREEN;           //  : GREEN value of textline
         int   text_BLUE;            //  : BLUE value of textline
         int   updated;              //  : update flag, true when a selectkey subtext was updated
         } SELKEY_SUBTEXT[max_keys]; //  : array of selectkey Subtext structures 

// Screen textlines:
struct { char  text[max_text0+2];    //  : text line string, ending with '\0'   
         int   font_size;            //  : fontsize of textline           
         char  font_style;           //  : style character                             
         int   text_RED;             //  : RED value of textline
         int   text_GREEN;           //  : GREEN value of textline
         int   text_BLUE;            //  : BLUE value of textline
         int   updated;              //  : update flag, true when a textline was updated
         } TEXTLINE[max_lines+1];    //  : array of textline structures
            
// CDU status:            
struct { int mess_light;            //  : 0 = light OFF, 1 = light ON
         int exec_indicator;        //  : 0 = indicator OFF, 1 = indicator ON
         int backlight;             //  : 0 = light OFF, 1 = light ON 
         int stby_mode;             //  : 0 = operational mode, 1 = standby mode
         int updated;               //  : update flag, true when one or more status items were updated
         } CDU_STATUS;           
            
// Clear screen flag:
int DO_CLR_SCREEN = false;          //  : Clear screen flag, true = perform a clear-screen

// CDU settings:
struct { int Baud;              //  : Baudrate can be 2400, 4800, 9600, 19200, 38400
         char Firmware_nr[15];  //  : firmware ID string, terminated with '\0' !
         char CDU_type[15];     //  : CDU type ID string, terminated with '\0' !
         int  Serial_nr;        //  : integer serial number
         char IP_address[20];   //  : IP address, 0.0.0.0 to 255.255.255.255 , terminated with '\0' !
         int  Port_nr;          //  : integer Port number
         char Server_ip[20];    //  : IP address of server , terminated with '\0' !     
         int  updated;          //  : update flag, true when one or more items were updated
         } CDU_SET;

// Common flag to signal that one or more updates were performed:
int FSdata_received_flag = false;  //  : true when one or more FS-to-CDU data was updated                                 
// --------------------------------------------------------------------------------------------------

extern MODSERIAL USB;      // >>>>>>>>>>> alleen t.b.v TEST output !!
extern char string_received[];  
extern int comma[];

void Send_VAL_message(int var, char *char_pntr); 

void set_initial_CDU_screen()
{  // Fill all FS-to-CDU datastructures with data for initial power-up conditions:
   int key_nr, line_nr;
 
    FSdata_received_flag = true;    // <<<<<<<<<<<<<< !
    
  // Init background colour of screen :
   BACKGROUND_COL.RED = 0;
   BACKGROUND_COL.GREEN = 0;
   BACKGROUND_COL.BLUE = 0;
   BACKGROUND_COL.updated = true;
   
  // Init Maintext at left selectkeys starting from 0 :
  for ( key_nr = 0; key_nr < max_leftkeys; key_nr++ )
  {  SELKEY_MAINTEXT[key_nr].text_RED =   255;
     SELKEY_MAINTEXT[key_nr].text_GREEN = 255;
     SELKEY_MAINTEXT[key_nr].text_BLUE =  255;
     SELKEY_MAINTEXT[key_nr].font_size =    0;
     SELKEY_MAINTEXT[key_nr].font_style = fstyle_1;
     strncpy(SELKEY_MAINTEXT[key_nr].text, "0|....key maintext..............................|\0",
     max_text0 + 2 ); // (max_text0+2) chars copied
     SELKEY_MAINTEXT[key_nr].updated = true;   
   }
  // 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 =   255;
     SELKEY_MAINTEXT[key_nr].text_GREEN = 255;
     SELKEY_MAINTEXT[key_nr].text_BLUE =  255;
     SELKEY_MAINTEXT[key_nr].font_size =    0;
     SELKEY_MAINTEXT[key_nr].font_style = fstyle_1; 
     strncpy(SELKEY_MAINTEXT[key_nr].text, "0|....key maintext..............................|\0",
     max_text0 + 2 ); // (max_text0+2) chars copied
     SELKEY_MAINTEXT[key_nr].updated = true;   
   }
  // Init Subtext at left selectkeys starting from 0 :
  for ( key_nr = 0; key_nr < max_leftkeys; key_nr++ )
  {  SELKEY_SUBTEXT[key_nr].text_RED =   255;
     SELKEY_SUBTEXT[key_nr].text_GREEN = 255;
     SELKEY_SUBTEXT[key_nr].text_BLUE =  255;
     SELKEY_SUBTEXT[key_nr].font_size =    0;
     SELKEY_SUBTEXT[key_nr].font_style = fstyle_1; 
     strncpy(SELKEY_SUBTEXT[key_nr].text, "0|....key subtext...............................|\0",
     max_text0 + 2 ); // (max_text0+2) chars copied
     SELKEY_SUBTEXT[key_nr].updated = true;   
   }   
  // 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 =   255;
     SELKEY_SUBTEXT[key_nr].text_GREEN = 255;
     SELKEY_SUBTEXT[key_nr].text_BLUE =  255;
     SELKEY_SUBTEXT[key_nr].font_size =    0;
     SELKEY_SUBTEXT[key_nr].font_style = fstyle_1; 
     strncpy(SELKEY_SUBTEXT[key_nr].text, "0|....key subtext...............................|\0",
     max_text0 + 2 ); // (max_text0+2) chars copied 
     SELKEY_SUBTEXT[key_nr].updated = true;   
   }     
  // Init screentext :
  for ( line_nr = 1; line_nr <= 14; line_nr++ )
  {  TEXTLINE[line_nr].text_RED =   255;
     TEXTLINE[line_nr].text_GREEN = 255;
     TEXTLINE[line_nr].text_BLUE =  255;
     TEXTLINE[line_nr].font_size =    0;
     TEXTLINE[line_nr].font_style = fstyle_1; 
     strncpy(TEXTLINE[line_nr].text, "0|....text line.................................|\0",
     max_text0 + 2 ); // (max_text0+2) chars copied 
     TEXTLINE[line_nr].updated = true;   
   }   
   // Init CDU status items:
   CDU_STATUS.mess_light = 1;
   CDU_STATUS.exec_indicator = 1;
   CDU_STATUS.backlight = 1;
   CDU_STATUS.stby_mode = 0;
   CDU_STATUS.updated = true;
   
   // Init Clear screen flag:
   DO_CLR_SCREEN = false;       
   
   // INIT CDU settings:
   CDU_SET.Baud = 38400; // : will be default baudrate
   strcpy(CDU_SET.Firmware_nr, "v1.0a\0"); // copy chars incl. '\0'
   strcpy(CDU_SET.CDU_type, "colour CDU\0"); // copy chars incl. '\0'
   CDU_SET.Serial_nr = 12345;
   strcpy(CDU_SET.IP_address, "255.255.255.123\0"); // copy chars incl. '\0'
   CDU_SET.Port_nr = 4321;
   strcpy(CDU_SET.Server_ip, "255.255.255.456\0"); // copy chars incl. '\0'
   CDU_SET.updated = true;
}

void read_datafields(int command_number) {
    // Function to read all comma seperated datafields in string_received[]
    // and fill in FS-to-CDU data structures.
    // Parameter is found command_number.
    int colour, size, pos, line, last, cnt, k_id, var, a ;
    int modified, char_pntr;
    char val_string[25]; // <<<<<---------------------------------------------------------Local !!!!! 
    char ch;
        
    modified = false;    
    switch ( command_number )
    {
        case 0:  
        {   // 0 is no valid commandnumber
             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.mess_light = atoi(&string_received[char_pntr]);
               CDU_STATUS.updated = true;    // : signal update of CDU status
               FSdata_received_flag = true;  // : set common update flag
             }
             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.updated = true;   // : signal update of of CDU status
               FSdata_received_flag = true;  // : set common update flag
             }
             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.updated = true;   // : signal update of of CDU status
               FSdata_received_flag = true;  // : set common update flag
             }
             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.updated = true;   // : signal update of CDU status
               FSdata_received_flag = true;  // : set common update flag
             }
             break;
        }        
        
        case 5: // CLS command, CDU clear screen control
        {    
             DO_CLR_SCREEN = true;        // : tell to clear the screen
             FSdata_received_flag = true;  // : set common update flag
             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.RED = colour;
                modified = true;
             }
             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.GREEN = colour;
                modified = true;
             }
             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.BLUE = colour; 
                modified = true;
             }                       
             if ( modified == true )
             { BACKGROUND_COL.updated = true;   // : signal update of background colour
               FSdata_received_flag = true;      // : set common update flag 
             } 
                         
             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 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 <= max_font ) {
                    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];
             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;
                modified = true;
                while ( a <= last )
                 {  ch = string_received[char_pntr];
                    if (ch == '*') break; // : do not include * in text
                    TEXTLINE[line].text[a] = ch;
                    a++;
                    char_pntr++;
                 }
             //TEXTLINE[line].text[a] = '\0'; // : mark end of text <<<<<<<<<< ??
             }            
          } 
           
          if ( modified == true )  {
            TEXTLINE[line].updated = true;    // : signal update of text line
            FSdata_received_flag = true;      // : set common update flag 
          }
           
          // Debug:
          // Print all fields : ----------------------------------------------------------------
          USB.printf("WTX line        : %d\n",line );                         // show line nr 
          USB.printf("WTX position    : %d\n",pos );                          // show pos   
          USB.printf("WTX text is     : %s\n",TEXTLINE[line].text );          // show text  
          USB.printf("WTX fontsize is : %d\n",TEXTLINE[line].font_size );     // show fontsize 
          USB.printf("WTX fontstyle is: %c\n",TEXTLINE[line].font_style);     // show fontstyle 
          USB.printf("WTX R_colour is : %d\n",TEXTLINE[line].text_RED );      // show textcolour 
          USB.printf("WTX G_colour is : %d\n",TEXTLINE[line].text_GREEN );    // show textcolour 
          USB.printf("WTX B_colour is : %d\n",TEXTLINE[line].text_BLUE );     // show textcolour 
          // END of debug printing --------------------------------------------------------------
                    
          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;
                modified = true;
                while ( a <= last && cnt > 0)
                 {  
                    TEXTLINE[line].text[a] = ' '; //: write space
                    a++;
                    cnt--;
                 }
             }              
          } 
          if ( modified == true )  {
            TEXTLINE[line].updated = true;    // : signal update of text line
            FSdata_received_flag = true;      // : set common update flag 
          }
           
          // Debug:
          // Print : -------------------------------------------------------------------------
          USB.printf("ETX line : %d\n",line );                                // show line nr 
          USB.printf("ETX position : %d\n",pos );                             // show pos   
          USB.printf("ETX modified text : %s\n",TEXTLINE[line].text );        // show text  
          // END of debug printing ------------------------------------------------------------
        }        
        
        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 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 <= max_font ) {
                  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];
             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 = 1;
                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 )  {
              SELKEY_MAINTEXT[k_id].updated = true;  // : signal update 
              FSdata_received_flag = true;      // : set common update flag 
             }
 
          // Debug:
          // Print all fields : --------------------------------------------------------------------
          USB.printf("KTX key nr is   : %d\n",k_id );                             // show key nr 
          USB.printf("KTX MAINTEXT is : %s\n",SELKEY_MAINTEXT[k_id].text );       // show text  
          USB.printf("KTX fontsize is : %d\n",SELKEY_MAINTEXT[k_id].font_size );  // show fontsize 
          USB.printf("KTX fontstyle is: %c\n",SELKEY_MAINTEXT[k_id].font_style);  // show fontstyle 
          USB.printf("KTX R_colour is : %d\n",SELKEY_MAINTEXT[k_id].text_RED );   // show textcolour 
          USB.printf("KTX G_colour is : %d\n",SELKEY_MAINTEXT[k_id].text_GREEN ); // show textcolour 
          USB.printf("KTX B_colour is : %d\n",SELKEY_MAINTEXT[k_id].text_BLUE );  // show textcolour 
          // END of debug printing -----------------------------------------------------------------
          
          }
          
          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 <= max_font ) {
                  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 = 1;
                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 )  {
              SELKEY_SUBTEXT[k_id].updated = true;  // : signal update 
              FSdata_received_flag = true;      // : set common update flag 
             }
             
          // Debug:
          // Print all fields : --------------------------------------------------------------------
          USB.printf("KTX key nr is   : %d\n",k_id );                            // show key nr 
          USB.printf("KTX SUBTEXT is : %s\n",SELKEY_SUBTEXT[k_id].text );        // show text  
          USB.printf("KTX fontsize is : %d\n",SELKEY_SUBTEXT[k_id].font_size );  // show fontsize 
          USB.printf("KTX fontstyle is: %c\n",SELKEY_SUBTEXT[k_id].font_style);  // show fontstyle 
          USB.printf("KTX R_colour is : %d\n",SELKEY_SUBTEXT[k_id].text_RED );   // show textcolour 
          USB.printf("KTX G_colour is : %d\n",SELKEY_SUBTEXT[k_id].text_GREEN ); // show textcolour 
          USB.printf("KTX B_colour is : %d\n",SELKEY_SUBTEXT[k_id].text_BLUE );  // show textcolour 
          // END of debug printing -----------------------------------------------------------------
          
          }
     
          break;
        }        
        
        case 10: // STV command, set a status value:
        { // Read var_number :
          char_pntr = comma[1] + 1; // : set char pointer to char after comma 1   
          var = atoi(&string_received[char_pntr]);
          if ( var == 0 ) // : test if valid var to write (var 0 = baudrate permitted only now)
          { // Set baudrate :
            char_pntr = comma[2] + 1; // : set char pointer to char after comma 2
            a = atoi(&string_received[char_pntr]);
            // Test for valid baudrates:
            if (a==2400 || a==4800 || a==9600 || a== 19200 || a==38400 )
            { CDU_SET.Baud = a;
                CDU_SET.updated = true;  // : signal status update 
                // Send a responding VAL message:
                sprintf(val_string,"%d",CDU_SET.Baud);                
                Send_VAL_message(var,val_string);
                FSdata_received_flag = true;      // : set common update flag
            }
            else { // no valid baudrate in command
                   // Send a responding VAL NACK message :
                   strcpy(val_string,"NACK\0"); // copy chars incl. '\0'
                   Send_VAL_message(var,val_string);
            }
          }
          else { // var is not valid var for writing
                   // Send a responding VAL NACK message :
                   strcpy(val_string,"NACK\0"); // copy chars incl. '\0'
                   Send_VAL_message(var,val_string);
          }
                  
          break;
        }               
        
        case 11: // GTV command, get a status value:     
        { // Read var_number :
          char_pntr = comma[1] + 1; // : set char pointer to char after comma 1   
          var = atoi(&string_received[char_pntr]);
          if ( var >= 0 && var <= 6) // : test if valid var to read
          { // Read value :
            switch ( var ) {
                case 0: { // baudrate asked
                          sprintf(val_string,"%d",CDU_SET.Baud);
                          Send_VAL_message(var,val_string);
                break;
                }
                case 1: { // firmware ID asked
                          strcpy(val_string,CDU_SET.Firmware_nr); // copy chars incl. '\0'
                          Send_VAL_message(var,val_string);                
                break;
                }
                case 2: { // CDU type ID asked
                          strcpy(val_string,CDU_SET.CDU_type); // copy chars incl. '\0'
                          Send_VAL_message(var,val_string);
                break;                
                } 
                case 3: { // serial number asked
                          sprintf(val_string,"%d",CDU_SET.Serial_nr);
                          Send_VAL_message(var,val_string);                          
                break;                
                }
                case 4: { // IP address of CDU asked
                          strcpy(val_string,CDU_SET.IP_address); // copy chars incl. '\0''
                          Send_VAL_message(var,val_string);               
                break;
                }
                case 5: { // Port number asked
                          sprintf(val_string,"%d",CDU_SET.Port_nr);                
                          Send_VAL_message(var,val_string);
                break;                
                }
                case 6: { // IP address of server asked
                          strcpy(val_string,CDU_SET.Server_ip); // copy chars incl. '\0'
                          Send_VAL_message(var,val_string);
                break;                
                }            

                default : { // invalid var , not possible 
                break;
                }   
                           
            }
          }
          else { // var is not valid 
                   // Send a responding VAL NACK message :
                   strcpy(val_string,"NACK\0"); // copy chars incl. '\0'
                   Send_VAL_message(var,val_string); 
          }
          break;
        }        
               
        case 12: // dbg, special debug command        
        {                    

          break;
        }               
        
        default:
        {   
          // unknown commandnumber !
          break;
        }


    } 
}