Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .github/workflows/clang-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
-not -path "*/zephyr/*" \
-not -path "*/.git/*" \
-not -path "*/CMakeFiles/*" \
-not -path "*/tools/autocoders/templates/*" \
-exec clang-format-18 -i {} \;

- name: Check for changes
Expand Down
2 changes: 1 addition & 1 deletion app/.template-project-backplane/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ LOG_MODULE_REGISTER(main);

int main() {
LOG_INF("Application started");

while (true) {
k_msleep(1000);
}
Expand Down
4 changes: 1 addition & 3 deletions app/.template-project/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
int main() {
return 0;
}
int main() { return 0; }
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
// F-Core Includes
#include <c_pyro_control_observer.h>
#include <f_core/c_project_configuration.h>
#include <f_core/device/c_rtc.h>
#include <f_core/net/application/c_udp_alert_tenant.h>
#include <f_core/os/c_task.h>
#include <f_core/os/flight_log.hpp>
#include <f_core/os/tenants/c_datalogger_tenant.h>
#include <f_core/net/application/c_udp_alert_tenant.h>
#include <n_autocoder_network_defs.h>
#include <f_core/device/c_rtc.h>

class CDeploymentModule : public CProjectConfiguration {
public:
Expand Down Expand Up @@ -39,7 +39,8 @@ class CDeploymentModule : public CProjectConfiguration {
CRtc rtc{*DEVICE_DT_GET(DT_ALIAS(rtc))};

std::string ipAddrStr = "10.4.1.1";
const char* sntpServerAddr = "10.2.1.1"; // TODO: Maybe we should look into hostnames? Also, still need to fix the create ip addr bug...
const char* sntpServerAddr =
"10.2.1.1"; // TODO: Maybe we should look into hostnames? Also, still need to fix the create ip addr bug...

// Tenants
CUdpAlertTenant alertTenant{"Alert Tenant", ipAddrStr.c_str(), NNetworkDefs::ALERT_PORT};
Expand All @@ -50,5 +51,3 @@ class CDeploymentModule : public CProjectConfiguration {
// Observers
CPyroControlObserver pyroControlObserver;
};


45 changes: 12 additions & 33 deletions app/backplane/deployment_module/include/c_pyro_control_observer.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
#include <f_core/utils/c_observer.h>
#include <f_core/utils/c_soft_timer.h>


class CPyroControlObserver : public CObserver {
public:
public:
CPyroControlObserver();

~CPyroControlObserver() override = default;
Expand All @@ -25,48 +24,28 @@ class CPyroControlObserver : public CObserver {
*/
void DisableCallback();

private:
private:
struct PyroTrio {
CGpio sense;
CGpio ctrl;
CGpio debugLed;
};

std::array<CGpio, 4> de9Gpios{
CGpio(GPIO_DT_SPEC_GET(DT_ALIAS(gpio0), gpios)),
CGpio(GPIO_DT_SPEC_GET(DT_ALIAS(gpio1), gpios)),
CGpio(GPIO_DT_SPEC_GET(DT_ALIAS(gpio2), gpios)),
CGpio(GPIO_DT_SPEC_GET(DT_ALIAS(gpio3), gpios))
};
CGpio(GPIO_DT_SPEC_GET(DT_ALIAS(gpio0), gpios)), CGpio(GPIO_DT_SPEC_GET(DT_ALIAS(gpio1), gpios)),
CGpio(GPIO_DT_SPEC_GET(DT_ALIAS(gpio2), gpios)), CGpio(GPIO_DT_SPEC_GET(DT_ALIAS(gpio3), gpios))};

// CFlightLog flightLog{"flight.log"};
CSoftTimer chargeDisableTimer;

std::array<PyroTrio, 4> pyroTrios{
PyroTrio{
CGpio(GPIO_DT_SPEC_GET(DT_ALIAS(pyro_sns_0), gpios)),
CGpio(GPIO_DT_SPEC_GET(DT_ALIAS(pyro_ctrl_0), gpios)),
CGpio(GPIO_DT_SPEC_GET(DT_ALIAS(led0), gpios))
},
PyroTrio{
CGpio(GPIO_DT_SPEC_GET(DT_ALIAS(pyro_sns_1), gpios)),
CGpio(GPIO_DT_SPEC_GET(DT_ALIAS(pyro_ctrl_1), gpios)),
CGpio(GPIO_DT_SPEC_GET(DT_ALIAS(led1), gpios))
},
PyroTrio{
CGpio(GPIO_DT_SPEC_GET(DT_ALIAS(pyro_sns_2), gpios)),
CGpio(GPIO_DT_SPEC_GET(DT_ALIAS(pyro_ctrl_2), gpios)),
CGpio(GPIO_DT_SPEC_GET(DT_ALIAS(led2), gpios))
},
PyroTrio{
CGpio(GPIO_DT_SPEC_GET(DT_ALIAS(pyro_sns_3), gpios)),
CGpio(GPIO_DT_SPEC_GET(DT_ALIAS(pyro_ctrl_3), gpios)),
CGpio(GPIO_DT_SPEC_GET(DT_ALIAS(led3), gpios))
},
PyroTrio{CGpio(GPIO_DT_SPEC_GET(DT_ALIAS(pyro_sns_0), gpios)),
CGpio(GPIO_DT_SPEC_GET(DT_ALIAS(pyro_ctrl_0), gpios)), CGpio(GPIO_DT_SPEC_GET(DT_ALIAS(led0), gpios))},
PyroTrio{CGpio(GPIO_DT_SPEC_GET(DT_ALIAS(pyro_sns_1), gpios)),
CGpio(GPIO_DT_SPEC_GET(DT_ALIAS(pyro_ctrl_1), gpios)), CGpio(GPIO_DT_SPEC_GET(DT_ALIAS(led1), gpios))},
PyroTrio{CGpio(GPIO_DT_SPEC_GET(DT_ALIAS(pyro_sns_2), gpios)),
CGpio(GPIO_DT_SPEC_GET(DT_ALIAS(pyro_ctrl_2), gpios)), CGpio(GPIO_DT_SPEC_GET(DT_ALIAS(led2), gpios))},
PyroTrio{CGpio(GPIO_DT_SPEC_GET(DT_ALIAS(pyro_sns_3), gpios)),
CGpio(GPIO_DT_SPEC_GET(DT_ALIAS(pyro_ctrl_3), gpios)), CGpio(GPIO_DT_SPEC_GET(DT_ALIAS(led3), gpios))},
};


};



8 changes: 3 additions & 5 deletions app/backplane/deployment_module/src/c_deployment_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@

LOG_MODULE_REGISTER(CDeploymentModule);

CDeploymentModule::CDeploymentModule(): CProjectConfiguration() {}
CDeploymentModule::CDeploymentModule() : CProjectConfiguration() {}

void CDeploymentModule::AddTenantsToTasks() {
}
void CDeploymentModule::AddTenantsToTasks() {}

void CDeploymentModule::AddTasksToRtos() {
}
void CDeploymentModule::AddTasksToRtos() {}

void CDeploymentModule::SetupCallbacks() {
alertTenant.Register();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

#include <cstdio>
#include <f_core/n_alerts.h>
#include <zephyr/logging/log.h>
#include <zephyr/drivers/rtc.h>
#include <zephyr/logging/log.h>

LOG_MODULE_REGISTER(CPyroControlObserver);

Expand All @@ -21,7 +21,6 @@ CPyroControlObserver::CPyroControlObserver() : chargeDisableTimer(chargeDisableT
chargeDisableTimer.SetUserData(this);
}


void CPyroControlObserver::Notify(void* ctx) {
uint8_t pyroCount = 0;
LOG_INF("Notified");
Expand All @@ -34,9 +33,9 @@ void CPyroControlObserver::Notify(void* ctx) {

for (auto& [sense, ctrl, led] : pyroTrios) {
// if (sense.GetPin() == 1) {
ctrl.SetPin(1);
led.SetPin(1);
LOG_INF("Deployed charge %d", pyroCount);
ctrl.SetPin(1);
led.SetPin(1);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

not strictly about the formatting but dyk why this is removed from the check

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Github diff just sucks. Look down. It just fixed the double indent

LOG_INF("Deployed charge %d", pyroCount);
// }
pyroCount++;
}
Expand All @@ -50,7 +49,6 @@ void CPyroControlObserver::Notify(void* ctx) {
break;
}


// flightLog.Sync();
}

Expand Down
34 changes: 14 additions & 20 deletions app/backplane/power_module/include/c_power_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@
#include <f_core/c_project_configuration.h>
#include <f_core/device/c_rtc.h>
#include <f_core/messaging/c_message_port.h>
#include <f_core/os/c_task.h>
#include <f_core/os/tenants/c_datalogger_tenant.h>
#include <f_core/net/application/c_udp_alert_tenant.h>
#include <f_core/net/application/c_udp_broadcast_tenant.h>

#include <f_core/os/c_task.h>
#include <f_core/os/tenants/c_datalogger_tenant.h>
#include <n_autocoder_network_defs.h>

class CPowerModule : public CProjectConfiguration {
public:
public:
/**
* Constructor
*/
Expand All @@ -42,7 +41,7 @@ class CPowerModule : public CProjectConfiguration {
*/
void Cleanup();

private:
private:
std::string ipAddrStr = CREATE_IP_ADDR(NNetworkDefs::POWER_MODULE_IP_ADDR_BASE, 2, CONFIG_MODULE_ID);
const char* sntpServerAddr = "10.2.1.1";
// TODO: Maybe we should look into hostnames?
Expand All @@ -58,29 +57,24 @@ class CPowerModule : public CProjectConfiguration {
CMessagePort<NTypes::LoRaBroadcastSensorData>& sensorDataDownlinkMessagePort;

// Tenants
CSensingTenant sensingTenant{
"Sensing Tenant", sensorDataBroadcastMessagePort, sensorDataLogMessagePort, sensorDataDownlinkMessagePort
};
CUdpBroadcastTenant<NTypes::SensorData> broadcastTenant{
"Broadcast Tenant", ipAddrStr.c_str(), telemetryBroadcastPort, telemetryBroadcastPort, sensorDataBroadcastMessagePort
};
CSensingTenant sensingTenant{"Sensing Tenant", sensorDataBroadcastMessagePort, sensorDataLogMessagePort,
sensorDataDownlinkMessagePort};
CUdpBroadcastTenant<NTypes::SensorData> broadcastTenant{"Broadcast Tenant", ipAddrStr.c_str(),
telemetryBroadcastPort, telemetryBroadcastPort,
sensorDataBroadcastMessagePort};
CUdpBroadcastTenant<NTypes::LoRaBroadcastSensorData> downlinkBroadcastTenant{
"Broadcast Tenant", ipAddrStr.c_str(), downlinkBroadcastPort, downlinkBroadcastPort, sensorDataDownlinkMessagePort
};
"Broadcast Tenant", ipAddrStr.c_str(), downlinkBroadcastPort, downlinkBroadcastPort,
sensorDataDownlinkMessagePort};

CDataLoggerTenant<NTypes::TimestampedSensorData> dataLoggerTenant{
"Data Logger Tenant", "/lfs/sensor_data.bin", LogMode::Growing, 0, sensorDataLogMessagePort, K_SECONDS(60), 5
};
"Data Logger Tenant", "/lfs/sensor_data.bin", LogMode::Growing, 0, sensorDataLogMessagePort, K_SECONDS(60), 5};
CUdpAlertTenant alertTenant{"Alert Tenant", ipAddrStr.c_str(), NNetworkDefs::ALERT_PORT};


// Tasks
static constexpr int ina219SampleTimeMillis = 69; // 68.1 ms based on our devicetree configuration, and we don't need to sample that quickly
// 68.1 ms based on our devicetree configuration, and we don't need to sample that quickly
static constexpr int ina219SampleTimeMillis = 69;

CTask networkTask{"Networking Task", 15, 3072, ina219SampleTimeMillis};
CTask sensingTask{"Sensing Task", 15, 2048, ina219SampleTimeMillis};
CTask dataLoggingTask{"Data Logging Task", 15, 2048, 0};
};



16 changes: 6 additions & 10 deletions app/backplane/power_module/src/c_power_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
#include <n_autocoder_types.h>

// F-Core Tenant
#include <f_core/os/n_rtos.h>
#include <f_core/messaging/c_msgq_message_port.h>
#include <f_core/messaging/c_latest_message_port.h>
#include <f_core/messaging/c_msgq_message_port.h>
#include <f_core/os/n_rtos.h>
#include <f_core/utils/n_time_utils.h>

static auto telemetryBroadcastMessagePort = CLatestMessagePort<NTypes::SensorData>();
Expand All @@ -14,10 +14,9 @@ static auto downlinkMessageMessagePort = CLatestMessagePort<NTypes::LoRaBroadcas
K_MSGQ_DEFINE(dataLogQueue, sizeof(NTypes::TimestampedSensorData), 512, 4);
static auto dataLogMsgQueue = CMsgqMessagePort<NTypes::TimestampedSensorData>(dataLogQueue);


CPowerModule::CPowerModule() : CProjectConfiguration(), sensorDataBroadcastMessagePort(telemetryBroadcastMessagePort),
sensorDataLogMessagePort(dataLogMsgQueue),
sensorDataDownlinkMessagePort(downlinkMessageMessagePort) {}
CPowerModule::CPowerModule()
: CProjectConfiguration(), sensorDataBroadcastMessagePort(telemetryBroadcastMessagePort),
sensorDataLogMessagePort(dataLogMsgQueue), sensorDataDownlinkMessagePort(downlinkMessageMessagePort) {}

void CPowerModule::AddTenantsToTasks() {
// Networking
Expand Down Expand Up @@ -52,7 +51,4 @@ void CPowerModule::SetupCallbacks() {
NTimeUtils::SntpSynchronize(rtc, sntpServerAddr, 5, K_MSEC(100));
}

void CPowerModule::Cleanup() {
dataLoggerTenant.Cleanup();
}

void CPowerModule::Cleanup() { dataLoggerTenant.Cleanup(); }
43 changes: 12 additions & 31 deletions app/backplane/power_module/src/c_sensing_tenant.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include "c_sensing_tenant.h"

#include "c_power_module.h"

#include <f_core/n_alerts.h>
#include <f_core/device/sensor/c_shunt.h>
#include <f_core/n_alerts.h>
#include <zephyr/logging/log.h>

LOG_MODULE_REGISTER(CSensingTenant);
Expand All @@ -17,26 +18,11 @@ void CSensingTenant::PostStartup() {}
void CSensingTenant::Run() {
NTypes::TimestampedSensorData timestampedData{
.timestamp = 0,
.data = {
.RailBattery = {
.Voltage = 0.0f,
.Current = 0.0f,
.Power = 0.0f
},
.Rail3v3 = {
.Voltage = 0.0f,
.Current = 0.0f,
.Power = 0.0f
},
.Rail5v0 = {
.Voltage = 0.0f,
.Current = 0.0f,
.Power = 0.0f
}
}
};
.data = {.RailBattery = {.Voltage = 0.0f, .Current = 0.0f, .Power = 0.0f},
.Rail3v3 = {.Voltage = 0.0f, .Current = 0.0f, .Power = 0.0f},
.Rail5v0 = {.Voltage = 0.0f, .Current = 0.0f, .Power = 0.0f}}};

NTypes::SensorData &data = timestampedData.data;
NTypes::SensorData& data = timestampedData.data;

#ifndef CONFIG_ARCH_POSIX
CShunt shuntBatt(*DEVICE_DT_GET(DT_ALIAS(shunt_batt)));
Expand Down Expand Up @@ -110,17 +96,12 @@ void CSensingTenant::Notify(void* ctx) {

void CSensingTenant::sendDownlinkData(const NTypes::SensorData& data) {
NTypes::LoRaBroadcastSensorData downlinkData{
.RailBattery = {
.Voltage = static_cast<int16_t>(data.RailBattery.Voltage),
.Current = static_cast<int16_t>(CSensorDevice::ToMilliUnits(data.RailBattery.Current)),
.Power = static_cast<int16_t>(CSensorDevice::ToMilliUnits(data.RailBattery.Power))
},
.Rail3v3 = {
.Voltage = static_cast<int16_t>(data.Rail3v3.Voltage),
.Current = static_cast<int16_t>(CSensorDevice::ToMilliUnits(data.Rail3v3.Current)),
.Power = static_cast<int16_t>(CSensorDevice::ToMilliUnits(data.Rail3v3.Power))
}
};
.RailBattery = {.Voltage = static_cast<int16_t>(data.RailBattery.Voltage),
.Current = static_cast<int16_t>(CSensorDevice::ToMilliUnits(data.RailBattery.Current)),
.Power = static_cast<int16_t>(CSensorDevice::ToMilliUnits(data.RailBattery.Power))},
.Rail3v3 = {.Voltage = static_cast<int16_t>(data.Rail3v3.Voltage),
.Current = static_cast<int16_t>(CSensorDevice::ToMilliUnits(data.Rail3v3.Current)),
.Power = static_cast<int16_t>(CSensorDevice::ToMilliUnits(data.Rail3v3.Power))}};

dataToDownlink.Send(downlinkData, K_MSEC(5));
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#pragma once

#include <f_core/radio/c_lora_frame_handler.h>
#include <f_core/os/c_runnable_tenant.h>
#include <f_core/radio/c_lora_frame_handler.h>
#include <f_core/state_machine/c_pad_flight_landing_state_machine.h>
#include <f_core/utils/c_hashmap.h>
#include <f_core/utils/c_soft_timer.h>

#include <memory>

class CDownlinkSchedulerTenant : public CRunnableTenant, public CPadFlightLandedStateMachine, public CLoraFrameHandler {
public:
public:
/**
* Constructor
* @param loraDownlinkMessagePort The message port to send downlink frames to
Expand All @@ -30,8 +29,7 @@ class CDownlinkSchedulerTenant : public CRunnableTenant, public CPadFlightLanded
*/
void Run() override;

protected:

protected:
/**
* See parent docs
*/
Expand All @@ -52,13 +50,10 @@ class CDownlinkSchedulerTenant : public CRunnableTenant, public CPadFlightLanded
*/
void GroundRun() override;

private:
private:
CMessagePort<LaunchLoraFrame>& loraDownlinkMessagePort;
CHashMap<uint16_t, CMessagePort<LaunchLoraFrame>*> telemetryMessagePortMap;
CHashMap<uint16_t, std::unique_ptr<CSoftTimer>> telemetryDownlinkTimers;

bool gnssDownlinkAvailable = false;
};



Loading
Loading