mirror of
https://github.com/jscrane/r65emu.git
synced 2024-12-21 12:29:51 +00:00
socket filer
This commit is contained in:
parent
61725b7865
commit
e90fb2c6e7
65
socket_filer.cpp
Normal file
65
socket_filer.cpp
Normal file
@ -0,0 +1,65 @@
|
||||
#include <Arduino.h>
|
||||
#include <stdint.h>
|
||||
#include "hardware.h"
|
||||
#include "serialio.h"
|
||||
#include "filer.h"
|
||||
#include "socket_filer.h"
|
||||
|
||||
#if !defined(ESP32)
|
||||
#pragma message "no socket filer"
|
||||
#else
|
||||
#include <WiFi.h>
|
||||
|
||||
static WiFiServer server(23);
|
||||
static WiFiClient client;
|
||||
|
||||
static bool connected() {
|
||||
if (client.connected())
|
||||
return true;
|
||||
client = server.available();
|
||||
return client.connected();
|
||||
}
|
||||
|
||||
// FIXME: hostname
|
||||
bool socket_filer::start(const char *) {
|
||||
|
||||
#if defined(WIFI_SSID)
|
||||
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
|
||||
|
||||
for (int i=0; i < 60 && WiFi.status() != WL_CONNECTED; i++)
|
||||
delay(1000);
|
||||
|
||||
server.begin();
|
||||
return WiFi.status() == WL_CONNECTED;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
void socket_filer::write(uint8_t b) {
|
||||
if (connected())
|
||||
client.write(b);
|
||||
}
|
||||
|
||||
uint8_t socket_filer::read() {
|
||||
if (connected())
|
||||
return client.read();
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool socket_filer::more() {
|
||||
return connected() && client.available() > 0;
|
||||
}
|
||||
|
||||
#if !defined(NO_CHECKPOINT)
|
||||
const char *socket_filer::checkpoint() {
|
||||
// FIXME
|
||||
return 0;
|
||||
}
|
||||
|
||||
void socket_filer::restore(const char *) {
|
||||
// FIXME
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
19
socket_filer.h
Normal file
19
socket_filer.h
Normal file
@ -0,0 +1,19 @@
|
||||
#ifndef __SOCKET_FILER_H__
|
||||
#define __SOCKET_FILER_H__
|
||||
|
||||
class socket_filer: public filer {
|
||||
public:
|
||||
const char *advance() { return 0; }
|
||||
const char *rewind() { return advance(); }
|
||||
|
||||
const char *checkpoint();
|
||||
void restore(const char *);
|
||||
|
||||
bool start(const char *);
|
||||
void stop() {}
|
||||
|
||||
uint8_t read();
|
||||
bool more();
|
||||
void write(uint8_t);
|
||||
};
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user