From 394c88ed408b6b2f2de7443d36351df9dfad865f Mon Sep 17 00:00:00 2001 From: mfxjx Date: Mon, 15 May 2023 13:08:45 +0800 Subject: [PATCH 1/3] fix --- src/modules/src/cpx/cpx.c | 14 ++++++++++++++ src/modules/src/cpx/cpx_internal_router.c | 1 + 2 files changed, 15 insertions(+) diff --git a/src/modules/src/cpx/cpx.c b/src/modules/src/cpx/cpx.c index 1c6bae9a2a..f6743f9350 100644 --- a/src/modules/src/cpx/cpx.c +++ b/src/modules/src/cpx/cpx.c @@ -86,6 +86,17 @@ bool cpxCheckVersion(const uint8_t version) { return isVersionOk; } +// Deepcopy from the received packet cpxRx to the provided packet +void cpxGetRxPacket(CPXPacket_t* packet) { + packet->route.destination=cpxRx.route.destination; + packet->route.source=cpxRx.route.source; + packet->route.lastPacket=cpxRx.route.lastPacket; + packet->route.function=cpxRx.route.function; + packet->route.version=cpxRx.route.version; + packet->dataLength=cpxRx.dataLength; + memcpy(packet->data, cpxRx.data, cpxRx.dataLength); +} + static void cpx(void* _param) { systemWaitStart(); while (1) { @@ -145,6 +156,9 @@ static void cpx(void* _param) { } } break; + case CPX_F_APP: + DEBUG_PRINT("CPX:Receive APP Message from [0x%02X]\n", cpxRx.route.source); + break; default: DEBUG_PRINT("Not handling function [0x%02X] from [0x%02X]\n", cpxRx.route.function, cpxRx.route.source); } diff --git a/src/modules/src/cpx/cpx_internal_router.c b/src/modules/src/cpx/cpx_internal_router.c index 8b878a0f6c..ba9d1c31f3 100644 --- a/src/modules/src/cpx/cpx_internal_router.c +++ b/src/modules/src/cpx/cpx_internal_router.c @@ -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; From 47e5679254023dae5b435bb699c5924b80f45c72 Mon Sep 17 00:00:00 2001 From: mfxjx Date: Mon, 15 May 2023 20:34:44 +0800 Subject: [PATCH 2/3] add function to process CPX_F_APP --- src/modules/interface/cpx/cpx.h | 4 ++++ src/modules/src/cpx/cpx.c | 10 +++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/modules/interface/cpx/cpx.h b/src/modules/interface/cpx/cpx.h index ab2c2f4bd2..d1828eb0de 100644 --- a/src/modules/interface/cpx/cpx.h +++ b/src/modules/interface/cpx/cpx.h @@ -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); \ No newline at end of file diff --git a/src/modules/src/cpx/cpx.c b/src/modules/src/cpx/cpx.c index f6743f9350..e57f6163bf 100644 --- a/src/modules/src/cpx/cpx.c +++ b/src/modules/src/cpx/cpx.c @@ -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 @@ -86,6 +88,10 @@ bool cpxCheckVersion(const uint8_t version) { return isVersionOk; } +void cpxRegisterAppMessageHandler(cpxAppMessageHandlerCallback_t callback) { + appMessageHandlerCallback = callback; +} + // Deepcopy from the received packet cpxRx to the provided packet void cpxGetRxPacket(CPXPacket_t* packet) { packet->route.destination=cpxRx.route.destination; @@ -157,7 +163,9 @@ static void cpx(void* _param) { } break; case CPX_F_APP: - DEBUG_PRINT("CPX:Receive APP Message from [0x%02X]\n", cpxRx.route.source); + if (appMessageHandlerCallback) { + appMessageHandlerCallback(&cpxRx); + } break; default: DEBUG_PRINT("Not handling function [0x%02X] from [0x%02X]\n", cpxRx.route.function, cpxRx.route.source); From de581f9f2aa3dd778d2cf2f627c0df9628e521be Mon Sep 17 00:00:00 2001 From: mfxjx Date: Mon, 15 May 2023 21:52:30 +0800 Subject: [PATCH 3/3] add callback function to process CPX_F_APP message --- src/modules/src/cpx/cpx.c | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/modules/src/cpx/cpx.c b/src/modules/src/cpx/cpx.c index e57f6163bf..291bb8a6ed 100644 --- a/src/modules/src/cpx/cpx.c +++ b/src/modules/src/cpx/cpx.c @@ -92,17 +92,6 @@ void cpxRegisterAppMessageHandler(cpxAppMessageHandlerCallback_t callback) { appMessageHandlerCallback = callback; } -// Deepcopy from the received packet cpxRx to the provided packet -void cpxGetRxPacket(CPXPacket_t* packet) { - packet->route.destination=cpxRx.route.destination; - packet->route.source=cpxRx.route.source; - packet->route.lastPacket=cpxRx.route.lastPacket; - packet->route.function=cpxRx.route.function; - packet->route.version=cpxRx.route.version; - packet->dataLength=cpxRx.dataLength; - memcpy(packet->data, cpxRx.data, cpxRx.dataLength); -} - static void cpx(void* _param) { systemWaitStart(); while (1) {