48 return "Data Provider";
72 if (ImGui::BeginTable(fmt::format(
"##VectorNavHeaders ({})",
id.AsPointer()).c_str(), 2,
73 ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg))
75 ImGui::TableSetupColumn(
"Basic", ImGuiTableColumnFlags_WidthFixed);
76 ImGui::TableSetupColumn(
"IMU", ImGuiTableColumnFlags_WidthFixed);
77 ImGui::TableHeadersRow();
79 auto TextColoredIfExists = [
this](
int index,
const char* displayText,
const char* searchText,
bool alwaysNormal =
false) {
80 ImGui::TableSetColumnIndex(index);
83 ImGui::TextUnformatted(displayText);
87 ImGui::TextDisabled(
"%s", displayText);
91 ImGui::TableNextRow();
92 TextColoredIfExists(0,
"GpsTime",
"GpsToW [s]");
93 TextColoredIfExists(1,
"UnCompMag",
"UnCompMagX [Gauss]");
94 ImGui::TableNextRow();
95 TextColoredIfExists(0,
"TimeStartup",
"TimeStartup [ns]");
96 TextColoredIfExists(1,
"UnCompAcc",
"UnCompAccX [m/s^2]");
97 ImGui::TableNextRow();
98 TextColoredIfExists(0,
"Temperature",
"Temperature [Celsius]");
99 TextColoredIfExists(1,
"UnCompGyro",
"UnCompGyroX [rad/s]");
100 ImGui::TableNextRow();
101 TextColoredIfExists(0,
"Status",
"Status");
102 ImGui::TableNextRow();
103 TextColoredIfExists(0,
"SequenceNumber",
"SequenceNumber");
110 ImGui::TextUnformatted(
"Binary file");
130 if (j.contains(
"FileReader"))
134 if (j.contains(
"Imu"))
163 std::shared_ptr<KvhObs> obs =
nullptr;
168 std::unique_ptr<uart::protocol::Packet> packet =
nullptr;
169 while (!
eof() &&
read(
reinterpret_cast<char*
>(&i), 1))
171 packet =
_sensor.findPacket(i);
173 if (packet !=
nullptr)
184 obs = std::make_shared<KvhObs>(
_imuPos, *packet);
187 if (obs->raw.getRawDataLength() == 0)
196 obs = std::make_shared<KvhObs>(
_imuPos);
202 line.erase(line.begin(), std::ranges::find_if(line, [](
int ch) { return std::isgraph(ch); }));
210 std::stringstream lineStream(line);
213 std::optional<uint16_t> gpsCycle = 0;
214 std::optional<uint16_t> gpsWeek;
215 std::optional<long double> gpsToW;
216 std::optional<double> magX;
217 std::optional<double> magY;
218 std::optional<double> magZ;
219 std::optional<double> accelX;
220 std::optional<double> accelY;
221 std::optional<double> accelZ;
222 std::optional<double> gyroX;
223 std::optional<double> gyroY;
224 std::optional<double> gyroZ;
229 if (std::getline(lineStream, cell,
','))
232 cell.erase(std::ranges::find_if(cell, [](
int ch) {
return std::iscntrl(ch); }), cell.end());
238 if (column ==
"GpsCycle")
240 gpsCycle =
static_cast<uint16_t
>(std::stoul(cell));
242 else if (column ==
"GpsWeek")
244 gpsWeek =
static_cast<uint16_t
>(std::stoul(cell));
246 else if (column ==
"GpsToW [s]")
248 gpsToW = std::stold(cell);
250 else if (column ==
"MagX [Gauss]")
252 magX = std::stod(cell);
254 else if (column ==
"MagY [Gauss]")
256 magY = std::stod(cell);
258 else if (column ==
"MagZ [Gauss]")
260 magZ = std::stod(cell);
262 else if (column ==
"AccX [m/s^2]")
264 accelX = std::stod(cell);
266 else if (column ==
"AccY [m/s^2]")
268 accelY = std::stod(cell);
270 else if (column ==
"AccZ [m/s^2]")
272 accelZ = std::stod(cell);
274 else if (column ==
"GyroX [rad/s]")
276 gyroX = std::stod(cell);
278 else if (column ==
"GyroY [rad/s]")
280 gyroY = std::stod(cell);
282 else if (column ==
"GyroZ [rad/s]")
284 gyroZ = std::stod(cell);
286 else if (column ==
"Temperature [Celsius]")
288 obs->temperature.emplace(std::stod(cell));
290 else if (column ==
"Status")
292 obs->status = std::bitset<8>{ cell };
294 else if (column ==
"SequenceNumber")
296 obs->sequenceNumber =
static_cast<uint8_t
>(std::stoul(cell));
301 if (!gpsCycle || !gpsWeek || !gpsToW)
303 LOG_ERROR(
"{}: Fields 'GpsCycle', 'GpsWeek', 'GpsToW [s]' are needed.",
nameId());
306 if (!accelX || !accelY || !accelZ)
308 LOG_ERROR(
"{}: Fields 'AccX [m/s^2]', 'AccY [m/s^2]', 'AccZ [m/s^2]' are needed.",
nameId());
311 if (!gyroX || !gyroY || !gyroZ)
313 LOG_ERROR(
"{}: Fields 'GyroX [rad/s]', 'GyroY [rad/s]', 'GyroZ [rad/s]' are needed.",
nameId());
316 obs->insTime =
InsTime(gpsCycle.value(), gpsWeek.value(), gpsToW.value());
317 obs->p_acceleration = { accelX.value(), accelY.value(), accelZ.value() };
318 obs->p_angularRate = { gyroX.value(), gyroY.value(), gyroZ.value() };
320 if (magX && magY && magZ)
322 obs->p_magneticField.emplace(magX.value(), magY.value(), magZ.value());
326 LOG_DATA(
"DATA({}): {}, {}, {}, {}, {}",
name, obs->sequenceNumber, obs->temperature.value(),
327 obs->p_acceleration.x(), obs->p_acceleration.y(), obs->p_acceleration.z());
352 if (filestream.good())
356 std::array<char, 4> buffer;
360 if (filestream.readsome(un.buffer.data(),
sizeof(uint32_t)) ==
sizeof(uint32_t))
373 filestream.seekg(0, std::ios_base::beg);
375 std::getline(filestream, line);
378 auto n = std::ranges::count(line,
',');
nlohmann::json json
json namespace
File Reader for Kvh log files.
Data storage class for one KVH Imu observation.
Helper Functions to work with Kvh Sensors.
Utility class for logging to console and file.
#define LOG_DEBUG
Debug information. Should not be called on functions which receive observations (spamming)
#define LOG_DATA
All output which occurs repeatedly every time observations are received.
#define LOG_ERROR
Error occurred, which stops part of the program to work, but not everything.
#define LOG_WARN
Error occurred, but a fallback option exists and program continues to work normally.
#define LOG_TRACE
Detailled info to trace the execution of the program. Should not be called on functions which receive...
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.
FileType _fileType
File Type.
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.
std::vector< std::string > _headerColumns
Header Columns of a CSV file.
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.
auto & getline(std::string &str)
Reads a line from the filestream.
json save() const
Saves the node into a json object.
void deinitialize()
Deinitialize the file reader.
json save() const override
Saves the node into a json object.
void restore(const json &j) override
Restores the node from a json object.
void guiConfig() override
ImGui config window which is shown on double click.
Imu(const Imu &)=delete
Copy constructor.
ImuPos _imuPos
Position and rotation information for conversion from platform to body frame.
The class is responsible for all time-related tasks.
static constexpr size_t OUTPUT_PORT_INDEX_KVH_OBS
Flow (KvhObs)
~KvhFile() override
Destructor.
KvhFile()
Default constructor.
static std::string typeStatic()
String representation of the Class Type.
bool resetNode() override
Resets the node. Moves the read cursor to the start.
void deinitialize() override
Deinitialize the node.
uint8_t _prevSequenceNumber
Previous Sequence number to check for order errors.
void restore(const json &j) override
Restores the node from a json object.
static std::string category()
String representation of the Class Category.
vendor::kvh::KvhUartSensor _sensor
Sensor Object.
void guiConfig() override
ImGui config window which is shown on double click.
FileType determineFileType() override
Determines the type of the file.
std::shared_ptr< const NodeData > pollData()
Polls data from the file.
std::string type() const override
String representation of the Class Type.
json save() const override
Saves the node into a json object.
bool initialize() override
Initialize the node.
static std::string type()
Returns the type of the data class.
bool doDeinitialize(bool wait=false)
Asks the node worker to deinitialize the node.
ImVec2 _guiConfigDefaultWindowSize
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.
bool callbacksEnabled
Enables the callbacks.
std::string nameId() const
Node name and id.
std::string name
Name of the Node.
bool doReinitialize(bool wait=false)
Asks the node worker to reinitialize the node.
void invokeCallbacks(size_t portIndex, const std::shared_ptr< const NodeData > &data)
Calls all registered callbacks on the specified output port.
bool _hasConfig
Flag if the config window should be shown.
static constexpr uint32_t HEADER_FMT_XBIT2
Header Format X Bit 2.
static constexpr uint32_t HEADER_FMT_A
Header Format A.
static constexpr uint32_t HEADER_FMT_B
Header Format B.
static constexpr uart::Endianness ENDIANNESS
Endianess of the sensor.
static constexpr uint32_t HEADER_FMT_C
Header Format C.
static constexpr uint32_t HEADER_FMT_XBIT
Header Format X Bit.
void ApplyChanges()
Signals that there have been changes to the flow.
void decryptKvhObs(const std::shared_ptr< NAV::KvhObs > &obs)
Decrypts the provided Kvh observation.