|
18 | 18 | package common |
19 | 19 |
|
20 | 20 | import ( |
21 | | - "bytes" |
22 | 21 | "fmt" |
23 | | - "os" |
24 | | - "path/filepath" |
25 | | - "strings" |
26 | 22 |
|
27 | 23 | "github.com/arduino/arduino-cli/arduino/cores/packagemanager" |
28 | | - "github.com/arduino/arduino-cli/arduino/serialutils" |
29 | 24 | "github.com/arduino/arduino-fwuploader/cli/feedback" |
30 | 25 | "github.com/arduino/arduino-fwuploader/cli/globals" |
31 | 26 | "github.com/arduino/arduino-fwuploader/indexes" |
32 | 27 | "github.com/arduino/arduino-fwuploader/indexes/download" |
33 | 28 | "github.com/arduino/arduino-fwuploader/indexes/firmwareindex" |
34 | | - programmer "github.com/arduino/arduino-fwuploader/programmers" |
35 | 29 | "github.com/arduino/go-paths-helper" |
36 | | - "github.com/arduino/go-properties-orderedmap" |
37 | 30 | "github.com/sirupsen/logrus" |
38 | 31 | ) |
39 | 32 |
|
@@ -128,56 +121,3 @@ func downloadTool(pm *packagemanager.PackageManager, tool string) *paths.Path { |
128 | 121 | logrus.Debugf("upload tool downloaded in %s", toolDir.String()) |
129 | 122 | return toolDir |
130 | 123 | } |
131 | | - |
132 | | -// FlashSketch is the business logic that handles the flashing procedure, |
133 | | -// it returns using a buffer the stdout and the stderr of the programmer |
134 | | -func FlashSketch(board *firmwareindex.IndexBoard, sketch string, uploadToolDir *paths.Path, address string) (programmerOut, programmerErr *bytes.Buffer, err error) { |
135 | | - bootloaderPort, err := GetNewAddress(board, address) |
136 | | - if err != nil { |
137 | | - return nil, nil, err |
138 | | - } |
139 | | - |
140 | | - uploaderCommand := board.GetUploaderCommand() |
141 | | - uploaderCommand = strings.ReplaceAll(uploaderCommand, "{tool_dir}", filepath.FromSlash(uploadToolDir.String())) |
142 | | - uploaderCommand = strings.ReplaceAll(uploaderCommand, "{serial.port.file}", bootloaderPort) |
143 | | - uploaderCommand = strings.ReplaceAll(uploaderCommand, "{loader.sketch}", sketch) // we leave that name here because it's only a template, |
144 | | - |
145 | | - logrus.Debugf("uploading with command: %s", uploaderCommand) |
146 | | - commandLine, err := properties.SplitQuotedString(uploaderCommand, "\"", false) |
147 | | - if err != nil { |
148 | | - feedback.Fatal(fmt.Sprintf(`Error splitting command line "%s": %s`, uploaderCommand, err), feedback.ErrGeneric) |
149 | | - } |
150 | | - |
151 | | - // Flash the actual sketch |
152 | | - programmerOut = new(bytes.Buffer) |
153 | | - programmerErr = new(bytes.Buffer) |
154 | | - if feedback.GetFormat() == feedback.JSON { |
155 | | - err = programmer.Flash(commandLine, programmerOut, programmerErr) |
156 | | - } else { |
157 | | - err = programmer.Flash(commandLine, os.Stdout, os.Stderr) |
158 | | - } |
159 | | - if err != nil { |
160 | | - return nil, nil, fmt.Errorf("error during sketch flashing: %s", err) |
161 | | - } |
162 | | - return programmerOut, programmerErr, err |
163 | | -} |
164 | | - |
165 | | -// GetNewAddress is a function used to reset a board and put it in bootloader mode |
166 | | -// it could happen that the board is assigned to a different serial port, after the reset, |
167 | | -// this fuction handles also this possibility |
168 | | -func GetNewAddress(board *firmwareindex.IndexBoard, oldAddress string) (string, error) { |
169 | | - // Check if board needs a 1200bps touch for upload |
170 | | - bootloaderPort := oldAddress |
171 | | - if board.UploadTouch { |
172 | | - logrus.Info("Putting board into bootloader mode") |
173 | | - newUploadPort, err := serialutils.Reset(oldAddress, board.UploadWait, nil, false) |
174 | | - if err != nil { |
175 | | - return "", fmt.Errorf("error during sketch flashing: missing board address. %s", err) |
176 | | - } |
177 | | - if newUploadPort != "" { |
178 | | - logrus.Infof("Found port to upload: %s", newUploadPort) |
179 | | - bootloaderPort = newUploadPort |
180 | | - } |
181 | | - } |
182 | | - return bootloaderPort, nil |
183 | | -} |
0 commit comments