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
tcp/tcpbuf.c@146:0fc66d610fd6, 2019-05-15 (annotated)
- Committer:
- andrewboyson
- Date:
- Wed May 15 15:33:15 2019 +0000
- Revision:
- 146:0fc66d610fd6
- Parent:
- 145:206bf0d073c7
- Child:
- 155:22f249751106
Tidied the http shim
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
andrewboyson | 61:aad055f1b0d1 | 1 | #include <stdbool.h> |
andrewboyson | 146:0fc66d610fd6 | 2 | #include <stdint.h> |
andrewboyson | 54:84ef2b29cf7e | 3 | |
andrewboyson | 79:f50e02fb5c94 | 4 | static uint32_t currentPositionInMessage; |
andrewboyson | 79:f50e02fb5c94 | 5 | static uint32_t bufferPositionInMessage; |
andrewboyson | 54:84ef2b29cf7e | 6 | static int bufferLength; |
andrewboyson | 54:84ef2b29cf7e | 7 | static char* pBuffer; |
andrewboyson | 54:84ef2b29cf7e | 8 | static char* p; |
andrewboyson | 54:84ef2b29cf7e | 9 | |
andrewboyson | 79:f50e02fb5c94 | 10 | void TcpBufStart(uint32_t position, int mss, char *pData) |
andrewboyson | 54:84ef2b29cf7e | 11 | { |
andrewboyson | 54:84ef2b29cf7e | 12 | currentPositionInMessage = 0; |
andrewboyson | 54:84ef2b29cf7e | 13 | bufferPositionInMessage = position; |
andrewboyson | 54:84ef2b29cf7e | 14 | bufferLength = mss; |
andrewboyson | 54:84ef2b29cf7e | 15 | pBuffer = pData; |
andrewboyson | 54:84ef2b29cf7e | 16 | p = pData; |
andrewboyson | 54:84ef2b29cf7e | 17 | } |
andrewboyson | 54:84ef2b29cf7e | 18 | int TcpBufLength() |
andrewboyson | 54:84ef2b29cf7e | 19 | { |
andrewboyson | 54:84ef2b29cf7e | 20 | return p - pBuffer; |
andrewboyson | 54:84ef2b29cf7e | 21 | } |
andrewboyson | 145:206bf0d073c7 | 22 | bool TcpBufFilled() |
andrewboyson | 145:206bf0d073c7 | 23 | { |
andrewboyson | 145:206bf0d073c7 | 24 | return p - pBuffer >= bufferLength; |
andrewboyson | 145:206bf0d073c7 | 25 | } |
andrewboyson | 54:84ef2b29cf7e | 26 | |
andrewboyson | 54:84ef2b29cf7e | 27 | void TcpBufAddChar(char c) |
andrewboyson | 54:84ef2b29cf7e | 28 | { |
andrewboyson | 145:206bf0d073c7 | 29 | //Add character if the current position is within the buffer |
andrewboyson | 145:206bf0d073c7 | 30 | if (currentPositionInMessage >= bufferPositionInMessage && |
andrewboyson | 145:206bf0d073c7 | 31 | currentPositionInMessage < bufferPositionInMessage + bufferLength) *p++ = c; |
andrewboyson | 145:206bf0d073c7 | 32 | |
andrewboyson | 54:84ef2b29cf7e | 33 | currentPositionInMessage++; |
andrewboyson | 54:84ef2b29cf7e | 34 | } |