Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions components/batt/Sconscript.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# ruff: noqa: F821

Import('env')
Import('envs')


firmware, flash = env.SConscript(
'src/SConscript.py',
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the SConscript.py under src/?

exports={'env': envs['esp32s3']},
)

component, name = env.Component(firmware, env.File('component.toml'))
env.ComponentSubtarget(name, 'flash', flash)


Return('component')
3 changes: 3 additions & 0 deletions components/batt/component.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[metadata]
name = 'batt'
description = 'battery-monitor'
40 changes: 40 additions & 0 deletions components/batt/src/batt.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include "batt.h"

#include "firmware-base/state-machine.h"
#include <ember_taskglue.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include <opencan_rx.h>
#include <opencan_tx.h>

#include <math.h>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Include only the headers you need.

#include <string.h>

// hypothetical battery percent data
typedef struct {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to make a CAN data struct, this is already generated by OpenCAN, we just have to implement a populate function.

uint8_t batteryPercent;
} CAN_Message_BatteryStatus;

static uint8_t batterypercent;

static void batt_1Hz();

// task scheduling
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't add redundant comments.

ember_rate_funcs_S module_rf = {
.call_1Hz = batt_1Hz,
};

static void batt_1Hz()
{
/*
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not in this scope, the battery monitor will just report the battery percentage.

Do I need any authorizationsfrom SUP? like
CANRX_is_message_battery_percent_data_Authorization_ok()
*/
batteryPercent = 0;
}

void CANTX_populate_BATT_BatteryPercentData(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where's the associated entry in can/network.yml?

struct CAN_Message_BatteryStatus * const m)
{
m->batteryPercent = batteryPercent;
}
4 changes: 4 additions & 0 deletions components/batt/src/batt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#ifndef BATT_H
#define BATT_H

#endif // BATT.H
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#endif // BATT.H
#endif /* BATT_H */