liaison bluetooth entre gros robot -> panneau ou gros robot -> petit robot
Fork of liaison_Bluetooth by
Diff: LiaisonBluetooth.cpp
- Revision:
- 3:46a9b9c1e1c0
- Parent:
- 2:4fc77e5b08e9
- Child:
- 4:642635655630
diff -r 4fc77e5b08e9 -r 46a9b9c1e1c0 LiaisonBluetooth.cpp --- a/LiaisonBluetooth.cpp Wed Apr 11 12:59:45 2018 +0000 +++ b/LiaisonBluetooth.cpp Wed Apr 11 15:03:52 2018 +0000 @@ -1,31 +1,20 @@ #include "LiaisonBluetooth/LiaisonBluetooth.h" /* -LiaisonBluetooth liaison(bluetooth, bluetooth_state); - -if (action_robot) { - char *score_char_array = convertir_int_en_4char(score_a_ajouter); - paquet_domotique_envoyer_ajouterscore(bluetooth, score_char_array); -} -if (action_robot1) { - char *score_char_array = convertir_int_en_4char(score_total); - paquet_domotique_envoyer_rafraichirscore(bluetooth, score_char_array); -} if (action_robot_2) { char *score_char_array = convertir_int_en_4char(score_total); - paquet_domotique_envoyer_finmatch(bluetooth, score_char_array); + paquet_domotique_envoyer(0x30, 4, score_char_array); } */ - -LiaisonBluetooth::LiaisonBluetooth(Serial bluetooth, DigitalIn state) : m_bluetooth(bluetooth), m_state(state) +LiaisonBluetooth::LiaisonBluetooth(Serial *bluetooth, DigitalIn *state) : m_bluetooth(bluetooth), m_state(state) { } bool LiaisonBluetooth::paquet_en_attente() { - while (m_bluetooth.readable() && m_state) { - if (m_bluetooth.getc() == MARQUEUR_DEBUT_TRAME) { + while (m_bluetooth->readable() && m_state) { + if (m_bluetooth->getc() == MARQUEUR_DEBUT_TRAME) { return true; } } @@ -36,14 +25,14 @@ PaquetDomotique *LiaisonBluetooth::lire() { char identifiant = 0; - if (m_bluetooth.readable() && m_state) { - identifiant = m_bluetooth.getc(); + if (m_bluetooth->readable() && m_state) { + identifiant = m_bluetooth->getc(); } else return NULL; char buffer_longueur_paquet[8]; for (int i = 0 ; i < 8 ; i++) { - if (m_bluetooth.readable() && m_state) { - buffer_longueur_paquet[i] = m_bluetooth.getc(); + if (m_bluetooth->readable() && m_state) { + buffer_longueur_paquet[i] = m_bluetooth->getc(); } else return NULL; } int longueur_paquet = convertir_4char_en_int(buffer_longueur_paquet); @@ -51,8 +40,8 @@ char buffer_data[longueur_paquet]; int index = 0; while (index < longueur_paquet-1) { - if (m_bluetooth.readable() && m_state) { - char c = m_bluetooth.getc(); + if (m_bluetooth->readable() && m_state) { + char c = m_bluetooth->getc(); if (c == MARQUEUR_FIN_TRAME) return NULL; @@ -66,20 +55,20 @@ void LiaisonBluetooth::envoyer(char idenfitiant, int longueur_data, char *data) { - if (m_state && m_bluetooth.writeable()) { - m_bluetooth.putc(idenfitiant); + if (m_state && m_bluetooth->writeable()) { + m_bluetooth->putc(idenfitiant); } char *longueur_buffer = convertir_int_en_4char(longueur_data); for (int i = 0 ; i < 4 ; i++) { - if (m_state && m_bluetooth.writeable()) { - m_bluetooth.putc(longueur_buffer[i]); + if (m_state && m_bluetooth->writeable()) { + m_bluetooth->putc(longueur_buffer[i]); } } for (int i = 0 ; i < longueur_data ; i++) { - if (m_state && m_bluetooth.writeable()) { - m_bluetooth.putc(data[i]); + if (m_state && m_bluetooth->writeable()) { + m_bluetooth->putc(data[i]); } } } @@ -103,7 +92,7 @@ char *convertir_int_en_4char(int integer) { - char data[4]; + char *data = new char[4]; data[3] = (integer>>24) & 0xFF; data[2] = (integer>>16) & 0xFF;