forked from jcrouchley/WiFly-Shield
-
Notifications
You must be signed in to change notification settings - Fork 4
/
WiFlyServer.cpp
65 lines (51 loc) · 1.6 KB
/
WiFlyServer.cpp
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
#include "WiFly.h"
// NOTE: Arbitrary cast to avoid constructor ambiguity.
// TODO: Handle this a different way so we're not using
// NULL pointers all over the place?
#define NO_CLIENT WiFlyClient ((uint8_t*) NULL, 0)
WiFlyServer::WiFlyServer(uint16_t port) : activeClient(NO_CLIENT){
/*
*/
_port = port;
// TODO: Handle this better.
// NOTE: This only works if the server object was created globally.
WiFly.serverPort = port;
}
void WiFlyServer::begin() {
/*
*/
// TODO: Send command to enable server functionality.
}
#define TOKEN_MATCH_OPEN "*OPEN*"
WiFlyClient& WiFlyServer::available() {
/*
*/
// TODO: Ensure no active non-server client connection.
if (!WiFly.serverConnectionActive) {
activeClient._port = 0;
}
// TODO: Ensure begin() has been called.
// Return active server connection if present
if (!activeClient) {
// TODO: Handle this better
if (WiFly.uart->available() >= strlen(TOKEN_MATCH_OPEN)) {
if (WiFly.responseMatched(TOKEN_MATCH_OPEN)) {
// The following values indicate that the connection was
// created when acting as a server.
// TODO: Work out why this alternate instantiation code doesn't work:
//activeClient = WiFlyClient((uint8_t*) NULL, _port);
activeClient._port = _port;
activeClient._domain = NULL;
activeClient._ip = NULL;
activeClient.connect();
WiFly.serverConnectionActive = true;
} else {
// Ignore other feedback from the WiFly module.
// TODO: Should we check we're not ditching a connect accidentally?
//WiFly.skipRemainderOfResponse();
WiFly.uart->flush();
}
}
}
return activeClient;
}