0.4.1
Loading...
Searching...
No Matches
EspressifUtilities.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
10
11#include "util/Eigen.hpp"
13#include "util/Logger.hpp"
14#include <cstring>
15
18
19bool NAV::vendor::espressif::decryptWiFiObs(const std::shared_ptr<NAV::WiFiObs>& obs, uart::protocol::Packet& packet, [[maybe_unused]] const std::string& nameId)
20{
21 obs->insTime = util::time::GetCurrentInsTime();
22 if (packet.type() == uart::protocol::Packet::Type::TYPE_BINARY)
23 {
24 packet.extractUint16(); // payloadLength
25 // Mac address
26 std::array<uint8_t, 6> mac{};
27 std::ranges::generate(mac, [&]() { return packet.extractUint8(); });
28 // Format the MAC address in the correct order (independent of compiler)
29 obs->macAddress = fmt::format("{:02X}:{:02X}:{:02X}:{:02X}:{:02X}:{:02X}",
30 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
31 std::ranges::transform(obs->macAddress, obs->macAddress.begin(), ::toupper); // Convert to uppercase
32 // Distance
33 int rtt = packet.extractInt32(); // Round trip time in picoseconds
34 obs->distance = static_cast<double>(rtt) * InsConst::C_AIR * 1e-12 / 2;
35 int rttStd = packet.extractInt32(); // Standard deviation of the round trip time in picoseconds
36 obs->distanceStd = static_cast<double>(rttStd) * InsConst::C_AIR * 1e-12 / 2;
37 // Time of measurement
38 InsTime_YMDHMS yearMonthDayHMS(packet.extractInt32(), packet.extractInt32(), packet.extractInt32(), packet.extractInt32(), packet.extractInt32(), packet.extractInt32());
39 InsTime timeOfMeasurement(yearMonthDayHMS, UTC);
40 [[maybe_unused]] uint32_t microseconds = packet.extractUint32();
41 obs->insTime = timeOfMeasurement + std::chrono::microseconds(microseconds);
42 // Time outputs
43 std::shared_ptr<vendor::vectornav::TimeOutputs> timeOutputs = std::make_shared<vendor::vectornav::TimeOutputs>();
44 obs->timeOutputs.syncInCnt = packet.extractUint32();
45 obs->timeOutputs.timeSyncIn = packet.extractUint64();
46 // Log the measurement details
47 LOG_DATA("WiFiObs mac Address: {}, measured distance: {}, time of measurement: {}", obs->macAddress, obs->distance, obs->insTime);
48 }
49 else
50 {
51 LOG_DATA("Received non-binary packet. Ignoring.");
52 return false;
53 }
54 return true;
55}
Transformation collection.
Vector space operations.
Helper Functions to work with Espressif Sensors.
Utility class for logging to console and file.
#define LOG_DATA
All output which occurs repeatedly every time observations are received.
Definition Logger.hpp:29
Keeps track of the current real/simulation time.
Binary Group 5 - Attitude Outputs.
static constexpr double C_AIR
Speed of light in air: CGPM defined speed of light divided by approximate refractory index of dry air...
Definition Constants.hpp:37
The class is responsible for all time-related tasks.
Definition InsTime.hpp:710
bool decryptWiFiObs(const std::shared_ptr< NAV::WiFiObs > &obs, uart::protocol::Packet &packet, const std::string &nameId)
Decrypts the provided Espressif observation.
@ UTC
Coordinated Universal Time.
Universal Time Coordinated [UTC].
Definition InsTime.hpp:465