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: 2021/03/03
|
---|
6 | // filename: IpcUs.cpp
|
---|
7 | //
|
---|
8 | // author: Sébastien Ambroziak
|
---|
9 | // Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
10 | //
|
---|
11 | // version: $Id: $
|
---|
12 | //
|
---|
13 | // purpose: Class for an ipc us
|
---|
14 | //
|
---|
15 | //
|
---|
16 | /*********************************************************************/
|
---|
17 |
|
---|
18 | #include "IpcUs.h"
|
---|
19 | #include "ipc_receive.h"
|
---|
20 | #include "shm_receive.h"
|
---|
21 | #include <FrameworkManager.h>
|
---|
22 | #include <SpinBox.h>
|
---|
23 | #include <GroupBox.h>
|
---|
24 | #include <Matrix.h>
|
---|
25 |
|
---|
26 | using namespace flair::core;
|
---|
27 | using namespace flair::gui;
|
---|
28 |
|
---|
29 | namespace flair {
|
---|
30 | namespace sensor {
|
---|
31 |
|
---|
32 | IpcUs::IpcUs(string name, uint8_t priority, const char* ipc_name, int ipc_channel)
|
---|
33 | : Thread(getFrameworkManager(), name, priority), UsRangeFinder( name) {
|
---|
34 | data_rate =
|
---|
35 | new SpinBox(GetGroupBox()->NewRow(), "data rate", " Hz", 1, 500, 1, 50);
|
---|
36 |
|
---|
37 | //init non blocking ipc receiver
|
---|
38 | receiver = new ShmReceiver<float>(ipc_name,ipc_channel,true);
|
---|
39 |
|
---|
40 | SetIsReady(true);
|
---|
41 | }
|
---|
42 |
|
---|
43 | IpcUs::~IpcUs() {
|
---|
44 | SafeStop();
|
---|
45 | Join();
|
---|
46 | }
|
---|
47 |
|
---|
48 |
|
---|
49 | void IpcUs::Run(void) {
|
---|
50 |
|
---|
51 | SetPeriodUS((uint32_t)(1000000. / data_rate->Value()));
|
---|
52 | Time stamp;
|
---|
53 | Time lastT = GetTime();
|
---|
54 | while (!ToBeStopped()) {
|
---|
55 | WaitPeriod();
|
---|
56 |
|
---|
57 | receiver->receive();
|
---|
58 |
|
---|
59 | stamp = GetTime();
|
---|
60 |
|
---|
61 | //SetPeriodUS((receiver->getTimestamp().toNanosec() - Last)/1000);
|
---|
62 |
|
---|
63 |
|
---|
64 |
|
---|
65 | if (data_rate->ValueChanged() == true) {
|
---|
66 | SetPeriodUS((uint32_t)(1000000. / data_rate->Value()));
|
---|
67 | }
|
---|
68 |
|
---|
69 | //output->SetDataTime((Time)receiver->getTimestamp().toNanosec());
|
---|
70 | /*if (lastT < receiver->getTimestamp().toNanosec()){
|
---|
71 | output->SetValue(0, 0, receiver->getValue());
|
---|
72 | output->SetDataTime(receiver->getTimestamp().toNanosec());
|
---|
73 | //cout << "lastT: " << receiver->getTimestamp().toNanosec() << " ecart: " << receiver->getTimestamp().toNanosec() - lastT << endl;
|
---|
74 | lastT = receiver->getTimestamp().toNanosec();
|
---|
75 | }
|
---|
76 |
|
---|
77 | else{
|
---|
78 | output->SetValue(0, 0, receiver->getValue());
|
---|
79 | output->SetDataTime(lastT + GetPeriodUS()*1000);
|
---|
80 | //cout << "stamp: " << lastT + GetPeriodUS() << ' ' << " \tecart: " << stamp - lastT << endl;
|
---|
81 | lastT = lastT + GetPeriodUS()*1000;
|
---|
82 | }*/
|
---|
83 |
|
---|
84 | /*if (receiver->getValue() >= 0){
|
---|
85 | output->SetValue(0, 0, (receiver->getValue())/100.0);
|
---|
86 | }
|
---|
87 | else
|
---|
88 | {
|
---|
89 | output->SetValue(0,0,0);
|
---|
90 | }*/
|
---|
91 |
|
---|
92 | output->SetValue(0, 0, (receiver->getValue())/100.0);
|
---|
93 | output->SetDataTime(stamp);
|
---|
94 | //output->SetDataTime(receiver->getTimestamp().toNanosec());
|
---|
95 |
|
---|
96 | //cout << receiver->getTimestamp().toNanosec() << ' ' << receiver->getValue() << endl;
|
---|
97 | ProcessUpdate(output);
|
---|
98 | //cout << "GetTime: " << stamp << " ipc: " << receiver->getTimestamp().toNanosec() << " écart: " << stamp - receiver->getTimestamp().toNanosec() << endl;
|
---|
99 | }
|
---|
100 | }
|
---|
101 |
|
---|
102 | } // end namespace sensor
|
---|
103 | } // end namespace flair
|
---|
104 |
|
---|