Skip to content

Commit 609f1e3

Browse files
committed
Add the USDP metadata header to the FM network output.
1 parent 82b5b01 commit 609f1e3

File tree

5 files changed

+136
-16
lines changed

5 files changed

+136
-16
lines changed

FMControl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ bool CFMControl::writeModem(const unsigned char* data, unsigned int length)
7979
return true;
8080

8181
if (data[0U] == TAG_EOT)
82-
return m_network->writeEOT();
82+
return m_network->writeEnd();
8383

8484
if (data[0U] != TAG_DATA1)
8585
return false;

FMNetwork.cpp

Lines changed: 127 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727

2828
const unsigned int BUFFER_LENGTH = 1500U;
2929

30-
CFMNetwork::CFMNetwork(const std::string& protocol, const std::string& localAddress, unsigned int localPort, const std::string& gatewayAddress, unsigned int gatewayPort, bool debug) :
30+
CFMNetwork::CFMNetwork(const std::string& callsign, const std::string& protocol, const std::string& localAddress, unsigned int localPort, const std::string& gatewayAddress, unsigned int gatewayPort, bool debug) :
31+
m_callsign(callsign),
3132
m_protocol(FMNP_USRP),
3233
m_socket(localAddress, localPort),
3334
m_addr(),
@@ -37,12 +38,18 @@ m_enabled(false),
3738
m_buffer(2000U, "FM Network"),
3839
m_seqNo(0U)
3940
{
41+
assert(!callsign.empty());
4042
assert(gatewayPort > 0U);
4143
assert(!gatewayAddress.empty());
4244

4345
if (CUDPSocket::lookup(gatewayAddress, gatewayPort, m_addr, m_addrLen) != 0)
4446
m_addrLen = 0U;
4547

48+
// Remove any trailing letters in the callsign
49+
size_t pos = callsign.find_first_of(' ');
50+
if (pos != std::string::npos)
51+
m_callsign = callsign.substr(0U, pos);
52+
4653
// if (protocol == "USRP")
4754
// m_protocol = FMNP_USRP;
4855
}
@@ -68,8 +75,14 @@ bool CFMNetwork::writeData(float* data, unsigned int nSamples)
6875
assert(data != NULL);
6976
assert(nSamples > 0U);
7077

71-
unsigned char buffer[1500U];
72-
::memset(buffer, 0x00U, 1500U);
78+
if (m_seqNo == 0U) {
79+
bool ret = writeStart();
80+
if (!ret)
81+
return false;
82+
}
83+
84+
unsigned char buffer[500U];
85+
::memset(buffer, 0x00U, 500U);
7386

7487
unsigned int length = 0U;
7588

@@ -133,10 +146,10 @@ bool CFMNetwork::writeData(float* data, unsigned int nSamples)
133146
return m_socket.write(buffer, length, m_addr, m_addrLen);
134147
}
135148

136-
bool CFMNetwork::writeEOT()
149+
bool CFMNetwork::writeEnd()
137150
{
138-
unsigned char buffer[1500U];
139-
::memset(buffer, 0x00U, 1500U);
151+
unsigned char buffer[500U];
152+
::memset(buffer, 0x00U, 500U);
140153

141154
unsigned int length = 0U;
142155

@@ -184,15 +197,19 @@ bool CFMNetwork::writeEOT()
184197
buffer[length++] = 0x00U;
185198
buffer[length++] = 0x00U;
186199

187-
length += 160U * sizeof(int16_t);
200+
length += 320U;
188201
}
189202

190-
if (m_debug)
191-
CUtils::dump(1U, "FM Network Data Sent", buffer, length);
203+
m_seqNo = 0U;
192204

193-
m_seqNo++;
205+
if (length > 0U) {
206+
if (m_debug)
207+
CUtils::dump(1U, "FM Network Data Sent", buffer, length);
194208

195-
return m_socket.write(buffer, length, m_addr, m_addrLen);
209+
return m_socket.write(buffer, length, m_addr, m_addrLen);
210+
} else {
211+
return true;
212+
}
196213
}
197214

198215
void CFMNetwork::clock(unsigned int ms)
@@ -280,3 +297,102 @@ void CFMNetwork::enable(bool enabled)
280297

281298
m_enabled = enabled;
282299
}
300+
301+
bool CFMNetwork::writeStart()
302+
{
303+
unsigned char buffer[500U];
304+
::memset(buffer, 0x00U, 500U);
305+
306+
unsigned int length = 0U;
307+
308+
if (m_protocol == FMNP_USRP) {
309+
buffer[length++] = 'U';
310+
buffer[length++] = 'S';
311+
buffer[length++] = 'R';
312+
buffer[length++] = 'P';
313+
314+
// Sequence number
315+
buffer[length++] = (m_seqNo >> 24) & 0xFFU;
316+
buffer[length++] = (m_seqNo >> 16) & 0xFFU;
317+
buffer[length++] = (m_seqNo >> 8) & 0xFFU;
318+
buffer[length++] = (m_seqNo >> 0) & 0xFFU;
319+
320+
buffer[length++] = 0x00U;
321+
buffer[length++] = 0x00U;
322+
buffer[length++] = 0x00U;
323+
buffer[length++] = 0x00U;
324+
325+
// PTT off
326+
buffer[length++] = 0x00U;
327+
buffer[length++] = 0x00U;
328+
buffer[length++] = 0x00U;
329+
buffer[length++] = 0x00U;
330+
331+
buffer[length++] = 0x00U;
332+
buffer[length++] = 0x00U;
333+
buffer[length++] = 0x00U;
334+
buffer[length++] = 0x00U;
335+
336+
// Type, 2 for metadata
337+
buffer[length++] = 0x00U;
338+
buffer[length++] = 0x00U;
339+
buffer[length++] = 0x00U;
340+
buffer[length++] = 0x02U;
341+
342+
buffer[length++] = 0x00U;
343+
buffer[length++] = 0x00U;
344+
buffer[length++] = 0x00U;
345+
buffer[length++] = 0x00U;
346+
347+
buffer[length++] = 0x00U;
348+
buffer[length++] = 0x00U;
349+
buffer[length++] = 0x00U;
350+
buffer[length++] = 0x00U;
351+
352+
// TLV TAG for Metadata
353+
buffer[length++] = 0x08U;
354+
355+
// TLV Length
356+
buffer[length++] = 3U + 4U + 3U + 1U + 1U + m_callsign.size() + 1U;
357+
358+
// DMR Id
359+
buffer[length++] = 0x00U;
360+
buffer[length++] = 0x00U;
361+
buffer[length++] = 0x00U;
362+
363+
// Rpt Id
364+
buffer[length++] = 0x00U;
365+
buffer[length++] = 0x00U;
366+
buffer[length++] = 0x00U;
367+
buffer[length++] = 0x00U;
368+
369+
// Talk Group
370+
buffer[length++] = 0x00U;
371+
buffer[length++] = 0x00U;
372+
buffer[length++] = 0x00U;
373+
374+
// Time Slot
375+
buffer[length++] = 0x00U;
376+
377+
// Color Code
378+
buffer[length++] = 0x00U;
379+
380+
// Callsign
381+
for (std::string::const_iterator it = m_callsign.cbegin(); it != m_callsign.cend(); ++it)
382+
buffer[length++] = *it;
383+
384+
// End of Metadata
385+
buffer[length++] = 0x00U;
386+
387+
length = 70U;
388+
}
389+
390+
if (length > 0U) {
391+
if (m_debug)
392+
CUtils::dump(1U, "FM Network Data Sent", buffer, length);
393+
394+
return m_socket.write(buffer, length, m_addr, m_addrLen);
395+
} else {
396+
return true;
397+
}
398+
}

FMNetwork.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ enum FM_NETWORK_PROTOCOL {
3131

3232
class CFMNetwork {
3333
public:
34-
CFMNetwork(const std::string& protocol, const std::string& myAddress, unsigned int myPort, const std::string& gatewayAddress, unsigned int gatewayPort, bool debug);
34+
CFMNetwork(const std::string& callsign, const std::string& protocol, const std::string& myAddress, unsigned int myPort, const std::string& gatewayAddress, unsigned int gatewayPort, bool debug);
3535
~CFMNetwork();
3636

3737
bool open();
@@ -40,7 +40,7 @@ class CFMNetwork {
4040

4141
bool writeData(float* data, unsigned int nSamples);
4242

43-
bool writeEOT();
43+
bool writeEnd();
4444

4545
unsigned int read(float* data, unsigned int nSamples);
4646

@@ -51,6 +51,7 @@ class CFMNetwork {
5151
void clock(unsigned int ms);
5252

5353
private:
54+
std::string m_callsign;
5455
FM_NETWORK_PROTOCOL m_protocol;
5556
CUDPSocket m_socket;
5657
sockaddr_storage m_addr;
@@ -59,6 +60,8 @@ class CFMNetwork {
5960
bool m_enabled;
6061
CRingBuffer<unsigned char> m_buffer;
6162
unsigned int m_seqNo;
63+
64+
bool writeStart();
6265
};
6366

6467
#endif

MMDVMHost.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1800,6 +1800,7 @@ bool CMMDVMHost::createPOCSAGNetwork()
18001800

18011801
bool CMMDVMHost::createFMNetwork()
18021802
{
1803+
std::string callsign = m_conf.getFMCallsign();
18031804
std::string protocol = m_conf.getFMNetworkProtocol();
18041805
std::string gatewayAddress = m_conf.getFMGatewayAddress();
18051806
unsigned int gatewayPort = m_conf.getFMGatewayPort();
@@ -1824,7 +1825,7 @@ bool CMMDVMHost::createFMNetwork()
18241825
LogInfo(" RX Audio Gain: %.2f", rxAudioGain);
18251826
LogInfo(" Mode Hang: %us", m_fmNetModeHang);
18261827

1827-
m_fmNetwork = new CFMNetwork(protocol, localAddress, localPort, gatewayAddress, gatewayPort, debug);
1828+
m_fmNetwork = new CFMNetwork(callsign, protocol, localAddress, localPort, gatewayAddress, gatewayPort, debug);
18281829

18291830
bool ret = m_fmNetwork->open();
18301831
if (!ret) {

Version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919
#if !defined(VERSION_H)
2020
#define VERSION_H
2121

22-
const char* VERSION = "20210420";
22+
const char* VERSION = "20210424";
2323

2424
#endif

0 commit comments

Comments
 (0)