OpenCPN Partial API docs
comm_decoder.h
1 /***************************************************************************
2  *
3  * Project: OpenCPN
4  * Purpose:
5  *
6  * Author: David Register, Alec Leamas
7  *
8  ***************************************************************************
9  * Copyright (C) 2022 by David Register, Alec Leamas *
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  * This program is distributed in the hope that it will be useful, *
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19  * GNU General Public License for more details. *
20  * *
21  * You should have received a copy of the GNU General Public License *
22  * along with this program; if not, write to the *
23  * Free Software Foundation, Inc., *
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
25  **************************************************************************/
26 
27 #ifndef _COMM_DECODER_H
28 #define _COMM_DECODER_H
29 
30 #include <memory>
31 #include <string>
32 
33 #include "rapidjson/fwd.h"
34 #include <wx/string.h>
35 
36 #include "model/comm_appmsg.h"
37 #include "model/config_vars.h"
38 #include "model/nmea_ctx_factory.h"
39 
40 #include "nmea0183.h"
41 #include "N2KParser.h"
42 
43 
44 typedef struct{
45  double gLat;
46  double gLon;
47  double gSog;
48  double gCog;
49  double gHdt;
50  double gHdm;
51  double gVar;
52  int n_satellites;
53  int SID;
54 } NavData;
55 
56 
57 class CommDecoder {
58 public:
59  CommDecoder() : m_NMEA0183(NmeaCtxFactory()) {};
60  ~CommDecoder(){};
61 
62  // NMEA0183 decoding, by sentence.
63  bool DecodeRMC(std::string s, NavData& temp_data);
64  bool DecodeHDM(std::string s, NavData& temp_data);
65  bool DecodeHDT(std::string s, NavData& temp_data);
66  bool DecodeHDG(std::string s, NavData& temp_data);
67  bool DecodeVTG(std::string s, NavData& temp_data);
68  bool DecodeGSV(std::string s, NavData& temp_data);
69  bool DecodeGGA(std::string s, NavData& temp_data);
70  bool DecodeGLL(std::string s, NavData& temp_data);
71 
72  bool ParsePosition(const LATLONG& Position, double& lat, double& lon);
73 
74  NMEA0183 m_NMEA0183; // Used to parse messages from NMEA threads
75 
76  // NMEA2000 decoding, by PGN
77  bool DecodePGN129025(std::vector<unsigned char> v, NavData& temp_data);
78  bool DecodePGN129026(std::vector<unsigned char> v, NavData& temp_data);
79  bool DecodePGN129029(std::vector<unsigned char> v, NavData& temp_data);
80  bool DecodePGN127250(std::vector<unsigned char> v, NavData& temp_data);
81  bool DecodePGN129540(std::vector<unsigned char> v, NavData& temp_data);
82 
83  // SignalK
84  bool DecodeSignalK(std::string s, NavData& temp_data);
85  void handleUpdate(const rapidjson::Value &update, NavData& temp_data);
86  void updateItem(const rapidjson::Value &item, wxString &sfixtime, NavData& temp_data);
87  bool updateNavigationPosition(const rapidjson::Value &value,
88  const wxString &sfixtime, NavData& temp_data);
89  void updateNavigationSpeedOverGround(const rapidjson::Value &value,
90  const wxString &sfixtime, NavData& temp_data);
91  void updateNavigationCourseOverGround(const rapidjson::Value &value,
92  const wxString &sfixtime, NavData& temp_data);
93  void updateGnssSatellites(const rapidjson::Value &value, const wxString &sfixtime, NavData& temp_data);
94  void updateHeadingTrue(const rapidjson::Value &value, const wxString &sfixtime, NavData& temp_data);
95  void updateHeadingMagnetic(const rapidjson::Value &value,
96  const wxString &sfixtime, NavData& temp_data);
97  void updateMagneticVariance(const rapidjson::Value &value,
98  const wxString &sfixtime, NavData& temp_data);
99 
100  std::string src_string;
101  std::unordered_map<std::string, int> GNSS_quality_map;
102 
103 };
104 
105 #endif // _COMM_DECODER_H