[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: 2014/05/26
|
---|
| 6 | // filename: SimuGps.cpp
|
---|
| 7 | //
|
---|
| 8 | // author: Guillaume Sanahuja
|
---|
| 9 | // Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
| 10 | //
|
---|
| 11 | // version: $Id: $
|
---|
| 12 | //
|
---|
| 13 | // purpose: Class for a simulation GPS
|
---|
| 14 | //
|
---|
| 15 | //
|
---|
| 16 | /*********************************************************************/
|
---|
| 17 |
|
---|
| 18 | #include "SimuGps.h"
|
---|
| 19 | #include <FrameworkManager.h>
|
---|
[51] | 20 | #include <GpsData.h>
|
---|
[55] | 21 | #include <SharedMem.h>
|
---|
| 22 | #include <SpinBox.h>
|
---|
| 23 | #include <DoubleSpinBox.h>
|
---|
| 24 | #include <GroupBox.h>
|
---|
| 25 | #include <Euler.h>
|
---|
[214] | 26 | #include <Matrix.h>
|
---|
[55] | 27 | #include <sstream>
|
---|
| 28 | #include "geodesie.h"
|
---|
[3] | 29 |
|
---|
| 30 | using std::string;
|
---|
[55] | 31 | using std::ostringstream;
|
---|
[3] | 32 | using namespace flair::core;
|
---|
[55] | 33 | using namespace flair::gui;
|
---|
| 34 | using namespace Geodesie;
|
---|
[3] | 35 |
|
---|
[15] | 36 | namespace flair {
|
---|
| 37 | namespace sensor {
|
---|
[3] | 38 |
|
---|
[137] | 39 | SimuGps::SimuGps(string name,
|
---|
[158] | 40 | NmeaGps::NMEAFlags_t NMEAFlags, uint32_t modelId,uint32_t deviceId,uint8_t priority)
|
---|
[137] | 41 | : NmeaGps(name, NMEAFlags),Thread(getFrameworkManager(), name, priority) {
|
---|
[3] | 42 |
|
---|
[55] | 43 | dataRate = new SpinBox(GetGroupBox()->NewRow(), "data rate", " Hz", 1, 500, 1, 200);
|
---|
| 44 | latitudeRef = new DoubleSpinBox(GetGroupBox()->NewRow(), "latitude ref", " deg", -90, 90, 1, 6,49.402313);
|
---|
| 45 | longitudeRef = new DoubleSpinBox(GetGroupBox()->LastRowLastCol(), "longitude ref", " deg", -180, 180, 1, 6,2.795463);
|
---|
| 46 | altitudeRef= new DoubleSpinBox(GetGroupBox()->LastRowLastCol(), "altitude ref", " m", 0, 6000, 100, 1,0);
|
---|
| 47 | fixQuality = new SpinBox(GetGroupBox()->NewRow(), "fix quality", 1, 8, 1, 1);
|
---|
| 48 | numberOfSatellites = new SpinBox(GetGroupBox()->NewRow(), "number of satellites", 1, 15, 1, 5);
|
---|
[206] | 49 | magneticDeclination= new DoubleSpinBox(GetGroupBox()->NewRow(), "magnetic declination", " deg", -180, 180, .1, 2,0);
|
---|
| 50 |
|
---|
[158] | 51 | shmem = new SharedMem((Thread *)this, ShMemName(modelId, deviceId),
|
---|
[55] | 52 | sizeof(gps_states_t));
|
---|
[157] | 53 |
|
---|
| 54 | SetIsReady(true);
|
---|
[55] | 55 | }
|
---|
| 56 |
|
---|
| 57 |
|
---|
[15] | 58 | SimuGps::~SimuGps() {
|
---|
| 59 | SafeStop();
|
---|
| 60 | Join();
|
---|
[3] | 61 | }
|
---|
| 62 |
|
---|
[158] | 63 | string SimuGps::ShMemName(uint32_t modelId,uint32_t deviceId) {
|
---|
| 64 | ostringstream dev_name;
|
---|
| 65 | dev_name << "simu" << modelId << "_gps_" << deviceId;
|
---|
| 66 | return dev_name.str().c_str();
|
---|
| 67 | }
|
---|
| 68 |
|
---|
[15] | 69 | void SimuGps::Run(void) {
|
---|
[55] | 70 | gps_states_t state;
|
---|
[68] | 71 | char buf[512];
|
---|
[51] | 72 | nmeaGPGGA gga;
|
---|
| 73 | nmeaGPVTG vtg;
|
---|
[55] | 74 | nmeaPOS pos;
|
---|
| 75 | nmeaINFO info;
|
---|
| 76 |
|
---|
[68] | 77 | vtg.dir_t='T';
|
---|
| 78 | vtg.dec_m='M';
|
---|
| 79 | vtg.spk_k='K';
|
---|
| 80 | vtg.spn_n='N';
|
---|
[214] | 81 | gga.elv_units='M';
|
---|
| 82 | gga.diff_units='M';
|
---|
[68] | 83 |
|
---|
[55] | 84 | SetPeriodUS((uint32_t)(1000000. / dataRate->Value()));
|
---|
| 85 |
|
---|
[15] | 86 | WarnUponSwitches(true);
|
---|
[3] | 87 |
|
---|
[51] | 88 |
|
---|
[15] | 89 | while (!ToBeStopped()) {
|
---|
| 90 | WaitPeriod();
|
---|
[51] | 91 |
|
---|
[55] | 92 | if (dataRate->ValueChanged() == true) {
|
---|
| 93 | SetPeriodUS((uint32_t)(1000000. / dataRate->Value()));
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | shmem->Read((char *)&state, sizeof(gps_states_t));
|
---|
| 97 |
|
---|
| 98 | double x, y, z;
|
---|
[68] | 99 | ENU_2_ECEF(state.e, state.n, state.u, x,y,z, Euler::ToRadian(longitudeRef->Value()), Euler::ToRadian(latitudeRef->Value()), altitudeRef->Value());
|
---|
[55] | 100 | ECEF_2_Geographique( x, y, z,pos.lon, pos.lat, gga.elv);
|
---|
| 101 | nmea_pos2info(&pos,&info);
|
---|
| 102 |
|
---|
| 103 | if(pos.lat>0) {
|
---|
| 104 | gga.ns='N';
|
---|
| 105 | gga.lat=info.lat;
|
---|
| 106 | } else {
|
---|
| 107 | gga.ns='S';
|
---|
| 108 | gga.lat=-info.lat;
|
---|
| 109 | }
|
---|
| 110 | if(pos.lon>0) {
|
---|
| 111 | gga.ew='E';
|
---|
| 112 | gga.lon=info.lon;
|
---|
| 113 | } else {
|
---|
| 114 | gga.ew='W';
|
---|
| 115 | gga.lon=-info.lon;
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | gga.sig=fixQuality->Value();
|
---|
| 119 | gga.satinuse=numberOfSatellites->Value();
|
---|
| 120 |
|
---|
[214] | 121 | int size=nmea_gen_GPGGA(buf,sizeof(buf),&gga);
|
---|
| 122 | parseFrame(buf,size);
|
---|
| 123 |
|
---|
[68] | 124 | vtg.dir=90-Euler::ToDegree(atan2f(state.vn,state.ve));
|
---|
| 125 | vtg.spk=sqrtf(state.ve*state.ve+state.vn*state.vn)*3600./1000.;
|
---|
[214] | 126 | size=nmea_gen_GPVTG(buf,sizeof(buf),&vtg);
|
---|
| 127 | parseFrame(buf,size);
|
---|
[15] | 128 | }
|
---|
[3] | 129 |
|
---|
[15] | 130 | WarnUponSwitches(false);
|
---|
[3] | 131 | }
|
---|
| 132 |
|
---|
| 133 | } // end namespace sensor
|
---|
[170] | 134 | } // end namespace flair
|
---|