// %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 // // /*********************************************************************/ #ifdef CORE2_64 #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 { SimuCamera::SimuCamera(string name, uint16_t width, uint16_t height, uint8_t channels, uint32_t modelId,uint32_t deviceId, 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" << modelId << "_cam_" << deviceId; shmem = new SharedMem((Thread *)this,ShMemName(modelId, deviceId), buf_size, SharedMem::Type::producerConsumer); SetIsReady(true); } SimuCamera::~SimuCamera() { SafeStop(); Join(); if(shmemReadBuf!=NULL) delete shmemReadBuf; } string SimuCamera::ShMemName(uint32_t modelId,uint32_t deviceId) { ostringstream dev_name; dev_name << "simu" << modelId << "_cam_" << deviceId; return dev_name.str().c_str(); } void SimuCamera::Run(void) { Time time; // 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 if (shmem->Read(shmemReadBuf, buf_size, 1000000000)) { // 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); } else { output->ReleaseMutex(); //Thread::Warn("Read Timeout\n"); } } } } // end namespace sensor } // end namespace flair #endif