From 294640989640876ac47159709db841722850f8c0 Mon Sep 17 00:00:00 2001 From: Andrey Klimov Date: Tue, 5 Oct 2021 03:44:31 +0300 Subject: [PATCH] interim (compiled) commit --- lighthub/config.h | 4 +- lighthub/flashstream.h | 116 +++++++++++++++++++++++--------------- lighthub/main.cpp | 69 ++++++++++------------- lighthub/seekablestream.h | 25 ++++++++ 4 files changed, 128 insertions(+), 86 deletions(-) create mode 100644 lighthub/seekablestream.h diff --git a/lighthub/config.h b/lighthub/config.h index 0dd9800..d315aa9 100644 --- a/lighthub/config.h +++ b/lighthub/config.h @@ -61,9 +61,9 @@ class systemConfig { int openStream(char mode = '\0') { #if defined(FS_STORAGE) - stream.open("/config.bin",mode); + stream->open("/config.bin",mode); #else - stream.open(EEPROM_offsetJSON,mode); + stream->open(EEPROM_offsetJSON,mode); #endif }; diff --git a/lighthub/flashstream.h b/lighthub/flashstream.h index d538594..d48c3da 100644 --- a/lighthub/flashstream.h +++ b/lighthub/flashstream.h @@ -3,6 +3,7 @@ #define _FLASHSTREAM_H_ #include +#include #if defined(FS_STORAGE) #include @@ -40,21 +41,9 @@ extern NRFFlashStorage EEPROM; #include #include +#include "seekablestream.h" -class seekableStream : public Stream -{ -protected: -unsigned int streamSize; -bool textMode; - -public: -seekableStream(unsigned int size):Stream(),streamSize(size) {}; -unsigned int getSize() {return streamSize;} -virtual unsigned int seek(unsigned int _pos = 0) = 0; -virtual int open(unsigned int _startPos=0, unsigned int _size=4096, char mode='\0') = 0; -virtual int open(String _filename, char mode='\0') = 0; -virtual void close() = 0; -}; +#define EOF 255 #if defined(FS_STORAGE) class flashStream : public seekableStream @@ -64,16 +53,43 @@ String filename; char openedMode; File fs; public: -flashStream(String _filename):seekableStream(65535) +flashStream():seekableStream(65535) { - filename=_filename; openedMode='\0'; - open('r'); - } - virtual int open(String _filename, char mode='\0') + //fs = 0; + filename = ""; + // open('r'); + }; + + virtual int open(String _filename, char mode) override { - textMode = _filename suffix == txt or json - open file + char modestr[2]; + modestr[0]=mode; modestr[1]=0; + filename=_filename; + + if (fs = SPIFFS.open(_filename,modestr)) + { + openedMode=mode; + //fs.seek(savedPos); + + if (_filename.endsWith(".json")) {contentType=HTTP_TEXT_JSON;textMode=true;} + else if (_filename.endsWith(".bin")) {contentType=HTTP_OCTET_STREAM;textMode=false;} + else if (_filename.endsWith(".txt")) {contentType=HTTP_TEXT_PLAIN;textMode=true;} + + + debugSerial<<("Opened/")<1) #else //JSONStream.open('w'); //JSONStream.seek(); - aJsonStream jsonEEPROMStream = aJsonStream(&JSONStream); + aJsonStream jsonEEPROMStream = aJsonStream(&sysConfStream); infoSerial< +#include + +class seekableStream : public Stream +{ +protected: +unsigned int streamSize; +bool textMode; +uint16_t contentType; + +public: +seekableStream(unsigned int size):Stream(),streamSize(size) {}; +unsigned int getSize() {return streamSize;} +virtual unsigned int seek(unsigned int _pos = 0) = 0; +//virtual int open(unsigned int _startPos=0, unsigned int _size=4096, char mode='\0') = 0; +virtual int open(String _filename, char mode) = 0; +virtual void close() = 0; +virtual uint16_t getContentType() {return contentType;}; +virtual void putEOF() {if (textMode) write (EOF);}; +}; + +#endif \ No newline at end of file