2019-03-25 16:12:38 +00:00
|
|
|
#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"
|
2019-03-26 19:27:25 +00:00
|
|
|
#elif defined(WIFI_SSID)
|
2019-03-25 16:12:38 +00:00
|
|
|
#include <WiFi.h>
|
|
|
|
|
|
|
|
static WiFiServer server(23);
|
|
|
|
static WiFiClient client;
|
|
|
|
|
|
|
|
static bool connected() {
|
|
|
|
if (client.connected())
|
|
|
|
return true;
|
|
|
|
client = server.available();
|
|
|
|
return client.connected();
|
|
|
|
}
|
|
|
|
|
2019-03-30 11:55:34 +00:00
|
|
|
const char *socket_filer::advance() {
|
|
|
|
if (connected())
|
|
|
|
return "connected";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-03-26 19:27:25 +00:00
|
|
|
bool socket_filer::start() {
|
2019-03-25 16:12:38 +00:00
|
|
|
|
|
|
|
#if defined(WIFI_SSID)
|
|
|
|
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
|
2019-03-26 19:27:25 +00:00
|
|
|
WiFi.setHostname(_hostname);
|
2019-03-25 16:12:38 +00:00
|
|
|
|
|
|
|
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() {
|
2019-03-30 11:55:34 +00:00
|
|
|
if (connected()) {
|
|
|
|
hardware_checkpoint(client);
|
|
|
|
client.flush();
|
|
|
|
client.stop();
|
|
|
|
return "checkpointed";
|
|
|
|
}
|
|
|
|
return "not connected";
|
2019-03-25 16:12:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void socket_filer::restore(const char *) {
|
2019-03-30 11:55:34 +00:00
|
|
|
if (connected()) {
|
|
|
|
hardware_restore(client);
|
|
|
|
client.stop();
|
|
|
|
}
|
2019-03-25 16:12:38 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|