Improved, thread compatible. Adds new features
Fork of GroveGPS by
GroveGPS.cpp@2:073674e3f5bf, 2018-04-19 (annotated)
- Committer:
- JimCarver
- Date:
- Thu Apr 19 17:54:31 2018 +0000
- Revision:
- 2:073674e3f5bf
- Child:
- 4:4615d6e99bb4
Updated to reflect cloud example
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JimCarver | 2:073674e3f5bf | 1 | // ---------------------------------------------------------------------------- |
JimCarver | 2:073674e3f5bf | 2 | // Copyright 2016-2017 ARM Ltd. |
JimCarver | 2:073674e3f5bf | 3 | // |
JimCarver | 2:073674e3f5bf | 4 | // SPDX-License-Identifier: Apache-2.0 |
JimCarver | 2:073674e3f5bf | 5 | // |
JimCarver | 2:073674e3f5bf | 6 | // Licensed under the Apache License, Version 2.0 (the "License"); |
JimCarver | 2:073674e3f5bf | 7 | // you may not use this file except in compliance with the License. |
JimCarver | 2:073674e3f5bf | 8 | // You may obtain a copy of the License at |
JimCarver | 2:073674e3f5bf | 9 | // |
JimCarver | 2:073674e3f5bf | 10 | // http://www.apache.org/licenses/LICENSE-2.0 |
JimCarver | 2:073674e3f5bf | 11 | // |
JimCarver | 2:073674e3f5bf | 12 | // Unless required by applicable law or agreed to in writing, software |
JimCarver | 2:073674e3f5bf | 13 | // distributed under the License is distributed on an "AS IS" BASIS, |
JimCarver | 2:073674e3f5bf | 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
JimCarver | 2:073674e3f5bf | 15 | // See the License for the specific language governing permissions and |
JimCarver | 2:073674e3f5bf | 16 | // limitations under the License. |
JimCarver | 2:073674e3f5bf | 17 | // ---------------------------------------------------------------------------- |
JimCarver | 2:073674e3f5bf | 18 | |
JimCarver | 2:073674e3f5bf | 19 | #include "mbed.h" |
JimCarver | 2:073674e3f5bf | 20 | |
JimCarver | 2:073674e3f5bf | 21 | #include "GroveGPS.h" |
JimCarver | 2:073674e3f5bf | 22 | |
JimCarver | 2:073674e3f5bf | 23 | Serial gps_serial(PE_8, PE_7, 9600); |
JimCarver | 2:073674e3f5bf | 24 | |
JimCarver | 2:073674e3f5bf | 25 | |
JimCarver | 2:073674e3f5bf | 26 | Thread gpsThread; |
JimCarver | 2:073674e3f5bf | 27 | GroveGPS gps; |
JimCarver | 2:073674e3f5bf | 28 | |
JimCarver | 2:073674e3f5bf | 29 | |
JimCarver | 2:073674e3f5bf | 30 | void service_serial(void) { |
JimCarver | 2:073674e3f5bf | 31 | gps.readCharacter(gps_serial.getc()); |
JimCarver | 2:073674e3f5bf | 32 | } |
JimCarver | 2:073674e3f5bf | 33 | |
JimCarver | 2:073674e3f5bf | 34 | |
JimCarver | 2:073674e3f5bf | 35 | int calc_cs(char * str) { |
JimCarver | 2:073674e3f5bf | 36 | char cs = 0; |
JimCarver | 2:073674e3f5bf | 37 | int x = 1; |
JimCarver | 2:073674e3f5bf | 38 | |
JimCarver | 2:073674e3f5bf | 39 | while(str[x] != '*') { |
JimCarver | 2:073674e3f5bf | 40 | cs ^= str[x++]; |
JimCarver | 2:073674e3f5bf | 41 | } |
JimCarver | 2:073674e3f5bf | 42 | return(cs); |
JimCarver | 2:073674e3f5bf | 43 | } |
JimCarver | 2:073674e3f5bf | 44 | |
JimCarver | 2:073674e3f5bf | 45 | void nema_send( void ) { |
JimCarver | 2:073674e3f5bf | 46 | |
JimCarver | 2:073674e3f5bf | 47 | char nema_mode[] = "$PMTK314,5,5,5,5,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0*"; |
JimCarver | 2:073674e3f5bf | 48 | char nema_cmd[64]; |
JimCarver | 2:073674e3f5bf | 49 | int x = 0; |
JimCarver | 2:073674e3f5bf | 50 | sprintf( nema_cmd, "%s%x\r\n", nema_mode, calc_cs(nema_mode)); |
JimCarver | 2:073674e3f5bf | 51 | while(nema_cmd[x]) { |
JimCarver | 2:073674e3f5bf | 52 | gps_serial.putc(nema_cmd[x++]); |
JimCarver | 2:073674e3f5bf | 53 | } |
JimCarver | 2:073674e3f5bf | 54 | } |
JimCarver | 2:073674e3f5bf | 55 | |
JimCarver | 2:073674e3f5bf | 56 | int GPS_init() { |
JimCarver | 2:073674e3f5bf | 57 | |
JimCarver | 2:073674e3f5bf | 58 | gps_serial.attach( &service_serial, Serial::RxIrq ); |
JimCarver | 2:073674e3f5bf | 59 | gps.gps_gga.new_flag = 0; |
JimCarver | 2:073674e3f5bf | 60 | gps.gps_zda.new_flag = 0; |
JimCarver | 2:073674e3f5bf | 61 | gps.gps_vtg.new_flag = 0; |
JimCarver | 2:073674e3f5bf | 62 | nema_send(); |
JimCarver | 2:073674e3f5bf | 63 | return 0; |
JimCarver | 2:073674e3f5bf | 64 | } |