88 "os"
99 "os/exec"
1010 "path/filepath"
11+ "regexp"
1112 "runtime"
1213 "strings"
1314 "time"
@@ -44,6 +45,12 @@ func main_load(args []string) {
4445 com_port := args [2 ]
4546 verbosity := args [3 ]
4647
48+ ble_compliance := ""
49+ if len (args ) >= 5 {
50+ // Called by post 1.0.6 platform.txt
51+ ble_compliance = args [4 ]
52+ }
53+
4754 if verbosity == "quiet" {
4855 verbose = false
4956 } else {
@@ -66,11 +73,14 @@ func main_load(args []string) {
6673
6774 dfu_search_command := []string {dfu , dfu_flags , "-l" }
6875
76+ var cmd_output string
77+
6978 for counter < 100 && board_found == false {
7079 if counter % 10 == 0 {
7180 PrintlnVerbose ("Waiting for device..." )
7281 }
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
7484 if err != nil {
7585 fmt .Println (err )
7686 os .Exit (1 )
@@ -93,8 +103,18 @@ func main_load(args []string) {
93103 os .Exit (1 )
94104 }
95105
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+
96116 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 )
98118
99119 if err == nil {
100120 fmt .Println ("SUCCESS: Sketch will execute in about 5 seconds." )
@@ -140,7 +160,7 @@ func main_debug(args []string) {
140160 cmd , _ := shellwords .Parse (command .command )
141161 fmt .Println (cmd )
142162 if command .background == false {
143- err , _ = launchCommandAndWaitForOutput (cmd , "" , true )
163+ err , _ , _ = launchCommandAndWaitForOutput (cmd , "" , true )
144164 } else {
145165 err , _ = launchCommandBackground (cmd , "" , true )
146166 }
@@ -170,7 +190,24 @@ func main() {
170190 os .Exit (1 )
171191}
172192
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 ) {
174211 oscmd := exec .Command (command [0 ], command [1 :]... )
175212 tellCommandNotToSpawnShell (oscmd )
176213 stdout , _ := oscmd .StdoutPipe ()
@@ -180,18 +217,20 @@ func launchCommandAndWaitForOutput(command []string, stringToSearch string, prin
180217 in := bufio .NewScanner (multi )
181218 in .Split (bufio .ScanLines )
182219 found := false
220+ out := ""
183221 for in .Scan () {
184222 if print_output {
185223 PrintlnVerbose (in .Text ())
186224 }
225+ out += in .Text () + "\n "
187226 if stringToSearch != "" {
188227 if strings .Contains (in .Text (), stringToSearch ) {
189228 found = true
190229 }
191230 }
192231 }
193232 err = oscmd .Wait ()
194- return err , found
233+ return err , found , out
195234}
196235
197236func launchCommandBackground (command []string , stringToSearch string , print_output bool ) (error , bool ) {
0 commit comments