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
7 changes: 7 additions & 0 deletions app/backplane/radio_module/include/c_radio_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <f_core/radio/frame_handlers/c_frequency_change_handler.h>
#include <f_core/radio/frame_handlers/c_lora_frame_to_udp_handler.h>
#include <f_core/radio/application/c_lora_tenant.h>
#include <f_core/radio/application/c_callsign_broadcast_tenant.h>
#include <f_core/device/c_rtc.h>

// Autocoder Includes
Expand Down Expand Up @@ -86,6 +87,12 @@ class CRadioModule : public CProjectConfiguration {

// Tenants
CGnssTenant gnssTenant{"GNSS Tenant", &gnssTelemetryMessagePort, &gnssDataLogMessagePort};
CCallsignBroadcastTenant callsignBroadcastTenant{
"KD2YIE", // TODO: Settings
K_SECONDS(300), // Every 5 minutes to be safe
loraDownlinkMessagePort,
0
};

CUdpListenerTenant sensorModuleListenerTenant{
"Sensor Module Listener Tenant",
Expand Down
2 changes: 2 additions & 0 deletions app/backplane/radio_module/src/c_radio_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,6 @@ void CRadioModule::SetupCallbacks() {
alertTenant.Subscribe(&stateMachineUpdater);
sntpServerTenant.Register();
alertTenant.Register();

callsignBroadcastTenant.Register();
}
37 changes: 37 additions & 0 deletions include/f_core/radio/application/c_callsign_broadcast_tenant.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once

#include <string>

#include "f_core/os/c_callback_tenant.h"
#include "f_core/radio/c_lora_link.h"
#include "f_core/utils/c_soft_timer.h"

class CCallsignBroadcastTenant : public CCallbackTenant {
public:
/**
Comment thread
AarC10 marked this conversation as resolved.
*
* @param callsign Callsign to broadcast
* @param transmitFrequency How often to broadcast the callsign
* @param txPort Message port to send the callsign frame to for transmission over LoRa
* @param loraBroadcastPort LoRa port to broadcast the callsign on
*/
CCallsignBroadcastTenant(const char* callsign, k_timeout_t transmitFrequency, CMessagePort<LaunchLoraFrame>& txPort, const uint8_t loraBroadcastPort);

/**
* See parent docs
*/
Comment thread
AarC10 marked this conversation as resolved.
void Register() override;


/**
* See parent docs
*/
void Callback() override;

private:
CMessagePort<LaunchLoraFrame>& txPort;
CSoftTimer broadcastTimer;
const k_timeout_t transmitFrequency;
const std::string callsign;
const uint8_t loraBroadcastPort;
};
8 changes: 8 additions & 0 deletions include/f_core/radio/c_lora.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ class CLora {
*/
int SetConfiguration(const lora_modem_config& newConfig);

/**
* Check if the current frequency is within the licensed frequency range (410-450 MHz)
* @return True if the current frequency is within the licensed frequency range (410-450 MHz), false otherwise
*/
bool IsLicensedFrequency() const {
return (config.frequency >= 410'000'000u && config.frequency <= 450'000'000u);
}

private:
const device* lora_dev;
lora_modem_config config = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ class CLoraFreqRequestTenant : public CRunnableTenant, public CLoraFrameHandler

void revertFrequency();



CLora& lora;
CUdpSocket udp;
CMessagePort<LaunchLoraFrame>& downlinkMessagePort;
Expand Down
35 changes: 35 additions & 0 deletions lib/f_core/radio/application/c_callsign_broadcast_tenant.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "f_core/radio/application/c_callsign_broadcast_tenant.h"

#include <zephyr/logging/log.h>

LOG_MODULE_REGISTER(CCallsignBroadcastTenant);

static void broadcastTimerCallbackFunction(k_timer *timer) {
auto *tenant = static_cast<CCallsignBroadcastTenant*>(k_timer_user_data_get(timer));
if (tenant) {
tenant->Callback();
}
}

CCallsignBroadcastTenant::CCallsignBroadcastTenant(const char* callsign, k_timeout_t transmitFrequency, CMessagePort<LaunchLoraFrame>& txPort, const uint8_t loraBroadcastPort)
: CCallbackTenant("CCallsignBroadcastTenant"), txPort(txPort),
broadcastTimer(broadcastTimerCallbackFunction), transmitFrequency(transmitFrequency), callsign(callsign), loraBroadcastPort(loraBroadcastPort) {
}

void CCallsignBroadcastTenant::Register() {
broadcastTimer.SetUserData(this);
broadcastTimer.StartTimer(transmitFrequency);
}

void CCallsignBroadcastTenant::Callback() {
LaunchLoraFrame frame = {};
frame.Port = loraBroadcastPort;
frame.Size = static_cast<uint8_t>(callsign.size());
if (frame.Size > sizeof(frame.Payload)) {
LOG_ERR("Callsign size %zu exceeds maximum payload size %zu", callsign.size(), sizeof(frame.Payload));
return;
}

memcpy(frame.Payload, callsign.data(), frame.Size);
txPort.Send(frame, K_NO_WAIT);
};
Loading