| 204 | } |
| 205 | |
| 206 | bool FlashC6_H2(const char *RepoUrl) { |
| 207 | String JsonFilename = "/firmware_" SHORT_CHIP_NAME ".json" ; |
| 208 | bool Ret = false; |
| 209 | bool bLoaderInit = false; |
| 210 | bool bDownload = strlen(RepoUrl) > 0; |
| 211 | int retry; |
| 212 | JsonDocument jsonDoc; |
| 213 | |
| 214 | LOG("%s#%d: ",__FUNCTION__,__LINE__); util::printHeap(); |
| 215 | |
| 216 | do { |
| 217 | if(bDownload) { |
| 218 | String FileUrl = RepoUrl + JsonFilename; |
| 219 | if(!downloadAndWriteBinary(JsonFilename, FileUrl.c_str())) { |
| 220 | LOG("%s#%d: ",__FUNCTION__,__LINE__); util::printHeap(); |
| 221 | break; |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | File readfile = contentFS->open(JsonFilename, "r"); |
| 226 | if(!readfile) { |
| 227 | wsSerial("load " + JsonFilename + ": Failed to open file"); |
| 228 | return true; |
| 229 | } |
| 230 | DeserializationError jsonError = deserializeJson(jsonDoc, readfile); |
| 231 | |
| 232 | if(jsonError) { |
| 233 | wsSerial(String("json error parsing") + JsonFilename); |
| 234 | break; |
| 235 | } |
| 236 | |
| 237 | if(!bDownload) { |
| 238 | Ret = true; |
| 239 | break; |
| 240 | } |
| 241 | |
| 242 | JsonArray jsonArray = jsonDoc.as<JsonArray>(); |
| 243 | for(JsonObject obj : jsonArray) { |
| 244 | String filename = "/" + obj["filename"].as<String>(); |
| 245 | String binaryUrl = RepoUrl + filename; |
| 246 | |
| 247 | for(retry = 0; retry < 10; retry++) { |
| 248 | if(downloadAndWriteBinary(filename, binaryUrl.c_str())) { |
| 249 | break; |
| 250 | } |
| 251 | wsSerial("Retry " + String(retry)); |
| 252 | if(retry < 9) { |
| 253 | delay(1000); |
| 254 | } |
| 255 | } |
| 256 | if(retry == 10) { |
| 257 | break; |
| 258 | } |
| 259 | } |
| 260 | if(retry < 10) { |
| 261 | Ret = true; |
| 262 | } |
| 263 | } while(false); |
no test coverage detected