Skip to content

Commit 366846c

Browse files
committed
Cleanup original project
1 parent 1ec989f commit 366846c

File tree

4 files changed

+8
-260
lines changed

4 files changed

+8
-260
lines changed

hub.go

+6-98
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,11 @@ type hub struct {
3535
}
3636

3737
var h = hub{
38-
// buffered. go with 1000 cuz should never surpass that
3938
broadcast: make(chan []byte, 1000),
4039
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),
4743
}
4844

4945
func (h *hub) run() {
@@ -74,10 +70,7 @@ func (h *hub) run() {
7470
}()
7571
case m := <-h.broadcast:
7672
if len(m) > 0 {
77-
//log.Print(string(m))
78-
//log.Print(h.broadcast)
7973
checkCmd(m)
80-
//log.Print("-----")
8174

8275
for c := range h.connections {
8376
select {
@@ -120,16 +113,6 @@ func checkCmd(m []byte) {
120113

121114
if strings.HasPrefix(sl, "open") {
122115

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-
133116
args := strings.Split(s, " ")
134117
if len(args) < 3 {
135118
go spErr("You did not specify a port and baud rate in your open cmd")
@@ -154,7 +137,7 @@ func checkCmd(m []byte) {
154137
buftype := strings.Replace(args[3], "\n", "", -1)
155138
bufferAlgorithm = buftype
156139
}
157-
go spHandlerOpen(args[1], baud, bufferAlgorithm, isSecondary)
140+
go spHandlerOpen(args[1], baud, bufferAlgorithm)
158141

159142
} else if strings.HasPrefix(sl, "close") {
160143

@@ -173,20 +156,9 @@ func checkCmd(m []byte) {
173156
log.Println("{\"uploadStatus\": \"Killed\"}")
174157
}()
175158

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-
184159
} else if strings.HasPrefix(sl, "send") {
185160
// will catch send and sendnobuf
186-
187-
//args := strings.Split(s, "send ")
188161
go spWrite(s)
189-
190162
} else if strings.HasPrefix(sl, "list") {
191163
go spList(false)
192164
go spList(true)
@@ -237,8 +209,6 @@ func checkCmd(m []byte) {
237209
go logAction(sl)
238210
} else if strings.HasPrefix(sl, "baudrate") {
239211
go spBaudRates()
240-
} else if strings.HasPrefix(sl, "broadcast") {
241-
go broadcast(s)
242212
} else if strings.HasPrefix(sl, "restart") {
243213
log.Println("Received restart from the daemon. Why? Boh")
244214
quitSystray()
@@ -257,8 +227,6 @@ func checkCmd(m []byte) {
257227
} else {
258228
go spErr("Could not understand command.")
259229
}
260-
261-
//log.Print("Done with checkCmd")
262230
}
263231

264232
func logAction(sl string) {
@@ -321,22 +289,7 @@ func restart(path string) {
321289
h.broadcastSys <- []byte("{\"Restarting\" : true}")
322290

323291
// 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
340293
exePath, err3 := osext.Executable()
341294
if err3 != nil {
342295
log.Printf("Error getting exe path using osext lib. err: %v\n", err3)
@@ -349,29 +302,16 @@ func restart(path string) {
349302
}
350303

351304
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-
}*/
364305

365306
hiberString := ""
366307
if *hibernate == true {
367308
hiberString = "-hibernate"
368309
}
369310

370-
cmd = exec.Command(exePath, "-ls", "-regex", *regExpFilter, "-gc", *gcType, hiberString)
311+
cmd := exec.Command(exePath, "-ls", "-regex", *regExpFilter, "-gc", *gcType, hiberString)
371312

372313
fmt.Println(cmd)
373314

374-
//cmd := exec.Command("./serial-port-json-server", "ls")
375315
err := cmd.Start()
376316
if err != nil {
377317
log.Printf("Got err restarting spjs: %v\n", err)
@@ -380,36 +320,4 @@ func restart(path string) {
380320
h.broadcastSys <- []byte("{\"Restarted\" : true}")
381321
}
382322
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
415323
}

queue.go

-143
This file was deleted.

seriallist.go

-4
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ type OsSerialPort struct {
2323

2424
func GetList(network bool) ([]OsSerialPort, error) {
2525

26-
//log.Println("Doing GetList()")
27-
2826
if network {
2927
netportList, err := GetNetworkList()
3028
return netportList, err
@@ -70,7 +68,5 @@ func GetList(network bool) ([]OsSerialPort, error) {
7068
}
7169

7270
return arrPorts, err
73-
//log.Printf("Done doing GetList(). arrPorts:%v\n", arrPorts)
7471
}
75-
7672
}

serialport.go

+2-15
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,6 @@ func (p *serport) writerNoBuf() {
284284
}
285285

286286
log.Print("Just wrote ", n2, " bytes to serial: ", string(data.data))
287-
//log.Print(n2)
288-
//log.Print(" bytes to serial: ")
289-
//log.Print(data)
290287
if err != nil {
291288
errstr := "Error writing to " + p.portConf.Name + " " + err.Error() + " Closing port."
292289
log.Print(errstr)
@@ -302,7 +299,7 @@ func (p *serport) writerNoBuf() {
302299
spList(false)
303300
}
304301

305-
func spHandlerOpen(portname string, baud int, buftype string, isSecondary bool) {
302+
func spHandlerOpen(portname string, baud int, buftype string) {
306303

307304
log.Print("Inside spHandler")
308305

@@ -315,20 +312,10 @@ func spHandlerOpen(portname string, baud int, buftype string, isSecondary bool)
315312
out.WriteString(" baud")
316313
log.Print(out.String())
317314

318-
//h.broadcast <- []byte("Opened a serial port ")
319-
//h.broadcastSys <- out.Bytes()
320-
321-
isPrimary := true
322-
if isSecondary {
323-
isPrimary = false
324-
}
325-
326315
conf := &SerialConfig{Name: portname, Baud: baud, RtsOn: true}
327316

328317
mode := &serial.Mode{
329318
BaudRate: baud,
330-
//Vmin: 0,
331-
//Vtimeout: 1,
332319
}
333320

334321
sp, err := serial.Open(portname, mode)
@@ -344,7 +331,7 @@ func spHandlerOpen(portname string, baud int, buftype string, isSecondary bool)
344331
log.Print("Opened port successfully")
345332
//p := &serport{send: make(chan []byte, 256), portConf: conf, portIo: sp}
346333
// we can go up to 256,000 lines of gcode in the buffer
347-
p := &serport{sendBuffered: make(chan Cmd, 256000), sendNoBuf: make(chan Cmd), portConf: conf, portIo: sp, BufferType: buftype, IsPrimary: isPrimary, IsSecondary: isSecondary}
334+
p := &serport{sendBuffered: make(chan Cmd, 256000), sendNoBuf: make(chan Cmd), portConf: conf, portIo: sp, BufferType: buftype}
348335

349336
var bw Bufferflow
350337

0 commit comments

Comments
 (0)