mirror of
https://github.com/jscrane/r65emu.git
synced 2025-01-13 23:30:02 +00:00
configure filers via ctor
This commit is contained in:
parent
e90fb2c6e7
commit
d7c82c67a1
21
filer.cpp
21
filer.cpp
@ -22,17 +22,14 @@ static File file;
|
|||||||
static Dir dir;
|
static Dir dir;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static const char *programs;
|
|
||||||
|
|
||||||
#define STORAGE defined(USE_SD) || defined(USE_SPIFFS) || defined(USE_FS)
|
#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)
|
#if defined(USE_FS)
|
||||||
dir = SPIFFS.openDir(programs);
|
dir = SPIFFS.openDir(_programs);
|
||||||
#elif defined(DISK)
|
#elif defined(DISK)
|
||||||
dir = DISK.open(programs);
|
dir = DISK.open(_programs);
|
||||||
if (!dir)
|
if (!dir)
|
||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
@ -72,7 +69,7 @@ const char *flash_filer::advance() {
|
|||||||
file = dir.openFile("r");
|
file = dir.openFile("r");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
dir = SPIFFS.openDir(programs);
|
dir = SPIFFS.openDir(_programs);
|
||||||
}
|
}
|
||||||
strncpy(buf, dir.fileName().c_str(), sizeof(buf));
|
strncpy(buf, dir.fileName().c_str(), sizeof(buf));
|
||||||
return buf;
|
return buf;
|
||||||
@ -112,7 +109,7 @@ static int cpid = 0;
|
|||||||
const char *flash_filer::checkpoint() {
|
const char *flash_filer::checkpoint() {
|
||||||
#if defined(USE_SD) || defined(USE_SPIFFS) || defined(ESP8266)
|
#if defined(USE_SD) || defined(USE_SPIFFS) || defined(ESP8266)
|
||||||
stop();
|
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)
|
#if defined(USE_SD)
|
||||||
File file = SD.open(buf, O_WRITE | O_CREAT | O_TRUNC);
|
File file = SD.open(buf, O_WRITE | O_CREAT | O_TRUNC);
|
||||||
@ -123,7 +120,7 @@ const char *flash_filer::checkpoint() {
|
|||||||
#endif
|
#endif
|
||||||
hardware_checkpoint(file);
|
hardware_checkpoint(file);
|
||||||
file.close();
|
file.close();
|
||||||
start(::programs);
|
start();
|
||||||
#endif
|
#endif
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
@ -131,7 +128,7 @@ const char *flash_filer::checkpoint() {
|
|||||||
void flash_filer::restore(const char *filename) {
|
void flash_filer::restore(const char *filename) {
|
||||||
#if defined(USE_SD) || defined(USE_SPIFFS) || defined(ESP8266)
|
#if defined(USE_SD) || defined(USE_SPIFFS) || defined(ESP8266)
|
||||||
stop();
|
stop();
|
||||||
snprintf(buf, sizeof(buf), "%s%s", ::programs, filename);
|
snprintf(buf, sizeof(buf), "%s%s", _programs, filename);
|
||||||
|
|
||||||
#if defined(USE_SD)
|
#if defined(USE_SD)
|
||||||
File file = SD.open(buf, O_READ);
|
File file = SD.open(buf, O_READ);
|
||||||
@ -142,9 +139,9 @@ void flash_filer::restore(const char *filename) {
|
|||||||
#endif
|
#endif
|
||||||
hardware_restore(file);
|
hardware_restore(file);
|
||||||
file.close();
|
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;
|
cpid = (n == 1)? 0: cpid+1;
|
||||||
#endif
|
#endif
|
||||||
start(::programs);
|
start();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
7
filer.h
7
filer.h
@ -9,7 +9,7 @@ public:
|
|||||||
virtual const char *checkpoint() =0;
|
virtual const char *checkpoint() =0;
|
||||||
virtual void restore(const char *) = 0;
|
virtual void restore(const char *) = 0;
|
||||||
|
|
||||||
virtual bool start(const char *) =0;
|
virtual bool start() =0;
|
||||||
virtual void stop() =0;
|
virtual void stop() =0;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -17,19 +17,22 @@ public:
|
|||||||
// implement write to new file (like checkpoint)
|
// implement write to new file (like checkpoint)
|
||||||
class flash_filer: public filer {
|
class flash_filer: public filer {
|
||||||
public:
|
public:
|
||||||
|
flash_filer(const char *programs): _programs(programs) {}
|
||||||
|
|
||||||
const char *advance();
|
const char *advance();
|
||||||
const char *rewind();
|
const char *rewind();
|
||||||
|
|
||||||
const char *checkpoint();
|
const char *checkpoint();
|
||||||
void restore(const char *);
|
void restore(const char *);
|
||||||
|
|
||||||
bool start(const char *);
|
bool start();
|
||||||
void stop();
|
void stop();
|
||||||
|
|
||||||
uint8_t read() { return _buf[_pos++]; }
|
uint8_t read() { return _buf[_pos++]; }
|
||||||
bool more();
|
bool more();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
const char *_programs;
|
||||||
unsigned _pos, _len;
|
unsigned _pos, _len;
|
||||||
uint8_t _buf[128];
|
uint8_t _buf[128];
|
||||||
};
|
};
|
||||||
|
1
r65emu.h
1
r65emu.h
@ -12,6 +12,7 @@
|
|||||||
#include "serialio.h"
|
#include "serialio.h"
|
||||||
#include "filer.h"
|
#include "filer.h"
|
||||||
#include "serial_filer.h"
|
#include "serial_filer.h"
|
||||||
|
#include "socket_filer.h"
|
||||||
#include "timed.h"
|
#include "timed.h"
|
||||||
#include "hardware.h"
|
#include "hardware.h"
|
||||||
#include "sound_dac.h"
|
#include "sound_dac.h"
|
||||||
|
@ -5,10 +5,6 @@
|
|||||||
#include "filer.h"
|
#include "filer.h"
|
||||||
#include "serial_filer.h"
|
#include "serial_filer.h"
|
||||||
|
|
||||||
bool serial_filer::start(const char *) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
const unsigned speeds[] = {
|
const unsigned speeds[] = {
|
||||||
115200, 57600, 19200, 9600, 4800, 2400
|
115200, 57600, 19200, 9600, 4800, 2400
|
||||||
};
|
};
|
||||||
@ -16,7 +12,7 @@ const unsigned speeds[] = {
|
|||||||
const char *serial_filer::advance() {
|
const char *serial_filer::advance() {
|
||||||
static char buf[16];
|
static char buf[16];
|
||||||
unsigned s = speeds[_currsp];
|
unsigned s = speeds[_currsp];
|
||||||
Serial.begin(s);
|
_serial.begin(s);
|
||||||
_currsp++;
|
_currsp++;
|
||||||
if (_currsp == sizeof(speeds)/sizeof(speeds[0]))
|
if (_currsp == sizeof(speeds)/sizeof(speeds[0]))
|
||||||
_currsp = 0;
|
_currsp = 0;
|
||||||
@ -24,15 +20,15 @@ const char *serial_filer::advance() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void serial_filer::write(uint8_t b) {
|
void serial_filer::write(uint8_t b) {
|
||||||
Serial.write(b);
|
_serial.write(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t serial_filer::read() {
|
uint8_t serial_filer::read() {
|
||||||
return Serial.read();
|
return _serial.read();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool serial_filer::more() {
|
bool serial_filer::more() {
|
||||||
return Serial.available() > 0;
|
return _serial.available() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(NO_CHECKPOINT)
|
#if !defined(NO_CHECKPOINT)
|
||||||
|
@ -1,17 +1,21 @@
|
|||||||
#ifndef __SERIAL_FILER_H__
|
#ifndef __SERIAL_FILER_H__
|
||||||
#define __SERIAL_FILER_H__
|
#define __SERIAL_FILER_H__
|
||||||
|
|
||||||
|
class HardwareSerial;
|
||||||
|
|
||||||
// see https://playground.arduino.cc/Interfacing/LinuxTTY
|
// see https://playground.arduino.cc/Interfacing/LinuxTTY
|
||||||
// FIXME: do this in minicom config file
|
// FIXME: do this in minicom config file
|
||||||
class serial_filer: public filer {
|
class serial_filer: public filer {
|
||||||
public:
|
public:
|
||||||
|
serial_filer(HardwareSerial &serial): _serial(serial) {}
|
||||||
|
|
||||||
const char *advance();
|
const char *advance();
|
||||||
const char *rewind() { _currsp = 0; return advance(); }
|
const char *rewind() { _currsp = 0; return advance(); }
|
||||||
|
|
||||||
const char *checkpoint();
|
const char *checkpoint();
|
||||||
void restore(const char *);
|
void restore(const char *);
|
||||||
|
|
||||||
bool start(const char *);
|
bool start() { return true; }
|
||||||
void stop() {}
|
void stop() {}
|
||||||
|
|
||||||
uint8_t read();
|
uint8_t read();
|
||||||
@ -19,6 +23,7 @@ public:
|
|||||||
void write(uint8_t);
|
void write(uint8_t);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
HardwareSerial &_serial;
|
||||||
unsigned _currsp;
|
unsigned _currsp;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
#if !defined(ESP32)
|
#if !defined(ESP32)
|
||||||
#pragma message "no socket filer"
|
#pragma message "no socket filer"
|
||||||
#else
|
#elif defined(WIFI_SSID)
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
|
|
||||||
static WiFiServer server(23);
|
static WiFiServer server(23);
|
||||||
@ -20,11 +20,11 @@ static bool connected() {
|
|||||||
return client.connected();
|
return client.connected();
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: hostname
|
bool socket_filer::start() {
|
||||||
bool socket_filer::start(const char *) {
|
|
||||||
|
|
||||||
#if defined(WIFI_SSID)
|
#if defined(WIFI_SSID)
|
||||||
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
|
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
|
||||||
|
WiFi.setHostname(_hostname);
|
||||||
|
|
||||||
for (int i=0; i < 60 && WiFi.status() != WL_CONNECTED; i++)
|
for (int i=0; i < 60 && WiFi.status() != WL_CONNECTED; i++)
|
||||||
delay(1000);
|
delay(1000);
|
||||||
|
@ -3,17 +3,22 @@
|
|||||||
|
|
||||||
class socket_filer: public filer {
|
class socket_filer: public filer {
|
||||||
public:
|
public:
|
||||||
|
socket_filer(const char *hostname): _hostname(hostname) {}
|
||||||
|
|
||||||
const char *advance() { return 0; }
|
const char *advance() { return 0; }
|
||||||
const char *rewind() { return advance(); }
|
const char *rewind() { return advance(); }
|
||||||
|
|
||||||
const char *checkpoint();
|
const char *checkpoint();
|
||||||
void restore(const char *);
|
void restore(const char *);
|
||||||
|
|
||||||
bool start(const char *);
|
bool start();
|
||||||
void stop() {}
|
void stop() {}
|
||||||
|
|
||||||
uint8_t read();
|
uint8_t read();
|
||||||
bool more();
|
bool more();
|
||||||
void write(uint8_t);
|
void write(uint8_t);
|
||||||
|
|
||||||
|
private:
|
||||||
|
const char *_hostname;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user