Skip to content

Commit efade62

Browse files
author
Thomas Kopriva
committed
Merge pull request #45 in SA/ble_examples from feature/spp_ble_fixes to ble_examples-2.2-develop
Squashed commit of the following: commit b228a7454d5be82bd26c0f8c24b052c825b0e2cc Author: Haq <[email protected]> Date: Fri May 19 12:42:06 2017 -0700 updated with some enhancements
1 parent 7f63c8e commit efade62

File tree

9 files changed

+96
-52
lines changed

9 files changed

+96
-52
lines changed

docs/spp_ble.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Running the demo is as simple and compiling and loading the code, then hooking u
5151
- You can use the terminal to send data from your PC to the LaunchPad, and also display the info sent from one device to another.
5252
- You will need to open two instances of the terminal program to, one to communicate with each board.
5353
- Follow the steps from our [FAQ](faq.md) to connect to the LaunchPad boards
54-
- **Please note that the SPP project uses a baud rate of 921600 not 115200**
54+
- **Please note that the SPP project uses the default baud rate of 115200**
5555

5656
2. Power the boards inividually and verify they are initialized
5757
- The client will blink the green LED twice at initialzation. It will also display `Auto connecting...` on the terminal
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/*
2-
** Stack Frontier Generator 1.1.0 (2016-11-02 11:47:45.467000)
2+
** Stack Frontier Generator 1.1.0 (2017-05-19 12:28:56.481000)
33
**
44
** WARNING - Auto-generated file. Modifications could be lost!
55
*/
66

7-
-D ICALL_STACK0_ADDR=0x0000e2f5
8-
-D ICALL_STACK0_START=0x0000e2f4
7+
-D ICALL_STACK0_ADDR=0x0000e2f9
8+
-D ICALL_STACK0_START=0x0000e2f8
99
-D ICALL_RAM0_START=0x20004320
1010

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/*
2-
** Stack Frontier Generator 1.1.0 (2016-11-02 11:47:45.467000)
2+
** Stack Frontier Generator 1.1.0 (2017-05-19 12:28:56.481000)
33
**
44
** WARNING - Auto-generated file. Modifications could be lost!
55
*/
66

77
--config_def ICALL_RAM0_START=0x20004320
8-
--config_def ICALL_STACK0_START=0x0000e2f4
9-
--config_def ICALL_STACK0_ADDR=0x0000e2f5
8+
--config_def ICALL_STACK0_START=0x0000e2f8
9+
--config_def ICALL_STACK0_ADDR=0x0000e2f9
1010

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/*
2-
** Stack Frontier Generator 1.1.0 (2016-11-02 14:24:42.407000)
2+
** Stack Frontier Generator 1.1.0 (2017-05-19 12:13:41.482000)
33
**
44
** WARNING - Auto-generated file. Modifications could be lost!
55
*/
66

7-
-D ICALL_STACK0_ADDR=0x0000f811
8-
-D ICALL_STACK0_START=0x0000f810
7+
-D ICALL_STACK0_ADDR=0x0000f815
8+
-D ICALL_STACK0_START=0x0000f814
99
-D ICALL_RAM0_START=0x20004320
1010

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/*
2-
** Stack Frontier Generator 1.1.0 (2016-11-02 14:24:42.407000)
2+
** Stack Frontier Generator 1.1.0 (2017-05-19 12:13:41.482000)
33
**
44
** WARNING - Auto-generated file. Modifications could be lost!
55
*/
66

77
--config_def ICALL_RAM0_START=0x20004320
8-
--config_def ICALL_STACK0_START=0x0000f810
9-
--config_def ICALL_STACK0_ADDR=0x0000f811
8+
--config_def ICALL_STACK0_START=0x0000f814
9+
--config_def ICALL_STACK0_ADDR=0x0000f815
1010

src/components/sdi/inc/sdi_task.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,15 @@ extern void SDITask_registerIncomingRXEventAppCB(sdiIncomingEventCBack_t appRxCB
115115
// -----------------------------------------------------------------------------
116116
extern void SDITask_sendToUART(uint8_t *pMsg, uint16_t length);
117117

118+
// -----------------------------------------------------------------------------
119+
//! \brief API for application task to set packet data size to send over the air.
120+
//!
121+
//! \param[in] mtuSize GATT MTU size.
122+
//!
123+
//! \return void
124+
// -----------------------------------------------------------------------------
125+
extern void SDITask_setAppDataSize(uint16_t mtuSize);
126+
118127
#ifdef __cplusplus
119128
{
120129
#endif // extern "C"

src/components/sdi/sdi_task.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
#define SDITASK_PRIORITY 2
8888

8989
//! \brief Max bytes received from UART send to App
90-
#define MAX_UART_LENGTH 128
90+
#define DEFAULT_APP_DATA_LENGTH 20
9191

9292
// ****************************************************************************
9393
// typedefs
@@ -144,6 +144,7 @@ ICall_EntityID sdiAppEntityID = 0;
144144
//! rerouting of messages to application.
145145
//!
146146
static sdiIncomingEventCBack_t incomingRXEventAppCBFunc = NULL;
147+
static uint16 maxAppDataSize = DEFAULT_APP_DATA_LENGTH;
147148

148149
//*****************************************************************************
149150
// function prototypes
@@ -169,6 +170,15 @@ static void SDITask_MRDYEventCB(int size);
169170
//!
170171
static void SDITask_ProcessTXQ(void);
171172

173+
// -----------------------------------------------------------------------------
174+
//! \brief Initialization for the SDI Thread
175+
//!
176+
//! \return void
177+
// -----------------------------------------------------------------------------
178+
void SDITask_setAppDataSize(uint16 mtuSize)
179+
{
180+
maxAppDataSize = mtuSize - 3; //subtract GATT Notification overhead: 1 byte opcode, 2 bytes conn. handle
181+
}
172182

173183
// -----------------------------------------------------------------------------
174184
//! \brief Initialization for the SDI Thread
@@ -249,9 +259,9 @@ static void SDITask_process(void)
249259
{
250260
length = SDIRxBuf_GetRxBufLen();
251261

252-
if(length > MAX_UART_LENGTH)
262+
if(length > maxAppDataSize)
253263
{
254-
lengthRead = MAX_UART_LENGTH;
264+
lengthRead = (maxAppDataSize & 0xFF);
255265
}else
256266
{
257267
lengthRead = (length & 0xFF);
@@ -269,8 +279,8 @@ static void SDITask_process(void)
269279
{
270280
incomingRXEventAppCBFunc( UART_DATA_EVT , buf, lengthRead);
271281
}
272-
273-
if(length > MAX_UART_LENGTH)
282+
283+
if(length > maxAppDataSize)
274284
{
275285
// Additional bytes to collect, preserve the flag and repost
276286
// to the semaphore

src/examples/spp_ble_client/cc26xx/app/spp_ble_client.c

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ typedef struct
219219
// App event passed from profiles.
220220
typedef struct
221221
{
222-
uint8_t data[SERIALPORTSERVICE_DATA_LEN]; // New data
222+
uint8_t *pData; // New data
223223
uint8_t length; // New status
224224
} sbcUARTEvt_t;
225225

@@ -323,6 +323,9 @@ static bool procedureInProgress = FALSE;
323323
// Maximum PDU size (default = 27 octets)
324324
static uint16 maxPduSize;
325325

326+
// Maximum MTU size (default = 23 octets)
327+
static uint16 currentMTUSize;
328+
326329
// Pins that are actively used by the application
327330
static PIN_Config SPPBLEAppPinTable[] =
328331
{
@@ -644,26 +647,26 @@ static void SPPBLEClient_taskFxn(UArg a0, UArg a1)
644647
// Process message.
645648
bStatus_t retVal = FAILURE;
646649

647-
// Do a write
648-
attWriteReq_t req;
649-
650-
//Allocate data bytes to send over the air
651-
req.pValue = GATT_bm_alloc(connHandle, ATT_WRITE_REQ, pMsg->length, NULL);
652-
653-
if ( (req.pValue != NULL) && charDataHdl)
654-
{
655-
req.handle = charDataHdl; //handle for Value of Data characteristic found during service discovery
656-
req.len = pMsg->length;
657-
memcpy(req.pValue, pMsg->data, pMsg->length);
658-
req.sig = FALSE;
659-
req.cmd = TRUE;
650+
// Do a write
651+
attWriteReq_t req;
652+
653+
//Allocate data bytes to send over the air
654+
req.pValue = GATT_bm_alloc(connHandle, ATT_WRITE_REQ, pMsg->length, NULL);
655+
656+
if ( (req.pValue != NULL) && charDataHdl)
657+
{
658+
req.handle = charDataHdl; //handle for Value of Data characteristic found during service discovery
659+
req.len = pMsg->length;
660+
memcpy(req.pValue, pMsg->pData, pMsg->length);
661+
req.sig = FALSE;
662+
req.cmd = TRUE;
660663

661664
retVal = GATT_WriteNoRsp(connHandle, &req);
662665

663666
if ( retVal != SUCCESS )
664667
{
665668
GATT_bm_free((gattMsg_t *)&req, ATT_WRITE_REQ);
666-
DEBUG("FAIL FROM CLIENT");
669+
DEBUG("FAIL FROM CLIENT: "); DEBUG((uint8_t*)convInt32ToText((int)retVal)); DEBUG_NEWLINE();
667670
}else
668671
{
669672
//Remove from the queue
@@ -672,6 +675,7 @@ static void SPPBLEClient_taskFxn(UArg a0, UArg a1)
672675
//Toggle LED to indicate data received from UART terminal and sent over the air
673676
//SPPBLEClient_toggleLed(Board_GLED, Board_LED_TOGGLE);
674677

678+
ICall_freeMsg(pMsg->pData);
675679
// Free the space from the message.
676680
ICall_free(pMsg);
677681

@@ -1203,6 +1207,11 @@ static void SPPBLEClient_processGATTMsg(gattMsgEvent_t *pMsg)
12031207
}
12041208
else if (pMsg->method == ATT_MTU_UPDATED_EVENT)
12051209
{
1210+
currentMTUSize = pMsg->msg.mtuEvt.MTU;
1211+
SDITask_setAppDataSize(currentMTUSize);
1212+
1213+
DEBUG("MTU Size: "); DEBUG((uint8_t*)convInt32ToText((int)currentMTUSize)); DEBUG_NEWLINE();
1214+
12061215
// MTU size updated
12071216
Display_print1(dispHandle, 4, 0, "MTU Size: %d", pMsg->msg.mtuEvt.MTU);
12081217
}
@@ -1538,14 +1547,11 @@ static void SPPBLEClient_processGATTDiscEvent(gattMsgEvent_t *pMsg)
15381547
if (pMsg->method == ATT_EXCHANGE_MTU_RSP)
15391548
{
15401549
uint8_t uuid[ATT_UUID_SIZE] = { TI_BASE_UUID_128(SERIALPORTSERVICE_SERV_UUID) };
1541-
1542-
DEBUG("Server receive MTU: ");
1543-
DEBUG((uint8_t*)convInt32ToText((int)pMsg->msg.exchangeMTURsp.serverRxMTU)); DEBUG_NEWLINE();
1544-
1550+
15451551
discState = BLE_DISC_STATE_SVC;
1546-
1547-
DEBUG("Discovering services...");
1548-
1552+
1553+
DEBUG("Discovering services..."); DEBUG_NEWLINE();
1554+
15491555
// Discovery simple BLE service
15501556
VOID GATT_DiscPrimaryServiceByUUID(connHandle, uuid, ATT_UUID_SIZE,
15511557
selfEntity);
@@ -1900,7 +1906,13 @@ void SPPBLEClient_enqueueUARTMsg(uint8_t event, uint8_t *data, uint8_t len)
19001906
// Create dynamic pointer to message.
19011907
if (pMsg = ICall_malloc(sizeof(sbcUARTEvt_t)))
19021908
{
1903-
memcpy(pMsg->data , data, len);
1909+
1910+
pMsg->pData = (uint8 *)ICall_allocMsg(len);
1911+
if(pMsg->pData)
1912+
{
1913+
//payload
1914+
memcpy(pMsg->pData , data, len);
1915+
}
19041916
pMsg->length = len;
19051917

19061918
// Enqueue the message.

src/examples/spp_ble_server/cc26xx/app/spp_ble_server.c

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,9 @@ typedef struct
173173
typedef struct
174174
{
175175
uint8_t event; // Type of event
176-
uint8_t data[SERIALPORTSERVICE_DATA_LEN]; // New data
176+
uint8_t *pData; // New data
177177
uint8_t length; // New status
178-
} sbpUARTEvt_t; //size = 22 bytes
178+
} sbpUARTEvt_t;
179179
/*********************************************************************
180180
* GLOBAL VARIABLES
181181
*/
@@ -186,6 +186,9 @@ typedef struct
186186
// Global pin resources
187187
PIN_State pinGpioState;
188188
PIN_Handle hGpioPin;
189+
190+
uint16 currentMTUSize;
191+
189192
/*********************************************************************
190193
* LOCAL VARIABLES
191194
*/
@@ -304,7 +307,7 @@ static uint8_t rspTxRetry = 0;
304307
static PIN_Config SPPBLEAppPinTable[] =
305308
{
306309
Board_RLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */
307-
Board_LED2 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */
310+
Board_GLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */
308311

309312
PIN_TERMINATE
310313
};
@@ -708,7 +711,7 @@ static void SPPBLEServer_taskFxn(UArg a0, UArg a1)
708711
case SBP_UART_DATA_EVT:
709712
{
710713
//Send the notification
711-
retVal = SerialPortService_SetParameter(SERIALPORTSERVICE_CHAR_DATA, pMsg->length, pMsg->data);
714+
retVal = SerialPortService_SetParameter(SERIALPORTSERVICE_CHAR_DATA, pMsg->length, pMsg->pData);
712715

713716
if(retVal != SUCCESS)
714717
{
@@ -724,8 +727,10 @@ static void SPPBLEServer_taskFxn(UArg a0, UArg a1)
724727
Util_dequeueMsg(appUARTMsgQueue);
725728

726729
//Toggle LED to indicate data received from UART terminal and sent over the air
727-
//SPPBLEServer_toggleLed(Board_LED2, Board_LED_TOGGLE);
728-
730+
//SPPBLEServer_toggleLed(Board_GLED, Board_LED_TOGGLE);
731+
732+
//Deallocate data payload being transmitted.
733+
ICall_freeMsg(pMsg->pData);
729734
// Free the space from the message.
730735
ICall_free(pMsg);
731736
}
@@ -875,9 +880,10 @@ static uint8_t SPPBLEServer_processGATTMsg(gattMsgEvent_t *pMsg)
875880
else if (pMsg->method == ATT_MTU_UPDATED_EVENT)
876881
{
877882
// MTU size updated
878-
Display_print1(dispHandle, 5, 0, "MTU Size: $d", pMsg->msg.mtuEvt.MTU);
879-
DEBUG("MTU Updated: ");
880-
DEBUG((uint8_t*)convInt32ToText((int)pMsg->msg.mtuEvt.MTU)); DEBUG_NEWLINE();
883+
currentMTUSize = pMsg->msg.mtuEvt.MTU;
884+
SDITask_setAppDataSize(currentMTUSize);
885+
Display_print1(dispHandle, 5, 0, "MTU Size: %d", currentMTUSize);
886+
DEBUG("MTU Size: "); DEBUG((uint8_t*)convInt32ToText((int)currentMTUSize)); DEBUG_NEWLINE();
881887
}
882888

883889
// Free message payload. Needed only for ATT Protocol messages
@@ -1103,6 +1109,7 @@ static void SPPBLEServer_processStateChangeEvt(gaprole_States_t newState)
11031109
{
11041110
Display_print1(dispHandle, 2, 0, "Num Conns: %d", (uint16_t)numActive);
11051111
Display_print0(dispHandle, 3, 0, Util_convertBdAddr2Str(linkInfo.addr));
1112+
DEBUG("CONNECTED..."); DEBUG_NEWLINE();
11061113
}
11071114
else
11081115
{
@@ -1151,6 +1158,7 @@ static void SPPBLEServer_processStateChangeEvt(gaprole_States_t newState)
11511158

11521159
Display_print0(dispHandle, 2, 0, "Disconnected");
11531160

1161+
DEBUG("DISCONNECTED..."); DEBUG_NEWLINE();
11541162
// Clear remaining lines
11551163
//Display_clearLines(dispHandle, 3, 5);
11561164
break;
@@ -1159,7 +1167,7 @@ static void SPPBLEServer_processStateChangeEvt(gaprole_States_t newState)
11591167
SPPBLEServer_freeAttRsp(bleNotConnected);
11601168

11611169
Display_print0(dispHandle, 2, 0, "Timed Out");
1162-
1170+
DEBUG("DISCONNECTED AFTER TIMEOUT..."); DEBUG_NEWLINE();
11631171
// Clear remaining lines
11641172
//Display_clearLines(dispHandle, 3, 5);
11651173

@@ -1314,7 +1322,12 @@ void SPPBLEServer_enqueueUARTMsg(uint8_t event, uint8_t *data, uint8_t len)
13141322
{
13151323

13161324
pMsg->event = event;
1317-
memcpy(pMsg->data , data, len);
1325+
pMsg->pData = (uint8 *)ICall_allocMsg(len);
1326+
if(pMsg->pData)
1327+
{
1328+
//payload
1329+
memcpy(pMsg->pData , data, len);
1330+
}
13181331
pMsg->length = len;
13191332

13201333
// Enqueue the message.

0 commit comments

Comments
 (0)