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