|
17 | 17 |
|
18 | 18 | #include "ncp_fw_update.h" |
19 | 19 | #include "system_error.h" |
20 | | -// #if HAL_PLATFORM_NCP_FW_UPDATE |
| 20 | +#if HAL_PLATFORM_NCP_FW_UPDATE |
21 | 21 |
|
22 | 22 | #include "logging.h" |
23 | 23 | #define SARA_NCP_FW_UPDATE_LOG_CATEGORY "system.ncp.update" |
@@ -84,10 +84,10 @@ const int NCP_FW_UUFWINSTALL_COMPLETE = 128; |
84 | 84 | * }; |
85 | 85 | */ |
86 | 86 | const SaraNcpFwUpdateConfig SARA_NCP_FW_UPDATE_CONFIG[] = { |
87 | | - // { sizeof(SaraNcpFwUpdateConfig), 3140001, 103140001, "SARA-R510S-01B-00-ES-0314A0001_SARA-R510S-01B-00-XX-0314ENG0099A0001.upd", "09c1a98d03c761bcbea50355f9b2a50f" }, |
88 | | - // { sizeof(SaraNcpFwUpdateConfig), 103140001, 3140001, "SARA-R510S-01B-00-XX-0314ENG0099A0001_SARA-R510S-01B-00-ES-0314A0001.upd", "136caf2883457093c9e41fda3c6a44e3" }, |
89 | | - // { sizeof(SaraNcpFwUpdateConfig), 2060001, 99010001, "SARA-R510S-00B-01_FW02.06_A00.01_IP_SARA-R510S-00B-01_FW99.01_A00.01.upd", "ccfdc48c0a45198d6e168b30d0740959" }, |
90 | | - // { sizeof(SaraNcpFwUpdateConfig), 99010001, 2060001, "SARA-R510S-00B-01_FW99.01_A00.01_SARA-R510S-00B-01_FW02.06_A00.01_IP.upd", "5fd6c0d3d731c097605895b86f28c2cf" }, |
| 87 | + // { sizeof(SaraNcpFwUpdateConfig), 31400010, 31400011, "SARA-R510S-01B-00-ES-0314A0001_SARA-R510S-01B-00-XX-0314ENG0099A0001.upd", "09c1a98d03c761bcbea50355f9b2a50f" }, |
| 88 | + // { sizeof(SaraNcpFwUpdateConfig), 31400011, 31400010, "SARA-R510S-01B-00-XX-0314ENG0099A0001_SARA-R510S-01B-00-ES-0314A0001.upd", "136caf2883457093c9e41fda3c6a44e3" }, |
| 89 | + // { sizeof(SaraNcpFwUpdateConfig), 20600010, 990100010, "SARA-R510S-00B-01_FW02.06_A00.01_IP_SARA-R510S-00B-01_FW99.01_A00.01.upd", "ccfdc48c0a45198d6e168b30d0740959" }, |
| 90 | + // { sizeof(SaraNcpFwUpdateConfig), 990100010, 20600010, "SARA-R510S-00B-01_FW99.01_A00.01_SARA-R510S-00B-01_FW02.06_A00.01_IP.upd", "5fd6c0d3d731c097605895b86f28c2cf" }, |
91 | 91 | }; |
92 | 92 | const size_t SARA_NCP_FW_UPDATE_CONFIG_SIZE = sizeof(SARA_NCP_FW_UPDATE_CONFIG) / sizeof(SARA_NCP_FW_UPDATE_CONFIG[0]); |
93 | 93 |
|
@@ -460,17 +460,18 @@ int SaraNcpFwUpdate::process() { |
460 | 460 | NCPFW_LOG(INFO, "Disconnecting Cellular..."); |
461 | 461 | // network_disconnect() doesn't wait for final OK response from CFUN=0 |
462 | 462 | // wait for DETACH: +CGEV: ME PDN DEACT 1 |
463 | | - // FIXME: Note that this uses internals of the NCP client/parser and that a new cellular_hal API |
464 | | - // should be added for this functionality later, as in all the other places we are using |
465 | | - // cellular_commandas opposed to directly calling into ncp client/parser. |
466 | | -// FIXME |
467 | | -#ifndef UNIT_TEST |
468 | | - auto mgr = cellularNetworkManager(); |
469 | | - auto client = mgr->ncpClient(); |
470 | | - auto parser = client->atParser(); |
471 | | - const NcpClientLock lock(client); |
472 | | - parser->addUrcHandler("+CGEV", cgevCallback, this); |
473 | | -#endif // UNIT_TEST |
| 463 | + cellular_add_urc_handler("+CGEV", [](const char* data, void* context) -> int { |
| 464 | + const auto self = (SaraNcpFwUpdate*)context; |
| 465 | + int profile; |
| 466 | + |
| 467 | + int r = ::sscanf(data, "+CGEV: ME PDN DEACT %d", &profile); |
| 468 | + // do not CHECK_TRUE as we intend to ignore +CGEV: ME DETACH |
| 469 | + if (r >= 1) { |
| 470 | + self->cgevDeactProfile_ = profile; |
| 471 | + } |
| 472 | + |
| 473 | + return SYSTEM_ERROR_NONE; |
| 474 | + }, this); |
474 | 475 | cgevDeactProfile_ = 0; |
475 | 476 | startTimer_ = millis(); |
476 | 477 | network_disconnect(0, NETWORK_DISCONNECT_REASON_USER, 0); |
@@ -537,17 +538,25 @@ int SaraNcpFwUpdate::process() { |
537 | 538 | } |
538 | 539 | } |
539 | 540 |
|
540 | | - // FIXME: Note that this uses internals of the NCP client/parser and that a new cellular_hal API |
541 | | - // should be added for this functionality later, as in all the other places we are using |
542 | | - // cellular_commandas opposed to directly calling into ncp client/parser. |
543 | | -// FIXME |
544 | | -#ifndef UNIT_TEST |
545 | | - auto mgr = cellularNetworkManager(); |
546 | | - auto client = mgr->ncpClient(); |
547 | | - auto parser = client->atParser(); |
548 | | - const NcpClientLock lock(client); |
549 | | - parser->addUrcHandler("+UUHTTPCR", httpRespCallback, this); |
550 | | -#endif // UNIT_TEST |
| 541 | + cellular_add_urc_handler("+UUHTTPCR", [](const char* data, void* context) -> int { |
| 542 | + const auto self = (SaraNcpFwUpdate*)context; |
| 543 | + int a, b, c; |
| 544 | + char s[40]; |
| 545 | + |
| 546 | + int r = ::sscanf(data, "+UUHTTPCR: %*d,%d,%d,%d,\"%32s\"", &a, &b, &c, s); |
| 547 | + CHECK_TRUE(r >= 3, SYSTEM_ERROR_AT_RESPONSE_UNEXPECTED); |
| 548 | + |
| 549 | + self->httpsResp_.valid = false; // make following lines atomic |
| 550 | + self->httpsResp_.command = a; |
| 551 | + self->httpsResp_.result = b; |
| 552 | + self->httpsResp_.status_code = c; |
| 553 | + if (r > 3) { |
| 554 | + memcpy(self->httpsResp_.md5_sum, &s, sizeof(s)); |
| 555 | + } |
| 556 | + self->httpsResp_.valid = true; |
| 557 | + |
| 558 | + return SYSTEM_ERROR_NONE; |
| 559 | + }, this); |
551 | 560 |
|
552 | 561 | NCPFW_LOG(INFO, "Starting download..."); |
553 | 562 | #if SARA_NCP_FW_UPDATE_ENABLE_DOWNLOAD |
@@ -575,6 +584,8 @@ int SaraNcpFwUpdate::process() { |
575 | 584 | } |
576 | 585 | } |
577 | 586 | } |
| 587 | + |
| 588 | + cellular_remove_urc_handler("+UUHTTPCR"); |
578 | 589 | #else // SARA_NCP_FW_UPDATE_ENABLE_DOWNLOAD |
579 | 590 | // DEBUG |
580 | 591 | modemFirmwareDownloadComplete = true; |
@@ -606,6 +617,7 @@ int SaraNcpFwUpdate::process() { |
606 | 617 | { |
607 | 618 | if (cgevDeactProfile_ == NCP_FW_UBLOX_DEFAULT_CID) { // Default CID detached |
608 | 619 | NCPFW_LOG(INFO, "Disconnected Cellular."); |
| 620 | + cellular_remove_urc_handler("+CGEV"); |
609 | 621 | saraNcpFwUpdateState_ = FW_UPDATE_STATE_INSTALL_STARTING; |
610 | 622 | cooldown(1000); // allow other disconnect URCs to pass |
611 | 623 | } |
@@ -1005,10 +1017,10 @@ int sara_ncp_fw_update_config(const SaraNcpFwUpdateConfig* userConfigData, void* |
1005 | 1017 | return particle::services::SaraNcpFwUpdate::instance()->setConfig(userConfigData); |
1006 | 1018 | } |
1007 | 1019 |
|
1008 | | -// #else // #if HAL_PLATFORM_NCP_FW_UPDATE |
| 1020 | +#else // #if HAL_PLATFORM_NCP_FW_UPDATE |
1009 | 1021 |
|
1010 | | -// int sara_ncp_fw_update_config(const SaraNcpFwUpdateConfig* userConfigData, void* reserved) { |
1011 | | -// return SYSTEM_ERROR_NONE; |
1012 | | -// } |
| 1022 | +int sara_ncp_fw_update_config(const SaraNcpFwUpdateConfig* userConfigData, void* reserved) { |
| 1023 | + return SYSTEM_ERROR_NONE; |
| 1024 | +} |
1013 | 1025 |
|
1014 | | -// #endif // #if HAL_PLATFORM_NCP_FW_UPDATE |
| 1026 | +#endif // #if HAL_PLATFORM_NCP_FW_UPDATE |
0 commit comments