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:
Wed Mar 06 08:21:41 2013 +0000
Revision:
13:69ff47a83260
Parent:
11:4ad44d62d510
Child:
17:8ba1b278b407
Child:
20:36931ee9af85
added comments; MB

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 13:69ff47a83260 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 11:4ad44d62d510 11 #include "MODSERIAL.h"
mariob 11:4ad44d62d510 12
mariob 4:dbbf82c966c2 13 #include <ssWiChannel.hpp>
mariob 4:dbbf82c966c2 14
mariob 4:dbbf82c966c2 15 #include "string"
mariob 4:dbbf82c966c2 16
mariob 4:dbbf82c966c2 17
mariob 4:dbbf82c966c2 18 class XBeeAddress
mariob 4:dbbf82c966c2 19 {
mariob 4:dbbf82c966c2 20 string low;
mariob 4:dbbf82c966c2 21 string high;
mariob 4:dbbf82c966c2 22
mariob 4:dbbf82c966c2 23 public:
mariob 4:dbbf82c966c2 24
mariob 4:dbbf82c966c2 25 XBeeAddress () : low(""), high("") {}
mariob 4:dbbf82c966c2 26
mariob 4:dbbf82c966c2 27 XBeeAddress (string low, string high) {
mariob 4:dbbf82c966c2 28 this->low = low;
mariob 4:dbbf82c966c2 29 this->high = high;
mariob 4:dbbf82c966c2 30 }
mariob 4:dbbf82c966c2 31
mariob 4:dbbf82c966c2 32 string getLowAddr () {
mariob 4:dbbf82c966c2 33 return low;
mariob 4:dbbf82c966c2 34 }
mariob 4:dbbf82c966c2 35
mariob 4:dbbf82c966c2 36 string getHighAddr () {
mariob 4:dbbf82c966c2 37 return high;
mariob 4:dbbf82c966c2 38 }
mariob 4:dbbf82c966c2 39 };
mariob 4:dbbf82c966c2 40
mariob 4:dbbf82c966c2 41
mariob 4:dbbf82c966c2 42 class XBeeBroadcastAddress: public XBeeAddress
mariob 4:dbbf82c966c2 43 {
mariob 4:dbbf82c966c2 44 public:
mariob 4:dbbf82c966c2 45 XBeeBroadcastAddress () : XBeeAddress("00FFFF", "0") {}
mariob 4:dbbf82c966c2 46 };
mariob 4:dbbf82c966c2 47
mariob 4:dbbf82c966c2 48
mariob 4:dbbf82c966c2 49 class XBeeModule: public ssWiChannel
mariob 4:dbbf82c966c2 50 {
mariob 4:dbbf82c966c2 51
mariob 11:4ad44d62d510 52 MODSERIAL xbee;
mariob 4:dbbf82c966c2 53 XBeeAddress local;
mariob 4:dbbf82c966c2 54
mariob 4:dbbf82c966c2 55 bool status;
mariob 4:dbbf82c966c2 56
mariob 4:dbbf82c966c2 57 bool executeWithOk (const char* cmd);
mariob 4:dbbf82c966c2 58 void executeWithRes (const char* cmd, char* res);
mariob 4:dbbf82c966c2 59 void readResponse (char* msg);
mariob 4:dbbf82c966c2 60
mariob 4:dbbf82c966c2 61 bool _getLocalAddr ();
mariob 4:dbbf82c966c2 62 bool _setChannel (int channel);
mariob 4:dbbf82c966c2 63 bool _setPanID (int id);
mariob 4:dbbf82c966c2 64
mariob 4:dbbf82c966c2 65 public:
mariob 4:dbbf82c966c2 66
mariob 4:dbbf82c966c2 67 XBeeModule (PinName tx, PinName rx, int panID, int channel);
mariob 4:dbbf82c966c2 68
mariob 13:69ff47a83260 69 /*
mariob 13:69ff47a83260 70 * specific for the XBee module
mariob 13:69ff47a83260 71 */
mariob 4:dbbf82c966c2 72 XBeeAddress getLocalAddress () {
mariob 4:dbbf82c966c2 73 return local;
mariob 4:dbbf82c966c2 74 }
mariob 4:dbbf82c966c2 75
mariob 4:dbbf82c966c2 76 bool setDstAddress (XBeeAddress addr);
mariob 4:dbbf82c966c2 77
mariob 4:dbbf82c966c2 78 XBeeAddress getDstAddress ();
mariob 4:dbbf82c966c2 79
mariob 4:dbbf82c966c2 80 int getChannel ();
mariob 13:69ff47a83260 81
mariob 4:dbbf82c966c2 82 int getPanID ();
mariob 4:dbbf82c966c2 83
mariob 13:69ff47a83260 84
mariob 13:69ff47a83260 85 /*
mariob 13:69ff47a83260 86 * inherited from ssWiChannel
mariob 13:69ff47a83260 87 */
mariob 4:dbbf82c966c2 88 virtual bool init (int TXRate, int RXRate) {
mariob 4:dbbf82c966c2 89 return _init(this, TXRate, RXRate);
mariob 4:dbbf82c966c2 90 }
mariob 13:69ff47a83260 91
mariob 13:69ff47a83260 92 virtual int read (char* msg);
mariob 4:dbbf82c966c2 93
mariob 4:dbbf82c966c2 94 virtual void write (const char* msg, int n);
mariob 4:dbbf82c966c2 95
mariob 4:dbbf82c966c2 96 };
mariob 4:dbbf82c966c2 97
mariob 4:dbbf82c966c2 98 #endif //__XBEE_MODULE_HPP__