0.5.1
Loading...
Searching...
No Matches
UbloxFile.cpp
Go to the documentation of this file.
1// This file is part of INSTINCT, the INS Toolkit for Integrated
2// Navigation Concepts and Training by the Institute of Navigation of
3// the University of Stuttgart, Germany.
4//
5// This Source Code Form is subject to the terms of the Mozilla Public
6// License, v. 2.0. If a copy of the MPL was not distributed with this
7// file, You can obtain one at https://mozilla.org/MPL/2.0/.
8
9#include "UbloxFile.hpp"
10
11#include "util/Logger.hpp"
12
14
17
19
30
32{
33 LOG_TRACE("{}: called", nameId());
34}
35
37{
38 return "UbloxFile";
39}
40
41std::string NAV::UbloxFile::type() const
42{
43 return typeStatic();
44}
45
47{
48 return "Data Provider";
49}
50
52{
53 if (auto res = FileReader::guiConfig(".ubx,.*", { ".ubx" }, size_t(id), nameId()))
54 {
55 LOG_DEBUG("{}: Path changed to {}", nameId(), _path);
57 if (res == FileReader::PATH_CHANGED)
58 {
60 }
61 else
62 {
64 }
65 }
66}
67
68[[nodiscard]] json NAV::UbloxFile::save() const
69{
70 LOG_TRACE("{}: called", nameId());
71
72 json j;
73
74 j["FileReader"] = FileReader::save();
75
76 return j;
77}
78
80{
81 LOG_TRACE("{}: called", nameId());
82
83 if (j.contains("FileReader"))
84 {
85 FileReader::restore(j.at("FileReader"));
86 }
87}
88
90{
91 LOG_TRACE("{}: called", nameId());
92
93 _lastObsTime.reset();
94
96}
97
99{
100 LOG_TRACE("{}: called", nameId());
101
103}
104
106{
108
109 return true;
110}
111
112std::shared_ptr<const NAV::NodeData> NAV::UbloxFile::pollData()
113{
114 uint8_t i = 0;
115 std::unique_ptr<uart::protocol::Packet> packet = nullptr;
116 std::shared_ptr<UbloxObs> obs;
117 while (true)
118 {
119 while (!eof() && read(reinterpret_cast<char*>(&i), 1))
120 {
121 packet = _sensor.findPacket(i);
122
123 if (packet != nullptr)
124 {
125 break;
126 }
127 }
128
129 if (!packet || eof())
130 {
131 LOG_DEBUG("{}: End of file reached.", nameId());
132 return nullptr;
133 }
134
135 if (packet->getRawDataLength() == 0)
136 {
137 LOG_TRACE("{}: Packet has empty payload", nameId());
138 return nullptr;
139 }
140
141 obs = std::make_shared<UbloxObs>();
142 if (!vendor::ublox::decryptUbloxObs(obs, *packet, nameId())) { continue; };
143 if (packet->type() != uart::protocol::Packet::Type::TYPE_BINARY) { continue; };
144
145 if (!obs->insTime.empty())
146 {
147 _lastObsTime = obs->insTime;
148 }
149 else
150 {
151 if (!_lastObsTime.empty())
152 {
153 obs->insTime = _lastObsTime;
154 }
155 else
156 {
157 LOG_DATA("{}: Could not set valid time. Skipping package.", nameId());
158 continue;
159 }
160 }
161 break;
162 }
163
164 LOG_DATA("{}: [{}] Packet found [{}][{}]", nameId(), obs->insTime.toYMDHMS(GPST),
165 obs->msgClass, vendor::ublox::getStringFromMsgId(obs->msgClass, obs->msgId));
166
168 return obs;
169}
170
172{
173 LOG_TRACE("called for {}", nameId());
174
175 auto filestream = std::ifstream(getFilepath());
176
177 constexpr uint16_t BUFFER_SIZE = 10;
178
179 std::array<char, BUFFER_SIZE> buffer{};
180 if (filestream.good())
181 {
182 filestream.read(buffer.data(), BUFFER_SIZE);
183
184 if ((static_cast<uint8_t>(buffer.at(0)) == vendor::ublox::UbloxUartSensor::BINARY_SYNC_CHAR_1
185 && static_cast<uint8_t>(buffer.at(1)) == vendor::ublox::UbloxUartSensor::BINARY_SYNC_CHAR_2)
187 {
188 filestream.close();
189 LOG_DEBUG("{} has the file type: Binary", nameId());
190 return FileType::BINARY;
191 }
192 filestream.close();
193
194 LOG_ERROR("{} could not determine file type", nameId());
195 return FileType::NONE;
196 }
197
198 LOG_ERROR("{} could not open file {}", nameId(), getFilepath());
199 return FileType::NONE;
200}
Save/Load the Nodes.
nlohmann::json json
json namespace
Utility class for logging to console and file.
#define LOG_DEBUG
Debug information. Should not be called on functions which receive observations (spamming)
Definition Logger.hpp:67
#define LOG_DATA
All output which occurs repeatedly every time observations are received.
Definition Logger.hpp:29
#define LOG_ERROR
Error occurred, which stops part of the program to work, but not everything.
Definition Logger.hpp:73
#define LOG_TRACE
Detailled info to trace the execution of the program. Should not be called on functions which receive...
Definition Logger.hpp:65
Keeps track of the current real/simulation time.
File Reader for ubx files.
ublox Observation Class
Helper Functions to work with Ublox Sensors.
bool initialize()
Initialize the file reader.
void restore(const json &j)
Restores the node from a json object.
std::string _path
Path to the file.
FileType
File Type Enumeration.
@ BINARY
Binary data.
@ NONE
Not specified.
auto eof() const
Check whether the end of file is reached.
auto & read(char *__s, std::streamsize __n)
Extraction without delimiters.
std::filesystem::path getFilepath()
Returns the path of the file.
@ PATH_CHANGED
The path changed and exists.
GuiResult guiConfig(const char *vFilters, const std::vector< std::string > &extensions, size_t id, const std::string &nameId)
ImGui config.
void resetReader()
Moves the read cursor to the start.
json save() const
Saves the node into a json object.
void deinitialize()
Deinitialize the file reader.
bool doDeinitialize(bool wait=false)
Asks the node worker to deinitialize the node.
Definition Node.cpp:465
ImVec2 _guiConfigDefaultWindowSize
Definition Node.hpp:522
Node(std::string name)
Constructor.
Definition Node.cpp:29
OutputPin * CreateOutputPin(const char *name, Pin::Type pinType, const std::vector< std::string > &dataIdentifier, OutputPin::PinData data=static_cast< void * >(nullptr), int idx=-1)
Create an Output Pin object.
Definition Node.cpp:278
std::string nameId() const
Node name and id.
Definition Node.cpp:323
std::string name
Name of the Node.
Definition Node.hpp:507
bool doReinitialize(bool wait=false)
Asks the node worker to reinitialize the node.
Definition Node.cpp:420
void invokeCallbacks(size_t portIndex, const std::shared_ptr< const NodeData > &data)
Calls all registered callbacks on the specified output port.
Definition Node.cpp:179
bool _hasConfig
Flag if the config window should be shown.
Definition Node.hpp:525
~UbloxFile() override
Destructor.
Definition UbloxFile.cpp:31
static std::string typeStatic()
String representation of the Class Type.
Definition UbloxFile.cpp:36
void deinitialize() override
Deinitialize the node.
Definition UbloxFile.cpp:98
void guiConfig() override
ImGui config window which is shown on double click.
Definition UbloxFile.cpp:51
InsTime _lastObsTime
Last obs time.
Definition UbloxFile.hpp:84
vendor::ublox::UbloxUartSensor _sensor
Sensor Object.
Definition UbloxFile.hpp:81
std::string type() const override
String representation of the Class Type.
Definition UbloxFile.cpp:41
UbloxFile()
Default constructor.
Definition UbloxFile.cpp:20
static constexpr size_t OUTPUT_PORT_INDEX_UBLOX_OBS
Flow (UbloxObs)
Definition UbloxFile.hpp:64
std::shared_ptr< const NodeData > pollData()
Polls data from the file.
json save() const override
Saves the node into a json object.
Definition UbloxFile.cpp:68
static std::string category()
String representation of the Class Category.
Definition UbloxFile.cpp:46
FileType determineFileType() override
Determines the type of the file.
void restore(const json &j) override
Restores the node from a json object.
Definition UbloxFile.cpp:79
bool resetNode() override
Resets the node. Moves the read cursor to the start.
bool initialize() override
Initialize the node.
Definition UbloxFile.cpp:89
static std::string type()
Returns the type of the data class.
Definition UbloxObs.hpp:30
static constexpr uint8_t BINARY_SYNC_CHAR_2
b - Second sync character which begins a new binary message
static constexpr uint8_t ASCII_START_CHAR
Ascii character which begins a new ascii message.
static constexpr uint8_t BINARY_SYNC_CHAR_1
ยต - First sync character which begins a new binary message
void ApplyChanges()
Signals that there have been changes to the flow.
std::string getStringFromMsgId(UbxClass msgClass, uint8_t msgId)
Get the a string from a UBX Msg Id.
bool decryptUbloxObs(const std::shared_ptr< NAV::UbloxObs > &obs, uart::protocol::Packet &packet, const std::string &nameId)
Decrypts the provided Ublox observation.
@ GPST
GPS Time.
@ Flow
NodeData Trigger.
Definition Pin.hpp:52