![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
201708能代のメインマイコンの保存データ送信用プログラム(データ送信部分を繰り返しタイマー割り込みにした)
Dependencies: MPU6050 MS5607 mbed
Fork of data_sousin by
main.cpp@5:a81dd9b6962a, 2017-08-16 (annotated)
- Committer:
- oichan
- Date:
- Wed Aug 16 11:53:05 2017 +0000
- Revision:
- 5:a81dd9b6962a
- Parent:
- 4:918ea47cc35c
- Child:
- 6:69546ac823b1
fixed a little
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 | 4:918ea47cc35c | 5 | ************************************************************/ |
oichan | 3:660279be8484 | 6 | |
oichan | 5:a81dd9b6962a | 7 | //TODO: 30分以上の動作試験 |
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 | 4:918ea47cc35c | 14 | #define BUFFNUM 100 /*受信側のBUFFNUMと同値*/ |
oichan | 5:a81dd9b6962a | 15 | #define CHARANUM 50 |
oichan | 4:918ea47cc35c | 16 | #define RATE 100.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 | 3:660279be8484 | 23 | Timer t; |
mikawataru | 2:1dbaef45ae46 | 24 | |
oichan | 5:a81dd9b6962a | 25 | float Time[2][BUFFNUM] = {}; |
oichan | 5:a81dd9b6962a | 26 | float Acc[2][BUFFNUM] = {}; |
oichan | 5:a81dd9b6962a | 27 | float Alt[2][BUFFNUM] = {}; |
oichan | 5:a81dd9b6962a | 28 | char Moji[2][BUFFNUM][CHARANUM] = {}; |
oichan | 5:a81dd9b6962a | 29 | bool Row = false; |
oichan | 3:660279be8484 | 30 | int8_t Col = 0; |
oichan | 5:a81dd9b6962a | 31 | int Send_cnt = 0; |
oichan | 5:a81dd9b6962a | 32 | int Moji_cnt = 0; |
mikawataru | 2:1dbaef45ae46 | 33 | |
mikawataru | 2:1dbaef45ae46 | 34 | void _log(); |
mikawataru | 2:1dbaef45ae46 | 35 | |
oichan | 3:660279be8484 | 36 | int main(){ |
oichan | 3:660279be8484 | 37 | t.start(); |
oichan | 3:660279be8484 | 38 | log_timer.attach(_log,1.0/RATE); |
oichan | 4:918ea47cc35c | 39 | while(1){ |
oichan | 4:918ea47cc35c | 40 | if(Moji_cnt==0){ |
oichan | 5:a81dd9b6962a | 41 | sprintf(&Moji[Row][Send_cnt][0],"%f, %f, %f",Time[!Row][Send_cnt],Acc[!Row][Send_cnt],Alt[!Row][Send_cnt]); |
oichan | 4:918ea47cc35c | 42 | } |
oichan | 4:918ea47cc35c | 43 | subCP.putc(Moji[Row][Send_cnt][Moji_cnt]); |
oichan | 4:918ea47cc35c | 44 | Moji_cnt++; |
oichan | 4:918ea47cc35c | 45 | if(Moji_cnt==CHARANUM || Moji[Row][Send_cnt][Moji_cnt]=='\0'){ |
oichan | 4:918ea47cc35c | 46 | Moji_cnt = 0; |
oichan | 4:918ea47cc35c | 47 | subCP.putc('$'); |
oichan | 4:918ea47cc35c | 48 | Send_cnt++; |
oichan | 4:918ea47cc35c | 49 | if(Send_cnt==BUFFNUM){ |
oichan | 4:918ea47cc35c | 50 | Send_cnt = 0; |
oichan | 4:918ea47cc35c | 51 | } |
oichan | 4:918ea47cc35c | 52 | } |
oichan | 4:918ea47cc35c | 53 | } |
mikawataru | 2:1dbaef45ae46 | 54 | } |
mikawataru | 2:1dbaef45ae46 | 55 | |
oichan | 4:918ea47cc35c | 56 | /* データ取得関数 */ |
oichan | 3:660279be8484 | 57 | void _log(){ |
oichan | 5:a81dd9b6962a | 58 | mpu.getAccelero(&Acc[Row][Col]); |
oichan | 5:a81dd9b6962a | 59 | Alt[Row][Col] = ms5607.getAltitude(); |
oichan | 3:660279be8484 | 60 | Time[Row][Col] = t.read(); |
oichan | 5:a81dd9b6962a | 61 | if(Time[Row][Col]>=1800){ |
oichan | 5:a81dd9b6962a | 62 | t.reset(); |
oichan | 5:a81dd9b6962a | 63 | } |
oichan | 3:660279be8484 | 64 | Col++; |
oichan | 3:660279be8484 | 65 | if(Col == BUFFNUM){ |
oichan | 3:660279be8484 | 66 | Col = 0; |
oichan | 3:660279be8484 | 67 | Row = !Row; |
oichan | 3:660279be8484 | 68 | } |
oichan | 3:660279be8484 | 69 | } |
mikawataru | 2:1dbaef45ae46 | 70 |