GDP group 24 node core

Dependencies:   EthernetInterface SDFileSystem mbed-rtos mbed snail MbedJSONValue

Files at this revision

API Documentation at this revision

Comitter:
jakehodges
Date:
Tue Jan 13 22:48:25 2015 +0000
Parent:
13:344f559bf5ec
Child:
16:3ac37613f849
Child:
18:e68c8551d12c
Commit message:
Implement individual reading size. Add readyLine.rise interrupt.

Changed in this revision

sensorinterface.cpp Show annotated file Show diff for this revision Revisions of this file
sensorinterface.h Show annotated file Show diff for this revision Revisions of this file
--- a/sensorinterface.cpp	Tue Jan 13 21:34:08 2015 +0000
+++ b/sensorinterface.cpp	Tue Jan 13 22:48:25 2015 +0000
@@ -1,8 +1,9 @@
 #include "sensorinterface.h"
  
 sensorinterface::sensorinterface() : i2c(p28,p27), readyLine(p29)
-{
-    readyLine.fall(this, &sensorinterface::readyTrigger);
+{ 
+    readyLine.fall(this, &sensorinterface::readySet);
+    readyLine.rise(this, &sensorinterface::readyUnset);
     
     this->ready = false;
     
@@ -53,11 +54,16 @@
     }
 }
 
-void sensorinterface::readyTrigger()
+void sensorinterface::readySet()
 {
     this->ready = true;
 }
 
+void sensorinterface::readyUnset()
+{
+    this->ready = false;
+}
+
 #ifdef DEBUG
 void sensorinterface::error(int e_num)
 {
@@ -108,14 +114,14 @@
  
 sensor& sensorinterface::findType(sensor& s, int address)
 {
-    char response[3];
-    char cmd[1] = {'T'};
+    char response[I2C_TYPE_PACKET_SIZE];
+    char cmd[1] = {I2C_TYPE_HEADER};
  
     this->i2c.write(address, cmd, 1);
     int type_timeout = 10;
     i2c.stop();
     i2c.start();
-    while( (this->i2c.read(address, response, 3)) && (type_timeout) )
+    while( (this->i2c.read(address, response, I2C_TYPE_PACKET_SIZE)) && (type_timeout) )
     {
         --type_timeout;
         if (type_timeout == 2)
@@ -127,25 +133,16 @@
         }
     }
 
-    if (response[0] != 'T')
+    if (response[0] != I2C_TYPE_HEADER)
     {
         #ifdef DEBUG
             error(1);
         #endif
     }
-    else
-    {
-        //seperate the incoming bits
-        if ((response[1] != 0x00) && (response[1] != 0x01) && (response[1] != 0x02))
-        {
-            //if its not a recognised type
-            #ifdef DEBUG
-                error(2);
-            #endif
-        }
-    }
+
     s.type = response[1];
-    s.readingSize = response[2]; 
+    s.packetSize = response[2];
+    s.readingSize = response[3]; 
     return s;
 }
  
@@ -165,7 +162,7 @@
     #endif
     char address = currentSensor->first;
     char cmd[1] = {'D'};
-    char bufSize = currentSensor->second.readingSize + 2;
+    char bufSize = currentSensor->second.packetSize + 2;
     char buffer[bufSize];
     this->i2c.write(address, cmd, 1);
     wait(0.01);
@@ -188,9 +185,6 @@
         #endif
     }
     
-    // TODO sync ready property to ready line - don't manually
-    this->ready = false;
-    
     if (currentSensor != sensors.end() && sensors.size() > 1 )
     {
         #ifdef DEBUG
--- a/sensorinterface.h	Tue Jan 13 21:34:08 2015 +0000
+++ b/sensorinterface.h	Tue Jan 13 22:48:25 2015 +0000
@@ -6,11 +6,17 @@
 #include <map>
 #include <vector>
 
+#define I2C_TYPE_HEADER     'T'
+#define I2C_TYPE_REQUEST    'R'
+#define I2C_TYPE_DATA       'D'
+#define I2C_TYPE_PACKET_SIZE    4
+
 #define DEBUG
 
 struct sensor
 {
     char type;
+    char packetSize;
     char readingSize;
 };
 
@@ -36,7 +42,8 @@
         void error(int);
         sensor& findType(sensor& s, int address);
         int sendRequest(char address);
-        void readyTrigger();
+        void readySet();
+        void readyUnset();
         bool ready;
         
         I2C i2c;