// %flair:license{ // This file is part of the Flair framework distributed under the // CECILL-C License, Version 1.0. // %flair:license} // created: 2014/03/06 // filename: SimuCamera.cpp // // author: Guillaume Sanahuja // Copyright Heudiasyc UMR UTC/CNRS 7253 // // version: $Id: $ // // purpose: Class for a simulation camera // // /*********************************************************************/ #include "SimuCamera.h" #include #include #include #include using std::string; using std::ostringstream; using namespace flair::core; using namespace flair::gui; namespace flair { namespace sensor { //control part SimuCamera::SimuCamera(string name, uint16_t width, uint16_t height, uint8_t channels, uint32_t dev_id, uint8_t priority) : Thread(getFrameworkManager(), name, priority), Camera(name, width, height, cvimage::Type::Format::BGR) { buf_size = width * height * channels+sizeof(Time); shmemReadBuf=(char*)malloc(buf_size); output->img->imageData = shmemReadBuf; ostringstream dev_name; dev_name << "simu_cam_" << dev_id; shmem = new SharedMem((Thread *)this, dev_name.str().c_str(), buf_size, SharedMem::Type::producerConsumer); SetIsReady(true); } //simulation part SimuCamera::SimuCamera(const IODevice *parent, string name, uint16_t width, uint16_t height, uint8_t channels, uint32_t dev_id) : Thread(parent, name, 0), Camera(parent,name) { buf_size = width * height * channels+sizeof(Time); ostringstream dev_name; dev_name << "simu_cam_" << dev_id; shmem = new SharedMem((Thread *)this, dev_name.str().c_str(), buf_size, SharedMem::Type::producerConsumer); shmemReadBuf=NULL; SetIsReady(true); } SimuCamera::~SimuCamera() { SafeStop(); Join(); if(shmemReadBuf!=NULL) delete shmemReadBuf; } void SimuCamera::Run(void) { Time time; // if (data_rate == NULL) { // Thread::Err("not applicable for simulation part.\n"); // return; // } // SetPeriodUS((uint32_t)(1000000. / data_rate->Value())); shmem->ReaderReady(); while (!ToBeStopped()) { // WaitPeriod(); // if (data_rate->ValueChanged() == true) { // SetPeriodUS((uint32_t)(1000000. / data_rate->Value())); // } output->GetMutex(); //blocking read shmem->Read(shmemReadBuf, buf_size); // remplacer copie par // échange de pointeur sur // double buffering output->ReleaseMutex(); memcpy(&time,shmemReadBuf+buf_size-sizeof(Time),sizeof(Time)); output->SetDataTime(time); ProcessUpdate(output); } } } // end namespace sensor } // end namespace flair