2018-02-21 20:46:21 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2009-2014,2016,2017,2018 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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef FCSNetwork_H
|
|
|
|
|
#define FCSNetwork_H
|
|
|
|
|
|
|
|
|
|
#include "YSFDefines.h"
|
|
|
|
|
#include "UDPSocket.h"
|
|
|
|
|
#include "RingBuffer.h"
|
2018-02-22 21:14:49 +01:00
|
|
|
#include "Timer.h"
|
2018-02-21 20:46:21 +01:00
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
#include <string>
|
2018-02-22 08:37:29 +01:00
|
|
|
#include <map>
|
2018-02-21 20:46:21 +01:00
|
|
|
|
2025-03-19 18:49:49 +01:00
|
|
|
enum class FCS_STATE {
|
|
|
|
|
UNLINKED,
|
|
|
|
|
LINKING,
|
|
|
|
|
LINKED
|
2018-02-22 21:14:49 +01:00
|
|
|
};
|
|
|
|
|
|
2018-02-21 20:46:21 +01:00
|
|
|
class CFCSNetwork {
|
|
|
|
|
public:
|
2021-04-25 07:51:51 +02:00
|
|
|
CFCSNetwork(unsigned short port, const std::string& callsign, unsigned int rxFrequency, unsigned int txFrequency, const std::string& locator, unsigned int id, bool debug);
|
2018-02-21 20:46:21 +01:00
|
|
|
~CFCSNetwork();
|
|
|
|
|
|
|
|
|
|
bool open();
|
|
|
|
|
|
2020-09-05 22:14:17 +02:00
|
|
|
void setOptions(const std::string& options);
|
|
|
|
|
|
2018-02-21 20:46:21 +01:00
|
|
|
void clearDestination();
|
|
|
|
|
|
2018-02-22 20:11:21 +01:00
|
|
|
void write(const unsigned char* data);
|
2018-02-21 20:46:21 +01:00
|
|
|
|
2018-02-22 23:06:24 +01:00
|
|
|
bool writeLink(const std::string& reflector);
|
2018-02-21 22:53:58 +01:00
|
|
|
|
2018-02-22 20:11:21 +01:00
|
|
|
void writeUnlink(unsigned int count = 1U);
|
2018-02-21 20:46:21 +01:00
|
|
|
|
|
|
|
|
unsigned int read(unsigned char* data);
|
|
|
|
|
|
|
|
|
|
void clock(unsigned int ms);
|
|
|
|
|
|
|
|
|
|
void close();
|
|
|
|
|
|
|
|
|
|
private:
|
2018-02-22 08:37:29 +01:00
|
|
|
CUDPSocket m_socket;
|
|
|
|
|
bool m_debug;
|
2020-09-03 17:13:27 +02:00
|
|
|
sockaddr_storage m_addr;
|
|
|
|
|
unsigned int m_addrLen;
|
2018-02-22 20:11:21 +01:00
|
|
|
unsigned char* m_ping;
|
2020-09-05 22:14:17 +02:00
|
|
|
unsigned char* m_options;
|
|
|
|
|
std::string m_opt;
|
2018-02-22 08:37:29 +01:00
|
|
|
unsigned char* m_info;
|
|
|
|
|
std::string m_reflector;
|
2018-02-27 19:14:06 +01:00
|
|
|
std::string m_print;
|
2018-02-22 08:37:29 +01:00
|
|
|
CRingBuffer<unsigned char> m_buffer;
|
2020-09-03 17:13:27 +02:00
|
|
|
std::map<std::string, std::pair<sockaddr_storage, unsigned int>> m_addresses;
|
2018-02-22 09:05:21 +01:00
|
|
|
unsigned char m_n;
|
2018-02-22 21:14:49 +01:00
|
|
|
CTimer m_pingTimer;
|
2018-02-26 20:12:26 +01:00
|
|
|
CTimer m_resetTimer;
|
2018-02-22 21:14:49 +01:00
|
|
|
FCS_STATE m_state;
|
2018-02-21 22:53:58 +01:00
|
|
|
|
2020-09-06 16:08:02 +02:00
|
|
|
void writeOptions(const std::string& reflector);
|
2018-02-21 22:53:58 +01:00
|
|
|
void writeInfo();
|
2018-02-22 20:11:21 +01:00
|
|
|
void writePing();
|
2018-02-21 20:46:21 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|