diff --git a/firmware/quadruna/VC/proto/telem.proto b/firmware/quadruna/VC/proto/telem.proto index aa34c0cf06..5739954ac7 100644 --- a/firmware/quadruna/VC/proto/telem.proto +++ b/firmware/quadruna/VC/proto/telem.proto @@ -1,8 +1,10 @@ -// Test tracksight message +// Tracksight Message + syntax = "proto3"; +import "nanopb.proto"; message TelemMessage { int32 can_id = 1; - int32 data = 2; + repeated int32 message = 2 [(nanopb).max_count = 8]; int32 time_stamp = 3; } \ No newline at end of file diff --git a/firmware/quadruna/VC/src/io/io_telemMessage.c b/firmware/quadruna/VC/src/io/io_telemMessage.c index 36e1a19125..da21ed2e66 100644 --- a/firmware/quadruna/VC/src/io/io_telemMessage.c +++ b/firmware/quadruna/VC/src/io/io_telemMessage.c @@ -2,8 +2,7 @@ #include "telem.pb.h" #include "pb_encode.h" #include "pb_decode.h" -#include "cmsis_os.h" -#include "queue.h" +#include "io_time.h" // create the truth table for now to decide which amount of things to use // create or grab the constants for the different modem and pins and such @@ -12,13 +11,17 @@ static bool modem_900_choice; static Modem *modem; +#define CAN_DATA_LENGTH 8 +#define UART_LENGTH 1 #define QUEUE_SIZE 12 #define QUEUE_BYTES 4 * QUEUE_SIZE // this is all temp +static bool modem_900_choice; +static Modem *modem; static bool proto_status; static uint8_t proto_msg_length; static uint8_t proto_buffer[QUEUE_SIZE]; // TODO: verify that this is the needed size (most likely can be smaller) -TelemMessage message = TelemMessage_init_zero; +TelemMessage t_message = TelemMessage_init_zero; void io_telemMessage_init(Modem *m) { @@ -26,29 +29,32 @@ void io_telemMessage_init(Modem *m) modem = m; } -bool io_telemMessage_broadcast() +bool io_telemMessage_broadcast(CanMsg *rx_msg) { // send it over the correct UART functionality pb_ostream_t stream = pb_ostream_from_buffer(proto_buffer, sizeof(proto_buffer)); // filling in fields - message.can_id = 53; - message.data = 23; - message.time_stamp = 9; + t_message.can_id = (int32_t)(rx_msg->std_id); + for (uint8_t i = 0; i < CAN_DATA_LENGTH; i++) + { + t_message.message[i] = rx_msg->data[i]; + } + t_message.time_stamp = (int32_t)io_time_getCurrentMs(); // encoding message - proto_status = pb_encode(&stream, TelemMessage_fields, &message); + proto_status = pb_encode(&stream, TelemMessage_fields, &t_message); proto_msg_length = (uint8_t)stream.bytes_written; if (modem_900_choice == true) { - hw_uart_transmitPoll(modem->modem900M, &proto_msg_length, 1, 1); - hw_uart_transmitPoll(modem->modem900M, proto_buffer, (uint8_t)sizeof(proto_buffer), 1); + hw_uart_transmitPoll(modem->modem900M, &proto_msg_length, UART_LENGTH, UART_LENGTH); + hw_uart_transmitPoll(modem->modem900M, proto_buffer, (uint8_t)sizeof(proto_buffer), UART_LENGTH); } else { - hw_uart_transmitPoll(modem->modem2_4G, &proto_msg_length, 1, 1); - hw_uart_transmitPoll(modem->modem2_4G, proto_buffer, (uint8_t)sizeof(proto_buffer), 1); + hw_uart_transmitPoll(modem->modem2_4G, &proto_msg_length, UART_LENGTH, UART_LENGTH); + hw_uart_transmitPoll(modem->modem2_4G, proto_buffer, (uint8_t)sizeof(proto_buffer), UART_LENGTH); } return true; } \ No newline at end of file diff --git a/firmware/quadruna/VC/src/io/io_telemMessage.h b/firmware/quadruna/VC/src/io/io_telemMessage.h index 88c8073cbf..05671d4d70 100644 --- a/firmware/quadruna/VC/src/io/io_telemMessage.h +++ b/firmware/quadruna/VC/src/io/io_telemMessage.h @@ -1,5 +1,6 @@ #pragma once #include "app_utils.h" +#include "io_can.h" #ifdef TARGET_EMBEDDED #include "hw_uart.h" @@ -23,4 +24,4 @@ void io_telemMessage_init(Modem *m); * Serializes the can msg and sends it over UART to the appropriate Modem */ -bool io_telemMessage_broadcast(void); \ No newline at end of file +bool io_telemMessage_broadcast(CanMsg *rx_msg); \ No newline at end of file diff --git a/firmware/quadruna/VC/src/tasks.c b/firmware/quadruna/VC/src/tasks.c index 6cf991aba4..41c775e6ec 100644 --- a/firmware/quadruna/VC/src/tasks.c +++ b/firmware/quadruna/VC/src/tasks.c @@ -400,7 +400,6 @@ _Noreturn void tasks_run100Hz(void) // Watchdog check-in must be the last function called before putting the // task to sleep. - io_telemMessage_broadcast(); hw_watchdog_checkIn(watchdog); start_ticks += period_ms; @@ -459,7 +458,7 @@ _Noreturn void tasks_runCanRx(void) { CanMsg rx_msg; io_can_popRxMsgFromQueue(&rx_msg); - + io_telemMessage_broadcast(&rx_msg); JsonCanMsg jsoncan_rx_msg; io_jsoncan_copyFromCanMsg(&rx_msg, &jsoncan_rx_msg); io_canRx_updateRxTableWithMessage(&jsoncan_rx_msg); diff --git a/firmware/shared/src/hw/hw_can.h b/firmware/shared/src/hw/hw_can.h index 8c43cece3a..cc95d31727 100644 --- a/firmware/shared/src/hw/hw_can.h +++ b/firmware/shared/src/hw/hw_can.h @@ -51,6 +51,7 @@ bool hw_can_transmit(const CanMsg *msg); /** * Receive a CAN msg from the bus, returning whether or not a message is available. + * This function also passes up the CanMsg to a callback function. * @param msg CAN msg to be RXed. * @param rx_fifo Which RX FIFO to receive a message from. * @return Whether or not the reception was successful. diff --git a/firmware/shared/src/io/io_can.c b/firmware/shared/src/io/io_can.c index a61749c77b..8e6b8d4fc7 100644 --- a/firmware/shared/src/io/io_can.c +++ b/firmware/shared/src/io/io_can.c @@ -1,5 +1,6 @@ #include "io_can.h" #include +#include #include #include "cmsis_os.h" #include "queue.h" diff --git a/firmware/shared/src/io/io_can.h b/firmware/shared/src/io/io_can.h index 7c70437043..51a9fa6898 100644 --- a/firmware/shared/src/io/io_can.h +++ b/firmware/shared/src/io/io_can.h @@ -2,8 +2,9 @@ #include #include -#include "hw_hal.h" +#ifdef TARGET_EMBEDDED #include "hw_can.h" +#endif /** * This module is a CAN driver which manages CAN msg transmission (TX) and reception (RX) via FreeRTOS queues: One for @@ -33,6 +34,17 @@ typedef struct void (*const rx_overflow_clear_callback)(); // Callback on RX queue overflow clear. } CanConfig; +#define CAN_PAYLOAD_BYTES 8 // TODO: grab from the same place perhaps + +#ifdef TARGET_TEST +typedef struct +{ + uint32_t std_id; + uint32_t dlc; // data length range : [0, 8] + uint8_t data[CAN_PAYLOAD_BYTES]; +} CanMsg; +#endif + /** * Initialize and start the CAN peripheral. * @param can_config Config struct. @@ -57,8 +69,10 @@ void io_can_transmitMsgFromQueue(void); */ void io_can_popRxMsgFromQueue(CanMsg *msg); +#ifdef TARGET_EMBEDDED /** * Callback fired by config-specific interrupts to receive a message from a given FIFO. * @param msg CAN msg to be populated by RXed msg. */ void io_can_msgReceivedCallback(CanMsg *rx_msg); +#endif