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:
Thu Sep 06 10:37:03 2012 +0000
Revision:
0:cc7218c5e5f7
Child:
4:dbbf82c966c2
ssWi

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mariob 0:cc7218c5e5f7 1 #ifndef __XBEE_MODULE_HPP__
mariob 0:cc7218c5e5f7 2 #define __XBEE_MODULE_HPP__
mariob 0:cc7218c5e5f7 3
mariob 0:cc7218c5e5f7 4 #include "mbed.h"
mariob 0:cc7218c5e5f7 5
mariob 0:cc7218c5e5f7 6 #include <ssWiChannel.hpp>
mariob 0:cc7218c5e5f7 7
mariob 0:cc7218c5e5f7 8 #include "string"
mariob 0:cc7218c5e5f7 9
mariob 0:cc7218c5e5f7 10
mariob 0:cc7218c5e5f7 11 class XBeeAddress
mariob 0:cc7218c5e5f7 12 {
mariob 0:cc7218c5e5f7 13 string low;
mariob 0:cc7218c5e5f7 14 string high;
mariob 0:cc7218c5e5f7 15
mariob 0:cc7218c5e5f7 16 public:
mariob 0:cc7218c5e5f7 17
mariob 0:cc7218c5e5f7 18 XBeeAddress () : low(""), high("") {}
mariob 0:cc7218c5e5f7 19
mariob 0:cc7218c5e5f7 20 XBeeAddress (string low, string high) {
mariob 0:cc7218c5e5f7 21 this->low = low;
mariob 0:cc7218c5e5f7 22 this->high = high;
mariob 0:cc7218c5e5f7 23 }
mariob 0:cc7218c5e5f7 24
mariob 0:cc7218c5e5f7 25 string getLowAddr () {
mariob 0:cc7218c5e5f7 26 return low;
mariob 0:cc7218c5e5f7 27 }
mariob 0:cc7218c5e5f7 28
mariob 0:cc7218c5e5f7 29 string getHighAddr () {
mariob 0:cc7218c5e5f7 30 return high;
mariob 0:cc7218c5e5f7 31 }
mariob 0:cc7218c5e5f7 32 };
mariob 0:cc7218c5e5f7 33
mariob 0:cc7218c5e5f7 34
mariob 0:cc7218c5e5f7 35 class XBeeBroadcastAddress: public XBeeAddress
mariob 0:cc7218c5e5f7 36 {
mariob 0:cc7218c5e5f7 37 public:
mariob 0:cc7218c5e5f7 38 XBeeBroadcastAddress () : XBeeAddress("00FFFF", "0") {}
mariob 0:cc7218c5e5f7 39 };
mariob 0:cc7218c5e5f7 40
mariob 0:cc7218c5e5f7 41
mariob 0:cc7218c5e5f7 42 class XBeeModule: public ssWiChannel
mariob 0:cc7218c5e5f7 43 {
mariob 0:cc7218c5e5f7 44
mariob 0:cc7218c5e5f7 45 Serial xbee;
mariob 0:cc7218c5e5f7 46 XBeeAddress local;
mariob 0:cc7218c5e5f7 47
mariob 0:cc7218c5e5f7 48 bool status;
mariob 0:cc7218c5e5f7 49
mariob 0:cc7218c5e5f7 50 bool executeWithOk (const char* cmd);
mariob 0:cc7218c5e5f7 51 void executeWithRes (const char* cmd, char* res);
mariob 0:cc7218c5e5f7 52 void readResponse (char* msg);
mariob 0:cc7218c5e5f7 53
mariob 0:cc7218c5e5f7 54 bool _getLocalAddr ();
mariob 0:cc7218c5e5f7 55 bool _setChannel (int channel);
mariob 0:cc7218c5e5f7 56 bool _setPanID (int id);
mariob 0:cc7218c5e5f7 57
mariob 0:cc7218c5e5f7 58 public:
mariob 0:cc7218c5e5f7 59
mariob 0:cc7218c5e5f7 60 XBeeModule (PinName tx, PinName rx, int panID, int channel);
mariob 0:cc7218c5e5f7 61
mariob 0:cc7218c5e5f7 62 XBeeAddress getLocalAddress () {
mariob 0:cc7218c5e5f7 63 return local;
mariob 0:cc7218c5e5f7 64 }
mariob 0:cc7218c5e5f7 65
mariob 0:cc7218c5e5f7 66 bool setDstAddress (XBeeAddress addr);
mariob 0:cc7218c5e5f7 67
mariob 0:cc7218c5e5f7 68 XBeeAddress getDstAddress ();
mariob 0:cc7218c5e5f7 69
mariob 0:cc7218c5e5f7 70
mariob 0:cc7218c5e5f7 71 int getChannel ();
mariob 0:cc7218c5e5f7 72 int getPanID ();
mariob 0:cc7218c5e5f7 73
mariob 0:cc7218c5e5f7 74 virtual int read (char* msg);
mariob 0:cc7218c5e5f7 75 virtual void write (const char* msg, int n);
mariob 0:cc7218c5e5f7 76
mariob 0:cc7218c5e5f7 77 };
mariob 0:cc7218c5e5f7 78
mariob 0:cc7218c5e5f7 79 #endif //__XBEE_MODULE_HPP__