Firmware for Arduino | PLEN Project Company Inc.
Protocol.h
Go to the documentation of this file.
1 
8 #pragma once
9 
10 #ifndef PLEN2_PROTOCOL_H
11 #define PLEN2_PROTOCOL_H
12 
13 
14 #include <stdint.h>
15 
16 namespace PLEN2
17 {
18  class Protocol;
19 }
20 
21 namespace Utility
22 {
23  class AbstractParser;
24 }
25 
35 {
36 protected:
40  typedef enum
41  {
47  } State;
48 
52  class Buffer
53  {
54  public:
62  enum { LENGTH = 128 };
63 
64  char data[LENGTH];
65  uint8_t position;
66 
71  : position(0)
72  {
73  for (uint8_t index = 0; index < LENGTH; index++)
74  {
75  data[index] = '\0';
76  }
77  }
78  };
79 
82  uint8_t m_store_length;
85 
89  void m_abort();
90 
91 public:
95  Protocol();
96 
100  virtual ~Protocol() {}
101 
107  void readByte(char byte);
108 
114  bool accept();
115 
119  void transitState();
120 
124  virtual void beforeHook();
125 
129  virtual void afterHook();
130 };
131 
132 #endif // PLEN2_PROTOCOL_H
Definition: AccelerationGyroSensor.h:16
Ready.
Definition: Protocol.h:42
char data[LENGTH]
Actual buffer instance.
Definition: Protocol.h:64
bool accept()
Accept buffered string considering internal state.
State m_state
Definition: Protocol.h:81
Buffer()
Constructor.
Definition: Protocol.h:70
virtual void beforeHook()
User-defined hook that runs before transitState()
Definition: Protocol.h:62
Buffer m_buffer
Definition: Protocol.h:80
void m_abort()
Abort analysis.
virtual void afterHook()
User-defined hook that runs after transitState()
void readByte(char byte)
Read a character, and store it in the ring buffer.
virtual ~Protocol()
Destructor.
Definition: Protocol.h:100
Abstract parser interface.
Definition: Parser.h:83
Definition: Parser.h:16
Analysis class of the PLEN2's protocol.
Definition: Protocol.h:34
uint8_t m_store_length
Definition: Protocol.h:82
bool m_installing
Definition: Protocol.h:83
Will receive string that might be COMMAND.
Definition: Protocol.h:44
uint8_t position
Current iterator's position.
Definition: Protocol.h:65
Will receive string that might be HEADER. (Alias of state READY.)
Definition: Protocol.h:43
Protocol()
Constructor.
Will receive string that might be ARGUMENTS.
Definition: Protocol.h:45
Buffer struct.
Definition: Protocol.h:52
State
List of the internal states.
Definition: Protocol.h:40
Utility::AbstractParser * m_parser[STATE_EOE]
Definition: Protocol.h:84
void transitState()
Transit internal state.
Summation of the states.
Definition: Protocol.h:46