Skip to content
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

Add callback for CPX app messages #1279

Merged
merged 3 commits into from
May 24, 2023
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
4 changes: 4 additions & 0 deletions src/modules/interface/cpx/cpx.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,12 @@ typedef struct {
uint8_t data[CPX_MAX_PAYLOAD_SIZE - CPX_ROUTING_PACKED_SIZE];
} CPXRoutablePacket_t;

typedef void (*cpxAppMessageHandlerCallback_t)(const CPXPacket_t* cpxRx);

void cpxInitRoute(const CPXTarget_t source, const CPXTarget_t destination, const CPXFunction_t function, CPXRouting_t* route);

void cpxInit();

void cpxRegisterAppMessageHandler(cpxAppMessageHandlerCallback_t callback);

bool cpxCheckVersion(uint8_t version);
11 changes: 11 additions & 0 deletions src/modules/src/cpx/cpx.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@

static CPXPacket_t cpxRx;

static volatile cpxAppMessageHandlerCallback_t appMessageHandlerCallback;

#define WIFI_SET_SSID_CMD 0x10
#define WIFI_SET_KEY_CMD 0x11

Expand Down Expand Up @@ -86,6 +88,10 @@ bool cpxCheckVersion(const uint8_t version) {
return isVersionOk;
}

void cpxRegisterAppMessageHandler(cpxAppMessageHandlerCallback_t callback) {
appMessageHandlerCallback = callback;
}

static void cpx(void* _param) {
systemWaitStart();
while (1) {
Expand Down Expand Up @@ -145,6 +151,11 @@ static void cpx(void* _param) {
}
}
break;
case CPX_F_APP:
if (appMessageHandlerCallback) {
appMessageHandlerCallback(&cpxRx);
}
break;
default:
DEBUG_PRINT("Not handling function [0x%02X] from [0x%02X]\n", cpxRx.route.function, cpxRx.route.source);
}
Expand Down
1 change: 1 addition & 0 deletions src/modules/src/cpx/cpx_internal_router.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ void cpxInternalRouterRouteIn(const CPXRoutablePacket_t* packet) {
case CPX_F_CONSOLE:
case CPX_F_WIFI_CTRL:
case CPX_F_BOOTLOADER:
case CPX_F_APP:
case CPX_F_TEST:
xQueueSend(mixedQueue, packet, portMAX_DELAY);
break;
Expand Down