nRF51 SDK
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages

Alert Notification Client Sample Application main file. More...

Macros

#define WAKEUP_BUTTON_PIN   NRF6310_BUTTON_0
 
#define BONDMNGR_DELETE_BUTTON_PIN_NO   NRF6310_BUTTON_1
 
#define CLEAR_NEW_ALERT_BUTTON_PIN   NRF6310_BUTTON_2
 
#define CLEAR_UNREAD_ALERT_BUTTON_PIN   NRF6310_BUTTON_3
 
#define NOTIFY_ALL_ALERTS_BUTTON_PIN   NRF6310_BUTTON_4
 
#define NEW_ALERT_NOTIF_LED_PIN_NO   NRF6310_LED_2
 
#define UNREAD_ALERT_NOTIF_LED_PIN_NO   NRF6310_LED_3
 
#define DEVICE_NAME   "Nordic_Alert_Notif."
 
#define MANUFACTURER_NAME   "NordicSemiconductor"
 
#define APP_ADV_INTERVAL   40
 
#define APP_ADV_INTERVAL_SLOW   3200
 
#define APP_ADV_TIMEOUT_IN_SECONDS   180
 
#define ADV_INTERVAL_FAST_PERIOD   30
 
#define APP_TIMER_PRESCALER   0
 
#define APP_TIMER_MAX_TIMERS   2
 
#define APP_TIMER_OP_QUEUE_SIZE   4
 
#define MIN_CONN_INTERVAL   MSEC_TO_UNITS(500, UNIT_1_25_MS)
 
#define MAX_CONN_INTERVAL   MSEC_TO_UNITS(1000, UNIT_1_25_MS)
 
#define SLAVE_LATENCY   0
 
#define CONN_SUP_TIMEOUT   MSEC_TO_UNITS(4000, UNIT_10_MS)
 
#define FIRST_CONN_PARAMS_UPDATE_DELAY   APP_TIMER_TICKS(20 * 1000, APP_TIMER_PRESCALER)
 
#define NEXT_CONN_PARAMS_UPDATE_DELAY   APP_TIMER_TICKS(5 * 1000, APP_TIMER_PRESCALER)
 
#define MAX_CONN_PARAMS_UPDATE_COUNT   3
 
#define MESSAGE_BUFFER_SIZE   18
 
#define APP_GPIOTE_MAX_USERS   1
 
#define BUTTON_DETECTION_DELAY   APP_TIMER_TICKS(50, APP_TIMER_PRESCALER)
 
#define SEC_PARAM_TIMEOUT   30
 
#define SEC_PARAM_BOND   1
 
#define SEC_PARAM_MITM   0
 
#define SEC_PARAM_IO_CAPABILITIES   BLE_GAP_IO_CAPS_NONE
 
#define SEC_PARAM_OOB   0
 
#define SEC_PARAM_MIN_KEY_SIZE   7
 
#define SEC_PARAM_MAX_KEY_SIZE   16
 
#define FLASH_PAGE_SYS_ATTR   (BLE_FLASH_PAGE_END - 3)
 
#define FLASH_PAGE_BOND   (BLE_FLASH_PAGE_END - 1)
 
#define ANS_FLASH_PAGE   (BLE_FLASH_PAGE_END - 4)
 
#define DEAD_BEEF   0xDEADBEEF
 

Enumerations

enum  ble_advertising_mode_t {
  BLE_NO_ADVERTISING,
  BLE_SLOW_ADVERTISING,
  BLE_FAST_ADVERTISING,
  BLE_NO_ADV,
  BLE_DIRECTED_ADV,
  BLE_FAST_ADV_WHITELIST,
  BLE_FAST_ADV,
  BLE_SLOW_ADV,
  BLE_SLEEP,
  BLE_NO_ADV,
  BLE_DIRECTED_ADV,
  BLE_FAST_ADV_WHITELIST,
  BLE_FAST_ADV,
  BLE_SLOW_ADV,
  BLE_SLEEP,
  BLE_NO_ADV,
  BLE_FAST_ADV_WHITELIST,
  BLE_FAST_ADV,
  BLE_SLOW_ADV,
  BLE_SLEEP,
  BLE_NO_ADV,
  BLE_FAST_ADV_WHITELIST,
  BLE_FAST_ADV,
  BLE_SLOW_ADV,
  BLE_SLEEP
}
 
enum  ble_ans_c_alert_state_t {
  ALERT_NOTIFICATION_DISABLED,
  ALERT_NOTIFICATION_ENABLED,
  ALERT_NOTIFICATION_ON
}
 

Functions

void app_error_handler (uint32_t error_code, uint32_t line_num, const uint8_t *p_file_name)
 Function for error handling, which is called when an error has occurred. More...
 
void assert_nrf_callback (uint16_t line_num, const uint8_t *p_file_name)
 Callback function for asserts in the SoftDevice. More...
 
static void alert_notification_setup (void)
 Function for setup of alert notifications in master. More...
 
static void control_point_setup (ble_ans_c_evt_t *p_evt)
 Function for setup of alert notifications in master. More...
 
static void supported_alert_notification_read (void)
 Function for reading supported alert notifications in master. More...
 
static void new_alert_state_toggle (void)
 Function for handling the key of the New Alert Notification button. More...
 
static void unread_alert_state_toggle (void)
 Function for handling the key of the Unread Alert button. More...
 
static void all_alert_notify_request (void)
 Function for handling key presses of the All Alert Notify button. More...
 
static void handle_alert_notification (ble_ans_c_evt_t *p_evt)
 Function for lighting up the LED corresponding to the notification received. More...
 
static void on_ans_c_evt (ble_ans_c_evt_t *p_evt)
 Function for handling the Alert Notification Service Client. More...
 
static void on_bond_mgmr_evt (ble_bondmngr_evt_t *p_evt)
 Function for handling the Bond Manager. More...
 
static void leds_init (void)
 Function for the LEDs initialization. More...
 
static void timers_init (void)
 Function for the Timer initialization. More...
 
static void gap_params_init (void)
 Function for the GAP initialization. More...
 
static void advertising_init (void)
 Function for initializing the Advertising functionality. More...
 
static void advertising_start (void)
 Function for starting advertising.
 
static void alert_notification_error_handler (uint32_t nrf_error)
 Function for handling the Alert Notification Service Client errors. More...
 
static void alert_notification_init (void)
 Function for initialization of the Alert Notification Service Client.
 
static void conn_params_error_handler (uint32_t nrf_error)
 Function for handling a Connection Parameters error. More...
 
static void conn_params_init (void)
 Function for initializing the Connection Parameters module.
 
static void sec_params_init (void)
 Function for initializing security parameters.
 
static void bond_manager_error_handler (uint32_t nrf_error)
 Function for handling a Bond Manager error. More...
 
static void bond_manager_init (void)
 Function for initializing the Bond Manager.
 
static void on_ble_evt (ble_evt_t *p_ble_evt)
 Function for handling the Application's BLE Stack events. More...
 
static void button_event_handler (uint8_t pin_no)
 Function for handling button events. More...
 
static void gpiote_init (void)
 Function for initializing the GPIOTE handler module.
 
static void buttons_init (void)
 Function for initializing the button handler module.
 
static void ble_evt_dispatch (ble_evt_t *p_ble_evt)
 Function for dispatching a BLE stack event to all modules with a BLE stack event handler. More...
 
static void ble_stack_init (void)
 Function for initializing the BLE stack. More...
 
static void radio_notification_init (void)
 Function for initializing the Radio Notification event handler.
 
static void power_manage (void)
 Function for the Power manager.
 
int main (void)
 Function for application main entry.
 

Variables

static ble_ans_c_t m_ans_c
 
static uint8_t m_alert_message_buffer [MESSAGE_BUFFER_SIZE]
 
static ble_gap_adv_params_t m_adv_params
 
static ble_advertising_mode_t m_advertising_mode
 
static ble_ans_c_alert_state_t m_new_alert_state = ALERT_NOTIFICATION_DISABLED
 
static ble_ans_c_alert_state_t m_unread_alert_state = ALERT_NOTIFICATION_DISABLED
 
static ble_gap_sec_params_t m_sec_params
 

Detailed Description

This file contains the source code for a sample application using the Alert Notification Profile Client. This application uses the srvlib_conn_params module.

Macro Definition Documentation

#define WAKEUP_BUTTON_PIN   NRF6310_BUTTON_0

Button used to wake up the application.

#define BONDMNGR_DELETE_BUTTON_PIN_NO   NRF6310_BUTTON_1

Button used for deleting all bonded masters/services during startup.

#define CLEAR_NEW_ALERT_BUTTON_PIN   NRF6310_BUTTON_2

Button used to clear New Alert status/Enable/Disable New Alert Notifications.

#define CLEAR_UNREAD_ALERT_BUTTON_PIN   NRF6310_BUTTON_3

Button used to clear Unread Alert status/Enable/Disable New Alert Notifications.

#define NOTIFY_ALL_ALERTS_BUTTON_PIN   NRF6310_BUTTON_4

Button used to request peer to notify all current alert statuses.

#define NEW_ALERT_NOTIF_LED_PIN_NO   NRF6310_LED_2

Is on when a New Alert Notification has been received.

#define UNREAD_ALERT_NOTIF_LED_PIN_NO   NRF6310_LED_3

Is on when a Unread Alert Notification has been received.

#define DEVICE_NAME   "Nordic_Alert_Notif."

Name of device. Will be included in the advertising data.

#define MANUFACTURER_NAME   "NordicSemiconductor"

Manufacturer. Will be passed to Device Information Service.

#define APP_ADV_INTERVAL   40

The advertising interval (in units of 0.625 ms. This value corresponds to 25 ms).

#define APP_ADV_INTERVAL_SLOW   3200

Slow advertising interval (in units of 0.625 ms. This value corresponds to 2 seconds).

#define APP_ADV_TIMEOUT_IN_SECONDS   180

The advertising timeout in units of seconds.

#define ADV_INTERVAL_FAST_PERIOD   30

The duration of the fast advertising period (in seconds).

#define APP_TIMER_PRESCALER   0

Value of the RTC1 PRESCALER register.

#define APP_TIMER_MAX_TIMERS   2

Maximum number of simultaneously created timers.

#define APP_TIMER_OP_QUEUE_SIZE   4

Size of timer operation queues.

#define MIN_CONN_INTERVAL   MSEC_TO_UNITS(500, UNIT_1_25_MS)

Minimum acceptable connection interval (0.5 seconds).

#define MAX_CONN_INTERVAL   MSEC_TO_UNITS(1000, UNIT_1_25_MS)

Maximum acceptable connection interval (1 second).

#define SLAVE_LATENCY   0

Slave latency.

#define CONN_SUP_TIMEOUT   MSEC_TO_UNITS(4000, UNIT_10_MS)

Connection supervisory timeout (4 seconds).

#define FIRST_CONN_PARAMS_UPDATE_DELAY   APP_TIMER_TICKS(20 * 1000, APP_TIMER_PRESCALER)

Time from initiating event (connect or start of notification) to first time sd_ble_gap_conn_param_update is called (20 seconds).

#define NEXT_CONN_PARAMS_UPDATE_DELAY   APP_TIMER_TICKS(5 * 1000, APP_TIMER_PRESCALER)

Time between each call to sd_ble_gap_conn_param_update after the first (5 seconds).

#define MAX_CONN_PARAMS_UPDATE_COUNT   3

Number of attempts before giving up the connection parameter negotiation.

#define MESSAGE_BUFFER_SIZE   18

Size of buffer holding optional messages in notifications.

#define APP_GPIOTE_MAX_USERS   1

Maximum number of users of the GPIOTE handler.

#define BUTTON_DETECTION_DELAY   APP_TIMER_TICKS(50, APP_TIMER_PRESCALER)

Delay from a GPIOTE event until a button is reported as pushed (in number of timer ticks).

#define SEC_PARAM_TIMEOUT   30

Timeout for Pairing Request or Security Request (in seconds).

#define SEC_PARAM_BOND   1

Perform bonding.

#define SEC_PARAM_MITM   0

Man In The Middle protection not required.

#define SEC_PARAM_IO_CAPABILITIES   BLE_GAP_IO_CAPS_NONE

No I/O capabilities.

#define SEC_PARAM_OOB   0

Out Of Band data not available.

#define SEC_PARAM_MIN_KEY_SIZE   7

Minimum encryption key size.

#define SEC_PARAM_MAX_KEY_SIZE   16

Maximum encryption key size.

#define FLASH_PAGE_SYS_ATTR   (BLE_FLASH_PAGE_END - 3)

Flash page used for bond manager system attribute information.

#define FLASH_PAGE_BOND   (BLE_FLASH_PAGE_END - 1)

Flash page used for bond manager bonding information.

#define ANS_FLASH_PAGE   (BLE_FLASH_PAGE_END - 4)

Flash page used for Alert Notification Client.

#define DEAD_BEEF   0xDEADBEEF

Value used as error code on stack dump, can be used to identify stack location on stack unwind.

Enumeration Type Documentation

Enumerator
BLE_NO_ADVERTISING 

No advertising running.

BLE_SLOW_ADVERTISING 

Slow advertising running.

BLE_FAST_ADVERTISING 

Fast advertising running.

BLE_NO_ADV 

No advertising running.

BLE_DIRECTED_ADV 

Direct advertising to the latest master.

BLE_FAST_ADV_WHITELIST 

Advertising whith whitelist.

BLE_FAST_ADV 

Fast advertising running.

BLE_SLOW_ADV 

Slow advertising running.

BLE_SLEEP 

Go to system-off.

BLE_NO_ADV 

No advertising running.

BLE_DIRECTED_ADV 

Direct advertising to the latest master.

BLE_FAST_ADV_WHITELIST 

Advertising whith whitelist.

BLE_FAST_ADV 

Fast advertising running.

BLE_SLOW_ADV 

Slow advertising running.

BLE_SLEEP 

Go to system-off.

BLE_NO_ADV 

No advertising running.

BLE_FAST_ADV_WHITELIST 

Advertising whith whitelist.

BLE_FAST_ADV 

Fast advertising running.

BLE_SLOW_ADV 

Slow advertising running.

BLE_SLEEP 

Go to system-off.

BLE_NO_ADV 

No advertising running.

BLE_FAST_ADV_WHITELIST 

Advertising with whitelist.

BLE_FAST_ADV 

Fast advertising running.

BLE_SLOW_ADV 

Slow advertising running.

BLE_SLEEP 

Go to system-off.

Enumerator
ALERT_NOTIFICATION_DISABLED 

Alert Notifications has been disabled.

ALERT_NOTIFICATION_ENABLED 

Alert Notifications has been enabled.

ALERT_NOTIFICATION_ON 

Alert State is on.

Function Documentation

void app_error_handler ( uint32_t  error_code,
uint32_t  line_num,
const uint8_t *  p_file_name 
)
Warning
This handler is an example only and does not fit a final product. You need to analyze how your product is supposed to react in case of error.
Parameters
[in]error_codeError code supplied to the handler.
[in]line_numLine number where the handler is called.
[in]p_file_namePointer to the file name.
void assert_nrf_callback ( uint16_t  line_num,
const uint8_t *  p_file_name 
)

This function will be called in case of an assert in the SoftDevice.

Warning
This handler is an example only and does not fit a final product. You need to analyze how your product is supposed to react in case of Assert.
On assert from the SoftDevice, the system can only recover on reset.
Parameters
[in]line_numLine number of the failing ASSERT call.
[in]file_nameFile name of the failing ASSERT call.
static void alert_notification_setup ( void  )
static

This function will be called when a successful connection has been established.

static void control_point_setup ( ble_ans_c_evt_t p_evt)
static

This function will be called when supported alert notification and supported unread alert notifications has been fetched.

Parameters
[in]p_evtEvent containing the response with supported alert types.
static void supported_alert_notification_read ( void  )
static

This function will be called when a connection has been established.

static void new_alert_state_toggle ( void  )
static

This function check the current state of new alert and then, enable, disable or clear the alert depending on the state.

static void unread_alert_state_toggle ( void  )
static

This function check the current state of unread alert and then, enable, disable or clear the alert depending on the state.

static void all_alert_notify_request ( void  )
static

This function check the current state of the alert notifications and based on the state it will request the master to resend current alert counters.

static void handle_alert_notification ( ble_ans_c_evt_t p_evt)
static
Parameters
[in]p_evtEvent containing the notification.
static void on_ans_c_evt ( ble_ans_c_evt_t p_evt)
static

This function will be called for all events in the Alert Notification Client which are passed to the application.

Parameters
[in]p_evtEvent received from the Alert Notification Service Client.
static void on_bond_mgmr_evt ( ble_bondmngr_evt_t p_evt)
static

This function will be called for all events in the Bond Manager which are passed to the application.

Parameters
[in]p_evtEvent received from the Bond Manager.
static void leds_init ( void  )
static

Initializes all LEDs used by this application.

static void timers_init ( void  )
static

Initializes the timer module.

static void gap_params_init ( void  )
static

This function shall be used to setup all the necessary GAP (Generic Access Profile) parameters of the device. It also sets the permissions and appearance.

static void advertising_init ( void  )
static

Encodes the required advertising data and passes it to the stack. Also builds a structure to be passed to the stack when starting advertising.

static void alert_notification_error_handler ( uint32_t  nrf_error)
static
Parameters
[in]nrf_errorError code containing information about what went wrong.
static void conn_params_error_handler ( uint32_t  nrf_error)
static
Parameters
[in]nrf_errorError code containing information about what went wrong.
static void bond_manager_error_handler ( uint32_t  nrf_error)
static
Parameters
[in]nrf_errorError code containing information about what went wrong.
static void on_ble_evt ( ble_evt_t p_ble_evt)
static
Parameters
[in]p_ble_evtBluetooth stack event.
static void button_event_handler ( uint8_t  pin_no)
static
Parameters
[in]pin_noThe pin number of the button pressed.
static void ble_evt_dispatch ( ble_evt_t p_ble_evt)
static

This function is called from the BLE Stack event interrupt handler after a BLE stack event has been received.

Parameters
[in]p_ble_evtBluetooth stack event.
static void ble_stack_init ( void  )
static

Initializes the SoftDevice and the BLE event interrupt.

Variable Documentation

ble_ans_c_t m_ans_c
static

Structure used to identify the Alert Notification Service Client.

uint8_t m_alert_message_buffer[MESSAGE_BUFFER_SIZE]
static

Message buffer for optional notify messages.

ble_gap_adv_params_t m_adv_params
static

Parameters to be passed to the stack when starting advertising.

ble_advertising_mode_t m_advertising_mode
static

Variable to keep track of when we are advertising.

State that holds the current state of New Alert Notifications, i.e. Enabled, Alert On, Disabled.

State that holds the current state of Unread Alert Notifications, i.e. Enabled, Alert On, Disabled.

ble_gap_sec_params_t m_sec_params
static

Security requirements for this application.