8
8
"os"
9
9
"os/exec"
10
10
"path/filepath"
11
+ "regexp"
11
12
"runtime"
12
13
"strings"
13
14
"time"
@@ -44,6 +45,12 @@ func main_load(args []string) {
44
45
com_port := args [2 ]
45
46
verbosity := args [3 ]
46
47
48
+ ble_compliance := ""
49
+ if len (args ) >= 5 {
50
+ // Called by post 1.0.6 platform.txt
51
+ ble_compliance = args [4 ]
52
+ }
53
+
47
54
if verbosity == "quiet" {
48
55
verbose = false
49
56
} else {
@@ -66,11 +73,14 @@ func main_load(args []string) {
66
73
67
74
dfu_search_command := []string {dfu , dfu_flags , "-l" }
68
75
76
+ var cmd_output string
77
+
69
78
for counter < 100 && board_found == false {
70
79
if counter % 10 == 0 {
71
80
PrintlnVerbose ("Waiting for device..." )
72
81
}
73
- err , found := launchCommandAndWaitForOutput (dfu_search_command , "sensor_core" , false )
82
+ err , found , output := launchCommandAndWaitForOutput (dfu_search_command , "sensor_core" , false )
83
+ cmd_output = output
74
84
if err != nil {
75
85
fmt .Println (err )
76
86
os .Exit (1 )
@@ -93,8 +103,18 @@ func main_load(args []string) {
93
103
os .Exit (1 )
94
104
}
95
105
106
+ if ble_compliance != "" {
107
+ // check for BLE library compliance
108
+ ble_version := extractBLEversionFromDFU (cmd_output )
109
+ if ble_compliance != ble_version {
110
+ fmt .Println ("BLE firmware version is not in sync with CurieBLE library" )
111
+ fmt .Println ("Update it using \" Burn Bootloader\" menu" )
112
+ os .Exit (1 )
113
+ }
114
+ }
115
+
96
116
dfu_download := []string {dfu , dfu_flags , "-D" , bin_file_name , "-v" , "--alt" , "7" , "-R" }
97
- err , _ := launchCommandAndWaitForOutput (dfu_download , "" , true )
117
+ err , _ , _ := launchCommandAndWaitForOutput (dfu_download , "" , true )
98
118
99
119
if err == nil {
100
120
fmt .Println ("SUCCESS: Sketch will execute in about 5 seconds." )
@@ -140,7 +160,7 @@ func main_debug(args []string) {
140
160
cmd , _ := shellwords .Parse (command .command )
141
161
fmt .Println (cmd )
142
162
if command .background == false {
143
- err , _ = launchCommandAndWaitForOutput (cmd , "" , true )
163
+ err , _ , _ = launchCommandAndWaitForOutput (cmd , "" , true )
144
164
} else {
145
165
err , _ = launchCommandBackground (cmd , "" , true )
146
166
}
@@ -170,7 +190,24 @@ func main() {
170
190
os .Exit (1 )
171
191
}
172
192
173
- func launchCommandAndWaitForOutput (command []string , stringToSearch string , print_output bool ) (error , bool ) {
193
+ func extractBLEversionFromDFU (command string ) string {
194
+ in := bufio .NewScanner (strings .NewReader (command ))
195
+ in .Split (bufio .ScanLines )
196
+ for in .Scan () {
197
+ if strings .Contains (in .Text (), "ble_core" ) {
198
+ re := regexp .MustCompile (`ver=([0-9]+)` )
199
+ ver := re .FindStringSubmatch (in .Text ())
200
+ if len (ver ) > 1 {
201
+ return ver [1 ]
202
+ } else {
203
+ return ""
204
+ }
205
+ }
206
+ }
207
+ return ""
208
+ }
209
+
210
+ func launchCommandAndWaitForOutput (command []string , stringToSearch string , print_output bool ) (error , bool , string ) {
174
211
oscmd := exec .Command (command [0 ], command [1 :]... )
175
212
tellCommandNotToSpawnShell (oscmd )
176
213
stdout , _ := oscmd .StdoutPipe ()
@@ -180,18 +217,20 @@ func launchCommandAndWaitForOutput(command []string, stringToSearch string, prin
180
217
in := bufio .NewScanner (multi )
181
218
in .Split (bufio .ScanLines )
182
219
found := false
220
+ out := ""
183
221
for in .Scan () {
184
222
if print_output {
185
223
PrintlnVerbose (in .Text ())
186
224
}
225
+ out += in .Text () + "\n "
187
226
if stringToSearch != "" {
188
227
if strings .Contains (in .Text (), stringToSearch ) {
189
228
found = true
190
229
}
191
230
}
192
231
}
193
232
err = oscmd .Wait ()
194
- return err , found
233
+ return err , found , out
195
234
}
196
235
197
236
func launchCommandBackground (command []string , stringToSearch string , print_output bool ) (error , bool ) {
0 commit comments