1 | // %flair:license{
|
---|
2 | // This file is part of the Flair framework distributed under the
|
---|
3 | // CECILL-C License, Version 1.0.
|
---|
4 | // %flair:license}
|
---|
5 | // created: 2013/08/23
|
---|
6 | // filename: NmeaGps.cpp
|
---|
7 | //
|
---|
8 | // author: Guillaume Sanahuja
|
---|
9 | // Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
10 | //
|
---|
11 | // version: $Id: $
|
---|
12 | //
|
---|
13 | // purpose: Base class for GPS using NMEA sentances
|
---|
14 | //
|
---|
15 | //
|
---|
16 | /*********************************************************************/
|
---|
17 |
|
---|
18 | #include "NmeaGps.h"
|
---|
19 | #include "geodesie.h"
|
---|
20 | #include <Euler.h>
|
---|
21 | #include <DataPlot1D.h>
|
---|
22 | #include <Tab.h>
|
---|
23 | #include <TabWidget.h>
|
---|
24 | #include <GridLayout.h>
|
---|
25 | #include <GroupBox.h>
|
---|
26 | #include <PushButton.h>
|
---|
27 | #include <FrameworkManager.h>
|
---|
28 | #include <Map.h>
|
---|
29 | #include <GeoCoordinate.h>
|
---|
30 | #include <Vector3D.h>
|
---|
31 | #include <Label.h>
|
---|
32 | #include <GpsData.h>
|
---|
33 | #include <string.h>
|
---|
34 |
|
---|
35 | using std::string;
|
---|
36 | using namespace Geodesie;
|
---|
37 | using namespace flair::core;
|
---|
38 | using namespace flair::gui;
|
---|
39 |
|
---|
40 | namespace flair {
|
---|
41 | namespace sensor {
|
---|
42 |
|
---|
43 | NmeaGps::NmeaGps(string name, NMEAFlags_t NMEAFlags)
|
---|
44 | : IODevice(getFrameworkManager(), name) {
|
---|
45 | this->NMEAFlags = NMEAFlags;
|
---|
46 |
|
---|
47 | nmea_zero_INFO(&info);
|
---|
48 | nmea_parser_init(&parser);
|
---|
49 | altRef = 0;
|
---|
50 |
|
---|
51 | if ((NMEAFlags & GGA) == 0) {
|
---|
52 | Err("Enable at least the GGA sentence\n");
|
---|
53 | }
|
---|
54 |
|
---|
55 | // station sol
|
---|
56 | mainTab = new Tab(getFrameworkManager()->GetTabWidget(), name);
|
---|
57 | tab = new TabWidget(mainTab->NewRow(), name);
|
---|
58 | sensorTab = new Tab(tab, "Setup");
|
---|
59 | setupGroupbox = new GroupBox(sensorTab->NewRow(), name);
|
---|
60 | buttonRef = new PushButton(setupGroupbox->NewRow(), "set ref");
|
---|
61 | nbSatLabel = new Label(setupGroupbox->NewRow(), "nb_sat");
|
---|
62 | fixLabel = new Label(setupGroupbox->LastRowLastCol(), "fix");
|
---|
63 |
|
---|
64 | position = new GeoCoordinate((IODevice *)this, "position", 0, 0, 0);
|
---|
65 |
|
---|
66 | takeRef = false;
|
---|
67 |
|
---|
68 | gpsData = new GpsData(this);
|
---|
69 | AddDataToLog(gpsData);
|
---|
70 |
|
---|
71 | nbSatLabel->SetText("number of satellies: %i", gpsData->GetNumberOfSatellites());
|
---|
72 | fixLabel->SetText("fix quality: %i", gpsData->GetFixQuality());
|
---|
73 | }
|
---|
74 |
|
---|
75 | NmeaGps::NmeaGps(const IODevice *parent, std::string name) : IODevice(parent, name) {
|
---|
76 | gpsData = new GpsData(this);
|
---|
77 | mainTab = NULL;
|
---|
78 | tab = NULL;
|
---|
79 | sensorTab = NULL;
|
---|
80 | }
|
---|
81 |
|
---|
82 | NmeaGps::~NmeaGps() {
|
---|
83 | if (mainTab != NULL) {
|
---|
84 | nmea_parser_destroy(&parser);
|
---|
85 | delete mainTab;
|
---|
86 | }
|
---|
87 | }
|
---|
88 |
|
---|
89 | GroupBox *NmeaGps::GetGroupBox(void) const { return setupGroupbox; }
|
---|
90 |
|
---|
91 | const GpsData *NmeaGps::GetDatas(void) const {
|
---|
92 | return gpsData;
|
---|
93 | }
|
---|
94 |
|
---|
95 | void NmeaGps::GetDatas(core::GpsData **outGpsData) const {
|
---|
96 | *outGpsData = gpsData;
|
---|
97 | }
|
---|
98 |
|
---|
99 | void NmeaGps::UseDefaultPlot(void) {
|
---|
100 | plotTab = new Tab(tab, "Mesures");
|
---|
101 |
|
---|
102 | if ((NMEAFlags & GGA) != 0) {
|
---|
103 | ePlot = new DataPlot1D(plotTab->NewRow(), "e", -10, 10);
|
---|
104 | ePlot->AddCurve(gpsData->Element(GpsData::East));
|
---|
105 | nPlot = new DataPlot1D(plotTab->LastRowLastCol(), "n", -10, 10);
|
---|
106 | nPlot->AddCurve(gpsData->Element(GpsData::North));
|
---|
107 | uPlot = new DataPlot1D(plotTab->LastRowLastCol(), "u", -10, 10);
|
---|
108 | uPlot->AddCurve(gpsData->Element(GpsData::Up));
|
---|
109 | }
|
---|
110 | if ((NMEAFlags & VTG) != 0) {
|
---|
111 | vePlot = new DataPlot1D(plotTab->NewRow(), "ve", -10, 10);
|
---|
112 | vePlot->AddCurve(gpsData->Element(GpsData::EastVelocity));
|
---|
113 | vnPlot = new DataPlot1D(plotTab->LastRowLastCol(), "vn", -10, 10);
|
---|
114 | vnPlot->AddCurve(gpsData->Element(GpsData::NorthVelocity));
|
---|
115 | }
|
---|
116 |
|
---|
117 | Tab *map_tab = new Tab(tab, "carte");
|
---|
118 | map = new Map(map_tab->NewRow(), "map");
|
---|
119 | map->AddPoint(position, "drone");
|
---|
120 | }
|
---|
121 |
|
---|
122 | DataPlot1D *NmeaGps::EPlot(void) const {
|
---|
123 | if ((NMEAFlags & GGA) != 0) {
|
---|
124 | return ePlot;
|
---|
125 | } else {
|
---|
126 | Err("GGA sentence not requested\n");
|
---|
127 | return NULL;
|
---|
128 | }
|
---|
129 | }
|
---|
130 |
|
---|
131 | DataPlot1D *NmeaGps::NPlot(void) const {
|
---|
132 | if ((NMEAFlags & GGA) != 0) {
|
---|
133 | return nPlot;
|
---|
134 | } else {
|
---|
135 | Err("GGA sentence not requested\n");
|
---|
136 | return NULL;
|
---|
137 | }
|
---|
138 | }
|
---|
139 |
|
---|
140 | DataPlot1D *NmeaGps::UPlot(void) const {
|
---|
141 | if ((NMEAFlags & GGA) != 0) {
|
---|
142 | return uPlot;
|
---|
143 | } else {
|
---|
144 | Err("GGA sentence not requested\n");
|
---|
145 | return NULL;
|
---|
146 | }
|
---|
147 | }
|
---|
148 |
|
---|
149 | DataPlot1D *NmeaGps::VEPlot(void) const {
|
---|
150 | if ((NMEAFlags & VTG) != 0) {
|
---|
151 | return vePlot;
|
---|
152 | } else {
|
---|
153 | Err("GGA sentence not requested\n");
|
---|
154 | return NULL;
|
---|
155 | }
|
---|
156 | }
|
---|
157 |
|
---|
158 | DataPlot1D *NmeaGps::VNPlot(void) const {
|
---|
159 | if ((NMEAFlags & VTG) != 0) {
|
---|
160 | return vnPlot;
|
---|
161 | } else {
|
---|
162 | Err("GGA sentence not requested\n");
|
---|
163 | return NULL;
|
---|
164 | }
|
---|
165 | }
|
---|
166 |
|
---|
167 | Layout *NmeaGps::GetLayout(void) const { return sensorTab; }
|
---|
168 |
|
---|
169 | Tab *NmeaGps::GetPlotTab(void) const { return plotTab; }
|
---|
170 |
|
---|
171 | TabWidget *NmeaGps::GetTab(void) const { return tab; }
|
---|
172 |
|
---|
173 | void NmeaGps::SetRef(void) { takeRef = true; }
|
---|
174 |
|
---|
175 | void NmeaGps::parseFrame(const char *frame, int frame_size) {
|
---|
176 |
|
---|
177 | int result;
|
---|
178 | //Printf("%s\n",frame);
|
---|
179 | result = nmea_parse(&parser, frame, frame_size, &info);
|
---|
180 | if (result != 1) {
|
---|
181 | Warn("unrecognized nmea sentence: %s\n",frame);
|
---|
182 | return;
|
---|
183 | }
|
---|
184 |
|
---|
185 | result = nmea_parse_GPGGA(frame, frame_size, &pack);
|
---|
186 |
|
---|
187 | if (result == 1) {
|
---|
188 | nmea_info2pos(&info, &pos);
|
---|
189 |
|
---|
190 | // Printf("nb:%i fix:%i lat:%f long:%f alt:%f vel:%f angle:%f\n",pack.satinuse,pack.sig,info.lat,info.lon,info.elv,info.speed*1000./3600.,info.direction);
|
---|
191 | //Printf("lat:%f long:%f\n",pos.lat,pos.lon);
|
---|
192 |
|
---|
193 | gpsData->GetMutex(); // on utilise le mutex de gpsData pour fix et nb_sat
|
---|
194 | if (gpsData->GetFixQuality() != (GpsData::FixQuality_t)pack.sig) {
|
---|
195 | gpsData->SetFixQuality((GpsData::FixQuality_t)pack.sig);
|
---|
196 | fixLabel->SetText("fix: %i", pack.sig);
|
---|
197 | }
|
---|
198 | if (gpsData->GetNumberOfSatellites() != pack.satinuse) {
|
---|
199 | gpsData->SetNumberOfSatellites(pack.satinuse) ;
|
---|
200 | nbSatLabel->SetText("nb_sat: %i", pack.satinuse);
|
---|
201 | }
|
---|
202 | gpsData->ReleaseMutex();
|
---|
203 |
|
---|
204 | gpsData->SetLla(Euler::ToDegree(pos.lat), Euler::ToDegree(pos.lon),info.elv);
|
---|
205 | position->SetCoordinates(Euler::ToDegree(pos.lat), Euler::ToDegree(pos.lon),
|
---|
206 | info.elv);
|
---|
207 |
|
---|
208 | if ((info.sig == 2 && altRef == 0) || buttonRef->Clicked() == true ||
|
---|
209 | takeRef == true) {
|
---|
210 | Printf("prise pos ref\n");
|
---|
211 | latRef = pos.lat;
|
---|
212 | longRef = pos.lon;
|
---|
213 | altRef = info.elv;
|
---|
214 | takeRef = false;
|
---|
215 | }
|
---|
216 | // if(alt_ref!=0)
|
---|
217 | {
|
---|
218 | double x, y, z;
|
---|
219 | double e, n, u;
|
---|
220 | Geographique_2_ECEF(pos.lon, pos.lat, info.elv, x, y, z);
|
---|
221 | ECEF_2_ENU(x, y, z, e, n, u, longRef, latRef, altRef);
|
---|
222 | // Printf("lon:%f lat:%f elv:%f\n",pos.lon,pos.lat,info.elv);
|
---|
223 |
|
---|
224 | gpsData->SetEnu(e,n,u);
|
---|
225 |
|
---|
226 | if ((NMEAFlags & VTG) != 0) {
|
---|
227 | gpsData->SetVelocity(info.speed * 1000. / 3600. * sin(Euler::ToRadian(info.direction)),
|
---|
228 | info.speed * 1000. / 3600. * cos(Euler::ToRadian(info.direction)));
|
---|
229 | }
|
---|
230 | if ((NMEAFlags & GSA) != 0) {
|
---|
231 | gpsData->SetDop(info.PDOP,info.HDOP,info.VDOP);
|
---|
232 | }
|
---|
233 | /*
|
---|
234 | if ((NMEAFlags & GST) != 0) {
|
---|
235 | // Thread::Printf("dev_lon:%f dev_lat:%f
|
---|
236 | // dev_elv:%f\n",info.dev_lat,info.dev_lon,info.dev_elv);
|
---|
237 | output->SetValueNoMutex(index, 0, info.dev_lat);
|
---|
238 | output->SetValueNoMutex(index + 1, 0, info.dev_lon);
|
---|
239 | output->SetValueNoMutex(index + 2, 0, info.dev_elv);
|
---|
240 | index += 3;
|
---|
241 | }*/
|
---|
242 |
|
---|
243 |
|
---|
244 | gpsData->SetDataTime(GetTime());
|
---|
245 | ProcessUpdate(gpsData);
|
---|
246 | }
|
---|
247 | }
|
---|
248 | }
|
---|
249 |
|
---|
250 | } // end namespace sensor
|
---|
251 | } // end namespace flair
|
---|