optimize code, size
This commit is contained in:
parent
8b77d51a88
commit
b6bfaea953
19 changed files with 3072 additions and 3008 deletions
5708
TestTHB2.hex
5708
TestTHB2.hex
File diff suppressed because it is too large
Load diff
|
|
@ -5,7 +5,7 @@
|
|||
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
|
||||
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
|
||||
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuildCommandParser" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser" keep-relative-paths="false" name="CDT GCC Build Output Parser" parameter="([^/\\\\]*)((g?cc)|([gc]\+\+)|(clang))" prefer-non-shared="true"/>
|
||||
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-940467565923246545" id="org.eclipse.embedcdt.managedbuild.cross.arm.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Arm Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
||||
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="150159375649064648" id="org.eclipse.embedcdt.managedbuild.cross.arm.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Arm Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
||||
<language-scope id="org.eclipse.cdt.core.gcc"/>
|
||||
<language-scope id="org.eclipse.cdt.core.g++"/>
|
||||
</provider>
|
||||
|
|
|
|||
|
|
@ -158,9 +158,9 @@ SRCS += $(SDK_PATH)/components/driver/log/my_printf.c
|
|||
#SRCS += $(SDK_PATH)/components/profiles/Roles/central.c
|
||||
#SRCS += $(SDK_PATH)/components/profiles/ota_app/ota_app_service.c
|
||||
#SRCS += $(SDK_PATH)/components/profiles/Roles/peripheral.c
|
||||
SRCS += $(SDK_PATH)/components/profiles/Roles/gap.c
|
||||
SRCS += $(SDK_PATH)/components/profiles/Roles/gapbondmgr.c
|
||||
SRCS += $(SDK_PATH)/components/profiles/Roles/gapgattserver.c
|
||||
SRCS += $(SDK_PATH)/components/profiles/Roles/gap.c
|
||||
SRCS += $(SDK_PATH)/components/profiles/GATT/gattservapp.c
|
||||
#SRCS += $(SDK_PATH)/components/profiles/DevInfo/devinfoservice.c
|
||||
|
||||
|
|
|
|||
|
|
@ -24,15 +24,6 @@ extern "C"
|
|||
/*********************************************************************
|
||||
CONSTANTS
|
||||
*/
|
||||
// Minimum connection interval (units of 1.25ms, 80=100ms) if automatic parameter update request is enabled
|
||||
#define DEFAULT_DESIRED_MIN_CONN_INTERVAL 24 // 12 -> 15 ms
|
||||
// Maximum connection interval (units of 1.25ms, 800=1000ms) if automatic parameter update request is enabled
|
||||
#define DEFAULT_DESIRED_MAX_CONN_INTERVAL 24 // 30 ms
|
||||
// Slave latency to use if automatic parameter update request is enabled
|
||||
#define DEFAULT_DESIRED_SLAVE_LATENCY 29
|
||||
// Supervision timeout value (units of 10ms, 1000=10s) if automatic parameter update request is enabled
|
||||
#define DEFAULT_DESIRED_CONN_TIMEOUT 400 // 4s
|
||||
|
||||
|
||||
#define GAP_DEVICE_NAME_LEN (20+1)
|
||||
|
||||
|
|
|
|||
|
|
@ -444,14 +444,17 @@ CHIP_ID_STATUS_e read_chip_mAddr(uint8_t * mAddr) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
#ifndef __GCC
|
||||
|
||||
chipMAddr_t g_chipMAddr;
|
||||
|
||||
void check_chip_mAddr(void) {
|
||||
//chip id check
|
||||
for (int i = 0; i < CHIP_MADDR_LEN; i++) {
|
||||
g_chipMAddr.mAddr[i] = 0xff;
|
||||
}
|
||||
g_chipMAddr.chipMAddrStatus = read_chip_mAddr();
|
||||
g_chipMAddr.chipMAddrStatus = read_chip_mAddr(g_chipMAddr.mAddr);
|
||||
}
|
||||
|
||||
void LOG_CHIP_MADDR(void) {
|
||||
|
|
@ -473,4 +476,4 @@ void LOG_CHIP_MADDR(void) {
|
|||
}
|
||||
}
|
||||
|
||||
*/
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -342,7 +342,7 @@ uint16 HidDev_ProcessEvent( uint8 task_id, uint16 events )
|
|||
uint8 bleupdateConnParams = TRUE;
|
||||
uint8 enable_update_request= TRUE;
|
||||
|
||||
if(hidDevGapState==GAPROLE_CONNECTED)
|
||||
if(hidDevGapState == GAPROLE_CONNECTED)
|
||||
{
|
||||
GAPRole_SetParameter( GAPROLE_PARAM_UPDATE_ENABLE, sizeof( uint8 ), &enable_update_request );
|
||||
GAPRole_SetParameter( GAPROLE_PARAM_UPDATE_REQ, sizeof( uint8 ), &bleupdateConnParams );
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
INCLUDES
|
||||
*/
|
||||
#include "bcomdef.h"
|
||||
#include "config.h"
|
||||
#include "OSAL.h"
|
||||
#include "gap.h"
|
||||
#include "gapgattserver.h"
|
||||
|
|
|
|||
|
|
@ -499,31 +499,11 @@
|
|||
<FileType>1</FileType>
|
||||
<FilePath>.\SDK\components\profiles\Roles\gapgattserver.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>peripheral.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>.\SDK\components\profiles\Roles\peripheral.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>gattservapp.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>.\SDK\components\profiles\GATT\gattservapp.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>ota_app_service.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>.\SDK\components\profiles\ota_app\ota_app_service.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>battservice.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>.\SDK\components\profiles\Batt\battservice.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>devinfoservice.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>.\SDK\components\profiles\DevInfo\devinfoservice.c</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
|
|
@ -594,6 +574,21 @@
|
|||
<FileType>1</FileType>
|
||||
<FilePath>.\source\osal_peripheral.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>thb2_peripheral.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>.\source\thb2_peripheral.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>devinfoservice.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>.\source\devinfoservice.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>battservice.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>.\source\battservice.c</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ LR_ROM_XIP 0x11020000 0x020000 {
|
|||
linkdb.o(+RO)
|
||||
sm*.o(+RO)
|
||||
gap*.o(+RO)
|
||||
peripheral.o(+RO)
|
||||
thb2_peripheral.o(+RO)
|
||||
;battservice.o(+RO)
|
||||
devinfoservice.o(+RO)
|
||||
thb2_main.o(+RO)
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ extern void SimpleBLEPeripheral_Init( uint8 task_id );
|
|||
/*
|
||||
* Task Event Processor for the BLE Application
|
||||
*/
|
||||
extern uint16 SimpleBLEPeripheral_ProcessEvent( uint8 task_id, uint16 events );
|
||||
extern uint16 BLEPeripheral_ProcessEvent( uint8 task_id, uint16 events );
|
||||
|
||||
/*********************************************************************
|
||||
*********************************************************************/
|
||||
|
|
|
|||
|
|
@ -8,12 +8,21 @@
|
|||
#ifndef SOURCE_CONFIG_H_
|
||||
#define SOURCE_CONFIG_H_
|
||||
|
||||
#define APP_VERSION 0x01 // BCD
|
||||
|
||||
#define APP_VERSION 0x04 // BCD
|
||||
|
||||
#define DEVICE_BTH2 1
|
||||
#define DEVICE_BTH01 2
|
||||
#define DEVICE_TH05 3
|
||||
|
||||
#ifndef DEVICE
|
||||
#define DEVICE DEVICE_BTH2
|
||||
#endif
|
||||
|
||||
#define DEF_SOFTWARE_REVISION {'V', '0'+ (APP_VERSION >> 4), '.' , '0'+ (APP_VERSION & 0x0F), 0}
|
||||
|
||||
#if DEVICE == DEVICE_BTH2
|
||||
/* Model: THB2 */
|
||||
|
||||
#define ADC_PIN GPIO_P11
|
||||
#define ADC_CHL ADC_CH1N_P11
|
||||
#define I2C_SDA GPIO_P18
|
||||
|
|
@ -25,8 +34,22 @@
|
|||
#define DEF_HARDWARE_REVISION "0001"
|
||||
#define DEF_MANUFACTURE_NAME_STR "Tuya"
|
||||
|
||||
#else
|
||||
#error "DEVICE Not released!"
|
||||
#endif
|
||||
|
||||
|
||||
// Minimum connection interval (units of 1.25ms, 80=100ms) if automatic parameter update request is enabled
|
||||
#define DEFAULT_DESIRED_MIN_CONN_INTERVAL 24 // 12 -> 15 ms
|
||||
// Maximum connection interval (units of 1.25ms, 800=1000ms) if automatic parameter update request is enabled
|
||||
#define DEFAULT_DESIRED_MAX_CONN_INTERVAL 24 // 30 ms
|
||||
// Slave latency to use if automatic parameter update request is enabled
|
||||
#define DEFAULT_DESIRED_SLAVE_LATENCY 29
|
||||
// Supervision timeout value (units of 10ms, 1000=10s) if automatic parameter update request is enabled
|
||||
#define DEFAULT_DESIRED_CONN_TIMEOUT 400 // 4s
|
||||
|
||||
|
||||
// fs ids
|
||||
#define FS_ID_MAC 0xACAD
|
||||
|
||||
#endif /* SOURCE_CONFIG_H_ */
|
||||
|
|
|
|||
|
|
@ -151,13 +151,13 @@ static uint8 devInfoSystemId[DEVINFO_SYSTEM_ID_LEN] = {0, 0, 0, 0, 0, 0, 0, 0};
|
|||
#if MODEL_NUMBER_STR_ENABLE
|
||||
// Model Number String characteristic
|
||||
static uint8 devInfoModelNumberProps = GATT_PROP_READ;
|
||||
static const uint8 devInfoModelNumber[] = DEF_MODEL_NUMBER_STR;
|
||||
const uint8 devInfoModelNumber[] = DEF_MODEL_NUMBER_STR;
|
||||
#endif
|
||||
|
||||
#if SERIAL_NUMBER_STR_ENABLE
|
||||
// Serial Number String characteristic
|
||||
static uint8 devInfoSerialNumberProps = GATT_PROP_READ;
|
||||
uint8 devInfoSerialNumber[17] = "000000-0000-0000"; // FLASH_ID-SENSOR_ID-EFUSE
|
||||
uint8 devInfoSerialNumber[17]; // = "000000-0000-0000"; // FLASH_ID-SENSOR_ID-EFUSE
|
||||
#endif
|
||||
|
||||
#if FIRMWARE_REVISION_ENABLE
|
||||
|
|
|
|||
|
|
@ -100,6 +100,7 @@ extern bStatus_t DevInfo_GetParameter( uint8 param, void* value );
|
|||
|
||||
|
||||
extern uint8 devInfoSerialNumber[17];
|
||||
extern const uint8 devInfoModelNumber[];
|
||||
/*********************************************************************
|
||||
*********************************************************************/
|
||||
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ const pTaskEventHandlerFn tasksArr[] =
|
|||
GAPBondMgr_ProcessEvent, // task , add 2017-11-15
|
||||
#endif
|
||||
GATTServApp_ProcessEvent, // task 7
|
||||
SimpleBLEPeripheral_ProcessEvent, // task 8
|
||||
BLEPeripheral_ProcessEvent, // task 8
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -91,22 +91,6 @@ uint8 simpleBLEPeripheral_TaskID; // Task ID for internal task/event processin
|
|||
|
||||
static gaprole_States_t gapProfileState = GAPROLE_INIT;
|
||||
|
||||
|
||||
/** Advertisement payload */
|
||||
static const uint8 advertData[] =
|
||||
{
|
||||
0x02, // length of this data
|
||||
GAP_ADTYPE_FLAGS,
|
||||
GAP_ADTYPE_FLAGS_GENERAL | GAP_ADTYPE_FLAGS_BREDR_NOT_SUPPORTED
|
||||
};
|
||||
|
||||
// GAP GATT Attributes
|
||||
static uint8 attDeviceName[] = "THB2-000000"; // GAP_DEVICE_NAME_LEN
|
||||
|
||||
// GAP - SCAN RSP data (max size = 31 bytes)
|
||||
static uint8 scanRspData[GAP_DEVICE_NAME_LEN + 2];
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
* LOCAL FUNCTIONS
|
||||
*/
|
||||
|
|
@ -124,26 +108,36 @@ uint8_t * str_bin2hex(uint8_t *d, uint8_t *s, int len) {
|
|||
return d;
|
||||
}
|
||||
|
||||
// GAP - SCAN RSP data (max size = 31 bytes)
|
||||
static void set_def_name(uint8_t * mac)
|
||||
{
|
||||
uint8 * p = gapRole_ScanRspData;
|
||||
gapRole_ScanRspDataLen = sizeof(DEF_MODEL_NUMBER_STR) + 8;
|
||||
*p++ = sizeof(DEF_MODEL_NUMBER_STR) + 7;
|
||||
*p++ = GAP_ADTYPE_LOCAL_NAME_COMPLETE;
|
||||
osal_memcpy(p, devInfoModelNumber, sizeof(DEF_MODEL_NUMBER_STR)-1);
|
||||
p += sizeof(DEF_MODEL_NUMBER_STR) - 1;
|
||||
*p++ = '-';
|
||||
p = str_bin2hex(p, mac+2, 1);
|
||||
p = str_bin2hex(p, mac+1, 1);
|
||||
str_bin2hex(p, mac, 1);
|
||||
}
|
||||
|
||||
static void set_mac(void)
|
||||
{
|
||||
extern uint8 ownPublicAddr[LL_DEVICE_ADDR_LEN];
|
||||
uint8 * p = &attDeviceName[5];
|
||||
if (read_chip_mAddr(ownPublicAddr) != CHIP_ID_VALID) {
|
||||
uint16 len;
|
||||
if(hal_fs_item_read(FS_ID_MAC, ownPublicAddr, LL_DEVICE_ADDR_LEN, &len) != PPlus_SUCCESS) {
|
||||
LL_Rand(ownPublicAddr,3);
|
||||
ownPublicAddr[3] = 0x8d;
|
||||
ownPublicAddr[4] = 0x1f;
|
||||
ownPublicAddr[5] = 0x38;
|
||||
hal_fs_item_write(0xACAD, ownPublicAddr, LL_DEVICE_ADDR_LEN);
|
||||
}
|
||||
extern uint8 ownPublicAddr[LL_DEVICE_ADDR_LEN];
|
||||
uint16 len;
|
||||
if (read_chip_mAddr(ownPublicAddr) != CHIP_ID_VALID) {
|
||||
if(hal_fs_item_read(FS_ID_MAC, ownPublicAddr, LL_DEVICE_ADDR_LEN, &len) != PPlus_SUCCESS) {
|
||||
LL_Rand(ownPublicAddr,3);
|
||||
// Tuya mac[0:3]
|
||||
ownPublicAddr[3] = 0x8d;
|
||||
ownPublicAddr[4] = 0x1f;
|
||||
ownPublicAddr[5] = 0x38;
|
||||
hal_fs_item_write(0xACAD, ownPublicAddr, LL_DEVICE_ADDR_LEN);
|
||||
}
|
||||
p = str_bin2hex(p, &ownPublicAddr[2], 1);
|
||||
p = str_bin2hex(p, &ownPublicAddr[1], 1);
|
||||
str_bin2hex(p, &ownPublicAddr[0], 1);
|
||||
scanRspData[0] = sizeof(attDeviceName) + 1;
|
||||
scanRspData[1] = GAP_ADTYPE_LOCAL_NAME_COMPLETE;
|
||||
osal_memcpy(&scanRspData[2], attDeviceName, sizeof(attDeviceName));
|
||||
}
|
||||
set_def_name(ownPublicAddr);
|
||||
}
|
||||
|
||||
typedef enum
|
||||
|
|
@ -169,43 +163,34 @@ static void set_serial_number(void)
|
|||
p = str_bin2hex(p, (uint8_t *)&temp_rd[0], 2);
|
||||
}
|
||||
|
||||
/*
|
||||
extern uint8 gapRole_AdvEnabled;
|
||||
extern uint8 gapRole_AdvertData[B_MAX_ADV_LEN];
|
||||
extern uint8 gapRole_AdvDirectAddr[B_ADDR_LEN];
|
||||
extern uint8 gapRole_AdvEventType;
|
||||
extern uint8 gapRole_AdvDirectType;
|
||||
extern uint8 gapRole_AdvChanMap;
|
||||
extern uint8 gapRole_AdvFilterPolicy;
|
||||
extern uint8 gapRole_TaskID;
|
||||
extern gaprole_States_t gapRole_state;
|
||||
#ifndef START_ADVERTISING_EVT
|
||||
#define START_ADVERTISING_EVT 1
|
||||
#endif
|
||||
*/
|
||||
|
||||
extern gapPeriConnectParams_t periConnParameters;
|
||||
extern uint16 gapParameters[];
|
||||
static void set_adv_interval(uint16 advInt);
|
||||
|
||||
// Set new advertising interval
|
||||
static void set_adv_interval(uint16 advInt)
|
||||
static void set_new_adv_interval(uint16 advInt)
|
||||
{
|
||||
#if 0
|
||||
GAP_SetParamValue( TGAP_LIM_DISC_ADV_INT_MIN, advInt );
|
||||
GAP_SetParamValue( TGAP_LIM_DISC_ADV_INT_MAX, advInt );
|
||||
GAP_SetParamValue( TGAP_GEN_DISC_ADV_INT_MIN, advInt );
|
||||
GAP_SetParamValue( TGAP_GEN_DISC_ADV_INT_MAX, advInt );
|
||||
#else
|
||||
gapParameters[TGAP_LIM_DISC_ADV_INT_MIN] = advInt;
|
||||
gapParameters[TGAP_LIM_DISC_ADV_INT_MAX] = advInt;
|
||||
gapParameters[TGAP_GEN_DISC_ADV_INT_MIN] = advInt;
|
||||
gapParameters[TGAP_GEN_DISC_ADV_INT_MAX] = advInt;
|
||||
#endif
|
||||
set_adv_interval(advInt);
|
||||
GAP_EndDiscoverable( gapRole_TaskID );
|
||||
gapRole_state = GAPROLE_WAITING_AFTER_TIMEOUT;
|
||||
// Turn advertising back on.
|
||||
osal_set_event( gapRole_TaskID, START_ADVERTISING_EVT );
|
||||
}
|
||||
// Set advertising interval
|
||||
static void set_adv_interval(uint16 advInt)
|
||||
{
|
||||
#ifdef __GCC
|
||||
gapParameters[TGAP_LIM_DISC_ADV_INT_MIN] = advInt;
|
||||
gapParameters[TGAP_LIM_DISC_ADV_INT_MAX] = advInt;
|
||||
gapParameters[TGAP_GEN_DISC_ADV_INT_MIN] = advInt;
|
||||
gapParameters[TGAP_GEN_DISC_ADV_INT_MAX] = advInt;
|
||||
#else
|
||||
GAP_SetParamValue( TGAP_LIM_DISC_ADV_INT_MIN, advInt );
|
||||
GAP_SetParamValue( TGAP_LIM_DISC_ADV_INT_MAX, advInt );
|
||||
GAP_SetParamValue( TGAP_GEN_DISC_ADV_INT_MIN, advInt );
|
||||
GAP_SetParamValue( TGAP_GEN_DISC_ADV_INT_MAX, advInt );
|
||||
#endif
|
||||
}
|
||||
|
||||
static void adv_measure(void) {
|
||||
if(gapRole_AdvEnabled) {
|
||||
|
|
@ -215,7 +200,7 @@ static void adv_measure(void) {
|
|||
LL_SetAdvData(sizeof(adv_bthome_ns1_t), gapRole_AdvertData);
|
||||
if(adv_con_count) {
|
||||
if(--adv_con_count == 0) {
|
||||
set_adv_interval(DEF_ADV_INERVAL);
|
||||
set_new_adv_interval(DEF_ADV_INERVAL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -239,7 +224,7 @@ static void posedge_int_wakeup_cb(GPIO_Pin_e pin, IO_Wakeup_Pol_e type)
|
|||
LOG("int or wakeup(pos):gpio:%d type:%d\n",pin,type);
|
||||
hal_gpio_write(GPIO_LED,1);
|
||||
if(gapRole_AdvEnabled) {
|
||||
set_adv_interval(DEF_CON_ADV_INERVAL); // actual time = advInt * 625us
|
||||
set_new_adv_interval(DEF_CON_ADV_INERVAL); // actual time = advInt * 625us
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
@ -269,6 +254,36 @@ void init_led_key(void)
|
|||
hal_gpio_write(GPIO_LED, 1);
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* GAPROLE ADVERTISING
|
||||
*/
|
||||
void gatrole_advert_enable(bool enable) {
|
||||
uint8 oldAdvEnabled = gapRole_AdvEnabled;
|
||||
gapRole_AdvEnabled = enable;
|
||||
|
||||
if ( (oldAdvEnabled) && (gapRole_AdvEnabled == FALSE) )
|
||||
{
|
||||
// Turn off Advertising
|
||||
if ( ( gapRole_state == GAPROLE_ADVERTISING )
|
||||
|| ( gapRole_state == GAPROLE_CONNECTED_ADV )
|
||||
|| ( gapRole_state == GAPROLE_WAITING_AFTER_TIMEOUT ) )
|
||||
{
|
||||
GAP_EndDiscoverable( gapRole_TaskID );
|
||||
}
|
||||
}
|
||||
else if ( (oldAdvEnabled == FALSE) && (gapRole_AdvEnabled) )
|
||||
{
|
||||
// Turn on Advertising
|
||||
if ( (gapRole_state == GAPROLE_STARTED)
|
||||
|| (gapRole_state == GAPROLE_WAITING)
|
||||
|| (gapRole_state == GAPROLE_CONNECTED)
|
||||
|| (gapRole_state == GAPROLE_WAITING_AFTER_TIMEOUT) )
|
||||
{
|
||||
osal_set_event( gapRole_TaskID, START_ADVERTISING_EVT );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* PROFILE CALLBACKS
|
||||
*/
|
||||
|
|
@ -298,7 +313,6 @@ simpleProfileCBs_t simpleBLEPeripheral_SimpleProfileCBs =
|
|||
/*********************************************************************
|
||||
* PUBLIC FUNCTIONS
|
||||
*/
|
||||
extern gapPeriConnectParams_t periConnParameters;
|
||||
/*********************************************************************
|
||||
* @fn SimpleBLEPeripheral_Init
|
||||
*
|
||||
|
|
@ -324,69 +338,42 @@ void SimpleBLEPeripheral_Init( uint8 task_id )
|
|||
set_serial_number();
|
||||
|
||||
// Setup the GAP
|
||||
#if 0
|
||||
GAP_SetParamValue( TGAP_CONN_PAUSE_PERIPHERAL, DEFAULT_CONN_PAUSE_PERIPHERAL );
|
||||
#else
|
||||
#ifdef __GCC
|
||||
gapParameters[TGAP_CONN_PAUSE_PERIPHERAL] = DEFAULT_CONN_PAUSE_PERIPHERAL;
|
||||
#else
|
||||
GAP_SetParamValue( TGAP_CONN_PAUSE_PERIPHERAL, DEFAULT_CONN_PAUSE_PERIPHERAL );
|
||||
#endif
|
||||
|
||||
// Setup the GAP Peripheral Role Profile
|
||||
{
|
||||
// device starts advertising upon initialization
|
||||
uint8 initial_advertising_enable = FALSE;
|
||||
|
||||
uint8 enable_update_request = DEFAULT_ENABLE_UPDATE_REQUEST;
|
||||
uint8 advChnMap = GAP_ADVCHAN_37 | GAP_ADVCHAN_38 | GAP_ADVCHAN_39;
|
||||
|
||||
// By setting this to zero, the device will go into the waiting state after
|
||||
// being discoverable for 30.72 second, and will not being advertising again
|
||||
// until the enabler is set back to TRUE
|
||||
uint16 gapRole_AdvertOffTime = 0;
|
||||
|
||||
uint8 peerPublicAddr[] = {
|
||||
0x01,
|
||||
0x02,
|
||||
0x03,
|
||||
0x04,
|
||||
0x05,
|
||||
0x06
|
||||
};
|
||||
set_mac();
|
||||
uint8 advType = LL_ADV_CONNECTABLE_UNDIRECTED_EVT;
|
||||
GAPRole_SetParameter( GAPROLE_ADV_EVENT_TYPE, sizeof( uint8 ), &advType );
|
||||
GAPRole_SetParameter( GAPROLE_ADV_DIRECT_ADDR, sizeof(peerPublicAddr), peerPublicAddr);
|
||||
// set adv channel map
|
||||
GAPRole_SetParameter( GAPROLE_ADV_CHANNEL_MAP, sizeof( uint8 ), &advChnMap);
|
||||
// gapRole_AdvEventType = LL_ADV_CONNECTABLE_UNDIRECTED_EVT; // already set default
|
||||
// gapRole_AdvDirectAddr[B_ADDR_LEN] = {1,2,3,4,5,6}; // already set default
|
||||
// gapRole_AdvChanMap = GAP_ADVCHAN_37 | GAP_ADVCHAN_38 | GAP_ADVCHAN_39; // already set default
|
||||
// Set the GAP Role Parameters
|
||||
GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &initial_advertising_enable );
|
||||
GAPRole_SetParameter( GAPROLE_ADVERT_OFF_TIME, sizeof( uint16 ), &gapRole_AdvertOffTime );
|
||||
GAPRole_SetParameter( GAPROLE_ADVERT_DATA, sizeof(advertData), (void *)advertData); // advertData
|
||||
GAPRole_SetParameter( GAPROLE_SCAN_RSP_DATA, scanRspData[0] + 1, scanRspData );
|
||||
GAPRole_SetParameter( GAPROLE_PARAM_UPDATE_ENABLE, sizeof( uint8 ), &enable_update_request);
|
||||
GAPRole_SetParameter( GAPROLE_MIN_CONN_INTERVAL, sizeof( uint16 ), &periConnParameters.intervalMin);
|
||||
GAPRole_SetParameter( GAPROLE_MAX_CONN_INTERVAL, sizeof( uint16 ), &periConnParameters.intervalMax );
|
||||
GAPRole_SetParameter( GAPROLE_SLAVE_LATENCY, sizeof( uint16 ), &periConnParameters.latency );
|
||||
GAPRole_SetParameter( GAPROLE_TIMEOUT_MULTIPLIER, sizeof( uint16 ), &periConnParameters.timeout );
|
||||
// device starts advertising upon initialization
|
||||
gatrole_advert_enable(FALSE);
|
||||
// gapRole_AdvertOffTime = 0; // already set default
|
||||
GAP_UpdateAdvertisingData( gapRole_TaskID, TRUE, gapRole_AdvertDataLen, gapRole_AdvertData );
|
||||
GAP_UpdateAdvertisingData( gapRole_TaskID, FALSE, gapRole_ScanRspDataLen, gapRole_ScanRspData );
|
||||
gapRole_ParamUpdateEnable = DEFAULT_ENABLE_UPDATE_REQUEST;
|
||||
|
||||
/* already set default
|
||||
// extern gapPeriConnectParams_t periConnParameters;
|
||||
gapRole_MinConnInterval = periConnParameters.intervalMin;
|
||||
gapRole_MaxConnInterval = periConnParameters.intervalMax;
|
||||
gapRole_SlaveLatency = periConnParameters.latency;
|
||||
gapRole_TimeoutMultiplier = periConnParameters.timeout;
|
||||
*/
|
||||
}
|
||||
|
||||
// Set the GAP Characteristics
|
||||
GGS_SetParameter( GGS_DEVICE_NAME_ATT, sizeof(attDeviceName), (void *)attDeviceName ); // GAP_DEVICE_NAME_LEN, attDeviceName );
|
||||
GGS_SetParameter( GGS_DEVICE_NAME_ATT, gapRole_ScanRspData[0] - 1, (void *)&gapRole_ScanRspData[2] ); // GAP_DEVICE_NAME_LEN, attDeviceName );
|
||||
|
||||
// Set advertising interval
|
||||
{
|
||||
uint16 advInt = DEF_ADV_INERVAL; // actual time = advInt * 625us
|
||||
#if 0
|
||||
GAP_SetParamValue( TGAP_LIM_DISC_ADV_INT_MIN, advInt );
|
||||
GAP_SetParamValue( TGAP_LIM_DISC_ADV_INT_MAX, advInt );
|
||||
GAP_SetParamValue( TGAP_GEN_DISC_ADV_INT_MIN, advInt );
|
||||
GAP_SetParamValue( TGAP_GEN_DISC_ADV_INT_MAX, advInt );
|
||||
#else
|
||||
gapParameters[TGAP_LIM_DISC_ADV_INT_MIN] = advInt;
|
||||
gapParameters[TGAP_LIM_DISC_ADV_INT_MAX] = advInt;
|
||||
gapParameters[TGAP_GEN_DISC_ADV_INT_MIN] = advInt;
|
||||
gapParameters[TGAP_GEN_DISC_ADV_INT_MAX] = advInt;
|
||||
#endif
|
||||
}
|
||||
set_adv_interval(DEF_ADV_INERVAL); // actual time = advInt * 625us
|
||||
|
||||
HCI_PPLUS_AdvEventDoneNoticeCmd(simpleBLEPeripheral_TaskID, ADV_BROADCAST_EVT);
|
||||
#if (DEF_GAPBOND_MGR_ENABLE==1)
|
||||
// Setup the GAP Bond Manager, add 2017-11-15
|
||||
|
|
@ -441,7 +428,7 @@ void SimpleBLEPeripheral_Init( uint8 task_id )
|
|||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn SimpleBLEPeripheral_ProcessEvent
|
||||
* @fn BLEPeripheral_ProcessEvent
|
||||
*
|
||||
* @brief Simple BLE Peripheral Application Task event processor. This function
|
||||
* is called to process all events for the task. Events
|
||||
|
|
@ -453,7 +440,7 @@ void SimpleBLEPeripheral_Init( uint8 task_id )
|
|||
*
|
||||
* @return events not processed
|
||||
*/
|
||||
uint16 SimpleBLEPeripheral_ProcessEvent( uint8 task_id, uint16 events )
|
||||
uint16 BLEPeripheral_ProcessEvent( uint8 task_id, uint16 events )
|
||||
{
|
||||
VOID task_id; // OSAL required parameter that isn't used in this function
|
||||
if ( events & ADV_BROADCAST_EVT)
|
||||
|
|
@ -485,9 +472,8 @@ uint16 SimpleBLEPeripheral_ProcessEvent( uint8 task_id, uint16 events )
|
|||
LOG("SBP_RESET_ADV_EVT\n");
|
||||
adv_count = 0;
|
||||
//adv_con_count = 1;
|
||||
// set_adv_interval(DEF_ADV_INERVAL); // actual time = advInt * 625us
|
||||
uint8 initial_advertising_enable = TRUE;
|
||||
GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &initial_advertising_enable );
|
||||
// set_new_adv_interval(DEF_ADV_INERVAL); // actual time = advInt * 625us
|
||||
gatrole_advert_enable(TRUE);
|
||||
return ( events ^ SBP_RESET_ADV_EVT );
|
||||
}
|
||||
if( events & TIMER_BATT_EVT)
|
||||
|
|
@ -615,7 +601,8 @@ static void peripheralStateReadRssiCB( int8 rssi )
|
|||
|
||||
case GAPROLE_CONNECTED:
|
||||
adv_con_count = 0;
|
||||
osal_start_reload_timer(simpleBLEPeripheral_TaskID, TIMER_BATT_EVT, 2*DEF_ADV_INERVAL_MS);
|
||||
//osal_start_timerEx(simpleBLEPeripheral_TaskID, TIMER_BATT_EVT, 1000000);
|
||||
osal_start_reload_timer(simpleBLEPeripheral_TaskID, TIMER_BATT_EVT, 10000); // 2*DEF_ADV_INERVAL_MS); // 5000 ms
|
||||
HCI_PPLUS_ConnEventDoneNoticeCmd(simpleBLEPeripheral_TaskID, NULL);
|
||||
LOG("Gaprole_Connected\n");
|
||||
break;
|
||||
|
|
@ -642,7 +629,7 @@ static void peripheralStateReadRssiCB( int8 rssi )
|
|||
break;
|
||||
}
|
||||
gapProfileState = newState;
|
||||
LOG("[GAP ROLE %d]\n",newState);
|
||||
LOG("[GAP ROLE %d]\n",newState);
|
||||
|
||||
VOID gapProfileState;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
INCLUDES
|
||||
*/
|
||||
#include "bcomdef.h"
|
||||
#include "config.h"
|
||||
#include "OSAL.h"
|
||||
#include "hci_tl.h"
|
||||
#include "l2cap.h"
|
||||
|
|
@ -92,7 +93,7 @@ static uint32 gapRole_signCounter;
|
|||
static uint8 gapRole_bdAddr[B_ADDR_LEN];
|
||||
uint8 gapRole_AdvEnabled = FALSE;
|
||||
|
||||
static uint16 gapRole_AdvertOffTime = DEFAULT_ADVERT_OFF_TIME;
|
||||
uint16 gapRole_AdvertOffTime = 0; // DEFAULT_ADVERT_OFF_TIME;
|
||||
uint8 gapRole_AdvertDataLen = 3;
|
||||
uint8 gapRole_AdvertData[B_MAX_ADV_LEN] =
|
||||
{
|
||||
|
|
@ -102,27 +103,28 @@ uint8 gapRole_AdvertData[B_MAX_ADV_LEN] =
|
|||
(GAP_ADTYPE_FLAGS_GENERAL | GAP_ADTYPE_FLAGS_BREDR_NOT_SUPPORTED),
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
||||
};
|
||||
static uint8 gapRole_ScanRspDataLen = 0;
|
||||
static uint8 gapRole_ScanRspData[B_MAX_ADV_LEN] = {0};
|
||||
uint8 gapRole_AdvEventType;
|
||||
uint8 gapRole_ScanRspDataLen = 0;
|
||||
uint8 gapRole_ScanRspData[B_MAX_ADV_LEN] = {0};
|
||||
uint8 gapRole_AdvEventType = LL_ADV_CONNECTABLE_UNDIRECTED_EVT;
|
||||
uint8 gapRole_AdvDirectType;
|
||||
uint8 gapRole_AdvDirectAddr[B_ADDR_LEN] = {0};
|
||||
uint8 gapRole_AdvChanMap;
|
||||
uint8 gapRole_AdvDirectAddr[B_ADDR_LEN] = {1,2,3,4,5,6};
|
||||
uint8 gapRole_AdvChanMap = GAP_ADVCHAN_37 | GAP_ADVCHAN_38 | GAP_ADVCHAN_39;
|
||||
uint8 gapRole_AdvFilterPolicy;
|
||||
|
||||
static uint16 gapRole_ConnectionHandle = INVALID_CONNHANDLE;
|
||||
static uint16 gapRole_ConnectionInterval = 0;
|
||||
static uint16 gapRole_ConnectionLatency = 0;
|
||||
uint16 gapRole_ConnectionHandle = INVALID_CONNHANDLE;
|
||||
uint16 gapRole_ConnectionInterval = 0;
|
||||
uint16 gapRole_ConnectionLatency = 0;
|
||||
|
||||
static uint16 gapRole_RSSIReadRate = 0;
|
||||
|
||||
static uint8 gapRole_ConnectedDevAddr[B_ADDR_LEN] = {0};
|
||||
|
||||
static uint8 gapRole_ParamUpdateEnable = FALSE;
|
||||
static uint16 gapRole_MinConnInterval = DEFAULT_MIN_CONN_INTERVAL;
|
||||
static uint16 gapRole_MaxConnInterval = DEFAULT_MAX_CONN_INTERVAL;
|
||||
static uint16 gapRole_SlaveLatency = MIN_SLAVE_LATENCY;
|
||||
static uint16 gapRole_TimeoutMultiplier = DEFAULT_TIMEOUT_MULTIPLIER;
|
||||
uint8 gapRole_ParamUpdateEnable = FALSE;
|
||||
|
||||
uint16 gapRole_MinConnInterval = DEFAULT_DESIRED_MIN_CONN_INTERVAL; // DEFAULT_MIN_CONN_INTERVAL;
|
||||
uint16 gapRole_MaxConnInterval = DEFAULT_DESIRED_MAX_CONN_INTERVAL; // DEFAULT_MAX_CONN_INTERVAL;
|
||||
uint16 gapRole_SlaveLatency = DEFAULT_DESIRED_SLAVE_LATENCY; // MIN_SLAVE_LATENCY;
|
||||
uint16 gapRole_TimeoutMultiplier = DEFAULT_DESIRED_CONN_TIMEOUT; // DEFAULT_TIMEOUT_MULTIPLIER;
|
||||
|
||||
static uint16 gapRole_ConnInterval = 0;
|
||||
static uint16 gapRole_ConnSlaveLatency = 0;
|
||||
|
|
@ -180,7 +182,7 @@ static void gapRole_startConnUpdate( uint8 handleFailure );
|
|||
/*********************************************************************
|
||||
PUBLIC FUNCTIONS
|
||||
*/
|
||||
|
||||
#if 0
|
||||
/*********************************************************************
|
||||
@brief Set a GAP Role parameter.
|
||||
|
||||
|
|
@ -262,7 +264,6 @@ bStatus_t GAPRole_SetParameter( uint16 param, uint8 len, void* pValue )
|
|||
}
|
||||
|
||||
break;
|
||||
|
||||
case GAPROLE_ADVERT_OFF_TIME:
|
||||
if ( len == sizeof ( uint16 ) )
|
||||
{
|
||||
|
|
@ -650,6 +651,7 @@ bStatus_t GAPRole_GetParameter( uint16 param, void* pValue )
|
|||
|
||||
return ( ret );
|
||||
}
|
||||
#endif
|
||||
|
||||
/*********************************************************************
|
||||
@brief Does the device initialization.
|
||||
|
|
|
|||
|
|
@ -312,8 +312,12 @@ extern bStatus_t GAPRole_extAdv_GetParameter( uint8 adv_handler, uint16 param, v
|
|||
#define START_CONN_UPDATE_EVT 0x0004 // Start Connection Update Procedure
|
||||
#define CONN_PARAM_TIMEOUT_EVT 0x0008 // Connection Parameters Update Timeout
|
||||
|
||||
extern uint16 gapRole_AdvertOffTime;
|
||||
extern uint8 gapRole_AdvEnabled;
|
||||
extern uint8 gapRole_AdvertDataLen;
|
||||
extern uint8 gapRole_AdvertData[B_MAX_ADV_LEN];
|
||||
extern uint8 gapRole_ScanRspDataLen;
|
||||
extern uint8 gapRole_ScanRspData[B_MAX_ADV_LEN];
|
||||
extern uint8 gapRole_AdvDirectAddr[B_ADDR_LEN];
|
||||
extern uint8 gapRole_AdvEventType;
|
||||
extern uint8 gapRole_AdvDirectType;
|
||||
|
|
@ -321,6 +325,11 @@ extern uint8 gapRole_AdvChanMap;
|
|||
extern uint8 gapRole_AdvFilterPolicy;
|
||||
extern uint8 gapRole_TaskID;
|
||||
extern gaprole_States_t gapRole_state;
|
||||
extern uint8 gapRole_ParamUpdateEnable;
|
||||
extern uint16 gapRole_MinConnInterval;
|
||||
extern uint16 gapRole_MaxConnInterval;
|
||||
extern uint16 gapRole_SlaveLatency;
|
||||
extern uint16 gapRole_TimeoutMultiplier;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
|||
|
|
@ -242,7 +242,7 @@ static uint8 thReadAttrCB( uint16 connHandle, gattAttribute_t* pAttr,
|
|||
// Measure temp level if reading level
|
||||
if ( uuid == TEMPERATYRE_UUID )
|
||||
{
|
||||
*pLen = 2;
|
||||
*pLen = 2;
|
||||
pValue[0] = measured_data.temp;
|
||||
pValue[1] = measured_data.temp >> 8;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
python3 rdwr_phy62x2.py -p COM11 -b 1000000 -w 0x20000 -r -e wh .\build\bthome_phy6222.hex
|
||||
python3 rdwr_phy62x2.py -p COM11 -b 1000000 -r -e wh .\build\bthome_phy6222.hex
|
||||
Loading…
Add table
Add a link
Reference in a new issue