adding can_cmd

This commit is contained in:
Данила Горнушко 2023-11-24 13:13:14 +03:00
parent db30acc651
commit c4da4bd248
2 changed files with 20 additions and 2 deletions

View file

@ -93,7 +93,7 @@ void can_task(void* arg) {
for (;;) { // A Task shall never return or exit. for (;;) { // A Task shall never return or exit.
// esp_task_wdt_reset(); // esp_task_wdt_reset();
can_bus_off_check(); can_bus_off_check();
if (twai_receive(&rx_msg, pdMS_TO_TICKS(10)) != ESP_OK) continue; if (twai_receive(&rx_msg, pdMS_TO_TICKS(1000)) != ESP_OK) continue;
// TODO: add software filtering // TODO: add software filtering
// if ((((rx_msg.identifier >> 8) & 0xFF) != CONFIG_DEVICE_ID) && (((rx_msg.identifier >> 8) & 0xFF) != 0xFF)) continue; // if ((((rx_msg.identifier >> 8) & 0xFF) != CONFIG_DEVICE_ID) && (((rx_msg.identifier >> 8) & 0xFF) != 0xFF)) continue;
// ESP_LOGI(LOG_TAG, "received can frame: %" PRIu32, rx_msg.identifier); // ESP_LOGI(LOG_TAG, "received can frame: %" PRIu32, rx_msg.identifier);

View file

@ -4,6 +4,7 @@
#include "hal/twai_types.h" #include "hal/twai_types.h"
#include "string.h" #include "string.h"
#include "esp_console.h" #include "esp_console.h"
#include "argtable3/argtable3.h"
#include "xvprintf.h" #include "xvprintf.h"
#include "can.h" #include "can.h"
@ -14,7 +15,19 @@ void register_can_commands(void) {
} }
static struct {
struct arg_str *message;
struct arg_end *end;
} cansend_args;
static int send_can_frame(int argc, char **argv) { static int send_can_frame(int argc, char **argv) {
int nerrors = arg_parse(argc, argv, (void **) &cansend_args);
if (nerrors != 0) {
arg_print_errors(stderr, cansend_args.end, argv[0]);
return 1;
}
const char* can_msg_str = cansend_args.message->sval[0];
char data_bytes_str[30]; char data_bytes_str[30];
twai_message_t msg = {.extd = 1}; twai_message_t msg = {.extd = 1};
msg.data_length_code = 0; msg.data_length_code = 0;
@ -26,11 +39,16 @@ static int send_can_frame(int argc, char **argv) {
} }
static void register_send_can_frame(void) { static void register_send_can_frame(void) {
cansend_args.message = arg_str1(NULL, NULL, "ID#data", "Message to send, ID and data bytes, all in hex. # is the delimiter.");
cansend_args.end = arg_end(2);
const esp_console_cmd_t cmd = { const esp_console_cmd_t cmd = {
.command = "cansend", .command = "cansend",
.help = "Send a can message to the bus", .help = "Send a can message to the bus, example: cansend 00008C03#02",
.hint = NULL, .hint = NULL,
.func = &send_can_frame, .func = &send_can_frame,
.argtable = &cansend_args,
}; };
ESP_ERROR_CHECK( esp_console_cmd_register(&cmd) ); ESP_ERROR_CHECK( esp_console_cmd_register(&cmd) );
} }