natsu tsumagari
/
test_cadenceClass
回転数計のクラスです。
Diff: Cadence.h
- Revision:
- 4:2def7f5f7fed
- Parent:
- 2:b492f029a2f4
- Child:
- 5:871c2d6c1129
--- a/Cadence.h Wed Nov 23 13:59:26 2016 +0000 +++ b/Cadence.h Fri Jan 27 14:10:44 2017 +0000 @@ -2,61 +2,54 @@ #define CADENCE_H #include "mbed.h" +#include "BufferedSoftSerial.h" #include <string> -class Cadence : public Serial{ + +class Cadence : public /*BufferedSoft*/RawSerial{ private: - static const int DATAS_NUM = 75; - + static const int DATAS_NUM = 69 + 4 + 1; //経過時間の文字数は最大4 +//;1816; 00 00000 0;168 ;001; 10133 e9;34 00;00 0e;00 00;10 70;06 89;G; -005; -009; -006; //2+4+67+2(\r\n) +// -- -- ---- protected: public: - string strC,strV; + char strC[4],strV[4]; char data[DATAS_NUM]; string strData; int data_count, data_num; - double cadence, cadenceV; - Cadence(PinName tx, PinName rx, const char* name = NULL) : Serial(tx, rx, NULL){ + double cadence, voltage, safeflag; + int cadence_i, voltage_i; + Cadence(PinName tx, PinName rx, const char* name = NULL) : /*BufferedSoft*/RawSerial(tx, rx, NULL){ for(int i=0;i<DATAS_NUM;i++) data[i]= NULL; - data_num=0; data_count=0; baud(115200); cadence=0; - cadenceV=0; + voltage=0; + strC[0] = '0'; + strV[0] = '0'; } void readData(){ //Ticker で定期的に呼び出して値を更新 + if(readable()){ data_count = 0; - data_num = 0; - cadence = 0; do{ - if(readable()) { + if(readable()){ data[data_count] = getc(); - data_count++; + if(data[data_count] != '\n') data_count++; } - }while(data[data_count-1] != '\n'); - - strData = data; - if(strData.length() > DATAS_NUM-4 ){ - switch (strData.length()){ - case DATAS_NUM-3 : - strData.erase(0,2); - break; - case DATAS_NUM-2 : - strData.erase(0,3); - break; - case DATAS_NUM-1 : - strData.erase(0,4); - break; - case DATAS_NUM : - strData.erase(0,5); + }while( data[data_count-1] != '\r' && data_count < DATAS_NUM ); + if( data_count > 71 ) { + for(int i = 0; i<4; i++){ + strC[i] = data[data_count - 6 + i]; // 7 = 5 + 1 + pc.putc(strC[i]); + strV[i] = data[data_count - 43 + i]; // 44 = 42 + 1 } - strV = strData.substr(26,4); - strC = strData.substr(64,4); - sscanf(strV.c_str(),"%lf",&cadenceV); - sscanf(strC.c_str(),"%lf",&cadence); - //cadence /= 6.0; -// cadenceV *= 0.001; + sscanf(strC,"%4d",&cadence); + sscanf(strV,"%4d",&voltage); +// cadence /= 6.0; +// voltage /= 1000.0; } + } } }; #endif \ No newline at end of file