Add RAW data in and out of the FM repeater for SVXLink.

This commit is contained in:
Jonathan Naylor 2023-10-17 12:56:54 +01:00
parent d7ee4c18b3
commit 77d38f37e0
5 changed files with 213 additions and 153 deletions

View file

@ -147,7 +147,7 @@ unsigned int CFMControl::readModem(unsigned char* data, unsigned int space)
space = 240U; // 160 samples 12-bit
float netData[160U]; // Modem can handle up to 160 samples at a time
unsigned int length = m_network->read(netData, 160U); // 160 samples 12-bit
unsigned int length = m_network->readData(netData, 160U); // 160 samples 12-bit
if (length == 0U)
return 0U;

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2020,2021 by Jonathan Naylor G4KLX
* Copyright (C) 2020,2021,2023 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
@ -50,8 +50,10 @@ m_seqNo(0U)
if (pos != std::string::npos)
m_callsign = callsign.substr(0U, pos);
// if (protocol == "USRP")
// m_protocol = FMNP_USRP;
if (protocol == "RAW")
m_protocol = FMNP_RAW;
else
m_protocol = FMNP_USRP;
}
CFMNetwork::~CFMNetwork()
@ -75,8 +77,21 @@ bool CFMNetwork::writeData(float* data, unsigned int nSamples)
assert(data != NULL);
assert(nSamples > 0U);
if (m_protocol == FMNP_USRP)
return writeUSRPData(data, nSamples);
else if (m_protocol == FMNP_RAW)
return writeRawData(data, nSamples);
else
return false;
}
bool CFMNetwork::writeUSRPData(float* data, unsigned int nSamples)
{
assert(data != NULL);
assert(nSamples > 0U);
if (m_seqNo == 0U) {
bool ret = writeStart();
bool ret = writeUSRPStart();
if (!ret)
return false;
}
@ -86,7 +101,6 @@ bool CFMNetwork::writeData(float* data, unsigned int nSamples)
unsigned int length = 0U;
if (m_protocol == FMNP_USRP) {
buffer[length++] = 'U';
buffer[length++] = 'S';
buffer[length++] = 'R';
@ -129,7 +143,6 @@ bool CFMNetwork::writeData(float* data, unsigned int nSamples)
buffer[length++] = 0x00U;
buffer[length++] = 0x00U;
buffer[length++] = 0x00U;
}
for (unsigned int i = 0U; i < nSamples; i++) {
short val = short(data[i] * 32767.0F + 0.5F); // Changing audio format from float to S16LE
@ -146,14 +159,47 @@ bool CFMNetwork::writeData(float* data, unsigned int nSamples)
return m_socket.write(buffer, length, m_addr, m_addrLen);
}
bool CFMNetwork::writeRawData(float* data, unsigned int nSamples)
{
assert(data != NULL);
assert(nSamples > 0U);
unsigned char buffer[1000U];
::memset(buffer, 0x00U, 1000U);
unsigned int length = 0U;
for (unsigned int i = 0U; i < nSamples; i++) {
short val = short(data[i] * 32767.0F + 0.5F); // Changing audio format from float to S16LE
buffer[length++] = (val >> 0) & 0xFFU;
buffer[length++] = (val >> 8) & 0xFFU;
buffer[length++] = (val >> 0) & 0xFFU;
buffer[length++] = (val >> 8) & 0xFFU;
}
if (m_debug)
CUtils::dump(1U, "FM Network Data Sent", buffer, length);
return m_socket.write(buffer, length, m_addr, m_addrLen);
}
bool CFMNetwork::writeEnd()
{
if (m_protocol == FMNP_USRP)
return writeUSRPEnd();
else
return true;
}
bool CFMNetwork::writeUSRPEnd()
{
unsigned char buffer[500U];
::memset(buffer, 0x00U, 500U);
unsigned int length = 0U;
if (m_protocol == FMNP_USRP) {
buffer[length++] = 'U';
buffer[length++] = 'S';
buffer[length++] = 'R';
@ -198,7 +244,6 @@ bool CFMNetwork::writeEnd()
buffer[length++] = 0x00U;
length += 320U;
}
m_seqNo = 0U;
@ -250,10 +295,19 @@ void CFMNetwork::clock(unsigned int ms)
if (type == 0U)
m_buffer.addData(buffer + 32U, length - 32U);
} else if (m_protocol == FMNP_RAW) {
for (int i = 0U; i < length; i += 4U) {
unsigned char data[2U];
data[0U] = buffer[i + 0];
data[1U] = buffer[i + 1];
m_buffer.addData(data, 2U);
}
}
}
unsigned int CFMNetwork::read(float* data, unsigned int nSamples)
unsigned int CFMNetwork::readData(float* data, unsigned int nSamples)
{
assert(data != NULL);
assert(nSamples > 0U);
@ -298,14 +352,13 @@ void CFMNetwork::enable(bool enabled)
m_enabled = enabled;
}
bool CFMNetwork::writeStart()
bool CFMNetwork::writeUSRPStart()
{
unsigned char buffer[500U];
::memset(buffer, 0x00U, 500U);
unsigned int length = 0U;
if (m_protocol == FMNP_USRP) {
buffer[length++] = 'U';
buffer[length++] = 'S';
buffer[length++] = 'R';
@ -385,7 +438,6 @@ bool CFMNetwork::writeStart()
buffer[length++] = 0x00U;
length = 70U;
}
if (length > 0U) {
if (m_debug)

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2020,2021 by Jonathan Naylor G4KLX
* Copyright (C) 2020,2021,2023 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
@ -26,7 +26,8 @@
#include <string>
enum FM_NETWORK_PROTOCOL {
FMNP_USRP
FMNP_USRP,
FMNP_RAW
};
class CFMNetwork {
@ -42,7 +43,7 @@ public:
bool writeEnd();
unsigned int read(float* data, unsigned int nSamples);
unsigned int readData(float* data, unsigned int nSamples);
void reset();
@ -61,7 +62,13 @@ private:
CRingBuffer<unsigned char> m_buffer;
unsigned int m_seqNo;
bool writeStart();
bool writeUSRPStart();
bool writeUSRPData(float* data, unsigned int nSamples);
bool writeRawData(float* data, unsigned int nSamples);
bool writeUSRPEnd();
};
#endif

View file

@ -287,7 +287,8 @@ Debug=0
[FM Network]
Enable=1
# Protocol=USRP
# Protocol may be USRP or RAW
Protocol=USRP
LocalAddress=127.0.0.1
LocalPort=3810
GatewayAddress=127.0.0.1

View file

@ -19,6 +19,6 @@
#if !defined(VERSION_H)
#define VERSION_H
const char* VERSION = "20230927";
const char* VERSION = "20231017";
#endif