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.
TODO:
- improve the parsing of the received messages
- communication tests with many nodes (so far, only 2 nodes have been tested)
xbee/xbee.hpp
- Committer:
- mariob
- Date:
- 2020-04-17
- Revision:
- 20:36931ee9af85
- Parent:
- 13:69ff47a83260
- Child:
- 24:80345e511574
File content as of revision 20:36931ee9af85:
/** \file xbee.hpp * \brief header of the ssWi channel using the XBee module * */ #ifndef __XBEE_MODULE_HPP__ #define __XBEE_MODULE_HPP__ #include "mbed.h" #include <ssWiChannel.hpp> #include "string" class XBeeAddress { uint32_t low; uint32_t high; public: XBeeAddress () : low(0), high(0) {} XBeeAddress (uint32_t low, uint32_t high) { this->low = low; this->high = high; } void setAddress(uint32_t low, uint32_t high) { this->low = low; this->high = high; } uint32_t getLowAddr () { return low; } uint32_t getHighAddr () { return high; } }; class XBeeBroadcastAddress: public XBeeAddress { public: XBeeBroadcastAddress () : XBeeAddress(0x00FFFF, 0) {} }; class XBeeModule: public ssWiChannel { Serial serial_xbee; XBeeAddress local; bool status; bool executeWithOk (const char* cmd); void executeWithRes (const char* cmd, char* res); void readResponse (char* msg); bool _getLocalAddr (); bool _setChannel (int channel); bool _setPanID (int id); bool initSequence(); public: XBeeModule (PinName tx, PinName rx, int panID, int channel); /* * specific for the XBee module */ XBeeAddress getLocalAddress () { return local; } bool setDstAddress (XBeeAddress addr); bool getDstAddress(XBeeAddress &addr); int getChannel (); int getPanID (); /* * inherited from ssWiChannel */ virtual bool init (int TXRate, int RXRate) { return _init(this, TXRate, RXRate); } virtual int read (char* msg); virtual void write (const char* msg, int n); }; #endif //__XBEE_MODULE_HPP__