2020-02-15 22:09:55 +01:00
|
|
|
/* Reflow Oven Controller
|
|
|
|
*
|
|
|
|
* Copyright (C) 2020 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.
|
|
|
|
*
|
2020-02-21 21:22:01 +01:00
|
|
|
* The Reflow Oven Control Firmware is distributed in the hope that it will be useful,
|
2020-02-15 22:09:55 +01:00
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2020-02-12 21:00:35 +01:00
|
|
|
#include <reflow-controller/shell.h>
|
2020-02-12 21:06:52 +01:00
|
|
|
#include <stm-periph/uart.h>
|
2020-02-09 19:13:37 +01:00
|
|
|
#include <string.h>
|
2020-02-12 21:00:35 +01:00
|
|
|
#include <reflow-controller/adc-meas.h>
|
|
|
|
#include <reflow-controller/digio.h>
|
2020-02-10 22:38:24 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <helper-macros/helper-macros.h>
|
2020-02-12 21:00:35 +01:00
|
|
|
#include <reflow-controller/systick.h>
|
2020-02-12 22:24:17 +01:00
|
|
|
#include <stm-periph/unique-id.h>
|
2020-02-15 01:04:40 +01:00
|
|
|
#include <reflow-controller/calibration.h>
|
2020-02-15 20:31:38 +01:00
|
|
|
#include <reflow-controller/temp-converter.h>
|
2020-02-21 23:08:38 +01:00
|
|
|
|
2020-02-21 23:01:04 +01:00
|
|
|
#include <reflow-controller/stack-check.h>
|
2020-02-16 18:17:10 +01:00
|
|
|
#include <reflow-controller/rotary-encoder.h>
|
2020-02-09 19:13:37 +01:00
|
|
|
|
|
|
|
#ifndef GIT_VER
|
|
|
|
#define GIT_VER "VERSION NOT SET"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static shellmatta_instance_t shell;
|
|
|
|
static char shell_buffer[512];
|
|
|
|
static char history_buffer[1024];
|
|
|
|
|
|
|
|
static shellmatta_retCode_t write_shell_callback(const char *data, uint32_t len)
|
|
|
|
{
|
2020-02-11 22:49:47 +01:00
|
|
|
uart_send_array_with_dma(data, len);
|
2020-02-09 19:13:37 +01:00
|
|
|
return SHELLMATTA_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static shellmatta_retCode_t shell_cmd_ver(const shellmatta_handle_t handle,
|
2020-02-21 23:08:38 +01:00
|
|
|
const char *arguments,
|
|
|
|
uint32_t length)
|
2020-02-09 19:13:37 +01:00
|
|
|
{
|
|
|
|
(void)arguments;
|
|
|
|
(void)length;
|
2020-02-12 22:24:17 +01:00
|
|
|
uint32_t low_id;
|
|
|
|
uint32_t mid_id;
|
|
|
|
uint32_t high_id;
|
|
|
|
|
|
|
|
unique_id_get(&high_id, &mid_id, &low_id);
|
2020-02-09 19:13:37 +01:00
|
|
|
|
2020-02-12 21:53:13 +01:00
|
|
|
shellmatta_printf(handle, "Reflow Oven Controller Firmware " xstr(GIT_VER) "\r\n"
|
2020-02-23 21:06:24 +01:00
|
|
|
"Compiled: " __DATE__ " at " __TIME__ "\r\n"
|
|
|
|
"Serial: %08X-%08X-%08X", high_id, mid_id, low_id);
|
2020-02-09 19:13:37 +01:00
|
|
|
|
|
|
|
return SHELLMATTA_OK;
|
|
|
|
}
|
|
|
|
|
2020-02-10 22:38:24 +01:00
|
|
|
static shellmatta_retCode_t shell_cmd_digio_get(const shellmatta_handle_t handle,
|
2020-02-21 23:08:38 +01:00
|
|
|
const char *arguments,
|
|
|
|
uint32_t length)
|
2020-02-10 22:38:24 +01:00
|
|
|
{
|
|
|
|
(void)arguments;
|
|
|
|
(void)length;
|
|
|
|
|
|
|
|
shellmatta_printf(handle,
|
2020-02-21 23:08:38 +01:00
|
|
|
"DIGIO0 DIGIO1 DIGIO2 DIGIO3 LED0 LED1 LS\r\n"
|
|
|
|
"%d %d %d %d %d %d %d\r\n",
|
2020-02-10 22:38:24 +01:00
|
|
|
digio_get(0), digio_get(1), digio_get(2), digio_get(3),
|
|
|
|
led_get(0), led_get(1), loudspeaker_get());
|
|
|
|
|
|
|
|
return SHELLMATTA_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static shellmatta_retCode_t shell_cmd_digio_set(const shellmatta_handle_t handle,
|
2020-02-21 23:08:38 +01:00
|
|
|
const char *arguments,
|
|
|
|
uint32_t length)
|
2020-02-10 22:38:24 +01:00
|
|
|
{
|
2020-02-12 21:19:11 +01:00
|
|
|
(void)length;
|
|
|
|
(void)handle;
|
2020-02-10 22:38:24 +01:00
|
|
|
int num = 100;
|
|
|
|
int state;
|
|
|
|
char buff[64];
|
|
|
|
char *curr_token;
|
|
|
|
|
|
|
|
strncpy(buff, arguments, sizeof(buff));
|
|
|
|
|
|
|
|
curr_token = strtok(buff, " ");
|
|
|
|
curr_token = strtok(NULL, " ");
|
|
|
|
if (!curr_token)
|
|
|
|
return SHELLMATTA_ERROR;
|
|
|
|
|
|
|
|
num = atoi(curr_token);
|
|
|
|
|
|
|
|
if (!curr_token)
|
|
|
|
return SHELLMATTA_ERROR;
|
|
|
|
|
|
|
|
curr_token = strtok(NULL, " ");
|
|
|
|
state = atoi(curr_token);
|
|
|
|
|
|
|
|
if (num < 4 && num >= 0)
|
|
|
|
digio_set(num, state);
|
|
|
|
else if (num >= 4 && num <= 5)
|
|
|
|
led_set(num - 4, state);
|
|
|
|
else if (num == 6)
|
|
|
|
loudspeaker_set(state);
|
|
|
|
else
|
|
|
|
return SHELLMATTA_ERROR;
|
|
|
|
|
|
|
|
return SHELLMATTA_OK;
|
|
|
|
}
|
|
|
|
|
2020-02-09 19:13:37 +01:00
|
|
|
static shellmatta_retCode_t shell_cmd_pt1000_res(const shellmatta_handle_t handle,
|
|
|
|
const char *arguments,
|
|
|
|
uint32_t length)
|
|
|
|
{
|
|
|
|
(void)arguments;
|
|
|
|
(void)length;
|
|
|
|
float resistance;
|
|
|
|
int pt1000_status;
|
|
|
|
enum adc_pt1000_error pt1000_flags;
|
2020-02-15 01:04:40 +01:00
|
|
|
char display_status[100];
|
2020-02-15 20:31:38 +01:00
|
|
|
float temp;
|
|
|
|
int temp_conv_status;
|
|
|
|
const char *temp_prefix;
|
2020-02-09 19:13:37 +01:00
|
|
|
|
2020-02-15 01:04:40 +01:00
|
|
|
display_status[0] = 0;
|
2020-02-09 19:13:37 +01:00
|
|
|
|
|
|
|
pt1000_status = adc_pt1000_get_current_resistance(&resistance);
|
|
|
|
|
|
|
|
if (pt1000_status == 2) {
|
2020-02-15 01:04:40 +01:00
|
|
|
strcat(display_status, " UNSTABLE ");
|
2020-02-09 19:13:37 +01:00
|
|
|
} else if (pt1000_status) {
|
|
|
|
pt1000_flags = adc_pt1000_check_error();
|
2020-02-15 01:04:40 +01:00
|
|
|
if (pt1000_flags & ADC_PT1000_INACTIVE)
|
|
|
|
strcat(display_status, " DEACTIVATED ");
|
|
|
|
else if (pt1000_flags & ADC_PT1000_WATCHDOG_ERROR)
|
|
|
|
strcat(display_status, " WATCHDOG ");
|
2020-02-09 19:13:37 +01:00
|
|
|
else if (pt1000_flags & ADC_PT1000_OVERFLOW)
|
2020-02-15 01:04:40 +01:00
|
|
|
strcat(display_status, " OVERFLOW ");
|
|
|
|
} else {
|
|
|
|
strcpy(display_status, "VALID");
|
2020-02-09 19:13:37 +01:00
|
|
|
}
|
|
|
|
|
2020-02-15 20:31:38 +01:00
|
|
|
temp_conv_status = temp_converter_convert_resistance_to_temp(resistance, &temp);
|
|
|
|
switch (temp_conv_status) {
|
|
|
|
case 1:
|
|
|
|
temp_prefix = ">";
|
|
|
|
break;
|
|
|
|
case -1:
|
|
|
|
temp_prefix = "<";
|
|
|
|
break;
|
|
|
|
case 0:
|
2020-02-15 21:06:45 +01:00
|
|
|
/* FALLTHRU */
|
2020-02-15 20:31:38 +01:00
|
|
|
default:
|
|
|
|
temp_prefix = "";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
shellmatta_printf(handle, "PT1000 resistance: %.2f Ohm (%s%.1f °C) [%s]\r\n", resistance, temp_prefix,temp, display_status);
|
2020-02-09 19:13:37 +01:00
|
|
|
|
|
|
|
return SHELLMATTA_OK;
|
|
|
|
}
|
2020-02-12 21:08:05 +01:00
|
|
|
static shellmatta_retCode_t shell_cmd_clear_error_status(const shellmatta_handle_t handle, const char *arguments,
|
|
|
|
uint32_t length)
|
2020-02-09 19:13:37 +01:00
|
|
|
{
|
2020-02-12 21:08:05 +01:00
|
|
|
(void)arguments;
|
|
|
|
(void)length;
|
2020-02-12 21:10:15 +01:00
|
|
|
(void)handle;
|
2020-02-12 21:08:05 +01:00
|
|
|
|
2020-02-09 19:13:37 +01:00
|
|
|
adc_pt1000_clear_error();
|
|
|
|
|
|
|
|
return SHELLMATTA_OK;
|
|
|
|
}
|
2020-02-11 22:59:30 +01:00
|
|
|
|
|
|
|
static shellmatta_retCode_t shell_cmd_uptime(const shellmatta_handle_t handle,
|
|
|
|
const char *arguments,
|
|
|
|
uint32_t length)
|
|
|
|
{
|
|
|
|
(void)arguments;
|
|
|
|
(void)length;
|
2020-02-12 21:10:15 +01:00
|
|
|
|
2020-02-11 22:59:30 +01:00
|
|
|
shellmatta_printf(handle, "Uptime: %llu secs", global_tick_ms/1000);
|
|
|
|
return SHELLMATTA_OK;
|
|
|
|
}
|
2020-02-15 01:04:40 +01:00
|
|
|
|
2020-02-15 17:53:15 +01:00
|
|
|
static shellmatta_retCode_t shell_cmd_cal(const shellmatta_handle_t handle,
|
2020-02-21 23:08:38 +01:00
|
|
|
const char *arguments,
|
|
|
|
uint32_t length)
|
2020-02-15 01:04:40 +01:00
|
|
|
{
|
2020-02-15 17:53:15 +01:00
|
|
|
(void)arguments;
|
|
|
|
(void)length;
|
2020-02-15 01:04:40 +01:00
|
|
|
|
2020-02-15 17:53:15 +01:00
|
|
|
calibration_sequence_shell_cmd(handle);
|
2020-02-15 01:04:40 +01:00
|
|
|
return SHELLMATTA_OK;
|
|
|
|
}
|
2020-02-21 23:01:04 +01:00
|
|
|
|
|
|
|
static shellmatta_retCode_t shell_get_sp(const shellmatta_handle_t handle,
|
2020-02-21 23:08:38 +01:00
|
|
|
const char *arguments,
|
|
|
|
uint32_t length)
|
2020-02-21 23:01:04 +01:00
|
|
|
{
|
|
|
|
(void)arguments;
|
|
|
|
(void)length;
|
|
|
|
|
|
|
|
shellmatta_printf(handle,
|
2020-02-21 23:08:38 +01:00
|
|
|
"Stack pointer: %p\r\n"
|
|
|
|
"Stack usage: 0x%x bytes\r\n"
|
|
|
|
"Lim to heap: 0x%x bytes\r\n",
|
|
|
|
read_stack_pointer(),
|
|
|
|
stack_check_get_usage(),
|
|
|
|
stack_check_get_free());
|
|
|
|
return SHELLMATTA_OK;
|
|
|
|
}
|
|
|
|
|
2020-02-16 18:17:10 +01:00
|
|
|
static shellmatta_retCode_t shell_cmd_rot(const shellmatta_handle_t handle,
|
2020-02-21 23:08:38 +01:00
|
|
|
const char *arguments,
|
|
|
|
uint32_t length)
|
2020-02-16 18:17:10 +01:00
|
|
|
{
|
|
|
|
(void)arguments;
|
|
|
|
(void)length;
|
2020-02-21 23:08:38 +01:00
|
|
|
|
2020-02-16 18:17:10 +01:00
|
|
|
uint32_t rot_val;
|
|
|
|
int32_t delta;
|
|
|
|
|
|
|
|
rot_val = rotary_encoder_get_abs_val();
|
|
|
|
delta = rotary_encoder_get_change_val();
|
|
|
|
shellmatta_printf(handle, "Rotary encoder value: %u, delta: %d\r\n", rot_val, delta);
|
|
|
|
|
2020-02-21 23:01:04 +01:00
|
|
|
return SHELLMATTA_OK;
|
|
|
|
}
|
|
|
|
|
2020-02-09 19:13:37 +01:00
|
|
|
//typedef struct shellmatta_cmd
|
|
|
|
//{
|
|
|
|
// char *cmd; /**< command name */
|
|
|
|
// char *cmdAlias; /**< command alias */
|
|
|
|
// char *helpText; /**< help text to print in "help" command */
|
|
|
|
// char *usageText; /**< usage text to print on parameter error */
|
|
|
|
// shellmatta_cmdFct_t cmdFct; /**< pointer to the cmd callack function */
|
|
|
|
// struct shellmatta_cmd *next; /**< pointer to next command or NULL */
|
|
|
|
//} shellmatta_cmd_t;
|
|
|
|
|
2020-02-21 23:08:38 +01:00
|
|
|
static shellmatta_cmd_t cmd[9] = {
|
2020-02-09 19:13:37 +01:00
|
|
|
{
|
|
|
|
.cmd = "version",
|
|
|
|
.cmdAlias = "ver",
|
|
|
|
.helpText = "Print firmware version",
|
|
|
|
.usageText = NULL,
|
|
|
|
.cmdFct = shell_cmd_ver,
|
|
|
|
.next = &cmd[1],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.cmd = "pt1000",
|
|
|
|
.cmdAlias = "pt",
|
|
|
|
.helpText = "Get current filtered and calibrated PT1000 resistance",
|
|
|
|
.usageText = NULL,
|
|
|
|
.cmdFct = shell_cmd_pt1000_res,
|
|
|
|
.next = &cmd[2],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.cmd = "pt1000-clear-error",
|
|
|
|
.cmdAlias = "pt-clear",
|
|
|
|
.helpText = "Clear error status of PT1000 reading",
|
|
|
|
.usageText = NULL,
|
|
|
|
.cmdFct = shell_cmd_clear_error_status,
|
2020-02-10 22:38:24 +01:00
|
|
|
.next = &cmd[3],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.cmd = "digio-get",
|
|
|
|
.cmdAlias = "dg",
|
|
|
|
.helpText = "Read all digital input/output ports",
|
|
|
|
.usageText = NULL,
|
|
|
|
.cmdFct = shell_cmd_digio_get,
|
|
|
|
.next = &cmd[4],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.cmd = "digio-set",
|
|
|
|
.cmdAlias = "ds",
|
|
|
|
.helpText = "Set DIGIO Port",
|
|
|
|
.usageText = "digio-set <num> <state>",
|
|
|
|
.cmdFct = shell_cmd_digio_set,
|
2020-02-11 22:59:30 +01:00
|
|
|
.next = &cmd[5],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.cmd = "uptime",
|
|
|
|
.cmdAlias = "upt",
|
|
|
|
.helpText = "Get uptime in seconds",
|
|
|
|
.usageText = "",
|
|
|
|
.cmdFct = shell_cmd_uptime,
|
2020-02-15 01:04:40 +01:00
|
|
|
.next = &cmd[6],
|
2020-02-09 19:13:37 +01:00
|
|
|
},
|
2020-02-15 01:04:40 +01:00
|
|
|
{
|
2020-02-15 17:53:15 +01:00
|
|
|
.cmd = "calibrate",
|
|
|
|
.cmdAlias = "cal",
|
|
|
|
.helpText = "Calibrate resistance measurement",
|
2020-02-15 01:04:40 +01:00
|
|
|
.usageText = "",
|
2020-02-15 17:53:15 +01:00
|
|
|
.cmdFct = shell_cmd_cal,
|
2020-02-21 23:01:04 +01:00
|
|
|
.next = &cmd[7],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.cmd = "get-stack-pointer",
|
|
|
|
.cmdAlias = "sp",
|
|
|
|
.helpText = "Get the stack pointer",
|
|
|
|
.usageText = "",
|
|
|
|
.cmdFct = shell_get_sp,
|
2020-02-21 23:08:38 +01:00
|
|
|
.next = &cmd[8],
|
|
|
|
},
|
2020-02-16 18:17:10 +01:00
|
|
|
{
|
|
|
|
.cmd = "rotary-encoder",
|
|
|
|
.cmdAlias = "rot",
|
|
|
|
.helpText = "Get current rotary encoder value",
|
|
|
|
.usageText = "",
|
|
|
|
.cmdFct = shell_cmd_rot,
|
2020-02-15 01:04:40 +01:00
|
|
|
.next = NULL,
|
|
|
|
}
|
2020-02-09 19:13:37 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
shellmatta_handle_t shell_init(void)
|
|
|
|
{
|
|
|
|
shellmatta_handle_t handle;
|
|
|
|
shellmatta_retCode_t ret;
|
|
|
|
|
|
|
|
ret = shellmatta_doInit(&shell, &handle, shell_buffer, sizeof(shell_buffer), history_buffer, sizeof(history_buffer),
|
2020-02-21 23:08:38 +01:00
|
|
|
"\e[1;32mEnter command:\e[m\r\n", cmd, write_shell_callback);
|
2020-02-09 19:13:37 +01:00
|
|
|
if (ret != SHELLMATTA_OK)
|
|
|
|
handle = NULL;
|
|
|
|
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void shell_handle_input(shellmatta_handle_t shell, const char *data, size_t len)
|
|
|
|
{
|
2020-02-21 23:08:38 +01:00
|
|
|
if (!shell)
|
|
|
|
return;
|
2020-02-09 19:13:37 +01:00
|
|
|
|
2020-02-21 23:08:38 +01:00
|
|
|
shellmatta_processData(shell, (char *)data, (uint32_t)len);
|
2020-02-09 19:13:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void shell_print_string(shellmatta_handle_t shell, const char *string)
|
|
|
|
{
|
|
|
|
if (!shell)
|
|
|
|
return;
|
|
|
|
|
|
|
|
shellmatta_write(shell, (char *)string, strlen(string));
|
|
|
|
}
|