@@ -35,15 +35,11 @@ type hub struct {
35
35
}
36
36
37
37
var h = hub {
38
- // buffered. go with 1000 cuz should never surpass that
39
38
broadcast : make (chan []byte , 1000 ),
40
39
broadcastSys : make (chan []byte , 1000 ),
41
- // non-buffered
42
- //broadcast: make(chan []byte),
43
- //broadcastSys: make(chan []byte),
44
- register : make (chan * connection ),
45
- unregister : make (chan * connection ),
46
- connections : make (map [* connection ]bool ),
40
+ register : make (chan * connection ),
41
+ unregister : make (chan * connection ),
42
+ connections : make (map [* connection ]bool ),
47
43
}
48
44
49
45
func (h * hub ) run () {
@@ -74,10 +70,7 @@ func (h *hub) run() {
74
70
}()
75
71
case m := <- h .broadcast :
76
72
if len (m ) > 0 {
77
- //log.Print(string(m))
78
- //log.Print(h.broadcast)
79
73
checkCmd (m )
80
- //log.Print("-----")
81
74
82
75
for c := range h .connections {
83
76
select {
@@ -120,16 +113,6 @@ func checkCmd(m []byte) {
120
113
121
114
if strings .HasPrefix (sl , "open" ) {
122
115
123
- // check if user wants to open this port as a secondary port
124
- // this doesn't mean much other than allowing the UI to show
125
- // a port as primary and make other ports sort of act less important
126
- isSecondary := false
127
- if strings .HasPrefix (s , "open secondary" ) {
128
- isSecondary = true
129
- // swap out the word secondary
130
- s = strings .Replace (s , "open secondary" , "open" , 1 )
131
- }
132
-
133
116
args := strings .Split (s , " " )
134
117
if len (args ) < 3 {
135
118
go spErr ("You did not specify a port and baud rate in your open cmd" )
@@ -154,7 +137,7 @@ func checkCmd(m []byte) {
154
137
buftype := strings .Replace (args [3 ], "\n " , "" , - 1 )
155
138
bufferAlgorithm = buftype
156
139
}
157
- go spHandlerOpen (args [1 ], baud , bufferAlgorithm , isSecondary )
140
+ go spHandlerOpen (args [1 ], baud , bufferAlgorithm )
158
141
159
142
} else if strings .HasPrefix (sl , "close" ) {
160
143
@@ -173,20 +156,9 @@ func checkCmd(m []byte) {
173
156
log .Println ("{\" uploadStatus\" : \" Killed\" }" )
174
157
}()
175
158
176
- } else if strings .HasPrefix (sl , "sendjsonraw" ) {
177
- // will catch sendjsonraw
178
- go spWriteJsonRaw (s )
179
-
180
- } else if strings .HasPrefix (sl , "sendjson" ) {
181
- // will catch sendjson
182
- go spWriteJson (s )
183
-
184
159
} else if strings .HasPrefix (sl , "send" ) {
185
160
// will catch send and sendnobuf
186
-
187
- //args := strings.Split(s, "send ")
188
161
go spWrite (s )
189
-
190
162
} else if strings .HasPrefix (sl , "list" ) {
191
163
go spList (false )
192
164
go spList (true )
@@ -237,8 +209,6 @@ func checkCmd(m []byte) {
237
209
go logAction (sl )
238
210
} else if strings .HasPrefix (sl , "baudrate" ) {
239
211
go spBaudRates ()
240
- } else if strings .HasPrefix (sl , "broadcast" ) {
241
- go broadcast (s )
242
212
} else if strings .HasPrefix (sl , "restart" ) {
243
213
log .Println ("Received restart from the daemon. Why? Boh" )
244
214
quitSystray ()
@@ -257,8 +227,6 @@ func checkCmd(m []byte) {
257
227
} else {
258
228
go spErr ("Could not understand command." )
259
229
}
260
-
261
- //log.Print("Done with checkCmd")
262
230
}
263
231
264
232
func logAction (sl string ) {
@@ -321,22 +289,7 @@ func restart(path string) {
321
289
h .broadcastSys <- []byte ("{\" Restarting\" : true}" )
322
290
323
291
// figure out current path of executable so we know how to restart
324
- // this process
325
- /*
326
- dir, err2 := filepath.Abs(filepath.Dir(os.Args[0]))
327
- if err2 != nil {
328
- //log.Fatal(err2)
329
- fmt.Printf("Error getting executable file path. err: %v\n", err2)
330
- }
331
- fmt.Printf("The path to this exe is: %v\n", dir)
332
-
333
- // alternate approach
334
- _, filename, _, _ := runtime.Caller(1)
335
- f, _ := os.Open(path.Join(path.Dir(filename), "serial-port-json-server"))
336
- fmt.Println(f)
337
- */
338
-
339
- // using osext
292
+ // this process using osext
340
293
exePath , err3 := osext .Executable ()
341
294
if err3 != nil {
342
295
log .Printf ("Error getting exe path using osext lib. err: %v\n " , err3 )
@@ -349,29 +302,16 @@ func restart(path string) {
349
302
}
350
303
351
304
exePath = strings .Trim (exePath , "\n " )
352
- // figure out garbageCollection flag
353
- //isGcFlag := "false"
354
-
355
- var cmd * exec.Cmd
356
-
357
- /*if *isGC {
358
- //isGcFlag = "true"
359
- cmd = exec.Command(exePath, "-ls", "-addr", *addr, "-regex", *regExpFilter, "-gc")
360
- } else {
361
- cmd = exec.Command(exePath, "-ls", "-addr", *addr, "-regex", *regExpFilter)
362
-
363
- }*/
364
305
365
306
hiberString := ""
366
307
if * hibernate == true {
367
308
hiberString = "-hibernate"
368
309
}
369
310
370
- cmd = exec .Command (exePath , "-ls" , "-regex" , * regExpFilter , "-gc" , * gcType , hiberString )
311
+ cmd : = exec .Command (exePath , "-ls" , "-regex" , * regExpFilter , "-gc" , * gcType , hiberString )
371
312
372
313
fmt .Println (cmd )
373
314
374
- //cmd := exec.Command("./serial-port-json-server", "ls")
375
315
err := cmd .Start ()
376
316
if err != nil {
377
317
log .Printf ("Got err restarting spjs: %v\n " , err )
@@ -380,36 +320,4 @@ func restart(path string) {
380
320
h .broadcastSys <- []byte ("{\" Restarted\" : true}" )
381
321
}
382
322
log .Fatal ("Exited current spjs for restart" )
383
- //log.Printf("Waiting for command to finish...")
384
- //err = cmd.Wait()
385
- //log.Printf("Command finished with error: %v", err)
386
- }
387
-
388
- type CmdBroadcast struct {
389
- Cmd string
390
- Msg string
391
- }
392
-
393
- func broadcast (arg string ) {
394
- // we will get a string of broadcast asdf asdf asdf
395
- log .Println ("Inside broadcast arg: " + arg )
396
- arg = strings .TrimPrefix (arg , " " )
397
- //log.Println("arg after trim: " + arg)
398
- args := strings .SplitN (arg , " " , 2 )
399
- if len (args ) != 2 {
400
- errstr := "Could not parse broadcast command: " + arg
401
- log .Println (errstr )
402
- spErr (errstr )
403
- return
404
- }
405
- broadcastcmd := strings .Trim (args [1 ], " " )
406
- log .Println ("The broadcast cmd is:" + broadcastcmd + "---" )
407
-
408
- bcmd := CmdBroadcast {
409
- Cmd : "Broadcast" ,
410
- Msg : broadcastcmd ,
411
- }
412
- json , _ := json .Marshal (bcmd )
413
- log .Printf ("bcmd:%v\n " , string (json ))
414
- h .broadcastSys <- json
415
323
}
0 commit comments