[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 | /*********************************************************************/
|
---|
[268] | 17 | #ifdef CORE2_64
|
---|
[3] | 18 |
|
---|
| 19 | #include "SimuCamera.h"
|
---|
| 20 | #include <FrameworkManager.h>
|
---|
[137] | 21 | #include <GroupBox.h>
|
---|
[3] | 22 | #include <SharedMem.h>
|
---|
| 23 | #include <sstream>
|
---|
| 24 |
|
---|
| 25 | using std::string;
|
---|
| 26 | using std::ostringstream;
|
---|
| 27 | using namespace flair::core;
|
---|
| 28 | using namespace flair::gui;
|
---|
| 29 |
|
---|
[15] | 30 | namespace flair {
|
---|
| 31 | namespace sensor {
|
---|
[3] | 32 |
|
---|
[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 |
|
---|
| 51 |
|
---|
| 52 | SimuCamera::~SimuCamera() {
|
---|
[15] | 53 | SafeStop();
|
---|
| 54 | Join();
|
---|
[151] | 55 | if(shmemReadBuf!=NULL) delete shmemReadBuf;
|
---|
[3] | 56 | }
|
---|
| 57 |
|
---|
[158] | 58 | string SimuCamera::ShMemName(uint32_t modelId,uint32_t deviceId) {
|
---|
| 59 | ostringstream dev_name;
|
---|
| 60 | dev_name << "simu" << modelId << "_cam_" << deviceId;
|
---|
| 61 | return dev_name.str().c_str();
|
---|
| 62 | }
|
---|
| 63 |
|
---|
[3] | 64 | void SimuCamera::Run(void) {
|
---|
[151] | 65 | Time time;
|
---|
[3] | 66 |
|
---|
[150] | 67 | // SetPeriodUS((uint32_t)(1000000. / data_rate->Value()));
|
---|
| 68 | shmem->ReaderReady();
|
---|
[3] | 69 |
|
---|
[15] | 70 | while (!ToBeStopped()) {
|
---|
[150] | 71 | // WaitPeriod();
|
---|
[3] | 72 |
|
---|
[150] | 73 | // if (data_rate->ValueChanged() == true) {
|
---|
| 74 | // SetPeriodUS((uint32_t)(1000000. / data_rate->Value()));
|
---|
| 75 | // }
|
---|
[3] | 76 |
|
---|
[15] | 77 | output->GetMutex();
|
---|
[144] | 78 | //blocking read
|
---|
[238] | 79 | if (shmem->Read(shmemReadBuf, buf_size, 1000000000)) { // remplacer copie par
|
---|
| 80 | // échange de pointeur sur
|
---|
| 81 | // double buffering
|
---|
[3] | 82 |
|
---|
[238] | 83 | output->ReleaseMutex();
|
---|
| 84 | memcpy(&time, shmemReadBuf + buf_size - sizeof(Time), sizeof(Time));
|
---|
| 85 | output->SetDataTime(time);
|
---|
| 86 |
|
---|
| 87 | ProcessUpdate(output);
|
---|
| 88 | } else {
|
---|
| 89 | output->ReleaseMutex();
|
---|
[271] | 90 | //Thread::Warn("Read Timeout\n");
|
---|
[238] | 91 | }
|
---|
[15] | 92 | }
|
---|
[3] | 93 | }
|
---|
| 94 |
|
---|
| 95 | } // end namespace sensor
|
---|
| 96 | } // end namespace flair
|
---|
[268] | 97 |
|
---|
| 98 | #endif |
---|