ELEC-C7222
Libraries for ELEC C7222 Course Work
Loading...
Searching...
No Matches
main_ble_att_server.cpp File Reference

BLE GATT server example with AttributeServer and SecurityManager. More...

#include <assert.h>
#include <cstdint>
#include <cstdio>
#include "advertisement_data.hpp"
#include "gap_event_handler.hpp"
#include "ble_onchip_temperature.hpp"
#include "ble.hpp"
#include "characteristic.hpp"
#include "freertos_task.hpp"
#include "freertos_timer.hpp"
#include "gap.hpp"
#include "onboard_led.hpp"
#include "onchip_temperature_sensor.hpp"
#include "pico/cyw43_arch.h"
#include "pico/stdlib.h"
#include "pico/time.h"
#include "platform.hpp"
#include "security_event_handler.hpp"
#include "security_manager.hpp"
#include "app_profile.h"
Include dependency graph for main_ble_att_server.cpp:

Functions

static void timer_callback ()
 Periodic timer callback to update temperature value.
 
static void on_turn_on ()
 Callback executed when the BLE stack is fully initialized.
 
void ble_app_task (void *params)
 FreeRTOS task that owns BLE initialization and GATT server setup.
 
int main ()
 Program entry point.
 

Variables

static c7222::OnBoardLEDonboard_led = nullptr
 On-board LED used as a heartbeat while advertising.
 
static c7222::OnChipTemperatureSensortemp_sensor = nullptr
 Temperature sensor wrapper used to read on-chip temperature.
 
static c7222::FreeRtosTimer app_timer
 Periodic timer used to update the temperature characteristic.
 
static c7222::Characteristictemperature_characteristic = nullptr
 Temperature characteristic handle resolved from the ATT database.
 
static c7222::Characteristicconfiguration_characteristic = nullptr
 Configuration characteristic handle resolved from the ATT database.
 
static c7222::Platformplatform = nullptr
 Platform abstraction (initializes CYW43/BTstack).
 
static c7222::SecurityManagersecurity_manager = nullptr
 SecurityManager instance for pairing/authorization.
 
static c7222::AttributeServeratt_server = nullptr
 AttributeServer instance providing GATT database access.
 
static BleOnchipTemperatureble_temperature_manager = nullptr
 Helper that binds characteristic event handlers for logging.
 
static SecurityEventHandler security_event_handler
 Security event handler (minimal example policy).
 
static GapEventHandler gap_event_handler
 GAP event handler (logging + restart advertising).
 

Detailed Description

BLE GATT server example with AttributeServer and SecurityManager.

Demonstrates how to:

  • Enable the AttributeServer with a GATT profile database.
  • Register GAP and Security Manager event handlers.
  • Locate services/characteristics and attach event handlers.
  • Periodically update a characteristic value (temperature) using a timer.

Dependencies:

Function Documentation

◆ ble_app_task()

void ble_app_task ( void *  params)

FreeRTOS task that owns BLE initialization and GATT server setup.

Initializes platform, security manager, attribute server, resolves characteristics, and starts advertising. A timer periodically updates the temperature characteristic when connected.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( void  )

Program entry point.

Here is the call graph for this function:

◆ on_turn_on()

static void on_turn_on ( )
static

Callback executed when the BLE stack is fully initialized.

Configures advertising data/parameters and starts advertising.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ timer_callback()

static void timer_callback ( )
static

Periodic timer callback to update temperature value.

Reads the temperature sensor and writes a fixed-point value (C * 100) into the temperature characteristic when a connection is active.

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ app_timer

c7222::FreeRtosTimer app_timer
static

Periodic timer used to update the temperature characteristic.

◆ att_server

c7222::AttributeServer* att_server = nullptr
static

AttributeServer instance providing GATT database access.

◆ ble_temperature_manager

BleOnchipTemperature* ble_temperature_manager = nullptr
static

Helper that binds characteristic event handlers for logging.

◆ configuration_characteristic

c7222::Characteristic* configuration_characteristic = nullptr
static

Configuration characteristic handle resolved from the ATT database.

◆ gap_event_handler

GapEventHandler gap_event_handler
static

GAP event handler (logging + restart advertising).

◆ onboard_led

c7222::OnBoardLED* onboard_led = nullptr
static

On-board LED used as a heartbeat while advertising.

◆ platform

c7222::Platform* platform = nullptr
static

Platform abstraction (initializes CYW43/BTstack).

◆ security_event_handler

SecurityEventHandler security_event_handler
static

Security event handler (minimal example policy).

◆ security_manager

c7222::SecurityManager* security_manager = nullptr
static

SecurityManager instance for pairing/authorization.

◆ temp_sensor

c7222::OnChipTemperatureSensor* temp_sensor = nullptr
static

Temperature sensor wrapper used to read on-chip temperature.

◆ temperature_characteristic

c7222::Characteristic* temperature_characteristic = nullptr
static

Temperature characteristic handle resolved from the ATT database.