forked from test34/can_wizard
add timestamp control
This commit is contained in:
parent
ebca79b676
commit
cc79d4e954
5 changed files with 66 additions and 1 deletions
|
@ -6,6 +6,7 @@ set(COMPONENT_SRCS
|
|||
"fs.c"
|
||||
"xvprintf.c"
|
||||
"cmd_can.c"
|
||||
"cmd_utils.c"
|
||||
)
|
||||
|
||||
set(COMPONENT_ADD_INCLUDEDIRS
|
||||
|
|
54
main/cmd_utils.c
Normal file
54
main/cmd_utils.c
Normal file
|
@ -0,0 +1,54 @@
|
|||
#include "cmd_utils.h"
|
||||
#include "esp_log.h"
|
||||
#include "inttypes.h"
|
||||
#include "freertos/projdefs.h"
|
||||
#include "string.h"
|
||||
#include "esp_console.h"
|
||||
#include "argtable3/argtable3.h"
|
||||
#include "xvprintf.h"
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
|
||||
static void register_timestamp(void);
|
||||
|
||||
void register_utils_commands(void) {
|
||||
register_timestamp();
|
||||
}
|
||||
|
||||
static struct {
|
||||
struct arg_str *enable;
|
||||
struct arg_end *end;
|
||||
} timestamp_args;
|
||||
|
||||
static int timestamp(int argc, char **argv) {
|
||||
bool en = true;
|
||||
int nerrors = arg_parse(argc, argv, (void **) ×tamp_args);
|
||||
if (nerrors == 0) {
|
||||
const char *arg_str_ptr = timestamp_args.enable->sval[0];
|
||||
if (arg_str_ptr[0] == 'd') en = false;
|
||||
}
|
||||
if (en) {
|
||||
print_w_clr_time("Enabled timestamps!", LOG_COLOR_PURPLE, true);
|
||||
timestamp_enabled = true;
|
||||
} else {
|
||||
print_w_clr_time("Disabled timestamps!", LOG_COLOR_PURPLE, true);
|
||||
timestamp_enabled = false;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void register_timestamp(void) {
|
||||
|
||||
timestamp_args.enable = arg_str1(NULL, NULL, "<enable|disable>", "Enable by default, can be abbreviations.");
|
||||
timestamp_args.end = arg_end(2);
|
||||
|
||||
const esp_console_cmd_t cmd = {
|
||||
.command = "timestamp",
|
||||
.help = "Enable or disable timestamp in messages.",
|
||||
.hint = NULL,
|
||||
.func = ×tamp,
|
||||
.argtable = ×tamp_args,
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_console_cmd_register(&cmd));
|
||||
}
|
8
main/cmd_utils.h
Normal file
8
main/cmd_utils.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
#ifndef MAIN_CMD_UTILS_H
|
||||
#define MAIN_CMD_UTILS_H
|
||||
|
||||
// functions
|
||||
|
||||
void register_utils_commands(void);
|
||||
|
||||
#endif // MAIN_CMD_UTILS_H
|
|
@ -18,6 +18,7 @@
|
|||
#include "driver/usb_serial_jtag.h"
|
||||
#include "cmd_system.h"
|
||||
#include "cmd_can.h"
|
||||
#include "cmd_utils.h"
|
||||
#include "can.h"
|
||||
#include "fs.h"
|
||||
#include "xvprintf.h"
|
||||
|
@ -210,4 +211,5 @@ void initialize_console(void) {
|
|||
esp_console_register_help_command();
|
||||
register_system();
|
||||
register_can_commands();
|
||||
register_utils_commands();
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include "esp_log.h"
|
||||
|
||||
RingbufHandle_t can_messages;
|
||||
bool timestamp_enabled = true;
|
||||
bool timestamp_enabled = false;
|
||||
|
||||
void init_tx_ringbuf() {
|
||||
can_messages = xRingbufferCreate(2200, RINGBUF_TYPE_NOSPLIT);
|
||||
|
|
Loading…
Reference in a new issue