Improved, thread compatible. Adds new features
Fork of GroveGPS by
Diff: GroveGPS.cpp
- Revision:
- 2:073674e3f5bf
- Child:
- 4:4615d6e99bb4
diff -r 403eb5e9e994 -r 073674e3f5bf GroveGPS.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/GroveGPS.cpp Thu Apr 19 17:54:31 2018 +0000 @@ -0,0 +1,64 @@ +// ---------------------------------------------------------------------------- +// Copyright 2016-2017 ARM Ltd. +// +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------- + +#include "mbed.h" + +#include "GroveGPS.h" + +Serial gps_serial(PE_8, PE_7, 9600); + + +Thread gpsThread; +GroveGPS gps; + + +void service_serial(void) { + gps.readCharacter(gps_serial.getc()); + } + + +int calc_cs(char * str) { + char cs = 0; + int x = 1; + + while(str[x] != '*') { + cs ^= str[x++]; + } + return(cs); + } + +void nema_send( void ) { + + char nema_mode[] = "$PMTK314,5,5,5,5,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0*"; + char nema_cmd[64]; + int x = 0; + sprintf( nema_cmd, "%s%x\r\n", nema_mode, calc_cs(nema_mode)); + while(nema_cmd[x]) { + gps_serial.putc(nema_cmd[x++]); + } + } + +int GPS_init() { + + gps_serial.attach( &service_serial, Serial::RxIrq ); + gps.gps_gga.new_flag = 0; + gps.gps_zda.new_flag = 0; + gps.gps_vtg.new_flag = 0; + nema_send(); + return 0; +} \ No newline at end of file