sebastian martinez / Mbed 2 deprecated 01-04_Primer_Avance

Dependencies:   mbed

Fork of 01-04EntregaPrimerCorte by ferney alberto beltran molina

Revision:
2:10956b8ceffb
Parent:
1:526bdd5faa37
Child:
3:60722da62531
--- a/main.cpp	Tue Sep 04 02:15:49 2018 +0000
+++ b/main.cpp	Thu Sep 06 18:05:07 2018 +0000
@@ -2,7 +2,9 @@
 
 #include "main.h"
 
-
+#define MEM_SIZE 10
+#define MEM_TYPE char
+MEM_TYPE buffer[MEM_SIZE];
 
 
 Serial command(USBTX, USBRX);
@@ -12,15 +14,29 @@
 int main() {
     init_servo();
     init_serial();
-
     debug_m("inicio \n");
+    
+    
     uint32_t read_cc;
     while(1)
     {
         read_cc=read_command();
+        debug_m("Entrando TC...\n");
+
         switch (read_cc) {
-            case  0x01: moving(); break;
-            default: debug_m("error de comando. \nSe espera  0xFEF0 o 0xFFF0 \n");break ;      
+
+            case  0x01: 
+            debug_m("Tc1\n");
+            
+            moving();
+            debug_m("FTc1\n");
+            break;
+            case  0x02: 
+            debug_m("Tc2 :) \n");
+            //moving();
+            debug_m("FTc2\n");
+            break;
+            default: debug_m("error de comando. \nSe espera  0x01 - 0x08 \n");break ;      
         }
     }
 }
@@ -31,30 +47,51 @@
 {
    // retorna los byte recibidos concatenados en un entero, 
    
-
+    //char intc=command.getc();
+    buffer[0] = command.getc();
+    buffer[1] = command.getc();
+    buffer[2] = command.getc();
+    buffer[3] = command.getc();
+    buffer[4] = command.getc();
     
-    char intc=command.getc();
+    char intc = buffer[0];
+    while(intc != 0xFF){
     
-    while(intc != '<')
         intc=command.getc();
-    return intc;
+        
+        debug_m("comando inicio invalido \n");
+        }
+        
+        printf("encontrado: %c \n",  buffer[0] ); 
+        //intc=command.getc();
+        int tele = buffer[1];
+        printf("dato siguente: %c \n",  tele ); 
+
+
+    return tele;
+ 
 }
 
 
 void init_serial()
 {
-    command.baud(9600);    
+    command.baud(9600);
+    debug_m("Serial 9600 \n");    
 }
 
 
 void moving(){
     debug_m("se inicia el comado mover..\n");    
     
-    char nmotor=command.getc();
-    char grados=command.getc();
-    char endc=command.getc();
+    char nmotor = buffer[2];
+    printf("Motor: %c \n",  nmotor ); 
+    char grados = buffer[3];
+    printf("Grados: %c \n",  grados ); 
+    char endc = buffer[4];
+    printf("Cierre: %c \n",  endc ); 
     mover_ser(nmotor,grados); 
-    debug_m("fin del comado guardar..\n");    
+    
+    debug_m("fin del comado mover..\n");    
     
 }