AvrIO  1.4.5
Bibliothèque C modulaire pour ATMEL AVR
avrio/wusb/sensor.h
1 
21 #ifndef _AVRIO_WUSB_SENSOR_H_
22 #define _AVRIO_WUSB_SENSOR_H_
23 
24 #include <avrio/wusb/net/network.h>
25 
26 __BEGIN_C_DECLS
27 /* ========================================================================== */
37 /* constants ================================================================ */
42 typedef enum {
43 
46  /* Mode */
48  /* Bit 2 dispo. */
49  /* Status */
56 
61 typedef enum {
62 
65  /* Erreur < 0 */
68  WSENSOR_NODE_UNBOUND = (WNET_LAST_ERROR - 1),
69  WSENSOR_NODE_REBOUND = (WNET_LAST_ERROR - 2),
70  WSENSOR_SEARCH_TIMEOUT = (WNET_LAST_ERROR - 3),
71  WSENSOR_BIND_TIMEOUT = (WNET_LAST_ERROR - 4)
73 
74 /* == <API> == public application interface ========class xWusbSensor======== */
75 
80 void vWSensorInit(eWDevDataRate DataRate);
81 
103 void vWSensorBind(bool Seeded);
104 
112 void vWSensorSleepCB (eWSensorError eError);
113 
114 #if defined(__DOXYGEN__)
115 
118 void vWSensorDataClear(void);
119 
123 inline void vWSensorDataAddByte(uint8_t ucByte);
124 
128 inline void vWSensorDataAddWord(uint16_t ucWord);
129 
133 inline void vWSensorDataAddBytes(const uint8_t * pucData, uint8_t ucLength);
134 
138 inline void vWSensorDataAddBytes_P(const uint8_t * pucData, uint8_t ucLength);
139 
144 inline void vWSensorDataAddStr(const char * pcStr);
145 
151 inline void vWSensorDataAddStr_P(const char * pcStr);
152 
201 int iWSensorDataSend(bool Synchronous);
202 
208 uint8_t * pucWSensorBackDataPayload (void);
209 
215 uint8_t ucWSensorBackDataPayloadLength (void);
216 
220 inline bool xWSensorBound (void);
221 
225 inline void vWSensorSetAutoSeededBind (bool xEnable);
226 
230 inline bool xWSensorAutoSeededBind (void);
231 
235 inline bool xWSensorFlag(eWSensorFlags eFlag);
236 
240 inline uint16_t usWSensorDeviceId(void);
241 
247 inline void vWSensorSleep (bool xSleep);
248 
249 /* == <API-END> == public application interface ====class xWusbSensor======== */
255 #else /* __DOXYGEN__ defined */
256 
257 /* structures =============================================================== */
258 /*
259  * @struct xWSensorConfig
260  * @brief Configuration d'un capteur
261  */
262 typedef struct xWSensorConfig {
263 
264  uint16_t usDeviceId; /*< Identifiant attribué par le hub */
265  uint8_t ucFlags; /*< Bits d'états et de mode */
266 } xWSensorConfig;
267 
268 /*
269  * @struct xWusbSensor
270  * @brief Classe capteur d'un réseau WirelessUSB&tm;
271  */
272 typedef struct xWusbSensor {
273 
274  uint8_t ucPktBits; /*< Drapeaux transmis dans l'entête de paquet */
275  xWSensorConfig xConfig; /*< Configuration */
276 } xWusbSensor;
277 
278 /* internal public functions ================================================ */
279 void vWSensorDataClear(void);
280 int iWSensorDataSend(bool Synchronous);
281 uint8_t * pucWSensorBackDataPayload (void);
282 uint8_t ucWSensorBackDataPayloadLength (void);
283 
284 /* public variables ========================================================= */
285 extern xWusbSensor dSensor;
286 
287 /* inline public functions ================================================== */
288 __STATIC_ALWAYS_INLINE (void
289 vWSensorSleep (bool xSleep)) {
290 
291  vWDevSleep (xSleep);
292 }
293 
294 __STATIC_ALWAYS_INLINE (bool
295 xWSensorFlag (eWSensorFlags eFlag)) {
296 
297  return xWPktBit (dSensor.xConfig.ucFlags, eFlag);
298 }
299 
300 __STATIC_ALWAYS_INLINE (bool
301 xWSensorBound (void)) {
302 
303  return xWSensorFlag (WSENSOR_BOUND);
304 }
305 
306 __STATIC_ALWAYS_INLINE (bool
307 xWSensorAutoSeededBind (void)) {
308 
310 }
311 
312 __STATIC_ALWAYS_INLINE (uint16_t
313 usWSensorDeviceId(void)) {
314 
315  return dSensor.xConfig.usDeviceId;
316 }
317 
318 __STATIC_ALWAYS_INLINE (void
319 vWSensorSetFlag (eWSensorFlags eFlag, bool xValue)) {
320 
321  vWPktSetBit (&dSensor.xConfig.ucFlags, eFlag, xValue);
322 }
323 
324 __STATIC_ALWAYS_INLINE (void
325 vWSensorSetAutoSeededBind (bool xEnable)) {
326 
327  vWSensorSetFlag (xEnable, WSENSOR_AUTOSEEDEDBIND);
328 }
329 
330 /*------------ Setters Net Tx Packet -------------*/
331 __STATIC_ALWAYS_INLINE (void
332 vWSensorDataAddByte(uint8_t ucByte)) {
333 
334  vWNetTxPktAddByte (ucByte);
335 }
336 
337 __STATIC_ALWAYS_INLINE (void
338 vWSensorDataAddWord(uint16_t usWord)) {
339 
340  vWNetTxPktAddWord (usWord);
341 }
342 
343 __STATIC_ALWAYS_INLINE (void
344 vWSensorDataAddBytes(const uint8_t * pucData, uint8_t ucLength)) {
345 
346  vWNetTxPktAddBytes (pucData, ucLength);
347 }
348 
349 __STATIC_ALWAYS_INLINE (void
350 vWSensorDataAddBytes_P(const uint8_t * pucData, uint8_t ucLength)) {
351 
352  vWNetTxPktAddBytes_P (pucData, ucLength);
353 }
354 
355 __STATIC_ALWAYS_INLINE (void
356 vWSensorDataAddStr(const char * pcStr)) {
357 
358  vWNetTxPktAddStr (pcStr);
359 }
360 
361 __STATIC_ALWAYS_INLINE (void
362 vWSensorDataAddStr_P(const char * pcStr)) {
363 
364  vWNetTxPktAddStr_P (pcStr);
365 }
366 
367 #ifdef WSENSOR_TEST
368  int iSensorTestPing (uint16_t usCount, uint16_t usInterval,
369  xWNetTestResult * pxResult);
370 #else /* WSENSOR_TEST not defined */
371 # define iSensorTestPing(c,i,r) (0)
372 #endif /* WSENSOR_TEST defined */
373 
374 #endif /* __DOXYGEN__ not defined */
375 /* ========================================================================== */
376 __END_C_DECLS
377 #endif /* _AVRIO_WUSB_SENSOR_H_ */
void vWSensorDataClear(void)
Efface les données à envoyer au hub et prépare le prochain paquet DATA.
bool xWPktBit(uint8_t Byte, uint8_t Bit)
Renvoie l&#39;état du bit de rang Bit de l&#39;octet Byte.
void vWNetTxPktAddByte(uint8_t ucByte)
Ajoute un octet au paquet TX.
int iWSensorDataSend(bool Synchronous)
Transmission/Réception de données vers le hub Cette fonction effectue les opérations suivantes: ...
void vWSensorDataAddStr(const char *pcStr)
Ajoute une chaîne de caractères aux données à transmettre au hub Le zéro final n&#39;est pas ajouté au pa...
eWSensorFlags
Indice des bits de mode et d&#39;état utilisés par un capteur.
uint8_t ucWSensorBackDataPayloadLength(void)
Renvoie le nombre d&#39;octets renvoyés par le hub lors de la dernière transmission.
void vWSensorSleep(bool xSleep)
Endort ou réveille le module WirelessUSB afin d&#39;économiser de l&#39;énergie Le module est à l&#39;état statiq...
void vWNetTxPktAddWord(uint16_t usWord)
Ajoute un mot de 16 bits au paquet TX.
uint8_t * pucWSensorBackDataPayload(void)
Renvoie un pointeur sur les données renvoyées par le hub lors de la dernière transmission.
void vWSensorInit(eWDevDataRate DataRate)
Initialisation de la couche application capteur WirelessUSB™.
void vWSensorSetAutoSeededBind(bool xEnable)
Autorise le BIND rapide automatique en cas de retrait du réseau par le hub.
void vWSensorDataAddWord(uint16_t ucWord)
Ajoute un mot de 16 bits aux données à transmettre au hub.
bool xWSensorBound(void)
Indique si le sensor est intégré à un réseau.
bool xWSensorAutoSeededBind(void)
Indique si le BIND rapide automatique en cas de retrait du réseau par le hub est autorisé.
void vWPktSetBit(uint8_t *Byte, uint8_t Bit, bool xValue)
Modifie l&#39;état du bit de rang Bit de l&#39;octet pointé par Byte.
void vWSensorDataAddBytes_P(const uint8_t *pucData, uint8_t ucLength)
Ajoute des octets stockés en mémoire programme aux données à transmettre au hub.
eWSensorError
Codes d&#39;erreurs d&#39;un capteur.
bool xWSensorFlag(eWSensorFlags eFlag)
Teste un bit d&#39;état d&#39;indice eFlag.
void vWNetTxPktAddBytes(const uint8_t *pucBytes, uint8_t ucLength)
Ajoute une suite d&#39;octets au paquet TX.
eWDevDataRate
Différentes vitesse de transmission.
Definition: device.h:53
void vWSensorSleepCB(eWSensorError eError)
Gestionnaire d&#39;endormissement Cette fonction doit être implémentée par l&#39;utilisateur. Elle est appellée lorsque le hub ne répond pas ou plus.
void vWNetTxPktAddStr(const char *pcStr)
Ajoute une chaîne de caractères à zéro terminal au paquet TX Le zéro final n&#39;est pas ajouté au paquet...
uint16_t usWSensorDeviceId(void)
Renvoie le Device ID attribué par le hub (WNET_INVALID_DEVICEID si invalide)
void vWNetTxPktAddBytes_P(const uint8_t *pucBytes, uint8_t ucLength)
Ajoute une suite d&#39;octets résidant en mémoire programme au paquet TX.
void vWDevSleep(bool Sleep)
Endort ou réveille le module afin d&#39;économiser de l&#39;énergie Le module est à l&#39;état statique...
void vWSensorDataAddBytes(const uint8_t *pucData, uint8_t ucLength)
Ajoute des octets aux données à transmettre au hub.
void vWSensorDataAddStr_P(const char *pcStr)
Ajoute une chaîne de caractères stockée en mémoire programme aux données à transmettre au hub Le zéro...
void vWSensorDataAddByte(uint8_t ucByte)
Ajoute un octet aux données à transmettre au hub.
void vWSensorBind(bool Seeded)
Intègre le capteur au réseau WirelessUSB™ Envoie des paquets BIND REQUEST à la recherche d&#39;un hub...
void vWNetTxPktAddStr_P(const char *pcStr)
Ajoute une chaîne de caractères à zéro terminal résidant en mémoire programme au paquet TX Le zéro fi...