diff --git a/filer.cpp b/filer.cpp index 80a7f75..4891ec8 100644 --- a/filer.cpp +++ b/filer.cpp @@ -22,17 +22,14 @@ static File file; static Dir dir; #endif -static const char *programs; - #define STORAGE defined(USE_SD) || defined(USE_SPIFFS) || defined(USE_FS) -bool flash_filer::start(const char *programs) +bool flash_filer::start() { - ::programs = programs; #if defined(USE_FS) - dir = SPIFFS.openDir(programs); + dir = SPIFFS.openDir(_programs); #elif defined(DISK) - dir = DISK.open(programs); + dir = DISK.open(_programs); if (!dir) return false; #endif @@ -72,7 +69,7 @@ const char *flash_filer::advance() { file = dir.openFile("r"); break; } - dir = SPIFFS.openDir(programs); + dir = SPIFFS.openDir(_programs); } strncpy(buf, dir.fileName().c_str(), sizeof(buf)); return buf; @@ -112,7 +109,7 @@ static int cpid = 0; const char *flash_filer::checkpoint() { #if defined(USE_SD) || defined(USE_SPIFFS) || defined(ESP8266) stop(); - snprintf(buf, sizeof(buf), "%s%s.%03d", ::programs, chkpt, cpid++); + snprintf(buf, sizeof(buf), "%s%s.%03d", _programs, chkpt, cpid++); #if defined(USE_SD) File file = SD.open(buf, O_WRITE | O_CREAT | O_TRUNC); @@ -123,7 +120,7 @@ const char *flash_filer::checkpoint() { #endif hardware_checkpoint(file); file.close(); - start(::programs); + start(); #endif return buf; } @@ -131,7 +128,7 @@ const char *flash_filer::checkpoint() { void flash_filer::restore(const char *filename) { #if defined(USE_SD) || defined(USE_SPIFFS) || defined(ESP8266) stop(); - snprintf(buf, sizeof(buf), "%s%s", ::programs, filename); + snprintf(buf, sizeof(buf), "%s%s", _programs, filename); #if defined(USE_SD) File file = SD.open(buf, O_READ); @@ -142,9 +139,9 @@ void flash_filer::restore(const char *filename) { #endif hardware_restore(file); file.close(); - int n = sscanf(buf + strlen(::programs), "%[A-Z0-9].%d", chkpt, &cpid); + int n = sscanf(buf + strlen(_programs), "%[A-Z0-9].%d", chkpt, &cpid); cpid = (n == 1)? 0: cpid+1; #endif - start(::programs); + start(); } #endif diff --git a/filer.h b/filer.h index a300efa..53de1e8 100644 --- a/filer.h +++ b/filer.h @@ -9,7 +9,7 @@ public: virtual const char *checkpoint() =0; virtual void restore(const char *) = 0; - virtual bool start(const char *) =0; + virtual bool start() =0; virtual void stop() =0; }; @@ -17,19 +17,22 @@ public: // implement write to new file (like checkpoint) class flash_filer: public filer { public: + flash_filer(const char *programs): _programs(programs) {} + const char *advance(); const char *rewind(); const char *checkpoint(); void restore(const char *); - bool start(const char *); + bool start(); void stop(); uint8_t read() { return _buf[_pos++]; } bool more(); private: + const char *_programs; unsigned _pos, _len; uint8_t _buf[128]; }; diff --git a/r65emu.h b/r65emu.h index 5c641df..0398db3 100644 --- a/r65emu.h +++ b/r65emu.h @@ -12,6 +12,7 @@ #include "serialio.h" #include "filer.h" #include "serial_filer.h" +#include "socket_filer.h" #include "timed.h" #include "hardware.h" #include "sound_dac.h" diff --git a/serial_filer.cpp b/serial_filer.cpp index a307200..a6a972d 100644 --- a/serial_filer.cpp +++ b/serial_filer.cpp @@ -5,10 +5,6 @@ #include "filer.h" #include "serial_filer.h" -bool serial_filer::start(const char *) { - return true; -} - const unsigned speeds[] = { 115200, 57600, 19200, 9600, 4800, 2400 }; @@ -16,7 +12,7 @@ const unsigned speeds[] = { const char *serial_filer::advance() { static char buf[16]; unsigned s = speeds[_currsp]; - Serial.begin(s); + _serial.begin(s); _currsp++; if (_currsp == sizeof(speeds)/sizeof(speeds[0])) _currsp = 0; @@ -24,15 +20,15 @@ const char *serial_filer::advance() { } void serial_filer::write(uint8_t b) { - Serial.write(b); + _serial.write(b); } uint8_t serial_filer::read() { - return Serial.read(); + return _serial.read(); } bool serial_filer::more() { - return Serial.available() > 0; + return _serial.available() > 0; } #if !defined(NO_CHECKPOINT) diff --git a/serial_filer.h b/serial_filer.h index 94b3a50..260faa9 100644 --- a/serial_filer.h +++ b/serial_filer.h @@ -1,17 +1,21 @@ #ifndef __SERIAL_FILER_H__ #define __SERIAL_FILER_H__ +class HardwareSerial; + // see https://playground.arduino.cc/Interfacing/LinuxTTY // FIXME: do this in minicom config file class serial_filer: public filer { public: + serial_filer(HardwareSerial &serial): _serial(serial) {} + const char *advance(); const char *rewind() { _currsp = 0; return advance(); } const char *checkpoint(); void restore(const char *); - bool start(const char *); + bool start() { return true; } void stop() {} uint8_t read(); @@ -19,6 +23,7 @@ public: void write(uint8_t); private: + HardwareSerial &_serial; unsigned _currsp; }; #endif diff --git a/socket_filer.cpp b/socket_filer.cpp index 5e00e81..d23a62b 100644 --- a/socket_filer.cpp +++ b/socket_filer.cpp @@ -7,7 +7,7 @@ #if !defined(ESP32) #pragma message "no socket filer" -#else +#elif defined(WIFI_SSID) #include static WiFiServer server(23); @@ -20,11 +20,11 @@ static bool connected() { return client.connected(); } -// FIXME: hostname -bool socket_filer::start(const char *) { +bool socket_filer::start() { #if defined(WIFI_SSID) WiFi.begin(WIFI_SSID, WIFI_PASSWORD); + WiFi.setHostname(_hostname); for (int i=0; i < 60 && WiFi.status() != WL_CONNECTED; i++) delay(1000); diff --git a/socket_filer.h b/socket_filer.h index 64b442b..1a3048c 100644 --- a/socket_filer.h +++ b/socket_filer.h @@ -3,17 +3,22 @@ class socket_filer: public filer { public: + socket_filer(const char *hostname): _hostname(hostname) {} + const char *advance() { return 0; } const char *rewind() { return advance(); } const char *checkpoint(); void restore(const char *); - bool start(const char *); + bool start(); void stop() {} uint8_t read(); bool more(); void write(uint8_t); + +private: + const char *_hostname; }; #endif