Skip to content

Commit

Permalink
FWXV-221 Added telemetry project (#213)
Browse files Browse the repository at this point in the history
* FWXV-221 Added telemetry project

* FWXV-221 Deleting unnecessary file

* Not sure why these extra files are being generated, getting rid of them
  • Loading branch information
elbertchen1 authored Sep 28, 2023
1 parent 266fafb commit bab1374
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 1 deletion.
2 changes: 1 addition & 1 deletion libraries/codegen/boards/boards.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@
- new_can
- can_communication
- can_debug

- telemetry
11 changes: 11 additions & 0 deletions libraries/codegen/boards/telemetry.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
Messages:
test_msg:
id: 0
target:
telemetry:
watchdog: 0
critical: true
signals:
test:
length: 8
16 changes: 16 additions & 0 deletions projects/telemetry/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!--
General guidelines
These are just guidelines, not strict rules - document however seems best.
A README for a firmware-only project (e.g. Babydriver, MPXE, bootloader, CAN explorer) should answer the following questions:
- What is it?
- What problem does it solve?
- How do I use it? (with usage examples / example commands, etc)
- How does it work? (architectural overview)
A README for a board project (powering a hardware board, e.g. power distribution, centre console, charger, BMS carrier) should answer the following questions:
- What is the purpose of the board?
- What are all the things that the firmware needs to do?
- How does it fit into the overall system?
- How does it work? (architectural overview, e.g. what each module's purpose is or how data flows through the firmware)
-->
# telemetry

7 changes: 7 additions & 0 deletions projects/telemetry/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"libs": [
"FreeRTOS",
"ms-common"
],
"can": true
}
61 changes: 61 additions & 0 deletions projects/telemetry/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include "can.h"
#include "can_board_ids.h"
#include "log.h"
#include "tasks.h"

#define TARGET_HEX_MASK 0xF0
#define TARGET_BIT_SHIFT 4
#define SIZE_OF_UINT32 4

// Add telemetry CAN message IDs here
static const CanMessageId telemetry_ids[] = {
SYSTEM_CAN_MESSAGE_TELEMETRY_TEST_MSG,
};

static CanStorage s_can_storage = { 0 };
const CanSettings can_settings = {
.device_id = 0x1,
.bitrate = CAN_HW_BITRATE_500KBPS,
.tx = { GPIO_PORT_A, 12 },
.rx = { GPIO_PORT_A, 11 },
.loopback = true,
.mode = CAN_ONE_SHOT_MODE,
};

// Function to pop CAN messages off the queue if they are addressed to telemetry
StatusCode telemetry_queue_pop(CanMessage *msg) {
if (can_receive(msg) == STATUS_CODE_OK) {
for (uint8_t i = 0; i < sizeof(telemetry_ids) / SIZE_OF_UINT32; i++) {
if (telemetry_ids[i] == msg->id.raw) {
return STATUS_CODE_OK;
}
}
}
memset(msg, 0, sizeof(*msg));
return STATUS_CODE_EMPTY;
}

// Sample task using telemetry_queue_pop to receive telemetry messages
TASK(master_task, TASK_MIN_STACK_SIZE) {
CanMessage msg = { 0 };
while (true) {
if (telemetry_queue_pop(&msg) == STATUS_CODE_OK) {
LOG_DEBUG("Received a message!\n");
}
}
}

int main() {
tasks_init();
log_init();

LOG_DEBUG("Welcome to Telemetry!\n");
can_init(&s_can_storage, &can_settings);

tasks_init_task(master_task, TASK_PRIORITY(2), NULL);

tasks_start();

LOG_DEBUG("exiting main?\n");
return 0;
}

0 comments on commit bab1374

Please sign in to comment.