Subversion Repositories Projects

Rev

Rev 211 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
211 dhylands 1
/****************************************************************************
2
*
3
*   Copyright (c) 2009 Dave Hylands     <dhylands@gmail.com>
4
*
5
*   This program is free software; you can redistribute it and/or modify
6
*   it under the terms of the GNU General Public License version 2 as
7
*   published by the Free Software Foundation.
8
*
9
*   Alternatively, this software may be distributed under the terms of BSD
10
*   license.
11
*
12
*   See README and COPYING for more details.
13
*
14
****************************************************************************/
15
/**
16
*
17
*   @file   BioloidBus.h
18
*
19
*   @brief  Contains the definitions for a bioloid bus. Essentially
20
*           there is a bus for each UART with bioloid devices attached.
21
*
22
****************************************************************************/
23
 
24
#if !defined( BIOLOIDPACKET_H )
25
#define BIOLOIDPACKET_H       /**< Include Guard                             */
26
 
27
// ---- Include Files -------------------------------------------------------
28
 
29
#include <stdint.h>
30
 
31
#include "Config.h"
32
#include "Bioloid.h"
33
 
34
/**
35
 * @addtogroup bioloid
36
 * @{
37
 */
38
 
39
class BioloidPacket
40
{
41
public:
42
 
43
    //------------------------------------------------------------------------
44
    // Default constructor
45
 
46
    BioloidPacket();
47
 
48
    //------------------------------------------------------------------------
213 dhylands 49
    // Constructor where the storage for parameter data is specified.
50
 
51
    BioloidPacket( void *data, uint8_t maxData );
52
 
53
    //------------------------------------------------------------------------
211 dhylands 54
    // Destructor
55
 
213 dhylands 56
    ~BioloidPacket();
211 dhylands 57
 
58
    //------------------------------------------------------------------------
59
    // Accessor functions which allow portions of the packet to be retrieved.
60
 
213 dhylands 61
    Bioloid::ID_t   ID()          { return m_id; }
62
    uint8_t         Length()      { return m_length; }
63
    uint8_t         Command()     { return m_cmd; }
64
    Bioloid::Error  ErrorCode()   { return (Bioloid::Error)m_cmd; }
65
    uint8_t         CheckSum(){ return m_checksum; }
211 dhylands 66
 
67
    //------------------------------------------------------------------------
68
    // Runs a single character through the state machine. Once a packet
69
    // has been parsed successfully, the PacketReceived virtual method
70
    // is called.
213 dhylands 71
    // 
72
    // ProcessChar returns Bioloid::ERROR_NOT_DONE if the packet is incomplete.
73
    // If the packet was parsed successfully, then Bioloid::ERROR_NONE is
74
    // returned. If an error is detected that Bioloid::ERROR_CHECKSUM is
75
    // returned.
211 dhylands 76
 
213 dhylands 77
    Bioloid::Error ProcessChar( uint8_t ch );
211 dhylands 78
 
79
private:
80
 
81
    enum State
82
    {
83
        STATE_IDLE,         ///< We're waiting for the beginning of the packet
84
        STATE_1ST_FF_RCVD,  ///< We've received the 1st 0xFF
85
        STATE_2ND_FF_RCVD,  ///< We've received the 2nd 0xFF
86
        STATE_ID_RCVD,      ///< We've received the ID
87
        STATE_LENGTH_RCVD,  ///< We've received the length
88
        STATE_COMMAND_RCVD, ///< We've received the command
89
    };
90
 
91
    State           m_state;
92
    uint8_t         m_paramIdx;
93
 
94
    Bioloid::ID_t   m_id;
95
    uint8_t         m_length;
213 dhylands 96
    uint8_t         m_cmd;  // Error code for a status packet
97
 
98
    uint8_t        *m_param;
99
    uint8_t         m_maxParam;
100
 
211 dhylands 101
    uint8_t         m_checksum;
102
};
103
 
104
/** @} */
105
 
106
#endif /* BIOLOIDPACKET_H */
107