whatever

Dependencies:   C027 C027_Support M2XStreamClient PowerControl jsonlite mbed-rtos mbed

Fork of PONY_Ph0-uAXIS by Sean McBeath

Committer:
sgmcb
Date:
Wed Jan 20 21:51:25 2016 +0000
Revision:
54:6ce53a145fa0
Parent:
53:3a99061b392f
fuck you

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lawliet 0:4e3cb26f6019 1 #include "mbed.h"
mazgch 9:26f694bc31b4 2
mazgch 19:f022ff746eb8 3 //------------------------------------------------------------------------------------
sgmcb 38:d86e744166b6 4 // C027 Support Libraries
mazgch 19:f022ff746eb8 5 #include "GPS.h"
mazgch 19:f022ff746eb8 6 #include "MDM.h"
sgmcb 36:258f3bb1c6a4 7
sgmcb 51:61a1ec3c56fc 8 #include "C027.h"
sgmcb 51:61a1ec3c56fc 9
sgmcb 50:bba466f093a4 10 // Power control libraries
sgmcb 50:bba466f093a4 11 #include "PowerControl.h"
sgmcb 50:bba466f093a4 12 #include "EthernetPowerControl.h"
sgmcb 50:bba466f093a4 13
sgmcb 52:ba2017c3ef8d 14 // MOD I2C
sgmcb 52:ba2017c3ef8d 15 //#include "MODI2C.h"
sgmcb 50:bba466f093a4 16
sgmcb 42:8e6e647cb7d5 17 // M2X Support Libraries
sgmcb 38:d86e744166b6 18 #include <jsonlite.h>
sgmcb 38:d86e744166b6 19 #include "M2XStreamClient.h"
sgmcb 37:71ab32b61dfb 20
sgmcb 42:8e6e647cb7d5 21 // PONY-specific config support libraries
sgmcb 41:f603d76dc6fe 22 #include "LIS331.h"
sgmcb 42:8e6e647cb7d5 23 #include "PONY_Loc.h" // PONY Location Code
sgmcb 41:f603d76dc6fe 24 #include "PONY_sense.h"
lawliet 0:4e3cb26f6019 25
sgmcb 41:f603d76dc6fe 26 //----
sgmcb 41:f603d76dc6fe 27 // DEBUG DEFINITIONS
sgmcb 48:3512b3c7a5ae 28 //#define THROWAWAY
sgmcb 47:d9180474fa1e 29 //#define MDMDEBUG
sgmcb 45:0d8cb417a9e2 30 #define LOCDEBUG
sgmcb 37:71ab32b61dfb 31
sgmcb 38:d86e744166b6 32 //------------------------------------------------------------------------------------
sgmcb 38:d86e744166b6 33 // Cellular modem/SIM parameters
sgmcb 38:d86e744166b6 34 #define SIMPIN "1111" //!SIMPIN is 1111 by default for AT&T SIMs.
sgmcb 38:d86e744166b6 35 #define APN "m2m.com.attz" // Defined AT&T M2M APN
sgmcb 38:d86e744166b6 36 #define USERNAME NULL //! Set the user name for your APN, or NULL if not needed (which, apparently, it isn't)
sgmcb 38:d86e744166b6 37 #define PASSWORD NULL //! Set the password for your APN, or NULL if not needed (which, apparently, it isn't)
sgmcb 38:d86e744166b6 38
sgmcb 38:d86e744166b6 39 //------------------------------------------------------------------------------------
sgmcb 38:d86e744166b6 40 // AT&T M2X Kekys
sgmcb 38:d86e744166b6 41
sgmcb 41:f603d76dc6fe 42
sgmcb 41:f603d76dc6fe 43 #ifdef THROWAWAY
sgmcb 41:f603d76dc6fe 44 // Codes for a throwaway M2X device
sgmcb 50:bba466f093a4 45 #define M2XAPIKEY "97f6f92f72b9dd1c66e9b81b982bc3ec"
sgmcb 50:bba466f093a4 46 #define DEVID "743fe2502be9d4d0c550ffa9340998a3"
sgmcb 41:f603d76dc6fe 47 #endif
sgmcb 41:f603d76dc6fe 48
sgmcb 41:f603d76dc6fe 49 #ifndef THROWAWAY
sgmcb 48:3512b3c7a5ae 50 // v1.4 codes
sgmcb 48:3512b3c7a5ae 51 #define M2XAPIKEY "537d09e921aa6589523e10aecde17a44"
sgmcb 48:3512b3c7a5ae 52 #define DEVID "59a85c486aaf8dd427945320f4f779eb"
sgmcb 41:f603d76dc6fe 53 #endif
sgmcb 41:f603d76dc6fe 54
sgmcb 38:d86e744166b6 55
sgmcb 38:d86e744166b6 56 //------------------------------------------------------------------------------------
sgmcb 39:c14aff678b25 57 // PIN Config
sgmcb 41:f603d76dc6fe 58 DigitalOut led1(LED1);
sgmcb 41:f603d76dc6fe 59 DigitalOut led2(LED2);
sgmcb 39:c14aff678b25 60
sgmcb 51:61a1ec3c56fc 61 AnalogIn tempPin(P0_23); // Label A0 -- Temperature
sgmcb 51:61a1ec3c56fc 62 AnalogIn fsrPin(P0_24); // Label A1 -- FSR output voltage
sgmcb 49:a8c40c816199 63 //AnalogIn tempGnd(P0_24);
sgmcb 38:d86e744166b6 64
sgmcb 52:ba2017c3ef8d 65 // Accelerometer
sgmcb 53:3a99061b392f 66 //I2C axis(P0_0, P0_1); // SDA, SCL
sgmcb 52:ba2017c3ef8d 67 //MODI2C axisMod(P0_0, P0_1); // Using MODI2C library
sgmcb 52:ba2017c3ef8d 68
sgmcb 44:bd259a4c83bb 69 //LIS331 axle(P0_0, P0_1); // Library object
sgmcb 38:d86e744166b6 70
sgmcb 38:d86e744166b6 71
sgmcb 51:61a1ec3c56fc 72 /* POWER CONFIG
sgmcb 52:ba2017c3ef8d 73 5V: To thermistor system, to FSR opamp
sgmcb 52:ba2017c3ef8d 74 3.3V: To FSR input voltage, to LIS331 accelerometer
sgmcb 51:61a1ec3c56fc 75
sgmcb 51:61a1ec3c56fc 76 */
sgmcb 51:61a1ec3c56fc 77
sgmcb 42:8e6e647cb7d5 78 //------------------------------------------------------------------------------------
sgmcb 42:8e6e647cb7d5 79 // GLOBAL VARIABLES
sgmcb 38:d86e744166b6 80
sgmcb 41:f603d76dc6fe 81 Ticker flipper;
sgmcb 38:d86e744166b6 82
sgmcb 42:8e6e647cb7d5 83 // M2X Drivers
sgmcb 38:d86e744166b6 84 Client client;
sgmcb 38:d86e744166b6 85 M2XStreamClient m2xClient(&client, M2XAPIKEY);
sgmcb 40:82b70b92169e 86 int M2X_response; // For m2x message responses
sgmcb 38:d86e744166b6 87
sgmcb 42:8e6e647cb7d5 88
sgmcb 40:82b70b92169e 89 char statusBuf[145] = "";
sgmcb 40:82b70b92169e 90
sgmcb 42:8e6e647cb7d5 91 // Location reading
sgmcb 48:3512b3c7a5ae 92 unsigned int kLocLoopDelayDef = 30 * 1000; // The default loop waiting time for location reads
sgmcb 48:3512b3c7a5ae 93 unsigned int kLocLoopDelay = kLocLoopDelayDef;
sgmcb 47:d9180474fa1e 94
sgmcb 47:d9180474fa1e 95
sgmcb 40:82b70b92169e 96 unsigned int kReadingDelay = 3 * 60 * 1000; // How many seconds to wait between reads
sgmcb 39:c14aff678b25 97 unsigned int kReadingDelayClimb = 15000; // How many seconds to add to the wait period when sitting idle
sgmcb 39:c14aff678b25 98 unsigned int kReadingDelayMax = 5 * 60000; // What's the maximum time between readings?
sgmcb 38:d86e744166b6 99
sgmcb 39:c14aff678b25 100
sgmcb 42:8e6e647cb7d5 101 // System time
sgmcb 41:f603d76dc6fe 102 time_t kSysSeconds = time(NULL);
sgmcb 47:d9180474fa1e 103 time_t thisTime = time(NULL);
sgmcb 41:f603d76dc6fe 104 bool kSysClockSet = false;
sgmcb 41:f603d76dc6fe 105 tm kFormatTime;
sgmcb 39:c14aff678b25 106
sgmcb 39:c14aff678b25 107
sgmcb 47:d9180474fa1e 108
sgmcb 42:8e6e647cb7d5 109 // Global function definitions
sgmcb 38:d86e744166b6 110
sgmcb 41:f603d76dc6fe 111 void flip() {
sgmcb 41:f603d76dc6fe 112 led1 = !led1;
sgmcb 41:f603d76dc6fe 113 }
sgmcb 41:f603d76dc6fe 114
sgmcb 38:d86e744166b6 115
sgmcb 38:d86e744166b6 116 //------------------------------------------------------------------------------------
sgmcb 38:d86e744166b6 117 //------------------------------------------------------------------------------------
sgmcb 38:d86e744166b6 118 //------------------------------------------------------------------------------------
sgmcb 38:d86e744166b6 119 int main(void)
sgmcb 38:d86e744166b6 120 {
sgmcb 38:d86e744166b6 121
sgmcb 52:ba2017c3ef8d 122 printf("\r\n\n\n\n-----\r\nI'm alive - vers. uAXIS - accelerometer testing\r\n\n");
sgmcb 49:a8c40c816199 123
sgmcb 50:bba466f093a4 124 // POWER MANAGEMENT
sgmcb 52:ba2017c3ef8d 125 printf("\nShut down ethernet interface.\r\n");
sgmcb 50:bba466f093a4 126 PHY_PowerDown(); // Turn off the ethernet interface; -175mW
sgmcb 50:bba466f093a4 127
sgmcb 51:61a1ec3c56fc 128 C027 thisBoard;
sgmcb 52:ba2017c3ef8d 129 printf("Disable GPS power supply.\r\n\n");
sgmcb 51:61a1ec3c56fc 130 thisBoard.gpsPower(false); // Turn off the GPS power supply
sgmcb 50:bba466f093a4 131
sgmcb 52:ba2017c3ef8d 132
sgmcb 41:f603d76dc6fe 133
sgmcb 52:ba2017c3ef8d 134
sgmcb 52:ba2017c3ef8d 135 /*
sgmcb 38:d86e744166b6 136 MDMSerial mdm;
sgmcb 39:c14aff678b25 137 MDMParser::DevStatus devStatus = {};
sgmcb 44:bd259a4c83bb 138 MDMParser::NetStatus netStatus = {};
sgmcb 39:c14aff678b25 139 bool mdmOk = mdm.init(SIMPIN, &devStatus);
sgmcb 46:ab4cccab10c9 140
sgmcb 41:f603d76dc6fe 141 #ifdef MDMDEBUG
sgmcb 46:ab4cccab10c9 142 mdm.setDebug(4);
sgmcb 41:f603d76dc6fe 143 #endif
sgmcb 41:f603d76dc6fe 144
sgmcb 43:80aa0c933e1a 145 // ----------------
sgmcb 42:8e6e647cb7d5 146 // LOCATION READING
sgmcb 39:c14aff678b25 147
sgmcb 38:d86e744166b6 148
sgmcb 44:bd259a4c83bb 149 // OPEN MODEM CONNECTION
sgmcb 38:d86e744166b6 150 if (!mdm.connect(SIMPIN, APN,USERNAME,PASSWORD))
sgmcb 44:bd259a4c83bb 151 return -1;
sgmcb 44:bd259a4c83bb 152
sgmcb 44:bd259a4c83bb 153 // SET DEEP SCAN MODE
sgmcb 44:bd259a4c83bb 154 printf("Configure deep scan mode\r\n");
sgmcb 44:bd259a4c83bb 155 int locConf = mdm.cellLocConfigSensor(1);
sgmcb 44:bd259a4c83bb 156
sgmcb 38:d86e744166b6 157
sgmcb 40:82b70b92169e 158 // Cell location data
sgmcb 49:a8c40c816199 159 MDMSerial::CellLocData thisLoc;
sgmcb 44:bd259a4c83bb 160
sgmcb 52:ba2017c3ef8d 161 */
sgmcb 52:ba2017c3ef8d 162
sgmcb 48:3512b3c7a5ae 163 // Location loop driving variables
sgmcb 45:0d8cb417a9e2 164 int loopIter = 0;
sgmcb 48:3512b3c7a5ae 165 bool sendStatus = false;
sgmcb 45:0d8cb417a9e2 166
sgmcb 45:0d8cb417a9e2 167 // Loop timing variables
sgmcb 45:0d8cb417a9e2 168 Timer cellLocDelay;
sgmcb 45:0d8cb417a9e2 169
sgmcb 45:0d8cb417a9e2 170 int cellLocPeriod = 30; // in seconds
sgmcb 45:0d8cb417a9e2 171 int timeoutMargin = 5; // in seconds
sgmcb 45:0d8cb417a9e2 172
sgmcb 45:0d8cb417a9e2 173
sgmcb 45:0d8cb417a9e2 174 // Location data filter variables
sgmcb 40:82b70b92169e 175 int locAccLower = 50; // Immediately accept locations with uncertainty lower than this
sgmcb 40:82b70b92169e 176 int locAccUpper = 5000; // Don't accept locations with uncertainty greater than this
sgmcb 46:ab4cccab10c9 177
sgmcb 46:ab4cccab10c9 178 // Filter counters
sgmcb 47:d9180474fa1e 179 int fail1count = 0;
sgmcb 47:d9180474fa1e 180 int fail2count = 0;
sgmcb 47:d9180474fa1e 181 int fail3count = 0;
sgmcb 41:f603d76dc6fe 182
sgmcb 41:f603d76dc6fe 183
sgmcb 45:0d8cb417a9e2 184 // Cell location call variables
sgmcb 45:0d8cb417a9e2 185 const int sensorMask = 2; // 1 = GNSS, 2 = CellLocate (aka cell grid position info), 3 = Hybrid: GNSS + CellLocate
sgmcb 45:0d8cb417a9e2 186 int cellLocReqTimeout = cellLocPeriod - timeoutMargin; // in seconds
sgmcb 45:0d8cb417a9e2 187 const int targetAccuracy = 1; // in meters
sgmcb 52:ba2017c3ef8d 188
sgmcb 53:3a99061b392f 189 I2C axis(P0_0, P0_1);
sgmcb 53:3a99061b392f 190 delay(5000);
sgmcb 45:0d8cb417a9e2 191
sgmcb 42:8e6e647cb7d5 192 // -----------------------
sgmcb 40:82b70b92169e 193 // Location reporting loop
sgmcb 40:82b70b92169e 194 while(true) {
sgmcb 40:82b70b92169e 195
sgmcb 44:bd259a4c83bb 196 // Set some important variables
sgmcb 41:f603d76dc6fe 197 M2X_response = 0;
sgmcb 48:3512b3c7a5ae 198 sendStatus = 0;
sgmcb 40:82b70b92169e 199 loopIter++;
sgmcb 40:82b70b92169e 200
sgmcb 45:0d8cb417a9e2 201 //printf("tick\r\n");
sgmcb 45:0d8cb417a9e2 202
sgmcb 52:ba2017c3ef8d 203
sgmcb 52:ba2017c3ef8d 204
sgmcb 52:ba2017c3ef8d 205 // Let's play with the accelerometer (STM LIS331)
sgmcb 52:ba2017c3ef8d 206
sgmcb 52:ba2017c3ef8d 207 printf("LIS331 experiments\r\n\n");
sgmcb 52:ba2017c3ef8d 208
sgmcb 53:3a99061b392f 209 axis.frequency(400000); // in Hz
sgmcb 52:ba2017c3ef8d 210
sgmcb 52:ba2017c3ef8d 211 int whowho;
sgmcb 52:ba2017c3ef8d 212 int I2Cret;
sgmcb 52:ba2017c3ef8d 213
sgmcb 53:3a99061b392f 214 int axWrite = 0x3A;
sgmcb 53:3a99061b392f 215 int axRead = 0x3B;
sgmcb 53:3a99061b392f 216
sgmcb 53:3a99061b392f 217 int axConf1 = 0x20;
sgmcb 53:3a99061b392f 218 int axWho = 0x0f;
sgmcb 53:3a99061b392f 219
sgmcb 53:3a99061b392f 220
sgmcb 53:3a99061b392f 221 printf("T-minus 1 second...\r\n");
sgmcb 53:3a99061b392f 222 delay(1000);
sgmcb 53:3a99061b392f 223
sgmcb 52:ba2017c3ef8d 224 // RAW WHOAMI
sgmcb 52:ba2017c3ef8d 225
sgmcb 52:ba2017c3ef8d 226 axis.start();
sgmcb 53:3a99061b392f 227 if(axis.write(axWrite))
sgmcb 53:3a99061b392f 228 printf("Write ACK\r\n");
sgmcb 53:3a99061b392f 229 axis.write(axWho);
sgmcb 52:ba2017c3ef8d 230 axis.start();
sgmcb 53:3a99061b392f 231 if(axis.write(axRead))
sgmcb 53:3a99061b392f 232 printf("Write ACK\r\n");
sgmcb 52:ba2017c3ef8d 233 whowho = axis.read(1);
sgmcb 52:ba2017c3ef8d 234 axis.stop();
sgmcb 52:ba2017c3ef8d 235 printf("raw WhoAmI = 0x%02x\r\n\n", whowho);
sgmcb 52:ba2017c3ef8d 236
sgmcb 52:ba2017c3ef8d 237 // RAW config1 set
sgmcb 52:ba2017c3ef8d 238 printf("Set CONFIG1 to 0xC7\r\n");
sgmcb 52:ba2017c3ef8d 239 axis.start();
sgmcb 53:3a99061b392f 240 if(axis.write(axWrite))
sgmcb 53:3a99061b392f 241 printf("Write ACK\r\n");
sgmcb 53:3a99061b392f 242 if(axis.write(axConf1))
sgmcb 53:3a99061b392f 243 printf("Write ACK\r\n");
sgmcb 52:ba2017c3ef8d 244 axis.write(0xC7);
sgmcb 52:ba2017c3ef8d 245 axis.stop();
sgmcb 52:ba2017c3ef8d 246
sgmcb 52:ba2017c3ef8d 247
sgmcb 52:ba2017c3ef8d 248 // RAW config1 read
sgmcb 52:ba2017c3ef8d 249 axis.start();
sgmcb 53:3a99061b392f 250 if(axis.write(axWrite))
sgmcb 53:3a99061b392f 251 printf("Write ACK\r\n");
sgmcb 53:3a99061b392f 252 axis.write(axConf1);
sgmcb 52:ba2017c3ef8d 253 axis.start();
sgmcb 53:3a99061b392f 254 if(axis.write(axRead))
sgmcb 53:3a99061b392f 255 printf("Write ACK\r\n");
sgmcb 52:ba2017c3ef8d 256 I2Cret = axis.read(1);
sgmcb 52:ba2017c3ef8d 257 axis.stop();
sgmcb 52:ba2017c3ef8d 258 printf("raw config1 = 0x%02x\r\n", I2Cret);
sgmcb 52:ba2017c3ef8d 259
sgmcb 52:ba2017c3ef8d 260
sgmcb 52:ba2017c3ef8d 261
sgmcb 52:ba2017c3ef8d 262 // RAW WHOAMI
sgmcb 52:ba2017c3ef8d 263 axis.start();
sgmcb 53:3a99061b392f 264 if(axis.write(axWrite))
sgmcb 53:3a99061b392f 265 printf("Write ACK\r\n");
sgmcb 53:3a99061b392f 266 axis.write(axWho);
sgmcb 52:ba2017c3ef8d 267 axis.start();
sgmcb 53:3a99061b392f 268 if(axis.write(axRead))
sgmcb 53:3a99061b392f 269 printf("Write ACK\r\n");
sgmcb 52:ba2017c3ef8d 270 whowho = axis.read(1);
sgmcb 52:ba2017c3ef8d 271 axis.stop();
sgmcb 53:3a99061b392f 272 printf("post-CONFIG1 raw WhoAmI = 0x%02x\r\n", whowho);
sgmcb 52:ba2017c3ef8d 273
sgmcb 53:3a99061b392f 274
sgmcb 52:ba2017c3ef8d 275 // RAW config1 read
sgmcb 52:ba2017c3ef8d 276 axis.start();
sgmcb 53:3a99061b392f 277 if(axis.write(axWrite))
sgmcb 53:3a99061b392f 278 printf("Write ACK\r\n");
sgmcb 53:3a99061b392f 279 axis.write(axConf1);
sgmcb 52:ba2017c3ef8d 280 axis.start();
sgmcb 53:3a99061b392f 281 if(axis.write(axRead))
sgmcb 53:3a99061b392f 282 printf("Write ACK\r\n");
sgmcb 52:ba2017c3ef8d 283 I2Cret = axis.read(1);
sgmcb 52:ba2017c3ef8d 284 axis.stop();
sgmcb 53:3a99061b392f 285 printf("raw config1 = 0x%02x\r\n", I2Cret);
sgmcb 52:ba2017c3ef8d 286
sgmcb 52:ba2017c3ef8d 287 printf("-- LOOP END --\r\n\n");
sgmcb 52:ba2017c3ef8d 288
sgmcb 53:3a99061b392f 289 break;
sgmcb 52:ba2017c3ef8d 290
sgmcb 40:82b70b92169e 291 }
sgmcb 38:d86e744166b6 292
sgmcb 39:c14aff678b25 293
sgmcb 40:82b70b92169e 294 //mdm.disconnect();
sgmcb 40:82b70b92169e 295 //mdm.powerOff();
msinig 35:16f1037626e3 296
lawliet 0:4e3cb26f6019 297 }