forked from Open-Acidification/TankController
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEthernetServer_TC.h
More file actions
93 lines (85 loc) · 1.94 KB
/
EthernetServer_TC.h
File metadata and controls
93 lines (85 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#pragma once
#include <Arduino.h>
#include "SD_TC.h"
#if defined(ARDUINO_CI_COMPILATION_MOCKS)
#include "Ethernet.h"
#else
#include <Ethernet.h>
#endif
#define TIMEOUT 5000
#define HTTP_REDIRECT 303
#define HTTP_BAD_REQUEST 400
#define HTTP_NOT_FOUND 404
#define HTTP_NOT_PERMITTED 405
#define HTTP_TIMEOUT 408
#define HTTP_ERROR 500
#define HTTP_NOT_IMPLEMENTED 501
enum serverState_t {
NOT_CONNECTED,
READ_REQUEST,
GET_REQUEST,
POST_REQUEST,
PUT_REQUEST,
OPTIONS_REQUEST,
COUNTING_FILES,
LISTING_FILES,
IN_TRANSFER,
FINISHED
};
/**
* EthernetServer_TC provides wrapper for web server for TankController
*
* If running in test mode, superclass = EthernetServer_CI
*/
class EthernetServer_TC : public EthernetServer {
public:
// class methods
static EthernetServer_TC* instance();
// instance methods
const char* className() const {
return "EthernetServer_TC";
}
serverState_t getState() const {
return state;
}
void loop();
void writeToClientBuffer(const char*, bool);
void sendHeadersForRootdir(int);
private:
// class variables
static EthernetServer_TC* _instance;
// instance variables
EthernetClient client;
serverState_t state = NOT_CONNECTED;
char buffer[512];
char boundary[9];
unsigned int bufferContentsSize = 0;
unsigned long connectedAt = 0;
File file;
int startTime;
// instance methods: constructor
EthernetServer_TC(uint16_t port);
// instance methods: utility
void sendHeadersWithSize(uint32_t size);
void sendResponse(int);
void sendCurrentRedirect();
void sendDisplayRedirect();
int weekday(int year, int month, int day);
// instance methods: HTTP
void get();
void post();
void put();
void options();
void echo();
void apiHandler();
void current();
void display();
void keypress();
void rootdirSetup();
void rootdir();
void testReadSpeed();
void testWriteSpeed();
bool isRequestForExistingFile();
void fileSetup();
bool fileContinue();
};