-
Notifications
You must be signed in to change notification settings - Fork 0
/
xbeep.h
188 lines (148 loc) · 5.5 KB
/
xbeep.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#ifndef __XBEE_CPP_H
#define __XBEE_CPP_H
/*
libxbee - a C/C++ library to aid the use of Digi's XBee wireless modules
running in API mode.
Copyright (C) 2009 onwards Attie Grande ([email protected])
libxbee is free software: you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
libxbee 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __cplusplus
#warning This header file is intended for use with C++
#else
#include <string>
#include <list>
#include <vector>
#include <stdarg.h>
#ifndef __XBEE_H
#include <xbee.h>
#endif
#ifndef EXPORT
#define EXPORT
#define XBEE_EXPORT_DEFINED
#endif
namespace libxbee {
class XBee;
class Con;
class ConCallback;
class Pkt;
extern std::list<XBee*> xbeeList;
std::list<std::string> getModes(void);
class xbee_etx {
public:
EXPORT explicit xbee_etx(xbee_err ret, unsigned char retVal): ret(ret), retVal(retVal) { };
const xbee_err ret;
const unsigned char retVal;
};
class EXPORT XBee {
public:
EXPORT explicit XBee(std::string mode);
EXPORT explicit XBee(std::string mode, std::string device, int baudrate);
EXPORT explicit XBee(std::string mode, va_list ap);
EXPORT ~XBee(void);
private:
struct xbee *xbee;
std::list<Con*> conList;
public:
EXPORT struct xbee *getHnd(void);
EXPORT void conRegister(Con *con);
EXPORT void conUnregister(Con *con);
EXPORT Con *conLocate(struct xbee_con *con);
EXPORT std::list<std::string> getConTypes(void);
EXPORT std::string mode(void);
EXPORT void setLogTarget(FILE *f);
EXPORT void setLogLevel(int level);
EXPORT int getLogLevel(void);
};
class EXPORT Con {
public:
EXPORT explicit Con(XBee &parent, std::string type, struct xbee_conAddress *address = NULL);
EXPORT ~Con(void);
EXPORT unsigned char operator<< (std::string data);
EXPORT unsigned char operator<< (std::vector<unsigned char> data);
EXPORT unsigned char operator<< (std::vector<char> data);
EXPORT void operator>> (Pkt &pkt);
EXPORT void operator>> (std::string &data);
EXPORT void operator>> (std::vector<unsigned char> &data);
EXPORT void operator>> (std::vector<char> &data);
private:
friend class XBee;
friend class ConCallback;
XBee &parent;
struct xbee *xbee;
struct xbee_con *con;
static void libxbee_callbackFunction(struct xbee *xbee, struct xbee_con *con, struct xbee_pkt **pkt, void **data);
virtual void xbee_conCallback(Pkt **pkt);
public:
EXPORT struct xbee_con *getHnd(void);
EXPORT unsigned char Tx(std::string data);
EXPORT unsigned char Tx(std::vector<unsigned char> data);
EXPORT unsigned char Tx(std::vector<char> data);
EXPORT unsigned char Tx(const unsigned char *buf, int len);
EXPORT unsigned char Tx(unsigned char *frameId, std::string data);
EXPORT unsigned char Tx(unsigned char *frameId, std::vector<unsigned char> data);
EXPORT unsigned char Tx(unsigned char *frameId, std::vector<char> data);
EXPORT unsigned char Tx(unsigned char *frameId, const unsigned char *buf, int len);
EXPORT void Rx(Pkt &pkt, int *remainingPackets = NULL);
EXPORT int RxAvailable(void);
EXPORT void purge(void);
EXPORT void sleep(void);
EXPORT void snooze(void);
EXPORT void wake(void);
EXPORT void setSleep(enum xbee_conSleepStates state);
EXPORT enum xbee_conSleepStates getSleep(void);
EXPORT void getSettings(struct xbee_conSettings *settings);
EXPORT void setSettings(struct xbee_conSettings *settings);
};
class EXPORT ConCallback: public Con {
private:
XBee &parent;
virtual void xbee_conCallback(Pkt **pkt) = 0;
public:
EXPORT explicit ConCallback(XBee &parent, std::string type, struct xbee_conAddress *address = NULL);
};
class EXPORT Pkt {
public:
EXPORT explicit Pkt(struct xbee_pkt *pkt = NULL);
EXPORT ~Pkt(void);
EXPORT unsigned char operator[] (int index);
EXPORT void operator<< (Con &con);
EXPORT void operator>> (std::string &data);
EXPORT void operator>> (std::vector<unsigned char> &data);
EXPORT void operator>> (std::vector<char> &data);
private:
struct xbee_pkt *pkt;
public:
EXPORT struct xbee_pkt *getHnd(void);
EXPORT void setHnd(struct xbee_pkt *pkt);
/* when calling this function, YOU become responsible for freeing the previously held packet */
EXPORT struct xbee_pkt *dropHnd(void);
EXPORT int size(void);
EXPORT std::string getData(void);
EXPORT std::vector<unsigned char> getVector(void);
EXPORT std::vector<char> getVector2(void);
/* use these three with care... */
EXPORT void *getData(const char *key);
EXPORT void *getData(const char *key, int id);
EXPORT void *getData(const char *key, int id, int index);
EXPORT std::string getATCommand(void);
EXPORT int getAnalog(int channel);
EXPORT int getAnalog(int channel, int index);
EXPORT bool getDigital(int channel);
EXPORT bool getDigital(int channel, int index);
};
};
#ifdef XBEE_EXPORT_DEFINED
#undef EXPORT
#undef XBEE_EXPORT_DEFINED
#endif
#endif /* __cplusplus */
#endif /* __XBEE_CPP_H */