Skip to content

Commit

Permalink
Telem Firmware Implemented (#1246)
Browse files Browse the repository at this point in the history
### Changelist 
Telem proto, .h and .c files, minor changes to io_can.h in order to have
it such that io can use can and pass tests (thanks Holly)

### Testing Done
built and flashed onto spare board, works fine

### Resolved Tickets
n/a
  • Loading branch information
forbesashli authored May 5, 2024
1 parent dc1d9e3 commit 42c6cf6
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 18 deletions.
6 changes: 4 additions & 2 deletions firmware/quadruna/VC/proto/telem.proto
Original file line number Diff line number Diff line change
@@ -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;
}
30 changes: 18 additions & 12 deletions firmware/quadruna/VC/src/io/io_telemMessage.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -12,43 +11,50 @@
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)
{
modem_900_choice = true; // if false, then using the 2.4GHz,
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;
}
3 changes: 2 additions & 1 deletion firmware/quadruna/VC/src/io/io_telemMessage.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once
#include "app_utils.h"
#include "io_can.h"

#ifdef TARGET_EMBEDDED
#include "hw_uart.h"
Expand All @@ -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);
bool io_telemMessage_broadcast(CanMsg *rx_msg);
3 changes: 1 addition & 2 deletions firmware/quadruna/VC/src/tasks.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions firmware/shared/src/hw/hw_can.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions firmware/shared/src/io/io_can.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "io_can.h"
#include <stdbool.h>
#include <string.h>
#include <assert.h>
#include "cmsis_os.h"
#include "queue.h"
Expand Down
16 changes: 15 additions & 1 deletion firmware/shared/src/io/io_can.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

#include <stdint.h>
#include <stdbool.h>
#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
Expand Down Expand Up @@ -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.
Expand All @@ -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

0 comments on commit 42c6cf6

Please sign in to comment.