From 8f11bbd858bc6d52ab68b315e2da4a76581c0592 Mon Sep 17 00:00:00 2001 From: Carl Philipp Klemm <philipp@uvos.xyz> Date: Fri, 3 Nov 2023 13:36:14 +0100 Subject: [PATCH] add mcu watchdog support --- heater.cpp | 3 +++ heaters.h | 1 + main.cpp | 10 ++++++++-- options.h | 5 +++++ 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/heater.cpp b/heater.cpp index cc5befb..bfef2fc 100644 --- a/heater.cpp +++ b/heater.cpp @@ -75,6 +75,8 @@ void Heaters::recoverDevice(int device) coincellhell_reset_bus(&devices[device].device); coincellhell_disconnect(&devices[device].device); ret = coincellhell_connect(&devices[device].device, devices[device].serial); + if(watchdogs) + coincellhell_enable_watchdog(&devices[device].device); } devices[device].mutex->unlock(); @@ -394,6 +396,7 @@ void Heaters::safetyCheck() void Heaters::enableWatchdogs() { + watchdogs = true; for(struct device& device : devices) { device.mutex->lock(); diff --git a/heaters.h b/heaters.h index c25bd14..a243d55 100644 --- a/heaters.h +++ b/heaters.h @@ -35,6 +35,7 @@ private: }; std::vector<struct device> devices; + bool watchdogs = false; std::function<void(int device, uint16_t serial, int code)> deviceFailCb; std::function<void(int heater, int device)> heaterFailCb; diff --git a/main.cpp b/main.cpp index fad2293..c5c0784 100644 --- a/main.cpp +++ b/main.cpp @@ -57,7 +57,7 @@ static void loggingThreadFn(Heaters* heaters, Multiplexers* multiplexers, static unsigned int step = 0; Log(Log::INFO)<<"Logging thread has started"; - std::filesystem::path logfile = outdir/"expiramentlog.txt"; + std::filesystem::path logfile = outdir/"expiramentlog.csv"; std::fstream file(logfile, std::ios_base::out); if(!file.is_open()) @@ -105,7 +105,7 @@ static void loggingThreadFn(Heaters* heaters, Multiplexers* multiplexers, file<<temp<<','; } file<<std::endl; - std::this_thread::sleep_for(std::chrono::seconds(5)); + std::this_thread::sleep_for(std::chrono::seconds(10)); } } @@ -252,6 +252,12 @@ int main(int argc, char** argv) return 2; } + if(config.watchdog) + { + Log(Log::INFO)<<"Enableing mcu watchdogs"; + heaters.enableWatchdogs(); + } + ret = expirament.run(config.globalStep, config.subStep); expirament.shutdown(); diff --git a/options.h b/options.h index 0f2648a..7128b35 100644 --- a/options.h +++ b/options.h @@ -31,6 +31,7 @@ static struct argp_option options[] = {"sub-step", 'k', "[STEP NUMBER]", 0, "sets the subset of the expirament"}, {"stepfile", 'f', "[PATH]", 0, "sets the subset of the expirament"}, {"skip-start", 'z' , 0, 0, "skipps the startup sequence"}, + {"watchdog", 'w' , 0, 0, "enable mcu watchdogs"}, { 0 } }; @@ -50,6 +51,7 @@ struct Config size_t globalStep = 0; size_t subStep = 0; bool skipstart = false; + bool watchdog = false; }; static std::vector<uint16_t> parseList(const std::string& in) @@ -116,6 +118,9 @@ static error_t parse_opt (int key, char *arg, struct argp_state *state) case 'z': config->skipstart = true; break; + case 'w': + config->watchdog = true; + break; default: return ARGP_ERR_UNKNOWN; } -- GitLab