/** * Digital Voice Modem - DSP Firmware (Hotspot) * GPLv2 Open Source. Use is subject to license terms. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * @package DVM / DSP Firmware (Hotspot) * */ // // Based on code from the MMDVM_HS project. (https://github.com/juribeparada/MMDVM_HS) // Licensed under the GPLv2 License (https://opensource.org/licenses/GPL-2.0) // /* * Copyright (C) 2015,2016,2018,2020,2021 by Jonathan Naylor G4KLX * Copyright (C) 2018 by Andy Uribe CA6JAU * Copyright (C) 2018,2021-2022 Bryan Biedenkapp N2PLL * * 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(__SERIAL_PORT_H__) #define __SERIAL_PORT_H__ #include "Defines.h" #include "Globals.h" #include "SerialBuffer.h" // --------------------------------------------------------------------------- // Constants // --------------------------------------------------------------------------- enum DVM_STATE { STATE_IDLE = 0U, // DMR STATE_DMR = 1U, // Project 25 STATE_P25 = 2U, // NXDN STATE_NXDN = 3U, // CW STATE_CW = 10U, // Calibration States STATE_INT_CAL = 90U, STATE_P25_LF_CAL = 91U, STATE_P25_CAL_1K = 92U, STATE_DMR_DMO_CAL_1K = 93U, STATE_DMR_CAL_1K = 94U, STATE_DMR_LF_CAL = 95U, STATE_RSSI_CAL = 96U, STATE_P25_CAL = 97U, STATE_DMR_CAL = 98U, STATE_NXDN_CAL = 99U }; enum DVM_COMMANDS { CMD_GET_VERSION = 0x00U, CMD_GET_STATUS = 0x01U, CMD_SET_CONFIG = 0x02U, CMD_SET_MODE = 0x03U, CMD_SET_SYMLVLADJ = 0x04U, CMD_SET_RXLEVEL = 0x05U, CMD_SET_RFPARAMS = 0x06U, CMD_CAL_DATA = 0x08U, CMD_RSSI_DATA = 0x09U, CMD_SEND_CWID = 0x0AU, CMD_DMR_DATA1 = 0x18U, CMD_DMR_LOST1 = 0x19U, CMD_DMR_DATA2 = 0x1AU, CMD_DMR_LOST2 = 0x1BU, CMD_DMR_SHORTLC = 0x1CU, CMD_DMR_START = 0x1DU, CMD_DMR_ABORT = 0x1EU, CMD_DMR_CACH_AT_CTRL = 0x1FU, CMD_P25_DATA = 0x31U, CMD_P25_LOST = 0x32U, CMD_P25_CLEAR = 0x33U, CMD_NXDN_DATA = 0x41U, CMD_NXDN_LOST = 0x42U, CMD_ACK = 0x70U, CMD_NAK = 0x7FU, CMD_FLSH_READ = 0xE0U, CMD_FLSH_WRITE = 0xE1U, CMD_DEBUG1 = 0xF1U, CMD_DEBUG2 = 0xF2U, CMD_DEBUG3 = 0xF3U, CMD_DEBUG4 = 0xF4U, CMD_DEBUG5 = 0xF5U, CMD_DEBUG_DUMP = 0xFAU, }; enum CMD_REASON_CODE { RSN_OK = 0U, RSN_NAK = 1U, RSN_ILLEGAL_LENGTH = 2U, RSN_INVALID_REQUEST = 4U, RSN_RINGBUFF_FULL = 8U, RSN_INVALID_FDMA_PREAMBLE = 10U, RSN_INVALID_MODE = 11U, RSN_INVALID_DMR_CC = 12U, RSN_INVALID_DMR_SLOT = 13U, RSN_INVALID_DMR_START = 14U, RSN_INVALID_DMR_RX_DELAY = 15U, RSN_INVALID_P25_CORR_COUNT = 16U, RSN_NO_INTERNAL_FLASH = 20U, RSN_FAILED_ERASE_FLASH = 21U, RSN_FAILED_WRITE_FLASH = 22U, RSN_FLASH_WRITE_TOO_BIG = 23U, RSN_HS_NO_DUAL_MODE = 32U, RSN_DMR_DISABLED = 63U, RSN_P25_DISABLED = 64U, RSN_NXDN_DISABLED = 65U }; const uint8_t DVM_FRAME_START = 0xFEU; #define SERIAL_SPEED 115200 #define STATE_SCAN_MAX 3 // --------------------------------------------------------------------------- // Class Declaration // Implements the RS232 serial bus to communicate with the HOST S/W. // --------------------------------------------------------------------------- class DSP_FW_API SerialPort { public: /// Initializes a new instance of the SerialPort class. SerialPort(); /// Starts serial port communications. void start(); /// Process data from serial port. void process(); /// Helper to check if the modem is in a calibration state. bool isCalState(DVM_STATE state); /// Helper to determine digital mode if the modem is in a calibration state. DVM_STATE calRelativeState(DVM_STATE state); /// Write DMR frame data to serial port. void writeDMRData(bool slot, const uint8_t* data, uint8_t length); /// Write lost DMR frame data to serial port. void writeDMRLost(bool slot); /// Write P25 frame data to serial port. void writeP25Data(const uint8_t* data, uint8_t length); /// Write lost P25 frame data to serial port. void writeP25Lost(); /// Write NXDN frame data to serial port. void writeNXDNData(const uint8_t* data, uint8_t length); /// Write lost NXDN frame data to serial port. void writeNXDNLost(); /// Write calibration frame data to serial port. void writeCalData(const uint8_t* data, uint8_t length); /// Write RSSI frame data to serial port. void writeRSSIData(const uint8_t* data, uint8_t length); /// 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 writeDump(const uint8_t* data, uint16_t length); private: uint8_t m_buffer[256U]; uint8_t m_ptr; uint8_t m_len; bool m_debug; /// Write acknowlegement. void sendACK(); /// Write negative acknowlegement. void sendNAK(uint8_t err); /// Write modem DSP status. void getStatus(); /// Write modem DSP version. void getVersion(); /// Helper to validate the passed modem state is valid. uint8_t modemStateCheck(DVM_STATE state); /// Set modem DSP configuration from serial port data. uint8_t setConfig(const uint8_t* data, uint8_t length); /// Set modem DSP mode from serial port data. uint8_t setMode(const uint8_t* data, uint8_t length); /// Sets the modem state. void setMode(DVM_STATE modemState); /// Sets the RF parameters. uint8_t setRFParams(const uint8_t* data, uint8_t length); /// void flashRead(); /// uint8_t flashWrite(const uint8_t* data, uint8_t length); // Hardware specific routines /// void beginInt(uint8_t n, int speed); /// int availableInt(uint8_t n); /// int availableForWriteInt(uint8_t n); /// uint8_t readInt(uint8_t n); /// void writeInt(uint8_t n, const uint8_t* data, uint16_t length, bool flush = false); }; #endif // __SERIAL_PORT_H__