2016-09-14 06:41:37 +00:00
|
|
|
/*
|
2020-09-06 11:54:08 +00:00
|
|
|
* Copyright (C) 2009-2014,2016,2019,2020 by Jonathan Naylor G4KLX
|
2016-09-14 06:41:37 +00: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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "P25Network.h"
|
2016-09-22 18:39:19 +00:00
|
|
|
#include "P25Defines.h"
|
2016-09-14 06:41:37 +00:00
|
|
|
#include "Defines.h"
|
|
|
|
#include "Utils.h"
|
|
|
|
#include "Log.h"
|
|
|
|
|
|
|
|
#include <cstdio>
|
|
|
|
#include <cassert>
|
|
|
|
#include <cstring>
|
|
|
|
|
2016-09-29 17:47:36 +00:00
|
|
|
const unsigned char REC62[] = {
|
2017-10-31 10:18:15 +00:00
|
|
|
0x62U, 0x02U, 0x02U, 0x0CU, 0x0BU, 0x12U, 0x64U, 0x00U, 0x00U, 0x80U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U,
|
2017-10-30 13:45:59 +00:00
|
|
|
0x00U, 0x00U, 0x00U, 0x00U, 0x00U};
|
2016-11-01 19:01:37 +00:00
|
|
|
|
|
|
|
const unsigned char REC63[] = {
|
2017-10-30 12:23:49 +00:00
|
|
|
0x63U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U};
|
2016-11-01 19:01:37 +00:00
|
|
|
|
|
|
|
const unsigned char REC64[] = {
|
|
|
|
0x64U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U};
|
|
|
|
|
|
|
|
const unsigned char REC65[] = {
|
|
|
|
0x65U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U};
|
|
|
|
|
|
|
|
const unsigned char REC66[] = {
|
|
|
|
0x66U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U};
|
|
|
|
|
|
|
|
const unsigned char REC67[] = {
|
2017-10-31 10:18:15 +00:00
|
|
|
0x67U, 0xF0U, 0x9DU, 0x6AU, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U};
|
2016-11-01 19:01:37 +00:00
|
|
|
|
|
|
|
const unsigned char REC68[] = {
|
2017-10-31 10:18:15 +00:00
|
|
|
0x68U, 0x19U, 0xD4U, 0x26U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U};
|
2016-11-01 19:01:37 +00:00
|
|
|
|
|
|
|
const unsigned char REC69[] = {
|
2017-10-31 10:18:15 +00:00
|
|
|
0x69U, 0xE0U, 0xEBU, 0x7BU, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U};
|
2016-11-01 19:01:37 +00:00
|
|
|
|
|
|
|
const unsigned char REC6A[] = {
|
2017-10-30 13:45:59 +00:00
|
|
|
0x6AU, 0x00U, 0x00U, 0x02U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U};
|
2016-09-29 17:47:36 +00:00
|
|
|
|
|
|
|
const unsigned char REC6B[] = {
|
2017-10-31 10:18:15 +00:00
|
|
|
0x6BU, 0x02U, 0x02U, 0x0CU, 0x0BU, 0x12U, 0x64U, 0x00U, 0x00U, 0x80U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U,
|
2017-10-30 13:45:59 +00:00
|
|
|
0x00U, 0x00U, 0x00U, 0x00U, 0x00U};
|
2016-11-01 19:01:37 +00:00
|
|
|
|
|
|
|
const unsigned char REC6C[] = {
|
2017-10-30 12:23:49 +00:00
|
|
|
0x6CU, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U};
|
2016-11-01 19:01:37 +00:00
|
|
|
|
|
|
|
const unsigned char REC6D[] = {
|
|
|
|
0x6DU, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U};
|
|
|
|
|
|
|
|
const unsigned char REC6E[] = {
|
|
|
|
0x6EU, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U};
|
|
|
|
|
|
|
|
const unsigned char REC6F[] = {
|
|
|
|
0x6FU, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U};
|
|
|
|
|
|
|
|
const unsigned char REC70[] = {
|
|
|
|
0x70U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U};
|
|
|
|
|
|
|
|
const unsigned char REC71[] = {
|
|
|
|
0x71U, 0xACU, 0xB8U, 0xA4U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U};
|
|
|
|
|
|
|
|
const unsigned char REC72[] = {
|
|
|
|
0x72U, 0x9BU, 0xDCU, 0x75U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U};
|
|
|
|
|
|
|
|
const unsigned char REC73[] = {
|
2017-10-30 13:45:59 +00:00
|
|
|
0x73U, 0x00U, 0x00U, 0x02U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U};
|
2016-11-01 19:01:37 +00:00
|
|
|
|
|
|
|
const unsigned char REC80[] = {
|
|
|
|
0x80U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U};
|
2016-09-21 06:51:13 +00:00
|
|
|
|
2016-09-14 06:41:37 +00:00
|
|
|
const unsigned int BUFFER_LENGTH = 100U;
|
|
|
|
|
|
|
|
CP25Network::CP25Network(const std::string& gatewayAddress, unsigned int gatewayPort, unsigned int localPort, bool debug) :
|
|
|
|
m_socket(localPort),
|
2020-09-06 11:54:08 +00:00
|
|
|
m_addr(),
|
|
|
|
m_addrLen(0U),
|
2016-09-14 06:41:37 +00:00
|
|
|
m_debug(debug),
|
|
|
|
m_enabled(false),
|
2016-09-21 06:51:13 +00:00
|
|
|
m_buffer(1000U, "P25 Network"),
|
|
|
|
m_audio()
|
2016-09-14 06:41:37 +00:00
|
|
|
{
|
2020-09-06 11:54:08 +00:00
|
|
|
if (CUDPSocket::lookup(gatewayAddress, gatewayPort, m_addr, m_addrLen) != 0)
|
|
|
|
m_addrLen = 0U;
|
2016-09-14 06:41:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CP25Network::~CP25Network()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CP25Network::open()
|
|
|
|
{
|
2020-09-06 11:54:08 +00:00
|
|
|
if (m_addrLen == 0U) {
|
|
|
|
LogError("Unable to resolve the address of the P25 Gateway");
|
2016-09-14 06:41:37 +00:00
|
|
|
return false;
|
2020-09-06 11:54:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LogMessage("Opening P25 network connection");
|
2016-09-14 06:41:37 +00:00
|
|
|
|
2020-09-06 11:54:08 +00:00
|
|
|
return m_socket.open(m_addr);
|
2016-09-14 06:41:37 +00:00
|
|
|
}
|
|
|
|
|
2016-09-28 06:53:45 +00:00
|
|
|
bool CP25Network::writeLDU1(const unsigned char* ldu1, const CP25Data& control, const CP25LowSpeedData& lsd, bool end)
|
2016-09-15 19:28:56 +00:00
|
|
|
{
|
|
|
|
assert(ldu1 != NULL);
|
2016-09-20 06:53:16 +00:00
|
|
|
|
|
|
|
unsigned char buffer[22U];
|
|
|
|
|
|
|
|
// The '62' record
|
2016-09-29 17:47:36 +00:00
|
|
|
::memcpy(buffer, REC62, 22U);
|
2016-09-21 06:51:13 +00:00
|
|
|
m_audio.decode(ldu1, buffer + 10U, 0U);
|
2016-09-15 19:28:56 +00:00
|
|
|
|
|
|
|
if (m_debug)
|
2016-09-20 06:53:16 +00:00
|
|
|
CUtils::dump(1U, "P25 Network LDU1 Sent", buffer, 22U);
|
2016-09-15 19:28:56 +00:00
|
|
|
|
2020-09-06 11:54:08 +00:00
|
|
|
bool ret = m_socket.write(buffer, 22U, m_addr, m_addrLen);
|
2016-09-20 06:53:16 +00:00
|
|
|
if (!ret)
|
|
|
|
return false;
|
|
|
|
|
2016-09-21 06:51:13 +00:00
|
|
|
// The '63' record
|
2016-11-01 19:01:37 +00:00
|
|
|
::memcpy(buffer, REC63, 14U);
|
2016-09-21 06:51:13 +00:00
|
|
|
m_audio.decode(ldu1, buffer + 1U, 1U);
|
|
|
|
|
|
|
|
if (m_debug)
|
2016-09-22 20:26:03 +00:00
|
|
|
CUtils::dump(1U, "P25 Network LDU1 Sent", buffer, 14U);
|
2016-09-21 06:51:13 +00:00
|
|
|
|
2020-09-06 11:54:08 +00:00
|
|
|
ret = m_socket.write(buffer, 14U, m_addr, m_addrLen);
|
2016-09-21 06:51:13 +00:00
|
|
|
if (!ret)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// The '64' record
|
2016-11-01 19:01:37 +00:00
|
|
|
::memcpy(buffer, REC64, 17U);
|
2016-09-22 18:39:19 +00:00
|
|
|
buffer[1U] = control.getLCF();
|
|
|
|
buffer[2U] = control.getMFId();
|
2016-09-21 06:51:13 +00:00
|
|
|
m_audio.decode(ldu1, buffer + 5U, 2U);
|
|
|
|
|
|
|
|
if (m_debug)
|
|
|
|
CUtils::dump(1U, "P25 Network LDU1 Sent", buffer, 17U);
|
|
|
|
|
2020-09-06 11:54:08 +00:00
|
|
|
ret = m_socket.write(buffer, 17U, m_addr, m_addrLen);
|
2016-09-21 06:51:13 +00:00
|
|
|
if (!ret)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// The '65' record
|
2016-11-01 19:01:37 +00:00
|
|
|
::memcpy(buffer, REC65, 17U);
|
2016-09-22 18:39:19 +00:00
|
|
|
unsigned int id = control.getDstId();
|
|
|
|
buffer[1U] = (id >> 16) & 0xFFU;
|
|
|
|
buffer[2U] = (id >> 8) & 0xFFU;
|
|
|
|
buffer[3U] = (id >> 0) & 0xFFU;
|
2016-09-21 06:51:13 +00:00
|
|
|
m_audio.decode(ldu1, buffer + 5U, 3U);
|
|
|
|
|
|
|
|
if (m_debug)
|
|
|
|
CUtils::dump(1U, "P25 Network LDU1 Sent", buffer, 17U);
|
|
|
|
|
2020-09-06 11:54:08 +00:00
|
|
|
ret = m_socket.write(buffer, 17U, m_addr, m_addrLen);
|
2016-09-21 06:51:13 +00:00
|
|
|
if (!ret)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// The '66' record
|
2016-11-01 19:01:37 +00:00
|
|
|
::memcpy(buffer, REC66, 17U);
|
2016-09-22 18:39:19 +00:00
|
|
|
id = control.getSrcId();
|
|
|
|
buffer[1U] = (id >> 16) & 0xFFU;
|
|
|
|
buffer[2U] = (id >> 8) & 0xFFU;
|
|
|
|
buffer[3U] = (id >> 0) & 0xFFU;
|
2016-09-21 06:51:13 +00:00
|
|
|
m_audio.decode(ldu1, buffer + 5U, 4U);
|
|
|
|
|
|
|
|
if (m_debug)
|
|
|
|
CUtils::dump(1U, "P25 Network LDU1 Sent", buffer, 17U);
|
|
|
|
|
2020-09-06 11:54:08 +00:00
|
|
|
ret = m_socket.write(buffer, 17U, m_addr, m_addrLen);
|
2016-09-21 06:51:13 +00:00
|
|
|
if (!ret)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// The '67' record
|
2016-11-01 19:01:37 +00:00
|
|
|
::memcpy(buffer, REC67, 17U);
|
2016-09-21 06:51:13 +00:00
|
|
|
m_audio.decode(ldu1, buffer + 5U, 5U);
|
|
|
|
|
|
|
|
if (m_debug)
|
|
|
|
CUtils::dump(1U, "P25 Network LDU1 Sent", buffer, 17U);
|
|
|
|
|
2020-09-06 11:54:08 +00:00
|
|
|
ret = m_socket.write(buffer, 17U, m_addr, m_addrLen);
|
2016-09-21 06:51:13 +00:00
|
|
|
if (!ret)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// The '68' record
|
2016-11-01 19:01:37 +00:00
|
|
|
::memcpy(buffer, REC68, 17U);
|
2016-09-21 06:51:13 +00:00
|
|
|
m_audio.decode(ldu1, buffer + 5U, 6U);
|
|
|
|
|
|
|
|
if (m_debug)
|
|
|
|
CUtils::dump(1U, "P25 Network LDU1 Sent", buffer, 17U);
|
|
|
|
|
2020-09-06 11:54:08 +00:00
|
|
|
ret = m_socket.write(buffer, 17U, m_addr, m_addrLen);
|
2016-09-21 06:51:13 +00:00
|
|
|
if (!ret)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// The '69' record
|
2016-11-01 19:01:37 +00:00
|
|
|
::memcpy(buffer, REC69, 17U);
|
2016-09-21 06:51:13 +00:00
|
|
|
m_audio.decode(ldu1, buffer + 5U, 7U);
|
|
|
|
|
|
|
|
if (m_debug)
|
|
|
|
CUtils::dump(1U, "P25 Network LDU1 Sent", buffer, 17U);
|
|
|
|
|
2020-09-06 11:54:08 +00:00
|
|
|
ret = m_socket.write(buffer, 17U, m_addr, m_addrLen);
|
2016-09-21 06:51:13 +00:00
|
|
|
if (!ret)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// The '6A' record
|
2016-11-01 19:01:37 +00:00
|
|
|
::memcpy(buffer, REC6A, 16U);
|
2016-09-22 18:39:19 +00:00
|
|
|
buffer[1U] = lsd.getLSD1();
|
|
|
|
buffer[2U] = lsd.getLSD2();
|
2016-09-21 06:51:13 +00:00
|
|
|
m_audio.decode(ldu1, buffer + 4U, 8U);
|
|
|
|
|
|
|
|
if (m_debug)
|
|
|
|
CUtils::dump(1U, "P25 Network LDU1 Sent", buffer, 16U);
|
|
|
|
|
2020-09-06 11:54:08 +00:00
|
|
|
ret = m_socket.write(buffer, 16U, m_addr, m_addrLen);
|
2016-09-21 06:51:13 +00:00
|
|
|
if (!ret)
|
|
|
|
return false;
|
|
|
|
|
2016-11-01 19:01:37 +00:00
|
|
|
if (end) {
|
|
|
|
if (m_debug)
|
|
|
|
CUtils::dump(1U, "P25 Network END Sent", REC80, 17U);
|
|
|
|
|
2020-09-06 11:54:08 +00:00
|
|
|
ret = m_socket.write(REC80, 17U, m_addr, m_addrLen);
|
2016-11-01 19:01:37 +00:00
|
|
|
if (!ret)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-09-15 19:28:56 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-09-28 06:53:45 +00:00
|
|
|
bool CP25Network::writeLDU2(const unsigned char* ldu2, const CP25Data& control, const CP25LowSpeedData& lsd, bool end)
|
2016-09-14 06:41:37 +00:00
|
|
|
{
|
2016-09-15 19:28:56 +00:00
|
|
|
assert(ldu2 != NULL);
|
2016-09-20 06:53:16 +00:00
|
|
|
|
|
|
|
unsigned char buffer[22U];
|
|
|
|
|
|
|
|
// The '6B' record
|
2016-09-29 17:47:36 +00:00
|
|
|
::memcpy(buffer, REC6B, 22U);
|
2016-09-21 06:51:13 +00:00
|
|
|
m_audio.decode(ldu2, buffer + 10U, 0U);
|
2016-09-14 06:41:37 +00:00
|
|
|
|
|
|
|
if (m_debug)
|
2016-09-20 06:53:16 +00:00
|
|
|
CUtils::dump(1U, "P25 Network LDU2 Sent", buffer, 22U);
|
2016-09-14 06:41:37 +00:00
|
|
|
|
2020-09-06 11:54:08 +00:00
|
|
|
bool ret = m_socket.write(buffer, 22U, m_addr, m_addrLen);
|
2016-09-20 06:53:16 +00:00
|
|
|
if (!ret)
|
|
|
|
return false;
|
|
|
|
|
2016-09-21 06:51:13 +00:00
|
|
|
// The '6C' record
|
2016-11-01 19:01:37 +00:00
|
|
|
::memcpy(buffer, REC6C, 14U);
|
2016-09-21 06:51:13 +00:00
|
|
|
m_audio.decode(ldu2, buffer + 1U, 1U);
|
2016-09-14 06:41:37 +00:00
|
|
|
|
2016-09-21 06:51:13 +00:00
|
|
|
if (m_debug)
|
2016-09-22 20:26:03 +00:00
|
|
|
CUtils::dump(1U, "P25 Network LDU2 Sent", buffer, 14U);
|
2016-09-21 06:51:13 +00:00
|
|
|
|
2020-09-06 11:54:08 +00:00
|
|
|
ret = m_socket.write(buffer, 14U, m_addr, m_addrLen);
|
2016-09-21 06:51:13 +00:00
|
|
|
if (!ret)
|
|
|
|
return false;
|
|
|
|
|
2016-09-22 18:39:19 +00:00
|
|
|
unsigned char mi[P25_MI_LENGTH_BYTES];
|
|
|
|
control.getMI(mi);
|
|
|
|
|
2016-09-21 06:51:13 +00:00
|
|
|
// The '6D' record
|
2016-11-01 19:01:37 +00:00
|
|
|
::memcpy(buffer, REC6D, 17U);
|
2016-09-22 18:39:19 +00:00
|
|
|
buffer[1U] = mi[0U];
|
|
|
|
buffer[2U] = mi[1U];
|
|
|
|
buffer[3U] = mi[2U];
|
2016-09-21 06:51:13 +00:00
|
|
|
m_audio.decode(ldu2, buffer + 5U, 2U);
|
|
|
|
|
|
|
|
if (m_debug)
|
|
|
|
CUtils::dump(1U, "P25 Network LDU2 Sent", buffer, 17U);
|
|
|
|
|
2020-09-06 11:54:08 +00:00
|
|
|
ret = m_socket.write(buffer, 17U, m_addr, m_addrLen);
|
2016-09-21 06:51:13 +00:00
|
|
|
if (!ret)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// The '6E' record
|
2016-11-01 19:01:37 +00:00
|
|
|
::memcpy(buffer, REC6E, 17U);
|
2016-09-22 18:39:19 +00:00
|
|
|
buffer[1U] = mi[3U];
|
|
|
|
buffer[2U] = mi[4U];
|
|
|
|
buffer[3U] = mi[5U];
|
2016-09-21 06:51:13 +00:00
|
|
|
m_audio.decode(ldu2, buffer + 5U, 3U);
|
|
|
|
|
|
|
|
if (m_debug)
|
|
|
|
CUtils::dump(1U, "P25 Network LDU2 Sent", buffer, 17U);
|
|
|
|
|
2020-09-06 11:54:08 +00:00
|
|
|
ret = m_socket.write(buffer, 17U, m_addr, m_addrLen);
|
2016-09-21 06:51:13 +00:00
|
|
|
if (!ret)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// The '6F' record
|
2016-11-01 19:01:37 +00:00
|
|
|
::memcpy(buffer, REC6F, 17U);
|
2016-09-22 18:39:19 +00:00
|
|
|
buffer[1U] = mi[6U];
|
|
|
|
buffer[2U] = mi[7U];
|
|
|
|
buffer[3U] = mi[8U];
|
2016-09-21 06:51:13 +00:00
|
|
|
m_audio.decode(ldu2, buffer + 5U, 4U);
|
|
|
|
|
|
|
|
if (m_debug)
|
|
|
|
CUtils::dump(1U, "P25 Network LDU2 Sent", buffer, 17U);
|
|
|
|
|
2020-09-06 11:54:08 +00:00
|
|
|
ret = m_socket.write(buffer, 17U, m_addr, m_addrLen);
|
2016-09-21 06:51:13 +00:00
|
|
|
if (!ret)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// The '70' record
|
2016-11-01 19:01:37 +00:00
|
|
|
::memcpy(buffer, REC70, 17U);
|
2016-09-22 18:39:19 +00:00
|
|
|
buffer[1U] = control.getAlgId();
|
|
|
|
unsigned int id = control.getKId();
|
|
|
|
buffer[2U] = (id >> 8) & 0xFFU;
|
|
|
|
buffer[3U] = (id >> 0) & 0xFFU;
|
2016-09-21 06:51:13 +00:00
|
|
|
m_audio.decode(ldu2, buffer + 5U, 5U);
|
|
|
|
|
|
|
|
if (m_debug)
|
|
|
|
CUtils::dump(1U, "P25 Network LDU2 Sent", buffer, 17U);
|
|
|
|
|
2020-09-06 11:54:08 +00:00
|
|
|
ret = m_socket.write(buffer, 17U, m_addr, m_addrLen);
|
2016-09-21 06:51:13 +00:00
|
|
|
if (!ret)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// The '71' record
|
2016-11-01 19:01:37 +00:00
|
|
|
::memcpy(buffer, REC71, 17U);
|
2016-09-21 06:51:13 +00:00
|
|
|
m_audio.decode(ldu2, buffer + 5U, 6U);
|
|
|
|
|
|
|
|
if (m_debug)
|
|
|
|
CUtils::dump(1U, "P25 Network LDU2 Sent", buffer, 17U);
|
|
|
|
|
2020-09-06 11:54:08 +00:00
|
|
|
ret = m_socket.write(buffer, 17U, m_addr, m_addrLen);
|
2016-09-21 06:51:13 +00:00
|
|
|
if (!ret)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// The '72' record
|
2016-11-01 19:01:37 +00:00
|
|
|
::memcpy(buffer, REC72, 17U);
|
2016-09-21 06:51:13 +00:00
|
|
|
m_audio.decode(ldu2, buffer + 5U, 7U);
|
|
|
|
|
|
|
|
if (m_debug)
|
|
|
|
CUtils::dump(1U, "P25 Network LDU2 Sent", buffer, 17U);
|
|
|
|
|
2020-09-06 11:54:08 +00:00
|
|
|
ret = m_socket.write(buffer, 17U, m_addr, m_addrLen);
|
2016-09-21 06:51:13 +00:00
|
|
|
if (!ret)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// The '73' record
|
2016-11-01 19:01:37 +00:00
|
|
|
::memcpy(buffer, REC73, 16U);
|
2016-09-22 18:39:19 +00:00
|
|
|
buffer[1U] = lsd.getLSD1();
|
|
|
|
buffer[2U] = lsd.getLSD2();
|
2016-09-21 06:51:13 +00:00
|
|
|
m_audio.decode(ldu2, buffer + 4U, 8U);
|
2016-09-20 06:53:16 +00:00
|
|
|
|
2016-09-21 06:51:13 +00:00
|
|
|
if (m_debug)
|
|
|
|
CUtils::dump(1U, "P25 Network LDU2 Sent", buffer, 16U);
|
|
|
|
|
2020-09-06 11:54:08 +00:00
|
|
|
ret = m_socket.write(buffer, 16U, m_addr, m_addrLen);
|
2016-09-21 06:51:13 +00:00
|
|
|
if (!ret)
|
|
|
|
return false;
|
2016-09-20 06:53:16 +00:00
|
|
|
|
2016-11-01 19:01:37 +00:00
|
|
|
if (end) {
|
|
|
|
if (m_debug)
|
|
|
|
CUtils::dump(1U, "P25 Network END Sent", REC80, 17U);
|
|
|
|
|
2020-09-06 11:54:08 +00:00
|
|
|
ret = m_socket.write(REC80, 17U, m_addr, m_addrLen);
|
2016-11-01 19:01:37 +00:00
|
|
|
if (!ret)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-09-14 06:41:37 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CP25Network::clock(unsigned int ms)
|
|
|
|
{
|
|
|
|
unsigned char buffer[BUFFER_LENGTH];
|
|
|
|
|
2020-03-27 20:40:35 +00:00
|
|
|
sockaddr_storage address;
|
2020-09-06 11:54:08 +00:00
|
|
|
unsigned int addrLen;
|
|
|
|
int length = m_socket.read(buffer, BUFFER_LENGTH, address, addrLen);
|
|
|
|
if (length <= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!CUDPSocket::match(m_addr, address)) {
|
|
|
|
LogMessage("P25, packet received from an invalid source");
|
2016-09-14 06:41:37 +00:00
|
|
|
return;
|
2020-09-06 11:54:08 +00:00
|
|
|
}
|
2016-09-14 06:41:37 +00:00
|
|
|
|
|
|
|
if (!m_enabled)
|
|
|
|
return;
|
|
|
|
|
2016-10-13 21:39:57 +00:00
|
|
|
if (m_debug)
|
2016-10-14 08:30:10 +00:00
|
|
|
CUtils::dump(1U, "P25 Network Data Received", buffer, length);
|
2016-10-13 21:39:57 +00:00
|
|
|
|
2016-09-20 06:53:16 +00:00
|
|
|
unsigned char c = length;
|
|
|
|
m_buffer.addData(&c, 1U);
|
|
|
|
|
|
|
|
m_buffer.addData(buffer, length);
|
2016-09-14 06:41:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int CP25Network::read(unsigned char* data, unsigned int length)
|
|
|
|
{
|
|
|
|
assert(data != NULL);
|
|
|
|
|
|
|
|
if (m_buffer.isEmpty())
|
|
|
|
return 0U;
|
|
|
|
|
|
|
|
unsigned char c = 0U;
|
|
|
|
m_buffer.getData(&c, 1U);
|
|
|
|
|
|
|
|
assert(c <= length);
|
|
|
|
|
2016-09-20 06:53:16 +00:00
|
|
|
m_buffer.getData(data, c);
|
2016-09-14 06:41:37 +00:00
|
|
|
|
2016-09-20 06:53:16 +00:00
|
|
|
return c;
|
2016-09-14 06:41:37 +00:00
|
|
|
}
|
|
|
|
|
2021-03-22 19:27:08 +00:00
|
|
|
bool CP25Network::isConnected() const
|
|
|
|
{
|
2021-03-23 21:32:36 +00:00
|
|
|
return (m_addrLen != 0);
|
2021-03-22 19:27:08 +00:00
|
|
|
}
|
|
|
|
|
2016-09-14 06:41:37 +00:00
|
|
|
void CP25Network::close()
|
|
|
|
{
|
|
|
|
m_socket.close();
|
|
|
|
|
|
|
|
LogMessage("Closing P25 network connection");
|
|
|
|
}
|
|
|
|
|
|
|
|
void CP25Network::enable(bool enabled)
|
|
|
|
{
|
2019-01-15 21:45:29 +00:00
|
|
|
if (!enabled && m_enabled)
|
|
|
|
m_buffer.clear();
|
|
|
|
|
2016-09-14 06:41:37 +00:00
|
|
|
m_enabled = enabled;
|
|
|
|
}
|