20
20
package sara
21
21
22
22
import (
23
+ "github.com/arduino-libraries/FirmwareUpdater/utils"
23
24
serial "github.com/facchinm/go-serial"
24
- "time"
25
- "strings"
26
25
"log"
26
+ "strings"
27
+ "time"
27
28
//"strconv"
28
29
)
29
30
@@ -44,7 +45,7 @@ func (flasher *Flasher) Hello() error {
44
45
f .Expect ("ATE0" , "OK" , 100 )
45
46
f .Expect ("ATE0" , "OK" , 100 )
46
47
f .Expect ("ATE0" , "OK" , 100 )
47
- _ , err := flasher .Expect ("AT" , "OK" , 100 );
48
+ _ , err := flasher .Expect ("AT" , "OK" , 100 )
48
49
return err
49
50
}
50
51
@@ -65,7 +66,7 @@ func (flasher *Flasher) ExpectMinBytes(buffer string, response string, timeout i
65
66
66
67
start := time .Now ()
67
68
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 ) {
69
70
data := 0
70
71
partial := make ([]byte , 65535 )
71
72
data , err = flasher .port .Read (partial )
@@ -79,7 +80,7 @@ func (flasher *Flasher) ExpectMinBytes(buffer string, response string, timeout i
79
80
log .Println (string (res ))
80
81
81
82
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 )}
83
84
}
84
85
return string (res ), nil
85
86
}
@@ -104,7 +105,6 @@ func (flasher *Flasher) Write(address uint32, buffer []byte) error {
104
105
return nil
105
106
}
106
107
107
-
108
108
// Fill buffer with data coming from serial port.
109
109
// Blocks until the buffer is full.
110
110
func (flasher * Flasher ) serialFillBuffer (buffer []byte ) error {
@@ -131,19 +131,9 @@ func (flasher *Flasher) sendCommand(payload []byte) error {
131
131
return nil
132
132
}
133
133
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
-
144
134
func OpenFlasher (portName string ) (* Flasher , error ) {
145
135
146
- port , err := OpenSerial (portName )
136
+ port , err := utils . OpenSerial (portName )
147
137
if err != nil {
148
138
return nil , & FlasherError {err : "Error opening serial port. " + err .Error ()}
149
139
}
0 commit comments