-
Notifications
You must be signed in to change notification settings - Fork 2
/
clogger.sh
executable file
·884 lines (812 loc) · 18.9 KB
/
clogger.sh
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
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
#!/bin/bash
# load config elements
#source clogger.cfg
source clogger.cfg
source "$contest"
clogger_version="1"
# turn on or off verbose debug logs
debugon="true"
debuglog="./debug"
echo "" > "$debuglog"
# This function reads keys, including special function keys
readkey() {
debug "${FUNCNAME[0]}"
local key settings
settings=$(stty -g) # save terminal settings
stty -icanon -echo min 0 # disable buffering/echo, allow read to poll
dd count=1 > /dev/null 2>&1 # Throw away anything currently in the buffer
stty min 1 # Don't allow read to poll anymore
key=$(dd count=1 2> /dev/null) # do a single read(2) call
stty "$settings" # restore terminal settings
printf "%s" "$key"
debug "rawkey: '$key'"
}
# Use tput to support portable multi char keypresses
# TERM has to be set correctly for this to work.
initkeys() {
debug "${FUNCNAME[0]}"
tput init
f1=$(tput kf1)
f2=$(tput kf2)
f3=$(tput kf3)
f4=$(tput kf4)
f5=$(tput kf5)
f6=$(tput kf6)
f7=$(tput kf7)
f8=$(tput kf8)
f9=$(tput kf9)
back=$(tput kbs)
enter=$(tput nel)
escape=$'\e'
tab=$'\t'
}
# takes a single argument of the keyvalue (from readkey)
# designed to be called using command substitution
# e.g.: mappedkey=$(mapkey "$key")
mapkey() {
debug "${FUNCNAME[0]}"
case "$1" in
"$f1") echo "f1";;
"$f2") echo "f2";;
"$f3") echo "f3";;
"$f4") echo "f4";;
"$f5") echo "f5";;
"$f6") echo "f6";;
"$f7") echo "f7";;
"$f8") echo "f8";;
"$f9") echo "f9";;
"$enter") echo "enter";;
"$back") echo "back";;
"$escape") echo "escape";;
"$tab") echo "tab";;
" ") echo "space";;
*)
if [[ "$1" =~ ^[[:alnum:]]*$ ]] || [[ "$1" =~ ^[[:punct:]]*$ ]]
then
echo "$1"
fi
;;
esac
}
debug() {
if [[ "$debugon" == "true" ]]
then
echo "$1" >> "$debuglog"
fi
}
# this expects the keyname as arg1, and the logmode as arg2
# these functions are mapped in log.cfg in the function map section
# if no function is found, the key appendbuff is called
execfunc() {
debug "${FUNCNAME[0]}"
# create a named function based on the key and mode
func="$2$1"
debug "$func"
if [[ "$func" =~ ^[[:alnum:]]*$ ]] && [ -n "$(type -t ${!func})" ] && [ "$(type -t ${!func})" = function ]
then
# when running the sendcq function, run it in background and capture the pid
if [[ "${!func}" == "sendcq" ]]
then
setband
${!func} &
cqpid=$!
debug "sendcq cqpid: $cqpid"
else
${!func}
fi
else
debug "appendbuff $1"
appendbuff "$1"
fi
}
killcqpid() {
debug "${FUNCNAME[0]}"
if [[ ! -z "$cqpid" ]]
then
debug "kill -9 $cqpid"
kill -9 $cqpid
wait $pid
cqpid=""
fi
}
# open the key
openkey() {
debug "${FUNCNAME[0]}"
$keyer -o -t "off"
}
# arg1: text arg2: async/sync (default to async)
cwsend() {
debug "${FUNCNAME[0]}"
debug "$1 usekeyer=$usekeyer"
debug "$mode"
if [[ ! -z $1 ]] && [[ "$usekeyer" == "true" ]] && [[ "$mode" == "CW" ]]
then
debug "passed cwsend tests"
lastaction="$1"
drawlastaction
if [[ "$keywithhamlib" != "true" ]]
then
debug "keying with cwkeyer"
if [[ "$2" == "sync" ]]
then
debug "$keyer -w $speed -d $cwdevice -t \"$1\""
$keyer -w $speed -d $cwdevice -t "$1"
else
debug "$keyer -w $speed -d $cwdevice -t \"$1\" &"
$keyer -w $speed -d $cwdevice -t "$1" &
fi
else
debug "keying with hamlib"
if [[ "$2" == "sync" ]]
then
rigcommand "b $1"
rigcommand \wait_morse
else
rigcommand "b $1"
fi
fi
fi
}
setwpm() {
speed="$1"
if [[ "$keywithhamlib" == "true" ]]
then
debug "$rigctl $rigoptions -m $rig -r $rigdevice L KEYSPD $1"
rigcommand "L KEYSPD $1"
fi
clearbuff
drawstatus
}
qrq() {
debug "${FUNCNAME[0]}"
speed="$(($speed+5))"
setwpm $speed
}
qrs() {
debug "${FUNCNAME[0]}"
speed="$(($speed-5))"
setwpm $speed
}
runqrq=qrq
sandpqrq=qrq
runqrs=qrs
sandpqrs=qrs
getcall() {
debug "${FUNCNAME[0]}"
local val=$(echo "$buff" | cut -d' ' -f1)
echo "$val"
}
gete1() {
debug "${FUNCNAME[0]}"
local val=$(echo "$buff" | cut -d' ' -f2)
echo "$val"
}
# these are the defined functions that you can map f1-f9 to for each mode
sendbuff() {
debug "${FUNCNAME[0]}"
cwsend "$buff"
}
sendcq() {
debug "${FUNCNAME[0]}"
while true
do
cwsend "$mycq" "sync"
debug "Sleeping $cqdelay seconds between CQ calls"
sleep $cqdelay
done
}
update_exchange(){
serial_length=${#serial}
if [ "$serial_length" == 1 ]
then
temp_serial="TT$serial"
elif [ "$serial_length" == 2 ]
then
temp_serial="T$serial"
else
temp_serial=$serial
fi
debug "temp_serial $temp_serial"
debug "serial $serial"
temp_exchange="${myexchange/SERIAL/$temp_serial}"
}
sendexchange() {
update_exchange
debug "${FUNCNAME[0]}"
cwsend "$temp_exchange"
}
sendmycall() {
setband
debug "${FUNCNAME[0]}"
cwsend "$mycall"
}
sendtu() {
debug "${FUNCNAME[0]}"
cwsend "TU"
}
sendagn() {
debug "${FUNCNAME[0]}"
cwsend "$myagn"
}
parse_rst() {
# extract RST based on mode
if [ "$mode" == "CW" ]
then
rsts=$(echo "$1" | grep -oP '(\d{3})' | tr "\n" " ")
elif [ "$mode" == "FT8" ]
then
rsts=$(echo "$1" | grep -oP '(\-|\+)\d{1,2}' | tr "\n" " ")
else
rsts=$(echo "$1" | grep -oP '(\d{2})' | tr "\n" " ")
fi
# assign RST's based on whether you were running, or s&p
if [ "logmode" == "run" ]
then
sentrs=$(echo "$1" | cut -d' ' -f3)
recvrs=$(echo "$1" | cut -d' ' -f2)
else
sentrs=$(echo "$1" | cut -d' ' -f2)
recvrs=$(echo "$1" | cut -d' ' -f3)
fi
}
lotw_upload() {
tqsl -p "$certpass" -d -u -a all -x -l "$lotw_station" "$logfile" 2>lotw_results.txt
lotw_result=$(grep "Final Status:" lotw_results.txt)
subbuff="$lotw_result"
buff=""
drawbuff
drawsubmenu
}
logqso() {
debug "${FUNCNAME[0]}"
dxcall=$(echo "$buff" | cut -d' ' -f1)
if [ ! -d "logs" ]
then
mkdir logs
fi
if [ -z "$dxcall" ]
then
return
fi
decall="$mycall"
date=$(date -u +"%Y%m%d")
timeon=$(date -u +%H%M)
if [ "$parserst" == "true" ]
then
parse_rst "$buff"
comments=$(echo "$buff" | cut -d' ' -f4- | tr -cd "[:print:]")
else
sentrs="599"
recvrs="599"
# strip non-printable chars from buffer when setting comments
comments=$(echo "$buff" | cut -d' ' -f2- | tr -cd "[:print:]")
fi
if [[ "$comments" == *"skcc"* ]]; then
skcc=$(awk -F 'skcc' '{print $2}' <<< "$comments")
skcc=$(echo "$skcc" | tr -d ' ')
else
skcc=""
fi
if [[ ! -z "$contestname" ]]
then
comments="$comments - $contestname"
fi
debug "$comments"
if [ ! -z "$freq" ]
then
mhz=$(bc <<< "scale = 4; ($khz/1000000)")
fi
echo "<CALL:${#dxcall}>$dxcall" | tr '[:lower:]' '[:upper:]' >> "$logfile"
echo " <BAND:${#band}>$band" | tr '[:lower:]' '[:upper:]' >> "$logfile"
echo " <FREQ:${#mhz}>$mhz" | tr '[:lower:]' '[:upper:]' >> "$logfile"
echo " <MODE:${#mode}>$mode" | tr '[:lower:]' '[:upper:]' >> "$logfile"
echo " <QSO_DATE:${#date}>$date" | tr '[:lower:]' '[:upper:]' >> "$logfile"
echo " <TIME_ON:${#timeon}>$timeon" | tr '[:lower:]' '[:upper:]' >> "$logfile"
echo " <STATION_CALLSIGN:${#station_call}>$station_call" | tr '[:lower:]' '[:upper:]' >> "$logfile"
echo " <OPERATOR:${#decall}>$decall" | tr '[:lower:]' '[:upper:]' >> "$logfile"
echo " <RST_SENT:${#sentrs}>$sentrs" | tr '[:lower:]' '[:upper:]' >> "$logfile"
echo " <RST_RCVD:${#recvrs}>$recvrs" | tr '[:lower:]' '[:upper:]' >> "$logfile"
echo " <COMMENT:${#comments}>$comments" | tr '[:lower:]' '[:upper:]' >> "$logfile"
if [ ! -z "$skcc" ] && [ ! -z "$myskcc" ]
then
echo " <SKCC:${#skcc}>$skcc" | tr '[:lower:]' '[:upper:]' >> "$logfile"
echo " <MY_SKCC:${#myskcc}>$myskcc" | tr '[:lower:]' '[:upper:]' >> "$logfile"
fi
echo "<EOR>" | tr '[:lower:]' '[:upper:]' >> "$logfile"
qsocount="$(($qsocount+1))"
serial="$(($serial+1))"
echo "QSO $qsocount" > "./.loginfo-$contestname"
echo "SERIAL $serial" >> "./.loginfo-$contestname"
dupe="false"
lastaction="Logged $buff"
drawlastaction
clearbuff
menu
}
send_tu_exchange_logqso() {
debug "${FUNCNAME[0]}"
update_exchange
cwsend "TU $temp_exchange"
logqso
clearbuff
}
send_tu_serial_exchange_logqso() {
debug "${FUNCNAME[0]}"
update_exchange
cwsend "TU $serial $temp_exchange"
logqso
clearbuff
}
send_call_exchange() {
debug "${FUNCNAME[0]}"
update_exchange
local call=$(getcall)
cwsend "$call $temp_exchange"
}
send_serial() {
cwsend "$serial"
}
send_tu_logqso_cq() {
debug "${FUNCNAME[0]}"
cwsend "TU $mycq"
logqso
clearbuff
}
send_tu_logqso_mycall() {
debug "${FUNCNAME[0]}"
cwsend "TU $mycall"
logqso
clearbuff
}
send_tu_e1_logqso_cq() {
debug "${FUNCNAME[0]}"
local e1=$(gete1)
cwsend "TU $e1 $mycq"
logqso
clearbuff
}
# switch between run and s&p
toggle_run() {
debug "${FUNCNAME[0]}"
if [[ "$logmode" == "run" ]]
then
logmode="sandp"
else
logmode="run"
fi
clearbuff
menu
}
# cycle through the list of modes available
cycle_modes() {
debug "${FUNCNAME[0]}"
max_mode_index=${#modes[@]}
max_mode_index=$((max_mode_index-1))
if [ "$mode_index" == "$max_mode_index" ]
then
mode_index=0
else
mode_index=$((mode_index+1))
fi
mode="${modes[$mode_index]}"
clearbuff
menu
}
setband() {
if [ "$userig" == "true" ]
then
# only lookup frequency and band information once per call
if [ "$checked_band_for_current_call" == "false" ]
then
getfreq
khz="$freq"
getband "$freq"
fi
fi
}
# arg1 is call to check
checkdupe() {
debug "${FUNCNAME[0]}"
if fgrep -qiF "$1" "$logfile"
then
if [ "$userig" == "true" ]
then
worked_bands=$(grep -iA3 "$1" "$logfile" | grep "BAND" | cut -d'>' -f2)
worked=$(echo "$worked_bands" | grep "$band")
if [ -z $worked ]
then
echo "false"
else
echo "true"
fi
else
echo "true"
fi
else
echo "false"
fi
}
#
# ------------ functions for special key bindings ---------------
# enter, tab, backspace, escape, space
#
runcommand() {
debug "${FUNCNAME[0]}"
local prefix=$(echo "$1" | cut -d' ' -f1)
if [[ "$prefix" == ":rig" ]]
then
local rigargs=$(echo "$1" | cut -d' ' -f2-)
rigcommand "$rigargs"
subbuff="$rigres"
drawsubmenu
else
case "$prefix" in
":quit") echo "" && exit ;;
":serial") setserial $(echo "$1" | cut -d' ' -f2) ;;
":qrs") qrs ;;
":qrq") qrq ;;
":freq") setfreq $(echo "$1" | cut -d' ' -f2) ;;
":lotw") lotw_upload ;;
":wpm") setwpm $(echo "$1" | cut -d' ' -f2) ;;
*) buff="unknown command $prefix" && drawbuff ;;
esac
fi
}
rigcommand() {
debug "${FUNCNAME[0]}"
rigctlcount=0
if [[ "$userig" == "true" ]]
then
local arg1=$(echo "$1" | cut -d' ' -f1)
#CW string might have spaces, and quotes don't pass correctly
#so they are treated specially
if [[ "$arg1" == "b" ]] #Sending CW
then
debug "Sending CW..."
local send1=$(echo "$1" | sed 's/^b\ //g' | sed "s/'//g")
debug "$rigctl $rigoptions -m $rig -r $rigdevice b '$send1'"
for rigctlcount in {1..5} #try rigctl several times in case radio is busy.
do
$($rigctl $rigoptions -m $rig -r $rigdevice b "$send1") && break
sleep 0.1
done
else #Anything but sending CW
local send1=$(echo "$1" | sed "s/'//g")
debug "$rigctl $rigoptions -m $rig -r $rigdevice $send1"
for rigctlcount in {1..5} #try rigctl several times in case radio is busy
do
rigres=$($rigctl $rigoptions -m $rig -r $rigdevice $send1) && break
sleep 0.1
done
fi
debug "Rig command returned: $rigres; required attempts: $rigctlcount"
if [[ "$keywithhamlib" != "true" ]]; then openkey; fi
if [[ "$arg1" == "F" ]]
then
freq="$rigres"
drawstatus
fi
if [[ "$arg1" == "l" ]]
then
speed="$rigres"
drawstatus
fi
fi
}
# arg1 is serial
setserial() {
debug "${FUNCNAME[0]}"
serial=$1
drawstatus
}
# arg1 is frequency
setfreq() {
debug "${FUNCNAME[0]}"
rigcommand "F $1"
freq=$1
drawstatus
}
getfreq() {
debug "${FUNCNAME[0]}"
rigcommand "f"
freq=$(tr -dc '[[:print:]]' <<< "$rigres")
freq=$(echo "$freq" | sed 's/[^0-9]*//g')
}
getkeyerspeed() {
if [[ "$keywithhamlib" == "true" ]]
then
rigcommand 'l KEYSPD'
debug "keyer is now $speed wpm"
fi
}
getband() {
declare -A regex_array
regex_array=( ['6M']='^50[0-9]*$' ['10M']='^28[0-9]*$' ['12M']='^24[0-9]*$' ['15M']='^21[0-9]*$' ['17M']='^18[0-9]*$' ['20M']='^14[0-9]*$' ['30M']='^10[0-9]*$' ['40M']='^7[0-9]*$' ['80M']='^35[0-9]*$' )
for k in "${!regex_array[@]}"
do
if [[ $freq =~ ${regex_array[$k]} ]]
then
band=$k
break
fi
done
}
# in both modes, enter simply sends what is in the buffer
enter() {
debug "${FUNCNAME[0]}"
if [[ "${buff:0:1}" == ":" ]]
then
runcommand "$buff"
else
sendbuff
fi
}
runenter=enter
sandpenter=enter
# kills any current keyer process to halt transmission
escape() {
debug "${FUNCNAME[0]}"
pid=""
pid=$(pgrep -f "$keyer")
if [[ ! -z $pid ]]
then
kill -9 $pid
wait $pid
fi
if [[ "$usekeyer" == "true" ]]
then
debug "$1 usekeyer=$usekeyer"
if [[ "$keywithhamlib" != "true" ]]
then
openkey
else
rigcommand \stop_morse
fi
fi
}
runescape=escape
sandpescape=escape
# auto completes the first column of the callfile if there are multiple matches
# if there is a single match, it pulls the exchange portion from the callfile
tab() {
debug "${FUNCNAME[0]}"
local callbuff=$(echo "$buff" | tr " " "$delimeter")
if [[ $(grep -i "$callbuff" "$callfile" | wc -l) -eq 1 ]]
then
# make certain to trim spaces, and any non-printable chars from autocompleted exchange
local buffexchange=$(grep -i "^$callbuff" "$callfile" | cut -d"$delimeter" -f2- | tr "$delimeter" ' ' | sed -e 's/^[[:space:]]*//' | tr -cd "[:print:]")
echo "grep -i \"$callbuff\" \"$callfile\" | cut -d\"$delimeter\" -f1)" >> debug
local call=$(grep -i "$callbuff" "$callfile" | cut -d"$delimeter" -f1)
buff="$call $buffexchange"
subbuff=""
echo "single: $callbuff" >> debug
drawsubmenu
drawbuff
# if the contest file wants a space after for copying serial etc. append it
if [[ "$appendspace" == "true" ]]
then
appendbuff " "
fi
else
subbuff=$(grep -i "^$callbuff" "$callfile" | cut -d"$delimeter" -f1 | tr '\r\n' ' ')
echo "mult: $callbuff" >> debug
drawsubmenu
fi
}
runtab=tab
sandptab=tab
# appends a space to the buffer
space() {
debug "${FUNCNAME[0]}"
appendbuff " "
}
runspace=space
sandpspace=space
# remove a char from the buffer
backspace() {
debug "${FUNCNAME[0]}"
if [[ ! -z "$buff" ]]
then
buff="${buff:0:-1}"
if [[ "${#buff}" -ge "3" ]]
then
local call=$(echo "$buff" | cut -d' ' -f1)
dupe=$(checkdupe "$call")
else
dupe="false"
fi
if [[ "$dupe" == "true" ]]
then
tput setaf 1
fi
tput el1
tput cup $buffline 0
echo -n ">$buff"
tput sgr0
fi
setbuffcursor
}
runback="backspace"
sandpback="backspace"
#
# ------------ drawing routines ---------------
#
# draw the main menu screen and calculate buffline
menu() {
debug "${FUNCNAME[0]}"
clearscreen
tput cup $menuline 0
buffline=0
drawstatus
drawlastaction
# build the function map for the menu
for i in {1..9}
do
f="f$i"
func="$logmode$f"
if [ -n "$(type -t ${!func})" ] && [ "$(type -t ${!func})" = function ]
then
let buffline+=1
echo -e "$f: ${!func}"
fi
done
let buffline+=2
drawsubmenu
drawbuff
}
# takes a single argument of the line number to clear
clearline() {
debug "${FUNCNAME[0]}"
tput cup $1 0
tput el
}
drawlastaction() {
debug "${FUNCNAME[0]}"
tput sc
clearline $lastactionline
tput dim
echo "Last action: $lastaction"
tput sgr0
tput rc
}
# takes a single argument of the text to append to buff
appendbuff() {
debug "${FUNCNAME[0]}"
buff="$buff$1"
tput el1
if [[ "${#buff}" -ge "3" ]]
then
local call=$(echo "$buff" | cut -d' ' -f1)
dupe=$(checkdupe "$call")
fi
if [[ "$dupe" == "true" ]]
then
tput setaf 1
fi
tput cup $buffline 0
echo -n ">$buff"
tput sgr0
setbuffcursor
}
clearbuff() {
debug "${FUNCNAME[0]}"
buff=""
drawbuff
}
clearscreen() {
debug "${FUNCNAME[0]}"
tput clear
}
drawbuff() {
debug "${FUNCNAME[0]}"
clearline $buffline
tput cup $buffline 0
echo -n ">$buff"
tput sgr0
setbuffcursor
}
drawstatus() {
debug "${FUNCNAME[0]}"
if [[ $(type -t get_mults) == "function" ]]
then
get_mults
status="Mode: $mode $logmode Speed: $speed Freq: $freq Call: $mycall QSO: $qsocount Serial: $serial Mults: $mults"
else
status="Mode: $mode $logmode Speed: $speed Freq: $freq Call: $mycall QSO: $qsocount Serial: $serial"
fi
tput sc
clearline $statusline
tput bold
echo "$status"
tput sgr0
tput rc
}
drawsubmenu() {
debug "${FUNCNAME[0]}"
tput sc
let subline=$buffline+2
tput cup $subline 0
tput ed
echo $subbuff
tput rc
}
setbuffcursor() {
debug "${FUNCNAME[0]}"
tput cup $buffline $((${#buff}+1))
}
#
# ------------ main loop and script init ---------------
#
mainloop() {
#redirect all stderr to dev null - this supressis killed pid messages etc.
exec 2>/dev/null
debug "${FUNCNAME[0]}"
debug "my pid $BASHPID"
debug "logfile: $logfile"
if [ ! -f "$logfile" ]; then
debug "no log found clearing loginfo"
#remove loginfo file if no current log is found
debug "removing ./.loginfo-$contestname"
rm "./.loginfo-$contest"
debug "creating logfile: $logfile"
touch "$logfile"
echo "<ADIF_VER:4>1.00" >> "$logfile"
echo "<EOH>" >> "$logfile"
fi
band=""
freq=""
if [ "$userig" == "true" ]
then
getfreq
getkeyerspeed
fi
khz="$freq"
getband "$freq"
buff=""
subbuff=""
lastaction=""
dupe="false"
statusline=0
lastactionline=1
menuline=2
cqpid=""
temp_exchange="$myexchange"
if [ "$config_version" != "$clogger_version" ]
then
subbuff="WARNING - Mismatched configuration version"
drawsubmenu
drawbuff
fi
if [ "$userig" == "false" & "$keywithrig" == "true " ]
then
subbuff="WARNING - Mismatched userig and keywithrig configuration"
drawsubmenu
drawbuff
fi
menu
while true
do
key=$(readkey)
mappedkey=$(mapkey "$key")
killcqpid
execfunc "$mappedkey" "$logmode"
done
}
# we MUST initialize our keycodes
initkeys
qsocount=0
serial=1
#set serial and log count based on loginfo
if test -f "./.loginfo-$contestname"; then
debug "getting qso count and serial from loginfo"
qsocount=$(grep QSO ".loginfo-$contestname" | cut -d' ' -f2)
serial=$(grep SERIAL ".loginfo-$contestname" | cut -d' ' -f2)
fi
# if we had a bogus loginfo, reset qso and serial counts
if [ "$qsocount" == "" ]
then
qsocount=0
serial=1
fi
# call our main loop
mainloop