Add AX.25 transmit functionality to the modem handler.
This commit is contained in:
parent
c026471aec
commit
92ceba052a
|
@ -12,6 +12,7 @@
|
|||
*/
|
||||
|
||||
#include "AX25Control.h"
|
||||
#include "AX25Defines.h"
|
||||
#include "Utils.h"
|
||||
#include "Log.h"
|
||||
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Copyright (C) 2020 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.
|
||||
*/
|
||||
|
||||
#if !defined(AX25Defines_H)
|
||||
#define AX25Defines_H
|
||||
|
||||
const unsigned int AX25_CALLSIGN_TEXT_LENGTH = 6U;
|
||||
const unsigned int AX25_SSID_LENGTH = 1U;
|
||||
const unsigned int AX25_CALLSIGN_LENGTH = 7U;
|
||||
|
||||
const unsigned int AX25_MAX_DIGIPEATERS = 6U;
|
||||
|
||||
const unsigned char AX25_PID_NOL3 = 0xF0U;
|
||||
|
||||
const unsigned int AX25_MAX_FRAME_LENGTH_BYTES = 300U;
|
||||
|
||||
const unsigned char AX25_KISS_DATA = 0x00U;
|
||||
|
||||
const unsigned char AX25_FEND = 0xC0U;
|
||||
const unsigned char AX25_FESC = 0xDBU;
|
||||
const unsigned char AX25_TFEND = 0xDCU;
|
||||
const unsigned char AX25_TFESC = 0xDDU;
|
||||
|
||||
#endif
|
|
@ -17,6 +17,7 @@
|
|||
*/
|
||||
|
||||
#include "AX25Network.h"
|
||||
#include "AX25Defines.h"
|
||||
#include "Defines.h"
|
||||
#include "Utils.h"
|
||||
#include "Log.h"
|
||||
|
@ -27,12 +28,6 @@
|
|||
|
||||
const unsigned int BUFFER_LENGTH = 500U;
|
||||
|
||||
const unsigned char AX25_KISS_DATA = 0x00U;
|
||||
|
||||
const unsigned char AX25_FEND = 0xC0U;
|
||||
const unsigned char AX25_FESC = 0xDBU;
|
||||
const unsigned char AX25_TFEND = 0xDCU;
|
||||
const unsigned char AX25_TFESC = 0xDDU;
|
||||
|
||||
CAX25Network::CAX25Network(const std::string& port, unsigned int speed, bool debug) :
|
||||
m_serial(port, SERIAL_SPEED(speed), false), // XXX
|
||||
|
|
|
@ -154,6 +154,7 @@
|
|||
<ItemGroup>
|
||||
<ClInclude Include="AMBEFEC.h" />
|
||||
<ClInclude Include="AX25Control.h" />
|
||||
<ClInclude Include="AX25Defines.h" />
|
||||
<ClInclude Include="AX25Network.h" />
|
||||
<ClInclude Include="BCH.h" />
|
||||
<ClInclude Include="BPTC19696.h" />
|
||||
|
|
|
@ -311,6 +311,9 @@
|
|||
<ClInclude Include="NXDNKenwoodNetwork.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="AX25Defines.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="BPTC19696.cpp">
|
||||
|
|
61
Modem.cpp
61
Modem.cpp
|
@ -22,6 +22,7 @@
|
|||
#include "YSFDefines.h"
|
||||
#include "P25Defines.h"
|
||||
#include "NXDNDefines.h"
|
||||
#include "AX25Defines.h"
|
||||
#include "POCSAGDefines.h"
|
||||
#include "Thread.h"
|
||||
#include "Modem.h"
|
||||
|
@ -160,6 +161,7 @@ m_rxNXDNData(1000U, "Modem RX NXDN"),
|
|||
m_txNXDNData(1000U, "Modem TX NXDN"),
|
||||
m_txPOCSAGData(1000U, "Modem TX POCSAG"),
|
||||
m_rxAX25Data(1000U, "Modem RX AX.25"),
|
||||
m_txAX25Data(1000U, "Modem TX AX.25"),
|
||||
m_rxTransparentData(1000U, "Modem RX Transparent"),
|
||||
m_txTransparentData(1000U, "Modem TX Transparent"),
|
||||
m_sendTransparentDataFrameType(0U),
|
||||
|
@ -173,6 +175,7 @@ m_ysfSpace(0U),
|
|||
m_p25Space(0U),
|
||||
m_nxdnSpace(0U),
|
||||
m_pocsagSpace(0U),
|
||||
m_ax25Space(0U),
|
||||
m_tx(false),
|
||||
m_cd(false),
|
||||
m_lockout(false),
|
||||
|
@ -621,6 +624,7 @@ void CModem::clock(unsigned int ms)
|
|||
m_p25Space = 0U;
|
||||
m_nxdnSpace = 0U;
|
||||
m_pocsagSpace = 0U;
|
||||
m_ax25Space = 0U;
|
||||
|
||||
m_mode = m_buffer[m_offset + 1U];
|
||||
|
||||
|
@ -657,9 +661,11 @@ void CModem::clock(unsigned int ms)
|
|||
m_nxdnSpace = m_buffer[m_offset + 8U];
|
||||
if (m_length > (m_offset + 9U))
|
||||
m_pocsagSpace = m_buffer[m_offset + 9U];
|
||||
if (m_length > (m_offset + 10U))
|
||||
m_ax25Space = m_buffer[m_offset + 10U] * 8U;
|
||||
|
||||
m_inactivityTimer.start();
|
||||
// LogMessage("status=%02X, tx=%d, space=%u,%u,%u,%u,%u,%u,%u lockout=%d, cd=%d", m_buffer[m_offset + 2U], int(m_tx), m_dstarSpace, m_dmrSpace1, m_dmrSpace2, m_ysfSpace, m_p25Space, m_nxdnSpace, m_pocsagSpace, int(m_lockout), int(m_cd));
|
||||
// LogMessage("status=%02X, tx=%d, space=%u,%u,%u,%u,%u,%u,%u,%u lockout=%d, cd=%d", m_buffer[m_offset + 2U], int(m_tx), m_dstarSpace, m_dmrSpace1, m_dmrSpace2, m_ysfSpace, m_p25Space, m_nxdnSpace, m_pocsagSpace, m_ax25Space, int(m_lockout), int(m_cd));
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -863,6 +869,23 @@ void CModem::clock(unsigned int ms)
|
|||
m_pocsagSpace--;
|
||||
}
|
||||
|
||||
if (m_ax25Space > 1U && !m_txAX25Data.isEmpty()) {
|
||||
unsigned char len = 0U;
|
||||
m_txAX25Data.getData((unsigned char*)&len, sizeof(unsigned int));
|
||||
m_txAX25Data.getData(m_buffer, len);
|
||||
|
||||
if (m_trace)
|
||||
CUtils::dump(1U, "TX AX.25 Data", m_buffer, len);
|
||||
|
||||
int ret = m_serial->write(m_buffer, len);
|
||||
if (ret != int(len))
|
||||
LogWarning("Error when writing AX.25 data to the MMDVM");
|
||||
|
||||
m_playoutTimer.start();
|
||||
|
||||
m_ax25Space -= len;
|
||||
}
|
||||
|
||||
if (!m_txTransparentData.isEmpty()) {
|
||||
unsigned char len = 0U;
|
||||
m_txTransparentData.getData(&len, 1U);
|
||||
|
@ -1225,6 +1248,42 @@ bool CModem::writePOCSAGData(const unsigned char* data, unsigned int length)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool CModem::hasAX25Space() const
|
||||
{
|
||||
unsigned int space = m_txAX25Data.freeSpace() / (AX25_MAX_FRAME_LENGTH_BYTES + 5U);
|
||||
|
||||
return space > 1U;
|
||||
}
|
||||
|
||||
bool CModem::writeAX25Data(const unsigned char* data, unsigned int length)
|
||||
{
|
||||
assert(data != NULL);
|
||||
assert(length > 0U);
|
||||
|
||||
unsigned char buffer[500U];
|
||||
|
||||
unsigned int len;
|
||||
if (length > 252U) {
|
||||
buffer[0U] = MMDVM_FRAME_START;
|
||||
buffer[1U] = 0U;
|
||||
buffer[2U] = (length + 4U) - 255U;
|
||||
buffer[3U] = MMDVM_AX25_DATA;
|
||||
::memcpy(buffer + 4U, data, length);
|
||||
len = length + 4U;
|
||||
} else {
|
||||
buffer[0U] = MMDVM_FRAME_START;
|
||||
buffer[1U] = length + 3U;
|
||||
buffer[2U] = MMDVM_AX25_DATA;
|
||||
::memcpy(buffer + 3U, data, length);
|
||||
len = length + 3U;
|
||||
}
|
||||
|
||||
m_txAX25Data.addData((unsigned char*)&len, sizeof(unsigned int));
|
||||
m_txAX25Data.addData(buffer, len);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CModem::writeTransparentData(const unsigned char* data, unsigned int length)
|
||||
{
|
||||
assert(data != NULL);
|
||||
|
|
2
Modem.h
2
Modem.h
|
@ -186,6 +186,7 @@ private:
|
|||
CRingBuffer<unsigned char> m_txNXDNData;
|
||||
CRingBuffer<unsigned char> m_txPOCSAGData;
|
||||
CRingBuffer<unsigned char> m_rxAX25Data;
|
||||
CRingBuffer<unsigned char> m_txAX25Data;
|
||||
CRingBuffer<unsigned char> m_rxTransparentData;
|
||||
CRingBuffer<unsigned char> m_txTransparentData;
|
||||
unsigned int m_sendTransparentDataFrameType;
|
||||
|
@ -199,6 +200,7 @@ private:
|
|||
unsigned int m_p25Space;
|
||||
unsigned int m_nxdnSpace;
|
||||
unsigned int m_pocsagSpace;
|
||||
unsigned int m_ax25Space;
|
||||
bool m_tx;
|
||||
bool m_cd;
|
||||
bool m_lockout;
|
||||
|
|
Loading…
Reference in New Issue