Michael Ling / ExoController

Dependents:   Data-Management-Honka

Revision:
2:be605799793f
Child:
3:14050370593a
diff -r b637b515d387 -r be605799793f BluetoothComm.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/BluetoothComm.h	Wed Dec 17 21:46:45 2014 +0000
@@ -0,0 +1,92 @@
+#include "mbed.h"
+#include "MODSERIAL.h"
+//#include "init.h"
+
+#include <map>
+#include <string>
+
+
+class BluetoothComm
+{
+public:
+    BluetoothComm(PinName pwm, PinName dirpin);
+    void readDataFromSD();
+    void readParamsFromSD();
+    bool parity(short c);
+    char* checkSum(char* b, int len);
+    void sendError(char errCode);
+    void setCharge(short level);
+    void setValues(std::map<string, short> newValues);
+    void writeParamsToSDCard();
+    void writeDataToSDCard();
+    void send(char* cmd);
+    void sendValues(char* paramList);
+    void sendReadOnlyValues();
+    bool msgCheck(char* msg, int len);
+    void processReadOnly(char* message, int len);
+    void processRead(char* message, int len);
+    void processWrite(char* message, int len);
+    void process(char* message, int len);
+    void attachment();
+    int main();
+private:
+    MODSERIAL rn42; // serial object to read data coming in
+    //Map containing values of Exo parameters
+    std::map<std::string, short> paramMap;
+    //Maps parameter indices to param names
+    std::string indexMap[50];
+    //Last received MSG
+    char msg[50];
+    //Value of Exo parameters, stored locally
+    char localValues[50];
+    char curMsg[50];
+    //START/END bytes, parameter indices
+    static const char START = 0xff;
+    static const char END = 0xfe;
+    static const char KPSTANCE_IND = 0x0;
+    static const char KPSWING_IND = 0x1;
+    static const char KPSTAND_IND = 0x2;
+    static const char KPSIT_IND = 0x3;
+    static const char KPUP_IND = 0x4;
+    static const char KPDOWN_IND = 0x5;
+    static const char KDSTANCE_IND = 0x6;
+    static const char KDSWING_IND = 0x7;
+    static const char KDSTAND_IND = 0x8;
+    static const char KDSIT_IND = 0x9;
+    static const char KDUP_IND = 0xa;
+    static const char KDDOWN_IND = 0xb;
+    static const char STAND_IND = 0xc;
+    static const char SIT_IND = 0xd;
+    static const char BENT_IND = 0xe;
+    static const char FORWARD_IND = 0xf;
+    static const char REAR_IND = 0x10;
+    static const char IMU_IND = 0x11;
+    static const char RETRACT_IND = 0x12;
+    static const char EXTEND_IND = 0x13;
+    static const char LOCK_IND = 0x14;
+    static const char RATE_IND = 0x15;
+    int numVars;
+    //Last sent command
+    char lastCmd[50];
+    int failures;
+    //Error codes
+    static const char START_ERR = 1;
+    static const char END_ERR = 2;
+    static const char PARITY_ERR = 3;
+    static const char CHECKSUM_ERR = 4;
+    static const char VAR_ERR = 5;
+    static const char DATA_ERR =  6;
+    static const char RW_ERR = 7;
+    //Readonly Parameters
+    int numReadOnlyParams;
+    short readOnlyParams[12];
+    //Indices where an escape char. is needed
+    int escapeNeeded[9];
+    int escapesNeeded;
+    //Indicates a readonly request
+    static const char READONLY_IND = 0x1f;
+    int len;
+    int counter;
+    bool inMsg;
+    int data;
+};
\ No newline at end of file