v2.0 beta4

This commit is contained in:
pvvx 2024-12-10 21:35:48 +03:00
parent a818721a61
commit 75504b6693
31 changed files with 7802 additions and 7712 deletions

View file

@ -104,7 +104,7 @@ The sensors are detected automatically, but have different ports depending on th
| 1.7 | <ul><li>Fixed en error (> 42 C) for sensor CHT8305</li></ul> |
| 1.8 | <ul><li>Added display of temperature in degrees Fahrenheit</li></ul> |
| 1.9 | <ul><li>Fixed the bug of restoring the changed device name after power reset</li></ul> |
| 2.0beta3 | <ul><li>Added processing of the CHT832x sensor (Support board TH05Y_v3.1)</li><li>Fixing a bug in BOOT OTA bin files</li><li>Added sleep function when battery is completely discharged</li><li>Added experimental firmware for [iSearching](https://pvvx.github.io/iSearching) key fobs on ST17H66B chip (support "FindMy")</li></ul> |
| 2.0beta4 | <ul><li>Added processing of the CHT832x sensor (Support board TH05Y_v3.1)</li><li>Fixing a bug in BOOT OTA bin files</li><li>Added sleep function when battery is completely discharged</li><li>Added experimental firmware for [iSearching](https://pvvx.github.io/iSearching) key fobs on ST17H66B chip (support "FindMy")</li></ul> |

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -89,7 +89,7 @@ uint8_t adv_set_data(void * pd) {
p->v_id = BtHomeID_voltage;
p->battery_mv = measured_data.battery_mv; // x mV
#if (DEV_SERVICES & SERVICE_BUTTON)
p->u_id = BtHomeID_button;
p->u_id = BtHomeID_button; // or BtHomeID_opened ?
p->button = measured_data.button;
p->c_id = BtHomeID_count32;
p->counter = adv_wrk.rds_count;
@ -111,7 +111,7 @@ uint8_t adv_set_event(void * ped) {
#elif (DEV_SERVICES & SERVICE_BUTTON)
uint8_t adv_set_event(void * ped) {
padv_bthome_event1_t p = (padv_bthome_event1_t)ped;
p->b_id = BtHomeID_button;
p->b_id = BtHomeID_button; // or BtHomeID_opened ?
p->button = measured_data.button;
p->c_id = BtHomeID_count32;
p->counter = adv_wrk.rds_count;

View file

@ -208,16 +208,56 @@ int cmd_parser(uint8_t * obuf, uint8_t * ibuf, uint32_t len) {
#endif
#if (DEV_SERVICES & SERVICE_FINDMY)
} else if (cmd == CMD_ID_FDMKEY) { // Get/set findmy key
if (len == sizeof(findmy_key) + 1) {
if(memcmp(findmy_key, &ibuf[1], sizeof(findmy_key))) {
memcpy(findmy_key, &ibuf[1], sizeof(findmy_key));
flash_write_cfg(findmy_key, EEP_ID_FDK, sizeof(findmy_key));
if (len == sizeof(findmy_key)/2 + 2) {
if(ibuf[1] == 3) {
memcpy(findmy_key_new, &ibuf[2], SIZE_FINDMY_KEY/2);
memcpy(&obuf[2], findmy_key_new, SIZE_FINDMY_KEY/2);
obuf[1] = 3;
olen = SIZE_FINDMY_KEY/2 + 2;
} else if(ibuf[1] == 4) {
memcpy(&findmy_key_new[SIZE_FINDMY_KEY/2], &ibuf[2], SIZE_FINDMY_KEY/2);
memcpy(&obuf[2], &findmy_key_new[SIZE_FINDMY_KEY/2], SIZE_FINDMY_KEY/2);
if(memcmp(findmy_key, findmy_key_new, SIZE_FINDMY_KEY)) {
memcpy(findmy_key, findmy_key_new, SIZE_FINDMY_KEY);
flash_write_cfg(findmy_key, EEP_ID_FDK, sizeof(findmy_key));
findmy_key_new[0] |= 0xC0;
swap_mac(findmy_key_new, findmy_key_new);
if(memcmp(ownPublicAddr, findmy_key_new, MAC_LEN)) {
memcpy(ownPublicAddr, findmy_key_new, MAC_LEN);
flash_write_cfg(ownPublicAddr, EEP_ID_MAC, MAC_LEN);
wrk.reboot |= 1;
}
}
obuf[1] = 4;
olen = SIZE_FINDMY_KEY/2 + 2;
} else {
obuf[1] = 0xff;
olen = 2;
}
}
if (flash_read_cfg(findmy_key, EEP_ID_FDK, sizeof(findmy_key)) == sizeof(findmy_key)) {
memcpy(&obuf[1], findmy_key, sizeof(findmy_key));
olen = sizeof(findmy_key) + 1;
} else { // No findmy key in EEP!
} else if (len == 2) {
if(ibuf[1] == 1) {
if (flash_read_cfg(findmy_key, EEP_ID_FDK, sizeof(findmy_key)) == sizeof(findmy_key)) {
memcpy(&obuf[2], findmy_key, SIZE_FINDMY_KEY/2);
obuf[1] = 1;
olen = SIZE_FINDMY_KEY/2 + 2;
} else { // No findmy key in EEP!
obuf[1] = 0xfe;
olen = 2;
}
} else if(ibuf[1] == 2) {
if (flash_read_cfg(findmy_key, EEP_ID_FDK, sizeof(findmy_key)) == sizeof(findmy_key)) {
memcpy(&obuf[2], &findmy_key[SIZE_FINDMY_KEY/2], SIZE_FINDMY_KEY/2);
obuf[1] = 2;
olen = SIZE_FINDMY_KEY/2 + 2;
} else { // No findmy key in EEP!
obuf[1] = 0xfe;
olen = 2;
}
} else {
obuf[1] = 0xff;
olen = 2;
}
} else {
obuf[1] = 0xff;
olen = 2;
}

View file

@ -9,31 +9,53 @@
#include "config.h"
#if (DEV_SERVICES & SERVICE_FINDMY)
#include "findmy_beacon.h"
#include "sensors.h"
uint8_t findmy_key[22];
uint8_t findmy_key[SIZE_FINDMY_KEY];
uint8_t findmy_key_new[SIZE_FINDMY_KEY];
typedef struct __attribute__((packed)) _adv_bthome_noencrypt_t {
uint8_t head[7];
uint8_t head[6];
uint8_t state;
/* State:
Bits 01: Reserved.
Bit 2: Maintained
Bits 34: Reserved
Bits 5: 0b1
Bits 67: Battery state:
0 = Full
1 = Medium
2 = Low
3 = Critically low
*/
uint8_t key[22];
uint8_t end[2];
uint8_t key0_bit67;
uint8_t end;
} adv_findmy_t, * padv_findmy_t;
static uint8 findmy_head[] = {
0x1e, /* Length (30) */
0xff, /* Manufacturer Specific Data (type 0xff) */
0x4c, 0x00, /* Company ID (Apple) */
0x12, 0x19, /* Offline Finding type and length */
0x00 /* State */
0x12, 0x19 /* Offline Finding type and length */
};
uint8_t findmy_beacon(void * padbuf) {
padv_findmy_t p = (padv_findmy_t)padbuf;
memcpy(p->head, findmy_head, sizeof(findmy_head));
memcpy(p->key, findmy_key, sizeof(findmy_key));
p->end[0] = 0;
p->end[1] = 0;
memcpy(p->key, &findmy_key[6], sizeof(p->key));
p->key0_bit67 = findmy_key[0] >> 6;
if(measured_data.battery > 80)
p->state = 0 << 6; // Full
else if(measured_data.battery > 60)
p->state = 1 << 6; // Medium
else if(measured_data.battery > 25)
p->state = 2 << 6; // Low
else
p->state = 3 << 6; // Critically low
p->end = 0;
return sizeof(adv_findmy_t);
}

View file

@ -8,7 +8,11 @@
#ifndef SOURCE_FINDMY_BEACON_H_
#define SOURCE_FINDMY_BEACON_H_
extern uint8_t findmy_key[22];
#define SIZE_FINDMY_KEY 28
extern uint8_t findmy_key[SIZE_FINDMY_KEY];
extern uint8_t findmy_key_new[SIZE_FINDMY_KEY];
uint8_t findmy_beacon(void * padbuf);
#endif /* SOURCE_FINDMY_BEACON_H_ */

View file

@ -144,6 +144,18 @@ void set_dev_name(void)
GGS_SetParameter( GGS_DEVICE_NAME_ATT, p[0] - 1, (void *)&p[2] ); // GAP_DEVICE_NAME_LEN, attDeviceName );
}
void swap_mac(uint8_t * d, uint8_t * s)
{
uint8_t buf[6];
buf[0] = s[5];
buf[1] = s[4];
buf[2] = s[3];
buf[3] = s[2];
buf[4] = s[1];
buf[5] = s[0];
memcpy(d, buf, 6);
}
static void set_mac(void)
{
//extern uint8_t ownPublicAddr[LL_DEVICE_ADDR_LEN];
@ -153,17 +165,10 @@ static void set_mac(void)
// Tuya mac[0:3]
ownPublicAddr[3] = 0x8d;
ownPublicAddr[4] = 0x1f;
#if (DEV_SERVICES & SERVICE_FINDMY)
ownPublicAddr[5] = 0xf8; // random mac
#else
ownPublicAddr[5] = 0x38;
#endif
}
flash_write_cfg(ownPublicAddr, EEP_ID_MAC, MAC_LEN);
}
#if (DEV_SERVICES & SERVICE_FINDMY)
ownPublicAddr[5] |= 0xc0; // random mac
#endif
pGlobal_config[MAC_ADDRESS_LOC] = (uint32_t)ownPublicAddr;
// device name
set_dev_name();

View file

@ -91,6 +91,8 @@ void SimpleBLEPeripheral_Init( uint8_t task_id );
uint16_t BLEPeripheral_ProcessEvent( uint8_t task_id, uint16_t events );
void swap_mac(uint8_t * d, uint8_t * s);
void set_def_name(void);
void set_dev_name(void);

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.