-
Notifications
You must be signed in to change notification settings - Fork 1
/
DCSHandler.h
129 lines (103 loc) · 4.19 KB
/
DCSHandler.h
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
/*
* Copyright (C) 2012,2013,2015 by Jonathan Naylor G4KLX
* Copyright (c) 2017-2018 by Thomas A. Early N7TAE
*
* 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.
*/
#pragma once
#include <netinet/in.h>
#include <string>
#include <cstdio>
#include <list>
#include "DCSProtocolHandlerPool.h"
#include "RemoteRepeaterData.h"
#include "ReflectorCallback.h"
#include "DStarDefines.h"
#include "CallsignList.h"
#include "ConnectData.h"
#include "AMBEData.h"
#include "PollData.h"
#include "Timer.h"
#include "Defs.h"
enum DCS_STATE {
DCS_LINKING,
DCS_LINKED,
DCS_UNLINKING
};
class CDCSHandler {
public:
static void setDCSProtocolHandlerPool(CDCSProtocolHandlerPool *pool);
static void setDCSProtocolIncoming(CDCSProtocolHandler *handler);
static void setGatewayType(GATEWAY_TYPE type);
static void link(IReflectorCallback *handler, const std::string &repeater, const std::string &reflector, const in_addr &address);
static void unlink(IReflectorCallback *handler, const std::string &reflector = std::string(""), bool exclude = true);
static void unlink(CDCSHandler *reflector);
static void unlink();
static void writeHeader(IReflectorCallback *handler, CHeaderData &header, DIRECTION direction);
static void writeAMBE(IReflectorCallback *handler, CAMBEData &data, DIRECTION direction);
static void process(CAMBEData &header);
static void process(CPollData &data);
static void process(CConnectData &connect);
static void gatewayUpdate(const std::string &reflector, const std::string &address);
static void clock(unsigned int ms);
static bool stateChange();
static void writeStatus(FILE *file);
static void setWhiteList(CCallsignList *list);
static void setBlackList(CCallsignList *list);
static void finalise();
static void getInfo(IReflectorCallback *handler, CRemoteRepeaterData &data);
static std::string getIncoming(const std::string &callsign);
protected:
CDCSHandler(IReflectorCallback *handler, const std::string &reflector, const std::string &repeater, CDCSProtocolHandler *protoHandler, const in_addr &address, unsigned int port, DIRECTION direction);
~CDCSHandler();
void processInt(CAMBEData &data);
bool processInt(CConnectData &connect, CD_TYPE type);
void writeHeaderInt(IReflectorCallback *handler, CHeaderData &header, DIRECTION direction);
void writeAMBEInt(IReflectorCallback *handler, CAMBEData &data, DIRECTION direction);
bool clockInt(unsigned int ms);
private:
static std::list<CDCSHandler *> m_DCSHandlers;
static CDCSProtocolHandlerPool *m_pool;
static CDCSProtocolHandler *m_incoming;
static bool m_stateChange;
static GATEWAY_TYPE m_gatewayType;
static CCallsignList *m_whiteList;
static CCallsignList *m_blackList;
std::string m_reflector;
std::string m_repeater;
CDCSProtocolHandler *m_handler;
in_addr m_yourAddress;
unsigned int m_yourPort;
unsigned int m_myPort;
DIRECTION m_direction;
DCS_STATE m_linkState;
IReflectorCallback *m_destination;
time_t m_time;
CTimer m_pollTimer;
CTimer m_pollInactivityTimer;
CTimer m_tryTimer;
unsigned int m_tryCount;
unsigned int m_dcsId;
unsigned int m_dcsSeq;
unsigned int m_seqNo;
CTimer m_inactivityTimer;
// Header data
std::string m_yourCall;
std::string m_myCall1;
std::string m_myCall2;
std::string m_rptCall1;
std::string m_rptCall2;
unsigned int calcBackoff();
};