2016-09-14 06:41:37 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2009-2014,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 "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-21 06:51:13 +00:00
|
|
|
const unsigned char STARTICW[] = {
|
2016-09-22 20:26:03 +00:00
|
|
|
0x00U, 0x02U, 0x02U, 0x0CU, 0x0BU, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U};
|
2016-09-21 06:51:13 +00:00
|
|
|
|
|
|
|
const unsigned char VHDR1[] = {
|
2016-09-22 20:26:03 +00:00
|
|
|
0x60U, 0x02U, 0x02U, 0x0CU, 0x0BU, 0x1BU, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U,
|
2016-09-21 06:51:13 +00:00
|
|
|
0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x08U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U, 0x36U};
|
|
|
|
|
|
|
|
const unsigned char ENDICW[] = {
|
2016-09-22 20:26:03 +00:00
|
|
|
0x00U, 0x02U, 0x02U, 0x25U, 0x0BU, 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),
|
|
|
|
m_address(),
|
|
|
|
m_port(gatewayPort),
|
|
|
|
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
|
|
|
{
|
|
|
|
m_address = CUDPSocket::lookup(gatewayAddress);
|
|
|
|
}
|
|
|
|
|
|
|
|
CP25Network::~CP25Network()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CP25Network::open()
|
|
|
|
{
|
|
|
|
LogMessage("Opening P25 network connection");
|
|
|
|
|
|
|
|
if (m_address.s_addr == INADDR_NONE)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return m_socket.open();
|
|
|
|
}
|
|
|
|
|
2016-09-22 19:31:25 +00:00
|
|
|
bool CP25Network::writeHeader(const CP25Data& control)
|
2016-09-15 19:28:56 +00:00
|
|
|
{
|
2016-09-20 06:53:16 +00:00
|
|
|
if (m_debug)
|
2016-09-21 06:51:13 +00:00
|
|
|
CUtils::dump(1U, "P25 Network ICW Sent", STARTICW, 10U);
|
2016-09-15 19:28:56 +00:00
|
|
|
|
2016-09-21 06:51:13 +00:00
|
|
|
bool ret = m_socket.write(STARTICW, 10U, m_address, m_port);
|
2016-09-20 06:53:16 +00:00
|
|
|
if (!ret)
|
|
|
|
return false;
|
|
|
|
|
2016-09-14 06:41:37 +00:00
|
|
|
if (m_debug)
|
2016-09-21 06:51:13 +00:00
|
|
|
CUtils::dump(1U, "P25 Network VHDR1 Sent", VHDR1, 30U);
|
2016-09-14 06:41:37 +00:00
|
|
|
|
2016-09-27 19:46:41 +00:00
|
|
|
ret = m_socket.write(VHDR1, 30U, m_address, m_port);
|
2016-09-20 06:53:16 +00:00
|
|
|
if (!ret)
|
|
|
|
return false;
|
|
|
|
|
2016-09-22 19:31:25 +00:00
|
|
|
unsigned int tgid = 0x0000U;
|
|
|
|
|
|
|
|
if (control.getLCF() == P25_LCF_GROUP)
|
|
|
|
tgid = control.getDstId();
|
|
|
|
|
2016-09-21 06:51:13 +00:00
|
|
|
// The VHDR2 record
|
|
|
|
unsigned char buffer[22U];
|
2016-09-20 06:53:16 +00:00
|
|
|
::memset(buffer, 0x00U, 22U);
|
|
|
|
buffer[0U] = 0x61U;
|
2016-09-28 06:17:11 +00:00
|
|
|
buffer[1U] = (tgid >> 8) & 0xFFU;
|
|
|
|
buffer[2U] = (tgid >> 0) & 0xFFU;
|
2016-09-20 06:53:16 +00:00
|
|
|
buffer[21U] = 0x02U;
|
|
|
|
|
|
|
|
if (m_debug)
|
|
|
|
CUtils::dump(1U, "P25 Network VHDR2 Sent", buffer, 22U);
|
|
|
|
|
2016-09-27 19:46:41 +00:00
|
|
|
ret = m_socket.write(buffer, 22U, m_address, m_port);
|
2016-09-20 06:53:16 +00:00
|
|
|
if (!ret)
|
|
|
|
return false;
|
|
|
|
|
2016-09-14 06:41:37 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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-21 06:51:13 +00:00
|
|
|
::memset(buffer, 0x00U, 22U);
|
|
|
|
::memcpy(buffer, STARTICW, 10U);
|
2016-09-20 06:53:16 +00:00
|
|
|
buffer[0U] = 0x62U;
|
2016-09-28 06:17:11 +00:00
|
|
|
buffer[9U] = 0x80U;
|
2016-09-21 06:51:13 +00:00
|
|
|
m_audio.decode(ldu1, buffer + 10U, 0U);
|
2016-09-20 06:53:16 +00:00
|
|
|
buffer[21U] = 0x02U;
|
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
|
|
|
|
2016-09-20 06:53:16 +00:00
|
|
|
bool ret = m_socket.write(buffer, 22U, m_address, m_port);
|
|
|
|
if (!ret)
|
|
|
|
return false;
|
|
|
|
|
2016-09-21 06:51:13 +00:00
|
|
|
// The '63' record
|
2016-09-22 20:26:03 +00:00
|
|
|
::memset(buffer, 0x00U, 14U);
|
2016-09-21 06:51:13 +00:00
|
|
|
buffer[0U] = 0x63U;
|
|
|
|
m_audio.decode(ldu1, buffer + 1U, 1U);
|
2016-09-22 20:26:03 +00:00
|
|
|
buffer[13U] = 0x02U;
|
2016-09-21 06:51:13 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
2016-09-27 19:46:41 +00:00
|
|
|
ret = m_socket.write(buffer, 14U, m_address, m_port);
|
2016-09-21 06:51:13 +00:00
|
|
|
if (!ret)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// The '64' record
|
|
|
|
::memset(buffer, 0x00U, 17U);
|
|
|
|
buffer[0U] = 0x64U;
|
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);
|
|
|
|
buffer[16U] = 0x02U;
|
|
|
|
|
|
|
|
if (m_debug)
|
|
|
|
CUtils::dump(1U, "P25 Network LDU1 Sent", buffer, 17U);
|
|
|
|
|
2016-09-27 19:46:41 +00:00
|
|
|
ret = m_socket.write(buffer, 17U, m_address, m_port);
|
2016-09-21 06:51:13 +00:00
|
|
|
if (!ret)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// The '65' record
|
|
|
|
::memset(buffer, 0x00U, 17U);
|
|
|
|
buffer[0U] = 0x65U;
|
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);
|
|
|
|
buffer[16U] = 0x02U;
|
|
|
|
|
|
|
|
if (m_debug)
|
|
|
|
CUtils::dump(1U, "P25 Network LDU1 Sent", buffer, 17U);
|
|
|
|
|
2016-09-27 19:46:41 +00:00
|
|
|
ret = m_socket.write(buffer, 17U, m_address, m_port);
|
2016-09-21 06:51:13 +00:00
|
|
|
if (!ret)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// The '66' record
|
|
|
|
::memset(buffer, 0x00U, 17U);
|
|
|
|
buffer[0U] = 0x66U;
|
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);
|
|
|
|
buffer[16U] = 0x02U;
|
|
|
|
|
|
|
|
if (m_debug)
|
|
|
|
CUtils::dump(1U, "P25 Network LDU1 Sent", buffer, 17U);
|
|
|
|
|
2016-09-27 19:46:41 +00:00
|
|
|
ret = m_socket.write(buffer, 17U, m_address, m_port);
|
2016-09-21 06:51:13 +00:00
|
|
|
if (!ret)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// The '67' record
|
|
|
|
::memset(buffer, 0x00U, 17U);
|
|
|
|
buffer[0U] = 0x67U;
|
|
|
|
m_audio.decode(ldu1, buffer + 5U, 5U);
|
|
|
|
buffer[16U] = 0x02U;
|
|
|
|
|
|
|
|
if (m_debug)
|
|
|
|
CUtils::dump(1U, "P25 Network LDU1 Sent", buffer, 17U);
|
|
|
|
|
2016-09-27 19:46:41 +00:00
|
|
|
ret = m_socket.write(buffer, 17U, m_address, m_port);
|
2016-09-21 06:51:13 +00:00
|
|
|
if (!ret)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// The '68' record
|
|
|
|
::memset(buffer, 0x00U, 17U);
|
2016-09-22 20:26:03 +00:00
|
|
|
buffer[0U] = 0x68U;
|
2016-09-21 06:51:13 +00:00
|
|
|
m_audio.decode(ldu1, buffer + 5U, 6U);
|
|
|
|
buffer[16U] = 0x02U;
|
|
|
|
|
|
|
|
if (m_debug)
|
|
|
|
CUtils::dump(1U, "P25 Network LDU1 Sent", buffer, 17U);
|
|
|
|
|
2016-09-27 19:46:41 +00:00
|
|
|
ret = m_socket.write(buffer, 17U, m_address, m_port);
|
2016-09-21 06:51:13 +00:00
|
|
|
if (!ret)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// The '69' record
|
|
|
|
::memset(buffer, 0x00U, 17U);
|
|
|
|
buffer[0U] = 0x69U;
|
|
|
|
m_audio.decode(ldu1, buffer + 5U, 7U);
|
|
|
|
buffer[16U] = 0x02U;
|
|
|
|
|
|
|
|
if (m_debug)
|
|
|
|
CUtils::dump(1U, "P25 Network LDU1 Sent", buffer, 17U);
|
|
|
|
|
2016-09-27 19:46:41 +00:00
|
|
|
ret = m_socket.write(buffer, 17U, m_address, m_port);
|
2016-09-21 06:51:13 +00:00
|
|
|
if (!ret)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// The '6A' record
|
|
|
|
::memset(buffer, 0x00U, 16U);
|
|
|
|
buffer[0U] = 0x6AU;
|
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);
|
2016-09-28 06:53:45 +00:00
|
|
|
buffer[15U] = end ? 0x00U : 0x02U;
|
2016-09-21 06:51:13 +00:00
|
|
|
|
|
|
|
if (m_debug)
|
|
|
|
CUtils::dump(1U, "P25 Network LDU1 Sent", buffer, 16U);
|
|
|
|
|
2016-09-27 19:46:41 +00:00
|
|
|
ret = m_socket.write(buffer, 16U, m_address, m_port);
|
2016-09-21 06:51:13 +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-21 06:51:13 +00:00
|
|
|
::memset(buffer, 0x00U, 22U);
|
|
|
|
::memcpy(buffer, STARTICW, 10U);
|
2016-09-20 06:53:16 +00:00
|
|
|
buffer[0U] = 0x6BU;
|
2016-09-28 06:17:11 +00:00
|
|
|
buffer[9U] = 0x80U;
|
2016-09-21 06:51:13 +00:00
|
|
|
m_audio.decode(ldu2, buffer + 10U, 0U);
|
2016-09-20 06:53:16 +00:00
|
|
|
buffer[21U] = 0x02U;
|
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
|
|
|
|
2016-09-20 06:53:16 +00:00
|
|
|
bool ret = m_socket.write(buffer, 22U, m_address, m_port);
|
|
|
|
if (!ret)
|
|
|
|
return false;
|
|
|
|
|
2016-09-21 06:51:13 +00:00
|
|
|
// The '6C' record
|
2016-09-22 20:26:03 +00:00
|
|
|
::memset(buffer, 0x00U, 14U);
|
2016-09-21 06:51:13 +00:00
|
|
|
buffer[0U] = 0x6CU;
|
|
|
|
m_audio.decode(ldu2, buffer + 1U, 1U);
|
2016-09-22 20:26:03 +00:00
|
|
|
buffer[13U] = 0x02U;
|
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
|
|
|
|
2016-09-27 19:46:41 +00:00
|
|
|
ret = m_socket.write(buffer, 14U, m_address, m_port);
|
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
|
|
|
|
::memset(buffer, 0x00U, 17U);
|
|
|
|
buffer[0U] = 0x6DU;
|
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);
|
|
|
|
buffer[16U] = 0x02U;
|
|
|
|
|
|
|
|
if (m_debug)
|
|
|
|
CUtils::dump(1U, "P25 Network LDU2 Sent", buffer, 17U);
|
|
|
|
|
2016-09-27 19:46:41 +00:00
|
|
|
ret = m_socket.write(buffer, 17U, m_address, m_port);
|
2016-09-21 06:51:13 +00:00
|
|
|
if (!ret)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// The '6E' record
|
|
|
|
::memset(buffer, 0x00U, 17U);
|
|
|
|
buffer[0U] = 0x6EU;
|
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);
|
|
|
|
buffer[16U] = 0x02U;
|
|
|
|
|
|
|
|
if (m_debug)
|
|
|
|
CUtils::dump(1U, "P25 Network LDU2 Sent", buffer, 17U);
|
|
|
|
|
2016-09-27 19:46:41 +00:00
|
|
|
ret = m_socket.write(buffer, 17U, m_address, m_port);
|
2016-09-21 06:51:13 +00:00
|
|
|
if (!ret)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// The '6F' record
|
|
|
|
::memset(buffer, 0x00U, 17U);
|
|
|
|
buffer[0U] = 0x6FU;
|
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);
|
|
|
|
buffer[16U] = 0x02U;
|
|
|
|
|
|
|
|
if (m_debug)
|
|
|
|
CUtils::dump(1U, "P25 Network LDU2 Sent", buffer, 17U);
|
|
|
|
|
2016-09-27 19:46:41 +00:00
|
|
|
ret = m_socket.write(buffer, 17U, m_address, m_port);
|
2016-09-21 06:51:13 +00:00
|
|
|
if (!ret)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// The '70' record
|
|
|
|
::memset(buffer, 0x00U, 17U);
|
|
|
|
buffer[0U] = 0x70U;
|
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);
|
|
|
|
buffer[16U] = 0x02U;
|
|
|
|
|
|
|
|
if (m_debug)
|
|
|
|
CUtils::dump(1U, "P25 Network LDU2 Sent", buffer, 17U);
|
|
|
|
|
2016-09-27 19:46:41 +00:00
|
|
|
ret = m_socket.write(buffer, 17U, m_address, m_port);
|
2016-09-21 06:51:13 +00:00
|
|
|
if (!ret)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// The '71' record
|
|
|
|
::memset(buffer, 0x00U, 17U);
|
|
|
|
buffer[0U] = 0x71U;
|
|
|
|
m_audio.decode(ldu2, buffer + 5U, 6U);
|
|
|
|
buffer[16U] = 0x02U;
|
|
|
|
|
|
|
|
if (m_debug)
|
|
|
|
CUtils::dump(1U, "P25 Network LDU2 Sent", buffer, 17U);
|
|
|
|
|
2016-09-27 19:46:41 +00:00
|
|
|
ret = m_socket.write(buffer, 17U, m_address, m_port);
|
2016-09-21 06:51:13 +00:00
|
|
|
if (!ret)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// The '72' record
|
|
|
|
::memset(buffer, 0x00U, 17U);
|
|
|
|
buffer[0U] = 0x72U;
|
|
|
|
m_audio.decode(ldu2, buffer + 5U, 7U);
|
|
|
|
buffer[16U] = 0x02U;
|
|
|
|
|
|
|
|
if (m_debug)
|
|
|
|
CUtils::dump(1U, "P25 Network LDU2 Sent", buffer, 17U);
|
|
|
|
|
2016-09-27 19:46:41 +00:00
|
|
|
ret = m_socket.write(buffer, 17U, m_address, m_port);
|
2016-09-21 06:51:13 +00:00
|
|
|
if (!ret)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// The '73' record
|
|
|
|
::memset(buffer, 0x00U, 16U);
|
|
|
|
buffer[0U] = 0x73U;
|
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-28 06:53:45 +00:00
|
|
|
buffer[15U] = end ? 0x00U : 0x02U;
|
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);
|
|
|
|
|
2016-09-27 19:46:41 +00:00
|
|
|
ret = m_socket.write(buffer, 16U, m_address, m_port);
|
2016-09-21 06:51:13 +00:00
|
|
|
if (!ret)
|
|
|
|
return false;
|
2016-09-15 19:28:56 +00:00
|
|
|
|
2016-09-21 06:51:13 +00:00
|
|
|
return true;
|
|
|
|
}
|
2016-09-15 19:28:56 +00:00
|
|
|
|
2016-09-21 06:51:13 +00:00
|
|
|
bool CP25Network::writeTerminator()
|
|
|
|
{
|
2016-09-20 06:53:16 +00:00
|
|
|
if (m_debug)
|
2016-09-21 06:51:13 +00:00
|
|
|
CUtils::dump(1U, "P25 Network ICW Sent", ENDICW, 10U);
|
2016-09-15 19:28:56 +00:00
|
|
|
|
2016-09-21 06:51:13 +00:00
|
|
|
bool ret = m_socket.write(ENDICW, 10U, m_address, m_port);
|
2016-09-20 06:53:16 +00:00
|
|
|
if (!ret)
|
|
|
|
return false;
|
2016-09-14 06:41:37 +00:00
|
|
|
|
2016-09-21 06:51:13 +00:00
|
|
|
ret = m_socket.write(ENDICW, 10U, m_address, m_port);
|
2016-09-20 06:53:16 +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];
|
|
|
|
|
|
|
|
in_addr address;
|
|
|
|
unsigned int port;
|
|
|
|
int length = m_socket.read(buffer, BUFFER_LENGTH, address, port);
|
|
|
|
if (length <= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Check if the data is for us
|
|
|
|
if (m_address.s_addr != address.s_addr || m_port != port) {
|
|
|
|
LogMessage("P25 packet received from an invalid source, %08X != %08X and/or %u != %u", m_address.s_addr, address.s_addr, m_port, port);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!m_enabled)
|
|
|
|
return;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void CP25Network::close()
|
|
|
|
{
|
|
|
|
m_socket.close();
|
|
|
|
|
|
|
|
LogMessage("Closing P25 network connection");
|
|
|
|
}
|
|
|
|
|
|
|
|
void CP25Network::enable(bool enabled)
|
|
|
|
{
|
|
|
|
m_enabled = enabled;
|
|
|
|
}
|