Skip to content

Commit 87f178b

Browse files
committed
Made spList a method of SpPortList
1 parent b0e9d0a commit 87f178b

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

hub.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ func checkCmd(m []byte) {
177177
// will catch send and sendnobuf and sendraw
178178
go spWrite(s)
179179
} else if strings.HasPrefix(sl, "list") {
180-
go spList()
180+
go serialPorts.List()
181181
} else if strings.HasPrefix(sl, "downloadtool") {
182182
go func() {
183183
args := strings.Split(s, " ")

serial.go

+6-7
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,12 @@ func write(wr writeRequest) {
120120
// no default since we alredy verified in spWrite()
121121
}
122122

123-
// spList broadcasts a Json representation of the ports found
124-
func spList() {
125-
var ls []byte
126-
var err error
127-
serialPorts.Mu.Lock()
128-
ls, err = json.MarshalIndent(&serialPorts, "", "\t")
129-
serialPorts.Mu.Unlock()
123+
// List broadcasts a Json representation of the ports found
124+
func (sp *SpPortList) List() {
125+
sp.Mu.Lock()
126+
ls, err := json.MarshalIndent(&serialPorts, "", "\t")
127+
sp.Mu.Unlock()
128+
130129
if err != nil {
131130
//log.Println(err)
132131
h.broadcastSys <- []byte("Error creating json on port list " +

serialport.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ func (p *serport) writerNoBuf() {
233233
h.broadcastSys <- []byte(msgstr)
234234
p.portIo.Close()
235235
updateSerialPortList()
236-
spList()
236+
serialPorts.List()
237237
}
238238

239239
// this method runs as its own thread because it's instantiated
@@ -328,7 +328,7 @@ func spHandlerOpen(portname string, baud int, buftype string) {
328328
defer func() { sh.unregister <- p }()
329329

330330
updateSerialPortList()
331-
spList()
331+
serialPorts.List()
332332

333333
// this is internally buffered thread to not send to serial port if blocked
334334
go p.writerBuffered()
@@ -340,7 +340,7 @@ func spHandlerOpen(portname string, baud int, buftype string) {
340340
p.reader(buftype)
341341

342342
updateSerialPortList()
343-
spList()
343+
serialPorts.List()
344344
}
345345

346346
func spHandlerClose(p *serport) {
@@ -353,5 +353,5 @@ func spCloseReal(p *serport) {
353353
p.bufferwatcher.Close()
354354
p.portIo.Close()
355355
updateSerialPortList()
356-
spList()
356+
serialPorts.List()
357357
}

0 commit comments

Comments
 (0)