mirror of
https://github.com/OpenEPaperLink/OpenEPaperLink.git
synced 2026-03-21 12:05:51 +01:00
better use of prepareIdleReq
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
class tagRecord {
|
||||
public:
|
||||
uint16_t nextCheckinpending;
|
||||
tagRecord() : mac{0}, alias(""), lastseen(0), nextupdate(0), contentMode(0), pending(false), md5{0}, md5pending{0}, expectedNextCheckin(0), modeConfigJson(""), LQI(0), RSSI(0), temperature(0), batteryMv(0), hwType(0), wakeupReason(0), capabilities(0), lastfullupdate(0), isExternal(false),
|
||||
tagRecord() : mac{0}, alias(""), lastseen(0), nextupdate(0), contentMode(0), pending(false), md5{0}, md5pending{0}, expectedNextCheckin(0), modeConfigJson(""), LQI(0), RSSI(0), temperature(0), batteryMv(0), hwType(0), wakeupReason(0), capabilities(0), lastfullupdate(0), isExternal(false), pendingIdle(0),
|
||||
filename(""), data(nullptr), len(0) {}
|
||||
|
||||
uint8_t mac[6];
|
||||
@@ -40,6 +40,7 @@ class tagRecord {
|
||||
uint8_t capabilities;
|
||||
uint32_t lastfullupdate;
|
||||
bool isExternal;
|
||||
uint16_t pendingIdle;
|
||||
|
||||
String filename;
|
||||
uint8_t* data;
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "makeimage.h"
|
||||
#include "newproto.h"
|
||||
#include "qrcode.h"
|
||||
#include "settings.h"
|
||||
#include "web.h"
|
||||
|
||||
#define PAL_BLACK 0
|
||||
@@ -43,15 +44,26 @@ void contentRunner() {
|
||||
tagRecord *taginfo = nullptr;
|
||||
taginfo = tagDB.at(c);
|
||||
|
||||
if (taginfo->RSSI && (now >= taginfo->nextupdate || taginfo->wakeupReason == WAKEUP_REASON_GPIO)) {
|
||||
uint8_t mac8[8] = {0, 0, 0, 0, 0, 0, 0, 0};
|
||||
memcpy(mac8 + 2, taginfo->mac, 6);
|
||||
uint8_t src[8];
|
||||
*((uint64_t *)src) = swap64(*((uint64_t *)mac8));
|
||||
uint8_t mac8[8] = {0, 0, 0, 0, 0, 0, 0, 0};
|
||||
memcpy(mac8 + 2, taginfo->mac, 6);
|
||||
uint8_t src[8];
|
||||
*((uint64_t *)src) = swap64(*((uint64_t *)mac8));
|
||||
|
||||
if (taginfo->RSSI && (now >= taginfo->nextupdate || taginfo->wakeupReason == WAKEUP_REASON_GPIO)) {
|
||||
drawNew(src, (taginfo->wakeupReason == WAKEUP_REASON_GPIO), taginfo);
|
||||
taginfo->wakeupReason = 0;
|
||||
}
|
||||
|
||||
if (taginfo->expectedNextCheckin > now - 10 && taginfo->expectedNextCheckin < now + 30 && taginfo->pendingIdle == 0 && taginfo->pending == false) {
|
||||
uint16_t minutesUntilNextUpdate = 0;
|
||||
minutesUntilNextUpdate = (taginfo->nextupdate - now) / 60;
|
||||
if (minutesUntilNextUpdate > MIN_RESPONSE_TIME) minutesUntilNextUpdate = MIN_RESPONSE_TIME;
|
||||
if (minutesUntilNextUpdate > 1) {
|
||||
taginfo->pendingIdle = minutesUntilNextUpdate;
|
||||
prepareIdleReq(src, minutesUntilNextUpdate);
|
||||
}
|
||||
}
|
||||
|
||||
vTaskDelay(1/portTICK_PERIOD_MS); // add a small delay to allow other threads to run
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,29 +69,26 @@ void prepareCancelPending(uint8_t dst[8]) {
|
||||
}
|
||||
|
||||
void prepareIdleReq(uint8_t* dst, uint16_t nextCheckin) {
|
||||
if (nextCheckin > MIN_RESPONSE_TIME) {
|
||||
// to prevent very long sleeps of the tag
|
||||
nextCheckin = MIN_RESPONSE_TIME;
|
||||
if (nextCheckin > MIN_RESPONSE_TIME) nextCheckin = MIN_RESPONSE_TIME;
|
||||
if (nextCheckin > 0) {
|
||||
struct pendingData pending = {0};
|
||||
memcpy(pending.targetMac, dst, 8);
|
||||
pending.availdatainfo.dataType = DATATYPE_NOUPDATE;
|
||||
pending.availdatainfo.nextCheckIn = nextCheckin;
|
||||
pending.attemptsLeft = 10 + MIN_RESPONSE_TIME;
|
||||
|
||||
char buffer[64];
|
||||
uint8_t src[8];
|
||||
*((uint64_t*)src) = swap64(*((uint64_t*)dst));
|
||||
sprintf(buffer, "< %02X%02X%02X%02X%02X%02X idle req\n\0", src[2], src[3], src[4], src[5], src[6], src[7]);
|
||||
Serial.print(buffer);
|
||||
|
||||
sendDataAvail(&pending);
|
||||
}
|
||||
struct pendingData pending = {0};
|
||||
memcpy(pending.targetMac, dst, 8);
|
||||
pending.availdatainfo.dataType = DATATYPE_NOUPDATE;
|
||||
pending.availdatainfo.nextCheckIn = nextCheckin;
|
||||
pending.attemptsLeft = 10 + MIN_RESPONSE_TIME;
|
||||
|
||||
char buffer[64];
|
||||
uint8_t src[8];
|
||||
*((uint64_t*)src) = swap64(*((uint64_t*)dst));
|
||||
Serial.print(buffer);
|
||||
|
||||
sendDataAvail(&pending);
|
||||
}
|
||||
|
||||
bool prepareDataAvail(String* filename, uint8_t dataType, uint8_t* dst, uint16_t nextCheckin) {
|
||||
if (nextCheckin > MIN_RESPONSE_TIME) {
|
||||
//to prevent very long sleeps of the tag
|
||||
nextCheckin = MIN_RESPONSE_TIME;
|
||||
}
|
||||
if (nextCheckin > MIN_RESPONSE_TIME) nextCheckin = MIN_RESPONSE_TIME;
|
||||
|
||||
uint8_t src[8];
|
||||
*((uint64_t*)src) = swap64(*((uint64_t*)dst));
|
||||
@@ -324,19 +321,8 @@ void processXferComplete(struct espXferComplete* xfc) {
|
||||
tagRecord* taginfo = nullptr;
|
||||
taginfo = tagRecord::findByMAC(mac);
|
||||
if (taginfo != nullptr) {
|
||||
|
||||
uint16_t minutesUntilNextUpdate = 0;
|
||||
if (taginfo->nextupdate > now + 2 * 60) {
|
||||
minutesUntilNextUpdate = (taginfo->nextupdate - now) / 60;
|
||||
if (minutesUntilNextUpdate > MIN_RESPONSE_TIME) minutesUntilNextUpdate = MIN_RESPONSE_TIME;
|
||||
taginfo->expectedNextCheckin = now + 60 * minutesUntilNextUpdate + 60;
|
||||
if (minutesUntilNextUpdate > 1) prepareIdleReq (xfc->src, minutesUntilNextUpdate);
|
||||
} else {
|
||||
taginfo->expectedNextCheckin = now + 60;
|
||||
}
|
||||
|
||||
clearPending(taginfo);
|
||||
memcpy(taginfo->md5, taginfo->md5pending, sizeof(taginfo->md5pending));
|
||||
clearPending(taginfo);
|
||||
}
|
||||
wsSendTaginfo(mac);
|
||||
}
|
||||
@@ -381,7 +367,6 @@ void processDataReq(struct espAvailDataReq* eadr) {
|
||||
}
|
||||
time_t now;
|
||||
time(&now);
|
||||
taginfo->lastseen = now;
|
||||
|
||||
if (eadr->src[7] == 0xFF) {
|
||||
taginfo->isExternal = true;
|
||||
@@ -389,15 +374,13 @@ void processDataReq(struct espAvailDataReq* eadr) {
|
||||
taginfo->isExternal = false;
|
||||
}
|
||||
|
||||
uint16_t minutesUntilNextUpdate = 0;
|
||||
if (taginfo->nextupdate > now + 2 * 60) {
|
||||
minutesUntilNextUpdate = (taginfo->nextupdate - now) / 60;
|
||||
if (minutesUntilNextUpdate > MIN_RESPONSE_TIME) minutesUntilNextUpdate = MIN_RESPONSE_TIME;
|
||||
taginfo->expectedNextCheckin = now + 60 * minutesUntilNextUpdate + 60;
|
||||
if (minutesUntilNextUpdate > 1 && taginfo->pending == false) prepareIdleReq(eadr->src, minutesUntilNextUpdate);
|
||||
} else {
|
||||
if (taginfo->pendingIdle == 0) {
|
||||
taginfo->expectedNextCheckin = now + 60;
|
||||
} else {
|
||||
taginfo->expectedNextCheckin = now + 60 * taginfo->pendingIdle;
|
||||
taginfo->pendingIdle = 0;
|
||||
}
|
||||
taginfo->lastseen = now;
|
||||
|
||||
if (eadr->adr.lastPacketRSSI != 0) {
|
||||
taginfo->LQI = eadr->adr.lastPacketLQI;
|
||||
|
||||
Reference in New Issue
Block a user