| Line | Branch | Exec | Source |
|---|---|---|---|
| 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 "EspressifUtilities.hpp" | ||
| 10 | |||
| 11 | #include "util/Eigen.hpp" | ||
| 12 | #include "Navigation/Transformations/CoordinateFrames.hpp" | ||
| 13 | #include "util/Logger.hpp" | ||
| 14 | #include <cstring> | ||
| 15 | |||
| 16 | #include "util/Time/TimeBase.hpp" | ||
| 17 | #include "util/Vendor/VectorNav/BinaryOutputs/TimeOutputs.hpp" | ||
| 18 | |||
| 19 | ✗ | bool 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 | } | ||
| 56 |