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: 2018/05/24
|
---|
6 | // filename: SimuPressureSensor.cpp
|
---|
7 | //
|
---|
8 | // author: Guillaume Sanahuja
|
---|
9 | // Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
10 | //
|
---|
11 | // version: $Id: $
|
---|
12 | //
|
---|
13 | // purpose: Class for a simulation pressure sensor
|
---|
14 | //
|
---|
15 | //
|
---|
16 | /*********************************************************************/
|
---|
17 | #ifdef CORE2_64
|
---|
18 |
|
---|
19 | #include "SimuPressureSensor.h"
|
---|
20 | #include <FrameworkManager.h>
|
---|
21 | #include <SpinBox.h>
|
---|
22 | #include <GroupBox.h>
|
---|
23 | #include <Matrix.h>
|
---|
24 | #include <SharedMem.h>
|
---|
25 | #include <sstream>
|
---|
26 |
|
---|
27 | using std::string;
|
---|
28 | using std::ostringstream;
|
---|
29 | using namespace flair::core;
|
---|
30 | using namespace flair::gui;
|
---|
31 |
|
---|
32 | namespace flair {
|
---|
33 | namespace sensor {
|
---|
34 |
|
---|
35 | SimuPressureSensor::SimuPressureSensor(string name, uint32_t modelId,uint32_t deviceId,
|
---|
36 | uint8_t priority)
|
---|
37 | : Thread(getFrameworkManager(), name, priority), PressureSensor( name) {
|
---|
38 | data_rate =
|
---|
39 | new SpinBox(GetGroupBox()->NewRow(), "data rate", " Hz", 1, 500, 1, 50);
|
---|
40 |
|
---|
41 | shmem = new SharedMem((Thread *)this, ShMemName(modelId, deviceId), sizeof(float));
|
---|
42 |
|
---|
43 | SetIsReady(true);
|
---|
44 | }
|
---|
45 |
|
---|
46 | SimuPressureSensor::~SimuPressureSensor() {
|
---|
47 | SafeStop();
|
---|
48 | Join();
|
---|
49 | }
|
---|
50 |
|
---|
51 | string SimuPressureSensor::ShMemName(uint32_t modelId,uint32_t deviceId) {
|
---|
52 | ostringstream dev_name;
|
---|
53 | dev_name << "simu" << modelId << "_pressure_" << deviceId;
|
---|
54 | return dev_name.str().c_str();
|
---|
55 | }
|
---|
56 |
|
---|
57 | void SimuPressureSensor::Run(void) {
|
---|
58 | float p;
|
---|
59 |
|
---|
60 | SetPeriodUS((uint32_t)(1000000. / data_rate->Value()));
|
---|
61 |
|
---|
62 | while (!ToBeStopped()) {
|
---|
63 | WaitPeriod();
|
---|
64 |
|
---|
65 | shmem->Read((char *)&p, sizeof(float));
|
---|
66 |
|
---|
67 | if (data_rate->ValueChanged() == true) {
|
---|
68 | SetPeriodUS((uint32_t)(1000000. / data_rate->Value()));
|
---|
69 | }
|
---|
70 |
|
---|
71 | output->SetValue(0, 0, p);
|
---|
72 | output->SetDataTime(GetTime());
|
---|
73 | ProcessUpdate(output);
|
---|
74 | }
|
---|
75 | }
|
---|
76 |
|
---|
77 | } // end namespace sensor
|
---|
78 | } // end namespace flair
|
---|
79 |
|
---|
80 | #endif |
---|