-
Notifications
You must be signed in to change notification settings - Fork 5
/
dmrcodec.h
177 lines (165 loc) · 4.55 KB
/
dmrcodec.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/*
Copyright (C) 2019 Doug McLain
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 3 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, see <https://www.gnu.org/licenses/>.
*/
#ifndef DMRCODEC_H
#define DMRCODEC_H
#include <QObject>
#include <QtNetwork>
#include <QPushButton>
#include "audioengine.h"
#include "serialambe.h"
#include "mbedec.h"
#include "mbeenc.h"
#ifdef USE_FLITE
#include <flite/flite.h>
#endif
#include <inttypes.h>
#include "DMRData.h"
#include "cbptc19696.h"
class DMRCodec : public QObject
{
Q_OBJECT
public:
DMRCodec(QString callsign, uint32_t dmrid, uint8_t essid, QString password, QString lat, QString lon, QString location, QString desc, QString options, uint32_t dstid, QString host, uint32_t port, QString vocoder, QString audioin, QString audioout);
~DMRCodec();
unsigned char * get_eot();
uint8_t get_status(){ return m_status; }
void set_srcid(uint32_t s){m_srcid = s;}
void set_dstid(uint32_t d){m_dstid = d;}
void set_cc(uint32_t cc){m_colorcode = cc;}
void set_slot(uint32_t s){m_slot = s;}
void set_calltype(uint8_t c){m_flco = FLCO(c);}
uint32_t get_src() { return m_srcid; }
uint32_t get_dst() { return m_dstid; }
uint32_t get_gw() { return m_gwid; }
QString get_host() { return m_host; }
int get_port() { return m_port; }
uint8_t get_fn() { return m_fn; }
int get_cnt() { return m_cnt; }
bool get_hwrx() { return m_hwrx; }
bool get_hwtx() { return m_hwtx; }
signals:
void update();
void update_output_level(unsigned short);
private slots:
void start_tx();
void stop_tx();
void deleteLater();
void process_udp();
void process_rx_data();
void get_ambe();
void send_ping();
void send_connect();
void send_disconnect();
void transmit();
void hostname_lookup(QHostInfo i);
void dmr_tgid_changed(unsigned int id) { m_txdstid = id; }
void dmrpc_state_changed(int pc){ m_pc = (pc ? true : false); }
void input_src_changed(int id, QString t) { m_ttsid = id; m_ttstext = t; }
void swrx_state_changed(int s) {m_hwrx = !s; }
void swtx_state_changed(int s) {m_hwtx = !s; }
void send_frame();
void in_audio_vol_changed(qreal);
void out_audio_vol_changed(qreal);
void decoder_gain_changed(qreal);
private:
enum{
DISCONNECTED,
CONNECTING,
DMR_AUTH,
DMR_CONF,
DMR_OPTS,
CONNECTED_RW,
CONNECTED_RO
} m_status;
QUdpSocket *m_udp = nullptr;
QHostAddress m_address;
QString m_callsign;
uint32_t m_dmrid;
uint32_t m_essid;
QString m_password;
QString m_lat;
QString m_lon;
QString m_location;
QString m_desc;
uint32_t m_srcid;
uint32_t m_dstid;
uint32_t m_txdstid;
uint32_t m_gwid;
QString m_hostname;
QString m_host;
int m_port;
uint8_t m_fn;
bool m_tx;
uint16_t m_txcnt;
uint32_t m_rxcnt;
uint8_t m_ttsid;
QString m_ttstext;
int m_cnt;
uint32_t m_transmitcnt;
QString m_vocoder;
SerialAMBE *m_ambedev;
QTimer *m_rxtimer;
bool m_hwrx;
bool m_hwtx;
uint8_t packet_size;
uint16_t m_ttscnt;
uint8_t m_ambe[27];
QQueue<char> m_rxambeq;
QQueue<char> m_ambeq;
#ifdef USE_FLITE
cst_voice *voice_slt;
cst_voice *voice_kal;
cst_voice *voice_awb;
cst_wave *tts_audio;
#endif
uint32_t m_defsrcid;
QString m_type;
uint16_t m_streamid;
QTimer *m_ping_timer;
QTimer *m_txtimer;
AudioEngine *m_audio;
MBEDecoder *m_mbedec;
MBEEncoder *m_mbeenc;
uint8_t m_dmrFrame[55];
uint8_t m_dataType;
uint32_t m_colorcode;
uint32_t m_slot;
uint32_t m_dmrcnt;
bool m_pc;
FLCO m_flco;
CBPTC19696 m_bptc;
bool m_raw[128U];
bool m_data[72U];
QString m_audioin;
QString m_audioout;
QString m_options;
void byteToBitsBE(uint8_t byte, bool* bits);
void bitsToByteBE(const bool* bits, uint8_t& byte);
void build_frame();
void encode_header();
void encode_data();
void encode16114(bool* d);
void encode_qr1676(uint8_t* data);
void get_slot_data(uint8_t* data);
void lc_get_data(uint8_t*);
void lc_get_data(bool* bits);
void encode_embedded_data();
uint8_t get_embedded_data(uint8_t* data, uint8_t n);
void get_emb_data(uint8_t* data, uint8_t lcss);
void full_lc_encode(uint8_t* data, uint8_t type);
void addDMRDataSync(uint8_t* data, bool duplex);
void addDMRAudioSync(uint8_t* data, bool duplex);
void setup_connection();
};
#endif // DMRCODEC_H