From 97305fb8dc697a68e959a3367e3091039188cdc0 Mon Sep 17 00:00:00 2001 From: schodet Date: Sat, 2 Apr 2005 22:37:19 +0000 Subject: Ajout de Proto. --- 2005/i/robert/src/proto/Makefile.defs | 7 +++ 2005/i/robert/src/proto/proto.hh | 86 +++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 2005/i/robert/src/proto/Makefile.defs create mode 100644 2005/i/robert/src/proto/proto.hh diff --git a/2005/i/robert/src/proto/Makefile.defs b/2005/i/robert/src/proto/Makefile.defs new file mode 100644 index 0000000..cdb99ea --- /dev/null +++ b/2005/i/robert/src/proto/Makefile.defs @@ -0,0 +1,7 @@ +PROGRAMS += test_proto + +proto_OBJECTS = proto.o + +test_proto_OBJECTS = test_proto.o $(proto_OBJECTS) $(utils_OBJECTS) + +test_proto: $(test_proto_OBJECTS) diff --git a/2005/i/robert/src/proto/proto.hh b/2005/i/robert/src/proto/proto.hh new file mode 100644 index 0000000..bea12ef --- /dev/null +++ b/2005/i/robert/src/proto/proto.hh @@ -0,0 +1,86 @@ +#ifndef proto_hh +#define proto_hh +// proto.hh +// robert - programme du robot 2005. {{{ +// +// Copyright (C) 2005 Nicolas Schodet +// +// Robot APB Team/Efrei 2005. +// Web: http://assos.efrei.fr/robot/ +// Email: robot AT efrei DOT fr +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +// }}} +#include "utils/non_copyable.hh" +#include "serial/serial.hh" + +/// Classe de dialogue avec une carte électronique par le port série. +class Proto : public NonCopyable +{ + class Receiver; + struct Frame; + Serial serial_; + Receiver &receiver_; + /// File d'attente des messages à aquiter. + typedef std::queue FrameQueue; + FrameQueue frameQueue_; + public: + /// Constructeur. + Proto (Receiver &receiver); + /// Ouvre le port série. + void open (const std::string &ttyname); + /// Ferme le port série. + void close (void); + /// Teste si tout les packets ont été envoyés et aquités, sinon, essaye de + /// le faire. + bool sync (void); + /// Envois un packet. + void send (const Frame &frame); + /// 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, + int a2 = 0, int a3 = 0); + //@{ + /// Teste si le packet correspond au format et décode les valeurs. Utilise + /// le même format que send. + static bool decode (const Frame &frame); + static bool decode (const Frame &frame, const char *format, int &a0); + static bool decode (const Frame &frame, const char *format, int &a0, int + &a1); + static bool decode (const Frame &frame, const char *format, int &a0, int + &a1, int &a2); + static bool decode (const Frame &frame, const char *format, int &a0, int + &a1, int &a2, int &a3); + //@} + public: + /// Les clients de Proto doivent dériver de Receiver. + class Receiver + { + public: + /// Recoit un packet. + virtual void receive (uint8_t command, const Frame &frame) = 0; + }; + /// Packet. + struct Frame + { + uint8_t command; + std::vector args; + }; + private: +}; + +#endif // proto_hh -- cgit v1.2.3