-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogic.tcl
813 lines (683 loc) · 18.7 KB
/
Logic.tcl
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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
###############################################################################
#
# Generic Logic event handlers
#
###############################################################################
#
# This is the namespace in which all functions and variables below will exist.
#
namespace eval Logic {
#
# A variable used to store a timestamp for the last identification.
#
variable prev_ident 0;
#
# A constant that indicates the minimum time in seconds to wait between two
# identifications. Manual and long identifications is not affected.
#
variable min_time_between_ident 120;
#
# Short and long identification intervals. They are setup from config
# variables below.
#
variable short_ident_interval 0;
variable long_ident_interval 0;
variable short_voice_id_enable 1
variable short_cw_id_enable 0
variable short_announce_enable 0
variable short_announce_file ""
variable long_voice_id_enable 1
variable long_cw_id_enable 0
variable long_announce_enable 0
variable long_announce_file ""
#
# The ident_only_after_tx variable indicates if identification is only to
# occur after the node has transmitted. The variable is setup below from the
# configuration variable with the same name.
# The need_ident variable indicates if identification is needed.
#
variable ident_only_after_tx 0;
variable need_ident 0;
#
# List of functions that should be called periodically. Use the
# addMinuteTickSubscriber and addSecondTickSubscriber functions to
# add subscribers.
#
variable minute_tick_subscribers [list];
variable second_tick_subscribers [list];
#
# Contains the ID of the last receiver that indicated squelch activity
#
variable sql_rx_id "?";
#
# Executed when the SvxLink software is started
#
proc startup {} {
#playMsg "Core" "online"
#send_short_ident
}
#
# Executed when a specified module could not be found
# module_id - The numeric ID of the module
#
proc no_such_module {module_id} {
playMsg "Core" "no_such_module";
playNumber $module_id;
}
#
# Executed when a manual identification is initiated with the * DTMF code
#
proc manual_identification {} {
global mycall;
global report_ctcss;
global active_module;
global loaded_modules;
variable CFG_TYPE;
variable prev_ident;
set epoch [clock seconds];
set hour [clock format $epoch -format "%k"];
regexp {([1-5]?\d)$} [clock format $epoch -format "%M"] -> minute;
set prev_ident $epoch;
playMsg "Core" "online";
spellWord $mycall;
if {$CFG_TYPE == "Repeater"} {
playMsg "Core" "repeater";
}
playSilence 250;
playMsg "Core" "the_time_is";
playTime $hour $minute;
playSilence 250;
if {$report_ctcss > 0} {
playMsg "Core" "pl_is";
playFrequency $report_ctcss
playSilence 300;
}
if {$active_module != ""} {
playMsg "Core" "active_module";
playMsg $active_module "name";
playSilence 250;
set func "::";
append func $active_module "::status_report";
if {"[info procs $func]" ne ""} {
$func;
}
} else {
foreach module [split $loaded_modules " "] {
set func "::";
append func $module "::status_report";
if {"[info procs $func]" ne ""} {
$func;
}
}
}
playMsg "Default" "press_0_for_help"
playSilence 250;
}
#
# Executed when a short identification should be sent
# hour - The hour on which this identification occur
# minute - The minute on which this identification occur
#
proc send_short_ident {{hour -1} {minute -1}} {
global mycall;
variable CFG_TYPE;
variable short_announce_file
variable short_announce_enable
variable short_voice_id_enable
variable short_cw_id_enable
# Play voice id if enabled
if {$short_voice_id_enable} {
puts "Playing short voice ID"
spellWord $mycall;
if {$CFG_TYPE == "Repeater"} {
playMsg "Core" "repeater";
}
playSilence 500;
}
# Play announcement file if enabled
if {$short_announce_enable} {
puts "Playing short announce"
if [file exist "$short_announce_file"] {
playFile "$short_announce_file"
playSilence 500
}
}
# Play CW id if enabled
if {$short_cw_id_enable} {
puts "Playing short CW ID"
if {$CFG_TYPE == "Repeater"} {
set call "$mycall/R"
CW::play $call
} else {
CW::play $mycall
}
playSilence 500;
}
}
#
# Executed when a long identification (e.g. hourly) should be sent
# hour - The hour on which this identification occur
# minute - The minute on which this identification occur
#
proc send_long_ident {hour minute} {
global mycall;
global loaded_modules;
global active_module;
variable CFG_TYPE;
variable long_announce_file
variable long_announce_enable
variable long_voice_id_enable
variable long_cw_id_enable
# Play the voice ID if enabled
if {$long_voice_id_enable} {
puts "Playing Long voice ID"
spellWord $mycall;
if {$CFG_TYPE == "Repeater"} {
playMsg "Core" "repeater";
}
playSilence 500;
playMsg "Core" "the_time_is";
playSilence 100;
playTime $hour $minute;
playSilence 500;
# Call the "status_report" function in all modules if no module is active
if {$active_module == ""} {
foreach module [split $loaded_modules " "] {
set func "::";
append func $module "::status_report";
if {"[info procs $func]" ne ""} {
$func;
}
}
}
playSilence 500;
}
# Play announcement file if enabled
if {$long_announce_enable} {
puts "Playing long announce"
if [file exist "$long_announce_file"] {
playFile "$long_announce_file"
playSilence 500
}
}
# Play CW id if enabled
if {$long_cw_id_enable} {
puts "Playing long CW ID"
if {$CFG_TYPE == "Repeater"} {
set call "$mycall/R"
CW::play $call
} else {
CW::play $mycall
}
playSilence 100
}
}
#
# Executed when the squelch have just closed and the RGR_SOUND_DELAY timer has
# expired.
#
proc send_rgr_sound {} {
variable sql_rx_id
if {$sql_rx_id != "?"} {
# 200 CPM, 1000 Hz, -10 dBFS
CW::play $sql_rx_id 200 1000 -10
set sql_rx_id "?"
} else {
playTone 440 500 100
}
playSilence 100
}
#
# Executed when an empty macro command (i.e. D#) has been entered.
#
proc macro_empty {} {
playMsg "Core" "operation_failed";
}
#
# Executed when an entered macro command could not be found
#
proc macro_not_found {} {
playMsg "Core" "operation_failed";
}
#
# Executed when a macro syntax error occurs (configuration error).
#
proc macro_syntax_error {} {
playMsg "Core" "operation_failed";
}
#
# Executed when the specified module in a macro command is not found
# (configuration error).
#
proc macro_module_not_found {} {
playMsg "Core" "operation_failed";
}
#
# Executed when the activation of the module specified in the macro command
# failed.
#
proc macro_module_activation_failed {} {
playMsg "Core" "operation_failed";
}
#
# Executed when a macro command is executed that requires a module to
# be activated but another module is already active.
#
proc macro_another_active_module {} {
global active_module;
playMsg "Core" "operation_failed";
playMsg "Core" "active_module";
playMsg $active_module "name";
}
#
# Executed when an unknown DTMF command is entered
# cmd - The command string
#
proc unknown_command {cmd} {
spellWord $cmd;
playMsg "Core" "unknown_command";
}
#
# Executed when an entered DTMF command failed
# cmd - The command string
#
proc command_failed {cmd} {
spellWord $cmd;
playMsg "Core" "operation_failed";
}
#
# Executed when a link to another logic core is activated.
# name - The name of the link
#
proc activating_link {name} {
if {[string length $name] > 0} {
playMsg "Core" "activating_link_to";
spellWord $name;
}
}
#
# Executed when a link to another logic core is deactivated.
# name - The name of the link
#
proc deactivating_link {name} {
if {[string length $name] > 0} {
playMsg "Core" "deactivating_link_to";
spellWord $name;
}
}
#
# Executed when trying to deactivate a link to another logic core but the
# link is not currently active.
# name - The name of the link
#
proc link_not_active {name} {
if {[string length $name] > 0} {
playMsg "Core" "link_not_active_to";
spellWord $name;
}
}
#
# Executed when trying to activate a link to another logic core but the
# link is already active.
# name - The name of the link
#
proc link_already_active {name} {
if {[string length $name] > 0} {
playMsg "Core" "link_already_active_to";
spellWord $name;
}
}
#
# Executed each time the transmitter is turned on or off
# is_on - Set to 1 if the transmitter is on or 0 if it's off
#
proc transmit {is_on} {
#puts "Turning the transmitter $is_on";
variable prev_ident;
variable need_ident;
if {$is_on && ([clock seconds] - $prev_ident > 5)} {
set need_ident 1;
}
}
#
# Executed each time the squelch is opened or closed
# rx_id - The ID of the RX that the squelch opened/closed on
# is_open - Set to 1 if the squelch is open or 0 if it's closed
#
proc squelch_open {rx_id is_open} {
variable sql_rx_id;
#puts "The squelch is $is_open on RX $rx_id";
set sql_rx_id $rx_id;
}
#
# Executed when a DTMF digit has been received
# digit - The detected DTMF digit
# duration - The duration, in milliseconds, of the digit
#
# Return 1 to hide the digit from further processing in SvxLink or
# return 0 to make SvxLink continue processing as normal.
#
proc dtmf_digit_received {digit duration} {
#puts "DTMF digit \"$digit\" detected with duration $duration ms";
return 0;
}
#
# Executed when a DTMF command has been received
# cmd - The command
#
# Return 1 to hide the command from further processing is SvxLink or
# return 0 to make SvxLink continue processing as normal.
#
# This function can be used to implement your own custom commands or to disable
# DTMF commands that you do not want users to execute.
proc dtmf_cmd_received {cmd} {
#global active_module
# Example: Ignore all commands starting with 3 in the EchoLink module.
# Allow commands that have four or more digits.
#if {$active_module == "EchoLink"} {
# if {[string length $cmd] < 4 && [string index $cmd 0] == "3"} {
# puts "Ignoring random connect command for module EchoLink: $cmd"
# return 1
# }
#}
# Handle the "force core command" mode where a command is forced to be
# executed by the core command processor instead of by an active module.
# The "force core command" mode is entered by prefixing a command by a star.
#if {$active_module != "" && [string index $cmd 0] != "*"} {
# return 0
#}
#if {[string index $cmd 0] == "*"} {
# set cmd [string range $cmd 1 end]
#}
# Example: Custom command executed when DTMF 99 is received
if {$cmd == "D911"} {
set runcmd [exec /usr/sbin/mylocalip];
puts "Local IP Adress : $runcmd"
set splitip [split $runcmd .]
lassign $splitip ip1 ip2 ip3 ip4
spellWord $ip1;
playMsg "Default" "decimal";
spellWord $ip2;
playMsg "Default" "decimal";
spellWord $ip3;
playMsg "Default" "decimal";
spellWord $ip4;
return 1
}
return 0
}
#
# Executed once every whole minute. Don't put any code here directly
# Create a new function and add it to the timer tick subscriber list
# by using the function addMinuteTickSubscriber.
#
proc every_minute {} {
variable minute_tick_subscribers;
#puts [clock format [clock seconds] -format "%Y-%m-%d %H:%M:%S"];
foreach subscriber $minute_tick_subscribers {
$subscriber;
}
}
#
# Executed once every whole minute. Don't put any code here directly
# Create a new function and add it to the timer tick subscriber list
# by using the function addSecondTickSubscriber.
#
proc every_second {} {
variable second_tick_subscribers;
#puts [clock format [clock seconds] -format "%Y-%m-%d %H:%M:%S"];
foreach subscriber $second_tick_subscribers {
$subscriber;
}
}
#
# Deprecated: Use the addMinuteTickSubscriber function instead
#
proc addTimerTickSubscriber {func} {
puts "*** WARNING: Calling deprecated TCL event handler addTimerTickSubcriber."
puts " Use addMinuteTickSubscriber instead"
addMinuteTickSubscriber $func;
}
#
# Use this function to add a function to the list of functions that
# should be executed once every whole minute. This is not an event
# function but rather a management function.
#
proc addMinuteTickSubscriber {func} {
variable minute_tick_subscribers;
lappend minute_tick_subscribers $func;
}
#
# Use this function to add a function to the list of functions that
# should be executed once every second. This is not an event
# function but rather a management function.
#
proc addSecondTickSubscriber {func} {
variable second_tick_subscribers;
lappend second_tick_subscribers $func;
}
proc svxlinkmessage {} {
set result [exec /usr/sbin/svxlink-message];
if {$result == "online"} {
puts "Internet online :Connected"
playMsg "Default" "connected";
set runcmd [exec /usr/sbin/mylocalip];
puts "Local IP Adress : $runcmd"
set splitip [split $runcmd .]
lassign $splitip ip1 ip2 ip3 ip4
spellWord $ip1;
playMsg "Default" "decimal";
spellWord $ip2;
playMsg "Default" "decimal";
spellWord $ip3;
playMsg "Default" "decimal";
spellWord $ip4;
}
if {$result == "offline"} {
puts "Internet online :Disconnected"
playMsg "Default" "disconnected";
}
}
Logic::addSecondTickSubscriber Logic::svxlinkmessage
#
# Should be executed once every whole minute to check if it is time to
# identify. Not exactly an event function. This function handle the
# identification logic and call the send_short_ident or send_long_ident
# functions when it is time to identify.
#
proc checkPeriodicIdentify {} {
variable prev_ident;
variable short_ident_interval;
variable long_ident_interval;
variable min_time_between_ident;
variable ident_only_after_tx;
variable need_ident;
global logic_name;
if {$short_ident_interval == 0} {
return;
}
set now [clock seconds];
set hour [clock format $now -format "%k"];
regexp {([1-5]?\d)$} [clock format $now -format "%M"] -> minute;
set short_ident_now \
[expr {($hour * 60 + $minute) % $short_ident_interval == 0}];
set long_ident_now 0;
if {$long_ident_interval != 0} {
set long_ident_now \
[expr {($hour * 60 + $minute) % $long_ident_interval == 0}];
}
if {$long_ident_now} {
puts "$logic_name: Sending long identification...";
send_long_ident $hour $minute;
set prev_ident $now;
set need_ident 0;
} else {
if {$now - $prev_ident < $min_time_between_ident} {
return;
}
if {$ident_only_after_tx && !$need_ident} {
return;
}
if {$short_ident_now} {
puts "$logic_name: Sending short identification...";
send_short_ident $hour $minute;
set prev_ident $now;
set need_ident 0;
}
}
}
#
# Executed when the QSO recorder is being activated
#
proc activating_qso_recorder {} {
playMsg "Core" "activating";
playMsg "Core" "qso_recorder";
}
#
# Executed when the QSO recorder is being deactivated
#
proc deactivating_qso_recorder {} {
playMsg "Core" "deactivating";
playMsg "Core" "qso_recorder";
}
#
# Executed when trying to deactivate the QSO recorder even though it's
# not active
#
proc qso_recorder_not_active {} {
playMsg "Core" "qso_recorder";
playMsg "Core" "not_active";
}
#
# Executed when trying to activate the QSO recorder even though it's
# already active
#
proc qso_recorder_already_active {} {
playMsg "Core" "qso_recorder";
playMsg "Core" "already_active";
}
#
# Executed when the timeout kicks in to activate the QSO recorder
#
proc qso_recorder_timeout_activate {} {
playMsg "Core" "timeout"
playMsg "Core" "activating";
playMsg "Core" "qso_recorder";
}
#
# Executed when the timeout kicks in to deactivate the QSO recorder
#
proc qso_recorder_timeout_deactivate {} {
playMsg "Core" "timeout"
playMsg "Core" "deactivating";
playMsg "Core" "qso_recorder";
}
#
# Executed when the user is requesting a language change
#
proc set_language {lang_code} {
global logic_name;
puts "$logic_name: Setting language $lang_code (NOT IMPLEMENTED)";
}
#
# Executed when the user requests a list of available languages
#
proc list_languages {} {
global logic_name;
puts "$logic_name: Available languages: (NOT IMPLEMENTED)";
}
#
# Executed when the node is being brought online or offline
#
proc logic_online {online} {
global mycall
variable CFG_TYPE
if {$online} {
playMsg "Core" "online";
spellWord $mycall;
if {$CFG_TYPE == "Repeater"} {
playMsg "Core" "repeater";
}
}
}
#
# Executed when a configuration variable is updated at runtime in the logic
# core
#
proc config_updated {tag value} {
#puts "Configuration variable updated: $tag=$value"
}
#
# Executed when a DTMF command is received from another linked logic core
#
# logic -- The name of the logic core
# cmd -- The received command
#
proc remote_cmd_received {logic cmd} {
#puts "Remote command received from logic $logic: $cmd"
#playDtmf "$cmd" "500" "50"
}
#
# Executed when a talkgroup is received from another linked logic core
#
# logic -- The name of the logic core
# tg -- The received talkgroup
#
proc remote_received_tg_updated {logic tg} {
#puts "Remote TG received from logic $logic: $tg"
#if {$tg > 0} {
# playDtmf "1$tg" "500" "50"
#}
}
##############################################################################
#
# Main program
#
##############################################################################
if [info exists CFG_SHORT_IDENT_INTERVAL] {
if {$CFG_SHORT_IDENT_INTERVAL > 0} {
set short_ident_interval $CFG_SHORT_IDENT_INTERVAL;
}
}
if [info exists CFG_LONG_IDENT_INTERVAL] {
if {$CFG_LONG_IDENT_INTERVAL > 0} {
set long_ident_interval $CFG_LONG_IDENT_INTERVAL;
if {$short_ident_interval == 0} {
set short_ident_interval $long_ident_interval;
}
}
}
if [info exists CFG_IDENT_ONLY_AFTER_TX] {
if {$CFG_IDENT_ONLY_AFTER_TX > 0} {
set ident_only_after_tx $CFG_IDENT_ONLY_AFTER_TX;
}
}
if [info exists CFG_SHORT_ANNOUNCE_ENABLE] {
set short_announce_enable $CFG_SHORT_ANNOUNCE_ENABLE
}
if [info exists CFG_SHORT_ANNOUNCE_FILE] {
set short_announce_file $CFG_SHORT_ANNOUNCE_FILE
}
if [info exists CFG_SHORT_VOICE_ID_ENABLE] {
set short_voice_id_enable $CFG_SHORT_VOICE_ID_ENABLE
}
if [info exists CFG_SHORT_CW_ID_ENABLE] {
set short_cw_id_enable $CFG_SHORT_CW_ID_ENABLE
}
if [info exists CFG_LONG_ANNOUNCE_ENABLE] {
set long_announce_enable $CFG_LONG_ANNOUNCE_ENABLE
}
if [info exists CFG_LONG_ANNOUNCE_FILE] {
set long_announce_file $CFG_LONG_ANNOUNCE_FILE
}
if [info exists CFG_LONG_VOICE_ID_ENABLE] {
set long_voice_id_enable $CFG_LONG_VOICE_ID_ENABLE
}
if [info exists CFG_LONG_CW_ID_ENABLE] {
set long_cw_id_enable $CFG_LONG_CW_ID_ENABLE
}
# end of namespace
}
#
# This file has not been truncated
#