/*
 * Kangaroo Punch MultiPlayer Game Server Mark II
 * Copyright (C) 2020-2021  Scott Duensing
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 *
 */


#ifndef COMPORT_H
#define COMPORT_H


#include "os.h"
#include "packet.h"


typedef struct ComWaitWithTimeoutS {
	int32_t   result;
	uint8_t   com;
	char     *buffer;
	int32_t   len;
	uint32_t  quarterSeconds;
	char     *expecting;
} ComWaitWithTimeoutT;


#ifdef __linux__

#define SER_SUCCESS              0
#define SER_ERR_UNKNOWN         -1
#define SER_ERR_NOT_OPEN        -2
#define SER_ERR_ALREADY_OPEN    -3

#define SER_HANDSHAKING_RTSCTS   2

int comClose(int com);
int comOpen(int com, long bps, int dataBits, char parity, int stopBits, int handshaking);
int comRead(int com, char *data, int len);
int comWrite(int com, const char *data, int len);

#else

#include "serial/serial.h"

#define comClose serial_close
#define comOpen  serial_open
#define comRead  serial_read
#define comWrite serial_write

#endif


void comPacketSender(char *data, uint32_t length, void *userData);
int  comReceiveBufferFlush(int com);


#endif // COMPORT_H
