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 Oct 11 06:21:42 2012 +0000
Revision:
11:4ad44d62d510
Parent:
4:dbbf82c966c2
Child:
13:69ff47a83260
buffer error fixed

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