diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 936095b11295b4afaad89e52fff50c3acd6ef35e..8e174a4bb077962864dcdfd7238fabbbcc9b5e37 100755 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -219,29 +219,6 @@ "${workspaceFolder}/skyward-boardcore/src/bsps/stm32f429zi_con_rig" ] }, - { - "name": "stm32f429zi_skyward_con_rig", - "cStandard": "c11", - "cppStandard": "c++14", - "compilerPath": "/opt/arm-miosix-eabi/bin/arm-miosix-eabi-g++", - "defines": [ - "{defaultDefines}", - "_MIOSIX_BOARDNAME=stm32f429zi_skyward_con_rig", - "_BOARD_STM32F429ZI_SKYWARD_CON_RIG", - "_ARCH_CORTEXM4_STM32F4", - "STM32F429xx", - "HSE_VALUE=8000000", - "SYSCLK_FREQ_168MHz=168000000", - "__ENABLE_XRAM", - "V_DDA_VOLTAGE=3.0f" - ], - "includePath": [ - "${defaultIncludePaths}", - "${workspaceFolder}/skyward-boardcore/libs/miosix-kernel/miosix/arch/cortexM4_stm32f4/common", - "${workspaceFolder}/skyward-boardcore/libs/miosix-kernel/miosix/arch/cortexM4_stm32f4/stm32f429zi_skyward_con_rig", - "${workspaceFolder}/skyward-boardcore/libs/miosix-kernel/miosix/config/arch/cortexM4_stm32f4/stm32f429zi_skyward_con_rig" - ] - }, { "name": "stm32f429zi_stm32f4discovery", "cStandard": "c11", diff --git a/CMakeLists.txt b/CMakeLists.txt index 12939a6d4daa4963cbc96ad021286d7379b591d6..e653dae887135ee1206bc11368ba96406226e108 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,6 +66,10 @@ add_executable(rig-entry src/entrypoints/RIG/rig-entry.cpp ${RIG_COMPUTER}) target_include_directories(rig-entry PRIVATE ${OBSW_INCLUDE_DIRS}) sbs_target(rig-entry stm32f429zi_rig) +add_executable(rig-v2-entry src/entrypoints/RIGv2/rig-v2-entry.cpp ${RIG_V2_COMPUTER}) +target_include_directories(rig-v2-entry PRIVATE ${OBSW_INCLUDE_DIRS}) +sbs_target(rig-v2-entry stm32f767zi_rig_v2) + add_executable(con_rig-entry src/entrypoints/con_RIG/con_rig-entry.cpp ${CON_RIG_COMPUTER}) target_include_directories(con_rig-entry PRIVATE ${OBSW_INCLUDE_DIRS}) sbs_target(con_rig-entry stm32f429zi_stm32f4discovery) diff --git a/cmake/dependencies.cmake b/cmake/dependencies.cmake index 6fc91baeb13787403ef4652b919668bbbd308569..2c5a04ec90aa89712d96eab6e46cd1f7b84da054 100644 --- a/cmake/dependencies.cmake +++ b/cmake/dependencies.cmake @@ -62,6 +62,10 @@ set(RIG_COMPUTER src/boards/RIG/StatesMonitor/StatesMonitor.cpp ) +set(RIG_V2_COMPUTER + src/boards/RIGv2/Sensors/Sensors.cpp +) + set(CON_RIG_COMPUTER src/boards/con_RIG/Buttons/Buttons.cpp src/boards/con_RIG/Radio/Radio.cpp diff --git a/src/boards/RIGv2/Buses.h b/src/boards/RIGv2/Buses.h new file mode 100644 index 0000000000000000000000000000000000000000..d4fbd3463c000b86123b49c34729b866e9dc2511 --- /dev/null +++ b/src/boards/RIGv2/Buses.h @@ -0,0 +1,53 @@ +/* Copyright (c) 2024 Skyward Experimental Rocketry + * Authors: Davide Mor + * + * 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 <drivers/spi/SPIBus.h> + +#include <utils/ModuleManager/ModuleManager.hpp> + +namespace RIGv2 +{ + +class Buses : public Boardcore::Module +{ +private: + Boardcore::SPIBus spi1; + Boardcore::SPIBus spi3; + Boardcore::SPIBus spi4; + Boardcore::SPIBus spi6; + +public: + Buses() : spi1(SPI1), spi3(SPI3), spi4(SPI4), spi6(SPI6) {} + + Boardcore::SPIBus &getH3LIS331DL() { return spi4; } + Boardcore::SPIBus &getLPS22DF() { return spi4; } + Boardcore::SPIBus &getLSM6DSRX() { return spi4; } + Boardcore::SPIBus &getLIS2MDL() { return spi4; } + Boardcore::SPIBus &getADS131M08_1() { return spi1; } + Boardcore::SPIBus &getADS131M08_2() { return spi3; } + Boardcore::SPIBus &getMAX31856_1() { return spi3; } + Boardcore::SPIBus &getMAX31856_2() { return spi1; } +}; + +} // namespace RIGv2 \ No newline at end of file diff --git a/src/boards/RIGv2/Configs/SensorsConfig.h b/src/boards/RIGv2/Configs/SensorsConfig.h new file mode 100644 index 0000000000000000000000000000000000000000..7f12a6710ae4fefbf0565566eeb55fd583d6b48e --- /dev/null +++ b/src/boards/RIGv2/Configs/SensorsConfig.h @@ -0,0 +1,42 @@ +/* Copyright (c) 2024 Skyward Experimental Rocketry + * Authors: Davide Mor + * + * 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 <cstdint> + +namespace RIGv2 +{ + +namespace Config +{ + +namespace Sensors +{ + +static constexpr uint32_t ADC_SAMPLE_PERIOD = 10; + +} + +} // namespace Config + +} // namespace RIGv2 \ No newline at end of file diff --git a/src/boards/RIGv2/Sensors/Sensors.cpp b/src/boards/RIGv2/Sensors/Sensors.cpp new file mode 100644 index 0000000000000000000000000000000000000000..07afb8e04f36fc8fc4097fea23dc29706bf8d87c --- /dev/null +++ b/src/boards/RIGv2/Sensors/Sensors.cpp @@ -0,0 +1,87 @@ +/* Copyright (c) 2024 Skyward Experimental Rocketry + * Authors: Davide Mor + * + * 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 <RIGv2/Buses.h> +#include <RIGv2/Configs/SensorsConfig.h> +#include <RIGv2/Sensors/SensorsData.h> +#include <interfaces-impl/hwmapping.h> + +using namespace Boardcore; +using namespace miosix; +using namespace RIGv2; + +bool Sensors::start() +{ + SensorManager::SensorMap_t map; + adc1Init(map); + + manager.reset(new SensorManager(map, &scheduler)); + return manager->start(); +} + +void Sensors::stop() { + manager->stop(); +} + +ADS131M08Data Sensors::getADC1LastSample() +{ + PauseKernelLock l; + return adc1->getLastSample(); +} + +void Sensors::adc1Init(SensorManager::SensorMap_t &map) +{ + ModuleManager &modules = ModuleManager::getInstance(); + + SPIBusConfig spiConfig = {}; + spiConfig.mode = SPI::Mode::MODE_0; + spiConfig.clockDivider = SPI::ClockDivider::DIV_32; + + ADS131M08::Config config = {}; + config.oversamplingRatio = ADS131M08Defs::OversamplingRatio::OSR_8192; + config.globalChopModeEnabled = true; + + adc1.reset(new ADS131M08(modules.get<Buses>()->getADS131M08_1(), + sensors::ADS131_1::cs::getPin(), spiConfig, + config)); + + SensorInfo info("ADS131M08_1", Config::Sensors::ADC_SAMPLE_PERIOD, + [this]() { adc1Callback(); }); + map.emplace(std::make_pair(adc1.get(), info)); +} + +void Sensors::adc1Callback() +{ + ADS131M08Data sample = adc1->getLastSample(); + + ADCsData data{sample.timestamp, 1, + sample.voltage[0], sample.voltage[1], + sample.voltage[2], sample.voltage[3], + sample.voltage[4], sample.voltage[5], + sample.voltage[6], sample.voltage[7]}; + + LOG_INFO(logger, "{}\t{}", sample.voltage[6], sample.voltage[7]); + + sdLogger.log(data); +} \ No newline at end of file diff --git a/src/boards/RIGv2/Sensors/Sensors.h b/src/boards/RIGv2/Sensors/Sensors.h new file mode 100644 index 0000000000000000000000000000000000000000..ec32a4674ae72d9c391a8b996afadf3431d2e494 --- /dev/null +++ b/src/boards/RIGv2/Sensors/Sensors.h @@ -0,0 +1,57 @@ +/* Copyright (c) 2024 Skyward Experimental Rocketry + * Authors: Davide Mor + * + * 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/ADS131M08/ADS131M08.h> +#include <sensors/SensorManager.h> + +#include <memory> +#include <utils/ModuleManager/ModuleManager.hpp> + +namespace RIGv2 +{ + +class Sensors : public Boardcore::Module +{ +public: + explicit Sensors(Boardcore::TaskScheduler &scheduler) : scheduler{scheduler} {} + + [[nodiscard]] bool start(); + + void stop(); + + Boardcore::ADS131M08Data getADC1LastSample(); + +private: + void adc1Init(Boardcore::SensorManager::SensorMap_t &map); + void adc1Callback(); + + Boardcore::Logger &sdLogger = Boardcore::Logger::getInstance(); + Boardcore::PrintLogger logger = Boardcore::Logging::getLogger("sensors"); + Boardcore::TaskScheduler &scheduler; + + std::unique_ptr<Boardcore::ADS131M08> adc1; + std::unique_ptr<Boardcore::SensorManager> manager; +}; + +} // namespace RIGv2 \ No newline at end of file diff --git a/src/boards/RIGv2/Sensors/SensorsData.h b/src/boards/RIGv2/Sensors/SensorsData.h new file mode 100644 index 0000000000000000000000000000000000000000..db59f9eef247763d23289271997f4bf8473fa3fc --- /dev/null +++ b/src/boards/RIGv2/Sensors/SensorsData.h @@ -0,0 +1,57 @@ +/* Copyright (c) 2024 Skyward Experimental Rocketry + * Authors: Davide Mor + * + * 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/ADS131M08/ADS131M08Data.h> + +namespace RIGv2 +{ +struct ADCsData : Boardcore::ADS131M08Data +{ + uint8_t adcNumber; + + ADCsData() : ADS131M08Data{0, 0, 0, 0, 0, 0, 0, 0, 0}, adcNumber{0} {} + + ADCsData(uint64_t time, uint8_t num, float ch1, float ch2, float ch3, + float ch4, float ch5, float ch6, float ch7, float ch8) + : ADS131M08Data{time, ch1, ch2, ch3, ch4, ch5, ch6, ch7, ch8}, + adcNumber{num} + { + } + + static std::string header() + { + return "timestamp,adc_number,voltage_channel_1,voltage_channel_2," + "voltage_channel_3,voltage_channel_4,voltage_channel_5,voltage_" + "channel_6,voltage_channel_7,voltage_channel_8\n"; + } + + void print(std::ostream& os) const + { + os << timestamp << "," << (int)adcNumber << "," << voltage[0] << "," + << voltage[1] << "," << voltage[2] << "," << voltage[3] << "," + << voltage[4] << "," << voltage[5] << "," << voltage[6] << "," + << voltage[7] << "\n"; + } +}; +} // namespace RIG \ No newline at end of file diff --git a/src/entrypoints/RIGv2/rig-v2-entry.cpp b/src/entrypoints/RIGv2/rig-v2-entry.cpp new file mode 100644 index 0000000000000000000000000000000000000000..08a75fcfd01f2b6d626d1e583190aaefe25a4f5b --- /dev/null +++ b/src/entrypoints/RIGv2/rig-v2-entry.cpp @@ -0,0 +1,85 @@ +/* Copyright (c) 2024 Skyward Experimental Rocketry + * Authors: Davide Mor + * + * 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 <RIGv2/Sensors/Sensors.h> +#include <RIGv2/Buses.h> +#include <diagnostic/CpuMeter/CpuMeter.h> +#include <diagnostic/StackLogger.h> + +using namespace Boardcore; +using namespace RIGv2; +using namespace miosix; + +int main() { + + ModuleManager &modules = ModuleManager::getInstance(); + PrintLogger logger = Logging::getLogger("main"); + + // TODO: Move this to a dedicated board scheduler + TaskScheduler *scheduler = new TaskScheduler(3); + + Buses *buses = new Buses(); + Sensors *sensors = new Sensors(*scheduler); + + Logger &sdLogger = Logger::getInstance(); + + bool initResult = true; + + // Insert modules + if(!modules.insert<Buses>(buses)) { + initResult = false; + LOG_ERR(logger, "Error failed to insert Buses"); + } + + if(!modules.insert<Sensors>(sensors)) { + initResult = false; + LOG_ERR(logger, "Error failed to insert Sensors"); + } + + // Start modules + if(!sensors->start()) { + initResult = false; + LOG_ERR(logger, "Error failed to start sensors module"); + } + + if(!scheduler->start()) { + initResult = false; + LOG_ERR(logger, "Error failed to start scheduler"); + } + + LOG_INFO(logger, "All good!"); + + // TEMPORARY CODE + // Start logger module + sdLogger.start(); + + // Periodic statistics + while(true) { + Thread::sleep(1000); + sdLogger.log(CpuMeter::getCpuStats()); + CpuMeter::resetCpuStats(); + // TODO: What the fuck is this? + // StackLogger::getInstance().log(); + } + + return 0; +} \ No newline at end of file diff --git a/src/scripts/logdecoder/RIGv2/Makefile b/src/scripts/logdecoder/RIGv2/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..6bbaf34fc2008754ca1425004f33514659c56baf --- /dev/null +++ b/src/scripts/logdecoder/RIGv2/Makefile @@ -0,0 +1,16 @@ +BOARDCORE := ../../../../skyward-boardcore/ +OBSW := ../../../../src/boards/ + +all: + g++ -std=c++17 -O2 -o logdecoder logdecoder.cpp \ + -DCOMPILE_FOR_X86 \ + -DCOMPILE_FOR_HOST \ + $(BOARDCORE)libs/tscpp/tscpp/stream.cpp \ + -I$(BOARDCORE)libs/miosix-host \ + -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/src/scripts/logdecoder/RIGv2/logdecoder.cpp b/src/scripts/logdecoder/RIGv2/logdecoder.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2a8a68ba1a6c1f0d54aa9019aa340f2f0d54de46 --- /dev/null +++ b/src/scripts/logdecoder/RIGv2/logdecoder.cpp @@ -0,0 +1,121 @@ +/* Copyright (c) 2018-2022 Skyward Experimental Rocketry + * Author: 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 <RIGv2/Sensors/SensorsData.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; +using namespace RIGv2; + +void registerTypes(Deserializer& ds) +{ + // Register all Boardcore types + LogTypes::registerTypes(ds); + + // Custom types + ds.registerType<ADCsData>(); +} + +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; +}