source: flair-src/trunk/lib/FlairSensorActuator/src/SimulatedCamera.cpp@ 319

Last change on this file since 319 was 286, checked in by Sanahuja Guillaume, 6 years ago

draw vrpn axis in simulator

File size: 2.4 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: SimulatedCamera.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 "SimulatedCamera.h"
20#include <FrameworkManager.h>
21#include <GroupBox.h>
22#include <SharedMem.h>
23#include <sstream>
24
25using std::string;
26using std::ostringstream;
27using namespace flair::core;
28using namespace flair::gui;
29
30namespace flair {
31namespace sensor {
32
33SimulatedCamera::SimulatedCamera(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 shmem = new SharedMem((Thread *)this,ShMemName(modelId, deviceId), buf_size, SharedMem::Type::producerConsumer);
45
46 SetIsReady(true);
47}
48
49
50SimulatedCamera::~SimulatedCamera() {
51 SafeStop();
52 Join();
53 if(shmemReadBuf!=NULL) delete shmemReadBuf;
54}
55
56string SimulatedCamera::ShMemName(uint32_t modelId,uint32_t deviceId) {
57 ostringstream dev_name;
58 dev_name << "simu" << modelId << "_cam_" << deviceId;
59 return dev_name.str().c_str();
60}
61
62void SimulatedCamera::Run(void) {
63 Time time;
64
65// SetPeriodUS((uint32_t)(1000000. / data_rate->Value()));
66 shmem->ReaderReady();
67
68 while (!ToBeStopped()) {
69// WaitPeriod();
70
71// if (data_rate->ValueChanged() == true) {
72// SetPeriodUS((uint32_t)(1000000. / data_rate->Value()));
73// }
74
75 output->GetMutex();
76 //blocking read
77 if (shmem->Read(shmemReadBuf, buf_size, 1000000000)) { // remplacer copie par
78 // échange de pointeur sur
79 // double buffering
80
81 output->ReleaseMutex();
82 memcpy(&time, shmemReadBuf + buf_size - sizeof(Time), sizeof(Time));
83 output->SetDataTime(time);
84
85 ProcessUpdate(output);
86 } else {
87 output->ReleaseMutex();
88 //Thread::Warn("Read Timeout\n");
89 }
90 }
91}
92
93} // end namespace sensor
94} // end namespace flair
95
96#endif
Note: See TracBrowser for help on using the repository browser.