Issue #28: Start Temp profile parser

This commit is contained in:
Mario Hüttel 2021-03-18 22:44:05 +01:00
parent b560a91673
commit 93ff4959a2
3 changed files with 178 additions and 1 deletions

View File

@ -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

View File

@ -0,0 +1,115 @@
/* Reflow Oven Controller
*
* Copyright (C) 2021 Mario Hüttel <mario.huettel@gmx.net>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <reflow-controller/config-parser/temp-profile-parser.h>
#include <stdint.h>
#include <fatfs/ff.h>
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;
}

View File

@ -0,0 +1,62 @@
/* Reflow Oven Controller
*
* Copyright (C) 2021 Mario Hüttel <mario.huettel@gmx.net>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef __CONFIG_PARSER_TEMP_PROFILE_PARSER_H__
#define __CONFIG_PARSER_TEMP_PROFILE_PARSER_H__
#include <stdint.h>
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__ */