A stack which works with or without an Mbed os library. Provides IPv4 or IPv6 with a full 1500 byte buffer.

Dependents:   oldheating gps motorhome heating

Committer:
andrewboyson
Date:
Sun May 12 17:17:49 2019 +0000
Revision:
144:6bd5c54efc7d
Parent:
142:a8c0890a58d1
Child:
145:206bf0d073c7
Tidied up tcp.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
andrewboyson 61:aad055f1b0d1 1 #include <stdbool.h>
andrewboyson 61:aad055f1b0d1 2
andrewboyson 54:84ef2b29cf7e 3 #include "http.h"
andrewboyson 54:84ef2b29cf7e 4 #include "tcpbuf.h"
andrewboyson 54:84ef2b29cf7e 5 #include "action.h"
andrewboyson 54:84ef2b29cf7e 6 #include "net.h"
andrewboyson 54:84ef2b29cf7e 7 #include "log.h"
andrewboyson 75:603b10404183 8 #include "led.h"
andrewboyson 142:a8c0890a58d1 9 #include "restart.h"
andrewboyson 144:6bd5c54efc7d 10 #include "mstimer.h"
andrewboyson 54:84ef2b29cf7e 11
andrewboyson 54:84ef2b29cf7e 12 bool HttpTrace = false;
andrewboyson 54:84ef2b29cf7e 13
andrewboyson 126:62edacc9f14d 14 //Plumb into these from your html server
andrewboyson 144:6bd5c54efc7d 15 void (*HttpRequestFunction)(int size, char* pRequestStream, uint32_t positionInRequestStream, char* pState);
andrewboyson 144:6bd5c54efc7d 16 int (*HttpReplyFunction )(char* pState);
andrewboyson 54:84ef2b29cf7e 17
andrewboyson 144:6bd5c54efc7d 18 void HttpHandleRequest(int size, char* pRequestStream, uint32_t positionInRequestStream, char* pState)
andrewboyson 54:84ef2b29cf7e 19 {
andrewboyson 142:a8c0890a58d1 20 int lastRestartPoint = RestartPoint;
andrewboyson 142:a8c0890a58d1 21 RestartPoint = FAULT_POINT_HttpHandleRequest;
andrewboyson 98:b977424ec7f7 22
andrewboyson 54:84ef2b29cf7e 23 if (HttpTrace)
andrewboyson 54:84ef2b29cf7e 24 {
andrewboyson 79:f50e02fb5c94 25 LogF("HTTP <<< %d (%u)\r\n", size, positionInRequestStream);
andrewboyson 54:84ef2b29cf7e 26 }
andrewboyson 126:62edacc9f14d 27
andrewboyson 144:6bd5c54efc7d 28 HttpRequestFunction(size, pRequestStream, positionInRequestStream, pState);
andrewboyson 126:62edacc9f14d 29
andrewboyson 142:a8c0890a58d1 30 RestartPoint = lastRestartPoint;
andrewboyson 71:736a5747ade1 31 }
andrewboyson 144:6bd5c54efc7d 32 int HttpSendReply(int* pSize, char* pReplyStream, uint32_t positionInReplyStream, uint16_t mss, char* pState)
andrewboyson 71:736a5747ade1 33 {
andrewboyson 54:84ef2b29cf7e 34 TcpBufStart(positionInReplyStream, mss, pReplyStream);
andrewboyson 144:6bd5c54efc7d 35 int status = HttpReplyFunction(pState); //0: not started; +1: started; -1: wait
andrewboyson 144:6bd5c54efc7d 36 if (status == 0) return TCP_APP_NOT_STARTED;
andrewboyson 144:6bd5c54efc7d 37 if (status == -1) return TCP_APP_STARTED;
andrewboyson 144:6bd5c54efc7d 38
andrewboyson 54:84ef2b29cf7e 39 *pSize = TcpBufLength();
andrewboyson 55:e64b8b47a2b6 40
andrewboyson 55:e64b8b47a2b6 41 if (HttpTrace)
andrewboyson 55:e64b8b47a2b6 42 {
andrewboyson 55:e64b8b47a2b6 43 LogF("HTTP >>> %d (%d)\r\n", *pSize, positionInReplyStream);
andrewboyson 55:e64b8b47a2b6 44 }
andrewboyson 144:6bd5c54efc7d 45 return *pSize < mss ? TCP_APP_FINISHED : TCP_APP_STARTED;
andrewboyson 71:736a5747ade1 46 }