-
Notifications
You must be signed in to change notification settings - Fork 0
/
interactive_control.go
122 lines (99 loc) · 2.53 KB
/
interactive_control.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
package vv104
import (
"bufio"
"os"
"strings"
)
func (state State) readCommandsFromStdIn() {
logDebug.Println("readCommandsFromStdIn started ******")
sc := bufio.NewScanner(os.Stdin)
state.Wg.Add(1)
defer state.Wg.Done()
for sc.Scan() {
select {
default:
state.Chans.CommandsFromStdin <- sc.Text()
case <-state.Ctx.Done():
logDebug.Println("readCommandsFromStdIn received Done(), returns")
return
}
}
}
func (state *State) evaluateInteractiveCommands() {
logDebug.Println("evaluateCommandsFromStdIn started")
defer logDebug.Println("evaluateCommandsFromStdIn returned")
state.Wg.Add(1)
defer state.Wg.Done()
for {
select {
case input := <-state.Chans.CommandsFromStdin:
inputSplit := strings.Split(input, " ")
state.evaluateInputSplit(inputSplit)
case <-state.Ctx.Done():
logDebug.Println("evaluateCommandsFromStdIn received Done(), returns")
return
}
}
}
func (state *State) evaluateInputSplit(inputSplit []string) {
var apdu Apdu
switch inputArgsCount := len(inputSplit); {
case inputArgsCount == 1:
switch inputSplit[0] {
case "restart":
logInfo.Println("called restart")
state.Cancel()
case "exit":
logInfo.Println("Exiting")
state.Cancel()
state.Wg.Wait()
os.Exit(1)
case "disconnect":
logInfo.Println("Disconnecting")
state.manualDisconnect = true
state.Cancel()
case "startdt_act":
apdu = NewApdu()
apdu.Apci.FrameFormat = UFormatFrame
apdu.Apci.UFormat = StartDTAct
state.Chans.ToSend <- apdu
case "startdt_con":
apdu = NewApdu()
apdu.Apci.FrameFormat = UFormatFrame
apdu.Apci.UFormat = StartDTCon
state.Chans.ToSend <- apdu
case "stopdt_act":
apdu = NewApdu()
apdu.Apci.FrameFormat = UFormatFrame
apdu.Apci.UFormat = StopDTAct
state.Chans.ToSend <- apdu
case "stopdt_con":
apdu = NewApdu()
apdu.Apci.FrameFormat = UFormatFrame
apdu.Apci.UFormat = StopDTCon
state.Chans.ToSend <- apdu
case "testfr_act":
apdu = NewApdu()
apdu.Apci.FrameFormat = UFormatFrame
apdu.Apci.UFormat = TestFRAct
state.Chans.ToSend <- apdu
case "testfr_con":
apdu = NewApdu()
apdu.Apci.FrameFormat = UFormatFrame
apdu.Apci.UFormat = TestFRCon
state.Chans.ToSend <- apdu
case "sp": // temporarily
sp := NewApdu()
infoObj := NewInfoObj()
infoObj.Ioa = 12345
infoObj.Value = IntVal(1)
sp.Apci.FrameFormat = IFormatFrame
sp.Asdu.TypeId = M_SP_NA_1
sp.Asdu.CauseTx = Spont
sp.Asdu.Casdu = 1
sp.Asdu.AddInfoObject(infoObj)
state.Chans.ToSend <- sp
}
case inputArgsCount > 2:
}
}