[224] | 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: 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>
|
---|
| 20 | #include <SharedMem.h>
|
---|
| 21 | #include <Matrix.h>
|
---|
| 22 | #include <sstream>
|
---|
| 23 |
|
---|
| 24 | using std::string;
|
---|
| 25 | using std::ostringstream;
|
---|
| 26 | using namespace flair::core;
|
---|
| 27 |
|
---|
| 28 | namespace flair {
|
---|
| 29 | namespace sensor {
|
---|
| 30 |
|
---|
| 31 |
|
---|
| 32 | SimuGps::SimuGps(const IODevice *parent, string name, uint32_t modelId,uint32_t deviceId)
|
---|
| 33 | : IODevice(parent, name) {
|
---|
| 34 |
|
---|
| 35 | shmem = new SharedMem(this,ShMemName(modelId, deviceId),
|
---|
| 36 | sizeof(gps_states_t));
|
---|
| 37 |
|
---|
| 38 | SetIsReady(true);
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | SimuGps::~SimuGps() {
|
---|
| 42 |
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | string SimuGps::ShMemName(uint32_t modelId,uint32_t deviceId) {
|
---|
| 46 | ostringstream dev_name;
|
---|
| 47 | dev_name << "simu" << modelId << "_gps_" << deviceId;
|
---|
| 48 | return dev_name.str().c_str();
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | void SimuGps::UpdateFrom(const io_data *data) {
|
---|
| 52 | if (data != NULL) {
|
---|
| 53 | Matrix *input = (Matrix *)data;
|
---|
| 54 | gps_states_t state;
|
---|
| 55 |
|
---|
| 56 | input->GetMutex();
|
---|
| 57 | //simulator is ned, convert it to enu
|
---|
| 58 | //TODO: put simulator in enu?
|
---|
| 59 | state.e = input->ValueNoMutex(5, 0);//y simulator
|
---|
| 60 | state.n = input->ValueNoMutex(4, 0);//x simulator
|
---|
| 61 | state.u = -input->ValueNoMutex(6, 0);//z simulator
|
---|
| 62 | state.ve = input->ValueNoMutex(11, 0);//vy simulator
|
---|
| 63 | state.vn = input->ValueNoMutex(10, 0);//vx simulator
|
---|
| 64 | input->ReleaseMutex();
|
---|
| 65 |
|
---|
| 66 | shmem->Write((char *)&state, sizeof(gps_states_t));
|
---|
| 67 | }
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | } // end namespace sensor
|
---|
| 71 | } // end namespace flair
|
---|