Export for Dan

Dependencies:   mbed MODSERIAL1

Revision:
3:4039b6c8da2e
Parent:
2:d6cadd28a68e
Child:
4:810c3971bb3e
--- a/main.cpp	Tue Oct 27 17:43:49 2015 +0000
+++ b/main.cpp	Tue Oct 27 20:45:57 2015 +0000
@@ -13,6 +13,7 @@
 MODSERIAL messageSystem(USBTX, USBRX);
 
 char messageBufferIncoming[MESSAGE_BUFFER_SIZE];
+int hexBufferIncoming[MESSAGE_BUFFER_SIZE];
 char messageBufferOutgoing[MESSAGE_BUFFER_SIZE];
 int count = 0;
 int i = 0;
@@ -22,19 +23,91 @@
 void messageReceive(MODSERIAL_IRQ_INFO *q) {
     // Get the pointer to MODSERIAL object that invoked this callback.
     MODSERIAL *sys = q->serial;
-    char c = sys->rxGetLastChar(); // Where local pc variable is a pointer to the global MODSERIAL pc object.
+    
+    //dereference rxGetLasChar() of sys object 
+    int c = sys->rxGetLastChar(); // Returns the last byte to pass through the RX interrupt handler.
+    
     //add char c to messageBufferIncoming
     if(i <=MESSAGE_BUFFER_SIZE){
         messageBufferIncoming[i] = c;
+        hexBufferIncoming[i] = c;
+
+      // if (c == 0xAA) led4 = !led4;
+      //  led3 = !led3;
         i++;
-       // led3 = !led3;
+       
         }
+        
     count++;
-    if (count == 8){
-         //led4 = !led4;
-        // 
-        if (!strncmp(messageBufferIncoming, "AA55FF00", sizeof("AA55FF00")-1)) led2 = !led2; 
-    //else if (!strncmp(messageBufferIncoming, "BB", sizeof("BB")-1)) led3 = !led3;
+    if (count == 4){ //Need to be able to find the string anywhere in the buffer
+    //need to change to HEX.  When I change to Hex, I can just use '==' instead of strncmp
+        // led4 = !led4;
+
+            if (hexBufferIncoming[0] == 0xAA){
+                if (hexBufferIncoming[1] == 0x55){
+                    if (hexBufferIncoming[2] == 0xFF){
+                        if (hexBufferIncoming[3] == 0x00){
+                            led1 = !led1;
+                            }
+                        }
+                    }
+                }
+            
+         else if (hexBufferIncoming[0] == 0xBB){
+                if (hexBufferIncoming[1] == 0x44){
+                    if (hexBufferIncoming[2] == 0xFF){
+                        if (hexBufferIncoming[3] == 0x00){
+                            led2 = !led2;
+                            }
+                        }
+                    }
+                }
+                
+        else if (hexBufferIncoming[0] == 0xCC){
+                if (hexBufferIncoming[1] == 0x33){
+                    if (hexBufferIncoming[2] == 0xFF){
+                        if (hexBufferIncoming[3] == 0x00){
+                            led3 = !led3;
+                            }
+                        }
+                    }
+                }     
+        else if (hexBufferIncoming[0] == 0xDD){
+                if (hexBufferIncoming[1] == 0x22){
+                    if (hexBufferIncoming[2] == 0xFF){
+                        if (hexBufferIncoming[3] == 0x00){
+                            led4 = !led4;
+                            }
+                        }
+                    }
+                }  
+        else if (hexBufferIncoming[0] == 0xDB){             //Get Heading
+                if (hexBufferIncoming[1] == 0x24){
+                    if (hexBufferIncoming[2] == 0xFF){
+                        if (hexBufferIncoming[3] == 0x00){
+                            led1 = !led1;
+                            }
+                        }
+                    }
+                }    
+        else if (hexBufferIncoming[0] == 0xD9){             //Get Temperature
+                if (hexBufferIncoming[1] == 0x26){
+                    if (hexBufferIncoming[2] == 0xFF){
+                        if (hexBufferIncoming[3] == 0x00){
+                            led2 = !led2;
+                            }
+                        }
+                    }
+                }     
+        else if (hexBufferIncoming[0] == 0xEE){             //Get Elapsed Time On
+                if (hexBufferIncoming[1] == 0x11){
+                    if (hexBufferIncoming[2] == 0x00){
+                        if (hexBufferIncoming[3] == 0x01){
+                            led3 = !led3;
+                            }
+                        }
+                    }
+                }      
          memset(messageBufferIncoming, '\0', sizeof(messageBufferIncoming));
          i = 0;
          messageReceived = true;
@@ -44,12 +117,8 @@
 }
 
 void messageProcess(void) { 
-       led1 = !led1;
-    //     if (!strncmp(messageBufferIncoming, "AA", sizeof("AA")-1)) led2 = !led2; //it's comparing the last character enetered
-    //else if (!strncmp(messageBufferIncoming, "BB", sizeof("BB")-1)) led3 = !led3;
-    //else led4 = !led4;
-    //else if (!strncmp(messageBufferIncoming, "CC33FF00", sizeof("CC33FF00")-1)) led4 = !led4;
-    //else if (!strncmp(messageBufferIncoming, "DD22FF00", sizeof("DD22FF00")-1)) led4 = !led4;
+     //  led1 = !led1;
+
     messageReceived = false;
 }
 
@@ -59,18 +128,12 @@
     messageReceived = false;
     memset(messageBufferIncoming, '\0', sizeof(messageBufferIncoming));
     messageSystem.baud(9600);
-    messageSystem.attach(&messageReceive, MODSERIAL::RxIrq);
-    //messageSystem.autoDetectChar('f'); 
+    messageSystem.attach(&messageReceive, MODSERIAL::RxIrq); //Attach a C++ type object/method pointer as the callback.
    
     // Fix Mbed library bug, see http://mbed.org/forum/bugs-suggestions/topic/1498
     LPC_GPIOINT->IO2IntClr = (1UL << 5) | (1UL << 4) | (1UL << 3) | (1UL << 2); 
  \
     while(1) {
-        
-        // if (messageSystem.readable()) {
-        //  messageSystem.putc(messageSystem.getc());
-        //}
-        // Process incoming messages.
     
         if (messageReceived)
         {