Skip to content

User TX/RX callbacks #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions src/include/pico/lorawan.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ extern "C" {
#include "hardware/spi.h"

#include "LoRaMac.h"
#include "LmHandler.h"

struct lorawan_sx1276_settings {
struct {
Expand Down Expand Up @@ -62,6 +63,10 @@ int lorawan_process_timeout_ms(uint32_t timeout_ms);

int lorawan_send_unconfirmed(const void* data, uint8_t data_len, uint8_t app_port);

void lorawan_set_tx_callback(void (*callback)(LmHandlerTxParams_t* params));

void lorawan_set_rx_callback(void (*callback)(LmHandlerRxParams_t* params));

int lorawan_receive(void* data, uint8_t data_len, uint8_t* app_port);

void lorawan_debug(bool debug);
Expand Down
21 changes: 21 additions & 0 deletions src/lorawan.c
Original file line number Diff line number Diff line change
Expand Up @@ -586,11 +586,23 @@ static void OnJoinRequest( LmHandlerJoinParams_t* params )
}
}

void (*txCallback)(LmHandlerTxParams_t* params) = NULL;
void (*rxCallback)(LmHandlerRxParams_t* params) = NULL;

static void OnTxData( LmHandlerTxParams_t* params )
{
if (Debug) {
DisplayTxUpdate( params );
}

if (txCallback != NULL) {
txCallback( params );
}
}

void lorawan_set_tx_callback( void (*callback)(LmHandlerTxParams_t*) )
{
txCallback = callback;
}

static void OnRxData( LmHandlerAppData_t* appData, LmHandlerRxParams_t* params )
Expand All @@ -602,6 +614,15 @@ static void OnRxData( LmHandlerAppData_t* appData, LmHandlerRxParams_t* params )
memcpy(AppRxData.Buffer, appData->Buffer, appData->BufferSize);
AppRxData.BufferSize = appData->BufferSize;
AppRxData.Port = appData->Port;

if (rxCallback != NULL) {
rxCallback( params );
}
}

void lorawan_set_rx_callback( void (*callback)(LmHandlerRxParams_t*) )
{
rxCallback = callback;
}

static void OnClassChange( DeviceClass_t deviceClass )
Expand Down