From def6b960a87d5fc1f174304aa4bfbe860d17a62d Mon Sep 17 00:00:00 2001 From: Mike Langmayr <1809691+mikelangmayr@users.noreply.github.com> Date: Wed, 7 Oct 2026 12:54:58 -0700 Subject: [PATCH] Give slow Archon commands the timeouts they need --- camerad/archon_controller.cpp | 31 +++++++++++++++++++++++++++++-- camerad/archon_interface.cpp | 24 +++++++++++------------- camerad/archon_interface.h | 1 - 3 files changed, 40 insertions(+), 16 deletions(-) diff --git a/camerad/archon_controller.cpp b/camerad/archon_controller.cpp index 9f26979..4ff1dc8 100644 --- a/camerad/archon_controller.cpp +++ b/camerad/archon_controller.cpp @@ -19,6 +19,32 @@ namespace Camera { + namespace { + struct CommandTimeout { + std::string_view command; + int timeout_ms; + }; + + // STA's own values, from the timeouts archongui passes interfaceCommand + constexpr std::array COMMAND_TIMEOUTS {{ + {"ERASESTOREDCONFIG", 60000}, + {"FLASHACTIVECONFIG", 60000}, + {"APPLYALL", 30000}, + {"POWERON", 30000}, + {"POWEROFF", 30000}, + {"LOADTIMING", 5000}, + }}; + + int timeout_for(const std::string &cmd) { + const size_t end = cmd.find(' '); + const std::string_view verb(cmd.data(), end == std::string::npos ? cmd.size() : end); + for (const auto &entry : COMMAND_TIMEOUTS) { + if (entry.command == verb) return entry.timeout_ms; + } + return Network::POLLTIMEOUT; + } + } + /***** Camera::ArchonController::ArchonController ***************************/ /** @@ -1114,9 +1140,10 @@ namespace Camera { constexpr size_t BUFSZ = 64*1024; auto buffer = std::make_unique(BUFSZ+1); reply.clear(); + const int timeout_ms = timeout_for(cmd); do { - if ( (retval=this->archon.Poll()) <= 0) { - if (retval==0) { logwrite(function, "Poll timeout waiting for response from Archon command (maybe unrecognized command?)"); error=TIMEOUT; } + if ( (retval=this->archon.Poll(timeout_ms)) <= 0) { + if (retval==0) { logwrite(function, "Poll timeout after "+std::to_string(timeout_ms)+"ms waiting for response to \""+cmd+"\""); error=TIMEOUT; } if (retval<0) { logwrite(function, "Poll error waiting for response from Archon command"); error=ERROR; } break; } diff --git a/camerad/archon_interface.cpp b/camerad/archon_interface.cpp index ea4d818..d62cf6f 100644 --- a/camerad/archon_interface.cpp +++ b/camerad/archon_interface.cpp @@ -708,28 +708,23 @@ namespace Camera { retstring.append( " Archon power will be off after this operation.\n" ); return HELP; } - // call the work function - return load_firmware(args); - } - /***** Camera::ArchonInterface::load_firmware *******************************/ - /** - * @brief loads the ACF file and applies the complete Archon Configuration - * @param[in] args fully qualified path of ACF - * @return ERROR|NO_ERROR - * - */ - long ArchonInterface::load_firmware(const std::string &acffile) { + const std::string function("Camera::ArchonInterface::load_firmware"); + const std::string &acffile = args; logwrite(function, acffile); // load the ACF file and write to Archon configuration memory // long error = this->controller->load_acf(acffile); + if (error != NO_ERROR) retstring = "writing the ACF to configuration memory"; // Parse and apply the complete system configuration from configuration memory. // Detector power will be off after this. // - if (error == NO_ERROR) error = this->controller->send_cmd(APPLYALL); + if (error == NO_ERROR) { + error = this->controller->send_cmd(APPLYALL); + if (error != NO_ERROR) retstring = "applying the configuration (APPLYALL)"; + } // read/clear Archon's internal error log // @@ -737,7 +732,10 @@ namespace Camera { // set the mode to DEFAULT // - if (error == NO_ERROR) error = this->set_camera_mode(std::string("DEFAULT")); + if (error == NO_ERROR) { + error = this->set_camera_mode(std::string("DEFAULT")); + if (error != NO_ERROR) retstring = "selecting the DEFAULT mode"; + } // TODO set exptime // TODO other instrument-specific defaults? diff --git a/camerad/archon_interface.h b/camerad/archon_interface.h index dff5231..956126e 100644 --- a/camerad/archon_interface.h +++ b/camerad/archon_interface.h @@ -58,7 +58,6 @@ namespace Camera { // found in the base class. // long disconnect_controller(); - long load_firmware(const std::string &acffile); long allocate_framebuf(uint32_t reqsz); long get_parameter(const std::string &args, std::string &retstring); long load_timing(std::string cmd, std::string &reply);