ADD info, time
This commit is contained in:
@ -8,6 +8,7 @@
|
||||
*
|
||||
******************************************************************************/
|
||||
#include "main.h"
|
||||
#include "at1_defines.h"
|
||||
#include "cmsis_os.h"
|
||||
#include <stdint.h>
|
||||
#include <ctype.h>
|
||||
@ -45,6 +46,7 @@ typedef struct {
|
||||
int (*func)(/*command_ctx_t *ctx,*/ char *args);
|
||||
} cmd_table_t;
|
||||
|
||||
// the entries must be in alphabetical order due to the binary search
|
||||
static const cmd_table_t cmd_table[] = {
|
||||
{"admin", 2, CMD_ADMIN, do_test },
|
||||
{"altitude", 1, CMD_NO_FLAG, do_test },
|
||||
@ -52,6 +54,7 @@ static const cmd_table_t cmd_table[] = {
|
||||
{"devid", 3, CMD_HIDDEN, do_devid },
|
||||
{"help", 1, CMD_NO_FLAG, do_help },
|
||||
{"hidden", 2, CMD_HIDDEN, do_test },
|
||||
{"info", 1, CMD_NO_FLAG, do_info },
|
||||
{"secret", 1, CMD_SECRET, do_test },
|
||||
{"time", 1, CMD_NO_FLAG, do_time },
|
||||
};
|
||||
@ -114,11 +117,11 @@ int cmd_interpreter(char * cmdline) {
|
||||
}
|
||||
entry = bsearch(cmdline, cmd_table, sizeof(cmd_table)/sizeof(cmd_table[0]), sizeof(cmd_table[0]), compar);
|
||||
if (entry == NULL) {
|
||||
printf("command \"%s\" not found.\n", cmdline);
|
||||
printf("Command \"%s\" not found.\n", cmdline);
|
||||
} else {
|
||||
printf("command: \"%s\" ...\n", entry->name );
|
||||
printf("Command \"%s\":\n", entry->name);
|
||||
if (*ptr != '\0')
|
||||
printf("with parameter: %s\n", ptr );
|
||||
printf("called with parameter: \"%s\"\n", ptr);
|
||||
rv = entry->func(ptr);
|
||||
}
|
||||
return rv;
|
||||
@ -145,21 +148,54 @@ int do_devid(char *args) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int do_info(char *args) {
|
||||
(void)args;
|
||||
print_system_info();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int do_time(char *args) {
|
||||
|
||||
HAL_StatusTypeDef status;
|
||||
RTC_TimeTypeDef time;
|
||||
RTC_DateTypeDef date;
|
||||
RTC_TimeTypeDef stime = {0};
|
||||
RTC_DateTypeDef sdate = {0};
|
||||
int rv = 0;
|
||||
|
||||
if (!args) {
|
||||
status = HAL_RTC_GetTime(&hrtc, &time, RTC_FORMAT_BIN);
|
||||
if (status != HAL_OK)
|
||||
puts("HAL_RTC_GetTime problem...");
|
||||
if (args) {
|
||||
|
||||
status = HAL_RTC_GetDate(&hrtc, &date, RTC_FORMAT_BIN);
|
||||
printf("%02d%02d-%02d-%02d %02d:%02d:%02d\n", (date.Year < 22) ? 21 : 20, date.Year, date.Month, date.Date, time.Hours, time.Minutes, time.Seconds);
|
||||
struct _tm_ tp;
|
||||
rv = strtotime (args, &tp);
|
||||
if (rv > 0) {
|
||||
printf("%02d%02d-%02d-%02d %02d:%02d:%02d\n", (tp.year < DATE_COMPILE_YEAR) ? DATE_COMPILE_CENTURY + 1 : DATE_COMPILE_CENTURY, \
|
||||
tp.year, tp.mon, tp.day, tp.hour, tp.min, tp.sec);
|
||||
/** Initialize RTC and set the Time and Date */
|
||||
stime.Hours = (uint8_t)tp.hour;
|
||||
stime.Minutes = (uint8_t)tp.min;
|
||||
stime.Seconds = (uint8_t)tp.sec;
|
||||
stime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
|
||||
stime.StoreOperation = RTC_STOREOPERATION_RESET;
|
||||
if (HAL_RTC_SetTime(&hrtc, &stime, RTC_FORMAT_BIN) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
sdate.WeekDay = RTC_WEEKDAY_MONDAY;
|
||||
sdate.Month = (uint8_t)tp.mon;
|
||||
sdate.Date = (uint8_t)tp.day;
|
||||
sdate.Year = (uint8_t)tp.year;
|
||||
//uint8_t weekday;
|
||||
//weekday = dayofweek((tp.year < DATE_COMPILE_YEAR) ? DATE_COMPILE_CENTURY + 1 : DATE_COMPILE_CENTURY, sdate.Year, sdate.Month, sdate.Date);
|
||||
//printf("Wochentag: %d\n", weekday);
|
||||
if (HAL_RTC_SetDate(&hrtc, &sdate, RTC_FORMAT_BIN) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
status = HAL_RTC_GetTime(&hrtc, &stime, RTC_FORMAT_BIN);
|
||||
if (status != HAL_OK)
|
||||
puts("HAL_RTC_GetTime problem...");
|
||||
status = HAL_RTC_GetDate(&hrtc, &sdate, RTC_FORMAT_BIN);
|
||||
printf("%02d%02d-%02d-%02d %02d:%02d:%02d\n", (sdate.Year < DATE_COMPILE_YEAR) ? DATE_COMPILE_CENTURY + 1 : DATE_COMPILE_CENTURY, \
|
||||
sdate.Year, sdate.Month, sdate.Date, stime.Hours, stime.Minutes, stime.Seconds);
|
||||
return rv;
|
||||
}
|
||||
|
||||
int do_help(char *args) {
|
||||
|
@ -6,6 +6,21 @@
|
||||
*/
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h> /* sscanf */
|
||||
|
||||
#include <at1_defines.h> /* include my defines from a global view, else */
|
||||
#ifndef DATE_COMPILE_CENTURY
|
||||
#define DATE_COMPILE_CENTURY (20)
|
||||
#define DATE_COMPILE_YEAR (22)
|
||||
#endif
|
||||
|
||||
#if !defined _SYS_ERRNO_H_ && !defined __ERRNO_H__ && !defined __AT1_ERROR_NUMBERS__
|
||||
#include <errno.h>
|
||||
#endif
|
||||
/* do not use the #include <time.h> library */
|
||||
#include "helper.h"
|
||||
|
||||
char *ltrim(char *s)
|
||||
{
|
||||
@ -25,3 +40,111 @@ char *trim(char *s)
|
||||
{
|
||||
return rtrim(ltrim(s));
|
||||
}
|
||||
|
||||
/* this is ISO 8601 2018-12-31 with separator == '-' */
|
||||
int strtotime (char *s, struct _tm_ *tp) {
|
||||
|
||||
int rv = 0;
|
||||
uint32_t tmp;
|
||||
struct _tm_ tm = {0};
|
||||
do {
|
||||
/* Check for the day and/or year */
|
||||
tmp = strtoul(s, &s, 10); /* base 10 */
|
||||
/* Check of plausibility: Year must be within compilation year and max 10 centuries from now on, i.e. 3000 */
|
||||
if (tmp >= (DATE_COMPILE_CENTURY * 100 + DATE_COMPILE_YEAR) && tmp < ((DATE_COMPILE_CENTURY + 10) * 100)) {
|
||||
tm.year = (uint8_t)(tmp % 100UL);
|
||||
} else {
|
||||
rv = -EINVAL;
|
||||
break;
|
||||
}
|
||||
rv = sscanf(s, "-%hu-%hu %hu:%hu:%hu", &tm.mon, &tm.day, &tm.hour, &tm.min, &tm.sec);
|
||||
if (rv >= 3)
|
||||
*tp = tm;
|
||||
else
|
||||
rv = -EINVAL;
|
||||
|
||||
} while(0);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
||||
while (*str == ' ') {
|
||||
str++;
|
||||
};
|
||||
*args = str;
|
||||
return CMD_OK;
|
||||
} else {
|
||||
separator = '/';
|
||||
if (tmp > 0 && tmp < 32)
|
||||
timeinfo.tm_mday = tmp;
|
||||
else
|
||||
goto error;
|
||||
}
|
||||
|
||||
str++;
|
||||
/* Read the month */
|
||||
tmp = strtoul(str, &str, 10);
|
||||
if (*str != separator || tmp == 0 || tmp > 12)
|
||||
goto error;
|
||||
timeinfo.tm_mon = tmp - 1; /* the month is interpreted from 0..11 */
|
||||
str++;
|
||||
/* Check either the day or the four-digit year */
|
||||
tmp = strtoul(str, &str, 10);
|
||||
/* there should either spaces or a T between date and time info */
|
||||
if ((toupper(*str) != 'T' && *str != ' ') || tmp == 0 || tmp >= 2106)
|
||||
goto error;
|
||||
if (separator == '-') {
|
||||
timeinfo.tm_mday = tmp;
|
||||
} else if (tmp >= FW_VERSION_YEAR) {
|
||||
timeinfo.tm_year = tmp - 1900;
|
||||
} else {
|
||||
goto error;
|
||||
}
|
||||
do {
|
||||
str++;
|
||||
} while (*str == ' ');
|
||||
|
||||
/* the hour have to be 0..23 */
|
||||
tmp = strtoul(str, &str, 10);
|
||||
if (*str != ':' || tmp > 23)
|
||||
goto error;
|
||||
timeinfo.tm_hour = tmp;
|
||||
str++;
|
||||
/* the minute have to be 0..59 */
|
||||
tmp = strtoul(str, &str, 10);
|
||||
if (tmp > 59)
|
||||
goto error;
|
||||
timeinfo.tm_min = tmp;
|
||||
|
||||
if (*str == ':') {
|
||||
str++;
|
||||
tmp = strtoul(str, &str, 10);
|
||||
} else {
|
||||
tmp = 0;
|
||||
}
|
||||
if (tmp > 59)
|
||||
goto error;
|
||||
timeinfo.tm_sec = tmp;
|
||||
|
||||
while (*str == ' ')
|
||||
str++;
|
||||
if (*str != '\0' && (flags & ARG_LAST))
|
||||
goto error;
|
||||
/* Try to create the time stamp */
|
||||
{
|
||||
time_t tmp_unixtime = mktime(&timeinfo);
|
||||
if (tmp_unixtime == (unsigned)-1) {
|
||||
goto error;
|
||||
}
|
||||
*args = str;
|
||||
*unixtime = tmp_unixtime;
|
||||
}
|
||||
return CMD_OK;
|
||||
|
||||
error:
|
||||
*args = str;
|
||||
return CMD_ERROR_PARAMETERS;
|
||||
}
|
||||
#endif
|
||||
|
@ -112,7 +112,7 @@ void start_morse_task(void *argument);
|
||||
void start_clk2_task(void *argument);
|
||||
|
||||
/* USER CODE BEGIN PFP */
|
||||
void print_system_info(void);
|
||||
|
||||
void ringbuffer_callback(uint16_t delimiterfound, void * cb_data);
|
||||
/* USER CODE END PFP */
|
||||
|
||||
@ -184,13 +184,13 @@ int main(void)
|
||||
/* USER CODE BEGIN 2 */
|
||||
si5351_inst_t si5351_inst = 0;
|
||||
|
||||
//printf("Date Compile Century: %d\n", DATE_COMPILE_CENTURY);
|
||||
//printf("Date Compile Year: %d\n", DATE_COMPILE_YEAR);
|
||||
|
||||
print_system_info();
|
||||
|
||||
|
||||
// do some tests for ringbuf.h library
|
||||
|
||||
//struct ringbuf * ring;
|
||||
|
||||
ring = ringbuf_create(mainbuf_size, RINGBUF_ALLOWOVERWRITE);
|
||||
if (ring == NULL)
|
||||
puts("Can't create memory for ringbuffer");
|
||||
@ -382,12 +382,8 @@ int main(void)
|
||||
/* We should never get here as control is now taken by the scheduler */
|
||||
/* Infinite loop */
|
||||
/* USER CODE BEGIN WHILE */
|
||||
|
||||
|
||||
|
||||
while (1)
|
||||
{
|
||||
|
||||
/* USER CODE END WHILE */
|
||||
|
||||
/* USER CODE BEGIN 3 */
|
||||
@ -578,8 +574,8 @@ static void MX_RTC_Init(void)
|
||||
|
||||
/** Initialize RTC and set the Time and Date
|
||||
*/
|
||||
sTime.Hours = 0x12;
|
||||
sTime.Minutes = 0x30;
|
||||
sTime.Hours = 0x0;
|
||||
sTime.Minutes = 0x0;
|
||||
sTime.Seconds = 0x0;
|
||||
sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
|
||||
sTime.StoreOperation = RTC_STOREOPERATION_RESET;
|
||||
@ -588,8 +584,8 @@ static void MX_RTC_Init(void)
|
||||
Error_Handler();
|
||||
}
|
||||
sDate.WeekDay = RTC_WEEKDAY_MONDAY;
|
||||
sDate.Month = RTC_MONTH_MAY;
|
||||
sDate.Date = 0x23;
|
||||
sDate.Month = RTC_MONTH_AUGUST;
|
||||
sDate.Date = 0x1;
|
||||
sDate.Year = 0x22;
|
||||
|
||||
if (HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BCD) != HAL_OK)
|
||||
@ -829,15 +825,24 @@ int _write(int fd, unsigned char *p, int len)
|
||||
return len;
|
||||
}
|
||||
|
||||
//int _write_r(void *reent, int fd, char *p, size_t len)
|
||||
//{
|
||||
// return _write(fd, p, len);
|
||||
//}
|
||||
|
||||
void print_system_info(void) {
|
||||
puts("\n**************************************");
|
||||
puts("*************************************");
|
||||
puts(PROGRAM_ID " " AUTHOR_STRING);
|
||||
puts("Compiled: " __DATE__ " " __TIME__);
|
||||
puts(osKernelSystemId);
|
||||
printf("CMSIS V%u.%u\n", __CM_CMSIS_VERSION_MAIN, __CM_CMSIS_VERSION_SUB);
|
||||
printf("STM32L4 CMSIS Device V%u.%u.%u.%u\n", __STM32L4_CMSIS_VERSION_MAIN,
|
||||
__STM32L4_CMSIS_VERSION_SUB1,__STM32L4_CMSIS_VERSION_SUB2,__STM32L4_CMSIS_VERSION_RC);
|
||||
printf("STM32L4xx HAL Driver V%u.%u.%u.%u\n", STM32L4XX_HAL_VERSION_MAIN,
|
||||
STM32L4XX_HAL_VERSION_SUB1, STM32L4XX_HAL_VERSION_SUB2, STM32L4XX_HAL_VERSION_RC);
|
||||
printf("Si5351 STM32-driver V%u.%u.%u\n", __SI5351__, __SI5351_MINOR__, __SI5351_PATCHLEVEL__);
|
||||
printf("GNU Compiler Collection V%u.%u.%u\n", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
|
||||
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
||||
puts("Byte Order: little-endian");
|
||||
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
|
||||
puts("Byte Order: big-endian");
|
||||
#endif
|
||||
puts("Newlib V" _NEWLIB_VERSION);
|
||||
}
|
||||
|
||||
void make_di_dah(si5351_inst_t inst, unsigned int dah, uint32_t delay, uint8_t clk) {
|
||||
@ -912,7 +917,6 @@ void morse(si5351_inst_t inst, char * s, uint32_t delay, uint8_t clk) {
|
||||
break;
|
||||
case '$': ch = 0x04; /* error 0b00000 100 */
|
||||
break;
|
||||
|
||||
case ' ': /* make a word break */
|
||||
osDelay(7*delay); /* fall through */
|
||||
default:
|
||||
@ -980,11 +984,11 @@ void StartDefaultTask(void *argument)
|
||||
|
||||
/* Infinite loop */
|
||||
for(;;) {
|
||||
HAL_GPIO_TogglePin(LD1_GPIO_Port, LD1_Pin);
|
||||
//HAL_GPIO_WritePin(LD1_GPIO_Port, LD1_Pin, GPIO_PIN_SET);
|
||||
//HAL_GPIO_TogglePin(LD1_GPIO_Port, LD1_Pin);
|
||||
HAL_GPIO_WritePin(LD1_GPIO_Port, LD1_Pin, GPIO_PIN_SET);
|
||||
osDelay(100);
|
||||
HAL_GPIO_TogglePin(LD1_GPIO_Port, LD1_Pin);
|
||||
//HAL_GPIO_WritePin(LD1_GPIO_Port, LD1_Pin, GPIO_PIN_RESET);
|
||||
//HAL_GPIO_TogglePin(LD1_GPIO_Port, LD1_Pin);
|
||||
HAL_GPIO_WritePin(LD1_GPIO_Port, LD1_Pin, GPIO_PIN_RESET);
|
||||
sw = HAL_GPIO_ReadPin(B1_GPIO_Port, B1_Pin);
|
||||
if (sw_last == GPIO_PIN_RESET && sw == GPIO_PIN_SET) {
|
||||
leds_on = !leds_on;
|
||||
@ -1019,8 +1023,7 @@ void start_terminal_task(void *argument)
|
||||
/* USER CODE BEGIN start_terminal_task */
|
||||
(void)argument;
|
||||
|
||||
|
||||
char data[128];
|
||||
char data[RINGBUF_MAX_READ_LEN + 1];
|
||||
char *tdata = data;
|
||||
int bytes;
|
||||
int rv;
|
||||
@ -1030,28 +1033,22 @@ void start_terminal_task(void *argument)
|
||||
//HAL_UART_Receive_IT(&hlpuart1, UART1_rxBuffer, 1);
|
||||
// osSemaphoreRelease is in the callback function when a command is entered
|
||||
osSemaphoreAcquire(commandHandle, osWaitForever);
|
||||
// status = HAL_RTC_GetTime(&hrtc, &time, RTC_FORMAT_BIN);
|
||||
// if (status != HAL_OK)
|
||||
// puts("HAL_RTC_GetTime problem...");
|
||||
// status = HAL_RTC_GetDate(&hrtc, &date, RTC_FORMAT_BIN);
|
||||
// printf("%02d%02d-%02d-%02d %02d:%02d:%02d\n", (date.Year < 22) ? 21 : 20, date.Year, date.Month, date.Date, time.Hours, time.Minutes, time.Seconds);
|
||||
//ringbuf_dump(ring);
|
||||
|
||||
do {
|
||||
bytes = ringbuf_read(ring, data);
|
||||
printf("READ (%d): %s\n",bytes, data);
|
||||
// printf("READ (%d): %s\n",bytes, data);
|
||||
if (bytes) {
|
||||
ringbuf_dump(ring);
|
||||
//ringbuf_dump(ring);
|
||||
tdata = trim(data);
|
||||
printf("TRIMMED (%d): %s\n",strlen(tdata), tdata);
|
||||
// printf("TRIMMED (%d): %s\n",strlen(tdata), tdata);
|
||||
rv = cmd_interpreter(tdata);
|
||||
if (rv) {
|
||||
if (rv < 0) {
|
||||
printf("ERROR: %d\n", -rv);
|
||||
}
|
||||
}
|
||||
if (ringbuf_is_empty(ring))
|
||||
break;
|
||||
} while (bytes);
|
||||
//osDelay(9999);
|
||||
}
|
||||
/* USER CODE END start_terminal_task */
|
||||
}
|
||||
|
Reference in New Issue
Block a user