This repository has been archived by the owner on Jul 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDefines.h
235 lines (209 loc) · 8.47 KB
/
Defines.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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/**
* Digital Voice Modem - Transcode Software
* GPLv2 Open Source. Use is subject to license terms.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* @package DVM / Transcode Software
*
*/
//
// Based on code from the MMDVMHost project. (https://github.com/g4klx/MMDVMHost)
// Licensed under the GPLv2 License (https://opensource.org/licenses/GPL-2.0)
//
/*
* Copyright (C) 2015,2016,2017 by Jonathan Naylor G4KLX
* Copyright (C) 2018-2021 by Bryan Biedenkapp N2PLL
*
* 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.
*/
#if !defined(__DEFINES_H__)
#define __DEFINES_H__
#include <stdint.h>
#ifdef __cplusplus
#include <memory>
#include <string>
#include <sstream>
#include <ios>
#endif
// ---------------------------------------------------------------------------
// Types
// ---------------------------------------------------------------------------
#ifndef _INT8_T_DECLARED
#ifndef __INT8_TYPE__
typedef signed char int8_t;
#endif // __INT8_TYPE__
#endif // _INT8_T_DECLARED
#ifndef _INT16_T_DECLARED
#ifndef __INT16_TYPE__
typedef short int16_t;
#endif // __INT16_TYPE__
#endif // _INT16_T_DECLARED
#ifndef _INT32_T_DECLARED
#ifndef __INT32_TYPE__
typedef int int32_t;
#endif // __INT32_TYPE__
#endif // _INT32_T_DECLARED
#ifndef _INT64_T_DECLARED
#ifndef __INT64_TYPE__
typedef long long int64_t;
#endif // __INT64_TYPE__
#endif // _INT64_T_DECLARED
#ifndef _UINT8_T_DECLARED
#ifndef __UINT8_TYPE__
typedef unsigned char uint8_t;
#endif // __UINT8_TYPE__
#endif // _UINT8_T_DECLARED
#ifndef _UINT16_T_DECLARED
#ifndef __UINT16_TYPE__
typedef unsigned short uint16_t;
#endif // __UINT16_TYPE__
#endif // _UINT16_T_DECLARED
#ifndef _UINT32_T_DECLARED
#ifndef __UINT32_TYPE__
typedef unsigned int uint32_t;
#endif // __UINT32_TYPE__
#endif // _UINT32_T_DECLARED
#ifndef _UINT64_T_DECLARED
#ifndef __UINT64_TYPE__
typedef unsigned long long uint64_t;
#endif // __UINT64_TYPE__
#endif // _UINT64_T_DECLARED
#ifndef __LONG64_TYPE__
typedef long long long64_t;
#endif // __LONG64_TYPE__
#ifndef __ULONG64_TYPE__
typedef unsigned long long ulong64_t;
#endif // __ULONG64_TYPE__
// ---------------------------------------------------------------------------
// Constants
// ---------------------------------------------------------------------------
#ifndef __GIT_VER__
#define __GIT_VER__ "00000000"
#endif
#ifndef __GIT_VER_HASH__
#define __GIT_VER_HASH__ "00000000"
#endif
#define __PROG_NAME__ "Digital Voice Modem Transcoder"
#define __NET_NAME__ "TCD_DMR_P25"
#define __EXE_NAME__ "dvmtranscode"
#define __VER__ "D01.00.00 (" __GIT_VER__ ")"
#define __BUILD__ __DATE__ " " __TIME__
#define HOST_SW_API
#if defined(_WIN32) || defined(_WIN64)
#define DEFAULT_CONF_FILE "config.yml"
#else
#define DEFAULT_CONF_FILE "/opt/DVM/bin/config.yml"
#endif // defined(_WIN32) || defined(_WIN64)
#if defined(_WIN32) || defined(_WIN64)
#define DEFAULT_LOCK_FILE "dvm_transcode.lock"
#else
#define DEFAULT_LOCK_FILE "/tmp/dvm_transcode.lock"
#endif // defined(_WIN32) || defined(_WIN64)
#if defined(__GNUC__) || defined(__GNUG__)
#define __forceinline __attribute__((always_inline))
#endif
/*
** Defined in HostMain.cpp
*/
extern const uint32_t TRAFFIC_DEFAULT_PORT;
extern const uint8_t BIT_MASK_TABLE[];
extern const uint8_t TAG_HEADER;
extern const uint8_t TAG_DATA;
extern const uint8_t TAG_LOST;
extern const uint8_t TAG_EOT;
enum RPT_NET_STATE {
RS_NET_IDLE,
RS_NET_AUDIO
};
// ---------------------------------------------------------------------------
// Inlines
// ---------------------------------------------------------------------------
#ifdef __cplusplus
inline std::string __BOOL_STR(const bool& value) {
std::stringstream ss;
ss << std::boolalpha << value;
return ss.str();
}
inline std::string __INT_STR(const int& value) {
std::stringstream ss;
ss << value;
return ss.str();
}
inline std::string __FLOAT_STR(const float& value) {
std::stringstream ss;
ss << value;
return ss.str();
}
#endif
// ---------------------------------------------------------------------------
// Macros
// ---------------------------------------------------------------------------
#define __FLOAT_ADDR(x) (*(uint32_t*)& x)
#define __DOUBLE_ADDR(x) (*(uint64_t*)& x)
#define WRITE_BIT(p, i, b) p[(i) >> 3] = (b) ? (p[(i) >> 3] | BIT_MASK_TABLE[(i) & 7]) : (p[(i) >> 3] & ~BIT_MASK_TABLE[(i) & 7])
#define READ_BIT(p, i) (p[(i) >> 3] & BIT_MASK_TABLE[(i) & 7])
#define __SET_UINT32(val, buffer, offset) \
buffer[0U + offset] = val >> 24; \
buffer[1U + offset] = val >> 16; \
buffer[2U + offset] = val >> 8; \
buffer[3U + offset] = val >> 0;
#define __GET_UINT32(buffer, offset) \
(buffer[offset + 0U] << 24) | \
(buffer[offset + 1U] << 16) | \
(buffer[offset + 2U] << 8) | \
(buffer[offset + 3U] << 0);
#define __SET_UINT16(val, buffer, offset) \
buffer[0U + offset] = val >> 16; \
buffer[1U + offset] = val >> 8; \
buffer[2U + offset] = val >> 0;
#define __GET_UINT16(buffer, offset) \
(buffer[offset + 0U] << 16) | \
(buffer[offset + 1U] << 8) | \
(buffer[offset + 2U] << 0);
#define new_unique(type, ...) std::unique_ptr<type>(new type(__VA_ARGS__))
/**
* Property Creation
* These macros should always be used LAST in the "public" section of a class definition.
*/
#ifdef __cplusplus
/// <summary>Creates a read-only get property.</summary>
#define __READONLY_PROPERTY(type, variableName, propName) \
private: type m_##variableName; \
public: __forceinline type get##propName(void) const { return m_##variableName; }
/// <summary>Creates a read-only get property, does not use "get".</summary>
#define __READONLY_PROPERTY_PLAIN(type, variableName, propName) \
private: type m_##variableName; \
public: __forceinline type propName(void) const { return m_##variableName; }
/// <summary>Creates a read-only get property by reference.</summary>
#define __READONLY_PROPERTY_BYREF(type, variableName, propName) \
private: type m_##variableName; \
public: __forceinline type& get##propName(void) const { return m_##variableName; }
/// <summary>Creates a get and set property.</summary>
#define __PROPERTY(type, variableName, propName) \
private: type m_##variableName; \
public: __forceinline type get##propName(void) const { return m_##variableName; } \
__forceinline void set##propName(type val) { m_##variableName = val; }
/// <summary>Creates a get and set property, does not use "get"/"set".</summary>
#define __PROPERTY_PLAIN(type, variableName, propName) \
private: type m_##variableName; \
public: __forceinline type propName(void) const { return m_##variableName; } \
__forceinline void propName(type val) { m_##variableName = val; }
/// <summary>Creates a get and set property by reference.</summary>
#define __PROPERTY_BYREF(type, variableName, propName) \
private: type m_##variableName; \
public: __forceinline type& get##propName(void) const { return m_##variableName; } \
__forceinline void set##propName(type& val) { m_##variableName = val; }
#endif
#endif // __DEFINES_H__