ClearCore Library
Loading...
Searching...
No Matches
EthernetTcp.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Teknic, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
27#ifndef __ETHERNETTCP_H__
28#define __ETHERNETTCP_H__
29
30#include "lwip/tcp.h"
31#include <string.h>
32#ifndef HIDE_FROM_DOXYGEN
33namespace ClearCore {
34
36#define CLIENT_MAX 8
38#define TCP_DATA_BUFFER_SIZE 600
39
48class EthernetTcp {
49
50public:
54 typedef struct {
55 struct tcp_pcb *pcb;
56 uint16_t dataHead;
57 uint16_t dataTail;
58 tcp_state state;
59 uint8_t data[TCP_DATA_BUFFER_SIZE];
61 } TcpData;
62
66 EthernetTcp() : m_tcpData(nullptr) {};
67
71 EthernetTcp(TcpData *tcpData);
72
82 uint32_t Send(uint8_t charToSend);
83
94 uint32_t Send(const char *nullTermStr) {
95 return Send((const uint8_t *)nullTermStr, strlen(nullTermStr));
96 }
97
109 virtual uint32_t Send(const uint8_t *buff, uint32_t size) = 0;
110
116 uint16_t LocalPort();
117
123 volatile const TcpData *ConnectionState() {
124 return m_tcpData;
125 }
126
127protected:
128 // The TCP state.
129 TcpData *m_tcpData;
130
131}; // EthernetTcp
132
133#ifndef HIDE_FROM_DOXYGEN
138err_t TcpAccept(void *arg, struct tcp_pcb *newpcb, err_t err);
139
143err_t TcpConnect(void *arg, struct tcp_pcb *tpcb, err_t err);
144
148void TcpError(void *arg, err_t err);
149
158err_t TcpReceive(void *arg, struct tcp_pcb *tpcb, struct pbuf *p,
159 err_t err);
160
164err_t TcpSend(void *arg, struct tcp_pcb *tpcb, u16_t len);
165
169void TcpClose(struct tcp_pcb *pcb, EthernetTcp::TcpData *data);
170#endif // !HIDE_FROM_DOXYGEN
171
172} // ClearCore namespace
173#endif // !HIDE_FROM_DOXYGEN
174#endif // !__ETHERNETTCP_H__
175
Namespace to encompass the ClearCore board API.
Definition AdcManager.h:36