drivers: can: shell: print device name in RX path
Include the device name when printing received CAN frames. This improves the user experience when working with multiple CAN controllers via the CAN shell. Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
This commit is contained in:
parent
68c48cd116
commit
88fb5e2edb
2 changed files with 43 additions and 13 deletions
|
@ -186,16 +186,20 @@ Received CAN frames matching the added filter(s) are printed to the shell. A few
|
||||||
|
|
||||||
.. code-block:: console
|
.. code-block:: console
|
||||||
|
|
||||||
# Flags ID Size Data bytes
|
# Dev Flags ID Size Data bytes
|
||||||
-- 010 [8] 01 02 03 04 05 06 07 08
|
can0 -- 010 [8] 01 02 03 04 05 06 07 08
|
||||||
B- 010 [08] 01 02 03 04 05 06 07 08
|
can0 B- 010 [08] 01 02 03 04 05 06 07 08
|
||||||
BP 010 [03] 01 aa bb
|
can0 BP 010 [03] 01 aa bb
|
||||||
-- 00000010 [0]
|
can0 -- 00000010 [0]
|
||||||
-- 010 [1] 20
|
can0 -- 010 [1] 20
|
||||||
-- 010 [8] remote transmission request
|
can0 -- 010 [8] remote transmission request
|
||||||
|
|
||||||
The columns have the following meaning:
|
The columns have the following meaning:
|
||||||
|
|
||||||
|
* Dev
|
||||||
|
|
||||||
|
* Name of the device receiving the frame.
|
||||||
|
|
||||||
* Flags
|
* Flags
|
||||||
|
|
||||||
* ``B``: The frame has the CAN FD Baud Rate Switch (BRS) flag set.
|
* ``B``: The frame has the CAN FD Baud Rate Switch (BRS) flag set.
|
||||||
|
|
|
@ -20,6 +20,11 @@ struct can_shell_tx_event {
|
||||||
int error;
|
int error;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct can_shell_rx_event {
|
||||||
|
struct can_frame frame;
|
||||||
|
const struct device *dev;
|
||||||
|
};
|
||||||
|
|
||||||
struct can_shell_mode_mapping {
|
struct can_shell_mode_mapping {
|
||||||
const char *name;
|
const char *name;
|
||||||
can_mode_t mode;
|
can_mode_t mode;
|
||||||
|
@ -49,7 +54,8 @@ static struct k_poll_event can_shell_tx_msgq_events[] = {
|
||||||
&can_shell_tx_msgq, 0)
|
&can_shell_tx_msgq, 0)
|
||||||
};
|
};
|
||||||
|
|
||||||
CAN_MSGQ_DEFINE(can_shell_rx_msgq, CONFIG_CAN_SHELL_RX_QUEUE_SIZE);
|
K_MSGQ_DEFINE(can_shell_rx_msgq, sizeof(struct can_shell_rx_event),
|
||||||
|
CONFIG_CAN_SHELL_RX_QUEUE_SIZE, 4);
|
||||||
const struct shell *can_shell_rx_msgq_sh;
|
const struct shell *can_shell_rx_msgq_sh;
|
||||||
static struct k_work_poll can_shell_rx_msgq_work;
|
static struct k_work_poll can_shell_rx_msgq_work;
|
||||||
static struct k_poll_event can_shell_rx_msgq_events[] = {
|
static struct k_poll_event can_shell_rx_msgq_events[] = {
|
||||||
|
@ -62,7 +68,8 @@ static struct k_poll_event can_shell_rx_msgq_events[] = {
|
||||||
static void can_shell_tx_msgq_triggered_work_handler(struct k_work *work);
|
static void can_shell_tx_msgq_triggered_work_handler(struct k_work *work);
|
||||||
static void can_shell_rx_msgq_triggered_work_handler(struct k_work *work);
|
static void can_shell_rx_msgq_triggered_work_handler(struct k_work *work);
|
||||||
|
|
||||||
static void can_shell_print_frame(const struct shell *sh, const struct can_frame *frame)
|
static void can_shell_print_frame(const struct shell *sh, const struct device *dev,
|
||||||
|
const struct can_frame *frame)
|
||||||
{
|
{
|
||||||
uint8_t nbytes = can_dlc_to_bytes(frame->dlc);
|
uint8_t nbytes = can_dlc_to_bytes(frame->dlc);
|
||||||
int i;
|
int i;
|
||||||
|
@ -72,6 +79,8 @@ static void can_shell_print_frame(const struct shell *sh, const struct can_frame
|
||||||
shell_fprintf(sh, SHELL_NORMAL, "(%05d) ", frame->timestamp);
|
shell_fprintf(sh, SHELL_NORMAL, "(%05d) ", frame->timestamp);
|
||||||
#endif /* CONFIG_CAN_RX_TIMESTAMP */
|
#endif /* CONFIG_CAN_RX_TIMESTAMP */
|
||||||
|
|
||||||
|
shell_fprintf(sh, SHELL_NORMAL, "%s ", dev->name);
|
||||||
|
|
||||||
#ifdef CONFIG_CAN_FD_MODE
|
#ifdef CONFIG_CAN_FD_MODE
|
||||||
/* Flags */
|
/* Flags */
|
||||||
shell_fprintf(sh, SHELL_NORMAL, "%c%c ",
|
shell_fprintf(sh, SHELL_NORMAL, "%c%c ",
|
||||||
|
@ -156,6 +165,23 @@ static void can_shell_tx_callback(const struct device *dev, int error, void *use
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void can_shell_rx_callback(const struct device *dev, struct can_frame *frame,
|
||||||
|
void *user_data)
|
||||||
|
{
|
||||||
|
struct can_shell_rx_event event;
|
||||||
|
int err;
|
||||||
|
|
||||||
|
ARG_UNUSED(user_data);
|
||||||
|
|
||||||
|
event.frame = *frame;
|
||||||
|
event.dev = dev;
|
||||||
|
|
||||||
|
err = k_msgq_put(&can_shell_rx_msgq, &event, K_NO_WAIT);
|
||||||
|
if (err != 0) {
|
||||||
|
LOG_ERR("CAN shell rx event queue full");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int can_shell_rx_msgq_poll_submit(const struct shell *sh)
|
static int can_shell_rx_msgq_poll_submit(const struct shell *sh)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
@ -177,10 +203,10 @@ static int can_shell_rx_msgq_poll_submit(const struct shell *sh)
|
||||||
|
|
||||||
static void can_shell_rx_msgq_triggered_work_handler(struct k_work *work)
|
static void can_shell_rx_msgq_triggered_work_handler(struct k_work *work)
|
||||||
{
|
{
|
||||||
struct can_frame frame;
|
struct can_shell_rx_event event;
|
||||||
|
|
||||||
while (k_msgq_get(&can_shell_rx_msgq, &frame, K_NO_WAIT) == 0) {
|
while (k_msgq_get(&can_shell_rx_msgq, &event, K_NO_WAIT) == 0) {
|
||||||
can_shell_print_frame(can_shell_rx_msgq_sh, &frame);
|
can_shell_print_frame(can_shell_rx_msgq_sh, event.dev, &event.frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)can_shell_rx_msgq_poll_submit(can_shell_rx_msgq_sh);
|
(void)can_shell_rx_msgq_poll_submit(can_shell_rx_msgq_sh);
|
||||||
|
@ -879,7 +905,7 @@ static int cmd_can_filter_add(const struct shell *sh, size_t argc, char **argv)
|
||||||
(filter.flags & CAN_FILTER_IDE) != 0 ? 8 : 3, filter.id,
|
(filter.flags & CAN_FILTER_IDE) != 0 ? 8 : 3, filter.id,
|
||||||
(filter.flags & CAN_FILTER_IDE) != 0 ? 8 : 3, filter.mask);
|
(filter.flags & CAN_FILTER_IDE) != 0 ? 8 : 3, filter.mask);
|
||||||
|
|
||||||
err = can_add_rx_filter_msgq(dev, &can_shell_rx_msgq, &filter);
|
err = can_add_rx_filter(dev, can_shell_rx_callback, NULL, &filter);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
shell_error(sh, "failed to add filter (err %d)", err);
|
shell_error(sh, "failed to add filter (err %d)", err);
|
||||||
return err;
|
return err;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue