Michael Ling / ExoController

Dependents:   Data-Management-Honka

Committer:
mzling
Date:
Wed Dec 17 21:46:45 2014 +0000
Revision:
2:be605799793f
Child:
3:14050370593a
Edited folder structure

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mzling 2:be605799793f 1 #include "mbed.h"
mzling 2:be605799793f 2 #include "MODSERIAL.h"
mzling 2:be605799793f 3 //#include "init.h"
mzling 2:be605799793f 4
mzling 2:be605799793f 5 #include <map>
mzling 2:be605799793f 6 #include <string>
mzling 2:be605799793f 7
mzling 2:be605799793f 8
mzling 2:be605799793f 9 class BluetoothComm
mzling 2:be605799793f 10 {
mzling 2:be605799793f 11 public:
mzling 2:be605799793f 12 BluetoothComm(PinName pwm, PinName dirpin);
mzling 2:be605799793f 13 void readDataFromSD();
mzling 2:be605799793f 14 void readParamsFromSD();
mzling 2:be605799793f 15 bool parity(short c);
mzling 2:be605799793f 16 char* checkSum(char* b, int len);
mzling 2:be605799793f 17 void sendError(char errCode);
mzling 2:be605799793f 18 void setCharge(short level);
mzling 2:be605799793f 19 void setValues(std::map<string, short> newValues);
mzling 2:be605799793f 20 void writeParamsToSDCard();
mzling 2:be605799793f 21 void writeDataToSDCard();
mzling 2:be605799793f 22 void send(char* cmd);
mzling 2:be605799793f 23 void sendValues(char* paramList);
mzling 2:be605799793f 24 void sendReadOnlyValues();
mzling 2:be605799793f 25 bool msgCheck(char* msg, int len);
mzling 2:be605799793f 26 void processReadOnly(char* message, int len);
mzling 2:be605799793f 27 void processRead(char* message, int len);
mzling 2:be605799793f 28 void processWrite(char* message, int len);
mzling 2:be605799793f 29 void process(char* message, int len);
mzling 2:be605799793f 30 void attachment();
mzling 2:be605799793f 31 int main();
mzling 2:be605799793f 32 private:
mzling 2:be605799793f 33 MODSERIAL rn42; // serial object to read data coming in
mzling 2:be605799793f 34 //Map containing values of Exo parameters
mzling 2:be605799793f 35 std::map<std::string, short> paramMap;
mzling 2:be605799793f 36 //Maps parameter indices to param names
mzling 2:be605799793f 37 std::string indexMap[50];
mzling 2:be605799793f 38 //Last received MSG
mzling 2:be605799793f 39 char msg[50];
mzling 2:be605799793f 40 //Value of Exo parameters, stored locally
mzling 2:be605799793f 41 char localValues[50];
mzling 2:be605799793f 42 char curMsg[50];
mzling 2:be605799793f 43 //START/END bytes, parameter indices
mzling 2:be605799793f 44 static const char START = 0xff;
mzling 2:be605799793f 45 static const char END = 0xfe;
mzling 2:be605799793f 46 static const char KPSTANCE_IND = 0x0;
mzling 2:be605799793f 47 static const char KPSWING_IND = 0x1;
mzling 2:be605799793f 48 static const char KPSTAND_IND = 0x2;
mzling 2:be605799793f 49 static const char KPSIT_IND = 0x3;
mzling 2:be605799793f 50 static const char KPUP_IND = 0x4;
mzling 2:be605799793f 51 static const char KPDOWN_IND = 0x5;
mzling 2:be605799793f 52 static const char KDSTANCE_IND = 0x6;
mzling 2:be605799793f 53 static const char KDSWING_IND = 0x7;
mzling 2:be605799793f 54 static const char KDSTAND_IND = 0x8;
mzling 2:be605799793f 55 static const char KDSIT_IND = 0x9;
mzling 2:be605799793f 56 static const char KDUP_IND = 0xa;
mzling 2:be605799793f 57 static const char KDDOWN_IND = 0xb;
mzling 2:be605799793f 58 static const char STAND_IND = 0xc;
mzling 2:be605799793f 59 static const char SIT_IND = 0xd;
mzling 2:be605799793f 60 static const char BENT_IND = 0xe;
mzling 2:be605799793f 61 static const char FORWARD_IND = 0xf;
mzling 2:be605799793f 62 static const char REAR_IND = 0x10;
mzling 2:be605799793f 63 static const char IMU_IND = 0x11;
mzling 2:be605799793f 64 static const char RETRACT_IND = 0x12;
mzling 2:be605799793f 65 static const char EXTEND_IND = 0x13;
mzling 2:be605799793f 66 static const char LOCK_IND = 0x14;
mzling 2:be605799793f 67 static const char RATE_IND = 0x15;
mzling 2:be605799793f 68 int numVars;
mzling 2:be605799793f 69 //Last sent command
mzling 2:be605799793f 70 char lastCmd[50];
mzling 2:be605799793f 71 int failures;
mzling 2:be605799793f 72 //Error codes
mzling 2:be605799793f 73 static const char START_ERR = 1;
mzling 2:be605799793f 74 static const char END_ERR = 2;
mzling 2:be605799793f 75 static const char PARITY_ERR = 3;
mzling 2:be605799793f 76 static const char CHECKSUM_ERR = 4;
mzling 2:be605799793f 77 static const char VAR_ERR = 5;
mzling 2:be605799793f 78 static const char DATA_ERR = 6;
mzling 2:be605799793f 79 static const char RW_ERR = 7;
mzling 2:be605799793f 80 //Readonly Parameters
mzling 2:be605799793f 81 int numReadOnlyParams;
mzling 2:be605799793f 82 short readOnlyParams[12];
mzling 2:be605799793f 83 //Indices where an escape char. is needed
mzling 2:be605799793f 84 int escapeNeeded[9];
mzling 2:be605799793f 85 int escapesNeeded;
mzling 2:be605799793f 86 //Indicates a readonly request
mzling 2:be605799793f 87 static const char READONLY_IND = 0x1f;
mzling 2:be605799793f 88 int len;
mzling 2:be605799793f 89 int counter;
mzling 2:be605799793f 90 bool inMsg;
mzling 2:be605799793f 91 int data;
mzling 2:be605799793f 92 };