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

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

remove opencv dep

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>
[330]24#include <string.h>
[3]25
26using std::string;
27using std::ostringstream;
28using namespace flair::core;
29using namespace flair::gui;
30
[15]31namespace flair {
32namespace sensor {
[3]33
[286]34SimulatedCamera::SimulatedCamera(string name,
[15]35 uint16_t width, uint16_t height, uint8_t channels,
[158]36 uint32_t modelId,uint32_t deviceId, uint8_t priority)
[137]37 : Thread(getFrameworkManager(), name, priority),
[338]38 Camera(name, width, height, Image::Type::Format::BGR) {
[3]39
[151]40 buf_size = width * height * channels+sizeof(Time);
[3]41
[151]42 shmemReadBuf=(char*)malloc(buf_size);
[330]43 output->buffer = shmemReadBuf;
[3]44
[158]45 shmem = new SharedMem((Thread *)this,ShMemName(modelId, deviceId), buf_size, SharedMem::Type::producerConsumer);
[157]46
47 SetIsReady(true);
[3]48}
49
50
[286]51SimulatedCamera::~SimulatedCamera() {
[15]52 SafeStop();
53 Join();
[151]54 if(shmemReadBuf!=NULL) delete shmemReadBuf;
[3]55}
56
[286]57string SimulatedCamera::ShMemName(uint32_t modelId,uint32_t deviceId) {
[158]58 ostringstream dev_name;
59 dev_name << "simu" << modelId << "_cam_" << deviceId;
60 return dev_name.str().c_str();
61}
62
[286]63void SimulatedCamera::Run(void) {
[151]64 Time time;
[3]65
[150]66// SetPeriodUS((uint32_t)(1000000. / data_rate->Value()));
67 shmem->ReaderReady();
[3]68
[15]69 while (!ToBeStopped()) {
[150]70// WaitPeriod();
[3]71
[150]72// if (data_rate->ValueChanged() == true) {
73// SetPeriodUS((uint32_t)(1000000. / data_rate->Value()));
74// }
[3]75
[15]76 output->GetMutex();
[144]77 //blocking read
[238]78 if (shmem->Read(shmemReadBuf, buf_size, 1000000000)) { // remplacer copie par
79 // échange de pointeur sur
80 // double buffering
[3]81
[238]82 output->ReleaseMutex();
83 memcpy(&time, shmemReadBuf + buf_size - sizeof(Time), sizeof(Time));
84 output->SetDataTime(time);
85
86 ProcessUpdate(output);
87 } else {
88 output->ReleaseMutex();
[271]89 //Thread::Warn("Read Timeout\n");
[238]90 }
[15]91 }
[3]92}
93
94} // end namespace sensor
95} // end namespace flair
[268]96
97#endif
Note: See TracBrowser for help on using the repository browser.