From 2996447bedf696f53a5e196991e0d640d5934448 Mon Sep 17 00:00:00 2001 From: knmcguire Date: Fri, 11 Oct 2019 16:01:20 +0200 Subject: [PATCH] #484 radiolink setup function to send p2p broadcast packets to nrf --- src/hal/interface/radiolink.h | 16 ++++++++++++++++ src/hal/src/radiolink.c | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/hal/interface/radiolink.h b/src/hal/interface/radiolink.h index c59bcd37ec..d287597a55 100644 --- a/src/hal/interface/radiolink.h +++ b/src/hal/interface/radiolink.h @@ -31,6 +31,21 @@ #include #include "syslink.h" +#define P2P_MAX_DATA_SIZE 61 + +typedef struct _P2PPacket +{ + uint8_t size; //< Size of data + uint8_t rssi; //< Received Signal Strength Intensity + union { + struct { + uint8_t port; //< Header selecting channel and port + uint8_t data[P2P_MAX_DATA_SIZE]; //< Data + }; + uint8_t raw[P2P_MAX_DATA_SIZE+1]; //< The full packet "raw" + }; +} __attribute__((packed)) P2PPacket; + void radiolinkInit(void); bool radiolinkTest(void); void radiolinkSetChannel(uint8_t channel); @@ -39,6 +54,7 @@ void radiolinkSetAddress(uint64_t address); void radiolinkSetPowerDbm(int8_t powerDbm); void radiolinkSyslinkDispatch(SyslinkPacket *slp); struct crtpLinkOperations * radiolinkGetLink(); +bool radiolinkSendP2PPacketBroadcast(P2PPacket *p2pp); #endif //__RADIO_H__ diff --git a/src/hal/src/radiolink.c b/src/hal/src/radiolink.c index 4a97c8360f..b399066086 100644 --- a/src/hal/src/radiolink.c +++ b/src/hal/src/radiolink.c @@ -212,6 +212,22 @@ static int radiolinkSendCRTPPacket(CRTPPacket *p) return false; } +bool radiolinkSendP2PPacketBroadcast(P2PPacket *p) +{ + static SyslinkPacket slp; + + ASSERT(p->size <= CRTP_MAX_DATA_SIZE); + + slp.type = SYSLINK_RADIO_P2P_BROADCAST; + slp.length = p->size + 1; + memcpy(slp.data, p->raw, p->size + 1); + + syslinkSendPacket(&slp); + + return true; +} + + struct crtpLinkOperations * radiolinkGetLink() { return &radiolinkOp;