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/03/06
|
---|
6 | // filename: SimuCamera.cpp
|
---|
7 | //
|
---|
8 | // author: Guillaume Sanahuja
|
---|
9 | // Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
10 | //
|
---|
11 | // version: $Id: $
|
---|
12 | //
|
---|
13 | // purpose: Class for a simulation camera
|
---|
14 | //
|
---|
15 | //
|
---|
16 | /*********************************************************************/
|
---|
17 | #ifdef CORE2_64
|
---|
18 |
|
---|
19 | #include "SimuCamera.h"
|
---|
20 | #include <FrameworkManager.h>
|
---|
21 | #include <GroupBox.h>
|
---|
22 | #include <SharedMem.h>
|
---|
23 | #include <sstream>
|
---|
24 |
|
---|
25 | using std::string;
|
---|
26 | using std::ostringstream;
|
---|
27 | using namespace flair::core;
|
---|
28 | using namespace flair::gui;
|
---|
29 |
|
---|
30 | namespace flair {
|
---|
31 | namespace sensor {
|
---|
32 |
|
---|
33 | SimuCamera::SimuCamera(string name,
|
---|
34 | uint16_t width, uint16_t height, uint8_t channels,
|
---|
35 | uint32_t modelId,uint32_t deviceId, uint8_t priority)
|
---|
36 | : Thread(getFrameworkManager(), name, priority),
|
---|
37 | Camera(name, width, height, cvimage::Type::Format::BGR) {
|
---|
38 |
|
---|
39 | buf_size = width * height * channels+sizeof(Time);
|
---|
40 |
|
---|
41 | shmemReadBuf=(char*)malloc(buf_size);
|
---|
42 | output->img->imageData = shmemReadBuf;
|
---|
43 |
|
---|
44 | ostringstream dev_name;
|
---|
45 | dev_name << "simu" << modelId << "_cam_" << deviceId;
|
---|
46 | shmem = new SharedMem((Thread *)this,ShMemName(modelId, deviceId), buf_size, SharedMem::Type::producerConsumer);
|
---|
47 |
|
---|
48 | SetIsReady(true);
|
---|
49 | }
|
---|
50 |
|
---|
51 |
|
---|
52 | SimuCamera::~SimuCamera() {
|
---|
53 | SafeStop();
|
---|
54 | Join();
|
---|
55 | if(shmemReadBuf!=NULL) delete shmemReadBuf;
|
---|
56 | }
|
---|
57 |
|
---|
58 | string SimuCamera::ShMemName(uint32_t modelId,uint32_t deviceId) {
|
---|
59 | ostringstream dev_name;
|
---|
60 | dev_name << "simu" << modelId << "_cam_" << deviceId;
|
---|
61 | return dev_name.str().c_str();
|
---|
62 | }
|
---|
63 |
|
---|
64 | void SimuCamera::Run(void) {
|
---|
65 | Time time;
|
---|
66 |
|
---|
67 | // SetPeriodUS((uint32_t)(1000000. / data_rate->Value()));
|
---|
68 | shmem->ReaderReady();
|
---|
69 |
|
---|
70 | while (!ToBeStopped()) {
|
---|
71 | // WaitPeriod();
|
---|
72 |
|
---|
73 | // if (data_rate->ValueChanged() == true) {
|
---|
74 | // SetPeriodUS((uint32_t)(1000000. / data_rate->Value()));
|
---|
75 | // }
|
---|
76 |
|
---|
77 | output->GetMutex();
|
---|
78 | //blocking read
|
---|
79 | if (shmem->Read(shmemReadBuf, buf_size, 1000000000)) { // remplacer copie par
|
---|
80 | // échange de pointeur sur
|
---|
81 | // double buffering
|
---|
82 |
|
---|
83 | output->ReleaseMutex();
|
---|
84 | memcpy(&time, shmemReadBuf + buf_size - sizeof(Time), sizeof(Time));
|
---|
85 | output->SetDataTime(time);
|
---|
86 |
|
---|
87 | ProcessUpdate(output);
|
---|
88 | } else {
|
---|
89 | output->ReleaseMutex();
|
---|
90 | Thread::Warn("Read Timeout\n");
|
---|
91 | }
|
---|
92 | }
|
---|
93 | }
|
---|
94 |
|
---|
95 | } // end namespace sensor
|
---|
96 | } // end namespace flair
|
---|
97 |
|
---|
98 | #endif |
---|