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

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

add timestamp to simucamera producer

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