Browse Source

ble-dongle: Get toggle of blue LED over BLE running

ble
Andreas Berthoud 4 years ago
parent
commit
871865d2d9
  1. 17
      backend/monsun_backend/command_execution.py
  2. 4
      nucleo-wb55-dongle-ble/STM32_WPAN/App/app_ble.c
  3. 15
      nucleo-wb55-dongle-ble/STM32_WPAN/App/p2p_client_app.c

17
backend/monsun_backend/command_execution.py

@ -211,9 +211,20 @@ def receive(
while bytes_read:
logger.debug(f"bytes: {bytes_read.hex()}")
command_id_int, data_length, _ = unpack(">BHB", bytes_read[:header_size])
payload = bytes(bytes_read[header_size : header_size + data_length])
stop_byte = bytes_read[header_size + data_length]
try:
command_id_int, data_length, _ = unpack(">BHB", bytes_read[:header_size])
payload = bytes(bytes_read[header_size : header_size + data_length])
stop_byte = bytes_read[header_size + data_length]
except IndexError:
# okay, something went wrong.
logger.error(
"There are less bytes than expected: "
f"Expected={header_size + data_length -1}, "
f"received={len(bytes_read)}",
)
logger.debug(f"bytes: {bytes_read.hex()}")
bytes_read = None
continue
try:
command_id = CommandId(command_id_int)

4
nucleo-wb55-dongle-ble/STM32_WPAN/App/app_ble.c

@ -360,7 +360,7 @@ SVCCTL_UserEvtFlowStatus_t SVCCTL_App_Notification( void *pckt )
int k = 0;
uint8_t adtype, adlength;
log_debug("SVCCTL_App_Notification", "enter, event=%d", 1, event_pckt->evt);
// log_debug("SVCCTL_App_Notification", "enter, event=%d", 1, event_pckt->evt);
switch (event_pckt->evt)
{
/* USER CODE BEGIN evt */
@ -440,7 +440,7 @@ SVCCTL_UserEvtFlowStatus_t SVCCTL_App_Notification( void *pckt )
case 0x0004:
{
/* USER CODE BEGIN RADIO_ACTIVITY_EVENT */
log_debug("SVCCTL_App_Notification", "RADIO_ACTIVITY_EVENT", 0);
// log_debug("SVCCTL_App_Notification", "RADIO_ACTIVITY_EVENT", 0);
HAL_GPIO_WritePin(LED_GREEN_GPIO_Port, LED_GREEN_Pin, GPIO_PIN_SET);
HAL_Delay(5);
HAL_GPIO_WritePin(LED_GREEN_GPIO_Port, LED_GREEN_Pin, GPIO_PIN_RESET);

15
nucleo-wb55-dongle-ble/STM32_WPAN/App/p2p_client_app.c

@ -626,7 +626,7 @@ uint8_t P2P_Client_APP_Get_State( void ) {
*/
tBleStatus Write_Char(uint16_t UUID, uint8_t Service_Instance, uint8_t *pPayload)
{
log_debug("Write_Char", "enter", 0);
tBleStatus ret = BLE_STATUS_INVALID_PARAMS;
uint8_t index;
@ -638,6 +638,7 @@ tBleStatus Write_Char(uint16_t UUID, uint8_t Service_Instance, uint8_t *pPayload
switch(UUID)
{
case P2P_WRITE_CHAR_UUID: /* SERVER RX -- so CLIENT TX */
log_debug("Write_Char", "payload 0x%x%x", 2, pPayload[0], pPayload[1]);
ret =aci_gatt_write_without_resp(aP2PClientContext[index].connHandle,
aP2PClientContext[index].P2PWriteToServerCharHdle,
2, /* charValueLen */
@ -686,37 +687,38 @@ void Update_Service()
{
case APP_BLE_DISCOVER_SERVICES:
log_debug("Update_Service", "P2P_DISCOVER_SERVICES", 0);
log_info("Update_Service", "P2P_DISCOVER_SERVICES", 0);
break;
case APP_BLE_DISCOVER_CHARACS:
log_debug("Update_Service", "* GATT : Discover P2P Characteristics", 0);
log_info("Update_Service", "* GATT : Discover P2P Characteristics", 0);
aci_gatt_disc_all_char_of_service(aP2PClientContext[index].connHandle,
aP2PClientContext[index].P2PServiceHandle,
aP2PClientContext[index].P2PServiceEndHandle);
break;
case APP_BLE_DISCOVER_WRITE_DESC: /* Not Used - No decriptor */
log_debug("Update_Service", "* GATT : Discover Descriptor of TX - Write Characteritic", 0);
log_info("Update_Service", "* GATT : Discover Descriptor of TX - Write Characteritic", 0);
aci_gatt_disc_all_char_desc(aP2PClientContext[index].connHandle,
aP2PClientContext[index].P2PWriteToServerCharHdle,
aP2PClientContext[index].P2PWriteToServerCharHdle+2);
break;
case APP_BLE_DISCOVER_NOTIFICATION_CHAR_DESC:
log_debug("Update_Service", "* GATT : Discover Descriptor of Rx - Notification Characteritic", 0);
log_info("Update_Service", "* GATT : Discover Descriptor of Rx - Notification Characteritic", 0);
aci_gatt_disc_all_char_desc(aP2PClientContext[index].connHandle,
aP2PClientContext[index].P2PNotificationCharHdle,
aP2PClientContext[index].P2PNotificationCharHdle+2);
break;
case APP_BLE_ENABLE_NOTIFICATION_DESC:
log_debug("Update_Service", "* GATT : Enable Server Notification", 0);
log_info("Update_Service", "* GATT : Enable Server Notification", 0);
aci_gatt_write_char_desc(aP2PClientContext[index].connHandle,
aP2PClientContext[index].P2PNotificationDescHandle,
2,
(uint8_t *)&enable);
aP2PClientContext[index].state = APP_BLE_CONNECTED_CLIENT;
log_info("Update_Service", "state: APP_BLE_CONNECTED_CLIENT", 0);
// BSP_LED_Off(LED_RED);
break;
@ -728,6 +730,7 @@ void Update_Service()
(uint8_t *)&disable);
aP2PClientContext[index].state = APP_BLE_CONNECTED_CLIENT;
log_info("Update_Service", "state: APP_BLE_CONNECTED_CLIENT", 0);
break;
default:

Loading…
Cancel
Save