|
|
|
@ -19,9 +19,10 @@ |
|
|
|
|
|
|
|
|
|
|
|
/* Includes ------------------------------------------------------------------*/ |
|
|
|
#include <stdio.h> |
|
|
|
#include "common_blesvc.h" |
|
|
|
#include "commands.h" |
|
|
|
/* Private typedef -----------------------------------------------------------*/ |
|
|
|
#include "ble_cmd_mbx.h" |
|
|
|
typedef struct{ |
|
|
|
uint16_t PeerToPeerSvcHdle; /**< Service handle */ |
|
|
|
uint16_t P2PWriteClientToServerCharHdle; /**< Characteristic handle */ |
|
|
|
@ -44,7 +45,7 @@ typedef struct{ |
|
|
|
|
|
|
|
|
|
|
|
/* Private macros ------------------------------------------------------------*/ |
|
|
|
|
|
|
|
#define COMMAND_CHAR_LENGTH (247) |
|
|
|
/* Private variables ---------------------------------------------------------*/ |
|
|
|
/**
|
|
|
|
* Reboot Characteristic UUID |
|
|
|
@ -150,11 +151,35 @@ static SVCCTL_EvtAckStatus_t PeerToPeer_Event_Handler(void *Event) |
|
|
|
|
|
|
|
else if(attribute_modified->Attr_Handle == (aPeerToPeerContext.P2PWriteClientToServerCharHdle + 1)) |
|
|
|
{ |
|
|
|
BLE_DBG_P2P_STM_MSG("-- GATT : LED CONFIGURATION RECEIVED\n"); |
|
|
|
Notification.P2P_Evt_Opcode = P2PS_STM_WRITE_EVT; |
|
|
|
Notification.DataTransfered.Length=attribute_modified->Attr_Data_Length; |
|
|
|
Notification.DataTransfered.pPayload=attribute_modified->Attr_Data; |
|
|
|
P2PS_STM_App_Notification(&Notification); |
|
|
|
#ifdef DEBUG_COMMADS |
|
|
|
uint8_t buffer[512]; |
|
|
|
buffer[0] = (uint8_t)('0'); |
|
|
|
buffer[1] = (uint8_t)('x'); |
|
|
|
uint8_t i; |
|
|
|
for (i = 0; i<attribute_modified->Attr_Data_Length; i++) { |
|
|
|
snprintf((char*)(buffer + i + 2), 512-i-2, "%x", attribute_modified->Attr_Data[i]); |
|
|
|
} |
|
|
|
buffer[i + 3] = (uint8_t)('\0'); |
|
|
|
log_debug("PeerToPeer_Event_Handler", "Notification payload: %s", 1, buffer); |
|
|
|
#endif /* DEBUG_COMMADS */ |
|
|
|
|
|
|
|
if (attribute_modified->Attr_Data_Length >= 4) { |
|
|
|
uint8_t * buf = attribute_modified->Attr_Data; |
|
|
|
uint8_t command_id = buf[0]; |
|
|
|
uint16_t length = buf[1] << 8 | buf[2]; |
|
|
|
uint8_t * payload_ptr = buf + 4; |
|
|
|
#ifdef DEBUG_COMMADS |
|
|
|
log_debug("PeerToPeer_Event_Handler", "calling handle_received_ble_command()", 0); |
|
|
|
#endif /* DEBUG_COMMADS */ |
|
|
|
handle_received_ble_command(command_id, payload_ptr, length); |
|
|
|
|
|
|
|
} else { |
|
|
|
BLE_DBG_P2P_STM_MSG("-- GATT : LED CONFIGURATION RECEIVED\n"); |
|
|
|
Notification.P2P_Evt_Opcode = P2PS_STM_WRITE_EVT; |
|
|
|
Notification.DataTransfered.Length=attribute_modified->Attr_Data_Length; |
|
|
|
Notification.DataTransfered.pPayload=attribute_modified->Attr_Data; |
|
|
|
P2PS_STM_App_Notification(&Notification); |
|
|
|
} |
|
|
|
} |
|
|
|
#if(BLE_CFG_OTA_REBOOT_CHAR != 0) |
|
|
|
else if(attribute_modified->Attr_Handle == (aPeerToPeerContext.RebootReqCharHdle + 1)) |
|
|
|
@ -223,7 +248,7 @@ void P2PS_STM_Init(void) |
|
|
|
COPY_P2P_WRITE_CHAR_UUID(uuid16.Char_UUID_128); |
|
|
|
aci_gatt_add_char(aPeerToPeerContext.PeerToPeerSvcHdle, |
|
|
|
UUID_TYPE_128, &uuid16, |
|
|
|
2, |
|
|
|
COMMAND_CHAR_LENGTH, |
|
|
|
CHAR_PROP_WRITE_WITHOUT_RESP|CHAR_PROP_READ, |
|
|
|
ATTR_PERMISSION_NONE, |
|
|
|
GATT_NOTIFY_ATTRIBUTE_WRITE, /* gattEvtMask */ |
|
|
|
@ -237,7 +262,7 @@ void P2PS_STM_Init(void) |
|
|
|
COPY_P2P_NOTIFY_UUID(uuid16.Char_UUID_128); |
|
|
|
aci_gatt_add_char(aPeerToPeerContext.PeerToPeerSvcHdle, |
|
|
|
UUID_TYPE_128, &uuid16, |
|
|
|
2, |
|
|
|
COMMAND_CHAR_LENGTH, |
|
|
|
CHAR_PROP_NOTIFY, |
|
|
|
ATTR_PERMISSION_NONE, |
|
|
|
GATT_NOTIFY_ATTRIBUTE_WRITE, /* gattEvtMask */ |
|
|
|
@ -293,4 +318,32 @@ tBleStatus P2PS_STM_App_Update_Char(uint16_t UUID, uint8_t *pPayload) |
|
|
|
return result; |
|
|
|
}/* end P2PS_STM_Init() */ |
|
|
|
|
|
|
|
void Send_Command(void) |
|
|
|
{ |
|
|
|
#ifdef DEBUG_COMMADS |
|
|
|
log_debug("Send_Command", "SEND COMMAND TO CLIENT ", 0); |
|
|
|
#endif /* DEBUG_COMMADS */ |
|
|
|
|
|
|
|
if (!get_number_of_ble_commands_in_mailbox()) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
raw_command_t command = pop_ble_command(); |
|
|
|
|
|
|
|
tBleStatus ret = BLE_STATUS_INVALID_PARAMS; |
|
|
|
uint8_t index = 0; |
|
|
|
|
|
|
|
ret = aci_gatt_update_char_value( |
|
|
|
aPeerToPeerContext.PeerToPeerSvcHdle, |
|
|
|
aPeerToPeerContext.P2PNotifyServerToClientCharHdle, |
|
|
|
0, /* charValOffset */ |
|
|
|
command.size, /* charValueLen */ |
|
|
|
command.payload); |
|
|
|
|
|
|
|
if (ret) { |
|
|
|
log_error("Send_Command", "aci_gatt_update_char_value() returned %d", 1, ret); |
|
|
|
} |
|
|
|
|
|
|
|
return; |
|
|
|
} |
|
|
|
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
|
|
|
|