New work version with additional functions

Dependencies:   4DGL-UC ConfigFile MODSERIAL mbed mbos

Fork of CDU_Mbed_35 by Engravity-CDU

Files at this revision

API Documentation at this revision

Comitter:
LvdK
Date:
Mon Nov 26 16:38:37 2012 +0000
Parent:
1:b3553e2842ee
Child:
3:58382fa6e555
Commit message:
aanroep decoder in main() (dus NIET met interrupt)

Changed in this revision

USB_receive.cpp Show annotated file Show diff for this revision Revisions of this file
decode_1.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/USB_receive.cpp	Mon Nov 26 14:54:26 2012 +0000
+++ b/USB_receive.cpp	Mon Nov 26 16:38:37 2012 +0000
@@ -60,11 +60,11 @@
             $_detected = FALSE;
             rx_buf_pntr = 0;
              
-        led3 = 1;       // ( TEST ! )
+        //led3 = 1;       // ( TEST ! )
         
-        decode_string();
+        // decode_string();  decode_string() in MAIN now!
         
-        led3 = 0;       // ( TEST ! )
+        //led3 = 0;       // ( TEST ! )
 
         }
         else  rx_buf_pntr = 0; 
--- a/decode_1.cpp	Mon Nov 26 14:54:26 2012 +0000
+++ b/decode_1.cpp	Mon Nov 26 16:38:37 2012 +0000
@@ -17,6 +17,7 @@
 int checksum_error;
 char command_string[20];  // <<<<<<<<<< ?
 int command_number;
+int select_key_nr;
 
 
 // Commands are defined in an array command[] of command structures :
@@ -48,7 +49,7 @@
 
     // char *first_comma_pntr;
 
-    int char_cntr,i;
+    int char_cntr,i = 0;
     int equal;
     char key_id;
 
@@ -56,14 +57,15 @@
        led4 = 1;
         command_valid = FALSE;
         key_id = '0';
-
+        select_key_nr = 0;
+             
         // Check checksum:
         // ---- komt nog --------------------------
 
         // Check on 5 char "$PCDU" header:
         equal = strncmp(string_received,"$PCDU",5);
         if (equal != 0) {
-            USB.printf("header is not $PCDU but : %5s\n",string_received );  // print first 5 chars ( TEST !)
+            //USB.printf("header is not $PCDU but : %5s\n",string_received );  // print first 5 chars ( TEST !)
         }
         else {
             // find first comma :
@@ -113,7 +115,6 @@
                 }
                 else {       
                     // Test on special key commands LxT, LxS, RxT, RxS :
-                    key_id = 'x';
                     if (string_received[5] == 'L') {    // : command is LxT or LxS
                         if (string_received[7] == 'T') {
                             i = 7; // : command 7 = LxT found
@@ -134,8 +135,9 @@
                             key_id = string_received[6];
                         }                     
                     }
-                    if (isdigit(key_id)) {
+                    if (isdigit(key_id)) {  // : test if DIGIT
                        USB.printf("gevonden key commando is : %d, key %c \n",i, key_id );  // show command3 number and key (TEST ! )
+                       select_key_nr = atoi(&key_id); // : convert to integer
                        command_valid = TRUE;
                     }
                      
@@ -144,13 +146,21 @@
              }// end of char 3 test <<<<<<<<<<
 
         }// end of header test <<<<<<<<<<
+ 
+        if (command_valid == TRUE) {
+            command_number = i;
+             USB.printf("found command %d with possible key %d \n",command_number, select_key_nr);
+             
+             // ---------------------------------------------------
+             // call function to get the rest of the data fields :
+             // ---------------------------------------------------
+             
+        } 
         
-        string_complete = FALSE;  // : reset flag again, because string has been analyzed
-        led4 = 0;
     } // end of string complete test
-  
- if (command_valid == TRUE) {
-        // call function to get the rest of the data fields :
-        
- }  
+
+            
+ string_complete = FALSE;  // : reset flag again, because string has been analyzed
+ led4 = 0;            
+              
 }
\ No newline at end of file
--- a/main.cpp	Mon Nov 26 14:54:26 2012 +0000
+++ b/main.cpp	Mon Nov 26 16:38:37 2012 +0000
@@ -4,6 +4,7 @@
 
 
 void init_USB();
+void decode_string();
  
 main()
 {
@@ -13,5 +14,6 @@
     while (1) { // this is my endless main loop :
         led1 = !led1; // : toggle LED1 to show this loop
         wait(0.5);    // : can be interrupted ???????????
+        decode_string();    // : call decoder to proces any valid command string received
     }
 }
\ No newline at end of file