forked from talkkonnect/talkkonnect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
commandkeys.go
868 lines (754 loc) · 26.9 KB
/
commandkeys.go
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
/*
* talkkonnect headless mumble client/gateway with lcd screen and channel control
* Copyright (C) 2018-2019, Suvir Kumar <[email protected]>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* talkkonnect is the based on talkiepi and barnard by Daniel Chote and Tim Cooper
*
* The Initial Developer of the Original Code is
* Suvir Kumar <[email protected]>
* Portions created by the Initial Developer are Copyright (C) Suvir Kumar. All Rights Reserved.
*
* Contributor(s):
*
* Suvir Kumar <[email protected]>
* Zoran Dimitrijevic
*
* My Blog is at www.talkkonnect.com
* The source code is hosted at github.com/talkkonnect
*
*
*/
package talkkonnect
import (
"bufio"
"bytes"
"fmt"
"log"
"runtime"
"strconv"
"time"
hd44780 "github.com/talkkonnect/go-hd44780"
"github.com/talkkonnect/volume-go"
)
func (b *Talkkonnect) cmdDisplayMenu() {
log.Println("debug: Delete Key Pressed Menu and Session Information Requested")
TTSEvent("displaymenu")
b.talkkonnectMenu("\x1b[0;44m") // add blue background to banner reference https://www.lihaoyi.com/post/BuildyourownCommandLinewithANSIescapecodes.html#background-colors
b.ParticipantLEDUpdate(true)
}
func (b *Talkkonnect) cmdChannelUp() {
log.Printf("debug: F1 pressed Channel Up (+) Requested\n")
b.ChannelUp()
}
func (b *Talkkonnect) cmdChannelDown() {
log.Printf("debug: F2 pressed Channel Down (-) Requested \n")
b.ChannelDown()
}
func (b *Talkkonnect) cmdMuteUnmute(subCommand string) {
log.Printf("debug: F3 pressed %v Speaker Requested \n", subCommand)
OrigMuted, err := volume.GetMuted(Config.Global.Software.Settings.OutputMuteControlDevice)
if err != nil {
log.Println("error: Unable to get current Muted/Unmuted State ", err)
} else {
if OrigMuted {
log.Println("debug: Originally Device is Muted")
} else {
log.Println("debug: Originally Device is Unmuted")
}
}
if subCommand == "toggle" {
if OrigMuted {
err := volume.Unmute(Config.Global.Software.Settings.OutputMuteControlDevice)
if err != nil {
log.Println("error: Unmuting Failed", err)
return
}
TTSEvent("unmutespeaker")
log.Println("info: Output Device Unmuted")
if Config.Global.Hardware.TargetBoard == "rpi" {
if LCDEnabled {
LcdText = [4]string{"nil", "nil", "nil", "UnMuted"}
LcdDisplay(LcdText, LCDRSPin, LCDEPin, LCDD4Pin, LCDD5Pin, LCDD6Pin, LCDD7Pin, LCDInterfaceType, LCDI2CAddress)
}
if OLEDEnabled {
oledDisplay(false, 6, 1, "Unmuted")
}
}
return
} else {
TTSEvent("mutespeaker")
err = volume.Mute(Config.Global.Software.Settings.OutputMuteControlDevice)
if err != nil {
log.Println("error: Muting Failed", err)
}
log.Println("info: Output Device Muted")
if Config.Global.Hardware.TargetBoard == "rpi" {
if LCDEnabled {
LcdText = [4]string{"nil", "nil", "nil", "Muted"}
LcdDisplay(LcdText, LCDRSPin, LCDEPin, LCDD4Pin, LCDD5Pin, LCDD6Pin, LCDD7Pin, LCDInterfaceType, LCDI2CAddress)
}
if OLEDEnabled {
oledDisplay(false, 6, 1, "Muted")
}
}
return
}
}
//force mute
if subCommand == "mute" {
TTSEvent("mutespeaker")
err = volume.Mute(Config.Global.Software.Settings.OutputMuteControlDevice)
if err != nil {
log.Println("error: Muting Failed ", err)
return
}
log.Println("info: Output Device Muted")
if Config.Global.Hardware.TargetBoard == "rpi" {
if LCDEnabled {
LcdText = [4]string{"nil", "nil", "nil", "Muted"}
LcdDisplay(LcdText, LCDRSPin, LCDEPin, LCDD4Pin, LCDD5Pin, LCDD6Pin, LCDD7Pin, LCDInterfaceType, LCDI2CAddress)
if OLEDEnabled {
oledDisplay(false, 6, 1, "Muted")
}
}
return
}
}
//force unmute
if subCommand == "unmute" {
err := volume.Unmute(Config.Global.Software.Settings.OutputMuteControlDevice)
TTSEvent("unmutespeaker")
if err != nil {
log.Println("error: Unmute Failed ", err)
return
}
log.Println("info: Output Device Unmuted")
if Config.Global.Hardware.TargetBoard == "rpi" {
if LCDEnabled {
LcdText = [4]string{"nil", "nil", "nil", "UnMuted"}
LcdDisplay(LcdText, LCDRSPin, LCDEPin, LCDD4Pin, LCDD5Pin, LCDD6Pin, LCDD7Pin, LCDInterfaceType, LCDI2CAddress)
}
if OLEDEnabled {
oledDisplay(false, 6, 1, "Unmuted")
}
}
return
}
}
func (b *Talkkonnect) cmdCurrentVolume() {
OrigVolume, err := volume.GetVolume(Config.Global.Software.Settings.OutputVolControlDevice)
if err != nil {
log.Printf("error: Unable to get current volume: %+v\n", err)
}
log.Printf("debug: F4 pressed Volume Level Requested\n")
log.Println("info: Volume Level is at", OrigVolume, "%")
TTSEvent("currentvolumelevel")
if Config.Global.Hardware.TargetBoard == "rpi" {
if LCDEnabled {
LcdText = [4]string{"nil", "nil", "nil", "Volume " + strconv.Itoa(OrigVolume)}
LcdDisplay(LcdText, LCDRSPin, LCDEPin, LCDD4Pin, LCDD5Pin, LCDD6Pin, LCDD7Pin, LCDInterfaceType, LCDI2CAddress)
}
if OLEDEnabled {
oledDisplay(false, 6, 1, "Volume "+strconv.Itoa(OrigVolume))
}
b.sevenSegment("localvolume", strconv.Itoa(OrigVolume))
}
}
func (b *Talkkonnect) cmdVolumeUp() {
log.Printf("debug: F5 pressed Volume UP (+) \n")
origVolume, err := volume.GetVolume(Config.Global.Software.Settings.OutputVolControlDevice)
if err != nil {
log.Printf("warn: unable to get original volume: %+v volume control will not work!\n", err)
return
}
if origVolume < 100 {
err := volume.IncreaseVolume(Config.Global.Hardware.IO.VolumeButtonStep.VolUpStep, Config.Global.Software.Settings.OutputVolControlDevice)
if err != nil {
log.Println("warn: F5 Increase Volume Failed! ", err)
}
origVolume, _ := volume.GetVolume(Config.Global.Software.Settings.OutputVolControlDevice)
log.Println("info: Volume UP (+) Now At ", origVolume, "%")
if Config.Global.Hardware.TargetBoard == "rpi" {
if LCDEnabled {
LcdText = [4]string{"nil", "nil", "nil", "Volume + " + strconv.Itoa(origVolume)}
LcdDisplay(LcdText, LCDRSPin, LCDEPin, LCDD4Pin, LCDD5Pin, LCDD6Pin, LCDD7Pin, LCDInterfaceType, LCDI2CAddress)
}
if OLEDEnabled {
oledDisplay(false, 6, 1, "Volume "+strconv.Itoa(origVolume))
}
b.sevenSegment("localvolume", strconv.Itoa(origVolume))
}
} else {
log.Println("debug: F5 Increase Volume")
log.Println("info: Already at Maximum Possible Volume")
if Config.Global.Hardware.TargetBoard == "rpi" {
if LCDEnabled {
LcdText = [4]string{"nil", "nil", "nil", "Max Vol"}
LcdDisplay(LcdText, LCDRSPin, LCDEPin, LCDD4Pin, LCDD5Pin, LCDD6Pin, LCDD7Pin, LCDInterfaceType, LCDI2CAddress)
}
if OLEDEnabled {
oledDisplay(false, 6, 1, "Max Vol")
}
b.sevenSegment("localvolume", "100")
}
}
TTSEvent("digitalvolumeup")
}
func (b *Talkkonnect) cmdVolumeDown() {
log.Printf("info: F6 pressed Volume Down (-) \n")
origVolume, err := volume.GetVolume(Config.Global.Software.Settings.OutputVolControlDevice)
if err != nil {
log.Printf("warn: unable to get original volume: %+v volume control will not work!\n", err)
return
}
if origVolume > 0 {
err := volume.IncreaseVolume(Config.Global.Hardware.IO.VolumeButtonStep.VolDownStep, Config.Global.Software.Settings.OutputVolControlDevice)
if err != nil {
log.Println("error: F6 Decrease Volume Failed! ", err)
}
origVolume, _ := volume.GetVolume(Config.Global.Software.Settings.OutputVolControlDevice)
log.Println("info: Volume Down (-) Now At ", origVolume, "%")
if Config.Global.Hardware.TargetBoard == "rpi" {
if LCDEnabled {
LcdText = [4]string{"nil", "nil", "nil", "Volume - " + strconv.Itoa(origVolume)}
LcdDisplay(LcdText, LCDRSPin, LCDEPin, LCDD4Pin, LCDD5Pin, LCDD6Pin, LCDD7Pin, LCDInterfaceType, LCDI2CAddress)
}
if OLEDEnabled {
oledDisplay(false, 6, 1, "Volume "+strconv.Itoa(origVolume))
}
b.sevenSegment("localvolume", strconv.Itoa(origVolume))
}
} else {
log.Println("debug: F6 Increase Volume Already")
log.Println("info: Already at Minimum Possible Volume")
if Config.Global.Hardware.TargetBoard == "rpi" {
if LCDEnabled {
LcdText = [4]string{"nil", "nil", "nil", "Min Vol"}
LcdDisplay(LcdText, LCDRSPin, LCDEPin, LCDD4Pin, LCDD5Pin, LCDD6Pin, LCDD7Pin, LCDInterfaceType, LCDI2CAddress)
}
if OLEDEnabled {
oledDisplay(false, 6, 1, "Min Vol")
}
b.sevenSegment("localvolume", "0")
}
}
TTSEvent("digitalvolumedown")
}
func (b *Talkkonnect) cmdListServerChannels() {
log.Printf("debug: F7 pressed Channel List Requested \n")
TTSEvent("listserverchannels")
//List Server Channels from ChannelsList[]
b.ParticipantLEDUpdate(true)
}
func (b *Talkkonnect) cmdStartTransmitting() {
log.Printf("debug: F8 pressed TX Mode Requested (Start Transmitting) \n")
log.Println("info: Start Transmitting")
TTSEvent("starttransmitting")
if IsPlayStream {
IsPlayStream = false
NowStreaming = false
var eventSound EventSoundStruct = findEventSound("stream")
if eventSound.Enabled {
if s, err := strconv.ParseFloat(eventSound.Volume, 32); err == nil {
b.playIntoStream(eventSound.FileName, float32(s))
}
}
}
if !b.IsTransmitting {
time.Sleep(100 * time.Millisecond)
b.TransmitStart()
} else {
log.Println("error: Already in Transmitting Mode")
}
}
func (b *Talkkonnect) cmdStopTransmitting() {
log.Printf("debug: F9 pressed RX Mode Request (Stop Transmitting) \n")
log.Println("info: Stop Transmitting")
TTSEvent("stoptransmitting")
if IsPlayStream {
IsPlayStream = false
NowStreaming = false
var eventSound EventSoundStruct = findEventSound("stream")
if eventSound.Enabled {
if s, err := strconv.ParseFloat(eventSound.Volume, 32); err == nil {
b.playIntoStream(eventSound.FileName, float32(s))
}
}
}
if b.IsTransmitting {
time.Sleep(100 * time.Millisecond)
b.TransmitStop(true)
} else {
log.Println("info: Not Already Transmitting")
}
}
func (b *Talkkonnect) cmdListOnlineUsers() {
log.Printf("debug: F10 pressed Online User(s) in Current Channel Requested \n")
log.Println("info: F10 Online User(s) in Current Channel")
TTSEvent("listonlineusers")
log.Printf("info: Channel %#v Has %d Online User(s)", b.Client.Self.Channel.Name, len(b.Client.Self.Channel.Users))
b.ListUsers()
b.ParticipantLEDUpdate(true)
}
func (b *Talkkonnect) cmdPlayback() {
log.Printf("debug: F11 pressed Start/Stop Stream Stream into Current Channel Requested \n")
log.Println("info: Stream into Current Channel")
b.BackLightTimer()
TTSEvent("playstream")
if b.IsTransmitting {
log.Println("alert: talkkonnect was already transmitting will now stop transmitting and start the stream")
b.TransmitStop(false)
}
IsPlayStream = !IsPlayStream
NowStreaming = IsPlayStream
if IsPlayStream && Config.Global.Software.Settings.StreamSendMessage {
b.SendMessage(fmt.Sprintf("%s Streaming", b.Username), false)
}
var eventSound EventSoundStruct = findEventSound("stream")
if eventSound.Enabled {
if s, err := strconv.ParseFloat(eventSound.Volume, 32); err == nil {
go b.playIntoStream(eventSound.FileName, float32(s))
}
}
}
func (b *Talkkonnect) cmdGPSPosition() {
log.Printf("debug: F12 pressed \n")
log.Println("info: GPS details requested")
TTSEvent("requestgpsposition")
var i int = 0
var tries int = 10
for i = 0; i < tries; i++ {
goodGPSRead, err := getGpsPosition(3)
if err != nil {
log.Println("error: GPS Function Returned Error Message", err)
if Config.Global.Hardware.GPS.Enabled {
if Config.Global.Hardware.GPS.GpsDiagSounds {
eventSound := findEventSound("gpsDeviceError")
if eventSound.Enabled {
if v, err := strconv.Atoi(eventSound.Volume); err == nil {
localMediaPlayer(eventSound.FileName, v, eventSound.Blocking, 0, 1)
log.Printf("debug: Playing a GPS diagnostic sound")
}
}
}
}
if Config.Global.Hardware.GPS.Enabled {
if Config.Global.Hardware.LCD.Enabled && (Config.Global.Hardware.GPS.GpsDisplayShow || Config.Global.Hardware.Traccar.DeviceScreenEnabled) {
LcdText = [4]string{"nil", "GPS ERR1", "GPS Device Error", ""}
go hd44780.LcdDisplay(LcdText, LCDRSPin, LCDEPin, LCDD4Pin, LCDD5Pin, LCDD6Pin, LCDD7Pin, LCDInterfaceType, LCDI2CAddress)
}
if Config.Global.Hardware.OLED.Enabled {
oledDisplay(false, 4, 1, "GPS ERR1 "+time.Now().Format("15:04:05"))
oledDisplay(false, 5, 1, "GPS Device Error")
oledDisplay(false, 6, 1, "")
oledDisplay(false, 7, 1, "")
}
}
break
}
if goodGPSRead {
break
}
}
if i == tries {
log.Println("warn: Could Not Get a Good GPS Read")
if Config.Global.Hardware.GPS.Enabled {
if Config.Global.Hardware.GPS.GpsDiagSounds {
eventSound := findEventSound("gpsNoGoodRead")
if eventSound.Enabled {
if v, err := strconv.Atoi(eventSound.Volume); err == nil {
localMediaPlayer(eventSound.FileName, v, eventSound.Blocking, 0, 1)
log.Printf("debug: Playing a GPS diagnostic sound")
}
}
}
}
//
if Config.Global.Hardware.GPS.Enabled {
if Config.Global.Hardware.LCD.Enabled && (Config.Global.Hardware.GPS.GpsDisplayShow || Config.Global.Hardware.Traccar.DeviceScreenEnabled) {
LcdText = [4]string{"nil", "GPS ERR2", "No Good GPS Reading", ""}
go hd44780.LcdDisplay(LcdText, LCDRSPin, LCDEPin, LCDD4Pin, LCDD5Pin, LCDD6Pin, LCDD7Pin, LCDInterfaceType, LCDI2CAddress)
}
if Config.Global.Hardware.OLED.Enabled {
oledDisplay(false, 4, 1, "GPS ERR2 "+time.Now().Format("15:04:05"))
oledDisplay(false, 5, 1, "No Good GPS Reading")
oledDisplay(false, 6, 1, "")
oledDisplay(false, 7, 1, "")
}
}
}
}
func (b *Talkkonnect) cmdQuitTalkkonnect() {
log.Printf("debug: Ctrl-C Terminate Program Requested \n")
duration := time.Since(StartTime)
log.Printf("info: Talkkonnect Now Running For %v \n", secondsToHuman(int(duration.Seconds())))
b.sevenSegment("bye", "")
TTSEvent("quittalkkonnect")
CleanUp()
}
func (b *Talkkonnect) cmdDebugStacktrace() {
buf := make([]byte, 1<<16)
stackSize := runtime.Stack(buf, true)
var debug bytes.Buffer
debug.WriteString(string(buf[0:stackSize]))
scanner := bufio.NewScanner(&debug)
var line int = 1
log.Println("debug: Pressed Ctrl-D")
log.Println("info: Stack Dump Requested")
for scanner.Scan() {
log.Printf("debug: line: %d %s\n", line, scanner.Text())
line++
}
goStreamStats()
}
func (b *Talkkonnect) cmdSendEmail() {
log.Printf("debug: Ctrl-E Pressed \n")
log.Println("info: Send Email Requested")
var i int = 0
var tries int = 10
for i = 0; i < tries; i++ {
goodGPSRead, err := getGpsPosition(3)
if err != nil {
log.Println("error: GPS Function Returned Error Message", err)
break
}
if goodGPSRead {
break
}
}
if i == tries {
log.Println("warn: Could Not Get a Good GPS Read")
return
}
TTSEvent("sendemail")
if Config.Global.Software.SMTP.Enabled {
emailMessage := fmt.Sprintf(Config.Global.Software.SMTP.Message + "\n")
emailMessage = emailMessage + fmt.Sprintf("Ident: %s \n", b.Ident)
emailMessage = emailMessage + fmt.Sprintf("Mumble Username: %s \n", b.Username)
if Config.Global.Software.SMTP.GpsDateTime {
emailMessage = emailMessage + fmt.Sprintf("Date "+GNSSData.Date+" UTC Time "+GNSSData.Time+"\n")
}
if Config.Global.Software.SMTP.GpsLatLong {
emailMessage = emailMessage + fmt.Sprintf("Latitude "+strconv.FormatFloat(GNSSData.Lattitude, 'f', 6, 64)+" Longitude "+strconv.FormatFloat(GNSSData.Longitude, 'f', 6, 64)+"\n")
}
if Config.Global.Software.SMTP.GoogleMapsURL {
emailMessage = emailMessage + "http://www.google.com/maps/place/" + strconv.FormatFloat(GNSSData.Lattitude, 'f', 6, 64) + "," + strconv.FormatFloat(GNSSData.Longitude, 'f', 6, 64)
}
err := sendviagmail(Config.Global.Software.SMTP.Username, Config.Global.Software.SMTP.Password, Config.Global.Software.SMTP.Receiver, Config.Global.Software.SMTP.Subject, emailMessage)
if err != nil {
log.Println("error: Error from Email Module: ", err)
}
} else {
log.Println("warning: Sending Email Disabled in Config")
}
}
func (b *Talkkonnect) cmdConnPreviousServer() {
log.Printf("debug: Ctrl-F Pressed \n")
log.Println("info: Previous Server Requested")
TTSEvent("previousserver")
if AccountCount > 1 {
if AccountIndex > 0 {
AccountIndex--
} else {
AccountIndex = AccountCount - 1
}
modifyXMLTagServerHopping(ConfigXMLFile, AccountIndex)
}
}
func (b *Talkkonnect) cmdClearScreen() {
reset()
log.Printf("debug: Ctrl-L Pressed Cleared Screen \n")
if Config.Global.Hardware.TargetBoard == "rpi" {
if LCDEnabled {
LcdText = [4]string{"nil", "nil", "nil", "nil"}
LcdDisplay(LcdText, LCDRSPin, LCDEPin, LCDD4Pin, LCDD5Pin, LCDD6Pin, LCDD7Pin, LCDInterfaceType, LCDI2CAddress)
}
if OLEDEnabled {
Oled.DisplayOn()
LCDIsDark = false
oledDisplay(true, 0, 0, "")
}
}
}
func (b *Talkkonnect) cmdRadioChannelMove(command string) {
log.Printf("debug: Ctrl-M Radio Channel %v\n", command)
if Config.Global.Hardware.TargetBoard == "rpi" {
if Config.Global.Hardware.Radio.Enabled {
if !(Config.Global.Hardware.Radio.Sa818.Enabled && Config.Global.Hardware.Radio.Sa818.Serial.Enabled) {
log.Println("error: Radio Module Not Configured Properly")
} else {
if command == "Up" {
go radioChannelIncrement("up")
}
if command == "Down" {
go radioChannelIncrement("down")
}
}
}
}
}
func (b *Talkkonnect) cmdPingServers() {
log.Printf("debug: Ctrl-O Pressed \n")
log.Println("info: Ping Servers")
TTSEvent("pingservers")
b.pingServers()
}
func (b *Talkkonnect) cmdConnNextServer() {
log.Printf("debug: Ctrl-N Pressed \n")
log.Println("info: Next Server Requested Killing This Session, talkkonnect should be restarted by systemd")
TTSEvent("nextserver")
if AccountCount > 1 {
if AccountIndex < AccountCount-1 {
AccountIndex++
} else {
AccountIndex = 0
}
modifyXMLTagServerHopping(ConfigXMLFile, AccountIndex)
}
}
func (b *Talkkonnect) cmdAudioTrafficRecord() {
log.Printf("debug: Ctrl-I Pressed \n")
log.Println("info: Traffic Recording Requested")
if !Config.Global.Hardware.AudioRecordFunction.Enabled {
log.Println("warn: Audio Recording Function Not Enabled")
}
if Config.Global.Hardware.AudioRecordFunction.RecordMode != "traffic" {
log.Println("warn: Traffic Recording Not Enabled")
}
if Config.Global.Hardware.AudioRecordFunction.Enabled {
if Config.Global.Hardware.AudioRecordFunction.RecordMode == "traffic" {
if Config.Global.Hardware.AudioRecordFunction.RecordFromOutput != "" {
if Config.Global.Hardware.AudioRecordFunction.RecordSoft == "sox" {
go AudioRecordTraffic()
if Config.Global.Hardware.TargetBoard == "rpi" {
if LCDEnabled {
LcdText = [4]string{"nil", "nil", "Traffic Audio Rec ->", "nil"} // 4 or 3
LcdDisplay(LcdText, LCDRSPin, LCDEPin, LCDD4Pin, LCDD5Pin, LCDD6Pin, LCDD7Pin, LCDInterfaceType, LCDI2CAddress)
}
if OLEDEnabled {
oledDisplay(false, 5, 1, "Traffic Audio Rec ->") // 6 or 5
}
}
} else {
log.Println("info: Traffic Recording is not Enabled or sox Encountered Problems")
}
}
}
}
}
func (b *Talkkonnect) cmdAudioMicRecord() {
log.Printf("debug: Ctrl-J Pressed \n")
log.Println("info: Ambient (Mic) Recording Requested")
if !Config.Global.Hardware.AudioRecordFunction.Enabled {
log.Println("warn: Audio Recording Function Not Enabled")
}
if Config.Global.Hardware.AudioRecordFunction.RecordMode != "ambient" {
log.Println("warn: Ambient (Mic) Recording Not Enabled")
}
if Config.Global.Hardware.AudioRecordFunction.Enabled {
if Config.Global.Hardware.AudioRecordFunction.RecordMode == "ambient" {
if Config.Global.Hardware.AudioRecordFunction.RecordFromInput != "" {
if Config.Global.Hardware.AudioRecordFunction.RecordSoft == "sox" {
go AudioRecordAmbient()
if Config.Global.Hardware.TargetBoard == "rpi" {
if LCDEnabled {
LcdText = [4]string{"nil", "nil", "Mic Audio Rec ->", "nil"} // 4 or 3
LcdDisplay(LcdText, LCDRSPin, LCDEPin, LCDD4Pin, LCDD5Pin, LCDD6Pin, LCDD7Pin, LCDInterfaceType, LCDI2CAddress)
}
if OLEDEnabled {
oledDisplay(false, 5, 1, "Mic Audio Rec ->") // 6 or 5
}
}
} else {
log.Println("error: Ambient (Mic) Recording is not Enabled or sox Encountered Problems")
}
}
}
}
}
func (b *Talkkonnect) cmdAudioMicTrafficRecord() {
log.Printf("debug: Ctrl-K Pressed \n")
log.Println("info: Recording (Traffic and Mic) Requested")
if !Config.Global.Hardware.AudioRecordFunction.Enabled {
log.Println("warn: Audio Recording Function Not Enabled")
}
if Config.Global.Hardware.AudioRecordFunction.RecordMode != "combo" {
log.Println("warn: Combo Recording (Traffic and Mic) Not Enabled")
}
if Config.Global.Hardware.AudioRecordFunction.Enabled {
if Config.Global.Hardware.AudioRecordFunction.RecordMode == "combo" {
if Config.Global.Hardware.AudioRecordFunction.RecordFromInput != "" {
if Config.Global.Hardware.AudioRecordFunction.RecordSoft == "sox" {
go AudioRecordCombo()
if Config.Global.Hardware.TargetBoard == "rpi" {
if LCDEnabled {
LcdText = [4]string{"nil", "nil", "Combo Audio Rec ->", "nil"} // 4 or 3
LcdDisplay(LcdText, LCDRSPin, LCDEPin, LCDD4Pin, LCDD5Pin, LCDD6Pin, LCDD7Pin, LCDInterfaceType, LCDI2CAddress)
}
if OLEDEnabled {
oledDisplay(false, 5, 1, "Combo Audio Rec ->") // 6 or 5
}
}
} else {
log.Println("error: Combo Recording (Traffic and Mic) is not Enabled or sox Encountered Problems")
}
}
}
}
}
func (b *Talkkonnect) cmdPanicSimulation() {
if !(IsConnected) {
return
}
b.BackLightTimer()
log.Printf("debug: Ctrl-P Pressed \n")
log.Println("info: Panic Button Start/Stop Simulation Requested")
TTSEvent("panicsimulation")
if Config.Global.Hardware.PanicFunction.Enabled {
if b.IsTransmitting {
b.TransmitStop(false)
} else {
b.IsTransmitting = true
b.SendMessage(Config.Global.Hardware.PanicFunction.Message, Config.Global.Hardware.PanicFunction.RecursiveSendMessage)
}
if Config.Global.Hardware.PanicFunction.SendIdent {
b.SendMessage(fmt.Sprintf("My Username is %s and Ident is %s", b.Username, b.Ident), Config.Global.Hardware.PanicFunction.RecursiveSendMessage)
}
if Config.Global.Hardware.PanicFunction.SendGpsLocation {
var i int = 0
var tries int = 10
for i = 0; i < tries; i++ {
goodGPSRead, err := getGpsPosition(3)
if err != nil {
log.Println("error: GPS Function Returned Error Message", err)
break
}
if goodGPSRead {
break
}
}
if i == tries {
log.Println("warn: Could Not Get a Good GPS Read")
}
if goodGPSRead && i != tries {
log.Println("info: Sending GPS Info My Message")
gpsMessage := "My GPS Coordinates are " + fmt.Sprintf(" Latitude "+strconv.FormatFloat(GNSSData.Lattitude, 'f', 6, 64)) + fmt.Sprintf(" Longitude "+strconv.FormatFloat(GNSSData.Longitude, 'f', 6, 64))
b.SendMessage(gpsMessage, Config.Global.Hardware.PanicFunction.RecursiveSendMessage)
}
IsPlayStream = true
b.playIntoStream(Config.Global.Hardware.PanicFunction.FilenameAndPath, Config.Global.Hardware.PanicFunction.Volume)
if Config.Global.Hardware.TargetBoard == "rpi" {
if LCDEnabled {
LcdText = [4]string{"nil", "nil", "nil", "Panic Message Sent!"}
LcdDisplay(LcdText, LCDRSPin, LCDEPin, LCDD4Pin, LCDD5Pin, LCDD6Pin, LCDD7Pin, LCDInterfaceType, LCDI2CAddress)
}
if OLEDEnabled {
oledDisplay(false, 6, 1, "Panic Message Sent!")
}
}
if Config.Global.Hardware.PanicFunction.TxLockEnabled && Config.Global.Hardware.PanicFunction.TxLockTimeOutSecs > 0 {
b.TxLockTimer()
}
// New. Send email after Panic Event //
if Config.Global.Hardware.PanicFunction.PMailEnabled {
b.cmdSendEmail()
log.Println("info: Sending Panic Alert Email To Predefined Email Address")
}
//
// New. Record ambient audio on Panic Event if recording is enabled
if Config.Global.Hardware.AudioRecordFunction.Enabled {
log.Println("info: Running sox for Audio Recording...")
AudioRecordAmbient()
}
//
} else {
log.Println("warn: Panic Function Disabled in Config")
}
IsPlayStream = false
b.IsTransmitting = false
if Config.Global.Hardware.PanicFunction.PLowProfile {
GPIOOutAll("led/relay", "off")
log.Println("info: Low Profile Lights Option is Enabled. Turning All Leds Off During Panic Event")
if LCDEnabled {
log.Println("info: Low Profile Lights is Enabled. Turning Off Display During Panic Event")
LcdText = [4]string{"", "", "", ""}
LcdDisplay(LcdText, LCDRSPin, LCDEPin, LCDD4Pin, LCDD5Pin, LCDD6Pin, LCDD7Pin, LCDInterfaceType, LCDI2CAddress)
}
if OLEDEnabled {
oledDisplay(true, 0, 0, "")
}
}
}
}
func (b *Talkkonnect) cmdRepeatTxLoop() {
log.Printf("debug: Ctrl-R Pressed \n")
log.Println("info: Repeat TX Test Requested")
isrepeattx = !isrepeattx
go b.repeatTx()
}
func (b *Talkkonnect) cmdScanChannels() {
log.Printf("debug: Ctrl-S Pressed fgrom \n")
log.Println("info: Scanning Channels")
TTSEvent("startscanning")
b.Scan()
}
func cmdThanks() {
log.Printf("debug: Ctrl-T Pressed \n")
log.Println("info: Thanks and Acknowledgements Screen Request ")
talkkonnectAcknowledgements("\x1b[0;44m") // add blue background to banner reference https://www.lihaoyi.com/post/BuildyourownCommandLinewithANSIescapecodes.html#background-colors
}
func (b *Talkkonnect) cmdShowUptime() {
log.Printf("debug: Ctrl-U Pressed \n")
log.Println("info: Talkkonnect Uptime Request ")
duration := time.Since(StartTime)
log.Printf("info: Talkkonnect Now Running For %v \n", secondsToHuman(int(duration.Seconds())))
}
func (b *Talkkonnect) cmdDisplayVersion() {
log.Printf("debug: Ctrl-V Pressed \n")
log.Println("info: Talkkonnect Version Request ")
releasedVersion := checkGitHubVersion()
if talkkonnectVersion != releasedVersion {
log.Printf("warn: Ver %v Rel %v (Different Ver %v Available!)\n", talkkonnectVersion, talkkonnectReleased, releasedVersion)
} else {
log.Printf("info: Ver %v Rel %v (Latest Release)\n", talkkonnectVersion, talkkonnectReleased)
}
}
func (b *Talkkonnect) cmdDumpXMLConfig() {
log.Printf("debug: Ctrl-X Pressed \n")
log.Println("info: Print XML Config " + ConfigXMLFile)
TTSEvent("printxmlconfig")
printxmlconfig()
}
func (b *Talkkonnect) cmdPlayRepeaterTone() {
log.Printf("debug: Ctrl-G Pressed \n")
log.Println("info: Play Repeater Tone on Speaker and Simulate RX Signal")
b.BackLightTimer()
if Config.Global.Software.Sounds.RepeaterTone.Enabled {
b.PlayTone(Config.Global.Software.Sounds.RepeaterTone.ToneFrequencyHz, Config.Global.Software.Sounds.RepeaterTone.ToneDurationSec, "local", true)
} else {
log.Println("warn: Repeater Tone Disabled by Config")
}
}
func (b *Talkkonnect) cmdLiveReload() {
log.Printf("debug: Ctrl-B Pressed \n")
log.Println("info: XML Config Live Reload")
err := readxmlconfig(ConfigXMLFile, true)
if err != nil {
message := err.Error()
FatalCleanUp(message)
}
}
func cmdSanityCheck() {
log.Printf("debug: Ctrl-H Pressed \n")
log.Println("info: XML Sanity Checker")
CheckConfigSanity(false)
}