-
Notifications
You must be signed in to change notification settings - Fork 76
/
misc.h
352 lines (282 loc) · 11.3 KB
/
misc.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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
/* Copyright 2023 Dual Tachyon
* https://github.com/DualTachyon
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MISC_H
#define MISC_H
#include <string.h>
#include <stdlib.h> // abs()
#include <stdbool.h>
#include <stdint.h>
//#include "settings.h"
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
#endif
#ifndef SQR
#define SQR(x) ((x) * (x))
#endif
#ifndef MAX
// #define MAX(a, b) ({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); _a > _b ? _a : _b; })
#endif
#ifndef MIN
// #define MIN(a, b) ({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); _a < _b ? _a : _b; })
#endif
//#define IS_USER_CHANNEL(x) ((x) >= USER_CHANNEL_FIRST && (x) <= USER_CHANNEL_LAST)
#define IS_USER_CHANNEL(x) ((x) <= USER_CHANNEL_LAST)
#define IS_FREQ_CHANNEL(x) ((x) >= FREQ_CHANNEL_FIRST && (x) <= FREQ_CHANNEL_LAST)
#define IS_VALID_CHANNEL(x) ((x) < LAST_CHANNEL)
#define IS_NOAA_CHANNEL(x) ((x) >= NOAA_CHANNEL_FIRST && (x) <= NOAA_CHANNEL_LAST)
//#define IS_NOT_NOAA_CHANNEL(x) ((x) >= USER_CHANNEL_FIRST && (x) <= FREQ_CHANNEL_LAST)
#define IS_NOT_NOAA_CHANNEL(x) ((x) <= FREQ_CHANNEL_LAST)
#define CHANNEL_NUM(chaanel, vfo) IS_FREQ_CHANNEL(channel) ? (FREQ_CHANNEL_FIRST + ((channel) - FREQ_CHANNEL_FIRST) * 2) + (vfo) : (channel);
// PTT key-up/key-down audio tone freq's used in NASA's apollo rides to the moon
#define APOLLO_TONE_MS 200 // slightly shorter tone length
//#define APOLLO_TONE_MS 250 // NASA tone length
#define APOLLO_TONE1_HZ 2525
#define APOLLO_TONE2_HZ 2475
#define TONE_1750_MS 500
enum {
USER_CHANNEL_FIRST = 0,
USER_CHANNEL_LAST = 199u,
FREQ_CHANNEL_FIRST = 200u,
FREQ_CHANNEL_LAST = 206u,
NOAA_CHANNEL_FIRST = 207u,
NOAA_CHANNEL_LAST = 216u,
LAST_CHANNEL
};
enum {
FLASHLIGHT_OFF = 0,
FLASHLIGHT_ON,
FLASHLIGHT_BLINK,
FLASHLIGHT_SOS,
FLASHLIGHT_LAST
};
enum {
VFO_CONFIGURE_NONE = 0,
VFO_CONFIGURE,
VFO_CONFIGURE_RELOAD
};
enum alarm_state_e {
ALARM_STATE_OFF = 0,
ALARM_STATE_TX_ALARM,
ALARM_STATE_ALARM,
ALARM_STATE_TX_TONE
};
typedef enum alarm_state_e alarm_state_t;
enum reception_mode_e {
RX_MODE_NONE = 0, // squelch close ?
RX_MODE_DETECTED, // signal detected
RX_MODE_LISTENING //
};
typedef enum reception_mode_e reception_mode_t;
enum css_scan_mode_e
{
CSS_SCAN_MODE_OFF = 0,
CSS_SCAN_MODE_SCANNING,
CSS_SCAN_MODE_FOUND,
};
typedef enum css_scan_mode_e css_scan_mode_t;
enum scan_next_chan_e {
SCAN_NEXT_CHAN_SCANLIST1 = 0,
SCAN_NEXT_CHAN_SCANLIST2,
SCAN_NEXT_CHAN_USER,
SCAN_NEXT_NUM
};
typedef enum scan_next_chan_e scan_next_chan_t;
enum scan_state_dir_e {
SCAN_STATE_DIR_REVERSE = -1,
SCAN_STATE_DIR_OFF = 0,
SCAN_STATE_DIR_FORWARD = +1
};
typedef enum scan_state_dir_e scan_state_dir_t;
extern const uint8_t obfuscate_array[16];
extern const uint16_t tx_timeout_secs[16];
extern const uint8_t fm_resume_500ms;
extern const uint8_t fm_radio_500ms;
extern const uint16_t fm_play_scan_10ms;
extern const uint16_t fm_play_noscan_10ms;
extern const uint8_t menu_timeout_500ms;
extern const uint16_t menu_timeout_long_500ms;
extern const uint16_t backlight_tx_rx_time_secs;
#ifdef ENABLE_DTMF_LIVE_DECODER
extern const uint8_t dtmf_rx_live_timeout_500ms;
#endif
extern const uint8_t dtmf_rx_timeout_500ms;
extern const uint8_t dtmf_decode_ring_500ms;
extern const uint8_t dtmf_txstop_500ms;
extern const uint8_t serial_config_tick_500ms;
extern const uint8_t key_input_timeout_500ms;
#ifdef ENABLE_KEYLOCK
extern const uint8_t key_lock_timeout_500ms;
#endif
extern const uint8_t key_debounce_10ms;
extern const uint8_t key_side_long_press_10ms;
extern const uint8_t key_long_press_10ms;
extern const uint8_t key_repeat_initial_10ms;
extern const uint8_t key_repeat_fastest_10ms;
extern const uint16_t key_repeat_speedup_10ms;
extern const uint16_t search_freq_css_10ms;
extern const uint16_t search_10ms;
extern const uint16_t power_save_pause_10ms;
extern const uint16_t power_save1_10ms;
extern const uint16_t power_save2_10ms;
#ifdef ENABLE_VOX
extern const uint16_t vox_stop_10ms;
#endif
extern const uint16_t noaa_tick_10ms;
extern const uint16_t noaa_tick_2_10ms;
extern const uint16_t noaa_tick_3_10ms;
#ifdef ENABLE_VOX
extern const uint16_t dual_watch_delay_after_vox_10ms;
#endif
extern const uint16_t dual_watch_delay_after_tx_10ms;
extern const uint16_t dual_watch_delay_toggle_10ms;
extern const uint16_t dual_watch_delay_noaa_10ms;
extern const uint16_t scan_pause_code_10ms;
extern const uint16_t scan_pause_css_10ms;
extern const uint16_t scan_pause_ctcss_10ms;
extern const uint16_t scan_pause_cdcss_10ms;
extern const uint16_t scan_pause_freq_10ms;
extern const uint16_t scan_pause_chan_10ms;
extern const uint8_t g_mic_gain_dB_2[5];
extern bool g_monitor_enabled;
extern const uint32_t g_default_aes_key[4];
extern bool g_has_aes_key;
extern uint32_t g_challenge[4];
extern volatile uint16_t g_power_save_pause_tick_10ms;
extern volatile bool g_power_save_pause_done;
extern volatile bool g_power_save_expired;
extern volatile uint16_t g_dual_watch_tick_10ms;
extern volatile bool g_dual_watch_delay_down_expired;
#if defined(ENABLE_UART)
extern volatile uint8_t g_serial_config_tick_500ms;
#endif
extern volatile bool g_next_time_slice_500ms;
extern volatile uint16_t g_tx_timer_tick_500ms;
extern volatile bool g_tx_timeout_reached;
extern volatile uint16_t g_tail_tone_elimination_tick_10ms;
#ifdef ENABLE_FMRADIO
extern volatile uint16_t g_fm_play_tick_10ms;
#endif
#ifdef ENABLE_NOAA
extern volatile uint16_t g_noaa_tick_10ms;
#endif
extern uint8_t g_update_screen_tick_500ms;
extern uint8_t g_key_input_count_down;
#ifdef ENABLE_KEYLOCK
extern uint8_t g_key_lock_tick_500ms;
#endif
extern uint8_t g_rtte_count_down;
extern bool g_password_locked;
extern uint8_t g_update_status;
extern uint8_t g_found_ctcss;
extern uint8_t g_found_cdcss;
extern bool g_end_of_rx_detected_maybe;
extern int16_t g_vfo_rssi[2];
extern uint8_t g_vfo_rssi_bar_level[2];
extern uint8_t g_reduced_service;
extern uint8_t g_battery_voltage_index;
extern css_scan_mode_t g_css_scan_mode;
extern bool g_update_rssi;
extern alarm_state_t g_alarm_state;
extern uint16_t g_menu_tick_10ms;
extern bool g_flag_reconfigure_vfos;
extern uint8_t g_vfo_configure_mode;
extern bool g_flag_reset_vfos;
extern bool g_request_save_vfo;
extern uint8_t g_request_save_channel;
extern bool g_request_save_settings;
#ifdef ENABLE_FMRADIO
extern bool g_request_save_fm;
#endif
extern bool g_flag_prepare_tx;
extern bool g_flag_accept_setting; // accept menu setting
extern bool g_update_menu; // refresh menu display
extern bool g_flag_save_vfo;
extern bool g_flag_save_settings;
extern bool g_flag_save_channel;
#ifdef ENABLE_FMRADIO
extern bool g_flag_save_fm;
#endif
extern bool g_cdcss_lost;
extern uint8_t g_cdcss_code_type;
extern bool g_ctcss_lost;
extern bool g_cxcss_tail_found;
extern uint8_t g_ctcss_tail_phase_shift_rx;
#ifdef ENABLE_VOX
extern bool g_vox_lost;
extern bool g_vox_audio_detected;
extern uint16_t g_vox_resume_tick_10ms;
extern uint16_t g_vox_pause_tick_10ms;
#endif
extern bool g_squelch_open;
extern uint8_t g_flash_light_state;
extern uint16_t g_flash_light_blink_tick_10ms;
extern bool g_flag_end_tx;
extern uint16_t g_low_battery_tick_10ms;
extern reception_mode_t g_rx_reception_mode;
extern uint32_t g_scan_initial_lower;
extern uint32_t g_scan_initial_upper;
extern uint32_t g_scan_initial_step_size;
extern uint8_t g_scan_next_channel; //
extern scan_next_chan_t g_scan_current_scan_list; //
extern uint8_t g_scan_restore_channel; // the channel we were on before starting the RF scan
extern uint32_t g_scan_restore_frequency; // the frequency we were on before starting the RF scan
extern bool g_scan_pause_time_mode; // set if we stopped in SCAN_RESUME_TIME mode
extern volatile uint16_t g_scan_tick_10ms; // ticks till we move to next channel/frequency
extern scan_state_dir_t g_scan_state_dir; // the direction we're scanning in
extern uint8_t g_rx_vfo_num;
extern bool g_rx_vfo_is_active;
extern uint16_t g_alarm_tone_counter_10ms;
extern uint16_t g_alarm_running_counter_10ms;
extern uint8_t g_menu_list_count;
extern uint8_t g_backup_cross_vfo;
#ifdef ENABLE_NOAA
extern bool g_noaa_mode;
extern uint8_t g_noaa_channel;
#endif
extern volatile bool g_next_time_slice;
extern bool g_update_display;
extern bool g_unhide_hidden;
#ifdef ENABLE_FMRADIO
extern uint8_t g_fm_channel_position;
#endif
extern volatile uint8_t g_found_cdcss_tick_10ms;
extern volatile uint8_t g_found_ctcss_tick_10ms;
#ifdef ENABLE_VOX
extern volatile uint16_t g_vox_stop_tick_10ms;
#endif
extern volatile bool g_next_time_slice_40ms;
#ifdef ENABLE_NOAA
extern volatile uint16_t g_noaa_tick_10ms;
extern volatile bool g_schedule_noaa;
#endif
extern volatile bool g_flag_tail_tone_elimination_complete;
extern int16_t g_current_rssi[2];
extern uint16_t g_current_glitch[2];
extern uint16_t g_current_noise[2];
extern volatile uint16_t g_boot_tick_10ms;
extern uint8_t g_mic_sensitivity_tuning;
extern const uint8_t g_orig_lnas;
extern const uint8_t g_orig_lna;
extern const uint8_t g_orig_mixer;
extern const uint8_t g_orig_pga;
unsigned int get_TX_VFO(void);
unsigned int get_RX_VFO(void);
void NUMBER_Get(char *pDigits, uint32_t *pInteger);
void NUMBER_ToDigits(uint32_t Value, char *pDigits);
int32_t NUMBER_AddWithWraparound(int32_t Base, int32_t Add, int32_t LowerLimit, int32_t UpperLimit);
void NUMBER_trim_trailing_zeros(char *str);
uint16_t NUMBER_isqrt(const uint32_t y);
#endif