Michael Ling / ExoController

Dependents:   Data-Management-Honka

Committer:
mzling
Date:
Thu Mar 05 23:48:54 2015 +0000
Revision:
11:56bd3affbbfc
Parent:
10:235c0b81c4c7
Parent:
9:8024861fccac
Child:
14:ac9949a0aff5
Added dataOut arguments.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mzling 8:57d988783b45 1 #ifndef DATACOMM_H
mzling 8:57d988783b45 2 #define DATACOMM_H
mzling 2:be605799793f 3
mzling 2:be605799793f 4 #include <map>
mzling 2:be605799793f 5 #include <string>
mzling 2:be605799793f 6
mzling 3:14050370593a 7 #include "mbed.h"
mzling 3:14050370593a 8 #include "MODSERIAL.h"
mzling 3:14050370593a 9 /**
mzling 3:14050370593a 10 * @file BluetoothComm.h
mzling 3:14050370593a 11 * @brief This header file describes BluetoothComm, an object that receives and processes messages through Bluetooth.
mzling 3:14050370593a 12 * @author Michael Ling
mzling 3:14050370593a 13 * @date 2/4/2015
mzling 3:14050370593a 14 */
mzling 2:be605799793f 15
mzling 2:be605799793f 16 class BluetoothComm
mzling 2:be605799793f 17 {
mzling 2:be605799793f 18 public:
mzling 2:be605799793f 19 BluetoothComm(PinName pwm, PinName dirpin);
mzling 3:14050370593a 20 void read_data_from_sd();
mzling 3:14050370593a 21 void read_params_from_sd();
mzling 2:be605799793f 22 bool parity(short c);
mzling 3:14050370593a 23 char* get_checksum(char* b, int len);
mzling 3:14050370593a 24 void send_error(char errCode);
mzling 3:14050370593a 25 //void setCharge(short level);
mzling 3:14050370593a 26 void set_values(std::map<string, short> newValues);
mzling 3:14050370593a 27 void write_params_to_sd_card();
mzling 3:14050370593a 28 void write_data_to_sd_card();
mzling 2:be605799793f 29 void send(char* cmd);
mzling 10:235c0b81c4c7 30 void send_values(char* paramList, short *dataOut);
mzling 3:14050370593a 31 void send_read_only_values();
mzling 3:14050370593a 32 bool msg_check(char* msg, int len);
mzling 3:14050370593a 33 void process_read_only(char* message, int len);
mzling 3:14050370593a 34 void process_read(char* message, int len);
mzling 10:235c0b81c4c7 35 void process_write(char* message, int len, short* dataOut);
mzling 10:235c0b81c4c7 36 void process(char* message, int len, short* dataOut);
mzling 10:235c0b81c4c7 37 void attachment(short* dataOut);
mzling 2:be605799793f 38 int main();
mzling 3:14050370593a 39
mzling 2:be605799793f 40 private:
mzling 3:14050370593a 41 MODSERIAL _rn42; // serial object to read data coming in
mzling 2:be605799793f 42 //Map containing values of Exo parameters
mzling 3:14050370593a 43 std::map<std::string, short> _paramMap;
mzling 2:be605799793f 44 //Maps parameter indices to param names
mzling 3:14050370593a 45 std::string _indexMap[50];
mzling 2:be605799793f 46 //Last received MSG
mzling 3:14050370593a 47 char _msg[50];
mzling 2:be605799793f 48 //Value of Exo parameters, stored locally
mzling 3:14050370593a 49 // _localValues[50];
mzling 3:14050370593a 50 char _curMsg[50];
mzling 3:14050370593a 51 int _numVars;
mzling 3:14050370593a 52 //Last sent command
mzling 3:14050370593a 53 char _lastCmd[50];
mzling 3:14050370593a 54 int _failures;
mzling 3:14050370593a 55 //Readonly Parameters
mzling 3:14050370593a 56 int _numReadOnlyParams;
mzling 3:14050370593a 57 short _readOnlyParams[12];
mzling 3:14050370593a 58 //Indices where an escape char. is needed
mzling 3:14050370593a 59 int _escapeNeeded[9];
mzling 3:14050370593a 60 int _escapesNeeded;
mzling 3:14050370593a 61 int _len;
mzling 3:14050370593a 62 int _counter;
mzling 3:14050370593a 63 bool _inMsg;
mzling 3:14050370593a 64 int _data;
mzling 3:14050370593a 65
mzling 2:be605799793f 66 //START/END bytes, parameter indices
mzling 2:be605799793f 67 static const char START = 0xff;
mzling 2:be605799793f 68 static const char END = 0xfe;
mzling 2:be605799793f 69 static const char KPSTANCE_IND = 0x0;
mzling 2:be605799793f 70 static const char KPSWING_IND = 0x1;
mzling 2:be605799793f 71 static const char KPSTAND_IND = 0x2;
mzling 2:be605799793f 72 static const char KPSIT_IND = 0x3;
mzling 2:be605799793f 73 static const char KPUP_IND = 0x4;
mzling 2:be605799793f 74 static const char KPDOWN_IND = 0x5;
mzling 2:be605799793f 75 static const char KDSTANCE_IND = 0x6;
mzling 2:be605799793f 76 static const char KDSWING_IND = 0x7;
mzling 2:be605799793f 77 static const char KDSTAND_IND = 0x8;
mzling 2:be605799793f 78 static const char KDSIT_IND = 0x9;
mzling 2:be605799793f 79 static const char KDUP_IND = 0xa;
mzling 2:be605799793f 80 static const char KDDOWN_IND = 0xb;
mzling 2:be605799793f 81 static const char STAND_IND = 0xc;
mzling 2:be605799793f 82 static const char SIT_IND = 0xd;
mzling 2:be605799793f 83 static const char BENT_IND = 0xe;
mzling 2:be605799793f 84 static const char FORWARD_IND = 0xf;
mzling 2:be605799793f 85 static const char REAR_IND = 0x10;
mzling 2:be605799793f 86 static const char IMU_IND = 0x11;
mzling 2:be605799793f 87 static const char RETRACT_IND = 0x12;
mzling 2:be605799793f 88 static const char EXTEND_IND = 0x13;
mzling 2:be605799793f 89 static const char LOCK_IND = 0x14;
mzling 2:be605799793f 90 static const char RATE_IND = 0x15;
mzling 9:8024861fccac 91 static const char SUASST_IND = 0x16;
mzling 9:8024861fccac 92 static const char SUTIME_IND = 0x17;
mzling 9:8024861fccac 93 static const char SDASST_IND = 0x18;
mzling 9:8024861fccac 94 static const char SDTIME_IND = 0x19;
mzling 9:8024861fccac 95 static const char WALK_IND = 0x1a;
mzling 3:14050370593a 96
mzling 3:14050370593a 97 //Indicates a readonly request
mzling 3:14050370593a 98 static const char READONLY_IND = 0x1f;
mzling 3:14050370593a 99
mzling 2:be605799793f 100 //Error codes
mzling 2:be605799793f 101 static const char START_ERR = 1;
mzling 2:be605799793f 102 static const char END_ERR = 2;
mzling 2:be605799793f 103 static const char PARITY_ERR = 3;
mzling 2:be605799793f 104 static const char CHECKSUM_ERR = 4;
mzling 2:be605799793f 105 static const char VAR_ERR = 5;
mzling 2:be605799793f 106 static const char DATA_ERR = 6;
mzling 2:be605799793f 107 static const char RW_ERR = 7;
mzling 3:14050370593a 108
mzling 3:14050370593a 109 };
mzling 3:14050370593a 110 #endif