| 378 | } |
| 379 | |
| 380 | void processBlockRequest(struct espBlockRequest* br) { |
| 381 | uint32_t t = millis(); |
| 382 | if (config.runStatus == RUNSTATUS_STOP) { |
| 383 | return; |
| 384 | } |
| 385 | if (!checkCRC(br, sizeof(struct espBlockRequest))) { |
| 386 | Serial.print("Failed CRC on a blockrequest received by the AP"); |
| 387 | return; |
| 388 | } |
| 389 | |
| 390 | PendingItem* queueItem = getQueueItem(br->src, br->ver); |
| 391 | if (queueItem == nullptr) { |
| 392 | prepareCancelPending(br->src); |
| 393 | Serial.printf("blockrequest: couldn't find taginfo %02X%02X%02X%02X%02X%02X%02X%02X\r\n", br->src[7], br->src[6], br->src[5], br->src[4], br->src[3], br->src[2], br->src[1], br->src[0]); |
| 394 | return; |
| 395 | } |
| 396 | if (queueItem->data == nullptr) { |
| 397 | fs::File file = contentFS->open(queueItem->filename); |
| 398 | if (!file) { |
| 399 | Serial.print("No current file. " + String(queueItem->filename) + " Canceling request\r\n"); |
| 400 | prepareCancelPending(br->src); |
| 401 | return; |
| 402 | } |
| 403 | queueItem->data = getDataForFile(file); |
| 404 | Serial.println("Reading file " + String(queueItem->filename) + " in " + String(millis() - t) + "ms"); |
| 405 | file.close(); |
| 406 | } |
| 407 | |
| 408 | // check if we're not exceeding max blocks (to prevent sendBlock from exceeding its boundary) |
| 409 | uint8_t totalblocks = (queueItem->len / BLOCK_DATA_SIZE); |
| 410 | if (queueItem->len % BLOCK_DATA_SIZE) totalblocks++; |
| 411 | if (br->blockId >= totalblocks) { |
| 412 | br->blockId = totalblocks - 1; |
| 413 | } |
| 414 | uint32_t len = queueItem->len - (BLOCK_DATA_SIZE * br->blockId); |
| 415 | if (len > BLOCK_DATA_SIZE) len = BLOCK_DATA_SIZE; |
| 416 | uint16_t checksum = sendBlock(queueItem->data + (br->blockId * BLOCK_DATA_SIZE), len); |
| 417 | char buffer[150]; |
| 418 | sprintf(buffer, "%02X%02X%02X%02X%02X%02X%02X%02X block request %s block %d, len %d checksum %u\0", br->src[7], br->src[6], br->src[5], br->src[4], br->src[3], br->src[2], br->src[1], br->src[0], queueItem->filename, br->blockId, len, checksum); |
| 419 | wsLog((String)buffer); |
| 420 | wsSendUploadProgress(br->src, br->blockId + 1, totalblocks); // live block x/total for the tag card |
| 421 | Serial.printf("<RQB file %s block %d, len %d checksum %u\r\n\0", queueItem->filename, br->blockId, len, checksum); |
| 422 | } |
| 423 | |
| 424 | void processXferComplete(struct espXferComplete* xfc, bool local) { |
| 425 | if (config.runStatus == RUNSTATUS_STOP) { |
no test coverage detected