-
Notifications
You must be signed in to change notification settings - Fork 1
/
HeardData.cpp
140 lines (110 loc) · 2.97 KB
/
HeardData.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
* Copyright (C) 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 "HeardData.h"
CHeardData::CHeardData() :
m_reflector(),
m_repeater(),
m_user(),
m_ext(),
m_address(),
m_port(0U)
{
}
CHeardData::CHeardData(const CHeardData& data) :
m_reflector(data.m_reflector),
m_repeater(data.m_repeater),
m_user(data.m_user),
m_ext(data.m_ext),
m_address(data.m_address),
m_port(data.m_port)
{
}
CHeardData::CHeardData(const CHeaderData& data, const std::string& repeater, const std::string& reflector) :
m_reflector(reflector),
m_repeater(repeater),
m_user(),
m_ext(),
m_address(),
m_port()
{
m_user = data.getMyCall1();
m_ext = data.getMyCall2();
}
CHeardData::~CHeardData()
{
}
bool CHeardData::setIcomRepeaterData(const unsigned char *data, unsigned int length, const in_addr& address, unsigned int port)
{
assert(data != NULL);
assert(length >= 26U);
std::string sdata((const char *)data);
m_user = sdata.substr(10, LONG_CALLSIGN_LENGTH);
m_repeater = sdata.substr(18, LONG_CALLSIGN_LENGTH);
m_address = address;
m_port = port;
return true;
}
unsigned int CHeardData::getCCSData(unsigned char *data, unsigned int length) const
{
assert(data != NULL);
assert(length >= 100U);
::memset(data, 0x00U, 100U);
data[0U] = '0';
data[1U] = '0';
data[2U] = '0';
data[3U] = '1';
::memset(data + 7U, ' ', 36U);
for (unsigned int i = 0U; i < m_reflector.size(); i++)
data[i + 7U] = m_reflector.at(i);
for (unsigned int i = 0U; i < m_repeater.size(); i++)
data[i + 15U] = m_repeater.at(i);
::memcpy(data + 23U, "CQCQCQ ", LONG_CALLSIGN_LENGTH);
for (unsigned int i = 0U; i < m_user.size(); i++)
data[i + 31U] = m_user.at(i);
for (unsigned int i = 0U; i < m_ext.size(); i++)
data[i + 39U] = m_ext.at(i);
data[61U] = 0x01U;
data[63U] = 0x21U;
::memset(data + 64U, ' ', 20U);
data[93U] = 0x36U;
return 100U;
}
std::string CHeardData::getRepeater() const
{
return m_repeater;
}
std::string CHeardData::getUser() const
{
return m_user;
}
void CHeardData::setDestination(const in_addr& address, unsigned int port)
{
m_address = address;
m_port = port;
}
in_addr CHeardData::getAddress() const
{
return m_address;
}
unsigned int CHeardData::getPort() const
{
return m_port;
}