From eda693abdfb91ab2bb842143eac35a16078868cd Mon Sep 17 00:00:00 2001 From: scilor Date: Sun, 18 Jul 2021 22:49:12 +0200 Subject: [PATCH 1/4] Prepare config for autodump (comments) --- BoxConfig.cpp | 27 ++++++++++++++++++++++++--- ConfigStructures.h | 5 +++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/BoxConfig.cpp b/BoxConfig.cpp index 332b066..ef011e2 100644 --- a/BoxConfig.cpp +++ b/BoxConfig.cpp @@ -73,7 +73,11 @@ String BoxConfig::getAsJson() { JsonObject logDoc = doc.createNestedObject("log"); ConfigLog* logCfg = &_config.log; logDoc["sdLog"] = logCfg->sdLog; - +/* + JsonObject miscDoc = doc.createNestedObject("misc"); + ConfigMisc* miscCfg = &_config.misc; + miscDoc["autodump"] = miscCfg->autodump; +*/ serializeJson(doc, json); return json; } @@ -110,17 +114,31 @@ bool BoxConfig::setFromJson(String json) { ConfigLog* logCfg = &_config.log; logCfg->sdLog = logDoc["sdLog"].as(); + /* + JsonObject miscDoc = doc["misc"]; + ConfigMisc* miscCfg = &_config.misc; + miscCfg->autodump = logDoc["autodump"].as(); + */ + // Convert old config version to latest one. if (_config.version != CONFIG_ACTIVE_VERSION) { switch (_config.version) { case 2: batteryCfg->criticalAdc = batteryDoc["minimalAdc"].as(); batteryCfg->lowAdc = batteryCfg->criticalAdc + 100; - _config.version = CONFIG_ACTIVE_VERSION; + _config.version = 3; + write(); break; - + /* + case 3: + miscCfg->autodump = false; + _config.version = 4; + write(); + break; + */ default: _initializeConfig(); + write(); break; } } @@ -153,4 +171,7 @@ void BoxConfig::_initializeConfig() { ConfigLog* log = &_config.log; log->sdLog = false; + + ConfigMisc* misc = &_config.misc; + misc->autodump = false; } \ No newline at end of file diff --git a/ConfigStructures.h b/ConfigStructures.h index 54d358b..81bf7e1 100644 --- a/ConfigStructures.h +++ b/ConfigStructures.h @@ -39,12 +39,17 @@ typedef struct { bool sdLog; } ConfigLog; +typedef struct { + bool autodump; +} ConfigMisc; + typedef struct { uint8_t version; ConfigBattery battery; ConfigButtonEars buttonEars; ConfigWifi wifi; ConfigLog log; + ConfigMisc misc; } ConfigStruct; #endif \ No newline at end of file From 4b54ec2e42fdb05cbe1637dfd385b210ece15273 Mon Sep 17 00:00:00 2001 From: scilor Date: Sun, 18 Jul 2021 22:49:31 +0200 Subject: [PATCH 2/4] ignore vscode --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index e673d35..af0c826 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ ConfigStatic.h +.vscode/* From e35015ef4dffc8d3a195bc1c8d129b4c6ccd2e93 Mon Sep 17 00:00:00 2001 From: scilor Date: Sun, 18 Jul 2021 22:50:26 +0200 Subject: [PATCH 3/4] add missing free() --- BoxEvents.cpp | 2 ++ BoxTonies.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/BoxEvents.cpp b/BoxEvents.cpp index 2703de8..4f0a706 100644 --- a/BoxEvents.cpp +++ b/BoxEvents.cpp @@ -292,8 +292,10 @@ void BoxEvents::handleTagEvent(BoxRFID::TAG_EVENT event) { ); free(path); Box.boxDAC.playFile((const char*)filepath); + free(filepath); } } + free(path); } break; case BoxRFID::TAG_EVENT::TAG_REMOVED: diff --git a/BoxTonies.cpp b/BoxTonies.cpp index 33c88db..b5371b6 100644 --- a/BoxTonies.cpp +++ b/BoxTonies.cpp @@ -12,8 +12,10 @@ bool BoxTonies::loadTonieByUid(uint8_t uid[8]) { memcpy(currentUid, uid, 8); if (loadTonieByPath(path)) { + free(path); return true; } + free(path); return false; } From 5603eae34f7a19149f0f3d170668b43b1e237cdb Mon Sep 17 00:00:00 2001 From: scilor Date: Sun, 18 Jul 2021 22:50:49 +0200 Subject: [PATCH 4/4] Add memory block read --- BoxCLI.cpp | 15 ++++++ BoxEvents.cpp | 19 ++++++- BoxRFID.cpp | 124 ++++++++++++++++++++++++++++++++++++++++++- BoxRFID.h | 12 ++++- WrapperWebServer.cpp | 16 ++++++ 5 files changed, 182 insertions(+), 4 deletions(-) diff --git a/BoxCLI.cpp b/BoxCLI.cpp index e8bac0c..e5593bd 100644 --- a/BoxCLI.cpp +++ b/BoxCLI.cpp @@ -34,6 +34,9 @@ void BoxCLI::begin() { cmdRFID.setDescription(" Access RFID"); cmdRFID.addFlagArg("u/id"); cmdRFID.addFlagArg("r/ead"); + cmdRFID.addFlagArg("m/emory"); + cmdRFID.addFlagArg("d/ump"); + cmdRFID.addFlagArg("o/verwrite"); cmdLoad = cli.addCmd("load"); cmdLoad.setDescription(" Shows the current load of all threads"); @@ -280,6 +283,18 @@ void BoxCLI::execRFID() { Log.error("No tag in place, last known is shown"); } Box.boxRFID.logUID(); + } else if (c.getArg("memory").isSet()) { + Box.boxRFID.loop(); + if (!Box.boxRFID.tagActive) { + Log.error("No tag in place"); + } + Box.boxRFID.logTagMemory(); + } else if (c.getArg("dump").isSet()) { + Box.boxRFID.loop(); + if (!Box.boxRFID.tagActive) { + Log.error("No tag in place"); + } + Box.boxRFID.dumpTagMemory(c.getArg("overwrite").isSet()); } else { Log.error("Nothing to do..."); } diff --git a/BoxEvents.cpp b/BoxEvents.cpp index 4f0a706..98c1bbd 100644 --- a/BoxEvents.cpp +++ b/BoxEvents.cpp @@ -259,14 +259,30 @@ void BoxEvents::handleTagEvent(BoxRFID::TAG_EVENT event) { uid[0], uid[1], uid[2], uid[3], uid[4], uid[5], uid[6], uid[7] ); + //Needs tooo much heap memory?! + //if(/*Config.get()->misc.autodump*/) { + if (Box.boxRFID.dumpTagMemory(false)) { + //Box.boxDAC.beep(); + //Box.boxLEDs.setActiveAnimationByIteration(BoxLEDs::ANIMATION_TYPE::BLINK, BoxLEDs::CRGB::Yellow, 5); + //Box.boxLEDs.waitForAnimationToFinish(); + } + //} + DirFs dir; char* rcontent = "/rCONTENT"; - if (!dir.openDir(rcontent)){ + if (!dir.openDir(rcontent)) { Log.info("Creating missing dir %s...", rcontent); if (!FatFs.mkdir(rcontent)) { Log.info("...failed!"); } } + char* rdump = "/rDUMP"; + if (!dir.openDir(rdump)) { + Log.info("Creating missing dir %s...", rdump); + if (!FatFs.mkdir(rdump)) { + Log.info("...failed!"); + } + } if (!dir.openDir((char*)path)) { Log.info("Creating missing dir %s...", path); if (!FatFs.mkdir((char*)path)) { @@ -290,7 +306,6 @@ void BoxEvents::handleTagEvent(BoxRFID::TAG_EVENT event) { path, dir.fileName() ); - free(path); Box.boxDAC.playFile((const char*)filepath); free(filepath); } diff --git a/BoxRFID.cpp b/BoxRFID.cpp index 6753c52..cd734d2 100644 --- a/BoxRFID.cpp +++ b/BoxRFID.cpp @@ -360,6 +360,45 @@ void BoxRFID::sendRawSPI(uint8_t* buffer, uint8_t length, bool continuedSend) { spiDisable(); } +BoxRFID::ISO15693_RESULT BoxRFID::ISO15693_readSingleBlock(uint8_t blockId, uint8_t* blockData) { + uint8_t offset = 0; + + trfBuffer[offset++] = 0x02; // ISO15693 flags - ISO15693_REQ_DATARATE_HIGH + trfBuffer[offset++] = 0x20; // Read Single BLock + /* + bool withUid = true; + if (withUid) { + trfBuffer[0] = trfBuffer[0] || 0x20 || 0x10; // ISO15693_REQ_DATARATE_HIGH || ISO15693_REQ_ADDRESS || ISO15693_REQ_OPTION + for (uint8_t i= 0; i<8; i++) { + trfBuffer[offset++] = tagUid[i]; + } + }*/ + trfBuffer[offset++] = blockId; // BlockId + + trfStatus = sendDataTag(&trfBuffer[0], offset); + if (trfStatus == TRF_STATUS::RX_COMPLETE) { // If data has been received + if (trfBuffer[0] == 0x00) { // Confirm "no error" in response flags byte + if (trfRxLength == 5) { + // data Starts at the 2rd received byte, length = 4 + for (uint8_t i=0; i<4; i++) { + blockData[i] = trfBuffer[i+1]; + } + return ISO15693_RESULT::READ_SINGLE_BLOCK_VALID_RESPONSE; + } else { + Log.error("Received invalid answer. Length should be %i but is %i", 5, trfRxLength); + for (uint8_t i=0; isend(200, "text/json", json); return; + } else if (sub.equals("memory")) { + StaticJsonDocument<512> memoryContent; //Size from https://arduinojson.org/v6/assistant/ + uint8_t data[32]; + uint8_t bytesRead; + bytesRead = Box.boxRFID.readBlocks(data, 32); + if (bytesRead == 32) { + for (uint8_t i=0; isend(200, "text/json", json); + return; + } } } else if (cmd.equals("cli")) { _server->setContentLength(CONTENT_LENGTH_UNKNOWN); // the payload can go on forever