liaison bluetooth entre gros robot -> panneau ou gros robot -> petit robot

Fork of liaison_Bluetooth by j d

Revision:
7:543d5548dbb9
Parent:
6:91cf94ff46ed
Child:
8:4b5a472a8f94
--- a/LiaisonBluetooth.cpp	Fri Apr 13 12:42:43 2018 +0000
+++ b/LiaisonBluetooth.cpp	Fri Apr 13 13:00:25 2018 +0000
@@ -8,7 +8,7 @@
 }
 */
 
-LiaisonBluetooth::LiaisonBluetooth(Serial *bluetooth) : m_bluetooth(bluetooth), m_state(true)
+LiaisonBluetooth::LiaisonBluetooth(Serial *bluetooth, Serial *pc) : m_bluetooth(bluetooth), m_state(true), m_pc(pc)
 {
 }
 
@@ -34,17 +34,17 @@
     
     if (m_bluetooth->readable() && m_state) {
         identifiant = m_bluetooth->getc();
-    } else { return NULL; }
+    } else { m_pc->printf("error identifiant %d\n", identifiant); return NULL; }
 
     char buffer_longueur_paquet[4];
     for (int i = 0 ; i < 4 ; i++) {
         if (m_bluetooth->readable() && m_state) {
             buffer_longueur_paquet[i] = m_bluetooth->getc();
-        } else { return NULL; }
+        } else { m_pc->printf("error buffer_longueur_paquet %d\n", i); return NULL; }
     }
     unsigned short longueur_paquet = atoi(buffer_longueur_paquet);
     
-    m_bluetooth->printf("longueur %d\n", longueur_paquet);
+    m_pc->printf("longueur %d\n", longueur_paquet);
     
     wait_ms(10);
     
@@ -54,16 +54,18 @@
         if (m_bluetooth->readable() && m_state) {
             char c = m_bluetooth->getc();
             
-            m_bluetooth->printf("%x\n", c);
+            m_pc->printf("%x\n", c);
             
             if (c == MARQUEUR_FIN_TRAME) {
+                m_pc->printf("error MARQUEUR_FIN_TRAME %d\n", index);
                 return NULL;
             }
 
             buffer_data[index++] = c;
-        } else { m_bluetooth->printf("buffer_data\n"); return NULL; }
+        } else { m_pc->printf("buffer_data\n"); return NULL; }
     }
-
+    
+    
     return creer_paquetdomotique(identifiant, longueur_paquet, buffer_data);
 }
 
@@ -71,11 +73,11 @@
 {
     if (m_state && m_bluetooth->writeable()) {
         m_bluetooth->putc(MARQUEUR_DEBUT_TRAME);
-    }
+    } else { m_pc->printf("MARQUEUR_DEBUT_TRAME\n"); }
     
     if (m_state && m_bluetooth->writeable()) {
         m_bluetooth->putc(idenfitiant);
-    }
+    } else { m_pc->printf("idenfitiant\n"); }
 
     //char *longueur_buffer = convertir_int_en_4char(longueur_data);
     char str[4]; 
@@ -83,18 +85,18 @@
     for (int i = 0 ; i < 4 ; i++) {
         if (m_state && m_bluetooth->writeable()) {
             m_bluetooth->putc(str[i]);
-        }
+        } else { m_pc->printf("longueur_data %d\n", i); }
     }
 
     for (int i = 0 ; i < longueur_data ; i++) {
         if (m_state && m_bluetooth->writeable()) {
             m_bluetooth->putc(data[i]);
-        }
+        } else { m_pc->printf("data %d\n", i); }
     }
     
     if (m_state && m_bluetooth->writeable()) {
         m_bluetooth->putc(MARQUEUR_FIN_TRAME);
-    }
+    } else { m_pc->printf("MARQUEUR_FIN_TRAME\n"); }
 }