MMDVM/SerialPort.h

136 lines
3.9 KiB
C
Raw Normal View History

2016-01-14 19:57:21 +01:00
/*
2021-03-14 19:24:30 +01:00
* Copyright (C) 2015,2016,2017,2018,2020,2021 by Jonathan Naylor G4KLX
2016-01-14 19:57:21 +01:00
*
* 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 2 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, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#if !defined(SERIALPORT_H)
#define SERIALPORT_H
#include "Config.h"
#include "Globals.h"
2020-05-10 06:50:35 +02:00
#include "RingBuffer.h"
2016-01-14 19:57:21 +01:00
2020-05-23 08:57:30 +02:00
#if !defined(SERIAL_SPEED)
#define SERIAL_SPEED 115200
#endif
2016-01-14 19:57:21 +01:00
class CSerialPort {
public:
CSerialPort();
void start();
void process();
#if defined(MODE_DSTAR)
2016-01-14 19:57:21 +01:00
void writeDStarHeader(const uint8_t* header, uint8_t length);
void writeDStarData(const uint8_t* data, uint8_t length);
void writeDStarLost();
void writeDStarEOT();
#endif
2016-01-14 19:57:21 +01:00
#if defined(MODE_DMR)
2016-01-14 19:57:21 +01:00
void writeDMRData(bool slot, const uint8_t* data, uint8_t length);
void writeDMRLost(bool slot);
#endif
2016-01-14 19:57:21 +01:00
#if defined(MODE_YSF)
2016-01-14 19:57:21 +01:00
void writeYSFData(const uint8_t* data, uint8_t length);
void writeYSFLost();
#endif
2016-01-14 19:57:21 +01:00
#if defined(MODE_P25)
2016-09-06 20:11:16 +02:00
void writeP25Hdr(const uint8_t* data, uint8_t length);
void writeP25Ldu(const uint8_t* data, uint8_t length);
void writeP25Lost();
#endif
2016-09-06 20:11:16 +02:00
#if defined(MODE_NXDN)
2018-01-10 21:30:35 +01:00
void writeNXDNData(const uint8_t* data, uint8_t length);
void writeNXDNLost();
#endif
2018-01-10 21:30:35 +01:00
#if defined(MODE_M17)
2021-03-14 19:24:30 +01:00
void writeM17LinkSetup(const uint8_t* data, uint8_t length);
void writeM17Stream(const uint8_t* data, uint8_t length);
2020-10-14 11:52:30 +02:00
void writeM17Lost();
#endif
2020-10-14 11:52:30 +02:00
#if defined(MODE_AX25)
2020-06-19 14:16:47 +02:00
void writeAX25Data(const uint8_t* data, uint16_t length);
#endif
2020-06-08 16:02:12 +02:00
#if defined(MODE_FM)
2020-06-25 11:41:48 +02:00
void writeFMData(const uint8_t* data, uint16_t length);
void writeFMStatus(uint8_t status);
2020-05-15 18:53:34 +02:00
void writeFMEOT();
#endif
#if defined(SERIAL_REPEATER)
void writeSerialData(const uint8_t* data, uint8_t length);
#endif
2020-11-13 16:20:54 +01:00
#if defined(I2C_REPEATER)
void writeI2CData(const uint8_t* data, uint8_t length);
#endif
2016-01-14 19:57:21 +01:00
void writeCalData(const uint8_t* data, uint8_t length);
2016-12-28 19:07:31 +01:00
void writeRSSIData(const uint8_t* data, uint8_t length);
2016-01-14 19:57:21 +01:00
void writeDebug(const char* text);
void writeDebug(const char* text, int16_t n1);
void writeDebug(const char* text, int16_t n1, int16_t n2);
void writeDebug(const char* text, int16_t n1, int16_t n2, int16_t n3);
void writeDebug(const char* text, int16_t n1, int16_t n2, int16_t n3, int16_t n4);
void writeDebugDump(const uint8_t* data, uint16_t length);
2016-03-14 21:24:51 +01:00
2016-01-14 19:57:21 +01:00
private:
2020-06-19 14:16:47 +02:00
uint8_t m_buffer[512U];
uint16_t m_ptr;
uint16_t m_len;
bool m_debug;
2020-11-13 16:20:54 +01:00
CRingBuffer<uint8_t> m_serialData;
int m_lastSerialAvail;
uint16_t m_lastSerialAvailCount;
CRingBuffer<uint8_t> m_i2CData;
2016-01-14 19:57:21 +01:00
void sendACK(uint8_t type);
void sendNAK(uint8_t type, uint8_t err);
2016-03-03 20:02:19 +01:00
void getStatus();
void getVersion();
2020-06-19 14:16:47 +02:00
uint8_t setConfig(const uint8_t* data, uint16_t length);
uint8_t setMode(const uint8_t* data, uint16_t length);
2016-01-14 19:57:21 +01:00
void setMode(MMDVM_STATE modemState);
void processMessage(uint8_t type, const uint8_t* data, uint16_t length);
#if defined(MODE_FM)
2020-06-19 14:16:47 +02:00
uint8_t setFMParams1(const uint8_t* data, uint16_t length);
uint8_t setFMParams2(const uint8_t* data, uint16_t length);
uint8_t setFMParams3(const uint8_t* data, uint16_t length);
2020-06-25 11:41:48 +02:00
uint8_t setFMParams4(const uint8_t* data, uint16_t length);
#endif
2016-11-01 19:01:22 +01:00
// Hardware versions
void beginInt(uint8_t n, int speed);
int availableForReadInt(uint8_t n);
int availableForWriteInt(uint8_t n);
2016-11-01 19:01:22 +01:00
uint8_t readInt(uint8_t n);
void writeInt(uint8_t n, const uint8_t* data, uint16_t length, bool flush = false);
2016-01-14 19:57:21 +01:00
};
#endif