summaryrefslogtreecommitdiff
path: root/2005/i/robert/src/proto/proto.hh
blob: bea12ef671f77ee3cbc6a7f5cba962124b1a0fdb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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