#if (OTA_SERVICE_ENABLE)
#undef TELINK_OTA_UUID_SERVICE
#define TELINK_OTA_UUID_SERVICE 0x12,0x19,0x0d,0x0c,0x0b,0x0a,0x09,0x08,0x07,0x06,0x05,0x04,0x03,0x02,0x01,0x00
// OTA attribute values
static const u8 my_OtaCharVal[19] = {
CHAR_PROP_READ | CHAR_PROP_WRITE_WITHOUT_RSP,
U16_LO(OTA_CMD_OUT_DP_H), U16_HI(OTA_CMD_OUT_DP_H),
TELINK_SPP_DATA_OTA
};
const u8 my_OtaServiceUUID[16] = {TELINK_OTA_UUID_SERVICE};
const u8 my_OtaUUID[16] = {TELINK_SPP_DATA_OTA};
const u8 my_OtaName[] = {'O', 'T', 'A'};
u8 my_OtaData = 0x00;
extern u32 blt_ota_start_tick;
int pre_otaWrite(void * p) {
blt_ota_start_tick = clock_time() | 1;
return otaWrite(p);
}
void __attribute__((weak)) show_ota_result(int result) {
}
void __attribute__((weak)) entry_ota_mode(void) {
bls_ota_setTimeout(100 * 1000000); // set OTA timeout 100 S
}
#endif // #if (OTA_SERVICE_ENABLE)
#if (BATT_SERVICE_ENABLE)
//////////////////////// Battery /////////////////////////////////////////////////
//// Battery attribute values
static const u8 my_batCharVal[5] = {
CHAR_PROP_READ | CHAR_PROP_NOTIFY,
U16_LO(BATT_LEVEL_INPUT_DP_H), U16_HI(BATT_LEVEL_INPUT_DP_H),
U16_LO(CHARACTERISTIC_UUID_BATTERY_LEVEL), U16_HI(CHARACTERISTIC_UUID_BATTERY_LEVEL)
};
const u16 my_batServiceUUID = SERVICE_UUID_BATTERY;
const u16 my_batCharUUID = CHARACTERISTIC_UUID_BATTERY_LEVEL;
//static
u16 batteryValueInCCC;
u8 my_batVal; // = {99};
#endif // #if (BATT_SERVICE_ENABLE)
const attribute_t my_Attributes[] = {
{ATT_END_H - 1, 0,0,0,0,0}, // total num of attribute
...
#if (BATT_SERVICE_ENABLE)
////////////////////////////////////// Battery Service /////////////////////////////////////////////////////
{4,ATT_PERMISSIONS_READ,2,2,(u8*)(&my_primaryServiceUUID), (u8*)(&my_batServiceUUID), 0},
{0,ATT_PERMISSIONS_READ,2,sizeof(my_batCharVal),(u8*)(&my_characterUUID), (u8*)(my_batCharVal), 0}, //prop
{0,ATT_PERMISSIONS_READ,2,sizeof(my_batVal),(u8*)(&my_batCharUUID), (u8*)(&my_batVal), 0}, //value
{0,ATT_PERMISSIONS_RDWR,2,sizeof(batteryValueInCCC),(u8*)(&clientCharacterCfgUUID), (u8*)(&batteryValueInCCC), 0}, //value
#endif
#if (OTA_SERVICE_ENABLE)
////////////////////////////////////// OTA Service /////////////////////////////////////////////////////
{4,ATT_PERMISSIONS_READ, 2,16,(u8*)(&my_primaryServiceUUID), (u8*)(&my_OtaServiceUUID), 0},
{0,ATT_PERMISSIONS_READ, 2,sizeof(my_OtaCharVal),(u8*)(&my_characterUUID), (u8*)(my_OtaCharVal), 0}, //prop
{0,ATT_PERMISSIONS_RDWR,16,sizeof(my_OtaData),(u8*)(&my_OtaUUID), (&my_OtaData), &pre_otaWrite, &otaRead}, //value
{0,ATT_PERMISSIONS_READ, 2,sizeof(my_OtaName),(u8*)(&userdesc_UUID), (u8*)(my_OtaName), 0},
#endif
};
void ble_init(void) {
...
#if (OTA_SERVICE_ENABLE)
// OTA init
bls_ota_clearNewFwDataArea(); //must
bls_ota_registerStartCmdCb(entry_ota_mode);
bls_ota_registerResultIndicateCb(show_ota_result);
#endif
...
}