Merge pull request #10558 from iNavFlight/MrD_Correct-comments-on-OSD-symbols
[inav.git] / src / main / drivers / serial_tcp.h
blob7f394b8ccd3c43e2394908bc5f90897e4cd00bf0
1 /*
2 * This file is part of INAV.
4 * INAV is free software. You can redistribute this software
5 * and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
8 * any later version.
10 * INAV is distributed in the hope that they will be
11 * useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
21 #pragma once
23 #include <pthread.h>
24 #include <arpa/inet.h>
25 #include <sys/socket.h>
26 #include <netinet/in.h>
27 #include <netdb.h>
29 #include "drivers/serial.h"
31 #define BASE_IP_ADDRESS 5760
32 #define TCP_BUFFER_SIZE 2048
33 #define TCP_MAX_PACKET_SIZE 65535
35 typedef struct
37 serialPort_t serialPort;
39 uint8_t rxBuffer[TCP_BUFFER_SIZE];
41 uint8_t id;
42 bool isInitalized;
43 pthread_mutex_t receiveMutex;
44 pthread_t receiveThread;
45 int socketFd;
46 int clientSocketFd;
47 struct sockaddr_storage sockAddress;
48 struct sockaddr_storage clientAddress;
49 bool isClientConnected;
50 } tcpPort_t;
53 serialPort_t *tcpOpen(USART_TypeDef *USARTx, serialReceiveCallbackPtr callback, void *rxCallbackData, uint32_t baudRate, portMode_t mode, portOptions_t options);
55 extern void tcpSend(tcpPort_t *port);
56 extern int tcpReceive(tcpPort_t *port);
57 extern void tcpReceiveBytesEx( int portIndex, const uint8_t* buffer, ssize_t recvSize );
58 extern uint32_t tcpRXBytesFree(int portIndex);