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)
Diff: ssWi.hpp
- Revision:
- 4:dbbf82c966c2
- Parent:
- 0:cc7218c5e5f7
- Child:
- 9:b5b5d0533fa6
diff -r 1adc077d4906 -r dbbf82c966c2 ssWi.hpp --- a/ssWi.hpp Thu Sep 06 12:11:52 2012 +0000 +++ b/ssWi.hpp Fri Sep 07 23:02:04 2012 +0000 @@ -1,63 +1,33 @@ -#ifndef __SHARED_SLOTTED_WIRELESS_HPP__ -#define __SHARED_SLOTTED_WIRELESS_HPP__ - -#include "ssWiTypes.hpp" -#include "ssWiChannel.hpp" -#include "ssWiPort.hpp" -#include "ssWiSocket.hpp" - -#include "rtos.h" - -#include <map> - - - -#define N_PORTS 256 - - - -class ssWi -{ - - ssWiChannel* channel; - Mutex mutexChannel; - - Thread* sender; - Thread* receiver; - - int msTXSleep; - int msRXSleep; - - std::map<int, ssWiPort> ports; - - friend void threadReceiver (void const* arg); - friend void threadSender (void const* arg); - - bool setPort (PortID port); - bool isActive (PortID port) { - return ports.find(port)!=ports.end(); - } - bool unsetPort (PortID port); - - void readFromChannel (char* msg, int& len); - void writeOnChannel (char* msg, int len); - - int getTXSleep () { - return msTXSleep; - } - int getRXSleep () { - return msRXSleep; - } - -public: - - ssWi (ssWiChannel* channel, int rateTX=10, int rateRX=20); - ~ssWi (); - - ssWiSocket* createSocket (PortID port); - - - -}; - -#endif //__SHARED_SLOTTED_WIRELESS_HPP__ +#ifndef __SHARED_SLOTTED_WIRELESS_HPP__ +#define __SHARED_SLOTTED_WIRELESS_HPP__ + +#include "ssWiTypes.hpp" + +/** \brief number of provided ports + * + */ +#define N_PORTS 256 + +class ssWiChannel; + +/** \brief Initialize the ssWi protocol + * + * It is not possible to have two instances of this protocol at the same time. + * + * \param c channel to be used for sending/receving data + * \param rateTX transmission rate + * \param rateRX receiving rate + * \return true if the network has been correctly initialized, false otherwise + */ +bool ssWi_init (ssWiChannel* c, int rateTX, int rateRX); + +void ssWi_stop (); + +bool ssWi_isActive (PortID port); + +bool ssWi_setPort (PortID port); + +bool ssWi_unsetPort (PortID port); + + +#endif //__SHARED_SLOTTED_WIRELESS_HPP__