16
16
package main
17
17
18
18
import (
19
- "bytes"
20
19
"encoding/json"
21
20
"fmt"
22
21
"html"
@@ -31,7 +30,6 @@ import (
31
30
"github.com/arduino/arduino-create-agent/tools"
32
31
"github.com/arduino/arduino-create-agent/upload"
33
32
log "github.com/sirupsen/logrus"
34
- "go.bug.st/serial"
35
33
)
36
34
37
35
type hub struct {
@@ -341,90 +339,6 @@ func (h *hub) garbageCollection() {
341
339
h .memoryStats ()
342
340
}
343
341
344
- func (h * hub ) spHandlerOpen (portname string , baud int , buftype string ) {
345
-
346
- log .Print ("Inside spHandler" )
347
-
348
- var out bytes.Buffer
349
-
350
- out .WriteString ("Opening serial port " )
351
- out .WriteString (portname )
352
- out .WriteString (" at " )
353
- out .WriteString (strconv .Itoa (baud ))
354
- out .WriteString (" baud" )
355
- log .Print (out .String ())
356
-
357
- conf := & SerialConfig {Name : portname , Baud : baud , RtsOn : true }
358
-
359
- mode := & serial.Mode {
360
- BaudRate : baud ,
361
- }
362
-
363
- sp , err := serial .Open (portname , mode )
364
- log .Print ("Just tried to open port" )
365
- if err != nil {
366
- //log.Fatal(err)
367
- log .Print ("Error opening port " + err .Error ())
368
- //h.broadcastSys <- []byte("Error opening port. " + err.Error())
369
- h .broadcastSys <- []byte ("{\" Cmd\" :\" OpenFail\" ,\" Desc\" :\" Error opening port. " + err .Error () + "\" ,\" Port\" :\" " + conf .Name + "\" ,\" Baud\" :" + strconv .Itoa (conf .Baud ) + "}" )
370
-
371
- return
372
- }
373
- log .Print ("Opened port successfully" )
374
- //p := &serport{send: make(chan []byte, 256), portConf: conf, portIo: sp}
375
- // we can go up to 256,000 lines of gcode in the buffer
376
- p := & serport {
377
- sendBuffered : make (chan string , 256000 ),
378
- sendNoBuf : make (chan []byte ),
379
- sendRaw : make (chan string ),
380
- portConf : conf ,
381
- portIo : sp ,
382
- portName : portname ,
383
- BufferType : buftype ,
384
- }
385
-
386
- p .OnMessage = func (msg []byte ) {
387
- h .broadcastSys <- msg
388
- }
389
- p .OnClose = func (port * serport ) {
390
- h .serialPortList .MarkPortAsClosed (p .portName )
391
- h .serialPortList .List ()
392
- }
393
-
394
- var bw Bufferflow
395
-
396
- switch buftype {
397
- case "timed" :
398
- bw = NewBufferflowTimed (portname , h .broadcastSys )
399
- case "timedraw" :
400
- bw = NewBufferflowTimedRaw (portname , h .broadcastSys )
401
- case "default" :
402
- bw = NewBufferflowDefault (portname , h .broadcastSys )
403
- default :
404
- log .Panicf ("unknown buffer type: %s" , buftype )
405
- }
406
-
407
- bw .Init ()
408
- p .bufferwatcher = bw
409
-
410
- h .serialHub .Register (p )
411
- defer h .serialHub .Unregister (p )
412
-
413
- h .serialPortList .MarkPortAsOpened (portname )
414
- h .serialPortList .List ()
415
-
416
- // this is internally buffered thread to not send to serial port if blocked
417
- go p .writerBuffered ()
418
- // this is thread to send to serial port regardless of block
419
- go p .writerNoBuf ()
420
- // this is thread to send to serial port but with base64 decoding
421
- go p .writerRaw ()
422
-
423
- p .reader (buftype )
424
-
425
- h .serialPortList .List ()
426
- }
427
-
428
342
func (h * hub ) spErr (err string ) {
429
343
h .broadcastSys <- []byte ("{\" Error\" : \" " + err + "\" }" )
430
344
}
0 commit comments