1 | // *********************************************************************
|
---|
2 | // created: 2007/11/13 - 16:49
|
---|
3 | // filename: DbtPlyAlascaManager.cpp
|
---|
4 | //
|
---|
5 | // author: Gerald Dherbomez
|
---|
6 | // Copyright Heudiasyc UMR UTC/CNRS 6599
|
---|
7 | //
|
---|
8 | // version: $Id: DbtPlyAlascaManager.cpp 1199 2012-08-01 08:51:24Z kurdejma $
|
---|
9 | //
|
---|
10 | // purpose:
|
---|
11 | // *********************************************************************
|
---|
12 |
|
---|
13 | #include "DbtPlyAlascaManager.h"
|
---|
14 |
|
---|
15 | #include <boost/assert.hpp>
|
---|
16 | #include <iostream>
|
---|
17 | #include <string>
|
---|
18 |
|
---|
19 | #include "kernel/Log.h"
|
---|
20 | #include "PacpusTools/ShMem.h"
|
---|
21 |
|
---|
22 | namespace pacpus {
|
---|
23 |
|
---|
24 | using namespace std;
|
---|
25 |
|
---|
26 | DECLARE_STATIC_LOGGER("pacpus.base.DbtPlyAlascaManager");
|
---|
27 |
|
---|
28 | /// Construction de la fabrique de composant DbtPlyAlascaManager
|
---|
29 | static ComponentFactory<DbtPlyAlascaManager> sFactory("DbtPlyAlascaManager");
|
---|
30 |
|
---|
31 | static const char * kAlaskaMemoryName = "alasca";
|
---|
32 |
|
---|
33 | //////////////////////////////////////////////////////////////////////////
|
---|
34 | /// Constructor.
|
---|
35 | DbtPlyAlascaManager::DbtPlyAlascaManager(QString name)
|
---|
36 | : DbtPlyFileManager(name)
|
---|
37 | {
|
---|
38 | LOG_TRACE("constructor(" << name << ")");
|
---|
39 |
|
---|
40 | mShMem = new ShMem(kAlaskaMemoryName, sizeof(ScanAlascaData));
|
---|
41 | }
|
---|
42 |
|
---|
43 | //////////////////////////////////////////////////////////////////////////
|
---|
44 | /// Destructor.
|
---|
45 | DbtPlyAlascaManager::~DbtPlyAlascaManager()
|
---|
46 | {
|
---|
47 | LOG_TRACE("destructor");
|
---|
48 | delete mShMem;
|
---|
49 | }
|
---|
50 |
|
---|
51 | //////////////////////////////////////////////////////////////////////////
|
---|
52 | /// Configure the component.
|
---|
53 | ComponentBase::COMPONENT_CONFIGURATION DbtPlyAlascaManager::configureComponent(XmlComponentConfig config)
|
---|
54 | {
|
---|
55 | DbtPlyFileManager::configureComponent(config);
|
---|
56 | mDataFilename = config.getProperty("binFile");
|
---|
57 |
|
---|
58 | return ComponentBase::CONFIGURED_OK;
|
---|
59 | }
|
---|
60 |
|
---|
61 | //////////////////////////////////////////////////////////////////////////
|
---|
62 | /// Starts the component.
|
---|
63 | void DbtPlyAlascaManager::startActivity()
|
---|
64 | {
|
---|
65 | mDataFilename = mEngine->getDataDir() + mDataFilename;
|
---|
66 |
|
---|
67 | mDataFile.open(mDataFilename.toLatin1().data(),std::ios_base::in|std::ios_base::binary);
|
---|
68 | if (!mDataFile) {
|
---|
69 | LOG_ERROR("cannot open file '" << mDataFilename << "'");
|
---|
70 | return;
|
---|
71 | }
|
---|
72 | DbtPlyFileManager::startActivity();
|
---|
73 | }
|
---|
74 |
|
---|
75 | //////////////////////////////////////////////////////////////////////////
|
---|
76 | /// Stops the component.
|
---|
77 | void DbtPlyAlascaManager::stopActivity()
|
---|
78 | {
|
---|
79 | DbtPlyFileManager::stopActivity();
|
---|
80 | mDataFile.close();
|
---|
81 | }
|
---|
82 |
|
---|
83 | //////////////////////////////////////////////////////////////////////////
|
---|
84 | /// processData
|
---|
85 | void DbtPlyAlascaManager::processData(road_time_t t, road_timerange_t tr, void * buffer)
|
---|
86 | {
|
---|
87 | if (!buffer) {
|
---|
88 | LOG_DEBUG("no data available: NULL buffer");
|
---|
89 | return;
|
---|
90 | }
|
---|
91 |
|
---|
92 | LOG_TRACE("sizeof(AlascaXT) = " << sizeof(AlascaXT));
|
---|
93 | BOOST_ASSERT(24 == sizeof(AlascaXT));
|
---|
94 | AlascaXT * alascaXT = static_cast<AlascaXT *>(buffer);
|
---|
95 |
|
---|
96 | // copy the values contained in the dbt file
|
---|
97 | mAlascaData.startAngle = alascaXT->startAngle;
|
---|
98 | mAlascaData.endAngle = alascaXT->endAngle;
|
---|
99 | mAlascaData.nbPoint = alascaXT->nbPoint;
|
---|
100 | mAlascaData.scannertype = alascaXT->scannertype;
|
---|
101 | mAlascaData.timeStart = alascaXT->timeStart;
|
---|
102 | mAlascaData.time = t;
|
---|
103 | mAlascaData.timerange = tr;
|
---|
104 |
|
---|
105 | // set the get pointer to the correct place
|
---|
106 | mDataFile.seekg(alascaXT->dataPos);
|
---|
107 |
|
---|
108 | // then copy the data contained in the binary file
|
---|
109 | for (size_t i = 0; i < mAlascaData.nbPoint; ++i) {
|
---|
110 | mDataFile.read(reinterpret_cast<char *>(&(mAlascaData.point[i].scannerId)), sizeof(uint8_t));
|
---|
111 | mDataFile.read(reinterpret_cast<char *>(&(mAlascaData.point[i].layerNumber)), sizeof(uint8_t));
|
---|
112 | mDataFile.read(reinterpret_cast<char *>(&(mAlascaData.point[i].echoNumber)), sizeof(uint8_t));
|
---|
113 | mDataFile.read(reinterpret_cast<char *>(&(mAlascaData.point[i].pointStatus)), sizeof(uint8_t));
|
---|
114 | mDataFile.read(reinterpret_cast<char *>(&(mAlascaData.point[i].x)), sizeof(int16_t));
|
---|
115 | mDataFile.read(reinterpret_cast<char *>(&(mAlascaData.point[i].y)), sizeof(int16_t));
|
---|
116 | mDataFile.read(reinterpret_cast<char *>(&(mAlascaData.point[i].z)), sizeof(int16_t));
|
---|
117 | mDataFile.read(reinterpret_cast<char *>(&(mAlascaData.point[i].width)), sizeof(uint16_t));
|
---|
118 | }
|
---|
119 |
|
---|
120 | // verify that the last value is the UTC magic word
|
---|
121 | int32_t utcMagicWord = 0;
|
---|
122 | mDataFile.read(reinterpret_cast<char *>(&(utcMagicWord)), sizeof(utcMagicWord));
|
---|
123 | if (UTC_MAGIC_WORD != utcMagicWord) {
|
---|
124 | LOG_WARN("corrupted data, do not use them!");
|
---|
125 | LOG_DEBUG("wrong magic word: EXPECTED=" << UTC_MAGIC_WORD << ", ACTUAL=" << utcMagicWord);
|
---|
126 | } else {
|
---|
127 | LOG_TRACE("writing scan");
|
---|
128 | mShMem->write(&mAlascaData, sizeof(ScanAlascaData));
|
---|
129 | }
|
---|
130 |
|
---|
131 | if (mVerbose) {
|
---|
132 | cout << "[ALASCA]:\t"
|
---|
133 | << "#points=" << mAlascaData.nbPoint << "\t"
|
---|
134 | << "timeStart=" << mAlascaData.timeStart << endl
|
---|
135 | ;
|
---|
136 | }
|
---|
137 | if (mVerbose >= 2) {
|
---|
138 | cout << "[ALASCA]:\t"
|
---|
139 | << "scannertype=" << (int) mAlascaData.scannertype << "\t"
|
---|
140 | << "startAngle=" << mAlascaData.startAngle << "\t"
|
---|
141 | << "endAngle=" << mAlascaData.endAngle << endl
|
---|
142 | ;
|
---|
143 | }
|
---|
144 | }
|
---|
145 |
|
---|
146 | //////////////////////////////////////////////////////////////////////////
|
---|
147 | /// Displays the graphical user interface (GUI)
|
---|
148 | void DbtPlyAlascaManager::displayUI()
|
---|
149 | {
|
---|
150 | LOG_WARN("GUI not implemented");
|
---|
151 |
|
---|
152 | // TODO
|
---|
153 | }
|
---|
154 |
|
---|
155 | } // namespace pacpus
|
---|