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)

Files at this revision

API Documentation at this revision

Comitter:
mariob
Date:
Thu Oct 11 06:21:42 2012 +0000
Parent:
10:9d5e02dea309
Child:
12:f35f9195d598
Commit message:
buffer error fixed

Changed in this revision

ssWi.cpp Show annotated file Show diff for this revision Revisions of this file
ssWiTypes.hpp Show annotated file Show diff for this revision Revisions of this file
xbee/MODSERIAL.lib Show annotated file Show diff for this revision Revisions of this file
xbee/xbee.cpp Show annotated file Show diff for this revision Revisions of this file
xbee/xbee.hpp Show annotated file Show diff for this revision Revisions of this file
--- a/ssWi.cpp	Mon Sep 24 21:16:35 2012 +0000
+++ b/ssWi.cpp	Thu Oct 11 06:21:42 2012 +0000
@@ -86,12 +86,12 @@
             mutexChannel.lock();
             channel->write(buffer, n);
             mutexChannel.unlock();
-/*
+            /*
             printf("W(%d): ", n);
             for(int k=0; k<n; k++)
                 printf("%d ", buffer[k]);
             printf("\n\r");
-*/
+            */
         }
         Thread::wait(TXRate);
     }
@@ -106,14 +106,14 @@
         int n = channel->read(buffer);
         mutexChannel.unlock();
 
-/*
-        if (n>0) {
-            printf("R(%d): ", n);
-            for(int k=0; k<n; k++)
-                printf("%d ", buffer[k]);
-            printf("\n\r");
-        }
-*/
+        /*
+                if (n>0) {
+                    printf("R(%d): ", n);
+                    for(int k=0; k<n; k++)
+                        printf("%d ", buffer[k]);
+                    printf("\n\r");
+                }
+        */
         bool alreadyIn = false;
         for (int i=0; i<(n-2);) {
             bool found = false;
@@ -126,7 +126,7 @@
                 PortID port = buffer[i++];
                 PortValue value = 0;
                 memcpy(&value, &buffer[i], sizeof(PortValue));
-                printf("Read[%d] = %d\n\r", port, value);
+//                printf("Read[%d] = %d\n\r", port, value);
                 i += sizeof(PortValue);
                 if (ports.find(port)!=ports.end())
                     ports[port].setRXValue(value);
--- a/ssWiTypes.hpp	Mon Sep 24 21:16:35 2012 +0000
+++ b/ssWiTypes.hpp	Thu Oct 11 06:21:42 2012 +0000
@@ -1,15 +1,15 @@
 /** \file ssWiTypes.hpp
  *  \brief type definition file
  */
-//
+
 #ifndef __SHARED_SLOTTED_TYPES_HPP__
 #define __SHARED_SLOTTED_TYPES_HPP__
 
-/** \brief Port Identifier
+/** \brief tyoe of the port IDentifier
  */
 typedef char PortID;
 
-/** \brief Value exchanged through the port
+/** \brief type of the Value exchanged through the port
  */
 typedef int PortValue;
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/xbee/MODSERIAL.lib	Thu Oct 11 06:21:42 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/AjK/code/MODSERIAL/#5c45c21f36b7
--- a/xbee/xbee.cpp	Mon Sep 24 21:16:35 2012 +0000
+++ b/xbee/xbee.cpp	Thu Oct 11 06:21:42 2012 +0000
@@ -39,7 +39,7 @@
 
 
 
-XBeeModule::XBeeModule (PinName tx, PinName rx, int panID, int channel) : xbee(tx, rx)
+XBeeModule::XBeeModule (PinName tx, PinName rx, int panID, int channel) : xbee(tx, rx, 64)
 {
     status = false;
     wait(1);
@@ -200,16 +200,17 @@
 int XBeeModule::read (char* msg)
 {
     int i = 0;
-    while (xbee.readable() && i<100)
+    while (xbee.readable())
         msg[i++] = xbee.getc();
     return i;
 }
 
 
+
 void XBeeModule::write (const char* msg, int n)
 {
     for (int i=0; i<n; i++) {
-        while(!xbee.writeable());
+        //while(!xbee.writeable());
         xbee.putc(msg[i]);
     }
 }
--- a/xbee/xbee.hpp	Mon Sep 24 21:16:35 2012 +0000
+++ b/xbee/xbee.hpp	Thu Oct 11 06:21:42 2012 +0000
@@ -3,6 +3,8 @@
 
 #include "mbed.h"
 
+#include "MODSERIAL.h"
+
 #include <ssWiChannel.hpp>
 
 #include "string"
@@ -42,7 +44,7 @@
 class XBeeModule: public ssWiChannel
 {
 
-    Serial xbee;
+    MODSERIAL xbee;
     XBeeAddress local;
 
     bool status;