diff --git a/scripts/logdecoder/Makefile b/scripts/logdecoder/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..b0b53f1bd7918199391c128e4d8939dbc358ac73 --- /dev/null +++ b/scripts/logdecoder/Makefile @@ -0,0 +1,14 @@ +BOARDCORE := ../../skyward-boardcore/ +OBSW := ../../src/boards/ + +all: + g++ -std=c++17 -O2 -o logdecoder logdecoder.cpp \ + -DCOMPILE_FOR_X86 \ + $(BOARDCORE)libs/tscpp/tscpp/stream.cpp \ + -I$(BOARDCORE)libs/mavlink-skyward-lib \ + -I$(BOARDCORE)libs/eigen \ + -I$(BOARDCORE)libs/tscpp \ + -I$(BOARDCORE)src/shared \ + -I$(OBSW) +clean: + rm logdecoder diff --git a/scripts/logdecoder/logdecoder b/scripts/logdecoder/logdecoder new file mode 100755 index 0000000000000000000000000000000000000000..77794097e0b8595ff84a11d850230f6f8ebb928b Binary files /dev/null and b/scripts/logdecoder/logdecoder differ diff --git a/scripts/logdecoder/logdecoder.cpp b/scripts/logdecoder/logdecoder.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1edf5fe55bad313be086f6ecbcd3ff1204b8c084 --- /dev/null +++ b/scripts/logdecoder/logdecoder.cpp @@ -0,0 +1,120 @@ +/* Copyright (c) 2018-2022 Skyward Experimental Rocketry + * Authors: Terrane Federico + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include <Main/Sensors/Pitot/PitotData.h> +#include <logger/Deserializer.h> +#include <logger/LogTypes.h> +#include <tscpp/stream.h> + +#include <fstream> +#include <iostream> +#include <stdexcept> +#include <string> + +/** + * @brief Binary log files decoder. + * + * This program is to compile for you computer and decodes binary log files + * through the tscpp library. + * + * In LogTypes.h there should be included all the classes you want to + * deserialize. + */ + +using namespace tscpp; +using namespace Boardcore; + +void registerTypes(Deserializer& ds) +{ + // Register all Boardcore types + LogTypes::registerTypes(ds); + + // Custom types + ds.registerType<PitotData>(); +} + +void showUsage(const string& cmdName) +{ + std::cerr << "Usage: " << cmdName << " {-a | <log_file_name> | -h}" + << "Options:\n" + << "\t-h,--help\t\tShow help message\n" + << "\t-a,--all Deserialize all logs in the current directory\n" + << std::endl; +} + +bool deserialize(string logName) +{ + std::cout << "Deserializing " << logName << "...\n"; + Deserializer d(logName); + LogTypes::registerTypes(d); + registerTypes(d); + + return d.deserialize(); +} + +bool deserializeAll() +{ + for (int i = 0; i < 100; i++) + { + char nextName[11]; + sprintf(nextName, "log%02d.dat", i); + struct stat st; + if (stat(nextName, &st) != 0) + continue; // File not found + // File found + if (!deserialize(string(nextName))) + return false; + } + return true; +} + +int main(int argc, char* argv[]) +{ + if (argc < 2) + { + showUsage(string(argv[0])); + return 1; // Error + } + + bool success = false; + string arg1 = string(argv[1]); + + // Help message + if (arg1 == "-h" || arg1 == "--help") + { + showUsage(string(argv[0])); + return 0; + } + + // File deserialization + if (arg1 == "-a" || arg1 == "--all") + success = deserializeAll(); + else + success = deserialize(arg1); + + // End + if (success) + std::cout << "Deserialization completed successfully\n"; + else + std::cout << "Deserialization ended with errors\n"; + return 0; +} diff --git a/src/boards/WindGallery/Buses.h b/src/boards/WindGallery/Buses.h deleted file mode 100644 index 2f3119e81f3fb7c178c02f7121915ff87f5ef15b..0000000000000000000000000000000000000000 --- a/src/boards/WindGallery/Buses.h +++ /dev/null @@ -1,58 +0,0 @@ -/* Copyright (c) 2022 Skyward Experimental Rocketry - * Author: Alberto Nidasio - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#pragma once - -#include <Singleton.h> -#include <drivers/spi/SPIBus.h> -#include <drivers/usart/USART.h> -#include <miosix.h> - -namespace WindGallery -{ - -struct Buses : public Boardcore::Singleton<Buses> -{ - friend class Boardcore::Singleton<Buses>; - - Boardcore::USART uart4; - Boardcore::SPIBus spi1; - Boardcore::SPIBus spi2; - -private: -#ifndef USE_MOCK_PERIPHERALS - Buses() - : uart4(UART4, Boardcore::USARTInterface::Baudrate::B115200), - spi1(SPI1), spi2(SPI2) - { - uart4.init(); - } -#else - Buses() - : uart4(UART4, Boardcore::USARTInterface::Baudrate::B115200), spi1({}), - spi2({}) - { - } -#endif -}; - -} // namespace WindGallery diff --git a/src/boards/WindGallery/Configs/SensorsConfig.h b/src/boards/WindGallery/Configs/SensorsConfig.h deleted file mode 100644 index bb5dd7fc9db91778584fa003bb717b7fe6a90b3b..0000000000000000000000000000000000000000 --- a/src/boards/WindGallery/Configs/SensorsConfig.h +++ /dev/null @@ -1,46 +0,0 @@ -/* Copyright (c) 2015-2021 Skyward Experimental Rocketry - * Authors: Luca Erbetta, Luca Conterio, Alberto Nidasio - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#pragma once - -#include <sensors/ADS1118/ADS1118.h> - -namespace WindGallery -{ - -namespace SensorsConfigs -{ - -static constexpr Boardcore::ADS1118::ADS1118Mux ADC_CH_PITOT_PORT = - Boardcore::ADS1118::MUX_AIN1_GND; -static constexpr Boardcore::ADS1118::ADS1118DataRate ADC_DR_PITOT_PORT = - Boardcore::ADS1118::DR_860; -static constexpr Boardcore::ADS1118::ADS1118Pga ADC_PGA_PITOT_PORT = - Boardcore::ADS1118::FSR_6_144; -static constexpr float ADC_REFERENCE_VOLTAGE = 5.0; - -// Sampling periods in milliseconds -static constexpr unsigned int SAMPLE_PERIOD_ADC_ADS1118 = 6; - -} // namespace SensorsConfigs - -} // namespace WindGallery diff --git a/src/boards/WindGallery/Configs/config.h b/src/boards/WindGallery/Configs/config.h deleted file mode 100644 index 38aaf9f6c0861a319004e2facf947918c19635a3..0000000000000000000000000000000000000000 --- a/src/boards/WindGallery/Configs/config.h +++ /dev/null @@ -1,27 +0,0 @@ -/* Copyright (c) 2022 Skyward Experimental Rocketry - * Author: Arturo Benedetti - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#pragma once - -static const float DEFAULT_REFERENCE_ALTITUDE = 1420.0f; -static const float DEFAULT_REFERENCE_PRESSURE = 85389.4f; -static const float DEFAULT_REFERENCE_TEMPERATURE = 288.15f; diff --git a/src/boards/WindGallery/Sensors/Sensors.cpp b/src/boards/WindGallery/Sensors/Sensors.cpp deleted file mode 100644 index 3a83880cdc0e00fb498f7d7149dff4435f05ffc9..0000000000000000000000000000000000000000 --- a/src/boards/WindGallery/Sensors/Sensors.cpp +++ /dev/null @@ -1,109 +0,0 @@ -/* Copyright (c) 2022 Skyward Experimental Rocketry - * Author: Alberto Nidasio - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "Sensors.h" - -#include <WindGallery/Buses.h> -#include <WindGallery/Configs/SensorsConfig.h> -#include <WindGallery/Configs/config.h> -#include <drivers/timer/TimestampTimer.h> - -using namespace std; -using namespace Boardcore; -using namespace WindGallery::SensorsConfigs; - -namespace WindGallery -{ - -bool Sensors::start() { return sensorManager->start(); } - -Sensors::Sensors() -{ - // Initialize all the sensors - ads1118Init(); - pitotPressureInit(); - - // Create the sensor manager - sensorManager = new SensorManager(sensorsMap); -} - -void Sensors::ads1118Init() -{ - SPIBusConfig spiConfig = ADS1118::getDefaultSPIConfig(); - spiConfig.clockDivider = SPI::ClockDivider::DIV_64; - - ADS1118::ADS1118Config config = ADS1118::ADS1118_DEFAULT_CONFIG; - config.bits.mode = ADS1118::ADS1118Mode::CONTINUOUS_CONV_MODE; - - ads1118 = - new ADS1118(Buses::getInstance().spi1, - miosix::sensors::ads1118::cs::getPin(), config, spiConfig); - - ads1118->enableInput(ADC_CH_PITOT_PORT, ADC_DR_PITOT_PORT, - ADC_PGA_PITOT_PORT); - - SensorInfo info("ADS1118", SAMPLE_PERIOD_ADC_ADS1118, - [&]() - { Logger::getInstance().log(ads1118->getLastSample()); }); - - sensorsMap.emplace(std::make_pair(ads1118, info)); - - LOG_INFO(logger, "ADS1118 setup done!"); -} - -void Sensors::pitotPressureInit() -{ - function<ADCData()> getVoltage( - bind(&ADS1118::getVoltage, ads1118, ADC_CH_PITOT_PORT)); - pitotPressure = new SSCDRRN015PDA(getVoltage, ADC_REFERENCE_VOLTAGE); - - SensorInfo info("PITOT", SAMPLE_PERIOD_ADC_ADS1118, - bind(&Sensors::pitotPressureCallback, this)); - - sensorsMap.emplace(std::make_pair(pitotPressure, info)); - - LOG_INFO(logger, "Pitot pressure sensor setup done!"); -} - -void Sensors::pitotPressureCallback() -{ - SSCDRRN015PDAData pressureData = pitotPressure->getLastSample(); - Logger::getInstance().log(pressureData); - - // In the reference code used, the first pressure parameter was measured by - // a different digital pressure sensor (MS5803). Here I used the value that - // has just been sampled - float rel_density = Aeroutils::relDensity( - pressureData.pressure, DEFAULT_REFERENCE_PRESSURE, - DEFAULT_REFERENCE_ALTITUDE, DEFAULT_REFERENCE_TEMPERATURE); - - if (rel_density != 0.0f) - { - float airspeed = sqrtf(2 * fabs(pressureData.pressure) / rel_density); - - aSpeedData = AirSpeedPitot{TimestampTimer::getTimestamp(), airspeed}; - - Logger::getInstance().log(aSpeedData); - } -} - -} // namespace WindGallery diff --git a/src/boards/WindGallery/Sensors/Sensors.h b/src/boards/WindGallery/Sensors/Sensors.h deleted file mode 100644 index 31f536f6ba21826504a5e90477cfde7f6f441234..0000000000000000000000000000000000000000 --- a/src/boards/WindGallery/Sensors/Sensors.h +++ /dev/null @@ -1,66 +0,0 @@ -/* Copyright (c) 2022 Skyward Experimental Rocketry - * Author: Alberto Nidasio - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#pragma once - -#include <diagnostic/PrintLogger.h> -#include <sensors/ADS1118/ADS1118.h> -#include <sensors/SensorManager.h> -#include <sensors/analog/pressure/honeywell/SSCDRRN015PDA.h> -#include <utils/AeroUtils/AeroUtils.h> - -namespace WindGallery -{ - -class Sensors : public Boardcore::Singleton<Sensors> -{ - friend Boardcore::Singleton<Sensors>; - -public: - Boardcore::ADS1118 *ads1118 = nullptr; - Boardcore::SSCDRRN015PDA *pitotPressure = nullptr; - - struct AirSpeedPitot - { - uint64_t timestamp; - float airspeed; - }; - - AirSpeedPitot aSpeedData; - - bool start(); - -private: - Sensors(); - - void ads1118Init(); - - void pitotPressureInit(); - void pitotPressureCallback(); - - Boardcore::SensorManager *sensorManager = nullptr; - Boardcore::SensorManager::SensorMap_t sensorsMap; - - Boardcore::PrintLogger logger = Boardcore::Logging::getLogger("sensors"); -}; - -} // namespace WindGallery diff --git a/src/entrypoints/Parafoil/logdecoder/LogTypes.h b/src/entrypoints/Parafoil/logdecoder/LogTypes.h index 8e7500d1a78eca01acfcd47ffde5cc7ebde778d6..e954a937497bb1057174d72aaae4247e73a5f2bc 100644 --- a/src/entrypoints/Parafoil/logdecoder/LogTypes.h +++ b/src/entrypoints/Parafoil/logdecoder/LogTypes.h @@ -94,7 +94,7 @@ void registerTypes(Deserializer& ds) registerType<BMX160Data>(ds); registerType<BMX160WithCorrectionData>(ds); registerType<BMX160GyroscopeCalibrationBiases>(ds); - registerType<BMX160Temperature>(ds); + registerType<BMX160TemperatureData>(ds); registerType<BMX160FifoStats>(ds); registerType<MS5803Data>(ds); registerType<MPXHZ6130AData>(ds);