feat: add support for findmy network

This commit is contained in:
reece
2024-03-08 00:45:45 +08:00
parent 039f899c6c
commit 296e63236c
9 changed files with 70 additions and 5 deletions

Binary file not shown.

View File

@@ -77,3 +77,7 @@ void blc_initMacAddress(int flash_addr, u8 *mac_public, u8 *mac_random_static)
}
}
void blc_setMacAddress(int flash_addr, u8 *mac_public)
{
flash_write_page (flash_addr, sizeof(mac_public), mac_public);
}

View File

@@ -30,6 +30,7 @@
void blc_initMacAddress(int flash_addr, u8 *mac_public, u8 *mac_random_static);
void blc_setMacAddress(int flash_addr, u8 *mac_public);

View File

@@ -44,7 +44,7 @@ _attribute_ram_code_ void main_loop(void)
{
blt_sdk_main_loop();
handler_time();
uint8_t flag = 0;
if (time_reached_period(Timer_CH_1, 30))
{
battery_mv = get_battery_mv();
@@ -53,6 +53,10 @@ _attribute_ram_code_ void main_loop(void)
set_adv_data(EPD_read_temp() * 10, battery_level, battery_mv);
ble_send_battery(battery_level);
ble_send_temp(EPD_read_temp() * 10);
flag = 1;
}
if (!flag && time_reached_period(Timer_CH_3, 17)) {
set_air_tag_adv_data();
}
epd_update(get_time(), battery_mv, temperature);

View File

@@ -49,6 +49,25 @@ RAM uint8_t advertising_data[] = {
RAM uint8_t mac_public[6];
RAM uint8_t PUB_KEY[28] = {
0x49,0x88,0x0,0x7a,0x27,0xac,0x38,0xb7,0x16,0x55,0x3c,0xc8,0x57,0x62,0x93,0xc3,0x95,0xef,0x3f,0x63,0x70,0xb2,0xa3,0x96,0x6d,0x4c,0x1a,0x7d //
};
RAM uint8_t air_tag_adv_data[31] = {
0x1e, /* Length (30) */
0xff, /* Manufacturer Specific Data (type 0xff) */
0x4c, 0x00, /* Company ID (Apple) */
0x12, 0x19, /* Offline Finding type and length */
0x00, /* State */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, /* First two bits */
0x00, /* Hint (0x00) */
};
RAM uint8_t AIR_TAG_OPEN = 1;
_attribute_ram_code_ void app_switch_to_indirect_adv(uint8_t e, uint8_t *p, int n)
{
bls_ll_setAdvParam(ADVERTISING_INTERVAL, ADVERTISING_INTERVAL + 50, ADV_TYPE_CONNECTABLE_UNDIRECTED, OWN_ADDRESS_PUBLIC, 0, NULL, BLT_ENABLE_ADV_ALL, ADV_FP_NONE);
@@ -105,7 +124,19 @@ void init_ble(void)
{
////////////////// BLE stack initialization ////////////////////////////////////
uint8_t mac_random_static[6];
blc_initMacAddress(CFG_ADR_MAC, mac_public, mac_random_static);
mac_public[5] = PUB_KEY[0] | 0b11000000;
mac_public[4] = PUB_KEY[1];
mac_public[3] = PUB_KEY[2];
mac_public[2] = PUB_KEY[3];
mac_public[1] = PUB_KEY[4];
mac_public[0] = PUB_KEY[5];
if(AIR_TAG_OPEN) {
blc_setMacAddress(CFG_ADR_MAC, mac_public);
} else {
blc_initMacAddress(CFG_ADR_MAC, mac_public, mac_random_static);
}
// Set the BLE Name to the last three MACs the first ones are always the same
const char *hex_ascii = {"0123456789ABCDEF"};
@@ -181,6 +212,16 @@ _attribute_ram_code_ void set_adv_data(int16_t temp, uint8_t battery_level, uint
bls_ll_setAdvData((uint8_t *)advertising_data, sizeof(advertising_data));
}
_attribute_ram_code_ void set_air_tag_adv_data(void)
{
if (AIR_TAG_OPEN) {
memcpy(&air_tag_adv_data[7], &PUB_KEY[6], 22);
air_tag_adv_data[29] = PUB_KEY[0] >> 6;
bls_ll_setAdvData((uint8_t *)air_tag_adv_data, sizeof(air_tag_adv_data));
}
}
_attribute_ram_code_ void ble_send_temp(int16_t temp)
{
my_tempVal[0] = temp & 0xFF;

View File

@@ -5,6 +5,7 @@
void init_ble(void);
void set_adv_data(int16_t temp, uint8_t battery_level, uint16_t battery_mv);
void set_air_tag_adv_data(void); // 发送 airtag 广播
bool ble_get_connected(void);
bool ble_get_ota_started(void);
void ble_send_temp(int16_t temp);

View File

@@ -95,7 +95,7 @@ _attribute_ram_code_ void EPD_detect_model(void)
{
epd_model = 1;
}
epd_model = 5; // FIXME: only for bwr_296
EPD_POWER_OFF();
}

View File

@@ -20,7 +20,14 @@ uint8_t map[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
_attribute_ram_code_ void init_time(void)
{
one_second_trimmed += time_trime;
current_unix_time = 0;
current_unix_time = 1709856857;
current_date.tm_year = 2024;
current_date.tm_month = 3;
current_date.tm_week = 5;
current_date.tm_day = 8;
current_date.tm_min = 14;
current_date.tm_hour = 0;
current_date.tm_sec = 17;
}
_attribute_ram_code_ void handler_time(void)

View File

@@ -1,4 +1,4 @@
<h1 align="center">hanshow stellar L3N 电子价签固件</h1>
<h1 align="center">hanshow stellar L3N 电子价签/airtag固件</h1>
### 适用型号 L3N@ (注意只适配了L3N@ 2.9寸设备,原项目的其他型号可能已经不再兼容)
@@ -64,6 +64,12 @@ Firmware CRC32: 0xe62d501e
- 3. 选择图片并上传,上传后可添加文字或者手动绘制文字。也可设置抖动算法。
- 4. 发送到设备,等待屏幕刷新
### 接入苹果findmy网络模拟airtag
- 设备已支持接入苹果findmy网络(设备会通过蓝牙广播自动发送符合airtag协议的公钥当设备附近的苹果设备接受到公钥时就会使用公钥加密自己的位置信息然后发送到findmy服务器用户可使用自己的私钥从苹果服务器获取设备的位置信息
- 该功能默认关闭
- 打开该功能 需要修改ble.c文件 PUB_KEY=后的数据改为你自己的公钥。PUB_KEY获取方法可参考项目(https://github.com/dchristl/macless-haystack 或者 https://github.com/malmeloo/openhaystack)
- 打开该功能 还需要修改ble.c文件 AIR_TAG_OPEN=1
### 已解决/未解决问题
- [X] 编译报错
@@ -83,6 +89,7 @@ Firmware CRC32: 0xe62d501e
- [X] 三色抖动算法、设备端三色显示支持,蓝牙传输支持
- [X] epd buffer刷新后 数据异常(左或右偶尔有黑条)?
- [X] 中文显示 部分中文以bitmap显示不支持全部中文
- [X] 支持接入苹果findmy网络模拟airtag
### 原始readme.md