forked from talkkonnect/talkkonnect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxmlparser.go
1741 lines (1613 loc) · 78.8 KB
/
xmlparser.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
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* 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
*
* xmlparser.go -> talkkonnect functionality to read from XML file and populate global variables
*/
package talkkonnect
import (
"encoding/xml"
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
"path/filepath"
"strconv"
"strings"
"time"
"github.com/talkkonnect/colog"
goled "github.com/talkkonnect/go-oled-i2c"
"github.com/talkkonnect/gumble/gumble"
"github.com/talkkonnect/gumble/gumbleffmpeg"
"github.com/talkkonnect/sa818"
"golang.org/x/sys/unix"
)
type ConfigStruct struct {
XMLName xml.Name `xml:"document"`
Accounts struct {
Account []struct {
Name string `xml:"name,attr"`
Default bool `xml:"default,attr"`
ServerAndPort string `xml:"serverandport"`
UserName string `xml:"username"`
Password string `xml:"password"`
Insecure bool `xml:"insecure"`
Register bool `xml:"register"`
Certificate string `xml:"certificate"`
Channel string `xml:"channel"`
Ident string `xml:"ident"`
TokensEnabled bool `xml:"enabled,attr"`
Tokens struct {
Token []string `xml:"token"`
} `xml:"tokens"`
Voicetargets struct {
ID []struct {
Value uint32 `xml:"value,attr"`
IsCurrent bool `xml:"iscurrent"`
Users struct {
User []string `xml:"user"`
} `xml:"users"`
Channels struct {
Channel []struct {
Name string `xml:"name"`
Recursive bool `xml:"recursive"`
Links bool `xml:"links"`
Group string `xml:"group"`
} `xml:"channel"`
} `xml:"channels"`
} `xml:"id"`
} `xml:"voicetargets"`
} `xml:"account"`
} `xml:"accounts"`
Global struct {
Software struct {
Settings struct {
SingleInstance bool `xml:"singleinstance"`
OutputDevice string `xml:"outputdevice"`
OutputDeviceShort string `xml:"outputdeviceshort"`
OutputVolControlDevice string `xml:"outputvolcontroldevice"`
OutputMuteControlDevice string `xml:"outputmutecontroldevice"`
LogFilenameAndPath string `xml:"logfilenameandpath"`
Logging string `xml:"logging"`
Loglevel string `xml:"loglevel"`
CancellableStream bool `xml:"cancellablestream"`
StreamOnStart bool `xml:"streamonstart"`
StreamOnStartAfter time.Duration `xml:"streamonstartafter"`
StreamSendMessage bool `xml:"streamsendmessage"`
TXOnStart bool `xml:"txonstart"`
TXOnStartAfter time.Duration `xml:"txonstartafter"`
RepeatTXTimes int `xml:"repeattxtimes"`
RepeatTXDelay time.Duration `xml:"repeattxdelay"`
SimplexWithMute bool `xml:"simplexwithmute"`
TxCounter bool `xml:"txcounter"`
NextServerIndex int `xml:"nextserverindex"`
TXLockOut bool `xml:"txlockout"`
} `xml:"settings"`
AutoProvisioning struct {
Enabled bool `xml:"enabled,attr"`
TkID string `xml:"tkid"`
URL string `xml:"url"`
SaveFilePath string `xml:"savefilepath"`
SaveFilename string `xml:"savefilename"`
} `xml:"autoprovisioning"`
Beacon struct {
Enabled bool `xml:"enabled,attr"`
BeaconTimerSecs int `xml:"beacontimersecs"`
BeaconFileAndPath string `xml:"beaconfileandpath"`
Volume float32 `xml:"volume"`
} `xml:"beacon"`
TTS struct {
Enabled bool `xml:"enabled,attr"`
Volumelevel int `xml:"volumelevel"`
Language string `xml:"language,attr"`
Sound []struct {
Action string `xml:"action,attr"`
File string `xml:"file,attr"`
Blocking bool `xml:"blocking,attr"`
Enabled bool `xml:"enabled,attr"`
} `xml:"sound"`
} `xml:"tts"`
SMTP struct {
Enabled bool `xml:"enabled,attr"`
Username string `xml:"username"`
Password string `xml:"password"`
Receiver string `xml:"receiver"`
Subject string `xml:"subject"`
Message string `xml:"message"`
GpsDateTime bool `xml:"gpsdatetime"`
GpsLatLong bool `xml:"gpslatlong"`
GoogleMapsURL bool `xml:"googlemapsurl"`
} `xml:"smtp"`
Sounds struct {
Sound []struct {
Event string `xml:"event,attr"`
File string `xml:"file,attr"`
Volume string `xml:"volume,attr"`
Blocking bool `xml:"blocking,attr"`
Enabled bool `xml:"enabled,attr"`
} `xml:"sound"`
Input struct {
Enabled bool `xml:"enabled,attr"`
Sound []struct {
Event string `xml:"event,attr"`
File string `xml:"file,attr"`
Enabled bool `xml:"enabled,attr"`
} `xml:"sound"`
} `xml:"input"`
RepeaterTone struct {
Enabled bool `xml:"enabled,attr"`
ToneFrequencyHz int `xml:"tonefrequencyhz"`
ToneDurationSec float32 `xml:"tonedurationsec"`
} `xml:"repeatertone"`
} `xml:"sounds"`
TxTimeOut struct {
Enabled bool `xml:"enabled,attr"`
TxTimeOutSecs int `xml:"txtimeoutsecs"`
} `xml:"txtimeout"`
RemoteControl struct {
XMLName xml.Name `xml:"remotecontrol"`
HTTP struct {
Enabled bool `xml:"enabled,attr"`
ListenPort string `xml:"listenport,attr"`
Command []struct {
Action string `xml:"action,attr"`
Funcname string `xml:"funcname,attr"`
Funcparamname string `xml:"funcparamname,attr"`
Message string `xml:"message,attr"`
Enabled bool `xml:"enabled,attr"`
} `xml:"command"`
} `xml:"http"`
MQTT struct {
Enabled bool `xml:"enabled,attr"`
Settings struct {
MQTTEnabled bool `xml:"enabled,attr"`
MQTTSubTopic string `xml:"mqttsubtopic"`
MQTTPubTopic string `xml:"mqttpubtopic"`
MQTTBroker string `xml:"mqttbroker"`
MQTTPassword string `xml:"mqttpassword"`
MQTTUser string `xml:"mqttuser"`
MQTTId string `xml:"mqttid"`
MQTTCleansess bool `xml:"cleansess"`
MQTTQos byte `xml:"qos"`
MQTTNum int `xml:"num"`
MQTTPayload string `xml:"payload"`
MQTTAction string `xml:"action"`
MQTTStore string `xml:"store"`
MQTTRetained bool `xml:"retained"`
MQTTAttentionBlinkTimes int `xml:"attentionblinktimes"`
MQTTAttentionBlinkmsecs int `xml:"attentionblinkmsecs"`
Pubpayload struct {
Mqtt []struct {
Item string `xml:"item,attr"`
Payload string `xml:"payload,attr"`
Enabled bool `xml:"enabled,attr"`
} `xml:"mqtt"`
} `xml:"pubpayload"`
} `xml:"settings"`
Commands struct {
Command []struct {
Action string `xml:"action,attr"`
Message string `xml:"message,attr"`
Enabled bool `xml:"enabled,attr"`
} `xml:"command"`
} `xml:"commands"`
} `xml:"mqtt"`
}
PrintVariables struct {
PrintAccount bool `xml:"printaccount"`
PrintSystemSettings bool `xml:"printsystemsettings"`
PrintProvisioning bool `xml:"printprovisioning"`
PrintBeacon bool `xml:"printbeacon"`
PrintTTS bool `xml:"printtts"`
PrintSMTP bool `xml:"printsmtp"`
PrintSounds bool `xml:"printsounds"`
PrintTxTimeout bool `xml:"printtxtimeout"`
PrintHTTPAPI bool `xml:"printhttpapi"`
PrintMQTT bool `xml:"printmqtt"`
PrintTTSMessages bool `xml:"printttsmessages"`
PrintIgnoreUser bool `xml:"printignoreuser"`
PrintHardware bool `xml:"printhardware"`
PrintGPIOExpander bool `xml:"printgpioexpander"`
PrintMax7219 bool `xml:"printmax7219"`
PrintPins bool `xml:"printpins"`
PrintRotary bool `xml:"printrotary"`
PrintPulse bool `xml:"printpulse"`
PrintVolumeButtonStep bool `xml:"printvolumebuttonstep"`
PrintHeartBeat bool `xml:"printheartbeat"`
PrintComment bool `xml:"printcomment"`
PrintLCD bool `xml:"printlcd"`
PrintOLED bool `xml:"printoled"`
PrintGPS bool `xml:"printgps"`
PrintTraccar bool `xml:"printtraccar"`
PrintPanic bool `xml:"printpanic"`
PrintUSBKeyboard bool `xml:"printusbkeyboard"`
PrintAudioRecord bool `xml:"printaudiorecord"`
PrintKeyboardMap bool `xml:"printkeyboardmap"`
PrintRadioModule bool `xml:"printradiomodule"`
PrintMultimedia bool `xml:"printmultimedia"`
} `xml:"printvariables"`
TTSMessages struct {
Enabled bool `xml:"enabled,attr"`
TTSLanguage string `xml:"ttslanguage"`
TTSMessageFromTag bool `xml:"ttsmessagefromtag"`
TTSTone struct {
ToneEnabled bool `xml:"enabled,attr"`
ToneFile string `xml:"file,attr"`
ToneVolume int `xml:"volume,attr"`
} `xml:"ttstone"`
Blocking bool `xml:"localblocking"`
TTSSoundDirectory string `xml:"ttssounddirectory"`
LocalPlay bool `xml:"localplay"`
PlayIntoStream bool `xml:"playintostream"`
SpeakVolumeIntoStream int `xml:"speakvolumeintostream"`
PlayVolumeIntoStream float32 `xml:"playvolumeintostream"`
GPIO struct {
Name string `xml:"name,attr"`
Enabled bool `xml:"enabled,attr"`
} `xml:"gpio"`
PreDelay struct {
Value time.Duration `xml:"value,attr"`
Enabled bool `xml:"enabled,attr"`
} `xml:"predelay"`
PostDelay struct {
Value time.Duration `xml:"value,attr"`
Enabled bool `xml:"enabled,attr"`
} `xml:"postdelay"`
} `xml:"ttsmessages"`
IgnoreUser struct {
IgnoreUserEnabled bool `xml:"enabled,attr"`
IgnoreUserRegex string `xml:"ignoreuserregex"`
} `xml:"ignoreuser"`
} `xml:"software"`
Hardware struct {
TargetBoard string `xml:"targetboard,attr"`
LedStripEnabled bool `xml:"ledstripenabled"`
VoiceActivityTimermsecs time.Duration `xml:"voiceactivitytimermsecs"`
IO struct {
GPIOExpander struct {
Enabled bool `xml:"enabled,attr"`
Chip []struct {
ID int `xml:"id,attr"`
I2Cbus uint8 `xml:"i2cbus,attr"`
MCP23017Device uint8 `xml:"mcp23017device,attr"`
Enabled bool `xml:"enabled,attr"`
} `xml:"chip"`
} `xml:"gpioexpander"`
Max7219 struct {
Enabled bool `xml:"enabled,attr"`
Max7219Cascaded int `xml:"max7219cascaded,attr"`
SPIBus int `xml:"spibus,attr"`
SPIDevice int `xml:"spidevice,attr"`
Brightness byte `xml:"brightness,attr"`
} `xml:"max7219"`
Pins struct {
Pin []struct {
Direction string `xml:"direction,attr"`
Device string `xml:"device,attr"`
Name string `xml:"name,attr"`
PinNo uint `xml:"pinno,attr"`
Type string `xml:"type,attr"`
ID int `xml:"chipid,attr"`
Inverted bool `xml:"inverted,attr"`
Enabled bool `xml:"enabled,attr"`
} `xml:"pin"`
} `xml:"pins"`
RotaryEncoder struct {
Enabled bool `xml:"enabled,attr"`
Control []struct {
Function string `xml:"function,attr"`
Enabled bool `xml:"enabled,attr"`
} `xml:"control"`
} `xml:"rotaryencoder"`
Pulse struct {
Leading time.Duration `xml:"leadingmsecs,attr"`
Pulse time.Duration `xml:"pulsemsecs,attr"`
Trailing time.Duration `xml:"trailingmsecs,attr"`
} `xml:"pulse"`
VolumeButtonStep struct {
VolUpStep int `xml:"volupstep"`
VolDownStep int `xml:"voldownstep"`
} `xml:"volumebuttonstep"`
} `xml:"io"`
HeartBeat struct {
Enabled bool `xml:"enabled,attr"`
LEDPin string `xml:"heartbeatledpin"`
Periodmsecs int `xml:"periodmsecs"`
LEDOnmsecs int `xml:"ledonmsecs"`
LEDOffmsecs int `xml:"ledoffmsecs"`
} `xml:"heartbeat"`
Comment struct {
CommentButtonPin string `xml:"commentbuttonpin"`
CommentMessageOff string `xml:"commentmessageoff"`
CommentMessageOn string `xml:"commentmessageon"`
} `xml:"comment"`
LCD struct {
Enabled bool `xml:"enabled,attr"`
InterfaceType string `xml:"lcdinterfacetype"`
I2CAddress uint8 `xml:"lcdi2caddress"`
BacklightTimerEnabled bool `xml:"lcdbacklighttimerenabled"`
BackLightTimeoutSecs int `xml:"lcdbacklighttimeoutsecs"`
BackLightLEDPin string `xml:"lcdbacklightpin"`
RsPin int `xml:"lcdrspin"`
EPin int `xml:"lcdepin"`
D4Pin int `xml:"lcdd4pin"`
D5Pin int `xml:"lcdd5pin"`
D6Pin int `xml:"lcdd6pin"`
D7Pin int `xml:"lcdd7pin"`
} `xml:"lcd"`
OLED struct {
Enabled bool `xml:"enabled,attr"`
InterfaceType string `xml:"oledinterfacetype"`
DisplayRows int `xml:"oleddisplayrows"`
DisplayColumns uint8 `xml:"oleddisplaycolumns"`
DefaultI2CBus int `xml:"oleddefaulti2cbus"`
DefaultI2CAddress uint8 `xml:"oleddefaulti2caddress"`
ScreenWidth int `xml:"oledscreenwidth"`
ScreenHeight int `xml:"oledscreenheight"`
CommandColumnAddressing int `xml:"oledcommandcolumnaddressing"`
AddressBasePageStart int `xml:"oledaddressbasepagestart"`
CharLength int `xml:"oledcharlength"`
StartColumn int `xml:"oledstartcolumn"`
} `xml:"oled"`
GPS struct {
Enabled bool `xml:"enabled,attr"`
Port string `xml:"port"`
Baud uint `xml:"baud"`
TxData string `xml:"txdata"`
Even bool `xml:"even"`
Odd bool `xml:"odd"`
Rs485 bool `xml:"rs485"`
Rs485HighDuringSend bool `xml:"rs485highduringsend"`
Rs485HighAfterSend bool `xml:"rs485highaftersend"`
StopBits uint `xml:"stopbits"`
DataBits uint `xml:"databits"`
CharTimeOut uint `xml:"chartimeout"`
MinRead uint `xml:"minread"`
Rx bool `xml:"rx"`
GpsInfoVerbose bool `xml:"gpsinfoverbose"`
GpsDiagSounds bool `xml:"gpsdiagsounds"`
GpsDisplayShow bool `xml:"gpsdisplayshow"`
} `xml:"gps"`
Traccar struct {
Enabled bool `xml:"enabled,attr"`
Track bool `xml:"track"`
ClientId string `xml:"clientid"`
DeviceScreenEnabled bool `xml:"devicescreenenabled"`
TraccarDiagSounds bool `xml:"traccardiagsounds"`
TraccarDisplayShow bool `xml:"traccardispayshow"`
Protocol struct {
Name string `xml:"name,attr"`
Osmand struct {
Port string `xml:"port,attr"`
ServerURL string `xml:"serverurl"`
} `xml:"osmand"`
T55 struct {
Port string `xml:"port,attr"`
ServerIP string `xml:"serverip"`
} `xml:"t55"`
Opengts struct {
Port string `xml:"port,attr"`
ServerURL string `xml:"serverurl"`
} `xml:"opengts"`
} `xml:"protocol"`
} `xml:"traccar"`
PanicFunction struct {
Enabled bool `xml:"enabled,attr"`
FilenameAndPath string `xml:"filenameandpath"`
Volume float32 `xml:"volume"`
Blocking bool `xml:"blocking,attr"`
SendIdent bool `xml:"sendident"`
Message string `xml:"panicmessage"`
PMailEnabled bool `xml:"panicemail"`
PEavesdropEnabled bool `xml:"eavesdrop"`
RecursiveSendMessage bool `xml:"recursivesendmessage"`
SendGpsLocation bool `xml:"sendgpslocation"`
TxLockEnabled bool `xml:"txlockenabled"`
TxLockTimeOutSecs uint `xml:"txlocktimeoutsecs"`
PLowProfile bool `xml:"lowprofile"`
} `xml:"panicfunction"`
USBKeyboard struct {
Enabled bool `xml:"enabled,attr"`
USBKeyboardPath string `xml:"usbkeyboarddevpath"`
NumlockScanID rune `xml:"numlockscanid"`
} `xml:"usbkeyboard"`
AudioRecordFunction struct {
Enabled bool `xml:"enabled,attr"`
RecordOnStart bool `xml:"recordonstart"`
RecordSystem string `xml:"recordsystem"`
RecordMode string `xml:"recordmode"`
RecordTimeout int64 `xml:"recordtimeout"`
RecordFromOutput string `xml:"recordfromoutput"`
RecordFromInput string `xml:"recordfrominput"`
RecordMicTimeout int64 `xml:"recordmictimeout"`
RecordSoft string `xml:"recordsoft"`
RecordSavePath string `xml:"recordsavepath"`
RecordArchivePath string `xml:"recordarchivepath"`
RecordProfile string `xml:"recordprofile"`
RecordFileFormat string `xml:"recordfileformat"`
RecordChunkSize string `xml:"recordchunksize"`
} `xml:"audiorecordfunction"`
Keyboard struct {
Command []struct {
Action string `xml:"action,attr"`
ParamName string `xml:"paramname,attr"`
Paramvalue string `xml:"paramvalue,attr"`
Enabled bool `xml:"enabled,attr"`
Ttykeyboard struct {
Scanid rune `xml:"scanid,attr"`
Keylabel uint32 `xml:"keylabel,attr"`
Enabled bool `xml:"enabled,attr"`
} `xml:"ttykeyboard"`
Usbkeyboard struct {
Scanid rune `xml:"scanid,attr"`
Keylabel uint32 `xml:"keylabel,attr"`
Enabled bool `xml:"enabled,attr"`
} `xml:"usbkeyboard"`
} `xml:"command"`
} `xml:"keyboard"`
Radio struct {
XMLName xml.Name `xml:"radio"`
Enabled bool `xml:"enabled,attr"`
ConnectChannelID string `xml:"connectchannelid"`
Sa818 struct {
Enabled bool `xml:"enabled,attr"`
PDEnabled bool `xml:"enabled"`
Serial struct {
Enabled bool `xml:"enabled,attr"`
Port string `xml:"port"`
Baud uint `xml:"baud"`
Stopbits uint `xml:"stopbits"`
Databits uint `xml:"databits"`
} `xml:"serial"`
Channels struct {
Channel []struct {
ID string `xml:"id,attr"`
Name string `xml:"name,attr"`
Enabled bool `xml:"enabled,attr"`
ItemInList int `xml:""`
Bandwidth int `xml:"bandwidth"`
Rxfreq float32 `xml:"rxfreq"`
Txfreq float32 `xml:"txfreq"`
Squelch int `xml:"squelch"`
Ctcsstone int `xml:"ctcsstone"`
Dcstone int `xml:"dcstone"`
Predeemph int `xml:"predeemph"`
Highpass int `xml:"highpass"`
Lowpass int `xml:"lowpass"`
Volume int `xml:"volume"`
TXPower string `xml:"txpower"`
} `xml:"channel"`
} `xml:"channels"`
} `xml:"sa818"`
}
} `xml:"hardware"`
Multimedia struct {
ID []struct {
Value string `xml:"value,attr"`
Enabled bool `xml:"enabled,attr"`
Params struct {
Announcementtone struct {
File string `xml:"file,attr"`
Volume int `xml:"volume,attr"`
Blocking bool `xml:"blocking"`
Enabled bool `xml:"enabled,attr"`
} `xml:"announcementtone"`
Localplay bool `xml:"localplay"`
GPIO struct {
Name string `xml:"name,attr"`
Enabled bool `xml:"enabled,attr"`
} `xml:"gpio"`
Predelay struct {
Value time.Duration `xml:"value,attr"`
Enabled bool `xml:"enabled,attr"`
} `xml:"predelay"`
Postdelay struct {
Value time.Duration `xml:"value,attr"`
Enabled bool `xml:"enabled,attr"`
} `xml:"postdelay"`
Playintostream bool `xml:"playintostream"`
Voicetarget bool `xml:"voicetarget"`
} `xml:"params"`
Media struct {
Source []struct {
Name string `xml:"name,attr"`
File string `xml:"file,attr"`
Volume int `xml:"volume,attr"`
Duration float32 `xml:"duration,attr"`
Offset float32 `xml:"offset,attr"`
Loop int `xml:"loop,attr"`
Blocking bool `xml:"blocking"`
Enabled bool `xml:"enabled,attr"`
} `xml:"source"`
} `xml:"media"`
} `xml:"id"`
} `xml:"multimedia"`
} `xml:"global"`
}
type VTStruct struct {
ID []struct {
Value uint32
IsCurrent bool
Users struct {
User []string
}
Channels struct {
Channel []struct {
Name string
Recursive bool
Links bool
Group string
}
}
}
}
type KBStruct struct {
Enabled bool
KeyLabel uint32
Command string
ParamName string
ParamValue string
}
type EventSoundStruct struct {
Enabled bool
FileName string
Volume string
Blocking bool
}
type InputEventSoundFileStruct struct {
Event string
File string
Enabled bool
}
type streamTrackerStruct struct {
UserID uint32
UserName string
UserSession uint32
C <-chan *gumble.AudioPacket
}
type talkingStruct struct {
IsTalking bool
WhoTalking string
}
type mqttPubButtonStruct struct {
Item string
Payload string
Enabled bool
}
type radioChannelsStruct struct {
ID string
Name string
ItemInList int
Bandwidth int
Rxfreq float32
Txfreq float32
Squelch int
Ctcsstone int
Dcstone int
Predeemph int
Highpass int
Lowpass int
Volume int
}
type rotaryFunctionsStruct struct {
Item int
Function string
}
// Generic Global Config Variables
var Config ConfigStruct
var ConfigXMLFile string
var radioChannels []radioChannelsStruct
var RotaryFunctions []rotaryFunctionsStruct
// Generic Global State Variables
var (
KillHeartBeat bool
IsPlayStream bool
IsConnected bool
Streaming bool
HTTPServRunning bool
NowStreaming bool
InStreamTalking bool
InStreamSource bool
LCDIsDark bool
GPSDataChannelReceivers int
TXLockOut bool
)
// Generic Global Counter Variables
var (
AccountCount int
ConnectAttempts int
AccountIndex int
GenericCounter int
CurrentIndex int
ChannelAction string
)
// Generic Global Timer Variables
var (
BackLightTime = time.NewTicker(5 * time.Second)
BackLightTimePtr = &BackLightTime
StartTime = time.Now()
LastTime = now.Unix()
TalkedTicker = time.NewTicker(time.Millisecond * 200)
Talking = make(chan talkingStruct, 10)
)
var (
LcdText = [4]string{"nil", "nil", "nil", "nil"}
MyLedStrip *LedStrip
TTYKeyMap = make(map[rune]KBStruct)
USBKeyMap = make(map[rune]KBStruct)
)
//Mumble Account Settings Global Variables
var (
Default []bool
Name []string
Server []string
Username []string
Password []string
Insecure []bool
Register []bool
Certificate []string
Channel []string
Ident []string
Tokens []gumble.AccessTokens
VT []VTStruct
Accounts int
ChannelsList []ChannelsListStruct
)
//HD44780 LCD Screen Settings Golbal Variables
var (
LCDEnabled bool
LCDInterfaceType string
LCDI2CAddress uint8
LCDBackLightTimerEnabled bool
LCDBackLightTimeout time.Duration
LCDRSPin int
LCDEPin int
LCDD4Pin int
LCDD5Pin int
LCDD6Pin int
LCDD7Pin int
)
//OLED Screen Settings Golbal Variables
var (
OLEDEnabled bool
OLEDInterfacetype string
OLEDDefaultI2cAddress uint8
OLEDDefaultI2cBus int
OLEDScreenWidth int
OLEDScreenHeight int
OLEDDisplayRows int
OLEDDisplayColumns uint8
OLEDStartColumn int
OLEDCharLength int
OLEDCommandColumnAddressing int
OLEDAddressBasePageStart int
Oled *goled.Oled
)
// Generic Local Variables
var (
txcounter int
isTx bool
pstream *gumbleffmpeg.Stream
LastSpeaker string = ""
RotaryFunction rotaryFunctionsStruct
)
var StreamTracker = map[uint32]streamTrackerStruct{}
var DMOSetup sa818.DMOSetupStruct
func readxmlconfig(file string, reloadxml bool) error {
var ReConfig ConfigStruct
xmlFile, err := os.Open(file)
if err != nil {
return fmt.Errorf(err.Error())
}
log.Println("info: Successfully Read file " + filepath.Base(file))
defer xmlFile.Close()
byteValue, _ := ioutil.ReadAll(xmlFile)
if !reloadxml {
err = xml.Unmarshal(byteValue, &Config)
if err != nil {
return fmt.Errorf(filepath.Base(file) + " " + err.Error())
}
} else {
err = xml.Unmarshal(byteValue, &ReConfig)
if err != nil {
return fmt.Errorf(filepath.Base(file) + " " + err.Error())
}
}
CheckConfigSanity(reloadxml)
if !reloadxml {
for _, account := range Config.Accounts.Account {
if account.Default {
Name = append(Name, account.Name)
Server = append(Server, account.ServerAndPort)
Username = append(Username, account.UserName)
Password = append(Password, account.Password)
Insecure = append(Insecure, account.Insecure)
Register = append(Register, account.Register)
Certificate = append(Certificate, account.Certificate)
Channel = append(Channel, account.Channel)
Ident = append(Ident, account.Ident)
Tokens = append(Tokens, account.Tokens.Token)
VT = append(VT, VTStruct(account.Voicetargets))
AccountCount++
}
}
}
for _, kMainCommands := range Config.Global.Hardware.Keyboard.Command {
if kMainCommands.Enabled {
if kMainCommands.Ttykeyboard.Enabled {
TTYKeyMap[kMainCommands.Ttykeyboard.Scanid] = KBStruct{kMainCommands.Ttykeyboard.Enabled, kMainCommands.Ttykeyboard.Keylabel, kMainCommands.Action, kMainCommands.ParamName, kMainCommands.Paramvalue}
}
if kMainCommands.Usbkeyboard.Enabled {
USBKeyMap[kMainCommands.Usbkeyboard.Scanid] = KBStruct{kMainCommands.Usbkeyboard.Enabled, kMainCommands.Usbkeyboard.Keylabel, kMainCommands.Action, kMainCommands.ParamName, kMainCommands.Paramvalue}
}
}
}
exec, err := os.Executable()
if err != nil {
exec = "./talkkonnect" //Hardcode our default name
}
// Set our default config file path (for autoprovision)
defaultConfPath, err := filepath.Abs(filepath.Dir(file))
if err != nil {
FatalCleanUp("Unable to get path for config file " + err.Error())
}
// Set our default logging path
//This section is pretty unix specific.. sorry if you like windows support.
defaultLogPath := "/tmp/" + filepath.Base(exec) + ".log" // Safe assumption as it should be writable for everyone
// First see if we can write in our CWD and use it over /tmp
cwd, err := os.Getwd()
if err == nil {
cwd, err := filepath.Abs(cwd)
if err == nil {
if unix.Access(cwd, unix.W_OK) == nil {
defaultLogPath = cwd + "/" + filepath.Base(exec) + ".log"
}
}
}
// Next try a file in our config path and favor it over CWD
if unix.Access(defaultConfPath, unix.W_OK) == nil {
defaultLogPath = defaultConfPath + "/" + filepath.Base(exec) + ".log"
}
// Last, see if the system talkkonnect log exists and is writeable and do that over CWD, HOME and /tmp
if _, err := os.Stat("/var/log/" + filepath.Base(exec) + ".log"); err == nil {
f, err := os.OpenFile("/var/log/"+filepath.Base(exec)+".log", os.O_WRONLY, 0664)
if err == nil {
defaultLogPath = "/var/log/" + filepath.Base(exec) + ".log"
}
f.Close()
}
if len(Config.Global.Software.Settings.OutputDeviceShort) == 0 {
Config.Global.Software.Settings.OutputDeviceShort = Config.Global.Software.Settings.OutputDevice
}
if len(Config.Global.Software.Settings.OutputVolControlDevice) == 0 {
Config.Global.Software.Settings.OutputVolControlDevice = Config.Global.Software.Settings.OutputDevice
}
if len(Config.Global.Software.Settings.OutputMuteControlDevice) == 0 {
Config.Global.Software.Settings.OutputMuteControlDevice = Config.Global.Software.Settings.OutputDevice
}
if strings.ToLower(Config.Global.Software.Settings.Logging) != "screen" && Config.Global.Software.Settings.LogFilenameAndPath == "" {
Config.Global.Software.Settings.LogFilenameAndPath = defaultLogPath
}
if !reloadxml {
LCDEnabled = Config.Global.Hardware.LCD.Enabled
LCDInterfaceType = Config.Global.Hardware.LCD.InterfaceType
LCDI2CAddress = Config.Global.Hardware.LCD.I2CAddress
LCDBackLightTimerEnabled = Config.Global.Hardware.LCD.Enabled
LCDBackLightTimeout = time.Duration(Config.Global.Hardware.LCD.BackLightTimeoutSecs)
LCDRSPin = Config.Global.Hardware.LCD.RsPin
LCDEPin = Config.Global.Hardware.LCD.EPin
LCDD4Pin = Config.Global.Hardware.LCD.D4Pin
LCDD5Pin = Config.Global.Hardware.LCD.D5Pin
LCDD6Pin = Config.Global.Hardware.LCD.D6Pin
LCDD7Pin = Config.Global.Hardware.LCD.D7Pin
OLEDEnabled = Config.Global.Hardware.OLED.Enabled
OLEDInterfacetype = Config.Global.Hardware.OLED.InterfaceType
OLEDDisplayRows = Config.Global.Hardware.OLED.DisplayRows
OLEDDisplayColumns = Config.Global.Hardware.OLED.DisplayColumns
OLEDDefaultI2cBus = Config.Global.Hardware.OLED.DefaultI2CBus
OLEDDefaultI2cAddress = Config.Global.Hardware.OLED.DefaultI2CAddress
OLEDScreenWidth = Config.Global.Hardware.OLED.ScreenWidth
OLEDScreenHeight = Config.Global.Hardware.OLED.ScreenHeight
OLEDCommandColumnAddressing = Config.Global.Hardware.OLED.CommandColumnAddressing
OLEDAddressBasePageStart = Config.Global.Hardware.OLED.AddressBasePageStart
OLEDCharLength = Config.Global.Hardware.OLED.CharLength
OLEDStartColumn = Config.Global.Hardware.OLED.StartColumn
if Config.Global.Hardware.TargetBoard != "rpi" {
LCDBackLightTimerEnabled = false
}
if Config.Global.Hardware.VoiceActivityTimermsecs == 0 {
Config.Global.Hardware.VoiceActivityTimermsecs = 200
}
if Config.Global.Hardware.IO.VolumeButtonStep.VolUpStep == 0 {
Config.Global.Hardware.IO.VolumeButtonStep.VolUpStep = +1
}
if Config.Global.Hardware.IO.VolumeButtonStep.VolDownStep == 0 {
Config.Global.Hardware.IO.VolumeButtonStep.VolDownStep = -1
}
if OLEDEnabled {
Oled, err = goled.BeginOled(OLEDDefaultI2cAddress, OLEDDefaultI2cBus, OLEDScreenWidth, OLEDScreenHeight, OLEDDisplayRows, OLEDDisplayColumns, OLEDStartColumn, OLEDCharLength, OLEDCommandColumnAddressing, OLEDAddressBasePageStart)
if err != nil {
log.Println("error: Cannot Communicate with OLED")
}
}
}
log.Println("info: Successfully loaded XML configuration file into memory")
// Add Allowed Mutable Settings For talkkonnect upon live reloadxml config to the list below omit all other variables
if reloadxml {
if Config.Global.Software.Settings.Loglevel != ReConfig.Global.Software.Settings.Loglevel {
Config.Global.Software.Settings.Loglevel = ReConfig.Global.Software.Settings.Loglevel
switch Config.Global.Software.Settings.Loglevel {
case "trace":
colog.SetMinLevel(colog.LTrace)
log.Println("info: Loglevel Set to Trace")
case "debug":
colog.SetMinLevel(colog.LDebug)
log.Println("info: Loglevel Set to Debug")
case "info":
colog.SetMinLevel(colog.LInfo)
log.Println("info: Loglevel Set to Info")
case "warning":
colog.SetMinLevel(colog.LWarning)
log.Println("info: Loglevel Set to Warning")
case "error":
colog.SetMinLevel(colog.LError)
log.Println("info: Loglevel Set to Error")
case "alert":
colog.SetMinLevel(colog.LAlert)
log.Println("info: Loglevel Set to Alert")
default:
colog.SetMinLevel(colog.LInfo)
log.Println("info: Default Loglevel unset in XML config automatically loglevel to Info")
}
}
Config.Global.Software.Settings.CancellableStream = ReConfig.Global.Software.Settings.CancellableStream
Config.Global.Software.Settings.StreamSendMessage = ReConfig.Global.Software.Settings.StreamSendMessage
Config.Global.Software.Settings.RepeatTXTimes = ReConfig.Global.Software.Settings.RepeatTXTimes
Config.Global.Software.Settings.RepeatTXDelay = ReConfig.Global.Software.Settings.RepeatTXDelay
Config.Global.Software.Settings.SimplexWithMute = ReConfig.Global.Software.Settings.SimplexWithMute
Config.Global.Software.Beacon = ReConfig.Global.Software.Beacon
Config.Global.Software.TTS = ReConfig.Global.Software.TTS
Config.Global.Software.Sounds = ReConfig.Global.Software.Sounds
Config.Global.Software.TxTimeOut = ReConfig.Global.Software.TxTimeOut
Config.Global.Software.RemoteControl.HTTP.Enabled = ReConfig.Global.Software.RemoteControl.HTTP.Enabled
Config.Global.Software.RemoteControl.HTTP.Command = ReConfig.Global.Software.RemoteControl.HTTP.Command
Config.Global.Software.RemoteControl.MQTT.Commands.Command = ReConfig.Global.Software.RemoteControl.MQTT.Commands.Command
Config.Global.Software.PrintVariables = ReConfig.Global.Software.PrintVariables
Config.Global.Software.TTSMessages = ReConfig.Global.Software.TTSMessages
Config.Global.Software.IgnoreUser = ReConfig.Global.Software.IgnoreUser
Config.Global.Hardware.PanicFunction = ReConfig.Global.Hardware.PanicFunction
Config.Global.Hardware.Keyboard.Command = ReConfig.Global.Hardware.Keyboard.Command
Config.Global.Multimedia = ReConfig.Global.Multimedia
}
return nil
}
func printxmlconfig() {
if Config.Global.Software.PrintVariables.PrintAccount {
log.Println("info: ---------- Account Info ---------- ")
for index, account := range Config.Accounts.Account {
if account.Default {
var AcctIsDefault string = "x"
if Server[AccountIndex] == account.ServerAndPort && Username[AccountIndex] == account.UserName {
AcctIsDefault = "✓"
}
log.Printf("info: %v Account %v Name %v Enabled %v \n", AcctIsDefault, index, account.Name, account.Default)
log.Printf("info: %v Server:Port %v \n", AcctIsDefault, account.ServerAndPort)
log.Printf("info: %v Username %v Password %v \n", AcctIsDefault, account.UserName, account.Password)
log.Printf("info: %v Insecure %v Register %v \n", AcctIsDefault, account.Insecure, account.Register)
log.Printf("info: %v Certificate %v \n", AcctIsDefault, account.Certificate)
log.Printf("info: %v Channel %v \n", AcctIsDefault, account.Channel)
log.Printf("info: %v Ident %v \n", AcctIsDefault, account.Ident)
log.Printf("info: %v Tokens %v \n", AcctIsDefault, account.Tokens)
log.Printf("info: %v VoiceTargets %v \n", AcctIsDefault, account.Voicetargets)
}
}
} else {
log.Println("info: ---------- Account Information -------- SKIPPED ")
}
if Config.Global.Software.PrintVariables.PrintSystemSettings {
log.Println("info: -------- System Settings -------- ")
log.Println("info: Single Instance ", Config.Global.Software.Settings.SingleInstance)
log.Println("info: Output Device ", Config.Global.Software.Settings.OutputDevice)
log.Println("info: Output Device(Short) ", Config.Global.Software.Settings.OutputDeviceShort)
log.Println("info: Output Vol Control Device ", Config.Global.Software.Settings.OutputVolControlDevice)
log.Println("info: Output Mute Control Device ", Config.Global.Software.Settings.OutputMuteControlDevice)
log.Println("info: Log File ", Config.Global.Software.Settings.LogFilenameAndPath)
log.Println("info: Logging ", Config.Global.Software.Settings.Logging)
log.Println("info: Loglevel ", Config.Global.Software.Settings.Loglevel)
log.Println("info: CancellableStream ", fmt.Sprintf("%t", Config.Global.Software.Settings.CancellableStream))
log.Println("info: StreamOnStart ", fmt.Sprintf("%t", Config.Global.Software.Settings.StreamOnStart))
log.Println("info: StreamOnStartAfter ", fmt.Sprintf("%v", Config.Global.Software.Settings.StreamOnStartAfter))
log.Println("info: TXOnStart ", fmt.Sprintf("%t", Config.Global.Software.Settings.TXOnStart))
log.Println("info: TXOnStartAfter ", fmt.Sprintf("%v", Config.Global.Software.Settings.TXOnStartAfter))
log.Println("info: RepeatTXTimes ", fmt.Sprintf("%v", Config.Global.Software.Settings.RepeatTXTimes))
log.Println("info: RepeatTXDelay ", fmt.Sprintf("%v", Config.Global.Software.Settings.RepeatTXDelay))
log.Println("info: SimplexWithMute ", fmt.Sprintf("%t", Config.Global.Software.Settings.SimplexWithMute))
log.Println("info: TxCounter ", fmt.Sprintf("%t", Config.Global.Software.Settings.TxCounter))