/
main.go
100 lines (78 loc) · 2.44 KB
/
main.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
/*
Copyright (C) 2019 Graeme Sutherland, Nodestone Limited
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package main
import (
"context"
"flag"
"fmt"
"../bitoip"
"../cwc"
"github.com/golang/glog"
)
const maxBufferSize = 508
func main() {
var cqMode = flag.Bool("cq", false, "-cq for local mode")
var configFile = flag.String("config", "/boot/cwc-station.txt", "-config <filename>")
var refAddPtr = flag.String("ref", "", "-ref <host>:<port>")
var serialDevice = flag.String("serial", "", "-serial=<serial-device-name>")
var echo = flag.Bool("echo", false, "-echo turns on remote echo of all sent morse")
var channel = flag.Int("ch", -1, "-ch <n> to connect to the channel n")
var callsign = flag.String("de", "", "-de <callsign>")
var noIO = flag.Bool("noio", false, "-noio uses fake morse IO connections")
// parse Command line
flag.Parse()
// read Config file and defaults
config := cwc.ReadConfig(*configFile)
// Network mode
if *cqMode {
config.NetworkMode = "local"
}
// Reflector address
if len(*refAddPtr) > 0 {
config.ReflectorAddress = *refAddPtr
}
if len(*serialDevice) > 0 {
config.SerialDevice = *serialDevice
config.HardwareType = "Serial"
}
if *echo {
config.RemoteEcho = true
}
if *channel >= 0 {
config.Channel = bitoip.ChannelIdType(*channel)
}
if len(*callsign) > 0 {
config.Callsign = *callsign
}
if *noIO {
config.HardwareType = "None"
}
// context
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
fmt.Println(DisplayVersion())
glog.Info(DisplayVersion())
// Morse Hardware
var morseIO cwc.IO
if config.HardwareType == "Serial" {
morseIO = cwc.NewSerialIO(config)
} else if config.HardwareType == "None" {
morseIO = cwc.NewNullIO(config)
} else if config.KeyType == "keyer" {
morseIO = cwc.NewKeyer(config)
} else {
morseIO = cwc.NewPiGPIO(config)
}
cwc.StationClient(ctx, config, morseIO)
}