Microchip® Advanced Software Framework

eddystone.c File Reference

Eddystone Beacons Support.

Copyright (c) 2017-2018 Microchip Technology Inc. and its subsidiaries.

#include "eddystone.h"

Data Structures

struct  esuid_data_t
 Eddystone-UID beacon data. More...
 
struct  esurl_data_t
 Eddystone-URL beacon data. More...
 

Macros

#define CONVERT_MS_TO_625_US_UNIT(x)   ((x * 16)/10)
 Convert ms to 0.625ms units; Required to set advertisement intervals. More...
 
#define EDDYSTONE_FRAME_HEADER_LEN   (8)
 
#define EDDYSTONE_FRAME_TYPE_OFFSET   (8)
 
#define EDDYSTONE_HEADER(adv_data, index)
 
#define EDDYSTONE_MAX_URL_ENC_LEN   (18)
 
#define EDDYSTONE_SERV_DATA_LEN_OFFSET   (4)
 Eddystone specific defines. More...
 
#define EDDYSTONE_TX_POWER_MODES_NUM   (4)
 
#define ESURL_CONF_CHAR_UUID_DIFF_OFFSET   (12)
 Eddystone URL configuration service defines. More...
 
#define ESURL_LOCK_CODE_MAX_SIZE   (16)
 
#define ESURL_URI_FLAG_SIZE   (1)
 
#define HIGH_BYTE(x)   (uint8_t)((((uint16_t)x) >> 8) & 0xFF)
 
#define LOCKED   (1)
 Possible lock states. More...
 
#define LOW_BYTE(x)   (uint8_t)(((uint16_t)x) & 0xFF)
 Extract LSB and MSB from 16-bit value. More...
 
#define UNLOCKED   (0)
 

Typedefs

typedef struct esuid_data_t esuid_data_t
 Eddystone-UID beacon data. More...
 
typedef struct esurl_data_t esurl_data_t
 Eddystone-URL beacon data. More...
 

Enumerations

enum  esurl_conf_char_uuid_value_t {
  UUID_CHAR_LOCK_STATE = 0x81,
  UUID_CHAR_LOCK = 0x82,
  UUID_CHAR_UNLOCK = 0x83,
  UUID_CHAR_URI_DATA = 0x84,
  UUID_CHAR_FLAGS = 0x85,
  UUID_CHAR_ADV_TX_POWER = 0x86,
  UUID_CHAR_TX_POWER_MODE = 0x87,
  UUID_CHAR_BEACON_PERIOD = 0x88,
  UUID_CHAR_RESET = 0x89,
  UUID_CHAR_RESERVED = 0x90
}
 One byte of the UUID value that changes for each characteristics of the URL configuration service. More...
 

Functions

static at_ble_status_t eddystone_adv_start (uint8_t *adv_data)
 Starts the Eddystone advertisement. More...
 
at_ble_status_t eddystone_adv_stop (void)
 Stop the Eddystone advertisement. More...
 
static at_ble_status_t eddystone_create_tlm_frame (uint8_t *adv_data, eddystone_tlm_data_t *tlm_data)
 Creates Eddystone-TLM frame from battery voltage value, beacon temperature, advertisement PDU count and 100ms counter. More...
 
static at_ble_status_t eddystone_create_uid_frame (uint8_t *adv_data)
 Creates Eddystone-UID frame from 16-byte beacon ID and calibrated TX power value. More...
 
static at_ble_status_t eddystone_create_url_frame (uint8_t *adv_data)
 Creates Eddystone-URL frame from URI data and advertised TX power value. More...
 
eddystone_mode_t eddystone_get_mode (void)
 Get current mode of the Eddystone beacon. More...
 
at_ble_status_t eddystone_init (void)
 Initializes all Eddystone parameters. More...
 
at_ble_status_t eddystone_set_beacon_id (beacon_id_t *uid)
 Update the Eddystone UID value. More...
 
at_ble_status_t eddystone_set_beacon_interval (uint16_t beacon_interval_ms)
 Update the beacon interval value. More...
 
at_ble_status_t eddystone_set_encoded_url (uint8_t *url_val, uint8_t len)
 Update Eddystone URL in the encoded form. More...
 
at_ble_status_t eddystone_set_power_mode (eddystone_tx_power_mode_t tx_power_mode)
 Update the advertised TX power mode in Eddystone-URL. More...
 
at_ble_status_t eddystone_set_uid_calib_tx_power (int8_t tx_power_0m, at_ble_tx_power_level_t radio_tx_power)
 Update the calibrated TX power present in the Eddystone-UID frame. More...
 
at_ble_status_t eddystone_tlm_frame_send (eddystone_tlm_data_t *tlm_data)
 Start sending the Eddystone TLM frames. More...
 
at_ble_status_t eddystone_uid_frame_send ()
 Start sending the Eddystone UID frames. More...
 
at_ble_status_t eddystone_url_frame_send ()
 Start sending the Eddystone URL frames. More...
 
static void esuid_data_reset (void)
 Functions to reset the UID and URL related parameters to default values. More...
 
at_ble_status_t esurl_char_changed_event (void *params)
 Event handling callback functions. More...
 
at_ble_status_t esurl_conf_adv_start (uint16_t adv_interval)
 Start the advertisement for Eddystone configuration service. More...
 
static at_ble_status_t esurl_conf_chars_reset (void)
 Resets all the configuration service characteristics to their default values. More...
 
at_ble_status_t esurl_conf_service_init (esurl_conf_gatt_service_t *serv)
 Initialize the Eddystone URL configuration service. More...
 
static void esurl_data_reset (void)
 Resets the URL related parameters to their default values. More...
 
at_ble_status_t esurl_dev_connected_event (void *params)
 Callback to handle the device connected event. More...
 
at_ble_status_t esurl_dev_disconnected_event (void *params)
 Callback to handle the device disconnected event. More...
 
at_ble_status_t esurl_paired_event (void *params)
 Callback to handle the device paired event. More...
 
at_ble_status_t esurl_read_authorize_event (void *params)
 
at_ble_status_t esurl_write_authorize_event (void *params)
 Callback to handle write authorization for the URL configuration characteristics. More...
 

Variables

volatile uint32_t eddystone_100ms_counter = 0
 100ms counter value used in the creation of TLM frame. More...
 
static volatile uint8_t eddystone_adv_enabled = 0
 
static uint8_t es_adv_data [AT_BLE_ADV_MAX_SIZE]
 
static at_ble_handle_t es_conf_conn_handle
 
volatile eddystone_mode_t es_mode = EDDYSTONE_BEACON_MODE
 
static uint8_t es_scan_data [AT_BLE_ADV_MAX_SIZE]
 
static uint8_t es_url_adv_data [AT_BLE_ADV_MAX_SIZE]
 
esuid_data_t esuid_data
 Eddystone-UID related data. More...
 
static uint8_t esurl_conf_char_initialized = 0
 
const ble_gap_event_cb_t esurl_conf_gap_cb
 Eddystone GAP events handler initialization. More...
 
const ble_gatt_server_event_cb_t esurl_conf_gatt_server_cb
 Eddystone GATT server events handler initialization. More...
 
esurl_conf_gatt_service_t esurl_conf_service
 Eddystone-URL configuration service information. More...
 
esurl_data_t esurl_data
 Eddystone-URL related data. More...
 

#define CONVERT_MS_TO_625_US_UNIT (   x)    ((x * 16)/10)

Convert ms to 0.625ms units; Required to set advertisement intervals.

Referenced by eddystone_adv_start().

#define EDDYSTONE_FRAME_HEADER_LEN   (8)
#define EDDYSTONE_FRAME_TYPE_OFFSET   (8)

Referenced by eddystone_adv_start().

#define EDDYSTONE_HEADER (   adv_data,
  index 
)
Value:
do {\
uint8_t pos = index;\
adv_data[index++] = 0x03;\
adv_data[index++] = 0x00;\
adv_data[index++] = (uint8_t)SERVICE_DATA;\
adv_data[index++] = adv_data[pos + 2];\
adv_data[index++] = adv_data[pos + 3];\
} while(0)
uint8_t adv_data[MAX_ADV_LEN]
Definition: simple_broadcaster_app.c:148
#define LOW_BYTE(x)
Extract LSB and MSB from 16-bit value.
Definition: eddystone.c:48
#define HIGH_BYTE(x)
Definition: eddystone.c:49
complete list of 16bits service uuids
Definition: ble_sdk/ble_services/ble_mgr/ble_manager.h:648
service data
Definition: ble_sdk/ble_services/ble_mgr/ble_manager.h:680
#define EDDYSTONE_16_BIT_UUID
16-bit Eddystone Service UUID
Definition: eddystone.h:49

Referenced by eddystone_create_tlm_frame(), eddystone_create_uid_frame(), and eddystone_create_url_frame().

#define EDDYSTONE_MAX_URL_ENC_LEN   (18)
#define EDDYSTONE_SERV_DATA_LEN_OFFSET   (4)
#define EDDYSTONE_TX_POWER_MODES_NUM   (4)
#define ESURL_CONF_CHAR_UUID_DIFF_OFFSET   (12)

Eddystone URL configuration service defines.

Referenced by esurl_conf_service_init().

#define ESURL_LOCK_CODE_MAX_SIZE   (16)
#define ESURL_URI_FLAG_SIZE   (1)
#define HIGH_BYTE (   x)    (uint8_t)((((uint16_t)x) >> 8) & 0xFF)
#define LOCKED   (1)

Possible lock states.

Referenced by esurl_write_authorize_event().

#define LOW_BYTE (   x)    (uint8_t)(((uint16_t)x) & 0xFF)

Extract LSB and MSB from 16-bit value.

Referenced by eddystone_create_tlm_frame(), eddystone_set_beacon_interval(), and esurl_data_reset().

#define UNLOCKED   (0)

typedef struct esuid_data_t esuid_data_t

Eddystone-UID beacon data.

typedef struct esurl_data_t esurl_data_t

Eddystone-URL beacon data.

One byte of the UUID value that changes for each characteristics of the URL configuration service.

Enumerator
UUID_CHAR_LOCK_STATE 
UUID_CHAR_LOCK 
UUID_CHAR_UNLOCK 
UUID_CHAR_URI_DATA 
UUID_CHAR_FLAGS 
UUID_CHAR_ADV_TX_POWER 
UUID_CHAR_TX_POWER_MODE 
UUID_CHAR_BEACON_PERIOD 
UUID_CHAR_RESET 
UUID_CHAR_RESERVED 

at_ble_status_t eddystone_adv_stop ( void  )
static at_ble_status_t eddystone_create_tlm_frame ( uint8_t *  adv_data,
eddystone_tlm_data_t tlm_data 
)
static

Creates Eddystone-TLM frame from battery voltage value, beacon temperature, advertisement PDU count and 100ms counter.

References at_ble_get_adv_cnt(), AT_BLE_SUCCESS, eddystone_tlm_data_t::battery_voltage_mV, eddystone_100ms_counter, EDDYSTONE_HEADER, EDDYSTONE_SERV_DATA_LEN_OFFSET, EDDYSTONE_TLM, EDDYSTONE_TLM_FRAME_VERSION, HIGH_BYTE, LOW_BYTE, and eddystone_tlm_data_t::temperature.

Referenced by eddystone_tlm_frame_send().

static at_ble_status_t eddystone_create_uid_frame ( uint8_t *  adv_data)
static

Creates Eddystone-UID frame from 16-byte beacon ID and calibrated TX power value.

It also set the radio TX power of the device

References AT_BLE_SUCCESS, at_ble_tx_power_set(), esuid_data_t::beacon_id, EDDYSTONE_HEADER, EDDYSTONE_SERV_DATA_LEN_OFFSET, EDDYSTONE_UID, esuid_data_t::radio_tx_power, esuid_data_t::tx_power_0m, and beacon_id_t::value.

Referenced by eddystone_uid_frame_send().

static at_ble_status_t eddystone_create_url_frame ( uint8_t *  adv_data)
static
eddystone_mode_t eddystone_get_mode ( void  )

Get current mode of the Eddystone beacon.

Obtain the current mode of the Eddystone beacon.

References es_mode.

Referenced by eddystone_custom_event(), and main().

at_ble_status_t eddystone_init ( void  )

Initializes all Eddystone parameters.

Eddystone initialization; all UID and URL data are reset to default values.

References AT_BLE_SUCCESS, esuid_data_reset(), and esurl_data_reset().

Referenced by eddystone_app_init().

at_ble_status_t eddystone_set_beacon_id ( beacon_id_t uid)

Update the Eddystone UID value.

Update the Eddystone-UID (beacon ID).

References AT_BLE_SUCCESS, esuid_data_t::beacon_id, beacon_id_t::instance_id, and beacon_id_t::namespace_id.

at_ble_status_t eddystone_set_beacon_interval ( uint16_t  beacon_interval_ms)

Update the beacon interval value.

Update the beacon interval.

Restart sending the Eddystone frames to use the updated beacon interval

References at_ble_characteristic_value_set(), AT_BLE_FAILURE, esurl_data_t::beacon_period, CHAR_BEACON_PERIOD, at_ble_characteristic_t::char_val_handle, esurl_conf_gatt_service_t::chars, esurl_conf_char_initialized, HIGH_BYTE, and LOW_BYTE.

at_ble_status_t eddystone_set_encoded_url ( uint8_t *  url_val,
uint8_t  len 
)
at_ble_status_t eddystone_set_power_mode ( eddystone_tx_power_mode_t  tx_power_mode)
at_ble_status_t eddystone_set_uid_calib_tx_power ( int8_t  tx_power_0m,
at_ble_tx_power_level_t  radio_tx_power 
)

Update the calibrated TX power present in the Eddystone-UID frame.

Update the calibrated TX power value present in the Eddystone-UID frame.

References AT_BLE_SUCCESS, esuid_data_t::radio_tx_power, and esuid_data_t::tx_power_0m.

at_ble_status_t eddystone_tlm_frame_send ( eddystone_tlm_data_t tlm_data)

Start sending the Eddystone TLM frames.

Start sending Eddystone TLM beacons continuously The TLM frame is created out of battery voltage value, beacon temperature, advertisement PDU count and time since boot up.

References AT_BLE_SUCCESS, eddystone_adv_start(), eddystone_adv_stop(), eddystone_create_tlm_frame(), EDDYSTONE_URL_CONFIG_MODE_ADV, es_adv_data, and es_mode.

Referenced by main().

at_ble_status_t eddystone_uid_frame_send ( void  )

Start sending the Eddystone UID frames.

Start sending Eddystone UID beacons continuously The UID frame is created out of parameters like Beacon ID and calibrated tx power at 0m.

References AT_BLE_SUCCESS, eddystone_adv_start(), eddystone_adv_stop(), eddystone_create_uid_frame(), EDDYSTONE_URL_CONFIG_MODE_ADV, es_adv_data, and es_mode.

Referenced by eddystone_app_init(), and main().

at_ble_status_t eddystone_url_frame_send ( void  )

Start sending the Eddystone URL frames.

Start sending Eddystone URL beacons continuously The URL frame is created out of encoded URL and advertised tx power level at 0m.

References at_ble_disconnect(), AT_BLE_SUCCESS, AT_BLE_TERMINATED_BY_USER, eddystone_adv_start(), eddystone_adv_stop(), eddystone_create_url_frame(), EDDYSTONE_URL_CONFIG_MODE_ADV, EDDYSTONE_URL_CONFIG_MODE_CONNECTED, es_conf_conn_handle, es_mode, and es_url_adv_data.

Referenced by eddystone_app_init(), eddystone_custom_event(), esurl_dev_disconnected_event(), and main().

static void esuid_data_reset ( void  )
static

Functions to reset the UID and URL related parameters to default values.

Resets the UID related parameters to their default values.

References esuid_data_t::beacon_id, CONF_ES_CALIB_TX_PWR_0m, CONF_ES_INSTANCE_ID, CONF_ES_NAMESPACE_ID, CONF_ES_RADIO_TX_PWR_0m, esuid_data, beacon_id_t::instance_id, beacon_id_t::namespace_id, esuid_data_t::radio_tx_power, and esuid_data_t::tx_power_0m.

Referenced by eddystone_init().

at_ble_status_t esurl_char_changed_event ( void *  params)

Event handling callback functions.

Callback to handle Characteristics changed event.

References AT_BLE_FAILURE, at_ble_characteristic_changed_t::char_handle, at_ble_characteristic_changed_t::char_len, at_ble_characteristic_changed_t::char_offset, and DBG_LOG.

at_ble_status_t esurl_conf_service_init ( esurl_conf_gatt_service_t serv)

Initialize the Eddystone URL configuration service.

Eddystone URL Configuration Service and Characteristics initialization.

References esurl_data_t::adv_tx_power_level, AT_BLE_ATTR_NO_PERMISSIONS, AT_BLE_ATTR_READABLE_NO_AUTHN_NO_AUTHR, AT_BLE_ATTR_READABLE_REQ_AUTHN_NO_AUTHR, AT_BLE_ATTR_WRITABLE_NO_AUTHN_REQ_AUTHR, AT_BLE_ATTR_WRITABLE_REQ_AUTHN_REQ_AUTHR, AT_BLE_CHAR_READ, AT_BLE_CHAR_WRITE, at_ble_primary_service_define(), AT_BLE_SUCCESS, AT_BLE_UUID_128, AT_BLE_UUID_128_LEN, esurl_data_t::beacon_period, BLE_PAIR_ENABLE, CHAR_ADV_TX_POWER_LEVELS, CHAR_BEACON_PERIOD, CHAR_LOCK, CHAR_LOCK_STATE, CHAR_RESET, CHAR_TX_POWER_MODE, CHAR_UNLOCK, CHAR_URI_DATA, CHAR_URI_FLAGS, at_ble_characteristic_t::char_val_handle, esurl_conf_gatt_service_t::chars, at_ble_characteristic_t::client_config_handle, at_ble_characteristic_t::client_config_permissions, CONF_ES_DEFAULT_URL_SIZE, EDDYSTONE_TX_POWER_MODES_NUM, EDDYSTONE_URI_DATA_MAX_SIZE, EDDYSTONE_URL_CONF_SERVICE_UUID, esurl_conf_char_initialized, ESURL_CONF_CHAR_NUM, ESURL_CONF_CHAR_UUID_DIFF_OFFSET, esurl_data_reset(), ESURL_LOCK_CODE_MAX_SIZE, esurl_conf_gatt_service_t::handle, at_ble_characteristic_t::init_value, esurl_data_t::lock_code, esurl_data_t::lock_code_len, esurl_data_t::lock_state, NULL, at_ble_characteristic_t::presentation_format, at_ble_characteristic_t::properties, at_ble_characteristic_t::server_config_handle, at_ble_characteristic_t::server_config_permissions, esurl_data_t::tx_power_mode, at_ble_uuid_t::type, esurl_data_t::uri_data, esurl_data_t::uri_flags, at_ble_characteristic_t::user_desc, at_ble_characteristic_t::user_desc_handle, at_ble_characteristic_t::user_desc_len, at_ble_characteristic_t::user_desc_max_len, at_ble_characteristic_t::user_desc_permissions, esurl_conf_gatt_service_t::uuid, at_ble_uuid_t::uuid, at_ble_characteristic_t::uuid, UUID_CHAR_ADV_TX_POWER, UUID_CHAR_BEACON_PERIOD, UUID_CHAR_FLAGS, UUID_CHAR_LOCK, UUID_CHAR_LOCK_STATE, UUID_CHAR_RESET, UUID_CHAR_TX_POWER_MODE, UUID_CHAR_UNLOCK, UUID_CHAR_URI_DATA, at_ble_characteristic_t::value_init_len, at_ble_characteristic_t::value_max_len, and at_ble_characteristic_t::value_permissions.

Referenced by eddystone_app_init().

at_ble_status_t esurl_dev_connected_event ( void *  params)
at_ble_status_t esurl_dev_disconnected_event ( void *  params)

Callback to handle the device disconnected event.

References AT_BLE_SUCCESS, DBG_LOG, EDDYSTONE_IDLE_MODE, eddystone_url_frame_send(), and es_mode.

at_ble_status_t esurl_paired_event ( void *  params)

Callback to handle the device paired event.

References AT_BLE_SUCCESS, and DBG_LOG.

at_ble_status_t esurl_read_authorize_event ( void *  params)

volatile uint32_t eddystone_100ms_counter = 0

100ms counter value used in the creation of TLM frame.

This counter variable needs to be updated by the application for every 100ms

Referenced by eddystone_create_tlm_frame(), and timer_callback_handler().

volatile uint8_t eddystone_adv_enabled = 0
static
at_ble_handle_t es_conf_conn_handle
static
uint8_t es_scan_data[AT_BLE_ADV_MAX_SIZE]
static

Referenced by esurl_conf_adv_start().

uint8_t es_url_adv_data[AT_BLE_ADV_MAX_SIZE]
static
esuid_data_t esuid_data

Eddystone-UID related data.

Referenced by esuid_data_reset().

uint8_t esurl_conf_char_initialized = 0
static
const ble_gap_event_cb_t esurl_conf_gap_cb
Initial value:
= {
.pair_done = esurl_paired_event,
}
at_ble_status_t esurl_dev_disconnected_event(void *params)
Callback to handle the device disconnected event.
Definition: eddystone.c:905
at_ble_status_t esurl_dev_connected_event(void *params)
Callback to handle the device connected event.
Definition: eddystone.c:892
at_ble_status_t esurl_paired_event(void *params)
Callback to handle the device paired event.
Definition: eddystone.c:915

Eddystone GAP events handler initialization.

Eddystone GAP events callback handler.

Referenced by eddystone_app_init().

const ble_gatt_server_event_cb_t esurl_conf_gatt_server_cb
Initial value:
= {
.characteristic_changed = esurl_char_changed_event,
.write_authorize_request = esurl_write_authorize_event,
}
at_ble_status_t esurl_write_authorize_event(void *params)
Callback to handle write authorization for the URL configuration characteristics. ...
Definition: eddystone.c:934
at_ble_status_t esurl_char_changed_event(void *params)
Event handling callback functions.
Definition: eddystone.c:922

Eddystone GATT server events handler initialization.

Eddystone GATT server events callback handler.

Referenced by eddystone_app_init().

esurl_conf_gatt_service_t esurl_conf_service

Eddystone-URL configuration service information.

Referenced by eddystone_app_init().

esurl_data_t esurl_data

Eddystone-URL related data.