2 * This file is part of INAV Project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
6 * You can obtain one at http://mozilla.org/MPL/2.0/.
8 * Alternatively, the contents of this file may be used under the terms
9 * of the GNU General Public License Version 3, as described below:
11 * This file is free software: you may copy, redistribute and/or modify
12 * it under the terms of the GNU General Public License as published by the
13 * Free Software Foundation, either version 3 of the License, or (at your
14 * option) any later version.
16 * This file is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
19 * Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see http://www.gnu.org/licenses/.
32 #include "build/build_config.h"
35 #if defined(USE_GPS_PROTO_MSP)
37 #include "build/debug.h"
39 #include "common/axis.h"
40 #include "common/gps_conversion.h"
41 #include "common/maths.h"
42 #include "common/utils.h"
44 #include "drivers/serial.h"
45 #include "drivers/time.h"
47 #include "fc/config.h"
48 #include "fc/runtime_config.h"
51 #include "io/gps_private.h"
52 #include "io/serial.h"
54 #include "msp/msp_protocol_v2_sensor_msg.h"
56 static bool newDataReady
;
58 void gpsRestartMSP(void)
63 void gpsHandleMSP(void)
66 gpsProcessNewSolutionData(false);
71 static uint8_t gpsMapFixType(uint8_t mspFixType
)
80 void mspGPSReceiveNewData(const uint8_t * bufferPtr
)
82 const mspSensorGpsDataMessage_t
* pkt
= (const mspSensorGpsDataMessage_t
*)bufferPtr
;
84 gpsSolDRV
.fixType
= gpsMapFixType(pkt
->fixType
);
85 gpsSolDRV
.numSat
= pkt
->satellitesInView
;
86 gpsSolDRV
.llh
.lon
= pkt
->longitude
;
87 gpsSolDRV
.llh
.lat
= pkt
->latitude
;
88 gpsSolDRV
.llh
.alt
= pkt
->mslAltitude
;
89 gpsSolDRV
.velNED
[X
] = pkt
->nedVelNorth
;
90 gpsSolDRV
.velNED
[Y
] = pkt
->nedVelEast
;
91 gpsSolDRV
.velNED
[Z
] = pkt
->nedVelDown
;
92 gpsSolDRV
.groundSpeed
= calc_length_pythagorean_2D((float)pkt
->nedVelNorth
, (float)pkt
->nedVelEast
);
93 gpsSolDRV
.groundCourse
= pkt
->groundCourse
/ 10; // in deg * 10
94 gpsSolDRV
.eph
= gpsConstrainEPE(pkt
->horizontalPosAccuracy
/ 10);
95 gpsSolDRV
.epv
= gpsConstrainEPE(pkt
->verticalPosAccuracy
/ 10);
96 gpsSolDRV
.hdop
= gpsConstrainHDOP(pkt
->hdop
);
97 gpsSolDRV
.flags
.validVelNE
= true;
98 gpsSolDRV
.flags
.validVelD
= true;
99 gpsSolDRV
.flags
.validEPE
= true;
101 gpsSolDRV
.time
.year
= pkt
->year
;
102 gpsSolDRV
.time
.month
= pkt
->month
;
103 gpsSolDRV
.time
.day
= pkt
->day
;
104 gpsSolDRV
.time
.hours
= pkt
->hour
;
105 gpsSolDRV
.time
.minutes
= pkt
->min
;
106 gpsSolDRV
.time
.seconds
= pkt
->sec
;
107 gpsSolDRV
.time
.millis
= 0;
109 gpsSolDRV
.flags
.validTime
= (pkt
->fixType
>= 3);
111 gpsProcessNewDriverData();