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

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

draw vrpn axis in simulator

File size: 2.4 KB
RevLine 
[3]1// %flair:license{
[15]2// This file is part of the Flair framework distributed under the
3// CECILL-C License, Version 1.0.
[3]4// %flair:license}
5// created: 2014/03/06
[286]6// filename: SimulatedCamera.cpp
[3]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/*********************************************************************/
[268]17#ifdef CORE2_64
[3]18
[286]19#include "SimulatedCamera.h"
[3]20#include <FrameworkManager.h>
[137]21#include <GroupBox.h>
[3]22#include <SharedMem.h>
23#include <sstream>
24
25using std::string;
26using std::ostringstream;
27using namespace flair::core;
28using namespace flair::gui;
29
[15]30namespace flair {
31namespace sensor {
[3]32
[286]33SimulatedCamera::SimulatedCamera(string name,
[15]34 uint16_t width, uint16_t height, uint8_t channels,
[158]35 uint32_t modelId,uint32_t deviceId, uint8_t priority)
[137]36 : Thread(getFrameworkManager(), name, priority),
37 Camera(name, width, height, cvimage::Type::Format::BGR) {
[3]38
[151]39 buf_size = width * height * channels+sizeof(Time);
[3]40
[151]41 shmemReadBuf=(char*)malloc(buf_size);
42 output->img->imageData = shmemReadBuf;
[3]43
[158]44 shmem = new SharedMem((Thread *)this,ShMemName(modelId, deviceId), buf_size, SharedMem::Type::producerConsumer);
[157]45
46 SetIsReady(true);
[3]47}
48
49
[286]50SimulatedCamera::~SimulatedCamera() {
[15]51 SafeStop();
52 Join();
[151]53 if(shmemReadBuf!=NULL) delete shmemReadBuf;
[3]54}
55
[286]56string SimulatedCamera::ShMemName(uint32_t modelId,uint32_t deviceId) {
[158]57 ostringstream dev_name;
58 dev_name << "simu" << modelId << "_cam_" << deviceId;
59 return dev_name.str().c_str();
60}
61
[286]62void SimulatedCamera::Run(void) {
[151]63 Time time;
[3]64
[150]65// SetPeriodUS((uint32_t)(1000000. / data_rate->Value()));
66 shmem->ReaderReady();
[3]67
[15]68 while (!ToBeStopped()) {
[150]69// WaitPeriod();
[3]70
[150]71// if (data_rate->ValueChanged() == true) {
72// SetPeriodUS((uint32_t)(1000000. / data_rate->Value()));
73// }
[3]74
[15]75 output->GetMutex();
[144]76 //blocking read
[238]77 if (shmem->Read(shmemReadBuf, buf_size, 1000000000)) { // remplacer copie par
78 // échange de pointeur sur
79 // double buffering
[3]80
[238]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();
[271]88 //Thread::Warn("Read Timeout\n");
[238]89 }
[15]90 }
[3]91}
92
93} // end namespace sensor
94} // end namespace flair
[268]95
96#endif
Note: See TracBrowser for help on using the repository browser.