A simple wireless protocol to let my examples communicate each other. ssWi stands for Shared Slotted Wireless protocol

Dependents:   rover_car rover_pc supervisor watering_unit ... more

This library aims at implementing a simple communication protocol among nodes, abstracting from the hardware. The name ssWi stands for Shared Slotted Wireless. Wireless is part of the name, even though the library abstracts from the hardware, as the first version was entirely focused on the XBee modules and then the name has not been changed.

The communication channel is represented by ssWiChannel, an abstract class which models the channel that the transceivers access to. The concrete classes must implement the functions: init, read and write. The protocol automatically sends and receives data through the selected channel, exploiting the operting system timers. Addresses are not considered as the communication lays on broadcast transmissions.

The protocol provides the ssWiPort abstraction which is like memory areas shared among all the connected nodes. Reading from one port lets the node retrieve the last written value from the other nodes. Writing on one port means sending such value to other nodes.

Objects instantiated from ssWiSocket are the interface for allowing nodes to access the protocol ports.

/media/uploads/mariob/scheme.png

TODO:

  • improve the parsing of the received messages
  • communication tests with many nodes (so far, only 2 nodes have been tested)
Committer:
mariob
Date:
Mon Apr 20 20:27:01 2020 +0000
Revision:
24:80345e511574
Parent:
20:36931ee9af85
few more comments

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mariob 13:69ff47a83260 1 /** \file xbee.hpp
mariob 13:69ff47a83260 2 * \brief header of the ssWi channel using the XBee module
mariob 13:69ff47a83260 3 *
mariob 13:69ff47a83260 4 */
mariob 24:80345e511574 5
mariob 4:dbbf82c966c2 6 #ifndef __XBEE_MODULE_HPP__
mariob 4:dbbf82c966c2 7 #define __XBEE_MODULE_HPP__
mariob 4:dbbf82c966c2 8
mariob 4:dbbf82c966c2 9 #include "mbed.h"
mariob 4:dbbf82c966c2 10
mariob 4:dbbf82c966c2 11 #include <ssWiChannel.hpp>
mariob 4:dbbf82c966c2 12
mariob 4:dbbf82c966c2 13 #include "string"
mariob 4:dbbf82c966c2 14
mariob 4:dbbf82c966c2 15
mariob 4:dbbf82c966c2 16 class XBeeAddress
mariob 4:dbbf82c966c2 17 {
mariob 20:36931ee9af85 18 uint32_t low;
mariob 20:36931ee9af85 19 uint32_t high;
mariob 4:dbbf82c966c2 20
mariob 4:dbbf82c966c2 21 public:
mariob 4:dbbf82c966c2 22
mariob 20:36931ee9af85 23 XBeeAddress () : low(0), high(0) {}
mariob 4:dbbf82c966c2 24
mariob 20:36931ee9af85 25 XBeeAddress (uint32_t low, uint32_t high) {
mariob 4:dbbf82c966c2 26 this->low = low;
mariob 4:dbbf82c966c2 27 this->high = high;
mariob 20:36931ee9af85 28 }
mariob 4:dbbf82c966c2 29
mariob 20:36931ee9af85 30 void setAddress(uint32_t low, uint32_t high) {
mariob 20:36931ee9af85 31 this->low = low;
mariob 20:36931ee9af85 32 this->high = high;
mariob 20:36931ee9af85 33 }
mariob 20:36931ee9af85 34
mariob 20:36931ee9af85 35 uint32_t getLowAddr () {
mariob 4:dbbf82c966c2 36 return low;
mariob 4:dbbf82c966c2 37 }
mariob 4:dbbf82c966c2 38
mariob 20:36931ee9af85 39 uint32_t getHighAddr () {
mariob 4:dbbf82c966c2 40 return high;
mariob 4:dbbf82c966c2 41 }
mariob 4:dbbf82c966c2 42 };
mariob 4:dbbf82c966c2 43
mariob 4:dbbf82c966c2 44
mariob 4:dbbf82c966c2 45 class XBeeBroadcastAddress: public XBeeAddress
mariob 4:dbbf82c966c2 46 {
mariob 4:dbbf82c966c2 47 public:
mariob 20:36931ee9af85 48 XBeeBroadcastAddress () : XBeeAddress(0x00FFFF, 0) {}
mariob 4:dbbf82c966c2 49 };
mariob 4:dbbf82c966c2 50
mariob 4:dbbf82c966c2 51
mariob 4:dbbf82c966c2 52 class XBeeModule: public ssWiChannel
mariob 4:dbbf82c966c2 53 {
mariob 4:dbbf82c966c2 54
mariob 20:36931ee9af85 55 Serial serial_xbee;
mariob 4:dbbf82c966c2 56 XBeeAddress local;
mariob 4:dbbf82c966c2 57
mariob 4:dbbf82c966c2 58 bool status;
mariob 4:dbbf82c966c2 59
mariob 4:dbbf82c966c2 60 bool executeWithOk (const char* cmd);
mariob 4:dbbf82c966c2 61 void executeWithRes (const char* cmd, char* res);
mariob 4:dbbf82c966c2 62 void readResponse (char* msg);
mariob 4:dbbf82c966c2 63
mariob 4:dbbf82c966c2 64 bool _getLocalAddr ();
mariob 4:dbbf82c966c2 65 bool _setChannel (int channel);
mariob 4:dbbf82c966c2 66 bool _setPanID (int id);
mariob 20:36931ee9af85 67
mariob 20:36931ee9af85 68 bool initSequence();
mariob 4:dbbf82c966c2 69
mariob 4:dbbf82c966c2 70 public:
mariob 4:dbbf82c966c2 71
mariob 4:dbbf82c966c2 72 XBeeModule (PinName tx, PinName rx, int panID, int channel);
mariob 4:dbbf82c966c2 73
mariob 13:69ff47a83260 74 /*
mariob 13:69ff47a83260 75 * specific for the XBee module
mariob 13:69ff47a83260 76 */
mariob 4:dbbf82c966c2 77 XBeeAddress getLocalAddress () {
mariob 4:dbbf82c966c2 78 return local;
mariob 4:dbbf82c966c2 79 }
mariob 4:dbbf82c966c2 80
mariob 4:dbbf82c966c2 81 bool setDstAddress (XBeeAddress addr);
mariob 4:dbbf82c966c2 82
mariob 20:36931ee9af85 83 bool getDstAddress(XBeeAddress &addr);
mariob 4:dbbf82c966c2 84
mariob 4:dbbf82c966c2 85 int getChannel ();
mariob 13:69ff47a83260 86
mariob 4:dbbf82c966c2 87 int getPanID ();
mariob 4:dbbf82c966c2 88
mariob 13:69ff47a83260 89
mariob 13:69ff47a83260 90 /*
mariob 13:69ff47a83260 91 * inherited from ssWiChannel
mariob 13:69ff47a83260 92 */
mariob 4:dbbf82c966c2 93 virtual bool init (int TXRate, int RXRate) {
mariob 4:dbbf82c966c2 94 return _init(this, TXRate, RXRate);
mariob 4:dbbf82c966c2 95 }
mariob 13:69ff47a83260 96
mariob 13:69ff47a83260 97 virtual int read (char* msg);
mariob 4:dbbf82c966c2 98
mariob 4:dbbf82c966c2 99 virtual void write (const char* msg, int n);
mariob 4:dbbf82c966c2 100
mariob 4:dbbf82c966c2 101 };
mariob 4:dbbf82c966c2 102
mariob 4:dbbf82c966c2 103 #endif //__XBEE_MODULE_HPP__