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

Last change on this file since 233 was 224, checked in by Sanahuja Guillaume, 6 years ago

maj for armv5te

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