summaryrefslogtreecommitdiff
path: root/2005/i/robert/src/proto
diff options
context:
space:
mode:
authorschodet2005-04-02 22:37:19 +0000
committerschodet2005-04-02 22:37:19 +0000
commit97305fb8dc697a68e959a3367e3091039188cdc0 (patch)
treec53bf23c6b2c268e6ace64da07ea0c8208191af4 /2005/i/robert/src/proto
parent43ae76992af5712d7303a7022ac14962cc925919 (diff)
Ajout de Proto.
Diffstat (limited to '2005/i/robert/src/proto')
-rw-r--r--2005/i/robert/src/proto/Makefile.defs7
-rw-r--r--2005/i/robert/src/proto/proto.hh86
2 files changed, 93 insertions, 0 deletions
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<Frame> 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<uint8_t> args;
+ };
+ private:
+};
+
+#endif // proto_hh