mirror of
https://github.com/tpunix/HMCLOCK.git
synced 2025-12-06 08:12:48 +08:00
改为16位UUID
This commit is contained in:
@@ -186,10 +186,7 @@ static const struct advertise_configuration user_adv_conf = {
|
||||
/// Advertising data
|
||||
#define USER_ADVERTISE_DATA ("\x03"\
|
||||
ADV_TYPE_COMPLETE_LIST_16BIT_SERVICE_IDS\
|
||||
ADV_UUID_DEVICE_INFORMATION_SERVICE\
|
||||
"\x11"\
|
||||
ADV_TYPE_COMPLETE_LIST_128BIT_SERVICE_IDS\
|
||||
"\x59\x5A\x08\xE4\x86\x2A\x9E\x8F\xE9\x11\xBC\x7C\x98\x43\x42\x18")
|
||||
"\x00\xff")
|
||||
|
||||
/// Advertising data length - maximum 28 bytes, 3 bytes are reserved to set
|
||||
#define USER_ADVERTISE_DATA_LEN (sizeof(USER_ADVERTISE_DATA)-1)
|
||||
|
||||
@@ -58,12 +58,10 @@
|
||||
*/
|
||||
|
||||
// Service 1 of the custom server 1
|
||||
static const att_svc_desc128_t custs1_svc1 = DEF_SVC1_UUID_128;
|
||||
|
||||
static const uint8_t SVC1_CTRL_POINT_UUID_128[ATT_UUID_128_LEN] = DEF_SVC1_CTRL_POINT_UUID_128;
|
||||
static const uint8_t SVC1_ADC_VAL_1_UUID_128[ATT_UUID_128_LEN] = DEF_SVC1_ADC_VAL_1_UUID_128;
|
||||
static const uint8_t SVC1_LONG_VALUE_UUID_128[ATT_UUID_128_LEN] = DEF_SVC1_LONG_VALUE_UUID_128;
|
||||
|
||||
static const uint16_t custs1_svc1 = 0xff00;
|
||||
static const uint16_t svc1_ctrl_point = 0xff03;
|
||||
static const uint16_t svc1_adc_val1 = 0xff02;
|
||||
static const uint16_t svc1_long_value = 0xff01;
|
||||
|
||||
// Attribute specifications
|
||||
static const uint16_t att_decl_svc = ATT_DECL_PRIMARY_SERVICE;
|
||||
@@ -89,25 +87,25 @@ const struct attm_desc_128 custs1_att_db[CUSTS1_IDX_NB] =
|
||||
*/
|
||||
|
||||
// Service 1 Declaration
|
||||
[SVC1_IDX_SVC] = {(uint8_t*)&att_decl_svc, ATT_UUID_128_LEN, PERM(RD, ENABLE),
|
||||
[SVC1_IDX_SVC] = {(uint8_t*)&att_decl_svc, ATT_UUID_16_LEN, PERM(RD, ENABLE),
|
||||
sizeof(custs1_svc1), sizeof(custs1_svc1), (uint8_t*)&custs1_svc1},
|
||||
|
||||
// Control Point Characteristic Declaration
|
||||
[SVC1_IDX_CONTROL_POINT_CHAR] = {(uint8_t*)&att_decl_char, ATT_UUID_16_LEN, PERM(RD, ENABLE), 0, 0, NULL},
|
||||
// Control Point Characteristic Value
|
||||
[SVC1_IDX_CONTROL_POINT_VAL] = {SVC1_CTRL_POINT_UUID_128, ATT_UUID_128_LEN, PERM(WR, ENABLE) | PERM(WRITE_REQ, ENABLE),
|
||||
[SVC1_IDX_CONTROL_POINT_VAL] = {(uint8_t*)&svc1_ctrl_point, ATT_UUID_16_LEN, PERM(WR, ENABLE) | PERM(WRITE_REQ, ENABLE),
|
||||
DEF_SVC1_CTRL_POINT_CHAR_LEN, 0, 0},
|
||||
|
||||
// ADC Value 1 Characteristic Declaration
|
||||
[SVC1_IDX_ADC_VAL_1_CHAR] = {(uint8_t*)&att_decl_char, ATT_UUID_16_LEN, PERM(RD, ENABLE), 0, 0, NULL},
|
||||
// ADC Value 1 Characteristic Value
|
||||
[SVC1_IDX_ADC_VAL_1_VAL] = {SVC1_ADC_VAL_1_UUID_128, ATT_UUID_128_LEN, PERM(RD, ENABLE),
|
||||
[SVC1_IDX_ADC_VAL_1_VAL] = {(uint8_t*)&svc1_adc_val1, ATT_UUID_16_LEN, PERM(RD, ENABLE),
|
||||
DEF_SVC1_ADC_VAL_1_CHAR_LEN, 0, 0},
|
||||
|
||||
// Long Value Characteristic Declaration
|
||||
[SVC1_IDX_LONG_VALUE_CHAR] = {(uint8_t*)&att_decl_char, ATT_UUID_16_LEN, PERM(RD, ENABLE), 0, 0, NULL},
|
||||
// Long Value Characteristic Value
|
||||
[SVC1_IDX_LONG_VALUE_VAL] = {SVC1_LONG_VALUE_UUID_128, ATT_UUID_128_LEN, PERM(RD, ENABLE) | PERM(WR, ENABLE) | PERM(WRITE_REQ, ENABLE),
|
||||
[SVC1_IDX_LONG_VALUE_VAL] = {(uint8_t*)&svc1_long_value, ATT_UUID_16_LEN, PERM(RD, ENABLE) | PERM(WR, ENABLE) | PERM(WRITE_REQ, ENABLE),
|
||||
DEF_SVC1_LONG_VALUE_CHAR_LEN, 0, 0},
|
||||
};
|
||||
|
||||
|
||||
@@ -57,12 +57,6 @@
|
||||
*/
|
||||
|
||||
// Service 1 of the custom server 1
|
||||
#define DEF_SVC1_UUID_128 {0x59, 0x5a, 0x08, 0xe4, 0x86, 0x2a, 0x9e, 0x8f, 0xe9, 0x11, 0xbc, 0x7c, 0x98, 0x43, 0x42, 0x18}
|
||||
|
||||
#define DEF_SVC1_CTRL_POINT_UUID_128 {0x20, 0xEE, 0x8D, 0x0C, 0xE1, 0xF0, 0x4A, 0x0C, 0xB3, 0x25, 0xDC, 0x53, 0x6A, 0x68, 0x86, 0x2D}
|
||||
#define DEF_SVC1_ADC_VAL_1_UUID_128 {0x17, 0xB9, 0x67, 0x98, 0x4C, 0x66, 0x4C, 0x01, 0x96, 0x33, 0x31, 0xB1, 0x91, 0x59, 0x00, 0x15}
|
||||
#define DEF_SVC1_LONG_VALUE_UUID_128 {0x8C, 0x09, 0xE0, 0xD1, 0x81, 0x54, 0x42, 0x40, 0x8E, 0x4F, 0xD2, 0xB3, 0x77, 0xE3, 0x2A, 0x77}
|
||||
|
||||
#define DEF_SVC1_CTRL_POINT_CHAR_LEN 1
|
||||
#define DEF_SVC1_ADC_VAL_1_CHAR_LEN 2
|
||||
#define DEF_SVC1_LONG_VALUE_CHAR_LEN 48
|
||||
|
||||
@@ -40,8 +40,8 @@
|
||||
try {
|
||||
console.log('请求设备...');
|
||||
device = await navigator.bluetooth.requestDevice({
|
||||
filters: [{ namePrefix: "DLG"}]
|
||||
, optionalServices: ['18424398-7cbc-11e9-8f9e-2a86e4085a59']
|
||||
filters: [{ namePrefix: "DLG-CLOCK"}]
|
||||
, optionalServices: [ 0xff00 ]
|
||||
});
|
||||
console.log('device: ', device.name);
|
||||
document.getElementById('device_name').textContent = "设备名: "+device.name;
|
||||
@@ -50,12 +50,12 @@
|
||||
var server = await device.gatt.connect();
|
||||
console.log('设备已连接!');
|
||||
|
||||
var service = await server.getPrimaryService('18424398-7cbc-11e9-8f9e-2a86e4085a59');
|
||||
var service = await server.getPrimaryService( 0xff00 );
|
||||
console.log('获得service: ', service.uuid);
|
||||
|
||||
var ctrlPoint = await service.getCharacteristic('2d86686a-53dc-25b3-0c4a-f0e10c8dee20');
|
||||
var adc1Value = await service.getCharacteristic('15005991-b131-3396-014c-664c9867b917');
|
||||
var longValue = await service.getCharacteristic('772ae377-b3d2-4f8e-4042-5481d1e0098c');
|
||||
var ctrlPoint = await service.getCharacteristic( 0xff03 );
|
||||
var adc1Value = await service.getCharacteristic( 0xff02 );
|
||||
var longValue = await service.getCharacteristic( 0xff01 );
|
||||
|
||||
cur_voltage = await adc1Value.readValue();
|
||||
console.log('cur_voltage:', cur_voltage);
|
||||
@@ -81,7 +81,7 @@
|
||||
hour = today.getHours();
|
||||
minute = today.getMinutes();
|
||||
second = today.getSeconds();
|
||||
console.log('today:',today);
|
||||
console.log('today:',today, 'wday:', wday);
|
||||
buf[0] = 0x91;
|
||||
buf[1] = year%256;
|
||||
buf[2] = year/256;
|
||||
|
||||
Reference in New Issue
Block a user