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