![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
v1
Dependencies: Nichrome_lib mbed mpu9250_i2c IM920 INA226_lib PQLPS22HB EEPROM_lib GPS_interrupt
Diff: main.cpp
- Revision:
- 2:980edad0eea2
- Parent:
- 1:3151936d9c55
- Child:
- 3:eca103d94b60
--- a/main.cpp Thu Jul 29 18:37:34 2021 +0000 +++ b/main.cpp Fri Jul 30 06:03:31 2021 +0000 @@ -46,6 +46,7 @@ void StopSeparate(); void SetSensor(); void GetData(); +void SendData(); void WriteEEPROM(); void setEEPROMGroup(int group_num); @@ -53,11 +54,12 @@ // 無線のヘッダまとめ // *************************************************** const char HEADER_SETUP = 0x01; -// 0xA1 +// 0xA1, GPS, LPS22HB, MPU9250, MPU9250_MAG, INA226_MAIN, INA226_SEP +// 1 1 1 1 1 1 1 const char HEADER_DATA = 0xA2; -// 0xA2 -// +// 0xA2, nich_status, lat, lon, height, press, temp, altitude, voltage_main, voltage_sep, current_main, current_sep +// 1 1 4 4 4 4 4 4 4 4 4 4 const char HEADER_ECHO = 0xA5; // 0xA5,コマンド @@ -88,9 +90,10 @@ pc.printf("Hello Main!\r\n"); SetSensor(); im920.attach(&uplink, 0xF0); - send_data.attach(&GetData, 1.0); + send_data.attach(&SendData, 1.0); while(1){ + GetData(); } } // *************************************************** @@ -256,30 +259,62 @@ // センサーのデータ取得 // *************************************************** void GetData(){ - if(!header_set){ - im920.header((char)HEADER_DATA); - header_set = true; - } - - pc.printf("********************\r\n\r\n"); //Nichrome if(nich.status){ nich_status = '1'; }else{ nich_status = '0'; } + + //GPS + lat = gps.Latitude(); + lon = gps.Longitude(); + height = gps.Height(); + //pc.printf("%f\t%f\t%f\t\r\n", lat, lon, height); + + //LPS22HB + lps22hb.read_press(&press); + lps22hb.read_temp(&temp); + altitude = (CURRENT_LOCATION_TEMP + 273.15)/0.0065*(1 - powf(press/CURRENT_LOCATION_PRESS, 287 * 0.0065/9.80665)); + //pc.printf("%f\t%f\t%f\r\n",press, temp, altitude); + + //MPU9250 + /* + mpu9250.getAll(imu, mag); + pc.printf("%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\t\r\n",imu[0], imu[1], imu[2], imu[3], imu[4], imu[5], mag[0], mag[1], mag[2]); + */ + + //INA226 + ina226_main.get_Voltage_current(&voltage_main, ¤t_main); + ina226_sep.get_Voltage_current(&voltage_sep, ¤t_sep); + voltage_main /= 1000; + current_main /= 1000; + voltage_sep /= 1000; + current_sep /= 1000; + //pc.printf("MainVol : %.2f, SepVol : %.2f, MainCur : %.2f, SepCur : %.2f\r\n", voltage_main, voltage_sep, current_main, current_sep); + //pc.printf("MainVol : %f, SepVol : %f, MainCur : %f, SepCur : %f\r\n", voltage_main*(1/1000), voltage_sep, current_main, current_sep); +} + +// *************************************************** +// 取得データを地上に送信 +// *************************************************** +void SendData(){ + if(!header_set){ + im920.header((char)HEADER_DATA); + header_set = true; + } + + pc.printf("********************\r\n\r\n"); + + //Nichrome pc.printf("Nichrome_status : %c\r\n",nich_status); im920.write((char)nich_status); im_buf_n ++; //GPS - lat = gps.Latitude(); - lon = gps.Longitude(); - height = gps.Height(); pc.printf("Latitude : %f\r\n",lat); pc.printf("Longitude : %f\r\n",lon); pc.printf("Height : %f\r\n",height); - //pc.printf("%f\t%f\t%f\t\r\n", lat, lon, height); im920.write((float)lat); im_buf_n ++; im920.write((float)lon); @@ -288,13 +323,9 @@ im_buf_n ++; //LPS22HB - lps22hb.read_press(&press); - lps22hb.read_temp(&temp); - altitude = (CURRENT_LOCATION_TEMP + 273.15)/0.0065*(1 - powf(press/CURRENT_LOCATION_PRESS, 287 * 0.0065/9.80665)); pc.printf("Pressure : %f\r\n",press); pc.printf("Temperarure : %f\r\n",temp); pc.printf("Altitude : %f\r\n",altitude); - //pc.printf("%f\t%f\t%f\r\n",press, temp, altitude); im920.write((float)press); im_buf_n ++; im920.write((float)temp); @@ -304,9 +335,6 @@ //MPU9250 /* - mpu9250.getAll(imu, mag); - pc.printf("%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\t\r\n",imu[0], imu[1], imu[2], imu[3], imu[4], imu[5], mag[0], mag[1], mag[2]); - im920.write((float)imu[0]); im_buf_n ++; im920.write((float)imu[1]); @@ -326,19 +354,12 @@ im920.write((float)mag[2]); im_buf_n ++; */ + //INA226 - ina226_main.get_Voltage_current(&voltage_main, ¤t_main); - ina226_sep.get_Voltage_current(&voltage_sep, ¤t_sep); - voltage_main /= 1000; - current_main /= 1000; - voltage_sep /= 1000; - current_sep /= 1000; pc.printf("Vlotage Mian : %.2f\r\n",voltage_main); pc.printf("Current Main : %.2f\r\n",current_main); pc.printf("Voltage Sep : %.2f\r\n",voltage_sep); pc.printf("Current Sep : %.2f\r\n",current_sep); - //pc.printf("MainVol : %.2f, SepVol : %.2f, MainCur : %.2f, SepCur : %.2f\r\n", voltage_main, voltage_sep, current_main, current_sep); - //pc.printf("MainVol : %f, SepVol : %f, MainCur : %f, SepCur : %f\r\n", voltage_main*(1/1000), voltage_sep, current_main, current_sep); im920.write((float)voltage_main); im_buf_n ++; im920.write((float)current_main); @@ -348,12 +369,11 @@ im920.write((float)current_sep); im_buf_n ++; - pc.printf("********************\r\n\r\n"); + pc.printf("********************\r\n\r\n"); - if(header_set){ im920.send(); - pc.printf("Send : %s\r\n", im_buf); + //pc.printf("Send : %s\r\n", im_buf); header_set = false; for(int i = 0; i < im_buf_n; i ++){ im_buf[i] = '\0'; @@ -362,6 +382,7 @@ } } + // *************************************************** // EEPROMにデータを書き込むプログラム // ***************************************************