пропажа слешей
Dependencies: mbed mbed-STM32F103C8T6 MLX90614 Watchdog DS1820
main.cpp@17:1fed4feeb5a8, 2021-01-16 (annotated)
- Committer:
- spin7ion
- Date:
- Sat Jan 16 18:15:11 2021 +0000
- Revision:
- 17:1fed4feeb5a8
- Parent:
- 16:319eece233ff
- Child:
- 18:11e82e17446d
no gps
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hudakz | 0:0279e8c1f111 | 1 | #include "stm32f103c8t6.h" |
hudakz | 0:0279e8c1f111 | 2 | #include "mbed.h" |
spin7ion | 6:70d0218c2a28 | 3 | #include "DS1820.h" |
spin7ion | 6:70d0218c2a28 | 4 | #include "MLX90614.h" |
spin7ion | 6:70d0218c2a28 | 5 | #include "config.h" |
spin7ion | 6:70d0218c2a28 | 6 | #include "ATCmdParser.h" |
spin7ion | 6:70d0218c2a28 | 7 | #include "UARTSerial.h" |
spin7ion | 6:70d0218c2a28 | 8 | #include "Watchdog.h" |
astartes | 15:b0d74907b9c1 | 9 | |
spin7ion | 6:70d0218c2a28 | 10 | Watchdog wd; |
spin7ion | 6:70d0218c2a28 | 11 | DigitalOut myled(PC_13); |
astartes | 11:57fa27cb533e | 12 | DigitalOut simPWR(PA_8); // (active low level) PWRKEY pin to power on or off module |
astartes | 15:b0d74907b9c1 | 13 | |
spin7ion | 6:70d0218c2a28 | 14 | //SIM7000 |
spin7ion | 6:70d0218c2a28 | 15 | UARTSerial *_serial; |
spin7ion | 6:70d0218c2a28 | 16 | ATCmdParser *_parser; |
spin7ion | 10:51960145754a | 17 | int rssiDB,rxQual; |
astartes | 15:b0d74907b9c1 | 18 | |
astartes | 11:57fa27cb533e | 19 | bool from_sleep = false; |
astartes | 15:b0d74907b9c1 | 20 | |
astartes | 15:b0d74907b9c1 | 21 | |
astartes | 11:57fa27cb533e | 22 | // ID |
astartes | 15:b0d74907b9c1 | 23 | |
astartes | 16:319eece233ff | 24 | char device_id[] = {'M','I','E','M','H','S','E','-','2','0','2','1','\0'}; |
astartes | 15:b0d74907b9c1 | 25 | |
spin7ion | 6:70d0218c2a28 | 26 | //Termometers |
spin7ion | 6:70d0218c2a28 | 27 | OneWire oneWire(PIN_ONEWIRE); |
spin7ion | 6:70d0218c2a28 | 28 | const int SENSORS_COUNT = 10; |
spin7ion | 6:70d0218c2a28 | 29 | DS1820* ds1820[SENSORS_COUNT]; |
spin7ion | 6:70d0218c2a28 | 30 | int sensors_found = 0; |
spin7ion | 6:70d0218c2a28 | 31 | const char sensorsOrder[]={4,2,5,8,0,3,6,1,9,7}; |
spin7ion | 6:70d0218c2a28 | 32 | float stickTemperatures[SENSORS_COUNT]; |
astartes | 15:b0d74907b9c1 | 33 | |
spin7ion | 6:70d0218c2a28 | 34 | int i=0; |
astartes | 15:b0d74907b9c1 | 35 | |
spin7ion | 6:70d0218c2a28 | 36 | //IR termometer |
spin7ion | 6:70d0218c2a28 | 37 | I2C i2c(PIN_SDA, PIN_SCL); //sda,scl |
spin7ion | 6:70d0218c2a28 | 38 | MLX90614 thermometer(&i2c); |
spin7ion | 6:70d0218c2a28 | 39 | float IRtemp; |
astartes | 15:b0d74907b9c1 | 40 | |
astartes | 11:57fa27cb533e | 41 | // GPS |
astartes | 11:57fa27cb533e | 42 | int Fix_st; |
astartes | 15:b0d74907b9c1 | 43 | |
astartes | 11:57fa27cb533e | 44 | float B_l; |
astartes | 11:57fa27cb533e | 45 | float L_l; |
astartes | 11:57fa27cb533e | 46 | float Alt; |
astartes | 15:b0d74907b9c1 | 47 | |
astartes | 11:57fa27cb533e | 48 | bool cold_start = 0; |
astartes | 11:57fa27cb533e | 49 | int step_p = 0; |
spin7ion | 6:70d0218c2a28 | 50 | #if DEBUG_PC |
spin7ion | 6:70d0218c2a28 | 51 | Serial pc(PIN_TX, PIN_RX); // TX, RX |
spin7ion | 6:70d0218c2a28 | 52 | #endif |
astartes | 15:b0d74907b9c1 | 53 | |
spin7ion | 6:70d0218c2a28 | 54 | int index; |
spin7ion | 6:70d0218c2a28 | 55 | char bufferString[2048]; |
astartes | 15:b0d74907b9c1 | 56 | |
spin7ion | 6:70d0218c2a28 | 57 | int h_time, m_time, s_time; |
spin7ion | 6:70d0218c2a28 | 58 | int fq, nst, fix, date; // fix quality, Number of satellites being tracked, 3D fix |
astartes | 11:57fa27cb533e | 59 | //float latitude, longitude, timefix, speed, altitude; |
astartes | 15:b0d74907b9c1 | 60 | |
spin7ion | 6:70d0218c2a28 | 61 | char state=STATE_INIT; |
spin7ion | 6:70d0218c2a28 | 62 | int sleepTimer=0; |
spin7ion | 6:70d0218c2a28 | 63 | int fixTries=0; |
astartes | 11:57fa27cb533e | 64 | float a = 66; |
astartes | 11:57fa27cb533e | 65 | void waste_time(int x) |
astartes | 11:57fa27cb533e | 66 | { |
astartes | 11:57fa27cb533e | 67 | |
astartes | 11:57fa27cb533e | 68 | for(int i; i < 10000000; i++) |
astartes | 11:57fa27cb533e | 69 | { |
astartes | 11:57fa27cb533e | 70 | for(int k; k < 10000000 * x * 5; k++) |
astartes | 11:57fa27cb533e | 71 | { |
astartes | 11:57fa27cb533e | 72 | a = a / 33; |
astartes | 11:57fa27cb533e | 73 | a = a * 33; |
astartes | 11:57fa27cb533e | 74 | } |
astartes | 11:57fa27cb533e | 75 | } |
astartes | 15:b0d74907b9c1 | 76 | |
astartes | 15:b0d74907b9c1 | 77 | |
astartes | 15:b0d74907b9c1 | 78 | |
astartes | 11:57fa27cb533e | 79 | } |
astartes | 15:b0d74907b9c1 | 80 | |
astartes | 15:b0d74907b9c1 | 81 | |
spin7ion | 6:70d0218c2a28 | 82 | void parseTime (float timeval) |
spin7ion | 6:70d0218c2a28 | 83 | { |
spin7ion | 6:70d0218c2a28 | 84 | //format utc time to beijing time,add 8 time zone |
spin7ion | 6:70d0218c2a28 | 85 | float time = timeval + 80000.00f; |
spin7ion | 6:70d0218c2a28 | 86 | h_time = int(time) / 10000; |
spin7ion | 6:70d0218c2a28 | 87 | m_time = (int(time) % 10000) / 100; |
spin7ion | 6:70d0218c2a28 | 88 | s_time = int(time) % 100; |
spin7ion | 6:70d0218c2a28 | 89 | } |
astartes | 15:b0d74907b9c1 | 90 | |
astartes | 15:b0d74907b9c1 | 91 | |
spin7ion | 6:70d0218c2a28 | 92 | bool checkIfOk() { |
spin7ion | 6:70d0218c2a28 | 93 | if(_parser->recv("OK")) { |
spin7ion | 6:70d0218c2a28 | 94 | #if DEBUG_PC |
spin7ion | 6:70d0218c2a28 | 95 | pc.printf("Done\r\n"); |
spin7ion | 6:70d0218c2a28 | 96 | #endif |
spin7ion | 6:70d0218c2a28 | 97 | |
spin7ion | 6:70d0218c2a28 | 98 | return true; |
spin7ion | 6:70d0218c2a28 | 99 | } else { |
spin7ion | 6:70d0218c2a28 | 100 | #if DEBUG_PC |
spin7ion | 6:70d0218c2a28 | 101 | pc.printf("Fail\r\n"); |
spin7ion | 6:70d0218c2a28 | 102 | #endif |
spin7ion | 6:70d0218c2a28 | 103 | |
spin7ion | 6:70d0218c2a28 | 104 | return false; |
spin7ion | 6:70d0218c2a28 | 105 | } |
spin7ion | 6:70d0218c2a28 | 106 | } |
astartes | 11:57fa27cb533e | 107 | void blink_fast() |
astartes | 11:57fa27cb533e | 108 | { |
astartes | 11:57fa27cb533e | 109 | for(i=0;i<5;i++) |
astartes | 11:57fa27cb533e | 110 | { |
astartes | 11:57fa27cb533e | 111 | myled = 1; |
astartes | 11:57fa27cb533e | 112 | wait(0.5); |
astartes | 11:57fa27cb533e | 113 | myled = 0; |
astartes | 11:57fa27cb533e | 114 | wait(0.5); |
astartes | 11:57fa27cb533e | 115 | myled = 1; |
astartes | 11:57fa27cb533e | 116 | } |
astartes | 11:57fa27cb533e | 117 | } |
astartes | 11:57fa27cb533e | 118 | void blink_slow() |
astartes | 11:57fa27cb533e | 119 | { |
astartes | 11:57fa27cb533e | 120 | for(i=0;i<5;i++) |
astartes | 11:57fa27cb533e | 121 | { |
astartes | 11:57fa27cb533e | 122 | myled = 1; |
astartes | 11:57fa27cb533e | 123 | wait(1); |
astartes | 11:57fa27cb533e | 124 | myled = 0; |
astartes | 11:57fa27cb533e | 125 | wait(1); |
astartes | 11:57fa27cb533e | 126 | myled = 1; |
astartes | 11:57fa27cb533e | 127 | } |
astartes | 11:57fa27cb533e | 128 | } |
astartes | 15:b0d74907b9c1 | 129 | |
astartes | 15:b0d74907b9c1 | 130 | |
astartes | 15:b0d74907b9c1 | 131 | |
spin7ion | 6:70d0218c2a28 | 132 | bool enableGPS(bool powerUp) { |
spin7ion | 10:51960145754a | 133 | #if DEBUG_PC |
astartes | 11:57fa27cb533e | 134 | pc.printf("Powering GPS %s:\r\n",powerUp?"up":"down"); |
spin7ion | 10:51960145754a | 135 | #endif |
spin7ion | 6:70d0218c2a28 | 136 | if(powerUp){ |
spin7ion | 6:70d0218c2a28 | 137 | _parser->send("AT+CGNSPWR=1"); //GPS power on |
spin7ion | 6:70d0218c2a28 | 138 | } else { |
spin7ion | 6:70d0218c2a28 | 139 | _parser->send("AT+CGNSPWR=0"); //GPS power off |
spin7ion | 6:70d0218c2a28 | 140 | } |
astartes | 11:57fa27cb533e | 141 | wait(0.5); |
spin7ion | 10:51960145754a | 142 | return checkIfOk(); |
spin7ion | 10:51960145754a | 143 | } |
astartes | 15:b0d74907b9c1 | 144 | bool configure() |
astartes | 15:b0d74907b9c1 | 145 | { |
astartes | 15:b0d74907b9c1 | 146 | _parser->send("AT+CNMP=38"); |
astartes | 15:b0d74907b9c1 | 147 | if (!checkIfOk()) |
astartes | 15:b0d74907b9c1 | 148 | { |
astartes | 15:b0d74907b9c1 | 149 | return false; |
astartes | 15:b0d74907b9c1 | 150 | } |
spin7ion | 10:51960145754a | 151 | |
astartes | 15:b0d74907b9c1 | 152 | _parser->send("AT+CMNB=2"); |
astartes | 15:b0d74907b9c1 | 153 | if (!checkIfOk()) |
astartes | 15:b0d74907b9c1 | 154 | { |
astartes | 15:b0d74907b9c1 | 155 | return false; |
astartes | 15:b0d74907b9c1 | 156 | } |
astartes | 15:b0d74907b9c1 | 157 | _parser->send("AT+CAPNMODE=1"); |
astartes | 15:b0d74907b9c1 | 158 | if (!checkIfOk()) |
astartes | 15:b0d74907b9c1 | 159 | { |
astartes | 15:b0d74907b9c1 | 160 | return false; |
astartes | 15:b0d74907b9c1 | 161 | } |
astartes | 16:319eece233ff | 162 | _parser->send("AT+CAPNMODE=1"); |
astartes | 16:319eece233ff | 163 | if (!checkIfOk()) |
astartes | 16:319eece233ff | 164 | { |
astartes | 16:319eece233ff | 165 | return false; |
astartes | 16:319eece233ff | 166 | } |
astartes | 16:319eece233ff | 167 | _parser->send("AT+CBANDCFG=\"NB-IOT\",8"); |
astartes | 16:319eece233ff | 168 | if (!checkIfOk()) |
astartes | 16:319eece233ff | 169 | { |
astartes | 16:319eece233ff | 170 | return false; |
astartes | 16:319eece233ff | 171 | } |
astartes | 16:319eece233ff | 172 | _parser->send("AT+CNDS=2"); |
astartes | 16:319eece233ff | 173 | if (!checkIfOk()) |
astartes | 16:319eece233ff | 174 | { |
astartes | 16:319eece233ff | 175 | return false; |
astartes | 16:319eece233ff | 176 | } |
astartes | 16:319eece233ff | 177 | |
astartes | 15:b0d74907b9c1 | 178 | return true; |
astartes | 15:b0d74907b9c1 | 179 | } |
astartes | 15:b0d74907b9c1 | 180 | |
spin7ion | 10:51960145754a | 181 | bool enableRF(bool powerUp){ |
spin7ion | 10:51960145754a | 182 | #if DEBUG_PC |
astartes | 11:57fa27cb533e | 183 | pc.printf("Powering RF %s: \r\n",powerUp?"up":"down"); |
spin7ion | 10:51960145754a | 184 | #endif |
spin7ion | 10:51960145754a | 185 | if(powerUp){ |
astartes | 11:57fa27cb533e | 186 | _parser->send("AT+CFUN=1"); |
spin7ion | 10:51960145754a | 187 | } else { |
spin7ion | 10:51960145754a | 188 | _parser->send("AT+CFUN=0"); //GPS power off |
spin7ion | 10:51960145754a | 189 | } |
astartes | 15:b0d74907b9c1 | 190 | //wait(0.1); |
astartes | 15:b0d74907b9c1 | 191 | return checkIfOk(); |
astartes | 15:b0d74907b9c1 | 192 | //return true; |
spin7ion | 6:70d0218c2a28 | 193 | } |
astartes | 15:b0d74907b9c1 | 194 | |
astartes | 11:57fa27cb533e | 195 | bool setPowerSavingMode() |
astartes | 11:57fa27cb533e | 196 | { |
astartes | 11:57fa27cb533e | 197 | _parser->send("AT+CPSMS=1");//power save on |
astartes | 11:57fa27cb533e | 198 | wait(0.2); |
spin7ion | 10:51960145754a | 199 | return checkIfOk(); |
spin7ion | 10:51960145754a | 200 | } |
astartes | 15:b0d74907b9c1 | 201 | |
spin7ion | 6:70d0218c2a28 | 202 | bool setSatSystems(){ |
spin7ion | 10:51960145754a | 203 | #if DEBUG_PC |
spin7ion | 10:51960145754a | 204 | pc.printf("Setting sats:"); |
spin7ion | 10:51960145754a | 205 | #endif |
spin7ion | 6:70d0218c2a28 | 206 | _parser->send("AT+CGNSMOD=1,1,1,1"); |
spin7ion | 6:70d0218c2a28 | 207 | return checkIfOk(); |
spin7ion | 6:70d0218c2a28 | 208 | } |
astartes | 15:b0d74907b9c1 | 209 | |
astartes | 11:57fa27cb533e | 210 | bool getSignalQuality() |
astartes | 11:57fa27cb533e | 211 | { |
spin7ion | 10:51960145754a | 212 | _parser->send("AT+CSQ"); |
spin7ion | 10:51960145754a | 213 | |
spin7ion | 10:51960145754a | 214 | if(_parser->recv("+CSQ: %d,%d", &rssiDB,&rxQual) && _parser->recv("OK")) { |
spin7ion | 10:51960145754a | 215 | return true; |
spin7ion | 10:51960145754a | 216 | } |
spin7ion | 10:51960145754a | 217 | return false; |
spin7ion | 10:51960145754a | 218 | } |
astartes | 15:b0d74907b9c1 | 219 | |
spin7ion | 10:51960145754a | 220 | bool setAPN() { |
astartes | 11:57fa27cb533e | 221 | _parser->send("AT+CNACT=1,\"iot\""); |
spin7ion | 10:51960145754a | 222 | return checkIfOk(); |
spin7ion | 10:51960145754a | 223 | } |
astartes | 15:b0d74907b9c1 | 224 | |
spin7ion | 10:51960145754a | 225 | bool disconnectNetwork() { |
spin7ion | 10:51960145754a | 226 | _parser->send("AT+CNACT=0"); |
spin7ion | 10:51960145754a | 227 | return checkIfOk(); |
spin7ion | 10:51960145754a | 228 | } |
astartes | 15:b0d74907b9c1 | 229 | |
astartes | 11:57fa27cb533e | 230 | int initSIM() |
astartes | 11:57fa27cb533e | 231 | { |
astartes | 11:57fa27cb533e | 232 | fixTries=0; |
astartes | 11:57fa27cb533e | 233 | while(fixTries<COMD_EXE_TRIES && !enableRF(1)) |
astartes | 11:57fa27cb533e | 234 | { |
astartes | 11:57fa27cb533e | 235 | |
astartes | 11:57fa27cb533e | 236 | wait(2); |
astartes | 11:57fa27cb533e | 237 | wd.Service(); |
astartes | 15:b0d74907b9c1 | 238 | |
astartes | 15:b0d74907b9c1 | 239 | fixTries++; |
astartes | 15:b0d74907b9c1 | 240 | if (fixTries >= COMD_EXE_TRIES) |
astartes | 15:b0d74907b9c1 | 241 | { |
astartes | 15:b0d74907b9c1 | 242 | return 0; |
astartes | 15:b0d74907b9c1 | 243 | } |
astartes | 15:b0d74907b9c1 | 244 | } |
astartes | 15:b0d74907b9c1 | 245 | fixTries=0; |
astartes | 15:b0d74907b9c1 | 246 | while(fixTries<COMD_EXE_TRIES && !configure()) |
astartes | 15:b0d74907b9c1 | 247 | { |
astartes | 15:b0d74907b9c1 | 248 | wait(1); |
astartes | 15:b0d74907b9c1 | 249 | wd.Service(); |
astartes | 11:57fa27cb533e | 250 | fixTries++; |
astartes | 11:57fa27cb533e | 251 | if (fixTries >= COMD_EXE_TRIES) |
astartes | 11:57fa27cb533e | 252 | { |
astartes | 11:57fa27cb533e | 253 | return 0; |
astartes | 11:57fa27cb533e | 254 | } |
astartes | 11:57fa27cb533e | 255 | } |
astartes | 11:57fa27cb533e | 256 | |
astartes | 11:57fa27cb533e | 257 | fixTries=0; |
astartes | 11:57fa27cb533e | 258 | while(fixTries<COMD_EXE_TRIES && !setSatSystems()) |
astartes | 11:57fa27cb533e | 259 | { |
astartes | 11:57fa27cb533e | 260 | |
astartes | 11:57fa27cb533e | 261 | wait(2); |
astartes | 11:57fa27cb533e | 262 | wd.Service(); |
astartes | 11:57fa27cb533e | 263 | fixTries++; |
astartes | 11:57fa27cb533e | 264 | if (fixTries >= COMD_EXE_TRIES) |
astartes | 11:57fa27cb533e | 265 | { |
astartes | 11:57fa27cb533e | 266 | return 0; |
astartes | 11:57fa27cb533e | 267 | } |
astartes | 11:57fa27cb533e | 268 | } |
spin7ion | 10:51960145754a | 269 | wd.Service(); |
astartes | 11:57fa27cb533e | 270 | |
astartes | 11:57fa27cb533e | 271 | |
astartes | 15:b0d74907b9c1 | 272 | |
astartes | 11:57fa27cb533e | 273 | return true; |
spin7ion | 10:51960145754a | 274 | } |
astartes | 15:b0d74907b9c1 | 275 | |
spin7ion | 6:70d0218c2a28 | 276 | bool getGPS() { |
spin7ion | 10:51960145754a | 277 | wd.Service(); |
astartes | 11:57fa27cb533e | 278 | char GNSSrunstatus_c[2]; |
astartes | 11:57fa27cb533e | 279 | char Fixstatus_c[2]; |
astartes | 11:57fa27cb533e | 280 | char UTCdatetime_c[19]; |
astartes | 11:57fa27cb533e | 281 | char latitude_c[11]; |
astartes | 11:57fa27cb533e | 282 | char logitude_c[12]; |
astartes | 11:57fa27cb533e | 283 | char altitude_c[9]; |
astartes | 11:57fa27cb533e | 284 | char speedOTG_c[7]; |
astartes | 11:57fa27cb533e | 285 | char course_c[7]; |
astartes | 11:57fa27cb533e | 286 | char fixmode_c[2]; |
astartes | 11:57fa27cb533e | 287 | char reserved_1[1]; |
astartes | 11:57fa27cb533e | 288 | char HDOP_c[5]; |
astartes | 11:57fa27cb533e | 289 | char PDOP_c[5]; |
astartes | 11:57fa27cb533e | 290 | char VDOP_c[5]; |
astartes | 11:57fa27cb533e | 291 | char reserved_2[1]; |
astartes | 11:57fa27cb533e | 292 | char satellitesinview_c[3]; |
astartes | 11:57fa27cb533e | 293 | char GNSSsatellitesused_c[3]; |
astartes | 11:57fa27cb533e | 294 | char GLONASSsatellitesused_c[3]; |
astartes | 11:57fa27cb533e | 295 | char reserved_3[1]; |
astartes | 11:57fa27cb533e | 296 | char cn0max_c[3]; |
astartes | 11:57fa27cb533e | 297 | char HPA_c[7]; |
astartes | 11:57fa27cb533e | 298 | char VPA_c[7]; |
astartes | 15:b0d74907b9c1 | 299 | |
astartes | 11:57fa27cb533e | 300 | const int numChars = 120; // spec says up to 94 characters |
astartes | 11:57fa27cb533e | 301 | char receivedChars[ numChars ]; |
astartes | 11:57fa27cb533e | 302 | receivedChars[0] = 0; |
astartes | 15:b0d74907b9c1 | 303 | |
astartes | 15:b0d74907b9c1 | 304 | |
astartes | 15:b0d74907b9c1 | 305 | |
astartes | 11:57fa27cb533e | 306 | _parser->send("AT+CGNSINF"); |
astartes | 15:b0d74907b9c1 | 307 | |
astartes | 11:57fa27cb533e | 308 | int nmeaStrLen=_parser->read(receivedChars, 120); |
astartes | 11:57fa27cb533e | 309 | _parser->flush(); |
astartes | 11:57fa27cb533e | 310 | char *curLine = receivedChars; |
astartes | 15:b0d74907b9c1 | 311 | |
astartes | 11:57fa27cb533e | 312 | char frame[150]; |
astartes | 11:57fa27cb533e | 313 | for (int i = 0; i< 115; i++) |
astartes | 11:57fa27cb533e | 314 | { |
astartes | 11:57fa27cb533e | 315 | if(curLine[i]==':') |
astartes | 11:57fa27cb533e | 316 | { |
astartes | 11:57fa27cb533e | 317 | i++; |
astartes | 11:57fa27cb533e | 318 | int j = 0; |
astartes | 11:57fa27cb533e | 319 | while(i < 125) |
astartes | 11:57fa27cb533e | 320 | { |
astartes | 11:57fa27cb533e | 321 | if(curLine[i]=='O' && curLine[i+1]=='K') |
astartes | 11:57fa27cb533e | 322 | { |
astartes | 11:57fa27cb533e | 323 | break; |
astartes | 11:57fa27cb533e | 324 | } |
astartes | 11:57fa27cb533e | 325 | else |
astartes | 11:57fa27cb533e | 326 | { |
astartes | 11:57fa27cb533e | 327 | frame[j] = curLine[i]; |
astartes | 11:57fa27cb533e | 328 | #if DEBUG_PC |
astartes | 11:57fa27cb533e | 329 | pc.printf("cahr %c\n", frame[j]); |
astartes | 11:57fa27cb533e | 330 | #endif |
astartes | 11:57fa27cb533e | 331 | i++; |
astartes | 11:57fa27cb533e | 332 | j++; |
astartes | 11:57fa27cb533e | 333 | } |
astartes | 11:57fa27cb533e | 334 | } |
astartes | 11:57fa27cb533e | 335 | break; |
astartes | 11:57fa27cb533e | 336 | } |
astartes | 11:57fa27cb533e | 337 | } |
astartes | 11:57fa27cb533e | 338 | // Parses the string |
astartes | 11:57fa27cb533e | 339 | char * pch = strtok (frame,","); |
astartes | 11:57fa27cb533e | 340 | strcpy(GNSSrunstatus_c, pch); |
astartes | 11:57fa27cb533e | 341 | pch = strtok(NULL, ","); |
astartes | 11:57fa27cb533e | 342 | strcpy(Fixstatus_c, pch); |
astartes | 11:57fa27cb533e | 343 | pch = strtok(NULL, ","); |
astartes | 11:57fa27cb533e | 344 | strcpy(UTCdatetime_c, pch); |
astartes | 11:57fa27cb533e | 345 | pch = strtok(NULL, ","); |
astartes | 11:57fa27cb533e | 346 | strcpy(latitude_c, pch); |
astartes | 11:57fa27cb533e | 347 | pch = strtok(NULL, ","); |
astartes | 11:57fa27cb533e | 348 | strcpy(logitude_c, pch); |
astartes | 11:57fa27cb533e | 349 | pch = strtok(NULL, ","); |
astartes | 11:57fa27cb533e | 350 | strcpy(altitude_c, pch); |
astartes | 11:57fa27cb533e | 351 | pch = strtok(NULL, ","); |
astartes | 11:57fa27cb533e | 352 | strcpy(speedOTG_c, pch); |
astartes | 11:57fa27cb533e | 353 | pch = strtok(NULL, ","); |
astartes | 11:57fa27cb533e | 354 | strcpy(course_c, pch); |
astartes | 11:57fa27cb533e | 355 | pch = strtok(NULL, ","); |
astartes | 11:57fa27cb533e | 356 | strcpy(fixmode_c, pch); |
astartes | 11:57fa27cb533e | 357 | pch = strtok(NULL, ","); |
astartes | 11:57fa27cb533e | 358 | strcpy(reserved_1, pch); |
astartes | 11:57fa27cb533e | 359 | pch = strtok(NULL, ","); |
astartes | 11:57fa27cb533e | 360 | strcpy(HDOP_c, pch); |
astartes | 11:57fa27cb533e | 361 | pch = strtok(NULL, ","); |
astartes | 11:57fa27cb533e | 362 | strcpy(PDOP_c, pch); |
astartes | 11:57fa27cb533e | 363 | pch = strtok(NULL, ","); |
astartes | 11:57fa27cb533e | 364 | strcpy(VDOP_c, pch); |
astartes | 11:57fa27cb533e | 365 | pch = strtok(NULL, ","); |
astartes | 11:57fa27cb533e | 366 | strcpy(reserved_2, pch); |
astartes | 11:57fa27cb533e | 367 | pch = strtok(NULL, ","); |
astartes | 11:57fa27cb533e | 368 | strcpy(satellitesinview_c, pch); |
astartes | 11:57fa27cb533e | 369 | pch = strtok(NULL, ","); |
astartes | 11:57fa27cb533e | 370 | strcpy(GNSSsatellitesused_c, pch); |
astartes | 11:57fa27cb533e | 371 | pch = strtok(NULL, ","); |
astartes | 11:57fa27cb533e | 372 | strcpy(GLONASSsatellitesused_c, pch); |
astartes | 11:57fa27cb533e | 373 | pch = strtok(NULL, ","); |
astartes | 11:57fa27cb533e | 374 | strcpy(reserved_3, pch); |
astartes | 11:57fa27cb533e | 375 | pch = strtok(NULL, ","); |
astartes | 11:57fa27cb533e | 376 | strcpy(cn0max_c, pch); |
astartes | 11:57fa27cb533e | 377 | pch = strtok(NULL, ","); |
astartes | 11:57fa27cb533e | 378 | strcpy(HPA_c, pch); |
astartes | 11:57fa27cb533e | 379 | pch = strtok(NULL, ","); |
astartes | 11:57fa27cb533e | 380 | strcpy(VPA_c, pch); |
spin7ion | 10:51960145754a | 381 | |
astartes | 11:57fa27cb533e | 382 | |
astartes | 15:b0d74907b9c1 | 383 | |
astartes | 11:57fa27cb533e | 384 | int GNSS_st = atof(GNSSrunstatus_c); |
astartes | 11:57fa27cb533e | 385 | Fix_st = atof(Fixstatus_c); |
astartes | 11:57fa27cb533e | 386 | int sat_count = atof(satellitesinview_c); |
astartes | 15:b0d74907b9c1 | 387 | |
astartes | 11:57fa27cb533e | 388 | B_l = atof(latitude_c); |
astartes | 11:57fa27cb533e | 389 | L_l = atof(logitude_c); |
astartes | 11:57fa27cb533e | 390 | Alt = atof(altitude_c); |
astartes | 15:b0d74907b9c1 | 391 | |
astartes | 11:57fa27cb533e | 392 | #if DEBUG_PC |
astartes | 11:57fa27cb533e | 393 | pc.printf("GNSS st %d, FIX %d,SAT Count %d, Latitude: %f , Longitude: %f, Altitude: %f \n",GNSS_st, Fix_st, sat_count, B_l, L_l, Alt); |
astartes | 11:57fa27cb533e | 394 | #endif |
astartes | 15:b0d74907b9c1 | 395 | |
astartes | 11:57fa27cb533e | 396 | wd.Service(); |
astartes | 15:b0d74907b9c1 | 397 | |
astartes | 11:57fa27cb533e | 398 | if(Fix_st != 0) |
astartes | 11:57fa27cb533e | 399 | { |
astartes | 16:319eece233ff | 400 | if (step_p >= 4 ) |
spin7ion | 6:70d0218c2a28 | 401 | { |
astartes | 11:57fa27cb533e | 402 | return true; |
spin7ion | 6:70d0218c2a28 | 403 | } |
astartes | 11:57fa27cb533e | 404 | else |
astartes | 11:57fa27cb533e | 405 | { |
astartes | 11:57fa27cb533e | 406 | step_p++; |
spin7ion | 10:51960145754a | 407 | } |
astartes | 11:57fa27cb533e | 408 | } |
astartes | 16:319eece233ff | 409 | //return true; |
spin7ion | 6:70d0218c2a28 | 410 | return false; |
spin7ion | 6:70d0218c2a28 | 411 | } |
astartes | 15:b0d74907b9c1 | 412 | |
astartes | 11:57fa27cb533e | 413 | int terminateCOAPSession() { |
astartes | 15:b0d74907b9c1 | 414 | |
astartes | 11:57fa27cb533e | 415 | for(int try_c = 0; try_c < 5; try_c++) |
astartes | 11:57fa27cb533e | 416 | { |
astartes | 11:57fa27cb533e | 417 | _parser->flush(); |
spin7ion | 10:51960145754a | 418 | _parser->send("AT+CCOAPTERM"); |
astartes | 11:57fa27cb533e | 419 | int r1 = checkIfOk(); |
spin7ion | 10:51960145754a | 420 | wait(0.5); |
spin7ion | 10:51960145754a | 421 | _parser->send("AT+CNACT=0"); |
astartes | 11:57fa27cb533e | 422 | int r2 = checkIfOk(); |
astartes | 11:57fa27cb533e | 423 | if (r1 == r2 == true) |
astartes | 11:57fa27cb533e | 424 | { |
astartes | 11:57fa27cb533e | 425 | return true; |
astartes | 11:57fa27cb533e | 426 | } |
astartes | 11:57fa27cb533e | 427 | else |
astartes | 11:57fa27cb533e | 428 | { |
astartes | 11:57fa27cb533e | 429 | if(try_c >=5) |
astartes | 11:57fa27cb533e | 430 | { |
astartes | 11:57fa27cb533e | 431 | return false; |
astartes | 11:57fa27cb533e | 432 | } |
astartes | 11:57fa27cb533e | 433 | } |
astartes | 11:57fa27cb533e | 434 | } |
astartes | 15:b0d74907b9c1 | 435 | |
spin7ion | 10:51960145754a | 436 | } |
astartes | 15:b0d74907b9c1 | 437 | |
astartes | 15:b0d74907b9c1 | 438 | |
astartes | 15:b0d74907b9c1 | 439 | |
astartes | 11:57fa27cb533e | 440 | bool sendTelemetry() |
astartes | 11:57fa27cb533e | 441 | { |
astartes | 11:57fa27cb533e | 442 | int check = 0; |
spin7ion | 10:51960145754a | 443 | wd.Service(); |
astartes | 11:57fa27cb533e | 444 | int tr = 0; |
astartes | 15:b0d74907b9c1 | 445 | |
spin7ion | 10:51960145754a | 446 | setAPN(); |
astartes | 11:57fa27cb533e | 447 | |
astartes | 11:57fa27cb533e | 448 | wd.Service(); |
astartes | 11:57fa27cb533e | 449 | check = tr = 0; |
astartes | 11:57fa27cb533e | 450 | wait(2); |
astartes | 15:b0d74907b9c1 | 451 | |
astartes | 11:57fa27cb533e | 452 | _parser->flush(); |
astartes | 15:b0d74907b9c1 | 453 | _parser->send("AT+CCOAPINIT"); |
astartes | 11:57fa27cb533e | 454 | |
astartes | 15:b0d74907b9c1 | 455 | |
astartes | 15:b0d74907b9c1 | 456 | wait(1); |
astartes | 11:57fa27cb533e | 457 | _parser->flush(); |
astartes | 12:7fe416cdac08 | 458 | //_parser->send("AT+CCOAPURL=\"" MTS_TELEMETRY_URL_STRING); |
astartes | 15:b0d74907b9c1 | 459 | _parser->send("AT+CCOAPURL=\"coap://193.227.232.26:5683/multisensors\""); |
astartes | 15:b0d74907b9c1 | 460 | checkIfOk(); |
astartes | 11:57fa27cb533e | 461 | //if(!checkIfOk()){ terminateCOAPSession();return false;} |
astartes | 15:b0d74907b9c1 | 462 | wait(1); |
astartes | 15:b0d74907b9c1 | 463 | _parser->flush(); |
astartes | 11:57fa27cb533e | 464 | //_parser->printf("AT+CCOAPPARA=code,2,token,0,\"%s\",payload,1,",xstr(MTS_COAP_TOKEN)); |
astartes | 16:319eece233ff | 465 | //_parser->printf("AT+CCOAPPARA=code,2,payload,1,"); |
astartes | 16:319eece233ff | 466 | |
astartes | 15:b0d74907b9c1 | 467 | _parser->printf("AT+CCOAPPARA=code,2,payload,1,"); |
astartes | 16:319eece233ff | 468 | |
astartes | 15:b0d74907b9c1 | 469 | for (size_t i = 0; i < strlen(bufferString); i++) { |
astartes | 15:b0d74907b9c1 | 470 | _parser->printf("%x",bufferString[i]); |
astartes | 15:b0d74907b9c1 | 471 | } |
astartes | 15:b0d74907b9c1 | 472 | _parser->printf("\r\n"); |
astartes | 16:319eece233ff | 473 | //parser->printf("\r\n"); |
astartes | 15:b0d74907b9c1 | 474 | checkIfOk(); |
astartes | 11:57fa27cb533e | 475 | //if(!checkIfOk()){ terminateCOAPSession();return false;} |
spin7ion | 10:51960145754a | 476 | wait(0.5); |
astartes | 11:57fa27cb533e | 477 | _parser->flush(); |
astartes | 15:b0d74907b9c1 | 478 | _parser->send("AT+CCOAPACTION"); |
astartes | 11:57fa27cb533e | 479 | //checkIfOk(); |
astartes | 15:b0d74907b9c1 | 480 | if(!checkIfOk()){ return false;} |
astartes | 12:7fe416cdac08 | 481 | wait(2); |
astartes | 12:7fe416cdac08 | 482 | wd.Service(); |
astartes | 12:7fe416cdac08 | 483 | wait(2); |
astartes | 12:7fe416cdac08 | 484 | wd.Service(); |
astartes | 12:7fe416cdac08 | 485 | wait(2); |
astartes | 12:7fe416cdac08 | 486 | wd.Service(); |
astartes | 12:7fe416cdac08 | 487 | wait(2); |
astartes | 15:b0d74907b9c1 | 488 | |
astartes | 15:b0d74907b9c1 | 489 | terminateCOAPSession(); |
spin7ion | 10:51960145754a | 490 | |
spin7ion | 10:51960145754a | 491 | return true; |
spin7ion | 10:51960145754a | 492 | } |
spin7ion | 6:70d0218c2a28 | 493 | int main() { |
spin7ion | 6:70d0218c2a28 | 494 | confSysClock(); //Configure system clock (72MHz HSE clock, 48MHz USB clock) |
astartes | 15:b0d74907b9c1 | 495 | |
astartes | 11:57fa27cb533e | 496 | #if ENABLE_WATCHDOG |
astartes | 11:57fa27cb533e | 497 | wd.Configure(WATCHDOG_INTERVAL_S); // sets the timeout interval |
astartes | 11:57fa27cb533e | 498 | #endif |
astartes | 15:b0d74907b9c1 | 499 | |
astartes | 11:57fa27cb533e | 500 | simPWR = 0; |
astartes | 11:57fa27cb533e | 501 | wait(2); |
astartes | 11:57fa27cb533e | 502 | simPWR = 1; |
astartes | 15:b0d74907b9c1 | 503 | |
astartes | 11:57fa27cb533e | 504 | //blink_slow(); |
astartes | 11:57fa27cb533e | 505 | wd.Service(); |
astartes | 11:57fa27cb533e | 506 | for(i=0;i<7;i++) |
astartes | 11:57fa27cb533e | 507 | { |
astartes | 11:57fa27cb533e | 508 | //myled = 1; |
spin7ion | 10:51960145754a | 509 | wait(0.5); |
astartes | 11:57fa27cb533e | 510 | //myled = 0; |
spin7ion | 10:51960145754a | 511 | wait(0.5); |
astartes | 11:57fa27cb533e | 512 | wd.Service(); |
astartes | 11:57fa27cb533e | 513 | //myled = 1; |
astartes | 11:57fa27cb533e | 514 | } |
astartes | 15:b0d74907b9c1 | 515 | |
astartes | 11:57fa27cb533e | 516 | //wait(7); |
astartes | 11:57fa27cb533e | 517 | //toggle_sim_power(); |
astartes | 11:57fa27cb533e | 518 | /* |
astartes | 11:57fa27cb533e | 519 | * Generally, the NET indicator will fast flash firstly (1 time per second), which means that the |
astartes | 11:57fa27cb533e | 520 | * module has not logged in the Network. After logging in, the indicator become to flash slowly (1 |
astartes | 11:57fa27cb533e | 521 | * time every three seconds). |
astartes | 11:57fa27cb533e | 522 | */ |
astartes | 15:b0d74907b9c1 | 523 | |
spin7ion | 10:51960145754a | 524 | //wait(WATCHDOG_INTERVAL_S-15);//Let SIM7000 wake up |
astartes | 11:57fa27cb533e | 525 | wd.Service(); |
spin7ion | 6:70d0218c2a28 | 526 | #if DEBUG_PC |
spin7ion | 6:70d0218c2a28 | 527 | pc.baud(115200); |
spin7ion | 6:70d0218c2a28 | 528 | pc.printf("Starting\r\n"); |
spin7ion | 9:e8a07983289f | 529 | if (wd.WatchdogCausedReset()) { |
spin7ion | 6:70d0218c2a28 | 530 | pc.printf("Watchdog caused reset.\r\n"); |
spin7ion | 9:e8a07983289f | 531 | } |
spin7ion | 6:70d0218c2a28 | 532 | #endif |
astartes | 15:b0d74907b9c1 | 533 | |
spin7ion | 6:70d0218c2a28 | 534 | |
astartes | 15:b0d74907b9c1 | 535 | |
astartes | 11:57fa27cb533e | 536 | |
astartes | 15:b0d74907b9c1 | 537 | |
spin7ion | 6:70d0218c2a28 | 538 | |
spin7ion | 6:70d0218c2a28 | 539 | //Initiate SIM7000 SERIAL |
spin7ion | 6:70d0218c2a28 | 540 | _serial = new UARTSerial(PIN_SIM_TX, PIN_SIM_RX, 115200); |
spin7ion | 6:70d0218c2a28 | 541 | _parser = new ATCmdParser(_serial); |
spin7ion | 6:70d0218c2a28 | 542 | _parser->debug_on( DEBUG_SIM ); |
spin7ion | 6:70d0218c2a28 | 543 | _parser->set_delimiter( "\r\n" ); |
astartes | 11:57fa27cb533e | 544 | _parser->set_timeout(PARSER_TIMEOUT_S); |
astartes | 11:57fa27cb533e | 545 | wait(2); |
astartes | 15:b0d74907b9c1 | 546 | |
astartes | 15:b0d74907b9c1 | 547 | wd.Service(); |
astartes | 15:b0d74907b9c1 | 548 | wait(2); |
astartes | 15:b0d74907b9c1 | 549 | wd.Service(); |
astartes | 15:b0d74907b9c1 | 550 | wait(2); |
astartes | 15:b0d74907b9c1 | 551 | wd.Service(); |
astartes | 15:b0d74907b9c1 | 552 | wait(2); |
astartes | 11:57fa27cb533e | 553 | wd.Service(); |
astartes | 11:57fa27cb533e | 554 | wait(2); |
astartes | 11:57fa27cb533e | 555 | wd.Service(); |
astartes | 11:57fa27cb533e | 556 | wait(2); |
astartes | 15:b0d74907b9c1 | 557 | wd.Service(); |
astartes | 15:b0d74907b9c1 | 558 | wait(2); |
astartes | 15:b0d74907b9c1 | 559 | |
astartes | 11:57fa27cb533e | 560 | fixTries=0; |
astartes | 15:b0d74907b9c1 | 561 | |
astartes | 11:57fa27cb533e | 562 | #if DEBUG_PC |
astartes | 11:57fa27cb533e | 563 | pc.printf("INIT START\r\n"); |
astartes | 11:57fa27cb533e | 564 | #endif |
astartes | 15:b0d74907b9c1 | 565 | |
spin7ion | 10:51960145754a | 566 | |
astartes | 15:b0d74907b9c1 | 567 | |
astartes | 15:b0d74907b9c1 | 568 | |
astartes | 11:57fa27cb533e | 569 | int res = initSIM(); |
astartes | 11:57fa27cb533e | 570 | if(!res) |
astartes | 11:57fa27cb533e | 571 | { |
astartes | 11:57fa27cb533e | 572 | #if DEBUG_PC |
astartes | 11:57fa27cb533e | 573 | pc.printf("Init Failed\r\n"); |
astartes | 11:57fa27cb533e | 574 | #endif |
astartes | 15:b0d74907b9c1 | 575 | wd.Service(); |
astartes | 15:b0d74907b9c1 | 576 | wait(2); |
astartes | 15:b0d74907b9c1 | 577 | wd.Service(); |
astartes | 15:b0d74907b9c1 | 578 | wait(2); |
astartes | 15:b0d74907b9c1 | 579 | wd.Service(); |
astartes | 15:b0d74907b9c1 | 580 | wait(2); |
astartes | 15:b0d74907b9c1 | 581 | wd.Service(); |
astartes | 15:b0d74907b9c1 | 582 | wait(2); |
astartes | 15:b0d74907b9c1 | 583 | wd.Service(); |
astartes | 15:b0d74907b9c1 | 584 | wait(2); |
astartes | 15:b0d74907b9c1 | 585 | wd.Service(); |
astartes | 15:b0d74907b9c1 | 586 | wait(2); |
astartes | 11:57fa27cb533e | 587 | if(!initSIM()); |
astartes | 11:57fa27cb533e | 588 | { |
astartes | 11:57fa27cb533e | 589 | wait(WATCHDOG_INTERVAL_S+10); // reset by dog |
astartes | 11:57fa27cb533e | 590 | } |
astartes | 11:57fa27cb533e | 591 | } |
astartes | 15:b0d74907b9c1 | 592 | |
astartes | 11:57fa27cb533e | 593 | #if DEBUG_PC |
astartes | 11:57fa27cb533e | 594 | pc.printf("INIT finished\r\n"); |
spin7ion | 10:51960145754a | 595 | #endif |
astartes | 15:b0d74907b9c1 | 596 | |
astartes | 11:57fa27cb533e | 597 | for(i=0;i<7;i++) |
astartes | 11:57fa27cb533e | 598 | { |
astartes | 11:57fa27cb533e | 599 | myled = 1; |
astartes | 11:57fa27cb533e | 600 | wait(0.5); |
astartes | 11:57fa27cb533e | 601 | myled = 0; |
astartes | 11:57fa27cb533e | 602 | wait(0.5); |
astartes | 11:57fa27cb533e | 603 | wd.Service(); |
astartes | 11:57fa27cb533e | 604 | myled = 1; |
spin7ion | 10:51960145754a | 605 | } |
spin7ion | 6:70d0218c2a28 | 606 | |
astartes | 15:b0d74907b9c1 | 607 | |
astartes | 11:57fa27cb533e | 608 | wd.Service(); |
astartes | 11:57fa27cb533e | 609 | |
spin7ion | 10:51960145754a | 610 | /*_parser->send("AT+CPSI?"); |
spin7ion | 10:51960145754a | 611 | checkIfOk(); |
spin7ion | 10:51960145754a | 612 | _parser->send("AT+CGNAPN"); |
spin7ion | 10:51960145754a | 613 | checkIfOk(); |
spin7ion | 10:51960145754a | 614 | _parser->send("AT+CAPNMODE=1"); |
spin7ion | 10:51960145754a | 615 | checkIfOk(); |
spin7ion | 10:51960145754a | 616 | _parser->send("AT+CREG?"); |
spin7ion | 10:51960145754a | 617 | checkIfOk(); |
spin7ion | 10:51960145754a | 618 | */ |
spin7ion | 10:51960145754a | 619 | getSignalQuality(); |
spin7ion | 10:51960145754a | 620 | #if DEBUG_PC |
spin7ion | 10:51960145754a | 621 | pc.printf("Signal quality: %d\r\n",rssiDB); |
spin7ion | 10:51960145754a | 622 | #endif |
spin7ion | 10:51960145754a | 623 | |
spin7ion | 10:51960145754a | 624 | wd.Service(); |
spin7ion | 6:70d0218c2a28 | 625 | //Initiate termal stick |
spin7ion | 6:70d0218c2a28 | 626 | for(i = 0; i < SENSORS_COUNT; i++) { |
spin7ion | 6:70d0218c2a28 | 627 | ds1820[i] = new DS1820(&oneWire); |
spin7ion | 6:70d0218c2a28 | 628 | if(!ds1820[i]->begin()) { |
spin7ion | 6:70d0218c2a28 | 629 | delete ds1820[i]; |
spin7ion | 6:70d0218c2a28 | 630 | break; |
spin7ion | 6:70d0218c2a28 | 631 | } |
spin7ion | 6:70d0218c2a28 | 632 | } |
spin7ion | 6:70d0218c2a28 | 633 | |
spin7ion | 6:70d0218c2a28 | 634 | sensors_found = i; |
spin7ion | 6:70d0218c2a28 | 635 | #if DEBUG_PC |
spin7ion | 6:70d0218c2a28 | 636 | pc.printf("Found %d sensors\r\n",sensors_found); |
spin7ion | 6:70d0218c2a28 | 637 | if (sensors_found==0) |
spin7ion | 6:70d0218c2a28 | 638 | pc.printf("No devices found"); |
spin7ion | 6:70d0218c2a28 | 639 | #endif |
spin7ion | 6:70d0218c2a28 | 640 | |
spin7ion | 6:70d0218c2a28 | 641 | //Feed the watchdog |
spin7ion | 6:70d0218c2a28 | 642 | wd.Service(); |
astartes | 15:b0d74907b9c1 | 643 | |
spin7ion | 17:1fed4feeb5a8 | 644 | //state=STATE_STARTING_GPS; |
spin7ion | 17:1fed4feeb5a8 | 645 | state = STATE_COLLECTING_TELEMETRY; |
spin7ion | 6:70d0218c2a28 | 646 | |
astartes | 11:57fa27cb533e | 647 | int off = 0; |
astartes | 15:b0d74907b9c1 | 648 | |
spin7ion | 6:70d0218c2a28 | 649 | while(1) { |
spin7ion | 10:51960145754a | 650 | wd.Service(); |
astartes | 11:57fa27cb533e | 651 | if (state==STATE_STARTING_GPS) |
astartes | 11:57fa27cb533e | 652 | { |
astartes | 11:57fa27cb533e | 653 | wd.Service(); |
astartes | 11:57fa27cb533e | 654 | |
astartes | 15:b0d74907b9c1 | 655 | |
spin7ion | 6:70d0218c2a28 | 656 | #if DEBUG_PC |
spin7ion | 10:51960145754a | 657 | pc.printf("STATE=STARTING GPS\r\n"); |
spin7ion | 6:70d0218c2a28 | 658 | #endif |
astartes | 15:b0d74907b9c1 | 659 | |
astartes | 11:57fa27cb533e | 660 | fixTries=0; |
astartes | 11:57fa27cb533e | 661 | while(fixTries<COMD_EXE_TRIES && !enableGPS(1)) |
astartes | 11:57fa27cb533e | 662 | { |
astartes | 11:57fa27cb533e | 663 | #if DEBUG_PC |
astartes | 11:57fa27cb533e | 664 | pc.printf("GPS enable Fail\r\n"); |
astartes | 11:57fa27cb533e | 665 | #endif |
astartes | 11:57fa27cb533e | 666 | wait(3); |
astartes | 11:57fa27cb533e | 667 | wd.Service(); |
astartes | 11:57fa27cb533e | 668 | fixTries++; |
astartes | 11:57fa27cb533e | 669 | if (fixTries >= COMD_EXE_TRIES) |
astartes | 11:57fa27cb533e | 670 | { |
astartes | 11:57fa27cb533e | 671 | wait(WATCHDOG_INTERVAL_S+5); |
astartes | 11:57fa27cb533e | 672 | } |
astartes | 11:57fa27cb533e | 673 | } |
astartes | 15:b0d74907b9c1 | 674 | |
astartes | 11:57fa27cb533e | 675 | |
astartes | 11:57fa27cb533e | 676 | for(int test = 0; test < FIX_MAX_TRIES; test ++) |
astartes | 11:57fa27cb533e | 677 | { |
astartes | 11:57fa27cb533e | 678 | #if DEBUG_PC |
astartes | 11:57fa27cb533e | 679 | pc.printf("WAITNG gps to turn on \r\n"); |
astartes | 11:57fa27cb533e | 680 | #endif |
astartes | 11:57fa27cb533e | 681 | wd.Service(); |
astartes | 12:7fe416cdac08 | 682 | wait(2); |
astartes | 12:7fe416cdac08 | 683 | wait(2); |
astartes | 12:7fe416cdac08 | 684 | wait(1); |
astartes | 11:57fa27cb533e | 685 | wd.Service(); |
astartes | 11:57fa27cb533e | 686 | _parser->send("AT+CGNSINF"); |
astartes | 11:57fa27cb533e | 687 | if(checkIfOk()) |
astartes | 11:57fa27cb533e | 688 | { |
astartes | 11:57fa27cb533e | 689 | if(cold_start) |
astartes | 11:57fa27cb533e | 690 | { |
astartes | 11:57fa27cb533e | 691 | off = 0; |
astartes | 11:57fa27cb533e | 692 | while(off<COMD_EXE_TRIES && !enableGPS(0)) |
astartes | 11:57fa27cb533e | 693 | { |
astartes | 11:57fa27cb533e | 694 | wd.Service(); |
astartes | 11:57fa27cb533e | 695 | off++; |
astartes | 11:57fa27cb533e | 696 | } |
astartes | 11:57fa27cb533e | 697 | break; |
astartes | 11:57fa27cb533e | 698 | } |
astartes | 11:57fa27cb533e | 699 | else |
astartes | 11:57fa27cb533e | 700 | { |
astartes | 11:57fa27cb533e | 701 | break; |
astartes | 11:57fa27cb533e | 702 | } |
astartes | 11:57fa27cb533e | 703 | } |
astartes | 11:57fa27cb533e | 704 | else |
astartes | 11:57fa27cb533e | 705 | { |
astartes | 11:57fa27cb533e | 706 | if (test > 2) |
astartes | 11:57fa27cb533e | 707 | { |
astartes | 11:57fa27cb533e | 708 | cold_start = true; |
astartes | 11:57fa27cb533e | 709 | } |
astartes | 11:57fa27cb533e | 710 | wd.Service(); |
astartes | 12:7fe416cdac08 | 711 | wait(2); |
astartes | 12:7fe416cdac08 | 712 | wait(2); |
astartes | 12:7fe416cdac08 | 713 | wait(1); |
astartes | 11:57fa27cb533e | 714 | wd.Service(); |
astartes | 11:57fa27cb533e | 715 | } |
astartes | 11:57fa27cb533e | 716 | |
astartes | 11:57fa27cb533e | 717 | |
astartes | 15:b0d74907b9c1 | 718 | |
astartes | 11:57fa27cb533e | 719 | } |
astartes | 15:b0d74907b9c1 | 720 | |
astartes | 15:b0d74907b9c1 | 721 | |
astartes | 11:57fa27cb533e | 722 | |
spin7ion | 6:70d0218c2a28 | 723 | state=STATE_WAITING_FIX; |
spin7ion | 6:70d0218c2a28 | 724 | fixTries=0; |
spin7ion | 6:70d0218c2a28 | 725 | wd.Service(); |
astartes | 11:57fa27cb533e | 726 | step_p = 0; |
astartes | 11:57fa27cb533e | 727 | //wait(FIX_CHECK_TIME_S); |
astartes | 11:57fa27cb533e | 728 | |
astartes | 11:57fa27cb533e | 729 | } |
astartes | 11:57fa27cb533e | 730 | else if(state==STATE_WAITING_FIX) { |
spin7ion | 10:51960145754a | 731 | |
spin7ion | 10:51960145754a | 732 | #if DEBUG_PC |
spin7ion | 10:51960145754a | 733 | pc.printf("STATE=WAITNG FIX\r\n"); |
spin7ion | 10:51960145754a | 734 | #endif |
astartes | 15:b0d74907b9c1 | 735 | |
astartes | 11:57fa27cb533e | 736 | off = 0; |
astartes | 11:57fa27cb533e | 737 | if (cold_start) |
astartes | 11:57fa27cb533e | 738 | { |
astartes | 11:57fa27cb533e | 739 | while(off<COMD_EXE_TRIES && !enableGPS(1)) |
astartes | 11:57fa27cb533e | 740 | { |
astartes | 11:57fa27cb533e | 741 | wd.Service(); |
astartes | 11:57fa27cb533e | 742 | off++; |
astartes | 11:57fa27cb533e | 743 | if (off >= COMD_EXE_TRIES) |
astartes | 11:57fa27cb533e | 744 | { |
astartes | 11:57fa27cb533e | 745 | wait(WATCHDOG_INTERVAL_S+5); |
astartes | 11:57fa27cb533e | 746 | } |
astartes | 11:57fa27cb533e | 747 | } |
astartes | 11:57fa27cb533e | 748 | cold_start = false; |
astartes | 11:57fa27cb533e | 749 | } |
astartes | 11:57fa27cb533e | 750 | |
astartes | 11:57fa27cb533e | 751 | |
astartes | 11:57fa27cb533e | 752 | if(getGPS()) |
astartes | 11:57fa27cb533e | 753 | { |
spin7ion | 10:51960145754a | 754 | wd.Service(); |
astartes | 11:57fa27cb533e | 755 | off = 0; |
astartes | 11:57fa27cb533e | 756 | while(off<FIX_MAX_TRIES && !enableGPS(0)) |
astartes | 11:57fa27cb533e | 757 | { |
astartes | 11:57fa27cb533e | 758 | #if DEBUG_PC |
astartes | 11:57fa27cb533e | 759 | pc.printf("GPS disable Fail\r\n"); |
astartes | 11:57fa27cb533e | 760 | #endif |
astartes | 11:57fa27cb533e | 761 | wait(3); |
astartes | 11:57fa27cb533e | 762 | wd.Service(); |
astartes | 11:57fa27cb533e | 763 | off++; |
astartes | 11:57fa27cb533e | 764 | } |
astartes | 11:57fa27cb533e | 765 | |
spin7ion | 6:70d0218c2a28 | 766 | state=STATE_COLLECTING_TELEMETRY; |
astartes | 11:57fa27cb533e | 767 | } |
astartes | 11:57fa27cb533e | 768 | else |
astartes | 11:57fa27cb533e | 769 | { |
spin7ion | 10:51960145754a | 770 | wd.Service(); |
spin7ion | 9:e8a07983289f | 771 | #if DEBUG_PC |
spin7ion | 10:51960145754a | 772 | pc.printf("No fix(%d) at %d/%d try\r\n", fix, fixTries, FIX_MAX_TRIES); |
spin7ion | 9:e8a07983289f | 773 | #endif |
spin7ion | 6:70d0218c2a28 | 774 | fixTries++; |
astartes | 11:57fa27cb533e | 775 | if (fixTries>FIX_MAX_TRIES) |
astartes | 11:57fa27cb533e | 776 | { |
spin7ion | 6:70d0218c2a28 | 777 | //fix not achieved in given tries, send as is |
spin7ion | 10:51960145754a | 778 | #if DEBUG_PC |
spin7ion | 10:51960145754a | 779 | pc.printf("No fix but continue\r\n"); |
spin7ion | 10:51960145754a | 780 | #endif |
astartes | 15:b0d74907b9c1 | 781 | |
astartes | 11:57fa27cb533e | 782 | off = 0; |
astartes | 11:57fa27cb533e | 783 | while(off<FIX_MAX_TRIES && !enableGPS(0)) |
astartes | 11:57fa27cb533e | 784 | { |
astartes | 11:57fa27cb533e | 785 | #if DEBUG_PC |
astartes | 11:57fa27cb533e | 786 | pc.printf("GPS disable Fail\r\n"); |
astartes | 11:57fa27cb533e | 787 | #endif |
astartes | 11:57fa27cb533e | 788 | wait(3); |
astartes | 11:57fa27cb533e | 789 | wd.Service(); |
astartes | 11:57fa27cb533e | 790 | off++; |
astartes | 11:57fa27cb533e | 791 | } |
astartes | 11:57fa27cb533e | 792 | |
astartes | 11:57fa27cb533e | 793 | |
spin7ion | 9:e8a07983289f | 794 | wd.Service(); |
spin7ion | 6:70d0218c2a28 | 795 | state=STATE_COLLECTING_TELEMETRY; |
spin7ion | 10:51960145754a | 796 | fixTries=0; |
astartes | 11:57fa27cb533e | 797 | } |
astartes | 11:57fa27cb533e | 798 | else |
astartes | 11:57fa27cb533e | 799 | { |
spin7ion | 10:51960145754a | 800 | #if DEBUG_PC |
spin7ion | 10:51960145754a | 801 | pc.printf("Waiting %d sec\r\n",FIX_CHECK_TIME_S); |
spin7ion | 10:51960145754a | 802 | #endif |
spin7ion | 6:70d0218c2a28 | 803 | wd.Service(); |
astartes | 16:319eece233ff | 804 | wait(2); |
astartes | 16:319eece233ff | 805 | wait(2); |
astartes | 16:319eece233ff | 806 | wait(1); |
astartes | 16:319eece233ff | 807 | wd.Service(); |
spin7ion | 6:70d0218c2a28 | 808 | } |
spin7ion | 6:70d0218c2a28 | 809 | } |
spin7ion | 6:70d0218c2a28 | 810 | } else if(state==STATE_COLLECTING_TELEMETRY) { |
spin7ion | 10:51960145754a | 811 | #if DEBUG_PC |
spin7ion | 10:51960145754a | 812 | pc.printf("STATE=COLLECTING TELEMETRY\r\n"); |
spin7ion | 10:51960145754a | 813 | #endif |
spin7ion | 6:70d0218c2a28 | 814 | for(i=0;i<SENSORS_COUNT;i++){ |
spin7ion | 6:70d0218c2a28 | 815 | if(sensorsOrder[i]<sensors_found){ |
spin7ion | 6:70d0218c2a28 | 816 | ds1820[sensorsOrder[i]]->startConversion(); |
spin7ion | 6:70d0218c2a28 | 817 | } |
spin7ion | 6:70d0218c2a28 | 818 | } |
astartes | 15:b0d74907b9c1 | 819 | wait(1); |
spin7ion | 6:70d0218c2a28 | 820 | for(i=0;i<SENSORS_COUNT;i++){ |
spin7ion | 6:70d0218c2a28 | 821 | if(sensorsOrder[i]<sensors_found){ |
spin7ion | 6:70d0218c2a28 | 822 | if(ds1820[sensorsOrder[i]]->isPresent()){ |
spin7ion | 6:70d0218c2a28 | 823 | stickTemperatures[i]=ds1820[i]->read(); |
spin7ion | 6:70d0218c2a28 | 824 | } else { |
spin7ion | 6:70d0218c2a28 | 825 | stickTemperatures[i]=-273.f; // Sensor is offline |
spin7ion | 6:70d0218c2a28 | 826 | } |
spin7ion | 6:70d0218c2a28 | 827 | } |
spin7ion | 6:70d0218c2a28 | 828 | } |
spin7ion | 6:70d0218c2a28 | 829 | |
spin7ion | 6:70d0218c2a28 | 830 | IRtemp=thermometer.read_temp(1); |
spin7ion | 6:70d0218c2a28 | 831 | |
astartes | 11:57fa27cb533e | 832 | float bat_v = 100; |
spin7ion | 6:70d0218c2a28 | 833 | //Form JSON as {"tempIR":1,"temps":[1,...,10],"latitude":37,"longitude":51,"altitude":21,"validGeo":true} |
astartes | 15:b0d74907b9c1 | 834 | snprintf(bufferString,2048,"{\"ID\":\"%s\",\"tempIR\":%f,\"latitude\":%f,\"longitude\":%f,\"altitude\":%f,\"validGeo\":%s,\"battery\":%f,\"netlvl\":%d,\"temps\":[",device_id, IRtemp, B_l, L_l, Alt, Fix_st ? "1" : "0", bat_v, rssiDB); |
astartes | 12:7fe416cdac08 | 835 | // snprintf(bufferString,2048,"{\"ID\":\"%s\",\"tempIR\":%f,\"latitude\":%f,\"longitude\":%f,\"altitude\":%f,\"validGeo\":%s,\"battery\":%f,\"netlvl\":%d,\"temps\":[",device_id, IRtemp, B_l, L_l, Alt, Fix_st ? ( 1: 0) , bat_v |
astartes | 11:57fa27cb533e | 836 | // device_id |
spin7ion | 6:70d0218c2a28 | 837 | index = strlen(bufferString); |
spin7ion | 6:70d0218c2a28 | 838 | |
spin7ion | 6:70d0218c2a28 | 839 | for(i=0;i<SENSORS_COUNT;i++){ |
spin7ion | 9:e8a07983289f | 840 | index += snprintf(&bufferString[index], 2048-index, i==0?"%f":",%f", stickTemperatures[i]); |
spin7ion | 6:70d0218c2a28 | 841 | } |
spin7ion | 9:e8a07983289f | 842 | strcat (bufferString,"]}"); |
spin7ion | 6:70d0218c2a28 | 843 | |
spin7ion | 10:51960145754a | 844 | wd.Service(); |
spin7ion | 6:70d0218c2a28 | 845 | state=STATE_SENDING_TELEMETRY; |
astartes | 11:57fa27cb533e | 846 | } |
astartes | 11:57fa27cb533e | 847 | else if(state==STATE_SENDING_TELEMETRY) |
astartes | 11:57fa27cb533e | 848 | { |
spin7ion | 6:70d0218c2a28 | 849 | #if DEBUG_PC |
spin7ion | 10:51960145754a | 850 | pc.printf("STATE=SENDING TELEMETRY\r\n"); |
spin7ion | 6:70d0218c2a28 | 851 | pc.printf(bufferString); |
spin7ion | 6:70d0218c2a28 | 852 | #endif |
astartes | 11:57fa27cb533e | 853 | |
astartes | 11:57fa27cb533e | 854 | for(int try_c = 0; try_c < COMD_EXE_TRIES; try_c ++) |
astartes | 11:57fa27cb533e | 855 | { |
astartes | 11:57fa27cb533e | 856 | if(getSignalQuality()) |
astartes | 11:57fa27cb533e | 857 | { |
astartes | 11:57fa27cb533e | 858 | break; |
astartes | 11:57fa27cb533e | 859 | } |
spin7ion | 10:51960145754a | 860 | wd.Service(); |
spin7ion | 10:51960145754a | 861 | } |
astartes | 11:57fa27cb533e | 862 | |
astartes | 11:57fa27cb533e | 863 | |
spin7ion | 10:51960145754a | 864 | fixTries=0; |
astartes | 11:57fa27cb533e | 865 | |
astartes | 11:57fa27cb533e | 866 | while(fixTries<FIX_MAX_TRIES && !sendTelemetry()) |
astartes | 11:57fa27cb533e | 867 | { |
astartes | 15:b0d74907b9c1 | 868 | wait(2); |
astartes | 11:57fa27cb533e | 869 | terminateCOAPSession(); |
astartes | 15:b0d74907b9c1 | 870 | wait(2); |
astartes | 11:57fa27cb533e | 871 | wd.Service(); |
astartes | 11:57fa27cb533e | 872 | fixTries++; |
astartes | 11:57fa27cb533e | 873 | } |
astartes | 11:57fa27cb533e | 874 | |
astartes | 11:57fa27cb533e | 875 | //disconnectNetwork(); |
astartes | 11:57fa27cb533e | 876 | //initSIM(); |
astartes | 11:57fa27cb533e | 877 | //enableGPS(0); |
astartes | 11:57fa27cb533e | 878 | //setPowerSavingMode(); |
astartes | 11:57fa27cb533e | 879 | //fixTries++; |
spin7ion | 10:51960145754a | 880 | wd.Service(); |
astartes | 15:b0d74907b9c1 | 881 | enableRF(0); |
astartes | 15:b0d74907b9c1 | 882 | |
astartes | 11:57fa27cb533e | 883 | off = 0; |
astartes | 11:57fa27cb533e | 884 | while(off<COMD_EXE_TRIES && !setPowerSavingMode()) |
astartes | 11:57fa27cb533e | 885 | { |
astartes | 11:57fa27cb533e | 886 | wd.Service(); |
astartes | 11:57fa27cb533e | 887 | off++; |
astartes | 11:57fa27cb533e | 888 | } |
astartes | 11:57fa27cb533e | 889 | #if DEBUG_PC |
astartes | 11:57fa27cb533e | 890 | pc.printf("Sim 7000 Off\r\n"); |
astartes | 15:b0d74907b9c1 | 891 | |
astartes | 11:57fa27cb533e | 892 | #endif |
astartes | 15:b0d74907b9c1 | 893 | |
astartes | 11:57fa27cb533e | 894 | simPWR = 0; |
astartes | 11:57fa27cb533e | 895 | wait(2); |
astartes | 11:57fa27cb533e | 896 | simPWR = 1; |
astartes | 11:57fa27cb533e | 897 | _parser->flush(); |
astartes | 11:57fa27cb533e | 898 | |
astartes | 15:b0d74907b9c1 | 899 | |
astartes | 11:57fa27cb533e | 900 | //wait(SLEEP_CHECK_TIME); |
astartes | 11:57fa27cb533e | 901 | wd.Service(); |
astartes | 11:57fa27cb533e | 902 | |
astartes | 15:b0d74907b9c1 | 903 | |
spin7ion | 6:70d0218c2a28 | 904 | state=STATE_SLEEPING; |
astartes | 12:7fe416cdac08 | 905 | sleepTimer=0; |
astartes | 15:b0d74907b9c1 | 906 | |
spin7ion | 6:70d0218c2a28 | 907 | } else if(state==STATE_SLEEPING){ |
spin7ion | 10:51960145754a | 908 | #if DEBUG_PC |
spin7ion | 10:51960145754a | 909 | pc.printf("STATE=SLEEPING already for %d\r\n",sleepTimer); |
spin7ion | 10:51960145754a | 910 | #endif |
spin7ion | 6:70d0218c2a28 | 911 | wd.Service(); |
spin7ion | 6:70d0218c2a28 | 912 | sleepTimer+=SLEEP_CHECK_TIME; |
spin7ion | 6:70d0218c2a28 | 913 | |
spin7ion | 6:70d0218c2a28 | 914 | if(sleepTimer>SLEEP_TIME_S){ |
astartes | 11:57fa27cb533e | 915 | simPWR = 0; |
astartes | 11:57fa27cb533e | 916 | wait(3); |
astartes | 11:57fa27cb533e | 917 | simPWR = 1; |
astartes | 11:57fa27cb533e | 918 | _parser->flush(); |
astartes | 11:57fa27cb533e | 919 | #if DEBUG_PC |
astartes | 11:57fa27cb533e | 920 | pc.printf("from sleep\r\n"); |
astartes | 11:57fa27cb533e | 921 | #endif |
astartes | 15:b0d74907b9c1 | 922 | wait(2); |
astartes | 11:57fa27cb533e | 923 | wd.Service(); |
astartes | 15:b0d74907b9c1 | 924 | wait(2); |
astartes | 15:b0d74907b9c1 | 925 | wd.Service(); |
astartes | 15:b0d74907b9c1 | 926 | wait(2); |
astartes | 11:57fa27cb533e | 927 | wd.Service(); |
astartes | 11:57fa27cb533e | 928 | |
astartes | 11:57fa27cb533e | 929 | _parser->flush(); |
astartes | 11:57fa27cb533e | 930 | |
astartes | 15:b0d74907b9c1 | 931 | |
astartes | 11:57fa27cb533e | 932 | for(i=0;i<7;i++) |
astartes | 11:57fa27cb533e | 933 | { |
astartes | 11:57fa27cb533e | 934 | myled = 1; |
astartes | 11:57fa27cb533e | 935 | wait(1); |
astartes | 11:57fa27cb533e | 936 | myled = 0; |
astartes | 11:57fa27cb533e | 937 | wait(1); |
astartes | 11:57fa27cb533e | 938 | wd.Service(); |
astartes | 11:57fa27cb533e | 939 | myled = 1; |
astartes | 11:57fa27cb533e | 940 | } |
astartes | 11:57fa27cb533e | 941 | #if DEBUG_PC |
astartes | 11:57fa27cb533e | 942 | pc.printf("boot\r\n"); |
astartes | 11:57fa27cb533e | 943 | #endif |
astartes | 11:57fa27cb533e | 944 | for(i=0;i<7;i++) |
astartes | 11:57fa27cb533e | 945 | { |
astartes | 11:57fa27cb533e | 946 | myled = 1; |
astartes | 11:57fa27cb533e | 947 | wait(1); |
astartes | 11:57fa27cb533e | 948 | myled = 0; |
astartes | 11:57fa27cb533e | 949 | wait(1); |
astartes | 11:57fa27cb533e | 950 | wd.Service(); |
astartes | 11:57fa27cb533e | 951 | myled = 1; |
astartes | 11:57fa27cb533e | 952 | } |
astartes | 15:b0d74907b9c1 | 953 | wd.Service(); |
astartes | 15:b0d74907b9c1 | 954 | wait(2); |
astartes | 15:b0d74907b9c1 | 955 | wd.Service(); |
astartes | 15:b0d74907b9c1 | 956 | wait(2); |
astartes | 15:b0d74907b9c1 | 957 | wd.Service(); |
astartes | 15:b0d74907b9c1 | 958 | wait(2); |
astartes | 15:b0d74907b9c1 | 959 | wd.Service(); |
astartes | 15:b0d74907b9c1 | 960 | wait(2); |
astartes | 15:b0d74907b9c1 | 961 | wd.Service(); |
astartes | 15:b0d74907b9c1 | 962 | wait(2); |
astartes | 15:b0d74907b9c1 | 963 | wd.Service(); |
astartes | 15:b0d74907b9c1 | 964 | wait(2); |
astartes | 15:b0d74907b9c1 | 965 | |
astartes | 11:57fa27cb533e | 966 | int res = initSIM(); |
astartes | 11:57fa27cb533e | 967 | if(!res) |
astartes | 11:57fa27cb533e | 968 | { |
astartes | 11:57fa27cb533e | 969 | #if DEBUG_PC |
astartes | 11:57fa27cb533e | 970 | pc.printf("Init Failed\r\n"); |
astartes | 11:57fa27cb533e | 971 | #endif |
astartes | 15:b0d74907b9c1 | 972 | wd.Service(); |
astartes | 15:b0d74907b9c1 | 973 | wait(2); |
astartes | 15:b0d74907b9c1 | 974 | wd.Service(); |
astartes | 15:b0d74907b9c1 | 975 | wait(2); |
astartes | 15:b0d74907b9c1 | 976 | wd.Service(); |
astartes | 15:b0d74907b9c1 | 977 | wait(2); |
astartes | 15:b0d74907b9c1 | 978 | wd.Service(); |
astartes | 15:b0d74907b9c1 | 979 | wait(2); |
astartes | 15:b0d74907b9c1 | 980 | wd.Service(); |
astartes | 15:b0d74907b9c1 | 981 | wait(2); |
astartes | 15:b0d74907b9c1 | 982 | wd.Service(); |
astartes | 15:b0d74907b9c1 | 983 | wait(2); |
astartes | 11:57fa27cb533e | 984 | if(!initSIM()); |
astartes | 11:57fa27cb533e | 985 | { |
astartes | 11:57fa27cb533e | 986 | wait(WATCHDOG_INTERVAL_S+10); // reset by dog |
astartes | 11:57fa27cb533e | 987 | } |
astartes | 11:57fa27cb533e | 988 | |
astartes | 15:b0d74907b9c1 | 989 | |
astartes | 11:57fa27cb533e | 990 | |
astartes | 11:57fa27cb533e | 991 | } |
astartes | 15:b0d74907b9c1 | 992 | |
spin7ion | 17:1fed4feeb5a8 | 993 | //state=STATE_STARTING_GPS; |
spin7ion | 17:1fed4feeb5a8 | 994 | state = STATE_COLLECTING_TELEMETRY; |
spin7ion | 6:70d0218c2a28 | 995 | sleepTimer=0; |
spin7ion | 6:70d0218c2a28 | 996 | } else { |
astartes | 12:7fe416cdac08 | 997 | wait(2); |
astartes | 12:7fe416cdac08 | 998 | wait(2); |
astartes | 12:7fe416cdac08 | 999 | wait(1); |
astartes | 12:7fe416cdac08 | 1000 | // = 5 = SLEEP_CHECK_TIME |
spin7ion | 6:70d0218c2a28 | 1001 | } |
spin7ion | 10:51960145754a | 1002 | wd.Service(); |
spin7ion | 10:51960145754a | 1003 | #if DEBUG_PC |
spin7ion | 10:51960145754a | 1004 | pc.printf("After sleep\r\n"); |
spin7ion | 10:51960145754a | 1005 | #endif |
astartes | 11:57fa27cb533e | 1006 | |
astartes | 11:57fa27cb533e | 1007 | //from_sleep = true; |
spin7ion | 6:70d0218c2a28 | 1008 | } |
astartes | 15:b0d74907b9c1 | 1009 | |
spin7ion | 6:70d0218c2a28 | 1010 | //Feed the watchdog |
spin7ion | 6:70d0218c2a28 | 1011 | wd.Service(); |
spin7ion | 6:70d0218c2a28 | 1012 | wait(0.5); |
spin7ion | 6:70d0218c2a28 | 1013 | } |
astartes | 15:b0d74907b9c1 | 1014 | } |