-
Notifications
You must be signed in to change notification settings - Fork 14
/
M17Gateway.h
90 lines (80 loc) · 2.33 KB
/
M17Gateway.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
/*
* Copyright (c) 2020-2021 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 <atomic>
#include <string>
#include <mutex>
#include "UnixDgramSocket.h"
#include "SockAddress.h"
#include "Configure.h"
#include "UDPSocket.h"
#include "Callsign.h"
#include "Timer.h"
#include "Packet.h"
#include "Base.h"
#include "CRC.h"
enum class ELinkState { unlinked, linking, linked };
using SM17Link = struct sm17link_tag
{
SM17RefPacket pongPacket;
CSockAddress addr;
CCallsign cs;
char from_mod;
std::atomic<ELinkState> state;
CTimer receivePingTimer;
};
using SStream = struct stream_tag
{
CTimer lastPacketTime;
SM17Frame header;
};
class CM17Gateway : public CBase
{
public:
CM17Gateway();
~CM17Gateway();
bool Init(const CFGDATA &cfgdata);
void Process();
void SetDestAddress(const std::string &address, uint16_t port);
ELinkState GetLinkState() const { return mlink.state; }
bool TryLock();
void ReleaseLock();
std::atomic<bool> keep_running;
private:
CFGDATA cfg;
CCRC crc;
CUnixDgramReader AM2M17;
CUnixDgramWriter M172AM;
CUDPSocket ipv4, ipv6;
SM17Link mlink;
CTimer linkingTime;
SStream currentStream;
std::mutex streamLock;
std::string qnvoice_file;
CSockAddress from17k, destination;
void LinkCheck();
void Write(const void *buf, const size_t size, const CSockAddress &addr) const;
void PlayAudioMessage(const char *msg);
void StreamTimeout();
void PlayVoiceFile();
void PlayAudioNotifyMessage(const char *msg);
void Send(const void *buf, size_t size, const CSockAddress &addr) const;
bool ProcessFrame(const uint8_t *buf);
bool ProcessAM(const uint8_t *buf);
void SendLinkRequest(const CCallsign &ref);
};