forked from Orange-OpenSource/SimpleBeeMessenger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SBMessenger.h
102 lines (79 loc) · 2.65 KB
/
SBMessenger.h
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
* Copyright (C) 2015 Orange
*
* This software is distributed under the terms and conditions of the 'Apache-2.0'
* license which can be found in the file 'LICENSE.txt' in this package distribution
* or at 'http://www.apache.org/licenses/LICENSE-2.0'.
*/
/* Device for SimpleBee Protocol
*
* Version: 0.1.0
* Created: 2015-02-24 by Franck Roudet
*/
#ifndef SBMESSENGER_H_
#define SBMESSENGER_H_
#include <inttypes.h>
#if ARDUINO >= 100
#include <Arduino.h>
#else
#include <WProgram.h>
#endif
#ifndef STREAMBUFFERSIZE
# define STREAMBUFFERSIZE 24 // The length of the streambuffer (default: 24) must be > MESSENGERBUFFERSIZE
#endif
#ifndef MESSENGERBUFFERSIZE
# define MESSENGERBUFFERSIZE 10 // The length of the commandbuffer (default: 10)
#endif
#ifndef CHECKSUMSIZE // for overidding
# define CHECKSUMSIZE 2 //
#endif
#include <SBDispatcherBase.h>
#include <sbdevice.h>
// Message States
enum {
kProccesingMessage, // Message is being received, not reached command separator
kEndOfMessage, // Message is fully received, reached command separator
};
class SBDevice;
/*
* CallBack checksum function type
*/
typedef void (*SBCheckSumFctType)(const char * start, int length, char * dest);
class SBMessenger {
private:
// **** Private variables ***
bool startCommand; // Indicates if sending of a command is underway
bool pauseProcessing; // pauses processing of new commands, during sending
char commandBuffer[MESSENGERBUFFERSIZE]; // Buffer command that holds the data
uint8_t bufferIndex; // Index where to write data in buffer
char streamBuffer[STREAMBUFFERSIZE]; // Buffer command that holds the data
Stream *comms; // Serial data stream
SBCheckSumFctType checksum; // checksum function
char command_separator; // Character indicating end of command (default: '\r')
SBDispatcherBase * dispatcher; // Message Dispatcher
// **** Initialize ****
void init (Stream & comms, const char cmd_separator);
void reset ();
bool checkMsgChecksum(const char * msg, int msglen);
public:
// ****** Public functions ******
// **** Initialization ****
SBMessenger (Stream & comms,
const char cmd_separator = '\r',
SBDispatcherBase *dispatcher=NULL,
const SBCheckSumFctType checksum=NULL);
/**
* Setting devices receive message
*/
void setDeviceList(SBDevice *devList);
// **** Command processing ****
void monitor (void);
bool available ();
bool isArgOk ();
uint8_t CommandID ();
/**
* Send message
*/
void send(const void * cmd, unsigned int cmdLen) ;
};
#endif // SBMESSENGER_H_