-
Notifications
You must be signed in to change notification settings - Fork 7
/
NetDisplay.cpp
211 lines (171 loc) · 4.41 KB
/
NetDisplay.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/*
* Copyright (C) 2016,2018,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.
*/
#include "NetDisplay.h"
#include "Log.h"
#include <string.h>
CNetDisplay::CNetDisplay(const std::string& address, unsigned int port) :
CDisplay(),
m_socket(NULL),
m_addressStr(address),
m_addr(),
m_addrLen(0U),
m_port(port)
{
}
CNetDisplay::~CNetDisplay()
{
}
bool CNetDisplay::open()
{
LogInfo("Display, opening socket");
if (CUDPSocket::lookup(m_addressStr, m_port, m_addr, m_addrLen) != 0) {
LogError("Display, Unable to resolve the address");
return 1;
}
m_socket = new CUDPSocket();
int ret = m_socket->open(m_addr.ss_family);
if (!ret) {
LogWarning("Display, Could not open socket, disabling");
delete m_socket;
m_socket = NULL;
}
return true;
}
void CNetDisplay::write(unsigned char* data, unsigned int length)
{
if (m_socket)
m_socket->write(data, length, m_addr, m_addrLen);
}
void CNetDisplay::setIdleInt()
{
unsigned char data[1U];
data[0] = 0x01;
write(data, 1U);
}
void CNetDisplay::setErrorInt(const char* text)
{
unsigned char data[100U];
data[0] = 0x02;
uint8_t count = 0;
for (uint8_t i = 0U; text[i] != '\0'; i++, count++)
data[2 + i] = text[i];
data[1] = count;
write(data, 2 + count);
}
void CNetDisplay::setQuitInt()
{
unsigned char data[1U];
data[0] = 0x03;
write(data, 1U);
}
void CNetDisplay::writeDMRInt(unsigned int slotNo, const std::string& src, bool group, const std::string& dst, const char* type)
{
unsigned char data[12U];
data[0] = 0x04;
data[1] = slotNo;
data[2] = atoi(src.c_str()) >> 24;
data[3] = atoi(src.c_str()) >> 16;
data[4] = atoi(src.c_str()) >> 8;
data[5] = atoi(src.c_str()) >> 0;
data[6] = group;
data[7] = atoi(dst.c_str()) >> 24;
data[8] = atoi(dst.c_str()) >> 16;
data[9] = atoi(dst.c_str()) >> 8;
data[10] = atoi(dst.c_str()) >> 0;
data[11] = type[0];
write(data, 12);
}
void CNetDisplay::writeDMRRSSIInt(unsigned int slotNo, unsigned char rssi)
{
unsigned char data[100U];
data[0] = 0x05;
data[1] = slotNo;
data[2] = rssi;
write(data, 3);
}
void CNetDisplay::writeDMRTAInt(unsigned int slotNo, const unsigned char* talkerAlias, const char* type)
{
unsigned char data[100U];
data[0] = 0x06;
data[1] = slotNo;
data[2] = type[0];
uint8_t count = 0;
for (uint8_t i = 0U; talkerAlias[i] != '\0'; i++, count++)
data[4 + i] = talkerAlias[i];
data[3] = count;
write(data, 4 + count);
}
void CNetDisplay::writeDMRBERInt(unsigned int slotNo, float ber)
{
unsigned char data[100U];
data[0] = 0x07;
data[1] = slotNo;
char _ber[10];
_ber[0] = 0;
snprintf(_ber, sizeof(_ber), "%f", ber);
uint8_t count = 0;
for (uint8_t i = 0U; _ber[i] != '\0'; i++, count++)
data[3 + i] = _ber[i];
data[2] = count;
write(data, 3 + count);
}
void CNetDisplay::clearDMRInt(unsigned int slotNo)
{
unsigned char data[2U];
data[0] = 0x08;
data[1] = slotNo;
write(data, 2);
}
void CNetDisplay::writePOCSAGInt(uint32_t ric, const std::string& message)
{
unsigned char data[100U];
data[0] = 0x09;
data[1] = ric >> 24;
data[2] = ric >> 16;
data[3] = ric >> 8;
data[4] = ric >> 0;
uint8_t count = 0;
for (uint8_t i = 0U; message[i] != '\0'; i++, count++)
data[6 + i] = message[i];
data[5] = count;
write(data, 6 + count);
}
void CNetDisplay::clearPOCSAGInt()
{
unsigned char data[1U];
data[0] = 0x0A;
write(data, 1U);
}
void CNetDisplay::writeCWInt()
{
unsigned char data[1U];
data[0] = 0x0B;
write(data, 1U);
}
void CNetDisplay::clearCWInt()
{
unsigned char data[1U];
data[0] = 0x0C;
write(data, 1U);
}
void CNetDisplay::close()
{
unsigned char data[1U];
data[0] = 0x0D;
write(data, 1U);
}