From 93ff4959a2212dc6b47de836e01d8215188e4f2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Thu, 18 Mar 2021 22:44:05 +0100 Subject: [PATCH] Issue #28: Start Temp profile parser --- stm-firmware/Makefile | 2 +- .../config-parser/temp-profile-parser.c | 115 ++++++++++++++++++ .../config-parser/temp-profile-parser.h | 62 ++++++++++ 3 files changed, 178 insertions(+), 1 deletion(-) create mode 100644 stm-firmware/config-parser/temp-profile-parser.c create mode 100644 stm-firmware/include/reflow-controller/config-parser/temp-profile-parser.h diff --git a/stm-firmware/Makefile b/stm-firmware/Makefile index 99985fe..9fa520f 100644 --- a/stm-firmware/Makefile +++ b/stm-firmware/Makefile @@ -49,7 +49,7 @@ CFILES += settings/settings.c settings/settings-sd-card.c settings/spi-eeprom.c CFILES += stm-periph/crc-unit.c CFILES += safety/safety-adc.c safety/safety-controller.c safety/watchdog.c safety/fault.c safety/safety-memory.c safety/stack-check.c CFILES += hw-version-detect.c -CFILES += config-parser/config-parser.c +CFILES += config-parser/config-parser.c config-parser/temp-profile-parser.c CFILES += updater/updater.c INCLUDEPATH += -Iconfig-parser/include diff --git a/stm-firmware/config-parser/temp-profile-parser.c b/stm-firmware/config-parser/temp-profile-parser.c new file mode 100644 index 0000000..526fe83 --- /dev/null +++ b/stm-firmware/config-parser/temp-profile-parser.c @@ -0,0 +1,115 @@ +/* Reflow Oven Controller +* +* Copyright (C) 2021 Mario Hüttel +* +* This file is part of the Reflow Oven Controller Project. +* +* The reflow oven controller is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* The Reflow Oven Control Firmware is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with the reflow oven controller project. +* If not, see . +*/ + +#include +#include +#include + +struct pl_command_list_map { + enum pl_command_type command; + const char * const token; + uint8_t expected_param_count; +}; + +/** + * @brief This list stores the command tokens and the expected number of arguments for each command + */ +static const struct pl_command_list_map cmd_list_map[_PL_NUM_CMDS] = { + {PL_PID_CONF, "pid_conf", 6u}, + {PL_SET_TEMP, "temp_set", 1u}, + {PL_WAIT_FOR_TEMP, "wait_temp", 1u}, + {PL_WAIT_FOR_TIME, "wait_time", 1u}, + {PL_SET_RAMP, "temp_ramp", 2u}, + {PL_LOUDSPEAKER_SET, "beep", 1u}, + {PL_OFF, "temp_off", 0u} +}; + +/** + * @brief Read a line in the file until a line break is detected or a comment is started. + * + * In case a comment is detected, it is still read form the file to ensure + * the next line is read afterwards + * + * @param f File to read from + * @param buffer Buffer to read in + * @param buffsize buffer size + * @return 0 if successful, -1 if disk error, + */ +static int read_line_until_comment(FIL *f, char *buffer, uint32_t buffsize) +{ + char *ptr; + uint32_t i; + + if (!f || !buffsize || !buffer) + return -1000; + + buffer[0] = 0; + /* Read the line from file */ + ptr = f_gets(buffer, (int)buffsize, f); + if (!ptr) { + buffer[0] = 0; + return -2; + } + + /* Go through the line until we encounter a # sign or the end of line*/ + for (i = 0; i < buffsize; i++) { + if (buffer[i] == '\n' || buffer[i] == '#') { + buffer[i] = 0; + break; + } else if (buffer[i] == 0) { + break; + } + } + + return 0; +} + +enum pl_ret_val temp_profile_parse_from_file(const char *filename, + struct pl_command *cmd_list, + uint32_t cmd_list_length, + struct pl_error *error, + uint32_t *cmds_parsed) +{ + FIL script_file; + FRESULT fres; + enum pl_ret_val ret = PL_RET_SUCCESS; + char workbuff[256]; + + if (!filename || !cmd_list || !cmd_list_length || !cmds_parsed || !error) + return PL_RET_PARAM_ERR; + error->column = 0; + error->line = 0; + + fres = f_open(&script_file, filename, FA_READ); + if (fres != FR_OK) { + error->errormsg = "Error opening file"; + ret = PL_RET_DISK_ERR; + goto exit; + } + + do { + /* TODO: Read lines and parse them */ + } while (!f_eof(&script_file)); + + + (void)f_close(&script_file); +exit: + return ret; +} diff --git a/stm-firmware/include/reflow-controller/config-parser/temp-profile-parser.h b/stm-firmware/include/reflow-controller/config-parser/temp-profile-parser.h new file mode 100644 index 0000000..344d7d7 --- /dev/null +++ b/stm-firmware/include/reflow-controller/config-parser/temp-profile-parser.h @@ -0,0 +1,62 @@ +/* Reflow Oven Controller +* +* Copyright (C) 2021 Mario Hüttel +* +* This file is part of the Reflow Oven Controller Project. +* +* The reflow oven controller is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* The Reflow Oven Control Firmware is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with the reflow oven controller project. +* If not, see . +*/ + +#ifndef __CONFIG_PARSER_TEMP_PROFILE_PARSER_H__ +#define __CONFIG_PARSER_TEMP_PROFILE_PARSER_H__ + +#include + +enum pl_command_type { + PL_PID_CONF = 0, + PL_SET_TEMP, + PL_SET_RAMP, + PL_WAIT_FOR_TEMP, + PL_WAIT_FOR_TIME, + PL_LOUDSPEAKER_SET, + PL_OFF, + _PL_NUM_CMDS, +}; + +enum pl_ret_val { + PL_RET_SUCCESS = 0, + PL_RET_DISK_ERR, + PL_RET_PARAM_ERR, + PL_RET_LIST_FULL, + PL_RET_SCRIPT_ERR, +}; + +struct pl_error { + const char *errormsg; + uint32_t line; + uint32_t column; +}; + +struct pl_command { + enum pl_command_type cmd; + float params[8]; +}; + +enum pl_ret_val temp_profile_parse_from_file(const char *filename, + struct pl_command *cmd_list, + uint32_t cmd_list_length, + struct pl_error *error, + uint32_t *cmds_parsed); + +#endif /* __CONFIG_PARSER_TEMP_PROFILE_PARSER_H__ */