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

Function queueDataAvail

ESP32_AP-Flasher/src/newproto.cpp:971–1030  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

969}
970
971bool queueDataAvail(struct pendingData* pending, bool local) {
972 PendingItem newPending;
973 newPending.pendingdata.availdatainfo = pending->availdatainfo;
974 newPending.pendingdata.attemptsLeft = pending->attemptsLeft;
975 std::copy(pending->targetMac, pending->targetMac + sizeof(pending->targetMac), newPending.pendingdata.targetMac);
976
977 tagRecord* taginfo = tagRecord::findByMAC(pending->targetMac);
978
979 if (taginfo == nullptr) {
980 return false;
981 }
982
983 std::strcpy(newPending.filename, taginfo->filename.c_str());
984 if (taginfo->data != nullptr) {
985 // move data pointer
986 newPending.data = taginfo->data;
987 taginfo->data = nullptr;
988 } else {
989 newPending.data = nullptr;
990
991 if (pendingQueue.size() < 5) { // maximized to 5 to save some memory
992 // optional: read data early, don't wait for block request.
993 fs::File file = contentFS->open(newPending.filename);
994 if (file) {
995 newPending.data = getDataForFile(file);
996 Serial.println("Reading file " + String(newPending.filename));
997 file.close();
998 } else {
999 Serial.println("Warning: not found: " + String(newPending.filename));
1000 }
1001 }
1002 }
1003 newPending.len = taginfo->len;
1004
1005 uint8_t dataType = pending->availdatainfo.dataType;
1006 if (dataType != DATATYPE_FW_UPDATE && dataType != DATATYPE_NOUPDATE && pending->availdatainfo.dataTypeArgument & 0xF8 == 0x00) {
1007 // in case of an image (no preload), remove already queued images
1008 pendingQueue.erase(std::remove_if(pendingQueue.begin(), pendingQueue.end(),
1009 [pending](const PendingItem& item) {
1010 bool macMatches = memcmp(item.pendingdata.targetMac, pending->targetMac, sizeof(item.pendingdata.targetMac)) == 0;
1011 bool dataTypeArgumentMatches = (pending->availdatainfo.dataType == item.pendingdata.availdatainfo.dataType) && ((item.pendingdata.availdatainfo.dataTypeArgument & 0xF8) == 0x00);
1012 return macMatches && dataTypeArgumentMatches;
1013 }),
1014 pendingQueue.end());
1015 }
1016
1017 enqueueItem(newPending);
1018 taginfo->pendingCount = countQueueItem(pending->targetMac);
1019 if (taginfo->pendingCount == 1) {
1020 Serial.printf("queue item added, first in line\r\n");
1021 // if (local) sendDataAvail(pending);
1022 } else {
1023 Serial.printf("queue item added, total %d elements\r\n", taginfo->pendingCount);
1024 // to do: notify C6 to shorten the checkin time for the current SDA
1025 }
1026
1027 if (local) checkQueue(pending->targetMac);
1028

Callers 7

prepareDataAvailFunction · 0.85
prepareExternalDataAvailFunction · 0.85
sendAPSegmentedDataFunction · 0.85
showAPSegmentedInfoFunction · 0.85
sendTagCommandFunction · 0.85
sendTagMacFunction · 0.85
checkMirrorFunction · 0.85

Calls 13

strcpyFunction · 0.85
getDataForFileFunction · 0.85
memcmpFunction · 0.85
enqueueItemFunction · 0.85
countQueueItemFunction · 0.85
checkQueueFunction · 0.85
openMethod · 0.80
printlnMethod · 0.80
closeMethod · 0.80
printfMethod · 0.80
sizeMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected