diff --git a/DStarDefines.h b/DStarDefines.h index 532b5d2..ae93f79 100644 --- a/DStarDefines.h +++ b/DStarDefines.h @@ -45,9 +45,13 @@ const unsigned char DSTAR_SLOW_DATA_TYPE_HEADER = 0x50U; const unsigned char DSTAR_SLOW_DATA_TYPE_SQUELCH = 0xC0U; const unsigned char DSTAR_SLOW_DATA_LENGTH_MASK = 0x0FU; -const unsigned char DSTAR_SCRAMBLER_BYTEs[] = {0x70U, 0x4FU, 0x93U}; +const unsigned char DSTAR_SCRAMBLER_BYTES[] = {0x70U, 0x4FU, 0x93U}; -const unsigned char DSTAR_REPEATER_CONTROL = 0x07U; +const unsigned char DSTAR_DATA_MASK = 0x80U; +const unsigned char DSTAR_REPEATER_MASK = 0x40U; +const unsigned char DSTAR_INTERRUPTED_MASK = 0x20U; +const unsigned char DSTAR_CONTROL_SIGNAL_MASK = 0x10U; +const unsigned char DSTAR_URGENT_MASK = 0x08U; const unsigned char DSTAR_SYNC_BYTES[] = {0x55U, 0x2DU, 0x16U}; diff --git a/DStarHeader.cpp b/DStarHeader.cpp index dd592b2..c9ad5fa 100644 --- a/DStarHeader.cpp +++ b/DStarHeader.cpp @@ -41,15 +41,15 @@ CDStarHeader::~CDStarHeader() bool CDStarHeader::isRepeater() const { - return (m_header[0U] & DSTAR_REPEATER_CONTROL) == DSTAR_REPEATER_CONTROL; + return (m_header[0U] & DSTAR_REPEATER_MASK) == DSTAR_REPEATER_MASK; } void CDStarHeader::setRepeater(bool on) { if (on) - m_header[0U] |= DSTAR_REPEATER_CONTROL; + m_header[0U] |= DSTAR_REPEATER_MASK; else - m_header[0U] &= ~DSTAR_REPEATER_CONTROL; + m_header[0U] &= ~DSTAR_REPEATER_MASK; } void CDStarHeader::getMyCall1(unsigned char* call1) const diff --git a/DStarSlowData.cpp b/DStarSlowData.cpp new file mode 100644 index 0000000..1f72a77 --- /dev/null +++ b/DStarSlowData.cpp @@ -0,0 +1,108 @@ +/* +* Copyright (C) 2016 by Jonathan Naylor G4KLX +* +* 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. +*/ + +#include "DStarSlowData.h" +#include "DStarDefines.h" +#include "CRC.h" + +#include +#include +#include + +CDStarSlowData::CDStarSlowData() : +m_header(NULL), +m_ptr(0U), +m_buffer(NULL), +m_state(SDD_FIRST) +{ + m_header = new unsigned char[50U]; // DSTAR_HEADER_LENGTH_BYTES + m_buffer = new unsigned char[DSTAR_DATA_FRAME_LENGTH_BYTES * 2U]; +} + +CDStarSlowData::~CDStarSlowData() +{ + delete[] m_header; + delete[] m_buffer; +} + +CDStarHeader* CDStarSlowData::add(const unsigned char* data) +{ + assert(data != NULL); + + switch (m_state) { + case SDD_FIRST: + m_buffer[0U] = data[9U] ^ DSTAR_SCRAMBLER_BYTES[0U]; + m_buffer[1U] = data[10U] ^ DSTAR_SCRAMBLER_BYTES[1U]; + m_buffer[2U] = data[11U] ^ DSTAR_SCRAMBLER_BYTES[2U]; + m_state = SDD_SECOND; + return NULL; + + case SDD_SECOND: + m_buffer[3U] = data[9U] ^ DSTAR_SCRAMBLER_BYTES[0U]; + m_buffer[4U] = data[10U] ^ DSTAR_SCRAMBLER_BYTES[1U]; + m_buffer[5U] = data[11U] ^ DSTAR_SCRAMBLER_BYTES[2U]; + m_state = SDD_FIRST; + break; + } + + if ((m_buffer[0U] & DSTAR_SLOW_DATA_TYPE_MASK) != DSTAR_SLOW_DATA_TYPE_HEADER) + return NULL; + + ::memcpy(m_header + m_ptr, m_buffer + 1U, 5U); + m_ptr += 5U; + + if (m_ptr < DSTAR_HEADER_LENGTH_BYTES) + return NULL; + + // Clean up the data + m_header[0U] &= (DSTAR_INTERRUPTED_MASK | DSTAR_URGENT_MASK | DSTAR_REPEATER_MASK); + m_header[1U] = 0x00U; + m_header[2U] = 0x00U; + + for (unsigned int i = 3U; i < 39U; i++) + m_header[i] &= 0x7FU; + + // Save the CRC for later comparison + unsigned char crc[2U]; + ::memcpy(crc, m_header + 39U, 2U); + + // Add the new CRC + CCRC::addCCITT16(m_header, DSTAR_HEADER_LENGTH_BYTES); + + m_ptr = 0U; + + // Compare them + if (crc[0U] != m_header[39U] || crc[1U] != m_header[40U]) + return NULL; + + return new CDStarHeader(m_header); +} + +void CDStarSlowData::start() +{ + ::memset(m_header, 0x00U, DSTAR_HEADER_LENGTH_BYTES); + + m_ptr = 0U; + m_state = SDD_FIRST; +} + +void CDStarSlowData::reset() +{ + m_ptr = 0U; + m_state = SDD_FIRST; +} diff --git a/DStarSlowData.h b/DStarSlowData.h new file mode 100644 index 0000000..f288df7 --- /dev/null +++ b/DStarSlowData.h @@ -0,0 +1,47 @@ +/* +* Copyright (C) 2016 by Jonathan Naylor G4KLX +* +* 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. +*/ + +#ifndef DStarSlowData_H +#define DStarSlowData_H + +#include "DStarHeader.h" + +class CDStarSlowData { +public: + CDStarSlowData(); + ~CDStarSlowData(); + + CDStarHeader* add(const unsigned char* data); + + void start(); + void reset(); + +private: + unsigned char* m_header; + unsigned int m_ptr; + unsigned char* m_buffer; + + enum SDD_STATE { + SDD_FIRST, + SDD_SECOND + }; + + SDD_STATE m_state; +}; + +#endif diff --git a/MMDVMHost.vcxproj b/MMDVMHost.vcxproj index 43e4a34..89d2185 100644 --- a/MMDVMHost.vcxproj +++ b/MMDVMHost.vcxproj @@ -163,6 +163,7 @@ + @@ -206,6 +207,7 @@ + diff --git a/MMDVMHost.vcxproj.filters b/MMDVMHost.vcxproj.filters index 3ce700e..5b70b06 100644 --- a/MMDVMHost.vcxproj.filters +++ b/MMDVMHost.vcxproj.filters @@ -143,6 +143,9 @@ Header Files + + Header Files + @@ -259,5 +262,8 @@ Source Files + + Source Files + \ No newline at end of file diff --git a/Makefile b/Makefile index 7446170..fbad51b 100644 --- a/Makefile +++ b/Makefile @@ -6,11 +6,12 @@ LDFLAGS = -g all: MMDVMHost MMDVMHost: AMBEFEC.o BPTC19696.o Conf.o CRC.o CSBK.o Display.o DMRControl.o DMRData.o DMRDataHeader.o DMRSlot.o DMRSync.o DStarEcho.o DStarHeader.o DStarNetwork.o \ - EMB.o EmbeddedLC.o FullLC.o Golay2087.o Golay24128.o Hamming.o HomebrewDMRIPSC.o LC.o Log.o MMDVMHost.o Modem.o NullDisplay.o QR1676.o RS129.o \ - SerialController.o SHA256.o ShortLC.o SlotType.o StopWatch.o TFTSerial.o Timer.o UDPSocket.o Utils.o YSFEcho.o + DStarSlowData.o EMB.o EmbeddedLC.o FullLC.o Golay2087.o Golay24128.o Hamming.o HomebrewDMRIPSC.o LC.o Log.o MMDVMHost.o Modem.o NullDisplay.o QR1676.o \ + RS129.o SerialController.o SHA256.o ShortLC.o SlotType.o StopWatch.o TFTSerial.o Timer.o UDPSocket.o Utils.o YSFEcho.o $(CC) $(LDFLAGS) -o MMDVMHost AMBEFEC.o BPTC19696.o Conf.o CRC.o CSBK.o Display.o DMRControl.o DMRData.o DMRDataHeader.o DMRSlot.o DMRSync.o DStarEcho.o \ - DStarHeader.o DStarNetwork.o EMB.o EmbeddedLC.o FullLC.o Golay2087.o Golay24128.o Hamming.o HomebrewDMRIPSC.o LC.o Log.o MMDVMHost.o Modem.o \ - NullDisplay.o QR1676.o RS129.o SerialController.o SHA256.o ShortLC.o SlotType.o StopWatch.o TFTSerial.o Timer.o UDPSocket.o Utils.o YSFEcho.o $(LIBS) + DStarHeader.o DStarNetwork.o DStarSlowData.o EMB.o EmbeddedLC.o FullLC.o Golay2087.o Golay24128.o Hamming.o HomebrewDMRIPSC.o LC.o Log.o MMDVMHost.o \ + Modem.o NullDisplay.o QR1676.o RS129.o SerialController.o SHA256.o ShortLC.o SlotType.o StopWatch.o TFTSerial.o Timer.o UDPSocket.o Utils.o YSFEcho.o \ + $(LIBS) AMBEFEC.o: AMBEFEC.cpp AMBEFEC.h Golay24128.h $(CC) $(CFLAGS) -c AMBEFEC.cpp @@ -55,6 +56,9 @@ DStarHeader.o: DStarHeader.cpp DStarHeader.h DStarDefines.h CRC.h DStarNetwork.o: DStarNetwork.cpp DStarNetwork.h Log.h UDPSocket.h RingBuffer.h Utils.h StopWatch.h DStarDefines.h Defines.h Timer.h $(CC) $(CFLAGS) -c DStarNetwork.cpp +DStarSlowData.o: DStarSlowData.cpp DStarSlowData.h DStarHeader.h DStarDefines.h CRC.h + $(CC) $(CFLAGS) -c DStarSlowData.cpp + EMB.o: EMB.cpp EMB.h $(CC) $(CFLAGS) -c EMB.cpp