Mobile Life IoT project using the AT&T IoT Starter Kit Software and files for my device to monitor the status or our Airstream travel trailer RV. A full description of the project is at Hackster.IO here as part of the Realtime AT&T IoT Starter Kit Challenge: https://www.hackster.io/Anubus/mobile-life-iot-9c10be

Dependencies:   FXOS8700CQ MODSERIAL mbed

Committer:
Anubus
Date:
Sun Apr 02 12:28:21 2017 +0000
Revision:
0:bd276b1f1249
public version commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Anubus 0:bd276b1f1249 1 /* ===================================================================
Anubus 0:bd276b1f1249 2 Copyright © 2016, AVNET Inc.
Anubus 0:bd276b1f1249 3
Anubus 0:bd276b1f1249 4 Licensed under the Apache License, Version 2.0 (the "License");
Anubus 0:bd276b1f1249 5 you may not use this file except in compliance with the License.
Anubus 0:bd276b1f1249 6 You may obtain a copy of the License at
Anubus 0:bd276b1f1249 7
Anubus 0:bd276b1f1249 8 http://www.apache.org/licenses/LICENSE-2.0
Anubus 0:bd276b1f1249 9
Anubus 0:bd276b1f1249 10 Unless required by applicable law or agreed to in writing,
Anubus 0:bd276b1f1249 11 software distributed under the License is distributed on an
Anubus 0:bd276b1f1249 12 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
Anubus 0:bd276b1f1249 13 either express or implied. See the License for the specific
Anubus 0:bd276b1f1249 14 language governing permissions and limitations under the License.
Anubus 0:bd276b1f1249 15
Anubus 0:bd276b1f1249 16 ======================================================================== */
Anubus 0:bd276b1f1249 17
Anubus 0:bd276b1f1249 18 #include "mbed.h"
Anubus 0:bd276b1f1249 19 #include "xadow_gps.h"
Anubus 0:bd276b1f1249 20 #include "hardware.h"
Anubus 0:bd276b1f1249 21
Anubus 0:bd276b1f1249 22 // Xadow code based on Eclipse test project at
Anubus 0:bd276b1f1249 23 // https://github.com/WayenWeng/Xadow_GPS_v2_test/
Anubus 0:bd276b1f1249 24
Anubus 0:bd276b1f1249 25 // These first 3 routines are to allow the mbed I2C to be used instead of what was in the Eclipse test code
Anubus 0:bd276b1f1249 26 void dlc_i2c_configure(int slave_addr, int speed)
Anubus 0:bd276b1f1249 27 {
Anubus 0:bd276b1f1249 28 } //dlc_i2c_configure
Anubus 0:bd276b1f1249 29
Anubus 0:bd276b1f1249 30 unsigned char dlc_i2c_receive_byte(void)
Anubus 0:bd276b1f1249 31 {
Anubus 0:bd276b1f1249 32 char rxbuffer [1];
Anubus 0:bd276b1f1249 33 i2c.read(GPS_DEVICE_ADDR, rxbuffer, 1 );
Anubus 0:bd276b1f1249 34 return (unsigned char)rxbuffer[0];
Anubus 0:bd276b1f1249 35 } //dlc_i2c_receive_byte()
Anubus 0:bd276b1f1249 36
Anubus 0:bd276b1f1249 37 unsigned char dlc_i2c_send_byte(unsigned char ucData)
Anubus 0:bd276b1f1249 38 {
Anubus 0:bd276b1f1249 39 int status;
Anubus 0:bd276b1f1249 40 char txbuffer [1];
Anubus 0:bd276b1f1249 41 txbuffer[0] = (char)ucData;
Anubus 0:bd276b1f1249 42 status = i2c.write(GPS_DEVICE_ADDR, txbuffer, 1, false); //true: do not send stop
Anubus 0:bd276b1f1249 43 return status;
Anubus 0:bd276b1f1249 44 } //dlc_i2c_send_byte()
Anubus 0:bd276b1f1249 45
Anubus 0:bd276b1f1249 46
Anubus 0:bd276b1f1249 47 unsigned char gps_check_online(void)
Anubus 0:bd276b1f1249 48 {
Anubus 0:bd276b1f1249 49 unsigned char data[GPS_SCAN_SIZE+2];
Anubus 0:bd276b1f1249 50 unsigned char i;
Anubus 0:bd276b1f1249 51
Anubus 0:bd276b1f1249 52 dlc_i2c_configure(GPS_DEVICE_ADDR, 100);
Anubus 0:bd276b1f1249 53
Anubus 0:bd276b1f1249 54 dlc_i2c_send_byte(GPS_SCAN_ID);
Anubus 0:bd276b1f1249 55
Anubus 0:bd276b1f1249 56 for(i=0;i<(GPS_SCAN_SIZE+2);i++)
Anubus 0:bd276b1f1249 57 {
Anubus 0:bd276b1f1249 58 data[i] = dlc_i2c_receive_byte();
Anubus 0:bd276b1f1249 59 }
Anubus 0:bd276b1f1249 60
Anubus 0:bd276b1f1249 61 if(data[5] == GPS_DEVICE_ID)
Anubus 0:bd276b1f1249 62 return 1;
Anubus 0:bd276b1f1249 63 else return 0;
Anubus 0:bd276b1f1249 64 }
Anubus 0:bd276b1f1249 65
Anubus 0:bd276b1f1249 66 unsigned char gps_utc_date_time[GPS_UTC_DATE_TIME_SIZE] = {0};
Anubus 0:bd276b1f1249 67
Anubus 0:bd276b1f1249 68 unsigned char* gps_get_utc_date_time(void)
Anubus 0:bd276b1f1249 69 {
Anubus 0:bd276b1f1249 70 unsigned char data[GPS_UTC_DATE_TIME_SIZE+2];
Anubus 0:bd276b1f1249 71 unsigned char i;
Anubus 0:bd276b1f1249 72
Anubus 0:bd276b1f1249 73 dlc_i2c_configure(GPS_DEVICE_ADDR, 100);
Anubus 0:bd276b1f1249 74
Anubus 0:bd276b1f1249 75 dlc_i2c_send_byte(GPS_UTC_DATE_TIME_ID);
Anubus 0:bd276b1f1249 76
Anubus 0:bd276b1f1249 77 for(i=0;i<(GPS_UTC_DATE_TIME_SIZE+2);i++)
Anubus 0:bd276b1f1249 78 {
Anubus 0:bd276b1f1249 79 data[i] = dlc_i2c_receive_byte();
Anubus 0:bd276b1f1249 80 }
Anubus 0:bd276b1f1249 81
Anubus 0:bd276b1f1249 82 for(i=0;i<GPS_UTC_DATE_TIME_SIZE;i++)
Anubus 0:bd276b1f1249 83 gps_utc_date_time[i] = data[i+2];
Anubus 0:bd276b1f1249 84
Anubus 0:bd276b1f1249 85 return gps_utc_date_time;
Anubus 0:bd276b1f1249 86 }
Anubus 0:bd276b1f1249 87
Anubus 0:bd276b1f1249 88 unsigned char gps_get_status(void)
Anubus 0:bd276b1f1249 89 {
Anubus 0:bd276b1f1249 90 unsigned char data[GPS_STATUS_SIZE+2];
Anubus 0:bd276b1f1249 91 unsigned char i;
Anubus 0:bd276b1f1249 92
Anubus 0:bd276b1f1249 93 dlc_i2c_configure(GPS_DEVICE_ADDR, 100);
Anubus 0:bd276b1f1249 94
Anubus 0:bd276b1f1249 95 dlc_i2c_send_byte(GPS_STATUS_ID);
Anubus 0:bd276b1f1249 96 for(i=0;i<(GPS_STATUS_SIZE+2);i++)
Anubus 0:bd276b1f1249 97 {
Anubus 0:bd276b1f1249 98 data[i] = dlc_i2c_receive_byte();
Anubus 0:bd276b1f1249 99 }
Anubus 0:bd276b1f1249 100
Anubus 0:bd276b1f1249 101 return data[2];
Anubus 0:bd276b1f1249 102 }
Anubus 0:bd276b1f1249 103
Anubus 0:bd276b1f1249 104 float gps_get_latitude(void)
Anubus 0:bd276b1f1249 105 {
Anubus 0:bd276b1f1249 106 char data[GPS_LATITUDE_SIZE+2];
Anubus 0:bd276b1f1249 107 unsigned char i;
Anubus 0:bd276b1f1249 108
Anubus 0:bd276b1f1249 109 dlc_i2c_configure(GPS_DEVICE_ADDR, 100);
Anubus 0:bd276b1f1249 110
Anubus 0:bd276b1f1249 111 dlc_i2c_send_byte(GPS_LATITUDE_ID);
Anubus 0:bd276b1f1249 112 for(i=0;i<(GPS_LATITUDE_SIZE+2);i++)
Anubus 0:bd276b1f1249 113 {
Anubus 0:bd276b1f1249 114 data[i] = (char)dlc_i2c_receive_byte();
Anubus 0:bd276b1f1249 115 }
Anubus 0:bd276b1f1249 116
Anubus 0:bd276b1f1249 117 return atof(&data[2]);
Anubus 0:bd276b1f1249 118 }
Anubus 0:bd276b1f1249 119
Anubus 0:bd276b1f1249 120 unsigned char gps_get_ns(void)
Anubus 0:bd276b1f1249 121 {
Anubus 0:bd276b1f1249 122 unsigned char data[GPS_NS_SIZE+2];
Anubus 0:bd276b1f1249 123 unsigned char i;
Anubus 0:bd276b1f1249 124
Anubus 0:bd276b1f1249 125 dlc_i2c_configure(GPS_DEVICE_ADDR, 100);
Anubus 0:bd276b1f1249 126
Anubus 0:bd276b1f1249 127 dlc_i2c_send_byte(GPS_NS_ID);
Anubus 0:bd276b1f1249 128 for(i=0;i<(GPS_NS_SIZE+2);i++)
Anubus 0:bd276b1f1249 129 {
Anubus 0:bd276b1f1249 130 data[i] = dlc_i2c_receive_byte();
Anubus 0:bd276b1f1249 131 }
Anubus 0:bd276b1f1249 132
Anubus 0:bd276b1f1249 133 if(data[2] == 'N' || data[2] == 'S')return data[2];
Anubus 0:bd276b1f1249 134 else return data[2] = '-';
Anubus 0:bd276b1f1249 135
Anubus 0:bd276b1f1249 136 }
Anubus 0:bd276b1f1249 137
Anubus 0:bd276b1f1249 138 float gps_get_longitude(void)
Anubus 0:bd276b1f1249 139 {
Anubus 0:bd276b1f1249 140 char data[GPS_LONGITUDE_SIZE+2];
Anubus 0:bd276b1f1249 141 unsigned char i;
Anubus 0:bd276b1f1249 142
Anubus 0:bd276b1f1249 143 dlc_i2c_configure(GPS_DEVICE_ADDR, 100);
Anubus 0:bd276b1f1249 144
Anubus 0:bd276b1f1249 145 dlc_i2c_send_byte(GPS_LONGITUDE_ID);
Anubus 0:bd276b1f1249 146 for(i=0;i<(GPS_LONGITUDE_SIZE+2);i++)
Anubus 0:bd276b1f1249 147 {
Anubus 0:bd276b1f1249 148 data[i] = (char)dlc_i2c_receive_byte();
Anubus 0:bd276b1f1249 149 }
Anubus 0:bd276b1f1249 150
Anubus 0:bd276b1f1249 151 return atof(&data[2]);
Anubus 0:bd276b1f1249 152 }
Anubus 0:bd276b1f1249 153
Anubus 0:bd276b1f1249 154 unsigned char gps_get_ew(void)
Anubus 0:bd276b1f1249 155 {
Anubus 0:bd276b1f1249 156 unsigned char data[GPS_EW_SIZE+2];
Anubus 0:bd276b1f1249 157 unsigned char i;
Anubus 0:bd276b1f1249 158
Anubus 0:bd276b1f1249 159 dlc_i2c_configure(GPS_DEVICE_ADDR, 100);
Anubus 0:bd276b1f1249 160
Anubus 0:bd276b1f1249 161 dlc_i2c_send_byte(GPS_EW_ID);
Anubus 0:bd276b1f1249 162 for(i=0;i<(GPS_EW_SIZE+2);i++)
Anubus 0:bd276b1f1249 163 {
Anubus 0:bd276b1f1249 164 data[i] = dlc_i2c_receive_byte();
Anubus 0:bd276b1f1249 165 }
Anubus 0:bd276b1f1249 166
Anubus 0:bd276b1f1249 167 if(data[2] == 'E' || data[2] == 'W')return data[2];
Anubus 0:bd276b1f1249 168 else return data[2] = '-';
Anubus 0:bd276b1f1249 169 }
Anubus 0:bd276b1f1249 170
Anubus 0:bd276b1f1249 171 float gps_get_speed(void)
Anubus 0:bd276b1f1249 172 {
Anubus 0:bd276b1f1249 173 char data[GPS_SPEED_SIZE+2];
Anubus 0:bd276b1f1249 174 unsigned char i;
Anubus 0:bd276b1f1249 175
Anubus 0:bd276b1f1249 176 dlc_i2c_configure(GPS_DEVICE_ADDR, 100);
Anubus 0:bd276b1f1249 177
Anubus 0:bd276b1f1249 178 dlc_i2c_send_byte(GPS_SPEED_ID);
Anubus 0:bd276b1f1249 179 for(i=0;i<(GPS_SPEED_SIZE+2);i++)
Anubus 0:bd276b1f1249 180 {
Anubus 0:bd276b1f1249 181 data[i] = (char)dlc_i2c_receive_byte();
Anubus 0:bd276b1f1249 182 }
Anubus 0:bd276b1f1249 183
Anubus 0:bd276b1f1249 184 return atof(&data[2]);
Anubus 0:bd276b1f1249 185 }
Anubus 0:bd276b1f1249 186
Anubus 0:bd276b1f1249 187 float gps_get_course(void)
Anubus 0:bd276b1f1249 188 {
Anubus 0:bd276b1f1249 189 char data[GPS_COURSE_SIZE+2];
Anubus 0:bd276b1f1249 190 unsigned char i;
Anubus 0:bd276b1f1249 191
Anubus 0:bd276b1f1249 192 dlc_i2c_configure(GPS_DEVICE_ADDR, 100);
Anubus 0:bd276b1f1249 193
Anubus 0:bd276b1f1249 194 dlc_i2c_send_byte(GPS_COURSE_ID);
Anubus 0:bd276b1f1249 195 for(i=0;i<(GPS_COURSE_SIZE+2);i++)
Anubus 0:bd276b1f1249 196 {
Anubus 0:bd276b1f1249 197 data[i] = (char)dlc_i2c_receive_byte();
Anubus 0:bd276b1f1249 198 }
Anubus 0:bd276b1f1249 199
Anubus 0:bd276b1f1249 200 return atof(&data[2]);
Anubus 0:bd276b1f1249 201 }
Anubus 0:bd276b1f1249 202
Anubus 0:bd276b1f1249 203 unsigned char gps_get_position_fix(void)
Anubus 0:bd276b1f1249 204 {
Anubus 0:bd276b1f1249 205 unsigned char data[GPS_POSITION_FIX_SIZE+2];
Anubus 0:bd276b1f1249 206 unsigned char i;
Anubus 0:bd276b1f1249 207
Anubus 0:bd276b1f1249 208 dlc_i2c_configure(GPS_DEVICE_ADDR, 100);
Anubus 0:bd276b1f1249 209
Anubus 0:bd276b1f1249 210 dlc_i2c_send_byte(GPS_POSITION_FIX_ID);
Anubus 0:bd276b1f1249 211 for(i=0;i<(GPS_POSITION_FIX_SIZE+2);i++)
Anubus 0:bd276b1f1249 212 {
Anubus 0:bd276b1f1249 213 data[i] = dlc_i2c_receive_byte();
Anubus 0:bd276b1f1249 214 }
Anubus 0:bd276b1f1249 215
Anubus 0:bd276b1f1249 216 return data[2];
Anubus 0:bd276b1f1249 217 }
Anubus 0:bd276b1f1249 218
Anubus 0:bd276b1f1249 219 unsigned char gps_get_sate_used(void)
Anubus 0:bd276b1f1249 220 {
Anubus 0:bd276b1f1249 221 unsigned char data[GPS_SATE_USED_SIZE+2];
Anubus 0:bd276b1f1249 222 unsigned char i;
Anubus 0:bd276b1f1249 223 unsigned char value;
Anubus 0:bd276b1f1249 224
Anubus 0:bd276b1f1249 225 dlc_i2c_configure(GPS_DEVICE_ADDR, 100);
Anubus 0:bd276b1f1249 226
Anubus 0:bd276b1f1249 227 dlc_i2c_send_byte(GPS_SATE_USED_ID);
Anubus 0:bd276b1f1249 228 for(i=0;i<(GPS_SATE_USED_SIZE+2);i++)
Anubus 0:bd276b1f1249 229 {
Anubus 0:bd276b1f1249 230 data[i] = dlc_i2c_receive_byte();
Anubus 0:bd276b1f1249 231 }
Anubus 0:bd276b1f1249 232
Anubus 0:bd276b1f1249 233 if(data[3] >= '0' && data[3] <= '9')value = (data[3] - '0') * 10;
Anubus 0:bd276b1f1249 234 else value = 0;
Anubus 0:bd276b1f1249 235 if(data[2] >= '0' && data[2] <= '9')value += (data[2] - '0');
Anubus 0:bd276b1f1249 236 else value += 0;
Anubus 0:bd276b1f1249 237
Anubus 0:bd276b1f1249 238 return value;
Anubus 0:bd276b1f1249 239 }
Anubus 0:bd276b1f1249 240
Anubus 0:bd276b1f1249 241 float gps_get_altitude(void)
Anubus 0:bd276b1f1249 242 {
Anubus 0:bd276b1f1249 243 char data[GPS_ALTITUDE_SIZE+2];
Anubus 0:bd276b1f1249 244 unsigned char i;
Anubus 0:bd276b1f1249 245
Anubus 0:bd276b1f1249 246 dlc_i2c_configure(GPS_DEVICE_ADDR, 100);
Anubus 0:bd276b1f1249 247
Anubus 0:bd276b1f1249 248 dlc_i2c_send_byte(GPS_ALTITUDE_ID);
Anubus 0:bd276b1f1249 249 for(i=0;i<(GPS_ALTITUDE_SIZE+2);i++)
Anubus 0:bd276b1f1249 250 {
Anubus 0:bd276b1f1249 251 data[i] = (char)dlc_i2c_receive_byte();
Anubus 0:bd276b1f1249 252 }
Anubus 0:bd276b1f1249 253
Anubus 0:bd276b1f1249 254 return atof(&data[2]);
Anubus 0:bd276b1f1249 255 }
Anubus 0:bd276b1f1249 256
Anubus 0:bd276b1f1249 257 unsigned char gps_get_mode(void)
Anubus 0:bd276b1f1249 258 {
Anubus 0:bd276b1f1249 259 unsigned char data[GPS_MODE_SIZE+2];
Anubus 0:bd276b1f1249 260 unsigned char i;
Anubus 0:bd276b1f1249 261
Anubus 0:bd276b1f1249 262 dlc_i2c_configure(GPS_DEVICE_ADDR, 100);
Anubus 0:bd276b1f1249 263
Anubus 0:bd276b1f1249 264 dlc_i2c_send_byte(GPS_MODE_ID);
Anubus 0:bd276b1f1249 265 for(i=0;i<(GPS_MODE_SIZE+2);i++)
Anubus 0:bd276b1f1249 266 {
Anubus 0:bd276b1f1249 267 data[i] = dlc_i2c_receive_byte();
Anubus 0:bd276b1f1249 268 }
Anubus 0:bd276b1f1249 269
Anubus 0:bd276b1f1249 270 return data[2];
Anubus 0:bd276b1f1249 271 }
Anubus 0:bd276b1f1249 272
Anubus 0:bd276b1f1249 273 unsigned char gps_get_mode2(void)
Anubus 0:bd276b1f1249 274 {
Anubus 0:bd276b1f1249 275 unsigned char data[GPS_MODE2_SIZE+2];
Anubus 0:bd276b1f1249 276 unsigned char i;
Anubus 0:bd276b1f1249 277
Anubus 0:bd276b1f1249 278 dlc_i2c_configure(GPS_DEVICE_ADDR, 100);
Anubus 0:bd276b1f1249 279
Anubus 0:bd276b1f1249 280 dlc_i2c_send_byte(GPS_MODE2_ID);
Anubus 0:bd276b1f1249 281 for(i=0;i<(GPS_MODE2_SIZE+2);i++)
Anubus 0:bd276b1f1249 282 {
Anubus 0:bd276b1f1249 283 data[i] = dlc_i2c_receive_byte();
Anubus 0:bd276b1f1249 284 }
Anubus 0:bd276b1f1249 285
Anubus 0:bd276b1f1249 286 return data[2];
Anubus 0:bd276b1f1249 287 }
Anubus 0:bd276b1f1249 288
Anubus 0:bd276b1f1249 289 unsigned char gps_get_sate_in_veiw(void)
Anubus 0:bd276b1f1249 290 {
Anubus 0:bd276b1f1249 291 unsigned char data[GPS_SATE_IN_VIEW_SIZE+2];
Anubus 0:bd276b1f1249 292 unsigned char i;
Anubus 0:bd276b1f1249 293
Anubus 0:bd276b1f1249 294 dlc_i2c_configure(GPS_DEVICE_ADDR, 100);
Anubus 0:bd276b1f1249 295
Anubus 0:bd276b1f1249 296 dlc_i2c_send_byte(GPS_SATE_IN_VIEW_ID);
Anubus 0:bd276b1f1249 297 for(i=0;i<(GPS_SATE_IN_VIEW_SIZE+2);i++)
Anubus 0:bd276b1f1249 298 {
Anubus 0:bd276b1f1249 299 data[i] = dlc_i2c_receive_byte();
Anubus 0:bd276b1f1249 300 }
Anubus 0:bd276b1f1249 301
Anubus 0:bd276b1f1249 302 return data[2];
Anubus 0:bd276b1f1249 303 }