forked from basvk/PIC-Websockets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomHTTPApp.c
210 lines (175 loc) · 6.79 KB
/
CustomHTTPApp.c
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/*********************************************************************
*
* Application to Demo HTTP2 Server
* Support for HTTP2 module in Microchip TCP/IP Stack
* -Implements the application
* -Reference: RFC 1002
*
*********************************************************************
* FileName: CustomHTTPApp.c
* Dependencies: TCP/IP stack
* Processor: PIC18, PIC24F, PIC24H, dsPIC30F, dsPIC33F, PIC32
* Compiler: Microchip C32 v1.05 or higher
* Microchip C30 v3.12 or higher
* Microchip C18 v3.30 or higher
* HI-TECH PICC-18 PRO 9.63PL2 or higher
* Company: Microchip Technology, Inc.
*
* Software License Agreement
*
* Copyright (C) 2002-2010 Microchip Technology Inc. All rights
* reserved.
*
* Microchip licenses to you the right to use, modify, copy, and
* distribute:
* (i) the Software when embedded on a Microchip microcontroller or
* digital signal controller product ("Device") which is
* integrated into Licensee's product; or
* (ii) ONLY the Software driver source files ENC28J60.c, ENC28J60.h,
* ENCX24J600.c and ENCX24J600.h ported to a non-Microchip device
* used in conjunction with a Microchip ethernet controller for
* the sole purpose of interfacing with the ethernet controller.
*
* You should refer to the license agreement accompanying this
* Software for additional information regarding your rights and
* obligations.
*
* THE SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT
* WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT
* LIMITATION, ANY WARRANTY OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL
* MICROCHIP BE LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF
* PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR SERVICES, ANY CLAIMS
* BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE
* THEREOF), ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION, OR OTHER
* SIMILAR COSTS, WHETHER ASSERTED ON THE BASIS OF CONTRACT, TORT
* (INCLUDING NEGLIGENCE), BREACH OF WARRANTY, OR OTHERWISE.
*
*
* Author Date Comment
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Elliott Wood 6/18/07 Original
* Yale 09/03/10 Port to PIC24 Web Server Demo Board
********************************************************************/
#define __CUSTOMHTTPAPP_C
#include "TCPIPConfig.h"
#if defined(STACK_USE_HTTP2_SERVER)
#include "TCPIP Stack/TCPIP.h"
typedef enum {
WS_L1_PROC,
WS_L1_SEND,
WS_L2_PROC,
WS_L2_SEND,
WS_L3_PROC,
WS_L3_SEND
} WS_STATE;
static WS_STATE state = WS_L1_PROC;
/****************************************************************************
Section:
Function Prototypes and Memory Globalizers
***************************************************************************/
#if defined(HTTP_USE_POST)
#if defined(USE_LCD)
static HTTP_IO_RESULT HTTPPostLCD(void);
#endif
#endif
/****************************************************************************
Section:
WebSocket handling
***************************************************************************/
// example: simple payload echoing.
#if defined(HTTP_USE_WEBSOCKETS)
BYTE dataBufferLength = 0;
void WebSocketIncomingDataCallback(WS_OPCODE opcode, BYTE *payloadBuffer, WORD payloadLength) {
memcpy(curHTTP.data, payloadBuffer, payloadLength); // copy incoming payload into curHTTP.data
dataBufferLength = payloadLength;
}
int WebSocketTaskCallback(void) {
if (dataBufferLength > 0) {
// send the previously copied payload
if (WebSocketSendPayload(WS_OPCODE_TEXT, dataBufferLength) == 0) {
dataBufferLength = 0; // transmission succesfull
}
}
return 0;
}
#endif
/****************************************************************************
Section:
GET Form Handlers
***************************************************************************/
/*****************************************************************************
Function:
HTTP_IO_RESULT HTTPExecuteGet(void)
Internal:
See documentation in the TCP/IP Stack API or HTTP2.h for details.
***************************************************************************/
HTTP_IO_RESULT HTTPExecuteGet(void)
{
return HTTP_IO_DONE;
}
/****************************************************************************
Section:
POST Form Handlers
***************************************************************************/
#if defined(HTTP_USE_POST)
/*****************************************************************************
Function:
HTTP_IO_RESULT HTTPExecutePost(void)
Internal:
See documentation in the TCP/IP Stack API or HTTP2.h for details.
***************************************************************************/
HTTP_IO_RESULT HTTPExecutePost(void)
{
return HTTP_IO_DONE;
}
/*****************************************************************************
Function:
static HTTP_IO_RESULT HTTPPostLCD(void)
Summary:
Processes the LCD form on forms.htm
Description:
Locates the 'lcd' parameter and uses it to update the text displayed
on the board's LCD display.
This function has four states. The first reads a name from the data
string returned as part of the POST request. If a name cannot
be found, it returns, asking for more data. Otherwise, if the name
is expected, it reads the associated value and writes it to the LCD.
If the name is not expected, the value is discarded and the next name
parameter is read.
In the case where the expected string is never found, this function
will eventually return HTTP_IO_NEED_DATA when no data is left. In that
case, the HTTP2 server will automatically trap the error and issue an
Internal Server Error to the browser.
Precondition:
None
Parameters:
None
Return Values:
HTTP_IO_DONE - the parameter has been found and saved
HTTP_IO_WAITING - the function is pausing to continue later
HTTP_IO_NEED_DATA - data needed by this function has not yet arrived
***************************************************************************/
#if defined(USE_LCD)
static HTTP_IO_RESULT HTTPPostLCD(void)
{
return HTTP_IO_DONE;
}
#endif
#endif //(use_post)
/****************************************************************************
Section:
Dynamic Variable Callback Functions
***************************************************************************/
/*****************************************************************************
Function:
void HTTPPrint_varname(void)
Internal:
See documentation in the TCP/IP Stack API or HTTP2.h for details.
***************************************************************************/
void HTTPPrint_version(void)
{
TCPPutROMString(sktHTTP, (ROM void*)TCPIP_STACK_VERSION);
}
#endif