File tree 1 file changed +51
-0
lines changed
1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change
1
+ package ota
2
+
3
+ import (
4
+ "bytes"
5
+ "errors"
6
+ "io/ioutil"
7
+ "os"
8
+
9
+ inota "github.com/arduino/iot-cloud-cli/internal/ota"
10
+ )
11
+
12
+ var (
13
+ arduinoVendorID = "2341"
14
+ fqbnToPID = map [string ]string {
15
+ "arduino:samd:nano_33_iot" : "8057" ,
16
+ "arduino:samd:mkr1000" : "804E" ,
17
+ "arduino:samd:mkrgsm1400" : "8052" ,
18
+ "arduino:samd:mkrnb1500" : "8055" ,
19
+ "arduino:samd:mkrwifi1010" : "8054" ,
20
+ "arduino:mbed_nano:nanorp2040connect" : "005E" ,
21
+ "arduino:mbed_portenta:envie_m7" : "025B" ,
22
+ }
23
+ )
24
+
25
+ // Generate takes a .bin file and generate a .ota file.
26
+ func Generate (binFile , outFile string , fqbn string ) error {
27
+ productID , ok := fqbnToPID [fqbn ]
28
+ if ! ok {
29
+ return errors .New ("fqbn not valid" )
30
+ }
31
+
32
+ data , err := ioutil .ReadFile (binFile )
33
+ if err != nil {
34
+ return err
35
+ }
36
+
37
+ var w bytes.Buffer
38
+ otaWriter := inota .NewWriter (& w , arduinoVendorID , productID )
39
+ _ , err = otaWriter .Write (data )
40
+ if err != nil {
41
+ return err
42
+ }
43
+ otaWriter .Close ()
44
+
45
+ err = ioutil .WriteFile (outFile , w .Bytes (), os .FileMode (0644 ))
46
+ if err != nil {
47
+ return err
48
+ }
49
+
50
+ return nil
51
+ }
You can’t perform that action at this time.
0 commit comments