Browse Source

ble: Writing char and notifications are working

ble
Andreas Berthoud 4 years ago
parent
commit
b024b7f623
  1. 1
      nucleo-wb55-ble/Core/Inc/stm32wbxx_it.h
  2. 9
      nucleo-wb55-ble/Core/Src/app_entry.c
  3. 14
      nucleo-wb55-ble/Core/Src/stm32wbxx_it.c
  4. 2
      nucleo-wb55-ble/STM32_WPAN/App/p2p_server_app.c
  5. 50
      nucleo-wb55-ble/commands/GPCommand.cpp
  6. 47
      nucleo-wb55-ble/commands/GPCommand.hpp
  7. 4
      nucleo-wb55-ble/commands/dispatch.cpp
  8. 4
      nucleo-wb55-dongle-ble/STM32_WPAN/App/p2p_client_app.c

1
nucleo-wb55-ble/Core/Inc/stm32wbxx_it.h

@ -56,7 +56,6 @@ void SVC_Handler(void);
void DebugMon_Handler(void);
void PendSV_Handler(void);
void SysTick_Handler(void);
void EXTI4_IRQHandler(void);
void USB_LP_IRQHandler(void);
void HSEM_IRQHandler(void);
/* USER CODE BEGIN EFP */

9
nucleo-wb55-ble/Core/Src/app_entry.c

@ -96,15 +96,6 @@ void APPE_Init( void )
return;
}
/* USER CODE BEGIN FD */
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {
switch (GPIO_Pin) {
case SW1_Pin:
UTIL_SEQ_SetTask(1<<CFG_TASK_SW1_BUTTON_PUSHED_ID, CFG_SCH_PRIO_0);
break;
default:
break;
}
}
/* USER CODE END FD */

14
nucleo-wb55-ble/Core/Src/stm32wbxx_it.c

@ -200,20 +200,6 @@ void SysTick_Handler(void)
/* please refer to the startup file (startup_stm32wbxx.s). */
/******************************************************************************/
/**
* @brief This function handles EXTI line4 interrupt.
*/
void EXTI4_IRQHandler(void)
{
/* USER CODE BEGIN EXTI4_IRQn 0 */
/* USER CODE END EXTI4_IRQn 0 */
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_4);
/* USER CODE BEGIN EXTI4_IRQn 1 */
/* USER CODE END EXTI4_IRQn 1 */
}
/**
* @brief This function handles USB low priority interrupt, USB wake-up interrupt through EXTI line 28.
*/

2
nucleo-wb55-ble/STM32_WPAN/App/p2p_server_app.c

@ -139,7 +139,7 @@ void P2PS_APP_Notification(P2PS_APP_ConnHandle_Not_evt_t *pNotification)
void P2PS_APP_Init(void)
{
/* USER CODE BEGIN P2PS_APP_Init */
UTIL_SEQ_RegTask(CFG_TASK_SW1_BUTTON_PUSHED_ID, UTIL_SEQ_DEFAULT, P2PS_Send_Notification);
UTIL_SEQ_RegTask(1<< CFG_TASK_SW1_BUTTON_PUSHED_ID, UTIL_SEQ_DEFAULT, P2PS_Send_Notification);
/* USER CODE END P2PS_APP_Init */
return;
}

50
nucleo-wb55-ble/commands/GPCommand.cpp

@ -0,0 +1,50 @@
/*
* GPCommand.cpp
*
* Created on: Jul 18, 2021
* Author: Andreas Berthoud
*/
#include "GPCommand.hpp"
#include "app_conf.h"
#include "stm32_seq.h"
GPResponse::GPResponse(uint16_t response_identifier, bool was_successful)
: Response(response_identifier) {
(this->payload_ptr + this->get_payload_size())[0] = (uint8_t)was_successful;
this->add_to_payload_size(1);
}
GPRequest::GPRequest(uint8_t * payload_ptr, uint16_t size) : Request(payload_ptr, size) {
uint16_t expected_length = this->buffer_offset + 1;
if (expected_length != size) {
this->has_error = true;
return;
}
uint8_t * data_ptr = payload_ptr + this->buffer_offset;
this->command_id = data_ptr[0];
}
GPResponse * GPRequest::execute_request(uint16_t response_identifier) {
bool was_successful = true;
if (this->has_error) {
was_successful = false;
} else {
switch (this->command_id)
{
case 1:
UTIL_SEQ_SetTask(1<<CFG_TASK_SW1_BUTTON_PUSHED_ID, CFG_SCH_PRIO_0);
break;
default:
break;
}
}
return new GPResponse(response_identifier, was_successful);
}

47
nucleo-wb55-ble/commands/GPCommand.hpp

@ -0,0 +1,47 @@
/*
* GPCommand.hpp
*
* Created on: Jul 18, 2021
* Author: Andreas Berthoud
*/
#ifndef GPCOMMAND_HPP_
#define GPCOMMAND_HPP_
#include "Request.hpp"
#include "Response.hpp"
class GPResponse : public Response {
public:
GPResponse(uint16_t response_identifier, bool was_successful);
CommandId get_command_id() override { return COMMAND_GP_RESPONSE; }
private:
bool was_successful = false;
};
class GPRequest : public Request {
public:
/**
* @brief Construct a new general purpose request object
*
* @param payload_ptr
* HEADER | command_id |
* | 1 byte |
*
* @param size
*/
GPRequest(uint8_t * payload_ptr, uint16_t size);
GPResponse * execute_request(uint16_t response_identifier);
CommandId get_command_id() override { return COMMAND_GP_REQUEST; }
private:
bool has_error = false;
int command_id = 0;
};
#endif /* GPCOMMAND_HPP_ */

4
nucleo-wb55-ble/commands/dispatch.cpp

@ -9,6 +9,7 @@
#include "HeartbeatCommand.hpp"
#include "LedCommand.hpp"
#include "GPCommand.hpp"
void handle_received_command(uint8_t command_id, uint8_t * payload_ptr, uint16_t size) {
@ -20,6 +21,9 @@ void handle_received_command(uint8_t command_id, uint8_t * payload_ptr, uint16_t
case COMMAND_LED_REQUEST:
push_command(new LedRequest(payload_ptr, size));
break;
case COMMAND_GP_REQUEST:
push_command(new GPRequest(payload_ptr, size));
break;
default:
break;

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

@ -568,6 +568,8 @@ void Gatt_Notification(P2P_Client_App_Notification_evt_t *pNotification)
{
/* USER CODE BEGIN Gatt_Notification_1*/
log_debug("Gatt_Notification", "enter", 0);
log_debug("Gatt_Notification", "pNotification->P2P_Client_Evt_Opcode=0x%x", 1, pNotification->P2P_Client_Evt_Opcode);
/* USER CODE END Gatt_Notification_1 */
switch(pNotification->P2P_Client_Evt_Opcode)
@ -580,6 +582,8 @@ void Gatt_Notification(P2P_Client_App_Notification_evt_t *pNotification)
/* USER CODE BEGIN P2P_NOTIFICATION_INFO_RECEIVED_EVT */
{
P2P_Client_App_Context.LedControl.Device_Led_Selection=pNotification->DataTransfered.pPayload[0];
log_debug("Gatt_Notification", "DataTransfered.pPayload[0]=0x%x", 1, pNotification->DataTransfered.pPayload[0]);
log_debug("Gatt_Notification", "DataTransfered.pPayload[1]=0x%x", 1, pNotification->DataTransfered.pPayload[1]);
switch(P2P_Client_App_Context.LedControl.Device_Led_Selection) {
case 0x01 : {

Loading…
Cancel
Save