@@ -61,35 +61,35 @@ type hub struct {
61
61
}
62
62
63
63
func newHub (tools * tools.Tools , systray * systray.Systray ) * hub {
64
- hub := & hub {
65
- broadcast : make (chan []byte , 1000 ),
66
- broadcastSys : make (chan []byte , 1000 ),
67
- register : make (chan * connection ),
68
- unregister : make (chan * connection ),
69
- connections : make (map [* connection ]bool ),
70
- serialHub : newSerialHub (),
71
- serialPortList : newSerialPortList (tools ),
72
- tools : tools ,
73
- systray : systray ,
74
- }
64
+ broadcastSys := make (chan []byte , 1000 )
75
65
76
- hub . serialHub . OnRegister = func (port * serport ) {
77
- hub . broadcastSys <- []byte ("{\" Cmd\" :\" Open\" ,\" Desc\" :\" Got register/open on port.\" ,\" Port\" :\" " + port .portConf .Name + "\" ,\" Baud\" :" + strconv .Itoa (port .portConf .Baud ) + ",\" BufferType\" :\" " + port .BufferType + "\" }" )
66
+ onRegister : = func (port * serport ) {
67
+ broadcastSys <- []byte ("{\" Cmd\" :\" Open\" ,\" Desc\" :\" Got register/open on port.\" ,\" Port\" :\" " + port .portConf .Name + "\" ,\" Baud\" :" + strconv .Itoa (port .portConf .Baud ) + ",\" BufferType\" :\" " + port .BufferType + "\" }" )
78
68
}
79
-
80
- hub .serialHub .OnUnregister = func (port * serport ) {
81
- hub .broadcastSys <- []byte ("{\" Cmd\" :\" Close\" ,\" Desc\" :\" Got unregister/close on port.\" ,\" Port\" :\" " + port .portConf .Name + "\" ,\" Baud\" :" + strconv .Itoa (port .portConf .Baud ) + "}" )
69
+ onUnregister := func (port * serport ) {
70
+ broadcastSys <- []byte ("{\" Cmd\" :\" Close\" ,\" Desc\" :\" Got unregister/close on port.\" ,\" Port\" :\" " + port .portConf .Name + "\" ,\" Baud\" :" + strconv .Itoa (port .portConf .Baud ) + "}" )
82
71
}
72
+ serialHub := newSerialHub (onRegister , onUnregister )
83
73
84
- hub . serialPortList . OnList = func (data []byte ) {
85
- hub . broadcastSys <- data
74
+ onList : = func (data []byte ) {
75
+ broadcastSys <- data
86
76
}
87
-
88
- hub .serialPortList .OnErr = func (err string ) {
89
- hub .broadcastSys <- []byte ("{\" Error\" :\" " + err + "\" }" )
77
+ onErr := func (err string ) {
78
+ broadcastSys <- []byte ("{\" Error\" :\" " + err + "\" }" )
90
79
}
80
+ serialPortList := newSerialPortList (tools , onList , onErr )
91
81
92
- return hub
82
+ return & hub {
83
+ broadcast : make (chan []byte , 1000 ),
84
+ broadcastSys : broadcastSys ,
85
+ register : make (chan * connection ),
86
+ unregister : make (chan * connection ),
87
+ connections : make (map [* connection ]bool ),
88
+ serialHub : serialHub ,
89
+ serialPortList : serialPortList ,
90
+ tools : tools ,
91
+ systray : systray ,
92
+ }
93
93
}
94
94
95
95
const commands = `{
@@ -216,6 +216,8 @@ func (hub *hub) checkCmd(m []byte) {
216
216
// will catch send and sendnobuf and sendraw
217
217
go hub .spWrite (s )
218
218
} else if strings .HasPrefix (sl , "list" ) {
219
+ // ports := hub.serialPortList.List()
220
+ // send to websockets the ports
219
221
go hub .serialPortList .List ()
220
222
} else if strings .HasPrefix (sl , "downloadtool" ) {
221
223
go func () {
0 commit comments