source: pacpussensors/trunk/StdDbtPlayerComponents/DbtPlySickLDMRSManager.cpp@ 50

Last change on this file since 50 was 50, checked in by phudelai, 10 years ago

Flea3Component: Shared memory changed for stereovision
StereoVisionDisparity: Added for the PFE of Pierre

File size: 5.2 KB
Line 
1// *********************************************************************
2// created: 1014/03/27 - 11:37
3// filename: DbtPlySickLDMRSManager.cpp
4//
5// authors: Gerald Dherbomez, Cyril Fougeray
6// Copyright Heudiasyc UMR UTC/CNRS 6599
7//
8// version: $Id$
9//
10// purpose:
11// *********************************************************************
12
13#include "DbtPlySickLDMRSManager.h"
14
15#include <boost/assert.hpp>
16#include <iostream>
17#include <string>
18
19#include "Pacpus/kernel/Log.h"
20#include "Pacpus/PacpusTools/ShMem.h"
21
22
23#define UTC_MAGIC_WORD 0x55544300
24
25
26namespace pacpus {
27
28using namespace std;
29
30DECLARE_STATIC_LOGGER("pacpus.base.DbtPlySickLDMRSManager");
31
32/// Construction de la fabrique de composant DbtPlySickLDMRSManager
33static ComponentFactory<DbtPlySickLDMRSManager> sFactory("DbtPlySickLDMRSManager");
34
35static const char * kSickMemoryName = "sickLDMRS";
36
37//////////////////////////////////////////////////////////////////////////
38/// Constructor.
39DbtPlySickLDMRSManager::DbtPlySickLDMRSManager(QString name)
40 : DbtPlyFileManager(name)
41{
42 LOG_TRACE("constructor(" << name << ")");
43
44 // mShMem = new ShMem(kAlaskaMemoryName, sizeof(ScanSickData));
45}
46
47//////////////////////////////////////////////////////////////////////////
48/// Destructor.
49DbtPlySickLDMRSManager::~DbtPlySickLDMRSManager()
50{
51 LOG_TRACE("destructor");
52 // delete mShMem;
53}
54
55//////////////////////////////////////////////////////////////////////////
56/// Configure the component.
57ComponentBase::COMPONENT_CONFIGURATION DbtPlySickLDMRSManager::configureComponent(XmlComponentConfig config)
58{
59 DbtPlyFileManager::configureComponent(config);
60
61 mDataFilename = param.getProperty("binFile");
62
63 return ComponentBase::CONFIGURED_OK;
64}
65
66//////////////////////////////////////////////////////////////////////////
67/// Starts the component.
68void DbtPlySickLDMRSManager::startActivity()
69{
70 // QString dataDir = mEngine->getDataDir();
71
72 // for (int i = 0; i < mDataFilenameList.size(); ++i) {
73 // QString file = mDataFilenameList.at(i);
74 // mDataFilenameList[i] = dataDir + file;
75
76 LOG_TRACE("DbtPlySickLDMRSManager component is starting.");
77
78 mDataFilename = mEngine->getDataDir() + mDataFilename;
79
80 LOG_TRACE("Opening "<< mDataFilename);
81
82 mDataFile.open(mDataFilename.toLatin1().data(),std::ios_base::in|std::ios_base::binary);
83 if (!mDataFile) {
84 LOG_ERROR("cannot open file '" << mDataFilename << "'");
85 return;
86 }
87 // }
88 DbtPlyFileManager::startActivity();
89}
90
91//////////////////////////////////////////////////////////////////////////
92/// Stops the component.
93void DbtPlySickLDMRSManager::stopActivity()
94{
95 DbtPlyFileManager::stopActivity();
96 mDataFile.close();
97}
98
99//////////////////////////////////////////////////////////////////////////
100/// processData
101void DbtPlySickLDMRSManager::processData(road_time_t t, road_timerange_t tr, void * buffer)
102{
103 if (!buffer) {
104 LOG_DEBUG("no data available: NULL buffer");
105 return;
106 }
107
108 LOG_TRACE("sizeof(sickLDMRS_dbt) = " << sizeof(SickLDMRS_dbt));
109 // BOOST_ASSERT(88 == sizeof(SickLMS_dbt));
110 SickLDMRS_dbt * sickLDMRS_dbt = static_cast<SickLDMRS_dbt *>(buffer);
111
112 // // copy the values contained in the dbt file
113 mSickDbt.timeStartFromSensor = sickLDMRS_dbt->timeStartFromSensor;
114 mSickDbt.hScan = sickLDMRS_dbt->hScan;
115 mSickDbt.dataPos = sickLDMRS_dbt->dataPos;
116 mSickDbt.time = t;
117 mSickDbt.timerange = tr;
118
119 LOG_TRACE("Number of points " << mSickDbt.hScan.numPoints);
120
121 LOG_TRACE("Reading UTC file ... ");
122
123 mDataFile.seekg(mSickDbt.dataPos); // set the get pointer to the correct place
124
125 ScanPoint* points = (ScanPoint*) malloc(mSickDbt.hScan.numPoints * sizeof(ScanPoint));
126
127 // then copy the data contained in the binary file
128 for (unsigned int i = 0 ; i < mSickDbt.hScan.numPoints ; ++i) {
129 mDataFile.read(reinterpret_cast<char *>(&(points[i])), sizeof(ScanPoint));
130 }
131
132
133 // verify that the last value is the UTC magic word
134 int32_t utcMagicWord = 0;
135 mDataFile.read(reinterpret_cast<char *>(&(utcMagicWord)), sizeof(int32_t));
136 if (UTC_MAGIC_WORD != utcMagicWord) {
137 LOG_WARN("corrupted data, do not use them!");
138 LOG_DEBUG("wrong magic word: EXPECTED=" << UTC_MAGIC_WORD << ", ACTUAL=" << utcMagicWord);
139 } else {
140 LOG_TRACE("writing scan ");
141 LOG_WARN("NOT YET IMPLEMENTED");
142 // mShMem->write(&mSickDbt, sizeof(SickLMS_dbt));
143
144 /**********************************/
145 /* TODO : Send data ! */
146 /**********************************/
147 }
148
149 if (mVerbose) {
150 cout << "[SICK LDMRS]:\t"
151 << "numPoints=" << mSickDbt.hScan.numPoints << "\t"
152 << "time=" << t << endl
153 ;
154 }
155 if (mVerbose >= 2) {
156 cout << "[SICK LDMRS]:\t"
157 << "startAngle=" << mSickDbt.hScan.startAngle << "\t"
158 << "endAngle=" << mSickDbt.hScan.endAngle << std::endl ;
159 }
160 free(points);
161}
162
163//////////////////////////////////////////////////////////////////////////
164/// Displays the graphical user interface (GUI)
165void DbtPlySickLDMRSManager::displayUI()
166{
167 LOG_WARN("GUI not implemented");
168
169 // TODO
170}
171
172} // namespace pacpus
Note: See TracBrowser for help on using the repository browser.