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:
Fri Sep 07 23:02:04 2012 +0000
Revision:
4:dbbf82c966c2
Parent:
0:cc7218c5e5f7
Child:
11:4ad44d62d510
new version

Who changed what in which revision?

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