Microchip® Advanced Software Framework

trans_service_app.c File Reference

BLE Transparent Service Application Implementations.

Copyright (c) 2020-2021 Microchip Technology Inc. and its subsidiaries.

#include "trans_service_app.h"
#include "ble_manager.h"
#include "trans_service.h"
#include "common/include/nm_common.h"
#include "sio2host.h"
#include <asf.h>
#include "driver/include/m2m_periph.h"
#include "driver/include/m2m_wifi.h"
#include "m2m_ble.h"
#include "at_ble_api.h"
#include "wifi_prov.h"

Macros

#define ADV_DATA_LEN   (28)
 ADV_DATA_LEN. More...
 
#define ADV_TYPE_LEN   (0x01)
 ADV_TYPE_LEN. More...
 
#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_TRANS_ADV_TIMEOUT   (1000)
 APP_TRANS_ADV_TIMEOUT Advertising time-out between 0x0001 and 0x3FFF in seconds, 0x0000 disables time-out. More...
 
#define APP_TRANS_FAST_ADV   (100)
 APP_TRANS_FAST_ADV between 0x0020 and 0x4000 in 0.625 ms units (20ms to 10.24s). More...
 
#define APP_WIFI_PROV_DISPLAY_NAME   ("3400 DEMO")
 
#define HEX2ASCII(x)   (((x)>=10)? (((x)-10)+'A') : ((x)+'0'))
 
#define SCAN_RESP_LEN   (12)
 scan_resp_len is the length of the scan response data More...
 
#define STRING_HEADER
 
#define TRANS_ADV_DATA_NAME_DATA   ("uC-TRANS")
 
#define TRANS_ADV_DATA_NAME_LEN   (8)
 TRANS_ADV_DATA_NAME_LEN the length of the device name. More...
 
#define TRANS_ADV_DATA_NAME_TYPE   (0x09)
 TRANS_ADV_DATA_NAME_TYPE the gap ad data type. More...
 
#define TRANS_ADV_DATA_UUID_LEN   (16)
 TRANS_ADV_DATA_UUID_LEN the size of TRANS service uuid. More...
 
#define TRANS_ADV_DATA_UUID_TYPE   (0x07)
 TRANS_ADV_DATA_UUID_TYPE the total sizeof TRANS service uuid. More...
 

Functions

static
at_ble_event_parameter_t
gu8BleParam 
__aligned (4)
 
static void app_ble_trans_service (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 at_ble_status_t ble_trans_char_changed_event (at_ble_characteristic_changed_t *char_changed)
 function to check the client characteristic configuration value. More...
 
static at_ble_status_t ble_trans_service_advertise (void)
 
static void ble_trans_service_handle_disconnect_event (at_ble_handle_t conn_handle)
 
void ble_trans_service_init (void)
 
void ble_trans_service_process_event (at_ble_events_t event, at_ble_event_parameter_t *params)
 
static void ble_trans_service_profile_init (void)
 
void ble_trans_service_send_buf (void)
 
at_ble_status_t ble_trans_update_value_on_btnpress (uint8_t *trans_tx_value, uint8_t len)
 
static void led_init (void)
 
int main (void)
 
uint32 nmi_inet_addr (char *pcIpAddr)
 

Variables

uint8_t enable_credit_based_fc
 
static volatile uint8 gu8BtnEvent
 
static uint8 gu8ScanIndex
 
static volatile uint8 gu8WiFiConnectionState = M2M_WIFI_DISCONNECTED
 
static const uint8_t SCAN_RESP_DATA [SCAN_RESP_LEN] = {0x0b,0x08, 'M', 'C', 'H', 'P', '-', 'T', 'R', 'A', 'N', 'S'}
 
uint8_t send_data [APP_TX_BUF_SIZE]
 
uint16_t send_length = 0
 
uint8_t trans_ctrl_notification_flag
 
static gatt_service_handler_t trans_service_handler
 
at_ble_uuid_t trans_service_uuid
 
uint8_t trans_tx_notification_flag
 

#define ADV_DATA_LEN   (28)

ADV_DATA_LEN.

#define ADV_TYPE_LEN   (0x01)

ADV_TYPE_LEN.

Referenced by ble_trans_service_advertise().

#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_TRANS_ADV_TIMEOUT   (1000)

APP_TRANS_ADV_TIMEOUT Advertising time-out between 0x0001 and 0x3FFF in seconds, 0x0000 disables time-out.

Referenced by ble_trans_service_advertise().

#define APP_TRANS_FAST_ADV   (100)

APP_TRANS_FAST_ADV between 0x0020 and 0x4000 in 0.625 ms units (20ms to 10.24s).

Referenced by ble_trans_service_advertise().

#define APP_WIFI_PROV_DISPLAY_NAME   ("3400 DEMO")
#define HEX2ASCII (   x)    (((x)>=10)? (((x)-10)+'A') : ((x)+'0'))

Referenced by app_wifi_init().

#define SCAN_RESP_LEN   (12)

scan_resp_len is the length of the scan response data

Referenced by ble_trans_service_advertise().

#define STRING_HEADER
Value:
"-- Wifi BLE demo with Transparent Service--\r\n" \
"-- "BOARD_NAME" --\r\n" \
"-- Compiled: "__DATE__" "__TIME__" --\r\n"
#define BOARD_NAME
Name string macro.
Definition: samd21_xplained_pro.h:65

Referenced by main().

#define TRANS_ADV_DATA_NAME_DATA   ("uC-TRANS")
#define TRANS_ADV_DATA_NAME_LEN   (8)

TRANS_ADV_DATA_NAME_LEN the length of the device name.

Referenced by ble_trans_service_advertise().

#define TRANS_ADV_DATA_NAME_TYPE   (0x09)

TRANS_ADV_DATA_NAME_TYPE the gap ad data type.

Referenced by ble_trans_service_advertise().

#define TRANS_ADV_DATA_UUID_LEN   (16)

TRANS_ADV_DATA_UUID_LEN the size of TRANS service uuid.

Referenced by ble_trans_service_advertise().

#define TRANS_ADV_DATA_UUID_TYPE   (0x07)

TRANS_ADV_DATA_UUID_TYPE the total sizeof TRANS service uuid.

Referenced by ble_trans_service_advertise().

static at_ble_event_parameter_t gu8BleParam __aligned ( )
static
static void app_ble_trans_service ( void  )
static
static void app_button_press_callback ( uint8  btn,
uint8  press 
)
static
static void app_main ( void  )
static
static void ble_trans_service_handle_disconnect_event ( at_ble_handle_t  conn_handle)
static
void ble_trans_service_init ( void  )
void ble_trans_service_process_event ( at_ble_events_t  event,
at_ble_event_parameter_t params 
)
at_ble_status_t ble_trans_update_value_on_btnpress ( uint8_t *  trans_tx_value,
uint8_t  len 
)
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).
Parameters
[in]pcIpAddrA null terminated string containing the IP address in IPv4 dotted-decimal address.
Returns
Unsigned 32-bit integer representing the IP address in Network byte order (eg. "192.168.10.1" will be expressed as 0x010AA8C0).

uint8_t enable_credit_based_fc
volatile uint8 gu8BtnEvent
static
uint8 gu8ScanIndex
static

Referenced by app_wifi_handle_event().

volatile uint8 gu8WiFiConnectionState = M2M_WIFI_DISCONNECTED
static

Referenced by app_wifi_handle_event().

const uint8_t SCAN_RESP_DATA[SCAN_RESP_LEN] = {0x0b,0x08, 'M', 'C', 'H', 'P', '-', 'T', 'R', 'A', 'N', 'S'}
static
uint8_t send_data[APP_TX_BUF_SIZE]
uint16_t send_length = 0
uint8_t trans_ctrl_notification_flag
gatt_service_handler_t trans_service_handler
static
at_ble_uuid_t trans_service_uuid
uint8_t trans_tx_notification_flag