bugfix deleting unknown tag / WIP locking

- bugfix: unable to delete unknown tag by right clicking
- work in progress: lock tag inventory, by rejecting new tags
This commit is contained in:
Nic Limper
2023-12-29 23:19:16 +01:00
parent a962828c4f
commit bcd2a4618d
8 changed files with 50 additions and 17 deletions

Binary file not shown.

View File

@@ -69,6 +69,7 @@ struct Config {
uint8_t stopsleep;
uint8_t runStatus;
uint8_t preview;
uint8_t lock;
uint8_t wifiPower;
char timeZone[52];
uint8_t sleepTime1;

View File

@@ -56,6 +56,7 @@ void prepareCancelPending(const uint8_t dst[8]) {
tagRecord* taginfo = tagRecord::findByMAC(dst);
if (taginfo == nullptr) {
if (config.lock) return;
wsErr("Tag not found, this shouldn't happen.");
return;
}
@@ -80,6 +81,7 @@ void prepareIdleReq(const uint8_t* dst, uint16_t nextCheckin) {
void prepareDataAvail(uint8_t* data, uint16_t len, uint8_t dataType, const uint8_t* dst) {
tagRecord* taginfo = tagRecord::findByMAC(dst);
if (taginfo == nullptr) {
if (config.lock) return;
wsErr("Tag not found, this shouldn't happen.");
return;
}
@@ -129,6 +131,7 @@ bool prepareDataAvail(String& filename, uint8_t dataType, uint8_t dataTypeArgume
tagRecord* taginfo = tagRecord::findByMAC(dst);
if (taginfo == nullptr) {
if (config.lock) return true;
wsErr("Tag not found, this shouldn't happen.");
return true;
}
@@ -345,6 +348,7 @@ void processBlockRequest(struct espBlockRequest* br) {
tagRecord* taginfo = tagRecord::findByMAC(br->src);
if (taginfo == nullptr) {
if (config.lock) return;
prepareCancelPending(br->src);
Serial.printf("blockrequest: couldn't find taginfo %02X%02X%02X%02X%02X%02X%02X%02X\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]);
return;
@@ -458,6 +462,7 @@ void processDataReq(struct espAvailDataReq* eadr, bool local, IPAddress remoteIP
tagRecord* taginfo = tagRecord::findByMAC(eadr->src);
if (taginfo == nullptr) {
if (config.lock) return;
taginfo = new tagRecord;
memcpy(taginfo->mac, eadr->src, sizeof(taginfo->mac));
taginfo->pending = false;
@@ -657,6 +662,7 @@ void updateTaginfoitem(struct TagInfo* taginfoitem, IPAddress remoteIP) {
tagRecord* taginfo = tagRecord::findByMAC(taginfoitem->mac);
if (taginfo == nullptr) {
if (config.lock) return;
taginfo = new tagRecord;
memcpy(taginfo->mac, taginfoitem->mac, sizeof(taginfo->mac));
taginfo->pending = false;

View File

@@ -130,9 +130,17 @@ void saveDB(const String& filename) {
Storage.begin();
xSemaphoreTake(fsMutex, portMAX_DELAY);
fs::File existingFile = contentFS->open(filename, "r");
if (existingFile) {
existingFile.close();
String backupFilename = filename + ".bak";
contentFS->rename(filename.c_str(), backupFilename.c_str());
}
fs::File file = contentFS->open(filename, "w");
if (!file) {
Serial.println("saveDB: Failed to open file");
Serial.println("saveDB: Failed to open file for writing");
xSemaphoreGive(fsMutex);
return;
}
@@ -307,6 +315,7 @@ void initAPconfig() {
config.maxsleep = APconfig["maxsleep"] | 10;
config.stopsleep = APconfig["stopsleep"] | 1;
config.preview = APconfig["preview"] | 1;
config.lock = APconfig["lock"] | 0;
config.sleepTime1 = APconfig["sleeptime1"] | 0;
config.sleepTime2 = APconfig["sleeptime2"] | 0;
// default wifi power 8.5 dbM
@@ -333,6 +342,7 @@ void saveAPconfig() {
APconfig["maxsleep"] = config.maxsleep;
APconfig["stopsleep"] = config.stopsleep;
APconfig["preview"] = config.preview;
APconfig["lock"] = config.lock;
APconfig["wifipower"] = config.wifiPower;
APconfig["timezone"] = config.timeZone;
APconfig["sleeptime1"] = config.sleepTime1;

View File

@@ -471,6 +471,9 @@ void init_web() {
if (request->hasParam("preview", true)) {
config.preview = static_cast<uint8_t>(request->getParam("preview", true)->value().toInt());
}
if (request->hasParam("lock", true)) {
config.lock = static_cast<uint8_t>(request->getParam("lock", true)->value().toInt());
}
if (request->hasParam("sleeptime1", true)) {
config.sleepTime1 = static_cast<uint8_t>(request->getParam("sleeptime1", true)->value().toInt());
config.sleepTime2 = static_cast<uint8_t>(request->getParam("sleeptime2", true)->value().toInt());

View File

@@ -327,6 +327,14 @@
<option value="0">no</option>
</select>
</p>
<p title="* Work in progress * When locking the tag inventory, the AP will only show tags that are already in the database.
For now, the AP will still keep answering new tags, because that needs to be fixed in the radio firmware. This will probably change in the future.">
<label for="apclock">Lock tag inventory</label>
<select id="apclock">
<option value="1">yes</option>
<option value="0" selected>no</option>
</select>
</p>
<p title="Wifi transmit power">
<label for="apcwifipower">Wifi power</label>
<select id="apcwifipower">

View File

@@ -590,6 +590,7 @@ document.addEventListener("loadTab", function (event) {
$("#apclatency").value = data.maxsleep;
$("#apcpreventsleep").value = data.stopsleep;
$("#apcpreview").value = data.preview;
$("#apclock").value = data.lock;
$("#apcwifipower").value = data.wifipower;
$("#apctimezone").value = data.timezone;
$("#apcnight1").value = data.sleeptime1;
@@ -614,6 +615,7 @@ $('#apcfgsave').onclick = function () {
formData.append('maxsleep', $('#apclatency').value);
formData.append('stopsleep', $('#apcpreventsleep').value);
formData.append('preview', $('#apcpreview').value);
formData.append('lock', $('#apclock').value);
formData.append('wifipower', $('#apcwifipower').value);
formData.append('timezone', $('#apctimezone').value);
formData.append('sleeptime1', $('#apcnight1').value);
@@ -858,7 +860,7 @@ function processQueue() {
return;
}
const { id, imageSrc } = imageQueue.shift();
const hwtype = $('#tag' + id).dataset.hwtype;
const hwtype = $('#tag' + id).dataset?.hwtype;
if (tagTypes[hwtype]?.busy) {
imageQueue.push({ id, imageSrc });
setTimeout(processQueue, 100);
@@ -1076,7 +1078,7 @@ async function getTagtype(hwtype) {
tagTypes[hwtype] = { busy: true };
const response = await fetch('/tagtypes/' + hwtype.toString(16).padStart(2, '0').toUpperCase() + '.json');
if (!response.ok) {
let data = { name: 'unknown id ' + hwtype, width: 0, height: 0, bpp: 0, rotatebuffer: 0, colortable: [], busy: false };
let data = { name: 'unknown id ' + hwtype.toString(16), width: 0, height: 0, bpp: 0, rotatebuffer: 0, colortable: [], busy: false };
tagTypes[hwtype] = data;
getTagtypeBusy = false;
return data;
@@ -1231,22 +1233,25 @@ $('#taglist').addEventListener('contextmenu', (e) => {
if (clickedGridItem) {
let mac = clickedGridItem.dataset.mac;
const hwtype = clickedGridItem.dataset.hwtype;
let contextMenuOptions = [
{ id: 'refresh', label: 'Force refresh' },
{ id: 'clear', label: 'Clear pending status' }
];
if (clickedGridItem.dataset.isexternal == "false") {
let contextMenuOptions = [];
if (tagTypes[hwtype]?.width > 0) {
contextMenuOptions.push(
{ id: 'scan', label: 'Scan channels' },
{ id: 'reboot', label: 'Reboot tag' },
);
};
if (tagTypes[hwtype].options?.includes("led")) {
contextMenuOptions.push(
{ id: 'ledflash', label: 'Flash the LED' },
{ id: 'ledflash_long', label: 'Flash the LED (long)' },
{ id: 'ledflash_stop', label: 'Stop flashing' }
{ id: 'refresh', label: 'Force refresh' },
{ id: 'clear', label: 'Clear pending status' }
);
if (clickedGridItem.dataset.isexternal == "false") {
contextMenuOptions.push(
{ id: 'scan', label: 'Scan channels' },
{ id: 'reboot', label: 'Reboot tag' },
);
};
if (tagTypes[hwtype]?.options?.includes("led")) {
contextMenuOptions.push(
{ id: 'ledflash', label: 'Flash the LED' },
{ id: 'ledflash_long', label: 'Flash the LED (long)' },
{ id: 'ledflash_stop', label: 'Stop flashing' }
);
}
}
contextMenuOptions.push(
{ id: 'del', label: 'Delete tag from list' }