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:
Tue Apr 21 08:23:47 2020 +0000
Revision:
25:83172a067b57
Parent:
14:0832655db3c1
added comments

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mariob 4:dbbf82c966c2 1 /** \file ssWiChannel.hpp
mariob 4:dbbf82c966c2 2 * \brief Abstract class for the communication channel
mariob 4:dbbf82c966c2 3 *
mariob 4:dbbf82c966c2 4 */
mariob 5:0b0ca40aeb81 5
mariob 0:cc7218c5e5f7 6 #ifndef __SHARED_SLOTTED_WIRELESS_CHANNEL_HPP__
mariob 0:cc7218c5e5f7 7 #define __SHARED_SLOTTED_WIRELESS_CHANNEL_HPP__
mariob 0:cc7218c5e5f7 8
mariob 4:dbbf82c966c2 9
mariob 4:dbbf82c966c2 10 #include "ssWi.hpp"
mariob 4:dbbf82c966c2 11
mariob 4:dbbf82c966c2 12
mariob 4:dbbf82c966c2 13 /** \brief Abstract class for a communication channel
mariob 4:dbbf82c966c2 14 *
mariob 4:dbbf82c966c2 15 */
mariob 0:cc7218c5e5f7 16 class ssWiChannel
mariob 0:cc7218c5e5f7 17 {
mariob 4:dbbf82c966c2 18
mariob 4:dbbf82c966c2 19 protected:
mariob 4:dbbf82c966c2 20
mariob 4:dbbf82c966c2 21 /** \brief Initialize the protocol
mariob 13:69ff47a83260 22 *
mariob 13:69ff47a83260 23 * \param c ssWi channel
mariob 14:0832655db3c1 24 * \param TXRate how may times trans every second
mariob 13:69ff47a83260 25 * \param RXRate how may time rx every second
mariob 13:69ff47a83260 26 * \return true if the channel is ready, false otherwise
mariob 4:dbbf82c966c2 27 */
mariob 4:dbbf82c966c2 28 bool _init (ssWiChannel* c, int TXRate, int RXRate) {
mariob 4:dbbf82c966c2 29 return ssWi_init(c, TXRate, RXRate);
mariob 4:dbbf82c966c2 30 }
mariob 4:dbbf82c966c2 31
mariob 0:cc7218c5e5f7 32 public:
mariob 4:dbbf82c966c2 33
mariob 4:dbbf82c966c2 34 /** \brief Initialize ssWi on this channel
mariob 4:dbbf82c966c2 35 *
mariob 4:dbbf82c966c2 36 * \param TXRate number of transmissions per second
mariob 4:dbbf82c966c2 37 * \param RXRate number of receptions per second
mariob 13:69ff47a83260 38 * \return true if ssWi has been initialized succefully, false otherwise
mariob 4:dbbf82c966c2 39 */
mariob 4:dbbf82c966c2 40 virtual bool init (int TXRate, int RXRate) = 0;
mariob 4:dbbf82c966c2 41
mariob 4:dbbf82c966c2 42 /** \brief read from the socket
mariob 4:dbbf82c966c2 43 *
mariob 4:dbbf82c966c2 44 * \param msg buffer where to write the read message
mariob 4:dbbf82c966c2 45 * \return the number of read bytes
mariob 4:dbbf82c966c2 46 */
mariob 0:cc7218c5e5f7 47 virtual int read (char* msg) = 0;
mariob 4:dbbf82c966c2 48
mariob 4:dbbf82c966c2 49 /** \brief write to the socket
mariob 4:dbbf82c966c2 50 *
mariob 4:dbbf82c966c2 51 * \param msg buffer with the message to send
mariob 14:0832655db3c1 52 * \param n number of bytes to send
mariob 4:dbbf82c966c2 53 */
mariob 0:cc7218c5e5f7 54 virtual void write (const char* msg, int n) = 0;
mariob 5:0b0ca40aeb81 55
mariob 0:cc7218c5e5f7 56 };
mariob 0:cc7218c5e5f7 57
mariob 0:cc7218c5e5f7 58 #endif //__SHARED_SLOTTED_WIRELESS_CHANNEL_HPP__