![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
v1
Dependencies: Nichrome_lib mbed mpu9250_i2c IM920 INA226_lib PQLPS22HB EEPROM_lib GPS_interrupt
main.cpp@2:980edad0eea2, 2021-07-30 (annotated)
- Committer:
- imadaemi
- Date:
- Fri Jul 30 06:03:31 2021 +0000
- Revision:
- 2:980edad0eea2
- Parent:
- 1:3151936d9c55
- Child:
- 3:eca103d94b60
v3; add void SendData()
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
imadaemi | 0:4e38f8b1c183 | 1 | #include "mbed.h" |
imadaemi | 0:4e38f8b1c183 | 2 | #include "IM920.h" |
imadaemi | 0:4e38f8b1c183 | 3 | #include "GPS_interrupt.h" |
imadaemi | 0:4e38f8b1c183 | 4 | #include "PQLPS22HB.h" |
imadaemi | 0:4e38f8b1c183 | 5 | #include "mpu9250_i2c.h" |
imadaemi | 0:4e38f8b1c183 | 6 | #include "INA226.h" |
imadaemi | 0:4e38f8b1c183 | 7 | #include "Nichrome_lib.h" |
imadaemi | 0:4e38f8b1c183 | 8 | #include "EEPROM_lib.h" |
imadaemi | 0:4e38f8b1c183 | 9 | |
imadaemi | 1:3151936d9c55 | 10 | #define FIRE_TIME 3.0 |
imadaemi | 0:4e38f8b1c183 | 11 | #define CURRENT_LOCATION_PRESS 1022.624268//投下前に設定 |
imadaemi | 0:4e38f8b1c183 | 12 | #define CURRENT_LOCATION_TEMP 10.650000//投下前に設定 |
imadaemi | 0:4e38f8b1c183 | 13 | #define ACC_RANGE _16G |
imadaemi | 0:4e38f8b1c183 | 14 | #define GYRO_RANGE _2000DPS |
imadaemi | 0:4e38f8b1c183 | 15 | |
imadaemi | 0:4e38f8b1c183 | 16 | // *************************************************** |
imadaemi | 0:4e38f8b1c183 | 17 | // コンストラクタ |
imadaemi | 0:4e38f8b1c183 | 18 | // *************************************************** |
imadaemi | 0:4e38f8b1c183 | 19 | Serial pc(USBTX, USBRX, 115200); |
imadaemi | 0:4e38f8b1c183 | 20 | Serial gps_serial(p9, p10, 115200); |
imadaemi | 0:4e38f8b1c183 | 21 | Serial im920_serial(p13, p14, 115200); |
imadaemi | 0:4e38f8b1c183 | 22 | |
imadaemi | 0:4e38f8b1c183 | 23 | I2C i2c(p28, p27); |
imadaemi | 0:4e38f8b1c183 | 24 | |
imadaemi | 0:4e38f8b1c183 | 25 | IM920 im920(im920_serial, pc, 115200); |
imadaemi | 0:4e38f8b1c183 | 26 | GPS_interrupt gps(&gps_serial); |
imadaemi | 0:4e38f8b1c183 | 27 | LPS22HB lps22hb(i2c, LPS22HB::SA0_LOW); |
imadaemi | 0:4e38f8b1c183 | 28 | mpu9250 mpu9250(i2c,AD0_HIGH); |
imadaemi | 0:4e38f8b1c183 | 29 | myINA226 ina226_main(i2c, myINA226::A1_GND, myINA226::A0_GND); |
imadaemi | 0:4e38f8b1c183 | 30 | myINA226 ina226_sep(i2c, myINA226::A1_VDD, myINA226::A0_VDD); |
imadaemi | 0:4e38f8b1c183 | 31 | Nichrome_lib nich(p20); |
imadaemi | 0:4e38f8b1c183 | 32 | EEPROM_lib EEPROM(i2c, 1); |
imadaemi | 0:4e38f8b1c183 | 33 | |
imadaemi | 0:4e38f8b1c183 | 34 | DigitalOut pinA(p21); |
imadaemi | 0:4e38f8b1c183 | 35 | DigitalOut pinB(p22); |
imadaemi | 0:4e38f8b1c183 | 36 | DigitalOut pinC(p23); |
imadaemi | 0:4e38f8b1c183 | 37 | |
imadaemi | 1:3151936d9c55 | 38 | Ticker send_data; |
imadaemi | 1:3151936d9c55 | 39 | Timeout fire_time; |
imadaemi | 0:4e38f8b1c183 | 40 | // *************************************************** |
imadaemi | 0:4e38f8b1c183 | 41 | // 関数の宣言 |
imadaemi | 0:4e38f8b1c183 | 42 | // *************************************************** |
imadaemi | 0:4e38f8b1c183 | 43 | void uplink(); |
imadaemi | 0:4e38f8b1c183 | 44 | void echoIM(); |
imadaemi | 0:4e38f8b1c183 | 45 | void Separate(); |
imadaemi | 0:4e38f8b1c183 | 46 | void StopSeparate(); |
imadaemi | 0:4e38f8b1c183 | 47 | void SetSensor(); |
imadaemi | 0:4e38f8b1c183 | 48 | void GetData(); |
imadaemi | 2:980edad0eea2 | 49 | void SendData(); |
imadaemi | 0:4e38f8b1c183 | 50 | void WriteEEPROM(); |
imadaemi | 0:4e38f8b1c183 | 51 | void setEEPROMGroup(int group_num); |
imadaemi | 0:4e38f8b1c183 | 52 | |
imadaemi | 0:4e38f8b1c183 | 53 | // *************************************************** |
imadaemi | 0:4e38f8b1c183 | 54 | // 無線のヘッダまとめ |
imadaemi | 0:4e38f8b1c183 | 55 | // *************************************************** |
imadaemi | 0:4e38f8b1c183 | 56 | const char HEADER_SETUP = 0x01; |
imadaemi | 2:980edad0eea2 | 57 | // 0xA1, GPS, LPS22HB, MPU9250, MPU9250_MAG, INA226_MAIN, INA226_SEP |
imadaemi | 2:980edad0eea2 | 58 | // 1 1 1 1 1 1 1 |
imadaemi | 0:4e38f8b1c183 | 59 | |
imadaemi | 0:4e38f8b1c183 | 60 | const char HEADER_DATA = 0xA2; |
imadaemi | 2:980edad0eea2 | 61 | // 0xA2, nich_status, lat, lon, height, press, temp, altitude, voltage_main, voltage_sep, current_main, current_sep |
imadaemi | 2:980edad0eea2 | 62 | // 1 1 4 4 4 4 4 4 4 4 4 4 |
imadaemi | 0:4e38f8b1c183 | 63 | |
imadaemi | 0:4e38f8b1c183 | 64 | const char HEADER_ECHO = 0xA5; |
imadaemi | 0:4e38f8b1c183 | 65 | // 0xA5,コマンド |
imadaemi | 0:4e38f8b1c183 | 66 | // 1 1 |
imadaemi | 0:4e38f8b1c183 | 67 | |
imadaemi | 0:4e38f8b1c183 | 68 | // *************************************************** |
imadaemi | 0:4e38f8b1c183 | 69 | // 変数の宣言 |
imadaemi | 0:4e38f8b1c183 | 70 | // *************************************************** |
imadaemi | 1:3151936d9c55 | 71 | char nich_status; |
imadaemi | 1:3151936d9c55 | 72 | |
imadaemi | 0:4e38f8b1c183 | 73 | bool header_set = false; |
imadaemi | 0:4e38f8b1c183 | 74 | char im_buf[55];//16なのって意味ある? |
imadaemi | 0:4e38f8b1c183 | 75 | int im_buf_n = 0; |
imadaemi | 0:4e38f8b1c183 | 76 | |
imadaemi | 0:4e38f8b1c183 | 77 | float lat, lon, height; |
imadaemi | 0:4e38f8b1c183 | 78 | float press, temp, altitude; |
imadaemi | 0:4e38f8b1c183 | 79 | |
imadaemi | 0:4e38f8b1c183 | 80 | float imu[6], mag[3]; |
imadaemi | 0:4e38f8b1c183 | 81 | float mag_geo[3]; |
imadaemi | 0:4e38f8b1c183 | 82 | |
imadaemi | 0:4e38f8b1c183 | 83 | float voltage_main, voltage_sep; |
imadaemi | 0:4e38f8b1c183 | 84 | float current_main, current_sep; |
imadaemi | 0:4e38f8b1c183 | 85 | |
imadaemi | 0:4e38f8b1c183 | 86 | // *************************************************** |
imadaemi | 0:4e38f8b1c183 | 87 | // メイン関数 |
imadaemi | 0:4e38f8b1c183 | 88 | // *************************************************** |
imadaemi | 0:4e38f8b1c183 | 89 | int main() { |
imadaemi | 0:4e38f8b1c183 | 90 | pc.printf("Hello Main!\r\n"); |
imadaemi | 0:4e38f8b1c183 | 91 | SetSensor(); |
imadaemi | 0:4e38f8b1c183 | 92 | im920.attach(&uplink, 0xF0); |
imadaemi | 2:980edad0eea2 | 93 | send_data.attach(&SendData, 1.0); |
imadaemi | 0:4e38f8b1c183 | 94 | |
imadaemi | 0:4e38f8b1c183 | 95 | while(1){ |
imadaemi | 2:980edad0eea2 | 96 | GetData(); |
imadaemi | 0:4e38f8b1c183 | 97 | } |
imadaemi | 0:4e38f8b1c183 | 98 | } |
imadaemi | 0:4e38f8b1c183 | 99 | // *************************************************** |
imadaemi | 0:4e38f8b1c183 | 100 | // アップリンク(地上局から) |
imadaemi | 0:4e38f8b1c183 | 101 | // *************************************************** |
imadaemi | 0:4e38f8b1c183 | 102 | void uplink(){ |
imadaemi | 0:4e38f8b1c183 | 103 | echoIM(); |
imadaemi | 0:4e38f8b1c183 | 104 | switch(im920.data[1]){ |
imadaemi | 0:4e38f8b1c183 | 105 | case 0x01: |
imadaemi | 0:4e38f8b1c183 | 106 | pc.printf("********************\r\n"); |
imadaemi | 0:4e38f8b1c183 | 107 | pc.printf("SEPARATE\r\n"); |
imadaemi | 0:4e38f8b1c183 | 108 | pc.printf("********************\r\n\r\n"); |
imadaemi | 0:4e38f8b1c183 | 109 | Separate(); |
imadaemi | 0:4e38f8b1c183 | 110 | break; |
imadaemi | 0:4e38f8b1c183 | 111 | |
imadaemi | 0:4e38f8b1c183 | 112 | case 0x00: |
imadaemi | 0:4e38f8b1c183 | 113 | pc.printf("********************\r\n"); |
imadaemi | 0:4e38f8b1c183 | 114 | pc.printf("STOP SEPARATE\r\n"); |
imadaemi | 0:4e38f8b1c183 | 115 | pc.printf("********************\r\n\r\n"); |
imadaemi | 0:4e38f8b1c183 | 116 | StopSeparate(); |
imadaemi | 0:4e38f8b1c183 | 117 | break; |
imadaemi | 0:4e38f8b1c183 | 118 | } |
imadaemi | 0:4e38f8b1c183 | 119 | } |
imadaemi | 0:4e38f8b1c183 | 120 | |
imadaemi | 0:4e38f8b1c183 | 121 | // *************************************************** |
imadaemi | 0:4e38f8b1c183 | 122 | // 無線信号の送り返し |
imadaemi | 0:4e38f8b1c183 | 123 | // *************************************************** |
imadaemi | 0:4e38f8b1c183 | 124 | void echoIM(){ |
imadaemi | 0:4e38f8b1c183 | 125 | im920.header(HEADER_ECHO); |
imadaemi | 0:4e38f8b1c183 | 126 | im920.write(im920.data[1]); |
imadaemi | 0:4e38f8b1c183 | 127 | im920.send(); |
imadaemi | 0:4e38f8b1c183 | 128 | } |
imadaemi | 0:4e38f8b1c183 | 129 | |
imadaemi | 0:4e38f8b1c183 | 130 | // *************************************************** |
imadaemi | 0:4e38f8b1c183 | 131 | // 分離実行 |
imadaemi | 0:4e38f8b1c183 | 132 | // *************************************************** |
imadaemi | 0:4e38f8b1c183 | 133 | void Separate(){ |
imadaemi | 1:3151936d9c55 | 134 | nich.fire_on(); |
imadaemi | 1:3151936d9c55 | 135 | fire_time.attach(&StopSeparate,FIRE_TIME); |
imadaemi | 0:4e38f8b1c183 | 136 | } |
imadaemi | 0:4e38f8b1c183 | 137 | |
imadaemi | 0:4e38f8b1c183 | 138 | void StopSeparate(){ |
imadaemi | 0:4e38f8b1c183 | 139 | nich.fire_off(); |
imadaemi | 0:4e38f8b1c183 | 140 | } |
imadaemi | 0:4e38f8b1c183 | 141 | |
imadaemi | 0:4e38f8b1c183 | 142 | // *************************************************** |
imadaemi | 0:4e38f8b1c183 | 143 | // センサーのセットアップ |
imadaemi | 0:4e38f8b1c183 | 144 | // *************************************************** |
imadaemi | 0:4e38f8b1c183 | 145 | void SetSensor(){ |
imadaemi | 0:4e38f8b1c183 | 146 | pc.printf("\r\n"); |
imadaemi | 0:4e38f8b1c183 | 147 | for(int i = 0; i < 20; i++){ |
imadaemi | 0:4e38f8b1c183 | 148 | pc.printf("*"); |
imadaemi | 0:4e38f8b1c183 | 149 | } |
imadaemi | 0:4e38f8b1c183 | 150 | pc.printf("\r\n"); |
imadaemi | 0:4e38f8b1c183 | 151 | pc.printf("Start Setting\r\n"); |
imadaemi | 0:4e38f8b1c183 | 152 | |
imadaemi | 0:4e38f8b1c183 | 153 | if(!header_set){ |
imadaemi | 0:4e38f8b1c183 | 154 | im920.header((char)HEADER_SETUP); |
imadaemi | 0:4e38f8b1c183 | 155 | header_set = true; |
imadaemi | 0:4e38f8b1c183 | 156 | } |
imadaemi | 0:4e38f8b1c183 | 157 | |
imadaemi | 0:4e38f8b1c183 | 158 | //GPS |
imadaemi | 0:4e38f8b1c183 | 159 | if(gps.gps_readable == true){ |
imadaemi | 0:4e38f8b1c183 | 160 | pc.printf("GPS : OK!\r\n"); |
imadaemi | 0:4e38f8b1c183 | 161 | im920.write((char)0x01); |
imadaemi | 0:4e38f8b1c183 | 162 | im_buf[im_buf_n] = '1'; |
imadaemi | 0:4e38f8b1c183 | 163 | im_buf_n ++; |
imadaemi | 0:4e38f8b1c183 | 164 | }else{ |
imadaemi | 0:4e38f8b1c183 | 165 | pc.printf("GPS : NG...\r\n"); |
imadaemi | 0:4e38f8b1c183 | 166 | im920.write((char)0x00); |
imadaemi | 0:4e38f8b1c183 | 167 | im_buf[im_buf_n] = '0'; |
imadaemi | 0:4e38f8b1c183 | 168 | im_buf_n ++; |
imadaemi | 0:4e38f8b1c183 | 169 | } |
imadaemi | 0:4e38f8b1c183 | 170 | |
imadaemi | 0:4e38f8b1c183 | 171 | //LPS22HB |
imadaemi | 0:4e38f8b1c183 | 172 | lps22hb.begin(); |
imadaemi | 0:4e38f8b1c183 | 173 | if(lps22hb.test() == true){ |
imadaemi | 0:4e38f8b1c183 | 174 | pc.printf("LPS22HB : OK!\r\n"); |
imadaemi | 0:4e38f8b1c183 | 175 | im920.write((char)0x01); |
imadaemi | 0:4e38f8b1c183 | 176 | im_buf[im_buf_n] = '1'; |
imadaemi | 0:4e38f8b1c183 | 177 | im_buf_n ++; |
imadaemi | 0:4e38f8b1c183 | 178 | }else{ |
imadaemi | 0:4e38f8b1c183 | 179 | pc.printf("LPS22HB : NG...\r\n"); |
imadaemi | 0:4e38f8b1c183 | 180 | im920.write((char)0x00); |
imadaemi | 0:4e38f8b1c183 | 181 | im_buf[im_buf_n] = '0'; |
imadaemi | 0:4e38f8b1c183 | 182 | im_buf_n ++; |
imadaemi | 0:4e38f8b1c183 | 183 | } |
imadaemi | 0:4e38f8b1c183 | 184 | |
imadaemi | 0:4e38f8b1c183 | 185 | //MPU9250 |
imadaemi | 0:4e38f8b1c183 | 186 | if(mpu9250.sensorTest() == true){ |
imadaemi | 0:4e38f8b1c183 | 187 | pc.printf("MPU9250 : OK!\r\n"); |
imadaemi | 0:4e38f8b1c183 | 188 | im920.write((char)0x01); |
imadaemi | 0:4e38f8b1c183 | 189 | im_buf[im_buf_n] = '1'; |
imadaemi | 0:4e38f8b1c183 | 190 | im_buf_n ++; |
imadaemi | 0:4e38f8b1c183 | 191 | }else{ |
imadaemi | 0:4e38f8b1c183 | 192 | pc.printf("MPU9250 : NG...\r\n"); |
imadaemi | 0:4e38f8b1c183 | 193 | im920.write((char)0x00); |
imadaemi | 0:4e38f8b1c183 | 194 | im_buf[im_buf_n] = '0'; |
imadaemi | 0:4e38f8b1c183 | 195 | im_buf_n ++; |
imadaemi | 0:4e38f8b1c183 | 196 | } |
imadaemi | 0:4e38f8b1c183 | 197 | if(mpu9250.mag_sensorTest() == true){ |
imadaemi | 0:4e38f8b1c183 | 198 | pc.printf("MPU9250 MAG : OK!\r\n"); |
imadaemi | 0:4e38f8b1c183 | 199 | im920.write((char)0x01); |
imadaemi | 0:4e38f8b1c183 | 200 | im_buf[im_buf_n] = '1'; |
imadaemi | 0:4e38f8b1c183 | 201 | im_buf_n ++; |
imadaemi | 0:4e38f8b1c183 | 202 | }else{ |
imadaemi | 0:4e38f8b1c183 | 203 | pc.printf("MPU9250 MAG : NG...\r\n"); |
imadaemi | 0:4e38f8b1c183 | 204 | im920.write((char)0x00); |
imadaemi | 0:4e38f8b1c183 | 205 | im_buf[im_buf_n] = '0'; |
imadaemi | 0:4e38f8b1c183 | 206 | im_buf_n ++; |
imadaemi | 0:4e38f8b1c183 | 207 | } |
imadaemi | 0:4e38f8b1c183 | 208 | mpu9250.setAcc(ACC_RANGE); |
imadaemi | 0:4e38f8b1c183 | 209 | mpu9250.setGyro(GYRO_RANGE); |
imadaemi | 0:4e38f8b1c183 | 210 | mpu9250.setOffset(0.528892327, -0.660206211, 0.757105891, -0.011691362, 0.025688783, 1.087885322, -159.750004, 121.425005, -392.700012); |
imadaemi | 0:4e38f8b1c183 | 211 | |
imadaemi | 0:4e38f8b1c183 | 212 | //INA226 |
imadaemi | 0:4e38f8b1c183 | 213 | ina226_main.set_callibretion(); |
imadaemi | 0:4e38f8b1c183 | 214 | ina226_sep.set_callibretion(); |
imadaemi | 1:3151936d9c55 | 215 | //ina226_main.setup(1); |
imadaemi | 1:3151936d9c55 | 216 | //ina226_sep.setup(1); |
imadaemi | 0:4e38f8b1c183 | 217 | |
imadaemi | 0:4e38f8b1c183 | 218 | if(ina226_main.Connection_check()==0){ |
imadaemi | 0:4e38f8b1c183 | 219 | pc.printf("INA226 Main : OK!\r\n"); |
imadaemi | 0:4e38f8b1c183 | 220 | im920.write((char)0x01); |
imadaemi | 0:4e38f8b1c183 | 221 | im_buf[im_buf_n] = '1'; |
imadaemi | 0:4e38f8b1c183 | 222 | im_buf_n ++; |
imadaemi | 0:4e38f8b1c183 | 223 | }else{ |
imadaemi | 0:4e38f8b1c183 | 224 | pc.printf("INA226 Main : NG...\r\n"); |
imadaemi | 0:4e38f8b1c183 | 225 | im920.write((char)0x00); |
imadaemi | 0:4e38f8b1c183 | 226 | im_buf[im_buf_n] = '0'; |
imadaemi | 0:4e38f8b1c183 | 227 | im_buf_n ++; |
imadaemi | 0:4e38f8b1c183 | 228 | } |
imadaemi | 0:4e38f8b1c183 | 229 | if(ina226_sep.Connection_check()==0){ |
imadaemi | 0:4e38f8b1c183 | 230 | pc.printf("INA226 Sep : OK!\r\n"); |
imadaemi | 0:4e38f8b1c183 | 231 | im920.write((char)0x01); |
imadaemi | 0:4e38f8b1c183 | 232 | im_buf[im_buf_n] = '1'; |
imadaemi | 0:4e38f8b1c183 | 233 | im_buf_n ++; |
imadaemi | 0:4e38f8b1c183 | 234 | }else{ |
imadaemi | 0:4e38f8b1c183 | 235 | pc.printf("INA226 Sep : NG...\r\n"); |
imadaemi | 0:4e38f8b1c183 | 236 | im920.write((char)0x00); |
imadaemi | 0:4e38f8b1c183 | 237 | im_buf[im_buf_n] = '0'; |
imadaemi | 0:4e38f8b1c183 | 238 | im_buf_n ++; |
imadaemi | 0:4e38f8b1c183 | 239 | } |
imadaemi | 0:4e38f8b1c183 | 240 | |
imadaemi | 0:4e38f8b1c183 | 241 | if(header_set){ |
imadaemi | 0:4e38f8b1c183 | 242 | im920.send(); |
imadaemi | 0:4e38f8b1c183 | 243 | pc.printf("Send : %s\r\n", im_buf); |
imadaemi | 0:4e38f8b1c183 | 244 | header_set = false; |
imadaemi | 0:4e38f8b1c183 | 245 | for(int i = 0; i < im_buf_n; i ++){ |
imadaemi | 0:4e38f8b1c183 | 246 | im_buf[i] = '\0'; |
imadaemi | 0:4e38f8b1c183 | 247 | } |
imadaemi | 0:4e38f8b1c183 | 248 | im_buf_n = 0; |
imadaemi | 0:4e38f8b1c183 | 249 | } |
imadaemi | 0:4e38f8b1c183 | 250 | |
imadaemi | 0:4e38f8b1c183 | 251 | pc.printf("\r\n"); |
imadaemi | 0:4e38f8b1c183 | 252 | for(int i = 0; i < 20; i++){ |
imadaemi | 0:4e38f8b1c183 | 253 | pc.printf("*"); |
imadaemi | 0:4e38f8b1c183 | 254 | } |
imadaemi | 0:4e38f8b1c183 | 255 | pc.printf("\r\n"); |
imadaemi | 0:4e38f8b1c183 | 256 | } |
imadaemi | 0:4e38f8b1c183 | 257 | |
imadaemi | 0:4e38f8b1c183 | 258 | // *************************************************** |
imadaemi | 0:4e38f8b1c183 | 259 | // センサーのデータ取得 |
imadaemi | 0:4e38f8b1c183 | 260 | // *************************************************** |
imadaemi | 0:4e38f8b1c183 | 261 | void GetData(){ |
imadaemi | 1:3151936d9c55 | 262 | //Nichrome |
imadaemi | 1:3151936d9c55 | 263 | if(nich.status){ |
imadaemi | 1:3151936d9c55 | 264 | nich_status = '1'; |
imadaemi | 1:3151936d9c55 | 265 | }else{ |
imadaemi | 1:3151936d9c55 | 266 | nich_status = '0'; |
imadaemi | 1:3151936d9c55 | 267 | } |
imadaemi | 2:980edad0eea2 | 268 | |
imadaemi | 2:980edad0eea2 | 269 | //GPS |
imadaemi | 2:980edad0eea2 | 270 | lat = gps.Latitude(); |
imadaemi | 2:980edad0eea2 | 271 | lon = gps.Longitude(); |
imadaemi | 2:980edad0eea2 | 272 | height = gps.Height(); |
imadaemi | 2:980edad0eea2 | 273 | //pc.printf("%f\t%f\t%f\t\r\n", lat, lon, height); |
imadaemi | 2:980edad0eea2 | 274 | |
imadaemi | 2:980edad0eea2 | 275 | //LPS22HB |
imadaemi | 2:980edad0eea2 | 276 | lps22hb.read_press(&press); |
imadaemi | 2:980edad0eea2 | 277 | lps22hb.read_temp(&temp); |
imadaemi | 2:980edad0eea2 | 278 | altitude = (CURRENT_LOCATION_TEMP + 273.15)/0.0065*(1 - powf(press/CURRENT_LOCATION_PRESS, 287 * 0.0065/9.80665)); |
imadaemi | 2:980edad0eea2 | 279 | //pc.printf("%f\t%f\t%f\r\n",press, temp, altitude); |
imadaemi | 2:980edad0eea2 | 280 | |
imadaemi | 2:980edad0eea2 | 281 | //MPU9250 |
imadaemi | 2:980edad0eea2 | 282 | /* |
imadaemi | 2:980edad0eea2 | 283 | mpu9250.getAll(imu, mag); |
imadaemi | 2:980edad0eea2 | 284 | 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]); |
imadaemi | 2:980edad0eea2 | 285 | */ |
imadaemi | 2:980edad0eea2 | 286 | |
imadaemi | 2:980edad0eea2 | 287 | //INA226 |
imadaemi | 2:980edad0eea2 | 288 | ina226_main.get_Voltage_current(&voltage_main, ¤t_main); |
imadaemi | 2:980edad0eea2 | 289 | ina226_sep.get_Voltage_current(&voltage_sep, ¤t_sep); |
imadaemi | 2:980edad0eea2 | 290 | voltage_main /= 1000; |
imadaemi | 2:980edad0eea2 | 291 | current_main /= 1000; |
imadaemi | 2:980edad0eea2 | 292 | voltage_sep /= 1000; |
imadaemi | 2:980edad0eea2 | 293 | current_sep /= 1000; |
imadaemi | 2:980edad0eea2 | 294 | //pc.printf("MainVol : %.2f, SepVol : %.2f, MainCur : %.2f, SepCur : %.2f\r\n", voltage_main, voltage_sep, current_main, current_sep); |
imadaemi | 2:980edad0eea2 | 295 | //pc.printf("MainVol : %f, SepVol : %f, MainCur : %f, SepCur : %f\r\n", voltage_main*(1/1000), voltage_sep, current_main, current_sep); |
imadaemi | 2:980edad0eea2 | 296 | } |
imadaemi | 2:980edad0eea2 | 297 | |
imadaemi | 2:980edad0eea2 | 298 | // *************************************************** |
imadaemi | 2:980edad0eea2 | 299 | // 取得データを地上に送信 |
imadaemi | 2:980edad0eea2 | 300 | // *************************************************** |
imadaemi | 2:980edad0eea2 | 301 | void SendData(){ |
imadaemi | 2:980edad0eea2 | 302 | if(!header_set){ |
imadaemi | 2:980edad0eea2 | 303 | im920.header((char)HEADER_DATA); |
imadaemi | 2:980edad0eea2 | 304 | header_set = true; |
imadaemi | 2:980edad0eea2 | 305 | } |
imadaemi | 2:980edad0eea2 | 306 | |
imadaemi | 2:980edad0eea2 | 307 | pc.printf("********************\r\n\r\n"); |
imadaemi | 2:980edad0eea2 | 308 | |
imadaemi | 2:980edad0eea2 | 309 | //Nichrome |
imadaemi | 1:3151936d9c55 | 310 | pc.printf("Nichrome_status : %c\r\n",nich_status); |
imadaemi | 1:3151936d9c55 | 311 | im920.write((char)nich_status); |
imadaemi | 1:3151936d9c55 | 312 | im_buf_n ++; |
imadaemi | 1:3151936d9c55 | 313 | |
imadaemi | 0:4e38f8b1c183 | 314 | //GPS |
imadaemi | 1:3151936d9c55 | 315 | pc.printf("Latitude : %f\r\n",lat); |
imadaemi | 1:3151936d9c55 | 316 | pc.printf("Longitude : %f\r\n",lon); |
imadaemi | 1:3151936d9c55 | 317 | pc.printf("Height : %f\r\n",height); |
imadaemi | 0:4e38f8b1c183 | 318 | im920.write((float)lat); |
imadaemi | 0:4e38f8b1c183 | 319 | im_buf_n ++; |
imadaemi | 0:4e38f8b1c183 | 320 | im920.write((float)lon); |
imadaemi | 0:4e38f8b1c183 | 321 | im_buf_n ++; |
imadaemi | 0:4e38f8b1c183 | 322 | im920.write((float)height); |
imadaemi | 0:4e38f8b1c183 | 323 | im_buf_n ++; |
imadaemi | 0:4e38f8b1c183 | 324 | |
imadaemi | 0:4e38f8b1c183 | 325 | //LPS22HB |
imadaemi | 1:3151936d9c55 | 326 | pc.printf("Pressure : %f\r\n",press); |
imadaemi | 1:3151936d9c55 | 327 | pc.printf("Temperarure : %f\r\n",temp); |
imadaemi | 1:3151936d9c55 | 328 | pc.printf("Altitude : %f\r\n",altitude); |
imadaemi | 0:4e38f8b1c183 | 329 | im920.write((float)press); |
imadaemi | 0:4e38f8b1c183 | 330 | im_buf_n ++; |
imadaemi | 0:4e38f8b1c183 | 331 | im920.write((float)temp); |
imadaemi | 0:4e38f8b1c183 | 332 | im_buf_n ++; |
imadaemi | 0:4e38f8b1c183 | 333 | im920.write((float)altitude); |
imadaemi | 0:4e38f8b1c183 | 334 | im_buf_n ++; |
imadaemi | 0:4e38f8b1c183 | 335 | |
imadaemi | 0:4e38f8b1c183 | 336 | //MPU9250 |
imadaemi | 0:4e38f8b1c183 | 337 | /* |
imadaemi | 0:4e38f8b1c183 | 338 | im920.write((float)imu[0]); |
imadaemi | 0:4e38f8b1c183 | 339 | im_buf_n ++; |
imadaemi | 0:4e38f8b1c183 | 340 | im920.write((float)imu[1]); |
imadaemi | 0:4e38f8b1c183 | 341 | im_buf_n ++; |
imadaemi | 0:4e38f8b1c183 | 342 | im920.write((float)imu[2]); |
imadaemi | 0:4e38f8b1c183 | 343 | im_buf_n ++; |
imadaemi | 0:4e38f8b1c183 | 344 | im920.write((float)imu[3]); |
imadaemi | 0:4e38f8b1c183 | 345 | im_buf_n ++; |
imadaemi | 0:4e38f8b1c183 | 346 | im920.write((float)imu[4]); |
imadaemi | 0:4e38f8b1c183 | 347 | im_buf_n ++; |
imadaemi | 0:4e38f8b1c183 | 348 | im920.write((float)imu[5]); |
imadaemi | 0:4e38f8b1c183 | 349 | im_buf_n ++; |
imadaemi | 0:4e38f8b1c183 | 350 | im920.write((float)mag[0]); |
imadaemi | 0:4e38f8b1c183 | 351 | im_buf_n ++; |
imadaemi | 0:4e38f8b1c183 | 352 | im920.write((float)mag[1]); |
imadaemi | 0:4e38f8b1c183 | 353 | im_buf_n ++; |
imadaemi | 0:4e38f8b1c183 | 354 | im920.write((float)mag[2]); |
imadaemi | 0:4e38f8b1c183 | 355 | im_buf_n ++; |
imadaemi | 0:4e38f8b1c183 | 356 | */ |
imadaemi | 2:980edad0eea2 | 357 | |
imadaemi | 0:4e38f8b1c183 | 358 | //INA226 |
imadaemi | 1:3151936d9c55 | 359 | pc.printf("Vlotage Mian : %.2f\r\n",voltage_main); |
imadaemi | 1:3151936d9c55 | 360 | pc.printf("Current Main : %.2f\r\n",current_main); |
imadaemi | 1:3151936d9c55 | 361 | pc.printf("Voltage Sep : %.2f\r\n",voltage_sep); |
imadaemi | 1:3151936d9c55 | 362 | pc.printf("Current Sep : %.2f\r\n",current_sep); |
imadaemi | 0:4e38f8b1c183 | 363 | im920.write((float)voltage_main); |
imadaemi | 0:4e38f8b1c183 | 364 | im_buf_n ++; |
imadaemi | 0:4e38f8b1c183 | 365 | im920.write((float)current_main); |
imadaemi | 0:4e38f8b1c183 | 366 | im_buf_n ++; |
imadaemi | 0:4e38f8b1c183 | 367 | im920.write((float)voltage_sep); |
imadaemi | 0:4e38f8b1c183 | 368 | im_buf_n ++; |
imadaemi | 0:4e38f8b1c183 | 369 | im920.write((float)current_sep); |
imadaemi | 0:4e38f8b1c183 | 370 | im_buf_n ++; |
imadaemi | 1:3151936d9c55 | 371 | |
imadaemi | 2:980edad0eea2 | 372 | pc.printf("********************\r\n\r\n"); |
imadaemi | 1:3151936d9c55 | 373 | |
imadaemi | 0:4e38f8b1c183 | 374 | if(header_set){ |
imadaemi | 0:4e38f8b1c183 | 375 | im920.send(); |
imadaemi | 2:980edad0eea2 | 376 | //pc.printf("Send : %s\r\n", im_buf); |
imadaemi | 0:4e38f8b1c183 | 377 | header_set = false; |
imadaemi | 0:4e38f8b1c183 | 378 | for(int i = 0; i < im_buf_n; i ++){ |
imadaemi | 0:4e38f8b1c183 | 379 | im_buf[i] = '\0'; |
imadaemi | 0:4e38f8b1c183 | 380 | } |
imadaemi | 0:4e38f8b1c183 | 381 | im_buf_n = 0; |
imadaemi | 0:4e38f8b1c183 | 382 | } |
imadaemi | 0:4e38f8b1c183 | 383 | } |
imadaemi | 0:4e38f8b1c183 | 384 | |
imadaemi | 2:980edad0eea2 | 385 | |
imadaemi | 0:4e38f8b1c183 | 386 | // *************************************************** |
imadaemi | 0:4e38f8b1c183 | 387 | // EEPROMにデータを書き込むプログラム |
imadaemi | 0:4e38f8b1c183 | 388 | // *************************************************** |
imadaemi | 0:4e38f8b1c183 | 389 | void WriteEEPROM(){ |
imadaemi | 0:4e38f8b1c183 | 390 | int ptr, n = 0; |
imadaemi | 0:4e38f8b1c183 | 391 | int eeprom_ptr = 0; |
imadaemi | 0:4e38f8b1c183 | 392 | |
imadaemi | 0:4e38f8b1c183 | 393 | for(int i = 0; i < 4; i++){ |
imadaemi | 0:4e38f8b1c183 | 394 | pc.printf("Start to write %d EEPROM\r\n", i); |
imadaemi | 0:4e38f8b1c183 | 395 | setEEPROMGroup(i); |
imadaemi | 0:4e38f8b1c183 | 396 | EEPROM.setWriteAddr(1, 0, 0x00, 0x00); |
imadaemi | 0:4e38f8b1c183 | 397 | |
imadaemi | 0:4e38f8b1c183 | 398 | while(1){ |
imadaemi | 0:4e38f8b1c183 | 399 | ptr = EEPROM.chargeBuff((int)n++); |
imadaemi | 0:4e38f8b1c183 | 400 | //ptr = EEPROM.chargeBuff((char)0xff); |
imadaemi | 0:4e38f8b1c183 | 401 | //ptr = EEPROM.chargeBuff((int)0); |
imadaemi | 0:4e38f8b1c183 | 402 | if(ptr == 128){ |
imadaemi | 0:4e38f8b1c183 | 403 | EEPROM.writeBuff(); |
imadaemi | 0:4e38f8b1c183 | 404 | //ptr = EEPROM.setNextPage(); |
imadaemi | 0:4e38f8b1c183 | 405 | eeprom_ptr = EEPROM.setNextPage(); |
imadaemi | 0:4e38f8b1c183 | 406 | //pc.printf("eeprom_ptr: %08x\r\n", eeprom_ptr); |
imadaemi | 0:4e38f8b1c183 | 407 | } |
imadaemi | 0:4e38f8b1c183 | 408 | |
imadaemi | 0:4e38f8b1c183 | 409 | if(eeprom_ptr == 0x01000000){ |
imadaemi | 0:4e38f8b1c183 | 410 | ptr = 0; |
imadaemi | 0:4e38f8b1c183 | 411 | eeprom_ptr = 0; |
imadaemi | 0:4e38f8b1c183 | 412 | break; |
imadaemi | 0:4e38f8b1c183 | 413 | } |
imadaemi | 0:4e38f8b1c183 | 414 | } |
imadaemi | 0:4e38f8b1c183 | 415 | } |
imadaemi | 0:4e38f8b1c183 | 416 | } |
imadaemi | 0:4e38f8b1c183 | 417 | |
imadaemi | 0:4e38f8b1c183 | 418 | // *************************************************** |
imadaemi | 0:4e38f8b1c183 | 419 | // マルチプレクサで使うEEPROMを変更する |
imadaemi | 0:4e38f8b1c183 | 420 | // *************************************************** |
imadaemi | 0:4e38f8b1c183 | 421 | void setEEPROMGroup(int group_num){ |
imadaemi | 0:4e38f8b1c183 | 422 | switch(group_num){ |
imadaemi | 0:4e38f8b1c183 | 423 | case 0: |
imadaemi | 0:4e38f8b1c183 | 424 | pinA = 0; |
imadaemi | 0:4e38f8b1c183 | 425 | pinB = 0; |
imadaemi | 0:4e38f8b1c183 | 426 | pinC = 0; |
imadaemi | 0:4e38f8b1c183 | 427 | break; |
imadaemi | 0:4e38f8b1c183 | 428 | |
imadaemi | 0:4e38f8b1c183 | 429 | case 1: |
imadaemi | 0:4e38f8b1c183 | 430 | pinA = 1; |
imadaemi | 0:4e38f8b1c183 | 431 | pinB = 0; |
imadaemi | 0:4e38f8b1c183 | 432 | pinC = 0; |
imadaemi | 0:4e38f8b1c183 | 433 | break; |
imadaemi | 0:4e38f8b1c183 | 434 | |
imadaemi | 0:4e38f8b1c183 | 435 | case 2: |
imadaemi | 0:4e38f8b1c183 | 436 | pinA = 0; |
imadaemi | 0:4e38f8b1c183 | 437 | pinB = 1; |
imadaemi | 0:4e38f8b1c183 | 438 | pinC = 0; |
imadaemi | 0:4e38f8b1c183 | 439 | break; |
imadaemi | 0:4e38f8b1c183 | 440 | |
imadaemi | 0:4e38f8b1c183 | 441 | case 3: |
imadaemi | 0:4e38f8b1c183 | 442 | pinA = 1; |
imadaemi | 0:4e38f8b1c183 | 443 | pinB = 1; |
imadaemi | 0:4e38f8b1c183 | 444 | pinC = 0; |
imadaemi | 0:4e38f8b1c183 | 445 | break; |
imadaemi | 0:4e38f8b1c183 | 446 | } |
imadaemi | 0:4e38f8b1c183 | 447 | } |