MCPcopy Create free account
hub / github.com/OpenEPaperLink/OpenEPaperLink / BLETask

Function BLETask

ESP32_AP-Flasher/src/ble_writer.cpp:260–515  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

258}
259
260void BLETask(void* parameter) {
261 vTaskDelay(5000 / portTICK_PERIOD_MS);
262 Serial.println("BLE task started");
263 BLE_dataReqQueue = xQueueCreate(BLE_DATA_REQ_QUEUE_LEN, sizeof(struct espAvailDataReq));
264 BLEDevice::init("");
265 while (1) {
266 // Process advertisements collected by the scan callback here, in this
267 // task's large stack, instead of inside the tiny BLE host task stack.
268 struct espAvailDataReq incomingDataReq;
269 while (BLE_dataReqQueue != nullptr && xQueueReceive(BLE_dataReqQueue, &incomingDataReq, 0) == pdTRUE) {
270 processDataReq(&incomingDataReq, true);
271 }
272 switch (ble_main_state) {
273 default:
274 case BLE_MAIN_STATE_IDLE:
275 if (millis() - last_ble_scan > (INTERVAL_BLE_SCANNING_SECONDS * 1000)) {
276 last_ble_scan = millis();
277 Serial.println("Doing the BLE Scan");
278 BLE_startScan(10); // timeout in seconds, this is blocking but only for this thread!
279 }
280 if (millis() - BLE_last_pending_check >= (INTERVAL_HANDLE_PENDING_SECONDS * 1000)) {
281 if (BLE_is_image_pending(BLE_curr_address)) {
282 Serial.println("BLE Image is pending but we wait a bit");
283 delay(5000); // We better wait here, since the pending image needs to be created first
284 if (BLE_curr_address[7] == 0x13 && BLE_curr_address[6] == 0x37) { // This is an ATC BLE OEPL display
285 // Here we create the compressed buffer
286 BLE_image_buffer = (uint8_t*)malloc(BUFFER_MAX_SIZE_COMPRESSING);
287 if (BLE_image_buffer == nullptr) {
288 Serial.println("BLE Could not create buffer!");
289 BLE_compressed_len = 0;
290 } else {
291 uint8_t dataType = 0x00;
292 uint8_t dataTypeArgument = 0x00;
293 uint16_t nextCheckin = 0x00;
294 BLE_compressed_len = get_ATC_BLE_OEPL_image(BLE_curr_address, BLE_image_buffer, BUFFER_MAX_SIZE_COMPRESSING, &dataType, &dataTypeArgument, &nextCheckin);
295 Serial.printf("BLE data Length: %i\r\n", BLE_compressed_len);
296 // then we connect to BLE to send the compressed data
297 if (BLE_compressed_len && BLE_connect(BLE_curr_address, BLE_TYPE_ATC_BLE_OEPL)) {
298 BLE_err_counter = 0;
299 BLE_curr_part = 0;
300 memset(BLE_notify_buffer, 0x00, sizeof(BLE_notify_buffer));
301
302 uint8_t md5bytes[16];
303 MD5Builder md5;
304 md5.begin();
305 md5.add(BLE_image_buffer, BLE_compressed_len);
306 md5.calculate();
307 md5.getBytes(md5bytes);
308
309 BLEavaildatainfo.dataType = dataType;
310 BLEavaildatainfo.dataVer = *((uint64_t*)md5bytes);
311 BLEavaildatainfo.dataSize = BLE_compressed_len;
312 BLEavaildatainfo.dataTypeArgument = dataTypeArgument;
313 BLEavaildatainfo.nextCheckIn = nextCheckin;
314 BLEavaildatainfo.checksum = 0;
315 for (uint16_t c = 1; c < sizeof(struct AvailDataInfo); c++) {
316 BLEavaildatainfo.checksum += (uint8_t)((uint8_t*)&BLEavaildatainfo)[c];
317 }

Callers

nothing calls this directly

Calls 15

initFunction · 0.85
processDataReqFunction · 0.85
BLE_startScanFunction · 0.85
BLE_is_image_pendingFunction · 0.85
get_ATC_BLE_OEPL_imageFunction · 0.85
BLE_connectFunction · 0.85
memsetFunction · 0.85
memcpyFunction · 0.85
BLE_clear_attemptsFunction · 0.85
compress_imageFunction · 0.85
BLE_reportProgressFunction · 0.85
wsSendUploadProgressFunction · 0.85

Tested by

no test coverage detected