201708能代のメインマイコンの保存データ送信用プログラム(データ送信部分を繰り返しタイマー割り込みにした)
Dependencies: MPU6050 MS5607 mbed
Fork of data_sousin by
main.cpp@7:33f48fc8fe7b, 2017-08-18 (annotated)
- Committer:
- oichan
- Date:
- Fri Aug 18 15:12:08 2017 +0000
- Revision:
- 7:33f48fc8fe7b
- Parent:
- 6:69546ac823b1
?data_sousin??????????????while????????????????????????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
oichan | 3:660279be8484 | 1 | |
oichan | 5:a81dd9b6962a | 2 | /*********************************************************** |
oichan | 4:918ea47cc35c | 3 | データ取得&送信するプログラム |
oichan | 4:918ea47cc35c | 4 | 各データの終わりの印として'$'を送信 |
oichan | 6:69546ac823b1 | 5 | 送信データが時間順にならないため、検証時は並び替えが必要 |
oichan | 4:918ea47cc35c | 6 | ************************************************************/ |
oichan | 3:660279be8484 | 7 | |
oichan | 5:a81dd9b6962a | 8 | |
mbed_official | 0:bdbd3d6fc5d5 | 9 | #include "mbed.h" |
oichan | 3:660279be8484 | 10 | #include "MPU6050.h" |
oichan | 5:a81dd9b6962a | 11 | #include "MS5607I2C.h" |
mikawataru | 2:1dbaef45ae46 | 12 | |
oichan | 3:660279be8484 | 13 | #define ACC 16384 |
oichan | 6:69546ac823b1 | 14 | #define BUFFNUM 50 /*受信側のBUFFNUMと同値*/ |
oichan | 5:a81dd9b6962a | 15 | #define CHARANUM 50 |
oichan | 6:69546ac823b1 | 16 | #define RATE 50.0 /*RATE[Hz]でデータ取得*/ |
mikawataru | 2:1dbaef45ae46 | 17 | |
oichan | 5:a81dd9b6962a | 18 | |
oichan | 3:660279be8484 | 19 | MPU6050 mpu(p9,p10); |
oichan | 5:a81dd9b6962a | 20 | MS5607I2C ms5607(p9,p10,false); |
oichan | 3:660279be8484 | 21 | Serial subCP(p28, p27); |
oichan | 3:660279be8484 | 22 | Ticker log_timer; |
oichan | 7:33f48fc8fe7b | 23 | Ticker send_timer; |
oichan | 3:660279be8484 | 24 | Timer t; |
mikawataru | 2:1dbaef45ae46 | 25 | |
oichan | 5:a81dd9b6962a | 26 | float Time[2][BUFFNUM] = {}; |
oichan | 5:a81dd9b6962a | 27 | float Acc[2][BUFFNUM] = {}; |
oichan | 5:a81dd9b6962a | 28 | float Alt[2][BUFFNUM] = {}; |
oichan | 5:a81dd9b6962a | 29 | char Moji[2][BUFFNUM][CHARANUM] = {}; |
oichan | 5:a81dd9b6962a | 30 | bool Row = false; |
oichan | 3:660279be8484 | 31 | int8_t Col = 0; |
oichan | 5:a81dd9b6962a | 32 | int Send_cnt = 0; |
oichan | 5:a81dd9b6962a | 33 | int Moji_cnt = 0; |
mikawataru | 2:1dbaef45ae46 | 34 | |
mikawataru | 2:1dbaef45ae46 | 35 | void _log(); |
oichan | 7:33f48fc8fe7b | 36 | void _send(); |
mikawataru | 2:1dbaef45ae46 | 37 | |
oichan | 3:660279be8484 | 38 | int main(){ |
oichan | 3:660279be8484 | 39 | t.start(); |
oichan | 3:660279be8484 | 40 | log_timer.attach(_log,1.0/RATE); |
oichan | 7:33f48fc8fe7b | 41 | send_timer.attach(_send,0.0001); |
oichan | 7:33f48fc8fe7b | 42 | while(1); |
mikawataru | 2:1dbaef45ae46 | 43 | } |
mikawataru | 2:1dbaef45ae46 | 44 | |
oichan | 7:33f48fc8fe7b | 45 | |
oichan | 4:918ea47cc35c | 46 | /* データ取得関数 */ |
oichan | 3:660279be8484 | 47 | void _log(){ |
oichan | 5:a81dd9b6962a | 48 | mpu.getAccelero(&Acc[Row][Col]); |
oichan | 5:a81dd9b6962a | 49 | Alt[Row][Col] = ms5607.getAltitude(); |
oichan | 3:660279be8484 | 50 | Time[Row][Col] = t.read(); |
oichan | 5:a81dd9b6962a | 51 | if(Time[Row][Col]>=1800){ |
oichan | 5:a81dd9b6962a | 52 | t.reset(); |
oichan | 5:a81dd9b6962a | 53 | } |
oichan | 3:660279be8484 | 54 | Col++; |
oichan | 3:660279be8484 | 55 | if(Col == BUFFNUM){ |
oichan | 3:660279be8484 | 56 | Col = 0; |
oichan | 3:660279be8484 | 57 | Row = !Row; |
oichan | 3:660279be8484 | 58 | } |
oichan | 3:660279be8484 | 59 | } |
mikawataru | 2:1dbaef45ae46 | 60 | |
oichan | 7:33f48fc8fe7b | 61 | /* データ送信関数 */ |
oichan | 7:33f48fc8fe7b | 62 | void _send(){ |
oichan | 7:33f48fc8fe7b | 63 | if(Moji_cnt==0){ |
oichan | 7:33f48fc8fe7b | 64 | sprintf(&Moji[Row][Send_cnt][0],"%f, %f, %f",Time[!Row][Send_cnt],Acc[!Row][Send_cnt],Alt[!Row][Send_cnt]); |
oichan | 7:33f48fc8fe7b | 65 | } |
oichan | 7:33f48fc8fe7b | 66 | subCP.putc(Moji[Row][Send_cnt][Moji_cnt]); |
oichan | 7:33f48fc8fe7b | 67 | Moji_cnt++; |
oichan | 7:33f48fc8fe7b | 68 | if(Moji_cnt==CHARANUM || Moji[Row][Send_cnt][Moji_cnt]=='\0'){ |
oichan | 7:33f48fc8fe7b | 69 | Moji_cnt = 0; |
oichan | 7:33f48fc8fe7b | 70 | subCP.putc('$'); |
oichan | 7:33f48fc8fe7b | 71 | Send_cnt++; |
oichan | 7:33f48fc8fe7b | 72 | if(Send_cnt==BUFFNUM){ |
oichan | 7:33f48fc8fe7b | 73 | Send_cnt = 0; |
oichan | 7:33f48fc8fe7b | 74 | } |
oichan | 7:33f48fc8fe7b | 75 | } |
oichan | 7:33f48fc8fe7b | 76 | } |