116 lines
3.0 KiB
C
116 lines
3.0 KiB
C
|
/* 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;
|
||
|
}
|