source: flair-src/trunk/lib/FlairSensorActuator/src/SimuCamera.cpp@ 164

Last change on this file since 164 was 158, checked in by Sanahuja Guillaume, 7 years ago

corrected simu/device id for sensors

File size: 3.0 KB
Line 
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
18#include "SimuCamera.h"
19#include <FrameworkManager.h>
20#include <GroupBox.h>
21#include <SharedMem.h>
22#include <sstream>
23
24using std::string;
25using std::ostringstream;
26using namespace flair::core;
27using namespace flair::gui;
28
29namespace flair {
30namespace sensor {
31
32//control part
33SimuCamera::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//simulation part
52SimuCamera::SimuCamera(const IODevice *parent, string name, uint16_t width,
53 uint16_t height, uint8_t channels, uint32_t modelId,uint32_t deviceId)
54 : Thread(parent, name, 0), Camera(parent,name) {
55
56 buf_size = width * height * channels+sizeof(Time);
57
58 shmem = new SharedMem((Thread *)this,ShMemName(modelId, deviceId),
59 buf_size, SharedMem::Type::producerConsumer);
60 shmemReadBuf=NULL;
61
62 SetIsReady(true);
63}
64
65SimuCamera::~SimuCamera() {
66 SafeStop();
67 Join();
68 if(shmemReadBuf!=NULL) delete shmemReadBuf;
69}
70
71string SimuCamera::ShMemName(uint32_t modelId,uint32_t deviceId) {
72 ostringstream dev_name;
73 dev_name << "simu" << modelId << "_cam_" << deviceId;
74 return dev_name.str().c_str();
75}
76
77void SimuCamera::Run(void) {
78 Time time;
79// if (data_rate == NULL) {
80// Thread::Err("not applicable for simulation part.\n");
81// return;
82// }
83
84// SetPeriodUS((uint32_t)(1000000. / data_rate->Value()));
85 shmem->ReaderReady();
86
87 while (!ToBeStopped()) {
88// WaitPeriod();
89
90// if (data_rate->ValueChanged() == true) {
91// SetPeriodUS((uint32_t)(1000000. / data_rate->Value()));
92// }
93
94 output->GetMutex();
95 //blocking read
96 shmem->Read(shmemReadBuf, buf_size); // remplacer copie par
97 // échange de pointeur sur
98 // double buffering
99 output->ReleaseMutex();
100 memcpy(&time,shmemReadBuf+buf_size-sizeof(Time),sizeof(Time));
101 output->SetDataTime(time);
102
103 ProcessUpdate(output);
104 }
105}
106
107} // end namespace sensor
108} // end namespace flair
Note: See TracBrowser for help on using the repository browser.