gxPL  1.0
Tools, Application and Framework for xPL
defs.h
1 
9 #ifndef _GXPL_DEFS_HEADER_
10 #define _GXPL_DEFS_HEADER_
11 
12 #if defined(__unix__)
13 #include <limits.h>
14 #include <assert.h>
15 #include <sysio/defs.h>
16 #include <sysio/log.h>
17 #include <sysio/dlist.h>
18 #include <sysio/vector.h>
19 #include <sysio/serial.h>
20 #include <sysio/delay.h>
21 #if defined(ARCH_ARM_RASPBERRYPI)
22 #include <sysio/doutput.h>
23 #endif
24 #define GXPL_TARGET_STR "unix"
25 #ifndef PROGMEM
26 #define PROGMEM
27 #endif
28 #elif defined(__AVR__)
29 #include <avrio/defs.h>
30 #include <avrio/vector.h>
31 #include <avrio/dlist.h>
32 #include <avrio/tc.h>
33 #include <avrio/dpin.h>
34 #include <avrio/assert.h>
35 #include <avrio/log.h>
36 #include <avrio/delay.h>
37 #define NAME_MAX 16
38 #define GXPL_TARGET_STR "avr"
39 #else
40 #error This target platform is not supported.
41 #endif
42 
43 __BEGIN_C_DECLS
44 /* ========================================================================== */
45 #include <errno.h>
46 
47 /* forward struct defined */
48 typedef struct _gxPLApplication gxPLApplication;
49 typedef struct _gxPLIo gxPLIo;
50 typedef struct _gxPLMessage gxPLMessage;
51 typedef struct _gxPLDevice gxPLDevice;
52 typedef struct _gxPLDeviceConfig gxPLDeviceConfig;
53 typedef struct _gxPLHub gxPLHub;
54 typedef struct _gxPLBridge gxPLBridge;
55 
56 #ifndef EINVAL
57 #define EINVAL 22 /* Invalid argument */
58 #endif
59 
65 /* constants ================================================================ */
66 
71 #define XPL_PORT 3865
72 
76 #define GXPL_VENDORID_MAX 8
77 
81 #define GXPL_DEVICEID_MAX 8
82 
86 #define GXPL_INSTANCEID_MAX 16
87 
91 #define GXPL_CLASS_MAX 8
92 
96 #define GXPL_TYPE_MAX 8
97 
101 #define GXPL_NAME_MAX 16
102 
106 #define GXPL_HOP_MAX 9
107 
111 #define GXPL_GETOPT "i:n:B:W:dDr"
112 
116 #define GXPL_DEFAULT_BAUDRATE 38400
117 
121 #define GXPL_DEFAULT_FLOW SERIAL_FLOW_RTSCTS
122 
126 typedef enum {
129  gxPLConnectAuto
131 
132 
136 typedef enum {
137  gxPLMessageAny,
138  gxPLMessageCommand,
139  gxPLMessageStatus,
140  gxPLMessageTrigger,
141  gxPLMessageUnknown = -1
143 
144 
148 typedef enum {
149  gxPLIoFuncNone = 0,
150  gxPLIoFuncPoll,
151  gxPLIoFuncGetIface,
152  gxPLIoFuncGetBcastAddr,
153  gxPLIoFuncGetNetInfo,
154  gxPLIoFuncGetLocalAddrList,
155  gxPLIoFuncNetAddrToString,
156  gxPLIoFuncNetAddrFromString,
157  gxPLIoFuncError = -1
158 } gxPLIoFunc;
159 
163 typedef enum {
164  gxPLNetFamilyUnknown = 0,
166  gxPLNetFamilyInet4 = gxPLNetFamilyInet,
167  gxPLNetFamilyInet6 = gxPLNetFamilyInet | 1,
168  gxPLNetFamilyZigbee = 4,
169  gxPLNetFamilyZigbee16 = gxPLNetFamilyZigbee,
170  gxPLNetFamilyZigbee64 = gxPLNetFamilyZigbee | 1
171 } gxPLNetFamily;
172 
176 typedef enum {
177  gxPLMessageStateInit = 0,
178  gxPLMessageStateHeader,
179  gxPLMessageStateHeaderHop,
180  gxPLMessageStateHeaderSource,
181  gxPLMessageStateHeaderTarget,
182  gxPLMessageStateHeaderEnd,
183  gxPLMessageStateSchema,
184  gxPLMessageStateBodyBegin,
185  gxPLMessageStateBody,
186  gxPLMessageStateBodyEnd,
187  gxPLMessageStateEnd,
188  gxPLMessageStateError = -1
190 
194 typedef enum {
195  gxPLHeartbeatHello = 0,
196  gxPLHeartbeatGoodbye = 1,
198 
202 typedef enum {
203  gxPLConfigOptional,
204  gxPLConfigMandatory,
205  gxPLConfigReconf
207 
208 /* types ==================================================================== */
209 
210 /* structures =============================================================== */
214 typedef struct _gxPLIoXBeeSetting {
215  xSerialIos ios;
216  uint64_t panid;
217  union {
218  uint8_t flag;
219  struct {
220  uint8_t coordinator: 1;
221  uint8_t new_panid: 1;
222  uint8_t reset_sw: 1;
223  uint8_t reset_hw: 1;
224  };
225  };
226 #if defined(__AVR__)
227 #define GXPL_XBEEZB_HAS_HWRESET 1
228  xDPin reset_pin;
229 #elif defined(ARCH_ARM_RASPBERRYPI)
230 #define GXPL_XBEEZB_HAS_HWRESET 1
231  xDout reset_pin;
232 #endif
234 
238 typedef struct _gxPLSetting {
239 
240  char iface[NAME_MAX];
241  char iolayer[NAME_MAX];
242  gxPLConnectType connecttype;
243  union {
244  uint16_t flag;
245  struct {
246  uint16_t log: 3;
247  uint16_t malloc: 1;
248  uint16_t nodaemon: 1;
249  uint16_t iosflag: 1;
250  uint16_t broadcast: 1;
251  };
252  };
253  unsigned iotimeout;
254  union {
255 
256  gxPLIoXBeeSetting xbee;
257  };
258 } gxPLSetting;
259 
263 typedef struct _gxPLIoAddr {
265  uint8_t addrlen;
266  uint8_t addr[16];
267  int port;
268  union {
269  uint16_t flag;
270  struct {
271  uint16_t isbroadcast: 1;
272  };
273  };
274 } gxPLIoAddr;
275 
279 typedef struct _gxPLId {
280  char vendor[GXPL_VENDORID_MAX + 1];
281  char device[GXPL_DEVICEID_MAX + 1];
282  char instance[GXPL_INSTANCEID_MAX + 1];
283 } gxPLId;
284 
288 typedef struct _gxPLSchema {
289  char class[GXPL_CLASS_MAX + 1];
290  char type[GXPL_TYPE_MAX + 1];
291 } gxPLSchema;
292 
296 typedef struct _gxPLFilter {
297 
298  gxPLMessageType type;
299  gxPLId source;
300  gxPLSchema schema;
301 } gxPLFilter;
302 
307 /* ========================================================================== */
308 __END_C_DECLS
309 #endif /* _GXPL_DEFS_HEADER_ defined */
gxPLConfigurableType
xPL Configurable Type
Definition: defs.h:202
uint64_t panid
Definition: defs.h:216
gxPLHeartbeatType
Heartbeat type.
Definition: defs.h:194
#define GXPL_DEVICEID_MAX
Maximum number of characters allowed for device ID.
Definition: defs.h:81
struct _gxPLSetting gxPLSetting
Describe a gxPLApplication configuration.
struct _gxPLFilter gxPLFilter
Describe a xPL filter.
uint8_t addrlen
Definition: defs.h:265
#define GXPL_TYPE_MAX
Maximum number of characters allowed for schema type.
Definition: defs.h:96
gxPLMessageType
Possible xPL message types.
Definition: defs.h:136
Describe a source or destination xPL identifier.
Definition: defs.h:279
struct _gxPLIoAddr gxPLIoAddr
Describe a network address.
struct _gxPLIoXBeeSetting gxPLIoXBeeSetting
Describe a XBee configuration.
xSerialIos ios
Definition: defs.h:215
gxPLNetFamily
Net families.
Definition: defs.h:163
gxPLConnectType
xPL Connection mode
Definition: defs.h:126
Describe a gxPLApplication configuration.
Definition: defs.h:238
struct _gxPLSchema gxPLSchema
Describe a xPL schema.
gxPLIoFunc
Possible xPL ioctl call.
Definition: defs.h:148
struct _gxPLId gxPLId
Describe a source or destination xPL identifier.
Describe a network address.
Definition: defs.h:263
Describe a XBee configuration.
Definition: defs.h:214
Describe a xPL schema.
Definition: defs.h:288
#define GXPL_CLASS_MAX
Maximum number of characters allowed for schema class.
Definition: defs.h:91
Describe a xPL filter.
Definition: defs.h:296
gxPLNetFamily family
Definition: defs.h:264
#define GXPL_INSTANCEID_MAX
Maximum number of characters allowed for instance ID.
Definition: defs.h:86
gxPLMessageState
Decoding states of a message.
Definition: defs.h:176
unsigned iotimeout
Definition: defs.h:253
#define GXPL_VENDORID_MAX
Maximum number of characters allowed for vendor ID.
Definition: defs.h:76
int port
Definition: defs.h:267