From e38ca71a9984bff9e01767801922c649e76c1179 Mon Sep 17 00:00:00 2001 From: Jonas Arnold Date: Mon, 5 Dec 2022 19:28:04 +0100 Subject: [PATCH] implemented splitflap wrapper, this will send commands to the splitflap tinyk22 to control splitflaps --- ADIS_ESP32_Eclipse/main/splitflap_wrapper.c | 46 +++++++++++++++++++++ ADIS_ESP32_Eclipse/main/splitflap_wrapper.h | 26 ++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 ADIS_ESP32_Eclipse/main/splitflap_wrapper.c create mode 100644 ADIS_ESP32_Eclipse/main/splitflap_wrapper.h diff --git a/ADIS_ESP32_Eclipse/main/splitflap_wrapper.c b/ADIS_ESP32_Eclipse/main/splitflap_wrapper.c new file mode 100644 index 0000000..43cb436 --- /dev/null +++ b/ADIS_ESP32_Eclipse/main/splitflap_wrapper.c @@ -0,0 +1,46 @@ +/* + * splitflap_wrapper.c + * + * Created on: 05.12.2022 + * Author: jonas + */ + +#include "splitflap_wrapper.h" +#include "rs485.h" + +#define RS_CMD_PREFIX "rs sendcmd SplitFlap " +#define BUF_SIZE 40 + + +/* moves all split flaps to the zero position + * After a timeout the initializtion is cancelled and the return value is false + * If all splitflaps report to be initialized before the timeout, the return value is true */ +bool SplitFlap_Wrapper_MoveAllToZeroPosition(void){ + char cmd[BUF_SIZE] = RS_CMD_PREFIX; + McuUtility_strcat(cmd, sizeof cmd, "initAll"); + RS485_ParseCommand(cmd); +} + +/* display a sentence on the splitflap combination + * splitflaps must be initialized to be able to display something! + * returns true when all movements finished */ +bool SplitFlap_Wrapper_Display(char sentence[]){ + char cmd[BUF_SIZE] = RS_CMD_PREFIX; + McuUtility_strcat(cmd, sizeof cmd, "Display "); + McuUtility_strcat(cmd, sizeof cmd, sentence); + RS485_ParseCommand(cmd); +} + +/* sets the hardware identifier of a splitflap with in the combination + * returns true when successful, false when not (e.g. split flap with given id not available) */ +bool SplitFlap_Wrapper_SetHardwareIdentifier(uint8_t id, uint8_t hwId){ + char cmd[BUF_SIZE] = RS_CMD_PREFIX; + char setupId_str[4] = {0}; char hardwareId_str[4] = {0}; + McuUtility_Num8uToStr(setupId_str, sizeof setupId_str, id); + McuUtility_Num8uToStr(hardwareId_str, sizeof hardwareId_str, hwId); + McuUtility_strcat(cmd, sizeof cmd, "setId "); + McuUtility_strcat(cmd, sizeof cmd, setupId_str); + McuUtility_strcat(cmd, sizeof cmd, " "); + McuUtility_strcat(cmd, sizeof cmd, hardwareId_str); + RS485_ParseCommand(cmd); +} diff --git a/ADIS_ESP32_Eclipse/main/splitflap_wrapper.h b/ADIS_ESP32_Eclipse/main/splitflap_wrapper.h new file mode 100644 index 0000000..f9ec113 --- /dev/null +++ b/ADIS_ESP32_Eclipse/main/splitflap_wrapper.h @@ -0,0 +1,26 @@ +/* + * splitflap_wrapper.h + * + * Created on: 05.12.2022 + * Author: jonas + */ + +#ifndef MAIN_SPLITFLAP_WRAPPER_H_ +#define MAIN_SPLITFLAP_WRAPPER_H_ + +/* moves all split flaps to the zero position + * After a timeout the initializtion is cancelled and the return value is false + * If all splitflaps report to be initialized before the timeout, the return value is true */ +bool SplitFlap_Wrapper_MoveAllToZeroPosition(void); + +/* display a sentence on the splitflap combination + * splitflaps must be initialized to be able to display something! + * returns true when all movements finished */ +bool SplitFlap_Wrapper_Display(char sentence[]); + +/* sets the hardware identifier of a splitflap with in the combination + * returns true when successful, false when not (e.g. split flap with given id not available) */ +bool SplitFlap_Wrapper_SetHardwareIdentifier(uint8_t id, uint8_t hwId); + + +#endif /* MAIN_SPLITFLAP_WRAPPER_H_ */