2020package sara
2121
2222import (
23+ "github.com/arduino-libraries/FirmwareUpdater/utils"
2324 serial "github.com/facchinm/go-serial"
24- "time"
25- "strings"
2625 "log"
26+ "strings"
27+ "time"
2728 //"strconv"
2829)
2930
@@ -44,7 +45,7 @@ func (flasher *Flasher) Hello() error {
4445 f .Expect ("ATE0" , "OK" , 100 )
4546 f .Expect ("ATE0" , "OK" , 100 )
4647 f .Expect ("ATE0" , "OK" , 100 )
47- _ , err := flasher .Expect ("AT" , "OK" , 100 );
48+ _ , err := flasher .Expect ("AT" , "OK" , 100 )
4849 return err
4950}
5051
@@ -65,7 +66,7 @@ func (flasher *Flasher) ExpectMinBytes(buffer string, response string, timeout i
6566
6667 start := time .Now ()
6768
68- for (( time .Since (start ) < time .Duration (timeout ) * time .Millisecond && ! strings .Contains (string (res ), response )) || (len (res ) < min_bytes ) ) {
69+ for (time .Since (start ) < time .Duration (timeout )* time .Millisecond && ! strings .Contains (string (res ), response )) || (len (res ) < min_bytes ) {
6970 data := 0
7071 partial := make ([]byte , 65535 )
7172 data , err = flasher .port .Read (partial )
@@ -79,7 +80,7 @@ func (flasher *Flasher) ExpectMinBytes(buffer string, response string, timeout i
7980 log .Println (string (res ))
8081
8182 if ! strings .Contains (string (res ), response ) {
82- return string (res ), & FlasherError {err : "Expected " + response + ", got " + string (res )}
83+ return string (res ), & FlasherError {err : "Expected " + response + ", got " + string (res )}
8384 }
8485 return string (res ), nil
8586}
@@ -104,7 +105,6 @@ func (flasher *Flasher) Write(address uint32, buffer []byte) error {
104105 return nil
105106}
106107
107-
108108// Fill buffer with data coming from serial port.
109109// Blocks until the buffer is full.
110110func (flasher * Flasher ) serialFillBuffer (buffer []byte ) error {
@@ -131,19 +131,9 @@ func (flasher *Flasher) sendCommand(payload []byte) error {
131131 return nil
132132}
133133
134- func OpenSerial (portName string ) (serial.Port , error ) {
135- mode := & serial.Mode {
136- BaudRate : 1000000 ,
137- Vtimeout : 100 ,
138- Vmin : 0 ,
139- }
140-
141- return serial .Open (portName , mode )
142- }
143-
144134func OpenFlasher (portName string ) (* Flasher , error ) {
145135
146- port , err := OpenSerial (portName )
136+ port , err := utils . OpenSerial (portName )
147137 if err != nil {
148138 return nil , & FlasherError {err : "Error opening serial port. " + err .Error ()}
149139 }
0 commit comments