0.4.1
Loading...
Searching...
No Matches
EmlidFile.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 "EmlidFile.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 "EmlidFile";
41}
42
43std::string NAV::EmlidFile::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::EmlidFile::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
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::EmlidFile::pollData()
113{
114 uint8_t i = 0;
115 std::unique_ptr<uart::protocol::Packet> packet = nullptr;
116 while (!eof() && read(reinterpret_cast<char*>(&i), 1))
117 {
118 packet = _sensor.findPacket(i);
119
120 if (packet != nullptr)
121 {
122 break;
123 }
124 }
125
126 if (!packet)
127 {
128 return nullptr;
129 }
130
131 // Check if package is empty
132 if (packet->getRawDataLength() == 0)
133 {
134 return nullptr;
135 }
136
137 auto obs = std::make_shared<EmlidObs>();
138 vendor::emlid::decryptEmlidObs(obs, *packet);
139
140 if (obs->insTime.empty())
141 {
142 if (auto currentTime = util::time::GetCurrentInsTime();
143 !currentTime.empty())
144 {
145 obs->insTime = currentTime;
146 }
147 }
148
150 return obs;
151}
152
154{
155 LOG_TRACE("called for {}", nameId());
156
157 auto filestream = std::ifstream(getFilepath());
158
159 constexpr uint16_t BUFFER_SIZE = 10;
160
161 std::array<char, BUFFER_SIZE> buffer{};
162 if (filestream.good())
163 {
164 filestream.read(buffer.data(), BUFFER_SIZE);
165
166 if ((static_cast<uint8_t>(buffer.at(0)) == vendor::emlid::EmlidUartSensor::BINARY_SYNC_CHAR_1
167 && static_cast<uint8_t>(buffer.at(1)) == vendor::emlid::EmlidUartSensor::BINARY_SYNC_CHAR_2)
169 {
170 filestream.close();
171 LOG_DEBUG("{} has the file type: Binary", nameId());
172 return FileType::BINARY;
173 }
174 filestream.close();
175
176 LOG_ERROR("{} could not determine file type", nameId());
177 return FileType::NONE;
178 }
179
180 LOG_ERROR("{} could not open file {}", nameId(), getFilepath());
181 return FileType::NONE;
182}
File Reader for Emlid log files.
Emlid Observation Class.
Helper Functions to work with Emlid Sensors.
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_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.
EmlidFile()
Default constructor.
Definition EmlidFile.cpp:22
bool resetNode() override
Resets the node. Moves the read cursor to the start.
void deinitialize() override
Deinitialize the node.
Definition EmlidFile.cpp:98
bool initialize() override
Initialize the node.
Definition EmlidFile.cpp:91
static std::string typeStatic()
String representation of the Class Type.
Definition EmlidFile.cpp:38
~EmlidFile() override
Destructor.
Definition EmlidFile.cpp:33
static constexpr size_t OUTPUT_PORT_INDEX_EMLID_OBS
Flow (EmlidObs)
Definition EmlidFile.hpp:64
void guiConfig() override
ImGui config window which is shown on double click.
Definition EmlidFile.cpp:53
FileType determineFileType() override
Determines the type of the file.
std::shared_ptr< const NodeData > pollData()
Polls data from the file.
vendor::emlid::EmlidUartSensor _sensor
Sensor Object.
Definition EmlidFile.hpp:81
void restore(const json &j) override
Restores the node from a json object.
Definition EmlidFile.cpp:81
json save() const override
Saves the node into a json object.
Definition EmlidFile.cpp:70
std::string type() const override
String representation of the Class Type.
Definition EmlidFile.cpp:43
static std::string category()
String representation of the Class Category.
Definition EmlidFile.cpp:48
static std::string type()
Returns the type of the data class.
Definition EmlidObs.hpp:30
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
static constexpr uint8_t BINARY_SYNC_CHAR_2
E - 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
R - 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.
void decryptEmlidObs(const std::shared_ptr< NAV::EmlidObs > &obs, uart::protocol::Packet &packet)
Decrypts the provided Emlid observation.
@ Flow
NodeData Trigger.
Definition Pin.hpp:52