| 969 | } |
| 970 | |
| 971 | bool 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 |
no test coverage detected