0.4.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
14namespace nm = NAV::NodeManager;
16
19
21
24{
25 LOG_TRACE("{}: called", name);
26
27 _hasConfig = true;
28 _guiConfigDefaultWindowSize = { 380, 70 };
29
31}
32
34{
35 LOG_TRACE("{}: called", nameId());
36}
37
39{
40 return "UbloxFile";
41}
42
43std::string NAV::UbloxFile::type() const
44{
45 return typeStatic();
46}
47
49{
50 return "Data Provider";
51}
52
54{
55 if (auto res = FileReader::guiConfig(".ubx,.*", { ".ubx" }, size_t(id), nameId()))
56 {
57 LOG_DEBUG("{}: Path changed to {}", nameId(), _path);
59 if (res == FileReader::PATH_CHANGED)
60 {
62 }
63 else
64 {
66 }
67 }
68}
69
70[[nodiscard]] json NAV::UbloxFile::save() const
71{
72 LOG_TRACE("{}: called", nameId());
73
74 json j;
75
76 j["FileReader"] = FileReader::save();
77
78 return j;
79}
80
82{
83 LOG_TRACE("{}: called", nameId());
84
85 if (j.contains("FileReader"))
86 {
87 FileReader::restore(j.at("FileReader"));
88 }
89}
90
92{
93 LOG_TRACE("{}: called", nameId());
94
95 _lastObsTime.reset();
96
98}
99
101{
102 LOG_TRACE("{}: called", nameId());
103
105}
106
108{
110
111 return true;
112}
113
114std::shared_ptr<const NAV::NodeData> NAV::UbloxFile::pollData()
115{
116 uint8_t i = 0;
117 std::unique_ptr<uart::protocol::Packet> packet = nullptr;
118 std::shared_ptr<UbloxObs> obs;
119 while (true)
120 {
121 while (!eof() && read(reinterpret_cast<char*>(&i), 1))
122 {
123 packet = _sensor.findPacket(i);
124
125 if (packet != nullptr)
126 {
127 break;
128 }
129 }
130
131 if (!packet || eof())
132 {
133 LOG_DEBUG("{}: End of file reached.", nameId());
134 return nullptr;
135 }
136
137 if (packet->getRawDataLength() == 0)
138 {
139 LOG_TRACE("{}: Packet has empty payload", nameId());
140 return nullptr;
141 }
142
143 obs = std::make_shared<UbloxObs>();
144 if (!vendor::ublox::decryptUbloxObs(obs, *packet, nameId())) { continue; };
145 if (packet->type() != uart::protocol::Packet::Type::TYPE_BINARY) { continue; };
146
147 if (!obs->insTime.empty())
148 {
149 _lastObsTime = obs->insTime;
150 }
151 else
152 {
153 if (!_lastObsTime.empty())
154 {
155 obs->insTime = _lastObsTime;
156 }
157 else
158 {
159 LOG_DATA("{}: Could not set valid time. Skipping package.", nameId());
160 continue;
161 }
162 }
163 break;
164 }
165
166 LOG_DATA("{}: [{}] Packet found [{}][{}]", nameId(), obs->insTime.toYMDHMS(GPST),
167 obs->msgClass, vendor::ublox::getStringFromMsgId(obs->msgClass, obs->msgId));
168
170 return obs;
171}
172
174{
175 LOG_TRACE("called for {}", nameId());
176
177 auto filestream = std::ifstream(getFilepath());
178
179 constexpr uint16_t BUFFER_SIZE = 10;
180
181 std::array<char, BUFFER_SIZE> buffer{};
182 if (filestream.good())
183 {
184 filestream.read(buffer.data(), BUFFER_SIZE);
185
186 if ((static_cast<uint8_t>(buffer.at(0)) == vendor::ublox::UbloxUartSensor::BINARY_SYNC_CHAR_1
187 && static_cast<uint8_t>(buffer.at(1)) == vendor::ublox::UbloxUartSensor::BINARY_SYNC_CHAR_2)
189 {
190 filestream.close();
191 LOG_DEBUG("{} has the file type: Binary", nameId());
192 return FileType::BINARY;
193 }
194 filestream.close();
195
196 LOG_ERROR("{} could not determine file type", nameId());
197 return FileType::NONE;
198 }
199
200 LOG_ERROR("{} could not open file {}", nameId(), getFilepath());
201 return FileType::NONE;
202}
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
Manages all Nodes.
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:395
ImVec2 _guiConfigDefaultWindowSize
Definition Node.hpp:410
Node(std::string name)
Constructor.
Definition Node.cpp:30
std::string nameId() const
Node name and id.
Definition Node.cpp:253
std::string name
Name of the Node.
Definition Node.hpp:395
bool doReinitialize(bool wait=false)
Asks the node worker to reinitialize the node.
Definition Node.cpp:350
void invokeCallbacks(size_t portIndex, const std::shared_ptr< const NodeData > &data)
Calls all registered callbacks on the specified output port.
Definition Node.cpp:180
bool _hasConfig
Flag if the config window should be shown.
Definition Node.hpp:413
~UbloxFile() override
Destructor.
Definition UbloxFile.cpp:33
static std::string typeStatic()
String representation of the Class Type.
Definition UbloxFile.cpp:38
void deinitialize() override
Deinitialize the node.
void guiConfig() override
ImGui config window which is shown on double click.
Definition UbloxFile.cpp:53
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:43
UbloxFile()
Default constructor.
Definition UbloxFile.cpp:22
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:70
static std::string category()
String representation of the Class Category.
Definition UbloxFile.cpp:48
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:81
bool resetNode() override
Resets the node. Moves the read cursor to the start.
bool initialize() override
Initialize the node.
Definition UbloxFile.cpp:91
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
OutputPin * CreateOutputPin(Node *node, 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.
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