diff --git a/coincellhell.c b/coincellhell.c index 23e42ad4bfc9bded2ac573d5f0cc62d91b4279b5..20801cebf44499a2f87d10d13a4950f91537b4aa 100644 --- a/coincellhell.c +++ b/coincellhell.c @@ -300,6 +300,23 @@ int coincellhell_reset(struct coincellhell* hell) return 0; } + +int coincellhell_enable_watchdog(struct coincellhell* hell) +{ + int ret; + while((ret = usbshm_writeControlTransfer(hell->priv, COMMAND_ENABLE_WATCHDOG, NULL, 0, 0, 0)) == USBSHM_ERROR_AGAIN) + usleep(100000); + return ret; +} + +int coincellhell_set_periodic_recal(struct coincellhell* hell, bool recal) +{ + int ret; + while((ret = usbshm_writeControlTransfer(hell->priv, COMMAND_ENABLE_WATCHDOG, NULL, 0, recal, 0)) == USBSHM_ERROR_AGAIN) + usleep(100000); + return ret; +} + void coincellhell_disconnect(struct coincellhell* hell) { if(!hell || !hell->priv) @@ -329,3 +346,4 @@ const char* coincellhell_string_for_fault(fault_t fault) } } + diff --git a/coincellhell/coincellhell.h b/coincellhell/coincellhell.h index 3d483321814171032265b3ef8191e39061ff8a5d..f073f1a3409471aa1fecc76f99432201fda5d0af 100644 --- a/coincellhell/coincellhell.h +++ b/coincellhell/coincellhell.h @@ -176,6 +176,8 @@ uint16_t coincellhell_read_eeprom(struct coincellhell* hell, uint16_t addr); uint8_t coincellhell_read_oscal(struct coincellhell* hell); uint32_t coincellhell_get_seconds(struct coincellhell* hell); const uint8_t* coincellhell_get_fw_git_revision(struct coincellhell* hell); +int coincellhell_enable_watchdog(struct coincellhell* hell); +int coincellhell_set_periodic_recal(struct coincellhell* hell, bool recal); #ifdef __cplusplus } diff --git a/coincellhell/usbcommands.h b/coincellhell/usbcommands.h index 05a8ef45018636ea1f1868ece8ed2c517c6a8d1b..9a6c1b503dc0f1873925e26f2302f22e1bcc3fa9 100644 --- a/coincellhell/usbcommands.h +++ b/coincellhell/usbcommands.h @@ -1,12 +1,5 @@ #pragma once -/** -Api to controll EISmultiplexer devices. -* @addtogroup API User API -* This api allows you to controll the EISmultiplexer device. -* @{ -*/ - typedef enum { COMMAND_LED_ON = 0, COMMAND_LED_OFF, @@ -23,6 +16,8 @@ typedef enum { COMMAND_WRITE_EEPROM, COMMAND_READ_OSCAL, COMMAND_GET_FIRMWARE_GITREV, + COMMAND_ENABLE_WATCHDOG, + COMMAND_SET_RECAL } usb_command_t; typedef enum { @@ -40,7 +35,3 @@ typedef enum { FAULT_UNDERTEMP, FAULT_UNSPECIFIED } fault_t; - -/* -* @} -*/ diff --git a/main.c b/main.c index a0fd86869d97e162562d67f3ac5cc88838d0cff4..916b64762481e2c90a57fff7e798e9fb584c8892 100644 --- a/main.c +++ b/main.c @@ -50,6 +50,8 @@ static void print_commands(void) puts("read [ADDRESS] [LENGTH]\t | read from the device eeprom at address"); puts("write [ADDRESS] [LENGTH] | write to the device eeprom at address"); puts("git\t\t\t | get the git revision of the firmware on the device"); + puts("watchdog\t\t\t | enables the on device command watchdog"); + puts("recal [BOOLEAN]\t\t | enables or disables periodic recal"); } static int convert_string_to_heater_id(const char* str) @@ -345,6 +347,26 @@ static int process_commands(char** commands, size_t command_count, struct coince const uint8_t* rev = coincellhell_get_fw_git_revision(hell); printf("Git: %x%x%x%x%x%x%x%x\n", rev[0], rev[1], rev[2], rev[3], rev[4], rev[5], rev[6], rev[7]); } + else if(strcmp(commands[0], "watchdog") == 0) + { + ret = coincellhell_enable_watchdog(hell); + if(ret < 0) + puts("could not enable watchdog"); + } + else if(strcmp(commands[0], "recal") == 0) + { + if(command_count < 2) + { + printf("Usage %s %s [BLOOEAN]\n", name, commands[0]); + return 2; + } + + bool enable = strtol(commands[1], NULL, 10); + printf("Seting recal to %s\n", enable ? "true" : "false"); + ret = coincellhell_set_periodic_recal(hell, enable); + if(ret < 0) + puts("could not enable watchdog"); + } else { printf("%s is not a valid command!", commands[0]);