0.5.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
14
17
19
30
32{
33 LOG_TRACE("{}: called", nameId());
34}
35
37{
38 return "EmlidFile";
39}
40
41std::string NAV::EmlidFile::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::EmlidFile::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
94}
95
97{
98 LOG_TRACE("{}: called", nameId());
99
101}
102
104{
106
107 return true;
108}
109
110std::shared_ptr<const NAV::NodeData> NAV::EmlidFile::pollData()
111{
112 uint8_t i = 0;
113 std::unique_ptr<uart::protocol::Packet> packet = nullptr;
114 while (!eof() && read(reinterpret_cast<char*>(&i), 1))
115 {
116 packet = _sensor.findPacket(i);
117
118 if (packet != nullptr)
119 {
120 break;
121 }
122 }
123
124 if (!packet)
125 {
126 return nullptr;
127 }
128
129 // Check if package is empty
130 if (packet->getRawDataLength() == 0)
131 {
132 return nullptr;
133 }
134
135 auto obs = std::make_shared<EmlidObs>();
136 vendor::emlid::decryptEmlidObs(obs, *packet);
137
138 if (obs->insTime.empty())
139 {
140 if (auto currentTime = util::time::GetCurrentInsTime();
141 !currentTime.empty())
142 {
143 obs->insTime = currentTime;
144 }
145 }
146
148 return obs;
149}
150
152{
153 LOG_TRACE("called for {}", nameId());
154
155 auto filestream = std::ifstream(getFilepath());
156
157 constexpr uint16_t BUFFER_SIZE = 10;
158
159 std::array<char, BUFFER_SIZE> buffer{};
160 if (filestream.good())
161 {
162 filestream.read(buffer.data(), BUFFER_SIZE);
163
164 if ((static_cast<uint8_t>(buffer.at(0)) == vendor::emlid::EmlidUartSensor::BINARY_SYNC_CHAR_1
165 && static_cast<uint8_t>(buffer.at(1)) == vendor::emlid::EmlidUartSensor::BINARY_SYNC_CHAR_2)
167 {
168 filestream.close();
169 LOG_DEBUG("{} has the file type: Binary", nameId());
170 return FileType::BINARY;
171 }
172 filestream.close();
173
174 LOG_ERROR("{} could not determine file type", nameId());
175 return FileType::NONE;
176 }
177
178 LOG_ERROR("{} could not open file {}", nameId(), getFilepath());
179 return FileType::NONE;
180}
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
Keeps track of the current real/simulation time.
EmlidFile()
Default constructor.
Definition EmlidFile.cpp:20
bool resetNode() override
Resets the node. Moves the read cursor to the start.
void deinitialize() override
Deinitialize the node.
Definition EmlidFile.cpp:96
bool initialize() override
Initialize the node.
Definition EmlidFile.cpp:89
static std::string typeStatic()
String representation of the Class Type.
Definition EmlidFile.cpp:36
~EmlidFile() override
Destructor.
Definition EmlidFile.cpp:31
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:51
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:79
json save() const override
Saves the node into a json object.
Definition EmlidFile.cpp:68
std::string type() const override
String representation of the Class Type.
Definition EmlidFile.cpp:41
static std::string category()
String representation of the Class Category.
Definition EmlidFile.cpp:46
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: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
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.
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