From 7ece72b39a003c9793a77628e93235964c8cfd57 Mon Sep 17 00:00:00 2001 From: dakkar Date: Sat, 2 Apr 2022 12:46:36 +0100 Subject: simple serial command protocol tagged responses, just because --- datalog.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'datalog.h') diff --git a/datalog.h b/datalog.h index 96a3dfd..8f7bd81 100644 --- a/datalog.h +++ b/datalog.h @@ -68,4 +68,26 @@ public: Serial.println("# flushed"); } } + + bool serialCommand(const String &tag, const String &command) { + if (command == "log") { + Serial.print(tag);Serial.println(" begin"); + + uint8_t buffer[1024]; + logfile.flush(); + int remaining = logfile.position(); + logfile.seek(0); + while (remaining > 0) { + int bytesRead = logfile.read(buffer, 1024); + Serial.write(buffer, bytesRead); + remaining -= bytesRead; + } + + Serial.print(tag);Serial.println(" end"); + + return true; + } + + return false; + } }; -- cgit v1.2.3