BLE Battery Service Application Implementations.
Copyright (c) 2020-2021 Microchip Technology Inc. and its subsidiaries.
#include "battery_app.h"
#include "ble_manager.h"
#include "battery.h"
#include "common/include/nm_common.h"
#include <asf.h>
#include "driver/include/m2m_wifi.h"
#include "driver/include/m2m_periph.h"
#include "m2m_ble.h"
#include "at_ble_api.h"
#include "wifi_prov.h"
Macros | |
#define | ADV_DATA_LEN (18) |
ADV_DATA_LEN. More... | |
#define | ADV_TYPE_LEN (0x01) |
ADV_TYPE_LEN. More... | |
#define | APP_BAS_ADV_TIMEOUT (1000) |
APP_BAS_ADV_TIMEOUT Advertising time-out between 0x0001 and 0x3FFF in seconds, 0x0000 disables time-out. More... | |
#define | APP_BAS_FAST_ADV (100) |
#define | APP_BTN_EVENT_BTN1_LONG_PRESS 2 |
#define | APP_BTN_EVENT_BTN1_SHORT_PRESS 1 |
#define | APP_BTN_EVENT_BTN2_LONG_PRESS 8 |
#define | APP_BTN_EVENT_BTN2_SHORT_PRESS 4 |
#define | APP_STATE_COMPLETE 6 |
#define | APP_STATE_IDLE 0 |
#define | APP_STATE_PROVISIONING 2 |
#define | APP_STATE_WAITING_FOR_BUTTON_PRESS 3 |
#define | APP_STATE_WAITING_FOR_PROFILE_SWITCH 5 |
#define | APP_STATE_WAITING_FOR_WIFI_CONNECTION 4 |
#define | APP_STATE_WAITING_FOR_WIFI_DISCONNECTION 1 |
#define | APP_WIFI_PROV_DISPLAY_NAME ("3400 DEMO") |
#define | BAS_ADV_DATA_NAME_DATA ("MCHP-BAS") |
#define | BAS_ADV_DATA_NAME_LEN (9) |
BAS_ADV_DATA_NAME_LEN the length of the device name. More... | |
#define | BAS_ADV_DATA_NAME_TYPE (0x09) |
BAS_ADV_DATA_NAME_TYPE the gap ad data type. More... | |
#define | BAS_ADV_DATA_UUID_LEN (2) |
BAS_ADV_DATA_UUID_LEN the size of BAS service uuid. More... | |
#define | BAS_ADV_DATA_UUID_TYPE (0x03) |
BAS_ADV_DATA_UUID_TYPE the total sizeof BAS service uuid. More... | |
#define | BATTERY_MAX_LEVEL (100) |
#define | BATTERY_UPDATE_INTERVAL (188) |
#define | HEX2ASCII(x) (((x)>=10)? (((x)-10)+'A') : ((x)+'0')) |
#define | SCAN_RESP_LEN (10) |
scan_resp_len is the length of the scan response data More... | |
#define | STRING_HEADER |
Functions | |
static at_ble_event_parameter_t gu8BleParam | __aligned (4) |
static void | app_ble_battery (void) |
static void | app_ble_wifi_provisioning (void) |
static void | app_button_press_callback (uint8 btn, uint8 press) |
static void | app_main (void) |
static void | app_wifi_handle_event (uint8 u8MsgType, void *pvMsg) |
static void | app_wifi_init (tpfAppWifiCb wifi_cb_func) |
static void | ble_bat_handle_disconnect_event (at_ble_handle_t conn_handle) |
static void | ble_bat_handle_paired_event (at_ble_handle_t conn_handle) |
static void | ble_bat_handle_timer_event (void) |
void | ble_bat_init (void) |
static void | ble_bat_process (void) |
void | ble_bat_process_event (at_ble_events_t event, at_ble_event_parameter_t *params) |
static void | ble_bat_profile_init (void) |
static at_ble_status_t | ble_bat_start_advertise (void) |
static void | configure_console (void) |
int | main (void) |
uint32 | nmi_inet_addr (char *pcIpAddr) |
Variables | |
static gatt_service_handler_t | bas_service_handler |
static uint8_t | battery_level |
static volatile uint8 | gu8BtnEvent |
static uint8 | gu8ScanIndex |
static volatile uint8 | gu8WiFiConnectionState = M2M_WIFI_UNDEF |
static uint8_t | led_toggle |
static const uint8_t | SCAN_RESP_DATA [SCAN_RESP_LEN] = {0x09,0xff, 0x00, 0x06, 0xd6, 0xb2, 0xf0, 0x05, 0xf0, 0xf8} |
bool volatile | timer_cb_done |
#define ADV_DATA_LEN (18) |
ADV_DATA_LEN.
#define ADV_TYPE_LEN (0x01) |
ADV_TYPE_LEN.
Referenced by ble_bat_start_advertise().
#define APP_BAS_ADV_TIMEOUT (1000) |
APP_BAS_ADV_TIMEOUT Advertising time-out between 0x0001 and 0x3FFF in seconds, 0x0000 disables time-out.
Referenced by ble_bat_start_advertise().
#define APP_BAS_FAST_ADV (100) |
Referenced by ble_bat_start_advertise().
#define APP_BTN_EVENT_BTN1_LONG_PRESS 2 |
Referenced by app_ble_wifi_provisioning(), and app_button_press_callback().
#define APP_BTN_EVENT_BTN1_SHORT_PRESS 1 |
Referenced by app_ble_wifi_provisioning(), and app_button_press_callback().
#define APP_BTN_EVENT_BTN2_LONG_PRESS 8 |
Referenced by app_button_press_callback().
#define APP_BTN_EVENT_BTN2_SHORT_PRESS 4 |
Referenced by app_button_press_callback().
#define APP_STATE_COMPLETE 6 |
Referenced by app_ble_wifi_provisioning().
#define APP_STATE_IDLE 0 |
Referenced by app_ble_wifi_provisioning().
#define APP_STATE_PROVISIONING 2 |
Referenced by app_ble_wifi_provisioning().
#define APP_STATE_WAITING_FOR_BUTTON_PRESS 3 |
Referenced by app_ble_wifi_provisioning().
#define APP_STATE_WAITING_FOR_PROFILE_SWITCH 5 |
Referenced by app_ble_wifi_provisioning().
#define APP_STATE_WAITING_FOR_WIFI_CONNECTION 4 |
Referenced by app_ble_wifi_provisioning().
#define APP_STATE_WAITING_FOR_WIFI_DISCONNECTION 1 |
Referenced by app_ble_wifi_provisioning().
#define APP_WIFI_PROV_DISPLAY_NAME ("3400 DEMO") |
Referenced by app_ble_wifi_provisioning().
#define BAS_ADV_DATA_NAME_DATA ("MCHP-BAS") |
Referenced by ble_bat_start_advertise().
#define BAS_ADV_DATA_NAME_LEN (9) |
BAS_ADV_DATA_NAME_LEN the length of the device name.
Referenced by ble_bat_start_advertise().
#define BAS_ADV_DATA_NAME_TYPE (0x09) |
BAS_ADV_DATA_NAME_TYPE the gap ad data type.
Referenced by ble_bat_start_advertise().
#define BAS_ADV_DATA_UUID_LEN (2) |
BAS_ADV_DATA_UUID_LEN the size of BAS service uuid.
Referenced by ble_bat_start_advertise().
#define BAS_ADV_DATA_UUID_TYPE (0x03) |
BAS_ADV_DATA_UUID_TYPE the total sizeof BAS service uuid.
Referenced by ble_bat_start_advertise().
#define BATTERY_MAX_LEVEL (100) |
Referenced by ble_bat_process(), and ble_bat_profile_init().
#define BATTERY_UPDATE_INTERVAL (188) |
Referenced by ble_bat_handle_paired_event().
#define HEX2ASCII | ( | x | ) | (((x)>=10)? (((x)-10)+'A') : ((x)+'0')) |
Referenced by app_wifi_init().
#define SCAN_RESP_LEN (10) |
scan_resp_len is the length of the scan response data
Referenced by ble_bat_start_advertise().
#define STRING_HEADER |
Referenced by main().
|
static |
|
static |
References AT_BLE_SUCCESS, ble_bat_init(), ble_bat_process_event(), m2m_ble_event_get(), and m2m_ble_init().
Referenced by app_main().
|
static |
References APP_BTN_EVENT_BTN1_LONG_PRESS, APP_BTN_EVENT_BTN1_SHORT_PRESS, APP_STATE_COMPLETE, APP_STATE_IDLE, APP_STATE_PROVISIONING, APP_STATE_WAITING_FOR_BUTTON_PRESS, APP_STATE_WAITING_FOR_PROFILE_SWITCH, APP_STATE_WAITING_FOR_WIFI_CONNECTION, APP_STATE_WAITING_FOR_WIFI_DISCONNECTION, APP_WIFI_PROV_DISPLAY_NAME, AT_BLE_AUTH_NO_MITM_NO_BOND, AT_BLE_SUCCESS, ble_prov_get_credentials(), ble_prov_get_provision_state(), ble_prov_init(), ble_prov_process_event(), ble_prov_start(), BLE_PROV_STATE_FAILED, BLE_PROV_STATE_SUCCESS, ble_prov_stop(), ble_prov_wifi_con_update, CREDENTIALS_VALID, DEFAULT_AUTH, DEFAULT_KEY, DEFAULT_SSID, gu8BtnEvent, gu8WiFiConnectionState, m2m_ble_event_get(), m2m_ble_init(), M2M_INFO, M2M_WIFI_CH_ALL, m2m_wifi_connect(), M2M_WIFI_CONNECTED, m2m_wifi_disconnect(), M2M_WIFI_DISCONNECTED, M2M_WIFI_UNDEF, credentials::passphrase, credentials::sec_type, credentials::ssid, credentials::ssid_length, WIFIPROV_CON_STATE_CONNECTED, WIFIPROV_CON_STATE_CONNECTING, and WIFIPROV_CON_STATE_DISCONNECTED.
Referenced by app_main().
References APP_BTN_EVENT_BTN1_LONG_PRESS, APP_BTN_EVENT_BTN1_SHORT_PRESS, APP_BTN_EVENT_BTN2_LONG_PRESS, APP_BTN_EVENT_BTN2_SHORT_PRESS, gu8BtnEvent, SW1, and SW2.
Referenced by app_main().
|
static |
References app_ble_battery(), app_ble_wifi_provisioning(), app_button_press_callback(), app_wifi_handle_event(), app_wifi_init(), nm_bsp_btn_init(), and nm_bsp_sleep().
Referenced by main().
|
static |
References ble_prov_scan_result(), gu8ScanIndex, gu8WiFiConnectionState, M2M_ERR, M2M_INFO, M2M_WIFI_CONNECTED, M2M_WIFI_DISCONNECTED, m2m_wifi_get_num_ap_found(), M2M_WIFI_REQ_DHCP_CONF, m2m_wifi_req_scan_result(), M2M_WIFI_RESP_CON_STATE_CHANGED, M2M_WIFI_RESP_CURRENT_RSSI, M2M_WIFI_RESP_SCAN_DONE, M2M_WIFI_RESP_SCAN_RESULT, M2M_WIFI_RESP_SET_GAIN_TABLE, NM_BSP_TIME_MSEC, tstrM2MGainTableRsp::s8ErrorCode, tstrM2MIPConfig::u32StaticIP, tstrM2mWifiStateChanged::u8CurrState, and tstrM2mScanDone::u8NumofCh.
Referenced by app_main().
|
static |
References tstrEthInitParam::au8ethRcvBuf, HEX2ASCII, m2m_ble_wifi_init(), M2M_DEVICE_NAME, M2M_ERR, M2M_INFO, M2M_LISTEN_INTERVAL, m2m_memset(), M2M_NO_PS, m2m_periph_pullup_ctrl(), M2M_PERIPH_PULLUP_DIS_HOST_WAKEUP, M2M_PERIPH_PULLUP_DIS_SD_CMD_SPI_SCK, M2M_PERIPH_PULLUP_DIS_SD_DAT0_SPI_TXD, M2M_PS_DEEP_AUTOMATIC, M2M_PS_MANUAL, m2m_strlen(), M2M_SUCCESS, m2m_wifi_get_mac_address(), m2m_wifi_get_otp_mac_address(), m2m_wifi_set_device_name(), m2m_wifi_set_lsn_int(), m2m_wifi_set_mac_address(), m2m_wifi_set_sleep_mode(), MAC_ADDRESS, tstrEthInitParam::pfAppEthCb, tstrWifiInitParam::pfAppWifiCb, tstrWifiInitParam::strEthInitParam, tstrEthInitParam::u16ethRcvBufSize, and tstrM2mLsnInt::u16LsnInt.
Referenced by app_main().
|
static |
References ble_bat_start_advertise(), nm_bsp_stop_timer(), and timer_cb_done.
Referenced by ble_bat_profile_init().
|
static |
References BATTERY_UPDATE_INTERVAL, ble_bat_handle_timer_event(), nm_bsp_start_timer(), nm_bsp_stop_timer(), and timer_cb_done.
Referenced by ble_bat_profile_init().
|
static |
References led_toggle, and timer_cb_done.
Referenced by ble_bat_handle_paired_event().
void ble_bat_init | ( | void | ) |
References ble_bat_profile_init(), ble_device_init(), and NULL.
Referenced by app_ble_battery().
|
static |
References AT_BLE_SUCCESS, bat_update_char_value(), battery_level, BATTERY_MAX_LEVEL, DBG_LOG, led_toggle, and timer_cb_done.
Referenced by ble_bat_process_event().
void ble_bat_process_event | ( | at_ble_events_t | event, |
at_ble_event_parameter_t * | params | ||
) |
References AT_BLE_UNDEFINED_EVENT, ble_bat_process(), and ble_event_manager().
Referenced by app_ble_battery().
|
static |
References bat_init_service(), bat_primary_service_define(), battery_level, BATTERY_MAX_LEVEL, ble_bat_handle_disconnect_event(), ble_bat_handle_paired_event(), ble_bat_start_advertise(), DBG_LOG, led_toggle, register_ble_disconnected_event_cb(), register_ble_paired_event_cb(), and timer_cb_done.
Referenced by ble_bat_init().
|
static |
References ADV_TYPE_LEN, APP_BAS_ADV_TIMEOUT, APP_BAS_FAST_ADV, at_ble_adv_data_set(), AT_BLE_ADV_FP_ANY, AT_BLE_ADV_GEN_DISCOVERABLE, at_ble_adv_start(), AT_BLE_ADV_TYPE_UNDIRECTED, AT_BLE_FAILURE, AT_BLE_GAP_PERIPHERAL_SLV, at_ble_set_dev_config(), AT_BLE_SUCCESS, BAS_ADV_DATA_NAME_DATA, BAS_ADV_DATA_NAME_LEN, BAS_ADV_DATA_NAME_TYPE, BAS_ADV_DATA_UUID_LEN, BAS_ADV_DATA_UUID_TYPE, BAT_SERVICE_UUID, DBG_LOG, NULL, SCAN_RESP_DATA, and SCAN_RESP_LEN.
Referenced by ble_bat_handle_disconnect_event(), and ble_bat_profile_init().
|
static |
References uart_rs232_options::baudrate, CONF_UART, CONF_UART_BAUDRATE, CONF_UART_CHAR_LENGTH, CONF_UART_PARITY, CONF_UART_STOP_BITS, CONSOLE_UART_ID, stdio_serial_init(), and sysclk_enable_peripheral_clock().
Referenced by main().
int main | ( | void | ) |
References app_main(), board_init(), configure_console(), F_CPU, nm_bsp_app_init(), nm_bsp_init(), STRING_HEADER, and sysclk_init().
uint32 nmi_inet_addr | ( | char * | pcIpAddr | ) |
Synchronous function which returns a BSD socket compliant Internet Protocol (IPv4) socket address. This IPv4 address in the input string parameter could either be specified as a hostname, or as a numeric string representation like n.n.n.n known as the IPv4 dotted-decimal format (i.e. "192.168.10.1"). This function is used whenever an ip address needs to be set in the proper format (i.e. for the @ref tstrM2MIPConfig structure).
[in] | pcIpAddr | A null terminated string containing the IP address in IPv4 dotted-decimal address. |
|
static |
|
static |
Referenced by ble_bat_process(), and ble_bat_profile_init().
|
static |
Referenced by app_ble_wifi_provisioning(), and app_button_press_callback().
|
static |
Referenced by app_wifi_handle_event().
|
static |
Referenced by app_ble_wifi_provisioning(), and app_wifi_handle_event().
|
static |
Referenced by ble_bat_handle_timer_event(), ble_bat_process(), and ble_bat_profile_init().
|
static |
Referenced by ble_bat_start_advertise().
bool volatile timer_cb_done |