forked from talkkonnect/talkkonnect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxmlparser.go
executable file
·1661 lines (1495 loc) · 71.3 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 <suvir@talkkonnect.com>
*
* 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 <suvir@talkkonnect.com>
* Portions created by the Initial Developer are Copyright (C) Suvir Kumar. All Rights Reserved.
*
* Contributor(s):
*
* Suvir Kumar <suvir@talkkonnect.com>
*
* 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"
"errors"
"fmt"
"golang.org/x/sys/unix"
"io/ioutil"
"log"
"os"
"path/filepath"
"strconv"
"strings"
"time"
)
//version and release date
const (
talkkonnectVersion string = "1.46.41"
talkkonnectReleased string = "March 29 2020"
)
// lcd timer
var (
BackLightTime = time.NewTimer(1 * time.Millisecond)
BackLightTimePtr = &BackLightTime
)
//account settings
var (
Default []bool
Name []string
Server []string
Username []string
Password []string
Insecure []bool
Certificate []string
Channel []string
Ident []string
)
//software settings
var (
OutputDevice string
DefaultOptVolume int
LogFilenameAndPath string
Logging string
Daemonize bool
SimplexWithMute bool
TxCounter bool
)
//autoprovision settings
var (
APEnabled bool
TkID string
URL string
SaveFilePath string
SaveFilename string
)
//beacon settings
var (
BeaconEnabled bool
BeaconTimerSecs int
BeaconFilenameAndPath string
BVolume float32
)
//tts
var (
TTSEnabled bool
TTSVolumeLevel int
TTSParticipants bool
TTSChannelUp bool
TTSChannelUpFilenameAndPath string
TTSChannelDown bool
TTSChannelDownFilenameAndPath string
TTSMuteUnMuteSpeaker bool
TTSMuteUnMuteSpeakerFilenameAndPath string
TTSCurrentVolumeLevel bool
TTSCurrentVolumeLevelFilenameAndPath string
TTSDigitalVolumeUp bool
TTSDigitalVolumeUpFilenameAndPath string
TTSDigitalVolumeDown bool
TTSDigitalVolumeDownFilenameAndPath string
TTSListServerChannels bool
TTSListServerChannelsFilenameAndPath string
TTSStartTransmitting bool
TTSStartTransmittingFilenameAndPath string
TTSStopTransmitting bool
TTSStopTransmittingFilenameAndPath string
TTSListOnlineUsers bool
TTSListOnlineUsersFilenameAndPath string
TTSPlayChimes bool
TTSPlayChimesFilenameAndPath string
TTSRequestGpsPosition bool
TTSRequestGpsPositionFilenameAndPath string
TTSNextServer bool
TTSNextServerFilenameAndPath string
TTSPreviousServer bool
TTSPreviousServerFilenameAndPath string
TTSPanicSimulation bool
TTSPanicSimulationFilenameAndPath string
TTSPrintXmlConfig bool
TTSPrintXmlConfigFilenameAndPath string
TTSSendEmail bool
TTSSendEmailFilenameAndPath string
TTSDisplayMenu bool
TTSDisplayMenuFilenameAndPath string
TTSQuitTalkkonnect bool
TTSQuitTalkkonnectFilenameAndPath string
TTSTalkkonnectLoaded bool
TTSTalkkonnectLoadedFilenameAndPath string
TTSPingServers bool
TTSPingServersFilenameAndPath string
TTSScan bool
TTSScanFilenameAndPath string
)
//gmail smtp settings
var (
EmailEnabled bool
EmailUsername string
EmailPassword string
EmailReceiver string
EmailSubject string
EmailMessage string
EmailGpsDateTime bool
EmailGpsLatLong bool
EmailGoogleMapsURL bool
)
//sound settings
var (
EventSoundEnabled bool
EventSoundFilenameAndPath string
AlertSoundEnabled bool
AlertSoundFilenameAndPath string
AlertSoundVolume float32
RogerBeepSoundEnabled bool
RogerBeepSoundFilenameAndPath string
RogerBeepSoundVolume float32
ChimesSoundEnabled bool
ChimesSoundFilenameAndPath string
ChimesSoundVolume float32
)
//api settings
var (
APIEnabled bool
APIListenPort string
APIDisplayMenu bool
APIChannelUp bool
APIChannelDown bool
APIMute bool
APICurrentVolumeLevel bool
APIDigitalVolumeUp bool
APIDigitalVolumeDown bool
APIListServerChannels bool
APIStartTransmitting bool
APIStopTransmitting bool
APIListOnlineUsers bool
APIPlayChimes bool
APIRequestGpsPosition bool
APIEmailEnabled bool
APINextServer bool
APIPreviousServer bool
APIPanicSimulation bool
APIScanChannels bool
APIDisplayVersion bool
APIClearScreen bool
APIPingServersEnabled bool
APIRepeatTxLoopTest bool
APIPrintXmlConfig bool
)
//print xml config sections for easy debugging, set any section to false to prevent printing to screen
var (
PrintAccount bool
PrintLogging bool
PrintProvisioning bool
PrintBeacon bool
PrintTTS bool
PrintSMTP bool
PrintSounds bool
PrintTxTimeout bool
PrintHTTPAPI bool
PrintTargetboard bool
PrintLeds bool
PrintHeartbeat bool
PrintButtons bool
PrintComment bool
PrintLcd bool
PrintOled bool
PrintGps bool
PrintPanic bool
PrintAudioRecord bool //New
)
// target board settings
var (
TargetBoard string
)
//indicator light settings
var (
VoiceActivityLEDPin uint
ParticipantsLEDPin uint
TransmitLEDPin uint
OnlineLEDPin uint
)
//heartbeat light settings
var (
HeartBeatEnabled bool
HeartBeatLEDPin uint
PeriodmSecs int
LEDOnmSecs int
LEDOffmSecs int
)
//button settings
var (
TxButtonPin uint
TxTogglePin uint
UpButtonPin uint
DownButtonPin uint
PanicButtonPin uint
ChimesButtonPin uint
)
//comment settings
var (
CommentButtonPin uint
CommentMessageOff string
CommentMessageOn string
)
//HD44780 screen lcd settings
var (
LCDEnabled bool
LCDInterfaceType string
LCDI2CAddress uint8
LCDBackLightTimerEnabled bool
LCDBackLightTimeoutSecs int
LCDBackLightLEDPin int
LCDRSPin int
LCDEPin int
LCDD4Pin int
LCDD5Pin int
LCDD6Pin int
LCDD7Pin int
)
//OLED screen settings
var (
OLEDEnabled bool
OLEDInterfacetype string
OLEDDefaultI2cAddress uint8
OLEDDefaultI2cBus int
OLEDScreenWidth int
OLEDScreenHeight int
OLEDDisplayRows int
OLEDDisplayColumns uint8 // int
OLEDStartColumn int
OLEDCharLength int
OLEDCommandColumnAddressing int //uint8
OLEDAddressBasePageStart int //uint8
)
//txtimeout settings
var (
TxTimeOutEnabled bool
TxTimeOutSecs int
)
//gps settings
var (
GpsEnabled bool
Port string
Baud uint
TxData string
Even bool
Odd bool
Rs485 bool
Rs485HighDuringSend bool
Rs485HighAfterSend bool
StopBits uint
DataBits uint
CharTimeOut uint
MinRead uint
Rx bool
)
//panic function settings
var (
PEnabled bool
PFilenameAndPath string
PMessage string
PRecursive bool
PVolume float32
PSendIdent bool
PSendGpsLocation bool
PTxLockEnabled bool
PTxlockTimeOutSecs uint
)
//audio recording settings // New
var (
AudioRecordEnabled bool // New
AudioRecordOnStart bool // New. Incoming Traffic
AudioRecordMode string // New. traffic, ambient, both.
AudioRecordTimeout int64 // New. Incoming Traffic
AudioRecordFromOutput string // New. Audio device name. Loopback name, Monitor, source, etc. Depends... Alsa, pulseaudo and/or Jack?
AudioRecordFromInput string // New. Audio Input Device (mic), that sox unerstands, e.g. default, plughw:1,0, hw:1,0
AudioRecordMicTimeout int64 // New. For recording from mic, a timeout. If "0", then continous.
AudioRecordSoft string // New
AudioRecordSavePath string // New
AudioRecordArchivePath string // New
AudioRecordProfile string // New. Sox recording profile. vox, silence detect and trim, file chunks.
AudioRecordFileFormat string // New. wav, mp3, ogg
AudioRecordChunkSize string // New. Size of audio file chunks in seconds.
)
//serial usage variables
var (
Serialcommenable bool
Serialport string
Serialpttmode string
Pttdefault bool
Sqldefault bool
Dsrdefault bool
Dsralarmenable bool
Dtrreference bool
)
//other global variables used for state tracking
var (
txcounter int
togglecounter int
isTx bool
isPlayStream bool
CancellableStream bool
)
type Document struct {
XMLName xml.Name `xml:"document"`
Type string `xml:"type,attr"`
Accounts Accounts `xml:"accounts"`
Global Global `xml:"global"`
}
type Accounts struct {
XMLName xml.Name `xml:"accounts"`
Accounts []Account `xml:"account"`
}
type Account struct {
XMLName xml.Name `xml:"account"`
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"`
Certificate string `xml:"certificate"`
Channel string `xml:"channel"`
Ident string `xml:"ident"`
}
type Global struct {
XMLName xml.Name `xml:"global"`
Software Software `xml:"software"`
Hardware Hardware `xml:"hardware"`
}
type Software struct {
XMLName xml.Name `xml:"software"`
AutoProvisioning AutoProvisioning `xml:"autoprovisioning"`
Beacon Beacon `xml:"beacon"`
Settings Settings `xml:"settings"`
Smtp Smtp `xml:"smtp"`
Sounds Sounds `xml:"sounds"`
TxTimeOut TxTimeOut `xml:"txtimeout"`
API API `xml:"api"`
PrintVariables PrintVariables `xml:"printvariables"`
TTS TTS `xml:"tts"`
}
type Settings struct {
XMLName xml.Name `xml:"settings"`
OutputDevice string `xml:"outputdevice"`
DefaultOptVolume int `xml:"defaultoptvolume"`
LogFilenameAndPath string `xml:"logfilenameandpath"`
Logging string `xml:"logging"`
Daemonize bool `xml:"daemonize"`
CancellableStream bool `xml:"cancellablestream"`
SimplexWithMute bool `xml:"simplexwithmute"`
TxCounter bool `xml:"txcounter"`
}
type AutoProvisioning struct {
XMLName xml.Name `xml:"autoprovisioning"`
APEnabled bool `xml:"enabled,attr"`
TkID string `xml:"tkid"`
URL string `xml:"url"`
SaveFilePath string `xml:"savefilepath"`
SaveFilename string `xml:"savefilename"`
}
type Beacon struct {
XMLName xml.Name `xml:"beacon"`
BeaconEnabled bool `xml:"enabled,attr"`
BeaconTimerSecs int `xml:"beacontimersecs"`
BeaconFilenameAndPath string `xml:"beaconfileandpath"`
BVolume float32 `xml:"volume"`
}
type TTS struct {
XMLName xml.Name `xml:"tts"`
TTSEnabled bool `xml:"enabled,attr"`
TTSVolumeLevel int `xml:"volumelevel"`
TTSParticipants bool `xml:"participants"`
TTSChannelUp bool `xml:"channelup"`
TTSChannelUpFilenameAndPath string `xml:"channelupfilenameandpath"`
TTSChannelDown bool `xml:"channeldown"`
TTSChannelDownFilenameAndPath string `xml:"channeldownfilenameandpath"`
TTSMuteUnMuteSpeaker bool `xml:"muteunmutespeaker"`
TTSMuteUnMuteSpeakerFilenameAndPath string `xml:"muteunmutespeakerfilenameandpath"`
TTSCurrentVolumeLevel bool `xml:"currentvolumelevel"`
TTSCurrentVolumeLevelFilenameAndPath string `xml:"currentvolumelevelfilenameandpath"`
TTSDigitalVolumeUp bool `xml:"digitalvolumeup"`
TTSDigitalVolumeUpFilenameAndPath string `xml:"digitalvolumeupfilenameandpath"`
TTSDigitalVolumeDown bool `xml:"digitalvolumedown"`
TTSDigitalVolumeDownFilenameAndPath string `xml:"digitalvolumedownfilenameandpath"`
TTSListServerChannels bool `xml:"listserverchannels"`
TTSListServerChannelsFilenameAndPath string `xml:"listserverchannelsfilenameandpath"`
TTSStartTransmitting bool `xml:"starttransmitting"`
TTSStartTransmittingFilenameAndPath string `xml:"starttransmittingfilenameandpath"`
TTSStopTransmitting bool `xml:"stoptransmitting"`
TTSStopTransmittingFilenameAndPath string `xml:"stoptransmittingfilenameandpath"`
TTSListOnlineUsers bool `xml:"listonlineusers"`
TTSListOnlineUsersFilenameAndPath string `xml:"listonlineusersfilenameandpath"`
TTSPlayChimes bool `xml:"playchimes"`
TTSPlayChimesFilenameAndPath string `xml:"playchimesfilenameandpath"`
TTSRequestGpsPosition bool `xml:"requestgpsposition"`
TTSRequestGpsPositionFilenameAndPath string `xml:"requestgpspositionfilenameandpath"`
TTSNextServer bool `xml:"nextserver"`
TTSNextServerFilenameAndPath string `xml:"nextserverfilenameandpath"`
TTSPreviousServer bool `xml:"previousserver"`
TTSPreviousServerFilenameAndPath string `xml:"previousserverfilenameandpath"`
TTSPanicSimulation bool `xml:"panicsimulation"`
TTSPanicSimulationFilenameAndPath string `xml:"panicsimulationfilenameandpath"`
TTSPrintXmlConfig bool `xml:"printxmlconfig"`
TTSPrintXmlConfigFilenameAndPath string `xml:"printxmlconfigfilenameandpath"`
TTSSendEmail bool `xml:"sendemail"`
TTSSendEmailFilenameAndPath string `xml:"sendemailfilenameandpath"`
TTSDisplayMenu bool `xml:"displaymenu"`
TTSDisplayMenuFilenameAndPath string `xml:"displaymenufilenameandpath"`
TTSQuitTalkkonnect bool `xml:"quittalkkonnect"`
TTSQuitTalkkonnectFilenameAndPath string `xml:"quittalkkonnectfilenameandpath"`
TTSTalkkonnectLoaded bool `xml:"talkkonnectloaded"`
TTSTalkkonnectLoadedFilenameAndPath string `xml:"talkkonnectloadedfilenameandpath"`
TTSPingServers bool `xml:"pingservers"`
TTSPingServersFilenameAndPath string `xml:"pingserversfilenameandpath"`
}
type Smtp struct {
XMLName xml.Name `xml:"smtp"`
EmailEnabled bool `xml:"enabled,attr"`
EmailUsername string `xml:"username"`
EmailPassword string `xml:"password"`
EmailReceiver string `xml:"receiver"`
EmailSubject string `xml:"subject"`
EmailMessage string `xml:"message"`
EmailGpsDateTime bool `xml:"gpsdatetime"`
EmailGpsLatLong bool `xml:"gpslatlong"`
EmailGoogleMapsURL bool `xml:"googlemapsurl"`
}
type Sounds struct {
XMLName xml.Name `xml:"sounds"`
Event Event `xml:"event"`
Alert Alert `xml:"alert"`
RogerBeep RogerBeep `xml:"rogerbeep"`
Chimes Chimes `xml:"chimes"`
}
type API struct {
XMLName xml.Name `xml:"api"`
APIEnabled bool `xml:"enabled,attr"`
APIListenPort string `xml:"apilistenport"`
APIDisplayMenu bool `xml:"displaymenu"`
APIChannelUp bool `xml:"channelup"`
APIChannelDown bool `xml:"channeldown"`
APIMute bool `xml:"mute"`
APICurrentVolumeLevel bool `xml:"currentvolumelevel"`
APIDigitalVolumeUp bool `xml:"digitalvolumeup"`
APIDigitalVolumeDown bool `xml:"digitalvolumedown"`
APIListServerChannels bool `xml:"listserverchannels"`
APIStartTransmitting bool `xml:"starttransmitting"`
APIStopTransmitting bool `xml:"stoptransmitting"`
APIListOnlineUsers bool `xml:"listonlineusers"`
APIPlayChimes bool `xml:"playchimes"`
APIRequestGpsPosition bool `xml:"requestgpsposition"`
APIEmailEnabled bool `xml:"sendemail"`
APINextServer bool `xml:"nextserver"`
APIPreviousServer bool `xml:"previousserver"`
APIPanicSimulation bool `xml:"panicsimulation"`
APIScanChannels bool `xml:"scanchannels"`
APIDisplayVersion bool `xml:"displayversion"`
APIClearScreen bool `xml:"clearscreen"`
APIPingServersEnabled bool `xml:"pingservers"`
APIRepeatTxLoopTest bool `xml:"repeattxlooptest"`
APIPrintXmlConfig bool `xml:"printxmlconfig"`
}
type PrintVariables struct {
XMLName xml.Name `xml:"printvariables"`
PrintAccount bool `xml:"printaccount"`
PrintLogging bool `xml:"printlogging"`
PrintProvisioning bool `xml:"printprovisioning"`
PrintBeacon bool `xml:"printbeacon"`
PrintTTS bool `xml:"printtss"`
PrintSMTP bool `xml:"printsmtp"`
PrintSounds bool `xml:"printsounds"`
PrintTxTimeout bool `xml:"printtxtimeout"`
PrintHTTPAPI bool `xml:"printhttpapi"`
PrintTargetboard bool `xml:"printtargetboard"`
PrintLeds bool `xml:"printleds"`
PrintHeartbeat bool `xml:"printheartbeat"`
PrintButtons bool `xml:"printbuttons"`
PrintComment bool `xml:"printcomment"`
PrintLcd bool `xml:"printlcd"`
PrintOled bool `xml:"printoled"`
PrintGps bool `xml:"printgps"`
PrintPanic bool `xml:"printpanic"`
PrintAudioRecord bool `xml:"printaudiorecord"` // New
}
type Event struct {
XMLName xml.Name `xml:"event"`
EEnabled bool `xml:"enabled,attr"`
EFilenameAndPath string `xml:"filenameandpath"`
}
type Alert struct {
XMLName xml.Name `xml:"alert"`
AEnabled bool `xml:"enabled,attr"`
AFilenameAndPath string `xml:"filenameandpath"`
AVolume float32 `xml:"volume"`
}
type RogerBeep struct {
XMLName xml.Name `xml:"rogerbeep"`
REnabled bool `xml:"enabled,attr"`
RFilenameAndPath string `xml:"filenameandpath"`
RBeepVolume float32 `xml:"volume"`
}
type TxTimeOut struct {
XMLName xml.Name `xml:"txtimeout"`
TxTimeOutEnabled bool `xml:"enabled,attr"`
TxTimeOutSecs int `xml:"txtimeoutsecs"`
}
type Chimes struct {
XMLName xml.Name `xml:"chimes"`
CEnabled bool `xml:"enabled,attr"`
CFilenameAndPath string `xml:"filenameandpath"`
CVolume float32 `xml:"volume"`
}
type Hardware struct {
XMLName xml.Name `xml:"hardware"`
TargetBoard string `xml:"targetboard,attr"`
Lights Lights `xml:"lights"`
HeartBeat HeartBeat `xml:"heartbeat"`
Buttons Buttons `xml:"buttons"`
Comment Comment `xml:"comment"`
LCD LCD `xml:"lcd"`
OLED OLED `xml:"oled"`
GPS GPS `xml:"gps"`
PanicFunction PanicFunction `xml:"panicfunction"`
AudioRecordFunction AudioRecordFunction `xml:"audiorecordfunction"` //New
Serialcomm Serialcomm `xml:"serialcomm"`
}
type Lights struct {
XMLName xml.Name `xml:"lights"`
VoiceActivityLedPin string `xml:"voiceactivityledpin"`
ParticipantsLedPin string `xml:"participantsledpin"`
TransmitLedPin string `xml:"transmitledpin"`
OnlineLedPin string `xml:"onlineledpin"`
}
type HeartBeat struct {
XMLName xml.Name `xml:"heartbeat"`
HeartBeatEnabled bool `xml:"enabled,attr"`
HeartBeatLEDPin string `xml:"heartbeatledpin"`
PeriodmSecs int `xml:"periodmsecs"`
LEDOnmSecs int `xml:"ledonmsecs"`
LEDOffmSecs int `xml:"ledoffmsecs"`
}
type Buttons struct {
XMLName xml.Name `xml:"buttons"`
TxButtonPin string `xml:"txbuttonpin"`
TxTogglePin string `xml:"txtogglepin"`
UpButtonPin string `xml:"upbuttonpin"`
DownButtonPin string `xml:"downbuttonpin"`
PanicButtonPin string `xml:"panicbuttonpin"`
ChimesButtonPin string `xml:"chimesbuttonpin"`
}
type Comment struct {
XMLName xml.Name `xml:"comment"`
CommentButtonPin string `xml:"commentbuttonpin"`
CommentMessageOff string `xml:"commentmessageoff"`
CommentMessageOn string `xml:"commentmessageon"`
}
type LCD struct {
XMLName xml.Name `xml:"lcd"`
LCDEnabled bool `xml:"enabled,attr"`
LCDInterfaceType string `xml:"lcdinterfacetype"`
LCDI2CAddress uint8 `xml:"lcdi2caddress"`
LCDBackLightTimerEnabled bool `xml:"lcdbacklighttimerenabled"`
LCDBackLightTimeoutSecs int `xml:"lcdbacklighttimeoutsecs"`
BackLightLEDPin string `xml:"lcdbacklightpin"`
RsPin int `xml:"lcdrspin"`
EsPin int `xml:"lcdepin"`
D4Pin int `xml:"lcdd4pin"`
D5Pin int `xml:"lcdd5pin"`
D6Pin int `xml:"lcdd6pin"`
D7Pin int `xml:"lcdd7pin"`
}
type OLED struct {
XMLName xml.Name `xml:"oled"`
OLEDEnabled bool `xml:"enabled,attr"`
OLEDInterfacetype string `xml:"oledinterfacetype"`
OLEDDisplayRows int `xml:"oleddisplayrows"`
OLEDDisplayColumns uint8 `xml:"oleddisplaycolumns"`
OLEDDefaultI2cBus int `xml:"oleddefaulti2cbus"`
OLEDDefaultI2cAddress uint8 `xml:"oleddefaulti2caddress"`
OLEDScreenWidth int `xml:"oledscreenwidth"`
OLEDScreenHeight int `xml:"oledscreenheight"`
OLEDCommandColumnAddressing int `xml:"oledcommandcolumnaddressing"`
OLEDAddressBasePageStart int `xml:"oledaddressbasepagestart"`
OLEDCharLength int `xml:"oledcharlength"`
OLEDStartColumn int `xml:"oledstartcolumn"`
}
type GPS struct {
XMLName xml.Name `xml:"gps"`
GpsEnabled 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"`
}
type PanicFunction struct {
XMLName xml.Name `xml:"panicfunction"`
PEnabled bool `xml:"enabled,attr"`
PMessage string `xml:"panicmessage"`
PRecursive string `xml:"recursivesendmessage"`
PFilenameAndPath string `xml:"filenameandpath"`
PVolume float32 `xml:"volume"`
PSendIdent bool `xml:"sendident"`
PSendGpsLocation bool `xml:"sendgpslocation"`
PTxLockEnabled bool `xml:"txlockenabled"`
PTxlockTimeOutSecs uint `xml:"txlocktimeoutsecs"`
}
type AudioRecordFunction struct {
XMLName xml.Name `xml:"audiorecordfunction"` // New
AudioRecordEnabled bool `xml:"enabled,attr"` // New
AudioRecordOnStart bool `xml:"recordonstart"` // New
AudioRecordMode string `xml:"recordmode"` // New
AudioRecordTimeout int64 `xml:"recordtimeout"` // New
AudioRecordFromOutput string `xml:"recordfromoutput"` // New
AudioRecordFromInput string `xml:"recordfrominput"` // New
AudioRecordMicTimeout int64 `xml:"recordmictimeout"` // New
AudioRecordSoft string `xml:"recordsoft"` // New
AudioRecordSavePath string `xml:"recordsavepath"` // New
AudioRecordArchivePath string `xml:"recordarchivepath"` // New
AudioRecordProfile string `xml:"recordprofile"` // New
AudioRecordFileFormat string `xml:"recordfileformat"` // New
AudioRecordChunkSize string `xml:"recordchunksize"` // New
}
type Serialcomm struct {
XMLName xml.Name `xml:"serialcomm"`
Serialcommenable bool `xml:"enabled,attr"`
Serialport string `xml:"serialport"`
Serialpttmode string `xml:"serialpttmode"`
Pttdefault bool `xml:"pttdefault"`
Sqldefault bool `xml:"sqldefault"`
Dsrdefault bool `xml:"dsrdefault"`
Dsralarmenable bool `xml:"dsralarmenable"`
Dtrreference bool `xml:"dtrreference"`
}
func readxmlconfig(file string) error {
var counter int = 0
xmlFile, err := os.Open(file)
if err != nil {
return errors.New(fmt.Sprintf("cannot open configuration file "+filepath.Base(file), err))
}
log.Println("info: Successfully Opened file " + filepath.Base(file))
defer xmlFile.Close()
byteValue, _ := ioutil.ReadAll(xmlFile)
var document Document
err = xml.Unmarshal(byteValue, &document)
if err != nil {
errors.New(fmt.Sprintf("File "+filepath.Base(file)+" formatting error Please fix! ", err))
}
log.Println("Document : " + document.Type)
for i := 0; i < len(document.Accounts.Accounts); i++ {
if document.Accounts.Accounts[i].Default == true {
Name = append(Name, document.Accounts.Accounts[i].Name)
Server = append(Server, document.Accounts.Accounts[i].ServerAndPort)
Username = append(Username, document.Accounts.Accounts[i].UserName)
Password = append(Password, document.Accounts.Accounts[i].Password)
Insecure = append(Insecure, document.Accounts.Accounts[i].Insecure)
Certificate = append(Certificate, document.Accounts.Accounts[i].Certificate)
Channel = append(Channel, document.Accounts.Accounts[i].Channel)
Ident = append(Ident, document.Accounts.Accounts[i].Ident)
counter++
}
}
if counter == 0 {
log.Fatal("No Default Accounts Found! Please Add at least 1 Default Account in XML File")
}
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 {
// log.Println("Error collecting abs path: " + err.Error())
// defaultConfPath = "/tmp"
log.Fatal("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()
}
// Set our default sharefile path
defaultSharePath := "/tmp"
dir := filepath.Dir(exec)
//Check for soundfiles directory in various locations
// First, check env for $GOPATH and check in the hardcoded talkkonnect/talkkonnect dir
if os.Getenv("GOPATH") != "" {
defaultRepo := os.Getenv("GOPATH") + "/src/github.com/HVelosoETI/talkkonnect"
if stat, err := os.Stat(defaultRepo); err == nil && stat.IsDir() {
defaultSharePath = defaultRepo
}
}
// Next, check the same dir as executable for 'soundfiles'
if stat, err := os.Stat(dir + "/soundfiles"); err == nil && stat.IsDir() {
defaultSharePath = dir
}
// Last, if its in a bin directory, we check for ../share/talkkonnect/ and prioritize it if it exists
if strings.HasSuffix(dir, "bin") {
shareDir := filepath.Dir(dir) + "/share/" + filepath.Base(exec)
if stat, err := os.Stat(shareDir); err == nil && stat.IsDir() {
defaultSharePath = shareDir
}
}
OutputDevice = document.Global.Software.Settings.OutputDevice
DefaultOptVolume = document.Global.Software.Settings.DefaultOptVolume
LogFilenameAndPath = document.Global.Software.Settings.LogFilenameAndPath
Logging = document.Global.Software.Settings.Logging
if strings.ToLower(Logging) != "screen" && LogFilenameAndPath == "" {
LogFilenameAndPath = defaultLogPath
}
Daemonize = document.Global.Software.Settings.Daemonize
CancellableStream = document.Global.Software.Settings.CancellableStream
SimplexWithMute = document.Global.Software.Settings.SimplexWithMute
TxCounter = document.Global.Software.Settings.TxCounter
APEnabled = document.Global.Software.AutoProvisioning.APEnabled
TkID = document.Global.Software.AutoProvisioning.TkID
URL = document.Global.Software.AutoProvisioning.URL
SaveFilePath = document.Global.Software.AutoProvisioning.SaveFilePath
SaveFilename = document.Global.Software.AutoProvisioning.SaveFilename
if APEnabled && SaveFilePath == "" {
SaveFilePath = defaultConfPath
}
if APEnabled && SaveFilename == "" {
SaveFilename = filepath.Base(exec) + ".xml" //Should default to talkkonnect.xml
}
BeaconEnabled = document.Global.Software.Beacon.BeaconEnabled
BeaconTimerSecs = document.Global.Software.Beacon.BeaconTimerSecs
BeaconFilenameAndPath = document.Global.Software.Beacon.BeaconFilenameAndPath
if BeaconEnabled && BeaconFilenameAndPath == "" {
path := defaultSharePath + "/soundfiles/voiceprompts/Beacon.wav"
if _, err := os.Stat(path); err == nil {
BeaconFilenameAndPath = path
}
}
BVolume = document.Global.Software.Beacon.BVolume
TTSEnabled = document.Global.Software.TTS.TTSEnabled
TTSVolumeLevel = document.Global.Software.TTS.TTSVolumeLevel
TTSParticipants = document.Global.Software.TTS.TTSParticipants
TTSChannelUp = document.Global.Software.TTS.TTSChannelUp
if TTSChannelUp && TTSChannelUpFilenameAndPath == "" {
path := defaultSharePath + "/soundfiles/voiceprompts/ChannelUp.wav"
if _, err := os.Stat(path); err == nil {
TTSChannelUpFilenameAndPath = path
}
}
TTSChannelUpFilenameAndPath = document.Global.Software.TTS.TTSChannelUpFilenameAndPath
TTSChannelDown = document.Global.Software.TTS.TTSChannelDown
TTSChannelDownFilenameAndPath = document.Global.Software.TTS.TTSChannelDownFilenameAndPath
if TTSChannelDown && TTSChannelDownFilenameAndPath == "" {
path := defaultSharePath + "/soundfiles/voiceprompts/ChannelDown.wav"
if _, err := os.Stat(path); err == nil {
TTSChannelDownFilenameAndPath = path
}
}
TTSMuteUnMuteSpeaker = document.Global.Software.TTS.TTSMuteUnMuteSpeaker
TTSMuteUnMuteSpeakerFilenameAndPath = document.Global.Software.TTS.TTSMuteUnMuteSpeakerFilenameAndPath
if TTSMuteUnMuteSpeaker && TTSMuteUnMuteSpeakerFilenameAndPath == "" {
path := defaultSharePath + "/soundfiles/voiceprompts/MuteUnMuteSpeaker.wav"
if _, err := os.Stat(path); err == nil {
TTSMuteUnMuteSpeakerFilenameAndPath = path
}
}
TTSCurrentVolumeLevel = document.Global.Software.TTS.TTSCurrentVolumeLevel
TTSCurrentVolumeLevelFilenameAndPath = document.Global.Software.TTS.TTSCurrentVolumeLevelFilenameAndPath
if TTSCurrentVolumeLevel && TTSCurrentVolumeLevelFilenameAndPath == "" {
path := defaultSharePath + "/soundfiles/voiceprompts/CurrentVolumeLevel.wav"
if _, err := os.Stat(path); err == nil {
TTSCurrentVolumeLevelFilenameAndPath = path
}
}
TTSDigitalVolumeUp = document.Global.Software.TTS.TTSDigitalVolumeUp
TTSDigitalVolumeUpFilenameAndPath = document.Global.Software.TTS.TTSDigitalVolumeUpFilenameAndPath
if TTSDigitalVolumeUp && TTSDigitalVolumeUpFilenameAndPath == "" {
path := defaultSharePath + "/soundfiles/voiceprompts/DigitalVolumeUp.wav"
if _, err := os.Stat(path); err == nil {
TTSDigitalVolumeUpFilenameAndPath = path
}
}
TTSDigitalVolumeDown = document.Global.Software.TTS.TTSDigitalVolumeDown
TTSDigitalVolumeDownFilenameAndPath = document.Global.Software.TTS.TTSDigitalVolumeDownFilenameAndPath
if TTSDigitalVolumeDown && TTSDigitalVolumeDownFilenameAndPath == "" {
path := defaultSharePath + "/soundfiles/voiceprompts/DigitalVolumeDown.wav"
if _, err := os.Stat(path); err == nil {
TTSDigitalVolumeDownFilenameAndPath = path
}
}
TTSListServerChannels = document.Global.Software.TTS.TTSListServerChannels
TTSListServerChannelsFilenameAndPath = document.Global.Software.TTS.TTSListServerChannelsFilenameAndPath
if TTSListServerChannels && TTSListServerChannelsFilenameAndPath == "" {
path := defaultSharePath + "/soundfiles/voiceprompts/ListServerChannels.wav"
if _, err := os.Stat(path); err == nil {
TTSListServerChannelsFilenameAndPath = path
}
}
TTSStartTransmitting = document.Global.Software.TTS.TTSStartTransmitting
TTSStartTransmittingFilenameAndPath = document.Global.Software.TTS.TTSStartTransmittingFilenameAndPath
if TTSStartTransmitting && TTSStartTransmittingFilenameAndPath == "" {
path := defaultSharePath + "/soundfiles/voiceprompts/StartTransmitting.wav"
if _, err := os.Stat(path); err == nil {
TTSStartTransmittingFilenameAndPath = path
}
}
TTSStopTransmitting = document.Global.Software.TTS.TTSStopTransmitting
TTSStopTransmittingFilenameAndPath = document.Global.Software.TTS.TTSStopTransmittingFilenameAndPath
if TTSStopTransmitting && TTSStopTransmittingFilenameAndPath == "" {
path := defaultSharePath + "/soundfiles/voiceprompts/StopTransmitting.wav"
if _, err := os.Stat(path); err == nil {
TTSStopTransmittingFilenameAndPath = path
}
}
TTSListOnlineUsers = document.Global.Software.TTS.TTSListOnlineUsers
TTSListOnlineUsersFilenameAndPath = document.Global.Software.TTS.TTSListOnlineUsersFilenameAndPath
if TTSListOnlineUsers && TTSListOnlineUsersFilenameAndPath == "" {
path := defaultSharePath + "/soundfiles/voiceprompts/ListOnlineUsers.wav"
if _, err := os.Stat(path); err == nil {
TTSListOnlineUsersFilenameAndPath = path
}
}
TTSPlayChimes = document.Global.Software.TTS.TTSPlayChimes
TTSPlayChimesFilenameAndPath = document.Global.Software.TTS.TTSPlayChimesFilenameAndPath
if TTSPlayChimes && TTSPlayChimesFilenameAndPath == "" {
path := defaultSharePath + "/soundfiles/voiceprompts/PlayChimes.wav"
if _, err := os.Stat(path); err == nil {
TTSPlayChimesFilenameAndPath = path
}
}
TTSRequestGpsPosition = document.Global.Software.TTS.TTSRequestGpsPosition
TTSRequestGpsPositionFilenameAndPath = document.Global.Software.TTS.TTSRequestGpsPositionFilenameAndPath