AvrIO  1.4.5
Bibliothèque C modulaire pour ATMEL AVR
xbee.h
1 
22 #ifndef _AVRIO_XBEE_H_
23 #define _AVRIO_XBEE_H_
24 
25 #include <avrio/defs.h>
26 
27 __BEGIN_C_DECLS
28 /* ========================================================================== */
29 #include <errno.h>
30 #include <stdio.h>
31 #include <avrio/tc.h>
32 #include <avrio/dpin.h>
33 #include <avrio/net.h>
34 
45 /* structures =============================================================== */
52 typedef struct _xXBeePkt xXBeePkt;
53 
59 typedef struct _xXBee xXBee;
60 
61 
62 /* types ==================================================================== */
73 typedef int (*iXBeeRxCB) (xXBee *xbee, xXBeePkt *pkt, uint8_t len);
74 
78 typedef enum {
82  XBEE_CB_IO = 3,
87  XBEE_CB_UNKNOWN = -1,
88  XBEE_CB_FIRST = XBEE_CB_AT_LOCAL,
89  XBEE_CB_LAST = XBEE_CB_NODE_IDENT
90 } eXBeeCbType;
91 
92 #ifndef __DOXYGEN__
93 // A modifier si eXBeeCbType modifié
94 #define XBEE_SIZEOF_CB 8
95 #endif
96 
102 typedef enum {
103  /* S1 & S2 Series */
104  XBEE_PKT_TYPE_ATCMD = 0x08,
105  XBEE_PKT_TYPE_QATCMD = 0x09, /* wait til an immed param or apply cmd */
106  XBEE_PKT_TYPE_REMOTE_ATCMD = 0x17,
107  XBEE_PKT_TYPE_ATCMD_RESP = 0x88,
108  XBEE_PKT_TYPE_MODEM_STATUS = 0x8a,
109  XBEE_PKT_TYPE_REMOTE_ATCMD_RESP = 0x97,
110 
111  /* S1 Series */
112  XBEE_PKT_TYPE_TX64 = 0x00,
113  XBEE_PKT_TYPE_TX16 = 0x01,
114  XBEE_PKT_TYPE_RX64 = 0x80,
115  XBEE_PKT_TYPE_RX16 = 0x81,
116  XBEE_PKT_TYPE_RX64_IO = 0x82,
117  XBEE_PKT_TYPE_RX16_IO = 0x83,
118  XBEE_PKT_TYPE_TX_STATUS = 0x89,
119 
120  /* S2 Series */
121  XBEE_PKT_TYPE_ZB_TX_REQ = 0x10,
122  XBEE_PKT_TYPE_ZB_CMD_FRAME = 0x11, /* Not yet impl */
123  XBEE_PKT_TYPE_ZB_TX_STATUS = 0x8b,
124  XBEE_PKT_TYPE_ZB_RX = 0x90,
125  XBEE_PKT_TYPE_ZB_RX_IO = 0x92,
126  XBEE_PKT_TYPE_ZB_RX_SENSOR = 0x94,
127  XBEE_PKT_TYPE_ZB_NODE_IDENT = 0x95,
128 } eXBeePktType;
129 
133 typedef enum {
134 
135  XBEE_PKT_STATUS_OK = 0,
136  XBEE_PKT_STATUS_ERROR = 1,
137  XBEE_PKT_STATUS_INVALID_COMMAND = 2,
138  XBEE_PKT_STATUS_INVALID_PARAMETER = 3,
139  XBEE_PKT_STATUS_TX_FAILURE = 4,
140  XBEE_PKT_STATUS_UNKNOWN = -1
142 
146 typedef enum {
147 
148  XBEE_PKT_MODEM_HARDWARE_RESET = 0,
149  XBEE_PKT_MODEM_WATCHDOG_TIMER_RESET = 1,
150  XBEE_PKT_MODEM_JOINED_NETWORK = 2,
151  XBEE_PKT_MODEM_DISASSOCIATED = 3,
152  XBEE_PKT_MODEM_COORDINATOR_STARTED = 4,
153  XBEE_PKT_MODEM_NETWORK_SECURITY_KEY_WAS_UPDATED = 7,
154  XBEE_PKT_MODEM_VOLTAGE_SUPPLY_LIMIT_EXCEEDED = 0x0D,
155  XBEE_PKT_MODEM_CONFIGURATION_CHANGED = 0x11,
156  XBEE_PKT_MODEM_STACK_ERROR = 0x80
158 
162 typedef enum {
163 
164  XBEE_RECV = 0x00,
165  XBEE_XMIT = 0x01
167 
171 typedef enum {
172 
173  XBEE_SERIES_S1 = 1,
174  XBEE_SERIES_S2 = 2,
175  XBEE_SERIES_S2B = 3,
176  XBEE_SERIES_UNKNOWN = -1
177 } eXBeeSeries;
178 
182 typedef enum {
183 
184  XBEE_DEVICE_COORDINATOR = 0,
185  XBEE_DEVICE_ROUTER = 1,
186  XBEE_DEVICE_END_DEVICE = 2,
187  XBEE_DEVICE_UNKNOWN = -1
189 
193 typedef enum {
194 
195  XBEE_EVENT_BUTTON = 1,
196  XBEE_EVENT_JOIN = 2,
197  XBEE_EVENT_POWER_ON = 3,
198  XBEE_EVENT_UNKNOWN = -1
200 
201 
202 /* internal public functions ================================================ */
211 xXBee * xXBeeNew (eXBeeSeries eSeries, xDPin * xResetPin);
212 
226 int iXBeeOpen (xXBee *xbee, const char * pcDevice, xSerialIos * xIos);
227 
235 int iXBeeClose (xXBee *xbee);
236 
246 void vXBeeSetCB (xXBee *xbee, eXBeeCbType cb_type, iXBeeRxCB cb);
247 
257 void * pvXBeeGetUserContext(xXBee *xbee);
258 
269 void vXBeeSetUserContext(xXBee *xbee, void * pvContext);
270 
276 eXBeeSeries eXBeeGetSeries (const xXBee *xbee);
277 
286 int iXBeePoll (xXBee *xbee, int timeout);
287 
294 /*
295  * Basic communication parameters/values
296  */
297 #define XBEE_CMD_CHANNEL "CH"
298 #define XBEE_CMD_PAN_ID "ID"
299 #define XBEE_CMD_OPERATING_PAN_ID "OP"
300 #define XBEE_CMD_DEST_ADDR64_HI "DH"
301 #define XBEE_CMD_DEST_ADDR64_LO "DL"
302 #define XBEE_CMD_SRC_ADDR16 "MY"
303 #define XBEE_CMD_SER_HI "SH"
304 #define XBEE_CMD_SER_LO "SL"
305 #define XBEE_CMD_RAND_DLY_SLOTS "RN"
306 #define XBEE_CMD_MAC_MODE "MM"
307 #define XBEE_CMD_COORD_ENA "CE"
308 #define XBEE_CMD_SCAN "SC"
309 #define XBEE_CMD_SCAN_DURATION "SD"
310 #define XBEE_CMD_ASSOC_END "A1"
311 #define XBEE_CMD_ASSOC_COORD "A2"
312 #define XBEE_CMD_ASSOC_STATUS "AI"
313 #define XBEE_CMD_RSSI "DB"
314 
315 /*
316  * Transceiver Control
317  */
318 #define XBEE_CMD_PWR_LEVEL "PL"
319 #define XBEE_CMD_CCA_THRESH "CA"
320 
321 /*
322  * Sleep Parameters
323  */
324 #define XBEE_CMD_SLEEP_MODE "SM"
325 #define XBEE_CMD_SLEEP_TIMEOUT "ST"
326 #define XBEE_CMD_SLEEP_PERIOD "SP"
327 #define XBEE_CMD_SLEEP_PERIOD_DISASSOC "DP"
328 
329 /*
330  * Interface parameters
331  */
332 #define XBEE_CMD_DATA_RATE "BD"
333 #define XBEE_CMD_PACKETIZATION_TIMEOUT "RO"
334 #define XBEE_CMD_DIO7_CONFIG "D7"
335 #define XBEE_CMD_DIO6_CONFIG "D6"
336 #define XBEE_CMD_DIO5_CONFIG "D5"
337 #define XBEE_CMD_DIO4_CONFIG "D4"
338 #define XBEE_CMD_DIO3_CONFIG "D3"
339 #define XBEE_CMD_DIO2_CONFIG "D2"
340 #define XBEE_CMD_DIO1_CONFIG "D1"
341 #define XBEE_CMD_DIO0_CONFIG "D0"
342 #define XBEE_CMD_PWM0_CONFIG "PO"
343 #define XBEE_CMD_API_ENA "AP"
344 #define XBEE_CMD_PULLUP_ENA "PR"
345 
346 /*
347  * Version Info
348  */
349 #define XBEE_CMD_VERS_FIRMWARE "VR"
350 #define XBEE_CMD_VERS_HARDWARE "HV"
351 #define XBEE_CMD_VERS_FIRM_VERBOSE "VL"
352 
353 /*
354  * Received Signal Strength
355  */
356 #define XBEE_CMD_RSSI_PWM_TIMER "RP"
357 #define XBEE_CMD_RSS "DB"
358 
359 /*
360  * Error counters
361  */
362 #define XBEE_CMD_CCA_FAILS "EC"
363 #define XBEE_CMD_ACK_FAILS "EA"
364 
365 /*
366  * AT Command Params
367  */
368 #define XBEE_CMD_AT_MODE_TIMEOUT "CT"
369 #define XBEE_CMD_AT_GUARD_TIME "GT"
370 #define XBEE_CMD_AT_CMD_CHAR "CC"
371 #define XBEE_CMD_AT_EXIT "CN"
372 
373 /*
374  * XBEE specific routing
375  */
376 #define XBEE_CMD_NODE_FIND_DEST "DN"
377 #define XBEE_CMD_NODE_DISCOVER "ND"
378 #define XBEE_CMD_NODE_ID "NI"
379 #define XBEE_CMD_ACTIVE_SCAN "AS"
380 #define XBEE_CMD_FORCE_DISASSOC "DA"
381 #define XBEE_CMD_ENERGY_SCAN "ED"
382 #define XBEE_CMD_FORCE_POLL "FP"
383 
384 /*
385  * IO Line Passing / Sensor Interfacing
386  */
387 #define XBEE_CMD_SAMPLE_RATE "IR"
388 #define XBEE_CMD_SAMPLES_BEFORE_TX "IT"
389 
390 /*
391  * Misc
392  */
393 #define XBEE_CMD_WRITE_PARAMS "WR"
394 #define XBEE_CMD_RESET_SOFT "FR"
395 #define XBEE_CMD_APPLY_CHANGES "AC"
396 #define XBEE_CMD_RESTORE_DEFAULTS "RE"
397 #define XBEE_CMD_MAX_PAYLOAD "NP"
398 
411 int iXBeeSendAt (xXBee *xbee,
412  const char cmd[],
413  const uint8_t *params,
414  uint8_t param_len);
415 
430 int iXBeeSendRemoteAt (xXBee *xbee,
431  const char cmd[],
432  const uint8_t params[],
433  uint8_t param_len,
434  const uint8_t addr64[8],
435  const uint8_t addr16[2],
436  uint8_t apply);
437 
438 
453 int iXBeeZbSend (xXBee *xbee,
454  const void *data,
455  uint8_t len,
456  const uint8_t addr64[8],
457  const uint8_t addr16[2],
458  uint8_t opt,
459  uint8_t radius);
460 
471 int iXBeeZbSendToCoordinator (xXBee *xbee, const void *data, uint8_t len);
472 
483 int iXBeeZbSendBroadcast (xXBee *xbee, const void *data, uint8_t len);
484 
497 int iXBeeSend64 (xXBee *xbee,
498  const void *data,
499  uint8_t len,
500  const uint8_t addr[8],
501  uint8_t opt);
502 
515 int iXBeeSend16 (xXBee *xbee,
516  const void *data,
517  uint8_t len,
518  const uint8_t addr[2],
519  uint8_t opt);
520 
521 
522 #ifdef __DOXYGEN__
523 
539 void *pvXBeeAllocPkt (xXBee *xbee, uint8_t direction, uint8_t len);
540 
548 void vXBeeFreePkt (xXBee *xbee, xXBeePkt *pkt);
549 
550 #else
551 // weak permet à l'utilisateur de redéfinir ces fonctions...
552 void *pvXBeeAllocPkt (xXBee *xbee, uint8_t direction, uint8_t len) __attribute__ ( (weak));
553 void vXBeeFreePkt (xXBee *xbee, xXBeePkt *pkt) __attribute__ ( (weak));
554 #endif
555 
561 uint8_t ucXBeePktType (xXBeePkt *pkt);
562 
569 uint16_t usXBeePktLength (xXBeePkt *pkt);
570 
577 uint8_t * pucXBeePktAddrSrc64 (xXBeePkt *pkt);
578 
585 uint8_t * pucXBeePktAddrSrc16 (xXBeePkt *pkt);
586 
593 uint8_t * iXBeePktDst16 (xXBeePkt *pkt);
594 
604 uint8_t * pucXBeePktData (xXBeePkt *pkt);
605 
612 int iXBeePktDataLen (xXBeePkt *pkt);
613 
620 int iXBeePktFrameId (xXBeePkt *pkt);
621 
628 int iXBeePktStatus (xXBeePkt *pkt);
629 
636 int iXBeePktDiscovery (xXBeePkt *pkt);
637 
644 int iXBeePktRetry (xXBeePkt *pkt);
645 
655 char * pcXBeePktCommand (xXBeePkt *pkt);
656 
663 uint8_t * pucXBeePktParam (xXBeePkt *pkt);
664 
676 int iXBeePktParamGetStr (char * pcDest, xXBeePkt *pkt, int iDestSize);
677 
686 int iXBeePktParamGetULong (uint32_t * ulDest, xXBeePkt *pkt, int iOffset);
687 
696 int iXBeePktParamGetULong (uint32_t * ulDest, xXBeePkt *pkt, int iOffset);
697 
706 int iXBeePktParamGetULongLong (uint64_t * ullDest, xXBeePkt *pkt, int iOffset);
707 
716 int iXBeePktParamGetUShort (uint16_t * usDest, xXBeePkt *pkt, int iOffset);
717 
726 int iXBeePktParamGetUByte (uint8_t * ucDest, xXBeePkt *pkt, int iOffset);
727 
734 int iXBeePktParamLen (xXBeePkt *pkt);
735 
742 int iXBeePktOptions (xXBeePkt *pkt);
743 
750 int iXBeePktRadius (xXBeePkt *pkt);
751 
758 int iXBeePktApply (xXBeePkt *pkt);
759 
766 int iXBeePktRssi (xXBeePkt *pkt);
767 
776 uint8_t * pucXBeePktAddrRemote64 (xXBeePkt *pkt);
777 
786 uint8_t * pucXBeePktAddrRemote16 (xXBeePkt *pkt);
787 
796 char * pcXBeePktNiString (xXBeePkt * pkt);
797 
806 uint8_t * pucXBeePktAddrParent16 (xXBeePkt *pkt);
807 
817 
827 
836 int iXBeePktProfileId (xXBeePkt * pkt);
837 
846 int iXBeePktManufacturerId (xXBeePkt * pkt);
847 
848 
855 int iXBeePktIsBroadcast (xXBeePkt *pkt);
856 
857 
861 bool bXBeePktAddressIsEqual (const uint8_t *a1, const uint8_t *a2, uint8_t len);
862 
869 const uint8_t * pucXBeeAddr16Unknown (void);
870 
877 const uint8_t * pucXBeeAddr64Unknown (void);
878 
885 const uint8_t * pucXBeeAddr64Coordinator (void);
886 
893 const uint8_t * pucXBeeAddr64Broadcast (void);
894 
895 /*==============================================================================
896  *
897  * TODO: Partie non finalisée par manque de temps
898  *
899  *============================================================================*/
900 #ifndef __DOXYGEN__
901 int iXBeePktDigital (xXBeePkt * pkt, int array[9], unsigned int index);
902 int iXBeePktAnalog (xXBeePkt * pkt, int array[6], unsigned int index);
903 int iXBeePktSamples (xXBeePkt * pkt);
904 
905 #endif /* __DOXYGEN__ not defined */
906 
912 /* ========================================================================== */
913 __END_C_DECLS
914 #endif /* _AVRIO_XBEE_H_ defined */
int iXBeePktApply(xXBeePkt *pkt)
Champs apply du paquet.
void vXBeeSetCB(xXBee *xbee, eXBeeCbType cb_type, iXBeeRxCB cb)
Modifie un gestionnaire de réception.
int iXBeePktFrameId(xXBeePkt *pkt)
Identifiant de paquet.
int iXBeePoll(xXBee *xbee, int timeout)
Scrute le flux relié au module en attente de réception d&#39;octet.
struct _xXBeePkt xXBeePkt
Paquet XBee générique.
Definition: xbee.h:52
int iXBeePktDataLen(xXBeePkt *pkt)
Nombre d&#39;octet de données (CRC exclu)
eXBeeCmdStatus
Réponses à une commande AT.
Definition: xbee.h:133
const uint8_t * pucXBeeAddr64Coordinator(void)
Adresse 64-bits du cordinateur Zigbee (0x0000000000000000)
eXBeeDirection
Direction d&#39;un échange XBee.
Definition: xbee.h:162
eXBeePktType
Types de paquets géré par le module.
Definition: xbee.h:102
eXBeeSourceEvent eXBeePktSourceEvent(xXBeePkt *pkt)
Source de l&#39;événement (Série 2)
uint8_t * pucXBeePktData(xXBeePkt *pkt)
Pointeur sur les données du paquet.
eXBeeDeviceType eXBeePktDeviceType(xXBeePkt *pkt)
Type de noeud (Série 2)
int iXBeePktParamGetULongLong(uint64_t *ullDest, xXBeePkt *pkt, int iOffset)
Copie d&#39;un très long mot des paramètres de commande AT.
eXBeeModemStatus
Status Modem.
Definition: xbee.h:146
char * pcXBeePktNiString(xXBeePkt *pkt)
Identifiant texte du noeud (Série 2)
int iXBeePktParamGetUByte(uint8_t *ucDest, xXBeePkt *pkt, int iOffset)
Copie d&#39;un octet des paramètres de commande AT.
int iXBeePktManufacturerId(xXBeePkt *pkt)
Identification du fabricant du module (Série 2)
int iXBeePktRadius(xXBeePkt *pkt)
Champs radius du paquet (Série 2)
eXBeeSourceEvent
Type de noeud.
Definition: xbee.h:193
int iXBeePktRssi(xXBeePkt *pkt)
Champs rssi du paquet (Série 1)
int iXBeeSendRemoteAt(xXBee *xbee, const char cmd[], const uint8_t params[], uint8_t param_len, const uint8_t addr64[8], const uint8_t addr16[2], uint8_t apply)
Envoi une commande AT à un module distant.
uint8_t * pucXBeePktAddrRemote16(xXBeePkt *pkt)
Adresse réseau 16-bits distante du paquet (Série 2)
int iXBeeSendAt(xXBee *xbee, const char cmd[], const uint8_t *params, uint8_t param_len)
Envoi une commande AT locale.
int iXBeePktIsBroadcast(xXBeePkt *pkt)
Indique si le paquet est un broadcast.
const uint8_t * pucXBeeAddr64Unknown(void)
Adresse 64-bits inconnue (0xFFFFFFFFFFFFFFFF)
struct _xXBee xXBee
Contexte d&#39;un module XBee.
Definition: xbee.h:59
void vXBeeFreePkt(xXBee *xbee, xXBeePkt *pkt)
Libère un paquet alloué avec pvXBeeAllocPkt()
int iXBeePktDiscovery(xXBeePkt *pkt)
Status de découverte de paquet (Série 2)
int iXBeePktParamLen(xXBeePkt *pkt)
Longueur des paramètres de la commande AT.
int iXBeeClose(xXBee *xbee)
Fermeture d&#39;un module XBee.
int iXBeeZbSendBroadcast(xXBee *xbee, const void *data, uint8_t len)
Envoi d&#39;un paquet de données de diffusion sur le réseau.
uint8_t * iXBeePktDst16(xXBeePkt *pkt)
Adresse réseau 16-bits destination du paquet (Série 2)
int iXBeeSend64(xXBee *xbee, const void *data, uint8_t len, const uint8_t addr[8], uint8_t opt)
Envoi d&#39;un paquet de données à un module distant par son adresse 64-bit.
int iXBeePktParamGetUShort(uint16_t *usDest, xXBeePkt *pkt, int iOffset)
Copie d&#39;un mot des paramètres de commande AT.
uint8_t * pucXBeePktAddrSrc64(xXBeePkt *pkt)
Adresse 64-bits source du paquet.
Broche numérique.
Definition: dpin.h:68
int iXBeeZbSendToCoordinator(xXBee *xbee, const void *data, uint8_t len)
Envoi d&#39;un paquet de données au coordinateur du réseau.
int iXBeeSend16(xXBee *xbee, const void *data, uint8_t len, const uint8_t addr[2], uint8_t opt)
Envoi d&#39;un paquet de données à un module distant par son adresse 16-bit.
int iXBeePktOptions(xXBeePkt *pkt)
Champs option du paquet.
void * pvXBeeGetUserContext(xXBee *xbee)
Renvoie le pointeur contexte utilisateur.
int iXBeeZbSend(xXBee *xbee, const void *data, uint8_t len, const uint8_t addr64[8], const uint8_t addr16[2], uint8_t opt, uint8_t radius)
Envoi d&#39;un paquet de données à un module distant.
uint8_t ucXBeePktType(xXBeePkt *pkt)
Lecture du type de paquet.
int iXBeeOpen(xXBee *xbee, const char *pcDevice, xSerialIos *xIos)
Ouverture d&#39;un module XBee.
int iXBeePktRetry(xXBeePkt *pkt)
Nombre de tentatives de paquet (Série 2)
int iXBeePktParamGetULong(uint32_t *ulDest, xXBeePkt *pkt, int iOffset)
Copie d&#39;un mot long des paramètres de commande AT.
eXBeeSeries
Serie du module XBee.
Definition: xbee.h:171
char * pcXBeePktCommand(xXBeePkt *pkt)
Nom de la commande AT.
int iXBeePktStatus(xXBeePkt *pkt)
Status de paquet.
uint16_t usXBeePktLength(xXBeePkt *pkt)
Taille du paquet en octets.
eXBeeSeries eXBeeGetSeries(const xXBee *xbee)
Retourne la série du module fournie à l&#39;ouverture.
uint8_t * pucXBeePktAddrSrc16(xXBeePkt *pkt)
Adresse réseau 16-bits source du paquet.
const uint8_t * pucXBeeAddr64Broadcast(void)
Adresse 64-bits de broadcast (0x000000000000FFFF)
eXBeeDeviceType
Type de noeud.
Definition: xbee.h:182
int iXBeePktProfileId(xXBeePkt *pkt)
Identifiant du profile Digi (Série 2)
bool bXBeePktAddressIsEqual(const uint8_t *a1, const uint8_t *a2, uint8_t len)
Vérifie l&#39;égalité de 2 adresses réseau de len octets.
void * pvXBeeAllocPkt(xXBee *xbee, uint8_t direction, uint8_t len)
Alloue la mémoire pour un paquet.
void vXBeeSetUserContext(xXBee *xbee, void *pvContext)
Modifie le contexte utilisateur.
int(* iXBeeRxCB)(xXBee *xbee, xXBeePkt *pkt, uint8_t len)
Prototype d&#39;un gestionnaire de réception.
Definition: xbee.h:73
uint8_t * pucXBeePktAddrRemote64(xXBeePkt *pkt)
Adresse 64-bits distante du paquet (Série 2)
const uint8_t * pucXBeeAddr16Unknown(void)
Adresse 16-bits inconnue (0xFFFE)
eXBeeCbType
Type de gestionnaire de réception.
Definition: xbee.h:78
uint8_t * pucXBeePktParam(xXBeePkt *pkt)
Paramètres de la commande AT.
uint8_t * pucXBeePktAddrParent16(xXBeePkt *pkt)
Adresse réseau 16-bits parent du paquet (Série 2)
int iXBeePktParamGetStr(char *pcDest, xXBeePkt *pkt, int iDestSize)
Copie les paramètres de commande AT.
xXBee * xXBeeNew(eXBeeSeries eSeries, xDPin *xResetPin)
Création d&#39;un nouvel objet XBee Si xResetPin est fournie, la broche RESET est affirmée à l&#39;état bas...