From 98f2eebf37b6bed5797a35f45039e9da7542e1df Mon Sep 17 00:00:00 2001 From: haller Date: Sat, 9 Apr 2005 22:42:58 +0000 Subject: Corrections de quelques bugs --- 2005/i/robert/src/proto/proto.cc | 44 +++++++++++++++++------------------ 2005/i/robert/src/proto/proto.hh | 13 ++++++----- 2005/i/robert/src/proto/test_proto.cc | 17 ++++++++++++++ 3 files changed, 46 insertions(+), 28 deletions(-) (limited to '2005') diff --git a/2005/i/robert/src/proto/proto.cc b/2005/i/robert/src/proto/proto.cc index c0f95f7..0df2ab5 100644 --- a/2005/i/robert/src/proto/proto.cc +++ b/2005/i/robert/src/proto/proto.cc @@ -102,7 +102,7 @@ Proto::send (const Frame & frame, bool fiable) /// format et le nombre de paramètres ('b' : 8 bits, 'w' : 16 bits, 'd' : /// 32 bits, majuscule pour signé). void -Proto::send (uint8_t command, const char *format, int a0, int a1, +Proto::send (char command, const char *format, int a0, int a1, int a2, int a3, bool fiable) { // Constitution de la frame @@ -128,7 +128,7 @@ Proto::send (uint8_t command, const char *format, int a0, int a1, /// permet d'envoyer un packet pas fiable void -Proto::send_pas_fiable (uint8_t command, const char *format, int a0, int a1, +Proto::send_pas_fiable (char command, const char *format, int a0, int a1, int a2, int a3) { send(command, format, a0, a1, a2, a3, false); @@ -188,7 +188,7 @@ Proto::getFrame(void) while((receivedChar = serial_.getchar()) != -1) { //si la donnée n'est pas erronnée - if(receivedChar != 0xff) + if(receivedChar != 0xff) // XXX Heu, c'est vraiment ça????? { //Si on reçoit un bang if(receivedChar == '!') @@ -198,31 +198,31 @@ Proto::getFrame(void) currentFrame_.args.clear(); } //Si on reçoit le retour chariot et que on reçevait les args - if(receivedChar == '\n' && revState_ == 3) + else if(receivedChar == '\n' && revState_ == 2) { revState_ = 0; return true; } //Pour les autres charactères //Si on attend la commande - switch(revState_) - { - case 1: - currentFrame_.command = (static_cast(hex2digit( receivedChar ))) - << 4; - revState_ = 2; - break; - case 2: - currentFrame_.command |= static_cast(hex2digit( - receivedChar )); - revState_ = 3; - break; - case 3: - currentFrame_.args.push_back(static_cast( - hex2digit( receivedChar )) << 4); - revState_ = 3; - break; - } + else + switch(revState_) + { + case 1: + currentFrame_.command = receivedChar; + revState_ = 2; + break; + case 2: // XXX Bite de poids fort à gauche dans la frame?? + currentFrame_.args.push_back(static_cast( + hex2digit( receivedChar )) << 4); + revState_ = 3; + break; + case 3: + *(currentFrame_.args.end()) |= static_cast( + hex2digit( receivedChar )); + revState_ = 2; + break; + } //Si revState == 0 alors on jette } } diff --git a/2005/i/robert/src/proto/proto.hh b/2005/i/robert/src/proto/proto.hh index 49c88e9..c8d0211 100644 --- a/2005/i/robert/src/proto/proto.hh +++ b/2005/i/robert/src/proto/proto.hh @@ -33,6 +33,7 @@ /// Classe de dialogue avec une carte électronique par le port série. class Proto : public NonCopyable { + public: class Receiver; /// Packet. struct Frame @@ -41,6 +42,7 @@ class Proto : public NonCopyable std::vector args; bool operator==(const Frame& frame); }; + private: Serial serial_; Receiver &receiver_; @@ -55,9 +57,8 @@ class Proto : public NonCopyable // Etat de la réception de la frame // 0 - Rien reçu // 1 - Bang reçu - // 2 - char 1 commande reçu - // 3 - Commande reçu & nouveau argument - // 4 - char 1 argument reçu + // 2 - Commande reçu & nouveau argument + // 3 - char 1 argument reçu public: /// Constructeur. @@ -74,10 +75,10 @@ class Proto : public NonCopyable /// Envois un packet. COMMAND est la commande à envoyer, FORMAT, donne le /// format et le nombre de paramètres ('b' : 8 bits, 'w' : 16 bits, 'd' : /// 32 bits, majuscule pour signé). - void send (uint8_t command, const char *format = 0, int a0 = 0, int a1 = 0, + void send (char command, const char *format = 0, int a0 = 0, int a1 = 0, int a2 = 0, int a3 = 0, bool fiable = true); /// permet d'envoyer un packet robert - void Proto::send_pas_fiable (uint8_t command, const char *format, int a0, + void Proto::send_pas_fiable (char command, const char *format, int a0, int a1, int a2, int a3); //@{ /// Teste si le packet correspond au format et décode les valeurs. Utilise @@ -97,7 +98,7 @@ class Proto : public NonCopyable { public: /// Recoit un packet. - virtual void receive (uint8_t command, const Frame &frame) = 0; + virtual void receive (char command, const Frame &frame) = 0; }; private: /// Récupère les infos de l'AVR pour construire une frame diff --git a/2005/i/robert/src/proto/test_proto.cc b/2005/i/robert/src/proto/test_proto.cc index 710db05..c5bcd0d 100644 --- a/2005/i/robert/src/proto/test_proto.cc +++ b/2005/i/robert/src/proto/test_proto.cc @@ -27,16 +27,33 @@ #include #include +class chier : public Proto::Receiver +{ + void receive(char command, const Proto::Frame &frame) + { + std::cout << "J'ai reçu en commande:" << command << std::endl; + std::cout << "J'ai reçu en arg:" << std::endl; + for(std::vector::const_iterator it = frame.args.begin(); it != frame.args.end(); it++) + std::cout << static_cast(*it) << std::endl; + } +}; + int main (int argc, char **argv) { try { + std::cout << "chier partout!!" << std::endl; } catch (const std::exception &e) { std::cerr << e.what () << std::endl; return 1; } + + chier ch; + Proto chieri(ch); + chieri.open("-"); + chieri.send('a', "bb", 3, 4); return 0; } -- cgit v1.2.3