2020-12-15 17:21:07 +01:00
|
|
|
/*
|
2023-10-17 13:56:54 +02:00
|
|
|
* Copyright (C) 2020,2021,2023 by Jonathan Naylor G4KLX
|
2020-12-15 17:21:07 +01:00
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef FMNetwork_H
|
|
|
|
|
#define FMNetwork_H
|
|
|
|
|
|
|
|
|
|
#include "RingBuffer.h"
|
|
|
|
|
#include "UDPSocket.h"
|
|
|
|
|
|
2023-10-18 12:34:38 +02:00
|
|
|
#include <samplerate.h>
|
|
|
|
|
|
2020-12-15 17:21:07 +01:00
|
|
|
#include <cstdint>
|
|
|
|
|
#include <string>
|
|
|
|
|
|
2021-03-14 15:59:34 +01:00
|
|
|
enum FM_NETWORK_PROTOCOL {
|
2023-10-17 13:56:54 +02:00
|
|
|
FMNP_USRP,
|
|
|
|
|
FMNP_RAW
|
2021-03-14 13:16:39 +01:00
|
|
|
};
|
|
|
|
|
|
2020-12-15 17:21:07 +01:00
|
|
|
class CFMNetwork {
|
|
|
|
|
public:
|
2023-10-18 12:34:38 +02:00
|
|
|
CFMNetwork(const std::string& callsign, const std::string& protocol, const std::string& localAddress, unsigned short localPort, const std::string& gatewayAddress, unsigned short gatewayPort, unsigned int sampleRate, bool debug);
|
2020-12-15 17:21:07 +01:00
|
|
|
~CFMNetwork();
|
|
|
|
|
|
|
|
|
|
bool open();
|
|
|
|
|
|
|
|
|
|
void enable(bool enabled);
|
|
|
|
|
|
2023-10-18 12:34:38 +02:00
|
|
|
bool writeData(const float* data, unsigned int nSamples);
|
2020-12-15 17:21:07 +01:00
|
|
|
|
2021-04-24 09:43:48 +02:00
|
|
|
bool writeEnd();
|
2020-12-15 17:21:07 +01:00
|
|
|
|
2023-10-18 12:34:38 +02:00
|
|
|
unsigned int readData(float* out, unsigned int nOut);
|
2020-12-15 17:21:07 +01:00
|
|
|
|
|
|
|
|
void reset();
|
|
|
|
|
|
|
|
|
|
void close();
|
|
|
|
|
|
|
|
|
|
void clock(unsigned int ms);
|
|
|
|
|
|
|
|
|
|
private:
|
2021-04-24 09:43:48 +02:00
|
|
|
std::string m_callsign;
|
2021-03-14 15:59:34 +01:00
|
|
|
FM_NETWORK_PROTOCOL m_protocol;
|
|
|
|
|
CUDPSocket m_socket;
|
|
|
|
|
sockaddr_storage m_addr;
|
|
|
|
|
unsigned int m_addrLen;
|
2023-10-18 12:34:38 +02:00
|
|
|
unsigned int m_sampleRate;
|
2021-03-14 15:59:34 +01:00
|
|
|
bool m_debug;
|
|
|
|
|
bool m_enabled;
|
2020-12-15 17:21:07 +01:00
|
|
|
CRingBuffer<unsigned char> m_buffer;
|
2021-03-14 15:59:34 +01:00
|
|
|
unsigned int m_seqNo;
|
2023-10-18 12:34:38 +02:00
|
|
|
SRC_STATE* m_resampler;
|
|
|
|
|
int m_error;
|
2021-04-24 09:43:48 +02:00
|
|
|
|
2023-10-17 13:56:54 +02:00
|
|
|
bool writeUSRPStart();
|
|
|
|
|
|
2023-10-18 12:34:38 +02:00
|
|
|
bool writeUSRPData(const float* data, unsigned int nSamples);
|
|
|
|
|
bool writeRawData(const float* in, unsigned int nIn);
|
2023-10-17 13:56:54 +02:00
|
|
|
|
|
|
|
|
bool writeUSRPEnd();
|
2020-12-15 17:21:07 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|
2023-10-17 13:56:54 +02:00
|
|
|
|