You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
110 lines
2.7 KiB
110 lines
2.7 KiB
/*
|
|
* Copyright (C) 2010,2012,2013 by Jonathan Naylor G4KLX
|
|
* Copyright (c) 2017 by Thomas A. Early N7TAE
|
|
*
|
|
* 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 <cassert>
|
|
#include <cstring>
|
|
|
|
#include "TextData.h"
|
|
#include "DStarDefines.h"
|
|
#include "Utils.h"
|
|
|
|
CTextData::CTextData(LINK_STATUS status, const std::string& reflector, const std::string& text, const in_addr& address, unsigned int port, bool temporary) :
|
|
m_status(status),
|
|
m_reflector(NULL),
|
|
m_text(NULL),
|
|
m_address(address),
|
|
m_port(port),
|
|
m_temporary(temporary)
|
|
{
|
|
assert(port > 0U);
|
|
|
|
m_reflector = new unsigned char[8U];
|
|
m_text = new unsigned char[20U];
|
|
|
|
::memset(m_reflector, ' ', 8U);
|
|
::memset(m_text, ' ', 20U);
|
|
|
|
if (status != LS_NONE) {
|
|
for (unsigned int i = 0U; i < reflector.size() && i < 8U; i++)
|
|
m_reflector[i] = reflector.at(i);
|
|
}
|
|
|
|
for (unsigned int i = 0U; i < text.size() && i < 20U; i++)
|
|
m_text[i] = text.at(i);
|
|
}
|
|
|
|
CTextData::CTextData(const std::string& text, const in_addr& address, unsigned int port, bool temporary) :
|
|
m_status(LS_NONE),
|
|
m_reflector(NULL),
|
|
m_text(NULL),
|
|
m_address(address),
|
|
m_port(port),
|
|
m_temporary(temporary)
|
|
{
|
|
assert(port > 0U);
|
|
|
|
m_reflector = new unsigned char[8U];
|
|
m_text = new unsigned char[20U];
|
|
|
|
::memset(m_reflector, ' ', 8U);
|
|
::memset(m_text, ' ', 20U);
|
|
|
|
for (unsigned int i = 0U; i < text.size() && i < 20U; i++)
|
|
m_text[i] = text.at(i);
|
|
}
|
|
|
|
CTextData::~CTextData()
|
|
{
|
|
delete[] m_reflector;
|
|
delete[] m_text;
|
|
}
|
|
|
|
unsigned int CTextData::getHBRepeaterData(unsigned char *data, unsigned int length) const
|
|
{
|
|
assert(data != NULL);
|
|
assert(length >= 34U);
|
|
|
|
data[0] = 'D';
|
|
data[1] = 'S';
|
|
data[2] = 'R';
|
|
data[3] = 'P';
|
|
|
|
if (m_temporary) {
|
|
data[4] = 0x01U; // Temporary text data
|
|
::memcpy(data + 5U, m_text, 20U);
|
|
return 25U;
|
|
} else {
|
|
data[4] = 0x00U; // Permanent text data
|
|
::memcpy(data + 5U, m_text, 20U);
|
|
data[25U] = (unsigned char)m_status;
|
|
::memcpy(data + 26U, m_reflector, 8U);
|
|
return 34U;
|
|
}
|
|
}
|
|
|
|
in_addr CTextData::getAddress() const
|
|
{
|
|
return m_address;
|
|
}
|
|
|
|
unsigned int CTextData::getPort() const
|
|
{
|
|
return m_port;
|
|
}
|