1 | /*********************************************************************
|
---|
2 | // created: 2011/04/26
|
---|
3 | // filename: DbtRawCanReader.cpp
|
---|
4 | //
|
---|
5 | // author: Gerald Dherbomez
|
---|
6 | // Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
7 | //
|
---|
8 | // version: $Id: DbtRawCanReader.cpp 1182 2012-07-05 16:42:32Z kurdejma $
|
---|
9 | //
|
---|
10 | // purpose:
|
---|
11 | *********************************************************************/
|
---|
12 |
|
---|
13 |
|
---|
14 | #include "Pacpus/kernel/ComponentFactory.h"
|
---|
15 | #include "Pacpus/kernel/DbiteFileTypes.h"
|
---|
16 | #include "Pacpus/kernel/Log.h"
|
---|
17 |
|
---|
18 | #include "Pacpus/kernel/road_time.h"
|
---|
19 |
|
---|
20 | using namespace pacpus;
|
---|
21 | using namespace std;
|
---|
22 |
|
---|
23 | #include "DbtRawCanReader.h"
|
---|
24 |
|
---|
25 | DECLARE_STATIC_LOGGER("pacpus.base.DbtRawCanReader");
|
---|
26 |
|
---|
27 | /// Component factory for DbtRawCanReader
|
---|
28 | static ComponentFactory<DbtRawCanReader> sFactory("DbtRawCanReader");
|
---|
29 |
|
---|
30 | /// Constructor
|
---|
31 | DbtRawCanReader::DbtRawCanReader(QString name)
|
---|
32 | : ComponentBase(name)
|
---|
33 | {
|
---|
34 | }
|
---|
35 |
|
---|
36 | /// Destructor
|
---|
37 | DbtRawCanReader::~DbtRawCanReader()
|
---|
38 | {
|
---|
39 | }
|
---|
40 |
|
---|
41 | /// Configures the component
|
---|
42 | ComponentBase::COMPONENT_CONFIGURATION DbtRawCanReader::configureComponent(XmlComponentConfig config)
|
---|
43 | {
|
---|
44 | dbtFileName_ = config.getProperty("dbt");
|
---|
45 |
|
---|
46 | return ComponentBase::CONFIGURED_OK;
|
---|
47 | }
|
---|
48 |
|
---|
49 | /// Starts the component
|
---|
50 | void DbtRawCanReader::startActivity()
|
---|
51 | {
|
---|
52 | start();
|
---|
53 | }
|
---|
54 |
|
---|
55 | /// Stops the component
|
---|
56 | void DbtRawCanReader::stopActivity()
|
---|
57 | {
|
---|
58 |
|
---|
59 | }
|
---|
60 |
|
---|
61 | void DbtRawCanReader::run()
|
---|
62 | {
|
---|
63 | road_time_t time;
|
---|
64 | road_timerange_t tr;
|
---|
65 | CanFrame dbtData;
|
---|
66 | TimestampedCanFrame dataToDecode;
|
---|
67 |
|
---|
68 | // create the DBT file
|
---|
69 | dbtFile_.open(dbtFileName_.toStdString(), ReadMode);
|
---|
70 |
|
---|
71 | LOG_INFO("DBT file opened for reading");
|
---|
72 |
|
---|
73 | for (;;)
|
---|
74 | {
|
---|
75 | if ( !dbtFile_.readRecord(time, tr, reinterpret_cast<char *>(&dbtData) ) )
|
---|
76 | break;
|
---|
77 | dataToDecode.frame = dbtData;
|
---|
78 | dataToDecode.time = time;
|
---|
79 | dataToDecode.timerange = tr;
|
---|
80 |
|
---|
81 | dispatchCanFrame(dataToDecode);
|
---|
82 | }
|
---|
83 |
|
---|
84 | LOG_INFO("reading finished");
|
---|
85 |
|
---|
86 | dbtFile_.close();
|
---|
87 |
|
---|
88 | }
|
---|