mirror of
https://github.com/OpenEPaperLink/OpenEPaperLink.git
synced 2026-03-21 05:06:39 +01:00
Added V2 ATC_BLE_OEPL Advertising Handling
This commit is contained in:
@@ -64,7 +64,7 @@ uint8_t gicToOEPLtype(uint8_t gicType) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct BleAdvDataStruct {
|
struct BleAdvDataStructV1 {
|
||||||
uint16_t manu_id; // 0x1337 for us
|
uint16_t manu_id; // 0x1337 for us
|
||||||
uint8_t version;
|
uint8_t version;
|
||||||
uint16_t hw_type;
|
uint16_t hw_type;
|
||||||
@@ -73,6 +73,16 @@ struct BleAdvDataStruct {
|
|||||||
uint16_t battery_mv;
|
uint16_t battery_mv;
|
||||||
uint8_t counter;
|
uint8_t counter;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
struct BleAdvDataStructV2 {
|
||||||
|
uint16_t manu_id; // 0x1337 for us
|
||||||
|
uint8_t version;
|
||||||
|
uint16_t hw_type;
|
||||||
|
uint16_t fw_version;
|
||||||
|
uint16_t capabilities;
|
||||||
|
uint16_t battery_mv;
|
||||||
|
int8_t temperature;
|
||||||
|
uint8_t counter;
|
||||||
|
} __packed;
|
||||||
|
|
||||||
bool BLE_filter_add_device(BLEAdvertisedDevice advertisedDevice) {
|
bool BLE_filter_add_device(BLEAdvertisedDevice advertisedDevice) {
|
||||||
Serial.print("BLE Advertised Device found: ");
|
Serial.print("BLE Advertised Device found: ");
|
||||||
@@ -91,16 +101,16 @@ bool BLE_filter_add_device(BLEAdvertisedDevice advertisedDevice) {
|
|||||||
uint8_t manuData[100];
|
uint8_t manuData[100];
|
||||||
if (manuDatalen > sizeof(manuData))
|
if (manuDatalen > sizeof(manuData))
|
||||||
return false; // Manu data too big, could never happen but better make sure here
|
return false; // Manu data too big, could never happen but better make sure here
|
||||||
|
#if ESP_ARDUINO_VERSION_MAJOR == 2
|
||||||
|
memcpy(&manuData, (uint8_t*)advertisedDevice.getManufacturerData().data(), manuDatalen);
|
||||||
|
#else
|
||||||
|
// [Nic] suggested fix for arduino 3.x by copilot, but I cannot test it
|
||||||
|
memcpy(&manuData, (uint8_t*)advertisedDevice.getManufacturerData().c_str(), manuDatalen);
|
||||||
|
#endif
|
||||||
Serial.printf(" Address type: %02X Manu data: ", advertisedDevice.getAddressType());
|
Serial.printf(" Address type: %02X Manu data: ", advertisedDevice.getAddressType());
|
||||||
for (int i = 0; i < advertisedDevice.getManufacturerData().length(); i++)
|
for (int i = 0; i < advertisedDevice.getManufacturerData().length(); i++)
|
||||||
Serial.printf("%02X", manuData[i]);
|
Serial.printf("%02X", manuData[i]);
|
||||||
Serial.printf("\r\n");
|
Serial.printf("\r\n");
|
||||||
#if ESP_ARDUINO_VERSION_MAJOR == 2
|
|
||||||
memcpy(&manuData, (uint8_t*)advertisedDevice.getManufacturerData().data(), manuDatalen);
|
|
||||||
#else
|
|
||||||
// [Nic] suggested fix for arduino 3.x by copilot, but I cannot test it
|
|
||||||
memcpy(&manuData, (uint8_t*)advertisedDevice.getManufacturerData().c_str(), manuDatalen);
|
|
||||||
#endif
|
|
||||||
if (manuDatalen == 7 && manuData[0] == 0x53 && manuData[1] == 0x50) { // Lets check for a Gicisky E-Paper display
|
if (manuDatalen == 7 && manuData[0] == 0x53 && manuData[1] == 0x50) { // Lets check for a Gicisky E-Paper display
|
||||||
|
|
||||||
struct espAvailDataReq theAdvData;
|
struct espAvailDataReq theAdvData;
|
||||||
@@ -125,23 +135,63 @@ bool BLE_filter_add_device(BLEAdvertisedDevice advertisedDevice) {
|
|||||||
|
|
||||||
processDataReq(&theAdvData, true);
|
processDataReq(&theAdvData, true);
|
||||||
return true;
|
return true;
|
||||||
} else if (manuDatalen >= sizeof(BleAdvDataStruct) && manuData[0] == 0x37 && manuData[1] == 0x13) { // Lets check for a Gicisky E-Paper display
|
} else if (manuDatalen >= 3 && manuData[0] == 0x37 && manuData[1] == 0x13) { // Lets check for a Gicisky E-Paper display
|
||||||
Serial.printf("ATC BLE OEPL Detected\r\n");
|
Serial.printf("ATC BLE OEPL Detected\r\n");
|
||||||
struct espAvailDataReq theAdvData;
|
struct espAvailDataReq theAdvData;
|
||||||
struct BleAdvDataStruct inAdvData;
|
|
||||||
|
|
||||||
memset((uint8_t*)&theAdvData, 0x00, sizeof(espAvailDataReq));
|
memset((uint8_t*)&theAdvData, 0x00, sizeof(espAvailDataReq));
|
||||||
memcpy(&inAdvData, manuData, sizeof(BleAdvDataStruct));
|
uint8_t versionAdvData = manuData[2];
|
||||||
/*Serial.printf("manu_id %04X\r\n", inAdvData.manu_id);
|
|
||||||
Serial.printf("version %04X\r\n", inAdvData.version);
|
switch (versionAdvData) {
|
||||||
Serial.printf("hw_type %04X\r\n", inAdvData.hw_type);
|
case 1: {
|
||||||
Serial.printf("fw_version %04X\r\n", inAdvData.fw_version);
|
if (manuDatalen >= sizeof(BleAdvDataStructV1)) {
|
||||||
Serial.printf("capabilities %04X\r\n", inAdvData.capabilities);
|
struct BleAdvDataStructV1 inAdvData;
|
||||||
Serial.printf("battery_mv %u\r\n", inAdvData.battery_mv);
|
memcpy(&inAdvData, manuData, sizeof(BleAdvDataStructV1));
|
||||||
Serial.printf("counter %u\r\n", inAdvData.counter);*/
|
printf("Version 1 ATC_BLE_OEPL Received\r\n");
|
||||||
if (inAdvData.version != 1) {
|
/*Serial.printf("manu_id %04X\r\n", inAdvData.manu_id);
|
||||||
printf("Version currently not supported!\r\n");
|
Serial.printf("version %02X\r\n", inAdvData.version);
|
||||||
return false;
|
Serial.printf("hw_type %04X\r\n", inAdvData.hw_type);
|
||||||
|
Serial.printf("fw_version %04X\r\n", inAdvData.fw_version);
|
||||||
|
Serial.printf("capabilities %04X\r\n", inAdvData.capabilities);
|
||||||
|
Serial.printf("battery_mv %u\r\n", inAdvData.battery_mv);
|
||||||
|
Serial.printf("counter %u\r\n", inAdvData.counter);*/
|
||||||
|
theAdvData.adr.batteryMv = inAdvData.battery_mv;
|
||||||
|
theAdvData.adr.lastPacketRSSI = advertisedDevice.getRSSI();
|
||||||
|
theAdvData.adr.hwType = inAdvData.hw_type & 0xff;
|
||||||
|
theAdvData.adr.tagSoftwareVersion = inAdvData.fw_version;
|
||||||
|
theAdvData.adr.capabilities = inAdvData.capabilities & 0xff;
|
||||||
|
} else {
|
||||||
|
printf("Version 1 data length incorrect!\r\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
case 2: {
|
||||||
|
if (manuDatalen >= sizeof(BleAdvDataStructV2)) {
|
||||||
|
struct BleAdvDataStructV2 inAdvData;
|
||||||
|
memcpy(&inAdvData, manuData, sizeof(BleAdvDataStructV2));
|
||||||
|
printf("Version 2 ATC_BLE_OEPL Received\r\n");
|
||||||
|
/*Serial.printf("manu_id %04X\r\n", inAdvData.manu_id);
|
||||||
|
Serial.printf("version %02X\r\n", inAdvData.version);
|
||||||
|
Serial.printf("hw_type %04X\r\n", inAdvData.hw_type);
|
||||||
|
Serial.printf("fw_version %04X\r\n", inAdvData.fw_version);
|
||||||
|
Serial.printf("capabilities %04X\r\n", inAdvData.capabilities);
|
||||||
|
Serial.printf("battery_mv %u\r\n", inAdvData.battery_mv);
|
||||||
|
Serial.printf("temperature %i\r\n", inAdvData.temperature);
|
||||||
|
Serial.printf("counter %u\r\n", inAdvData.counter);*/
|
||||||
|
theAdvData.adr.batteryMv = inAdvData.battery_mv;
|
||||||
|
theAdvData.adr.temperature = inAdvData.temperature;
|
||||||
|
theAdvData.adr.lastPacketRSSI = advertisedDevice.getRSSI();
|
||||||
|
theAdvData.adr.hwType = inAdvData.hw_type & 0xff;
|
||||||
|
theAdvData.adr.tagSoftwareVersion = inAdvData.fw_version;
|
||||||
|
theAdvData.adr.capabilities = inAdvData.capabilities & 0xff;
|
||||||
|
} else {
|
||||||
|
printf("Version 2 data length incorrect!\r\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
default:
|
||||||
|
printf("Version %02X currently not supported!\r\n", versionAdvData);
|
||||||
|
return false;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
uint8_t macReversed[6];
|
uint8_t macReversed[6];
|
||||||
memcpy(&macReversed, (uint8_t*)advertisedDevice.getAddress().getNative(), 6);
|
memcpy(&macReversed, (uint8_t*)advertisedDevice.getAddress().getNative(), 6);
|
||||||
@@ -153,11 +203,6 @@ bool BLE_filter_add_device(BLEAdvertisedDevice advertisedDevice) {
|
|||||||
theAdvData.src[5] = macReversed[0];
|
theAdvData.src[5] = macReversed[0];
|
||||||
theAdvData.src[6] = manuData[0]; // We use this do find out what type of display we got for compression^^
|
theAdvData.src[6] = manuData[0]; // We use this do find out what type of display we got for compression^^
|
||||||
theAdvData.src[7] = manuData[1];
|
theAdvData.src[7] = manuData[1];
|
||||||
theAdvData.adr.batteryMv = inAdvData.battery_mv;
|
|
||||||
theAdvData.adr.lastPacketRSSI = advertisedDevice.getRSSI();
|
|
||||||
theAdvData.adr.hwType = inAdvData.hw_type & 0xff;
|
|
||||||
theAdvData.adr.tagSoftwareVersion = inAdvData.fw_version;
|
|
||||||
theAdvData.adr.capabilities = inAdvData.capabilities & 0xff;
|
|
||||||
processDataReq(&theAdvData, true);
|
processDataReq(&theAdvData, true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user