source: flair-src/trunk/lib/FlairSensorActuator/src/SimuCamera.cpp@ 152

Last change on this file since 152 was 151, checked in by Sanahuja Guillaume, 7 years ago

add timestamp to simucamera producer

File size: 2.7 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
6// filename: SimuCamera.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
18#include "SimuCamera.h"
19#include <FrameworkManager.h>
[137]20#include <GroupBox.h>
[3]21#include <SharedMem.h>
22#include <sstream>
23
24using std::string;
25using std::ostringstream;
26using namespace flair::core;
27using namespace flair::gui;
28
[15]29namespace flair {
30namespace sensor {
[3]31
[151]32//control part
[137]33SimuCamera::SimuCamera(string name,
[15]34 uint16_t width, uint16_t height, uint8_t channels,
35 uint32_t dev_id, 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
[15]44 ostringstream dev_name;
45 dev_name << "simu_cam_" << dev_id;
[150]46 shmem = new SharedMem((Thread *)this, dev_name.str().c_str(), buf_size, SharedMem::Type::producerConsumer);
[3]47}
48
[151]49//simulation part
[15]50SimuCamera::SimuCamera(const IODevice *parent, string name, uint16_t width,
51 uint16_t height, uint8_t channels, uint32_t dev_id)
[137]52 : Thread(parent, name, 0), Camera(parent,name) {
[3]53
[151]54 buf_size = width * height * channels+sizeof(Time);
55
[15]56 ostringstream dev_name;
57 dev_name << "simu_cam_" << dev_id;
58 shmem = new SharedMem((Thread *)this, dev_name.str().c_str(),
[151]59 buf_size, SharedMem::Type::producerConsumer);
60 shmemReadBuf=NULL;
[3]61}
62
63SimuCamera::~SimuCamera() {
[15]64 SafeStop();
65 Join();
[151]66 if(shmemReadBuf!=NULL) delete shmemReadBuf;
[3]67}
68
69void SimuCamera::Run(void) {
[151]70 Time time;
[150]71// if (data_rate == NULL) {
72// Thread::Err("not applicable for simulation part.\n");
73// return;
74// }
[3]75
[150]76// SetPeriodUS((uint32_t)(1000000. / data_rate->Value()));
77 shmem->ReaderReady();
[3]78
[15]79 while (!ToBeStopped()) {
[150]80// WaitPeriod();
[3]81
[150]82// if (data_rate->ValueChanged() == true) {
83// SetPeriodUS((uint32_t)(1000000. / data_rate->Value()));
84// }
[3]85
[15]86 output->GetMutex();
[144]87 //blocking read
[151]88 shmem->Read(shmemReadBuf, buf_size); // remplacer copie par
[15]89 // échange de pointeur sur
90 // double buffering
91 output->ReleaseMutex();
[151]92 memcpy(&time,shmemReadBuf+buf_size-sizeof(Time),sizeof(Time));
93 output->SetDataTime(time);
[3]94
[15]95 ProcessUpdate(output);
96 }
[3]97}
98
99} // end namespace sensor
100} // end namespace flair
Note: See TracBrowser for help on using the repository browser.