Index: sources/update/VSwUpdate.cpp =================================================================== diff -u -r6424f7371416a378b4c28f40839266adf603cb91 -r7e905e51f1651ef329a9b121e31f9c22d3d898d2 --- sources/update/VSwUpdate.cpp (.../VSwUpdate.cpp) (revision 6424f7371416a378b4c28f40839266adf603cb91) +++ sources/update/VSwUpdate.cpp (.../VSwUpdate.cpp) (revision 7e905e51f1651ef329a9b121e31f9c22d3d898d2) @@ -37,10 +37,11 @@ #define REBOOT_ENABLED (0) #endif -#define MSG_ID_HD_ENTER_BOOTLOADER_NOW (0x8093) ///< HD Jump to the bootloader application -#define MSG_ID_HD_REBOOT_NOW (0x8094) ///< HD Reboot RM46 immediately -#define MSG_ID_HD_SET_ENTER_BOOTLOADER (0x8095) ///< HD Set the flag to stay +#define MSG_ID_ENTER_BOOTLOADER_NOW (0x808F) ///< HD Jump to the bootloader application +#define MSG_ID_REBOOT_NOW (0x8090) ///< HD Reboot RM46 immediately +#define MSG_ID_SET_ENTER_BOOTLOADER (0x8091) ///< HD Set the flag to stay + /*! * \brief Constructor. * @@ -284,10 +285,8 @@ // // If these did fail which is extremely unlikely it feels to the user like they didn't quite // press the start button. - sendAppCommand(MSG_ID_HD_ENTER_BOOTLOADER_NOW, false); - QThread::currentThread()->msleep(10); - sendAppCommand(MSG_ID_HD_ENTER_BOOTLOADER_NOW, true); - QThread::currentThread()->msleep(10); + sendAppCommand(MSG_ID_ENTER_BOOTLOADER_NOW); + sendAppCommand(MSG_ID_ENTER_BOOTLOADER_NOW); ok = _package.start_hasKey(package_location, update); if (ok) @@ -302,10 +301,7 @@ // Because we didn't write MSG_ID_HD_SET_ENTER_BOOTLOADER this should reboot to the app. // // TODO: Don't have a good recovery for this ... - sendAppCommand(MSG_ID_HD_REBOOT_NOW, false); - QThread::currentThread()->msleep(10); - sendAppCommand(MSG_ID_HD_REBOOT_NOW, true); - QThread::currentThread()->msleep(10); + sendAppCommand(MSG_ID_REBOOT_NOW); set_progress("Failed to start " + QString::fromStdString(_available[row_index].fileName)); writeLog("Failed to start " + QString::fromStdString(package_location), false); @@ -416,43 +412,51 @@ } /*! - * \brief Send an APP layer style message to the FW. + * \brief Send an APP layer style message to both FW nodes. * * cmd: 0x808F Enter bootloader (MSG_ID_HD_ENTER_BOOTLOADER_NOW) * 0x8090 Reboot now (MSG_ID_HD_REBOOT_NOW) * 0x8091 Set boot bit to stay in bootloader after reboot (MSG_ID_HD_SET_ENTER_BOOTLOADER) * * \param cmd 16 bit command. - * \param isHD It is for HD not DG. */ -void VSWUpdate::sendAppCommand(uint16 cmd, bool isHD) { +void VSWUpdate::sendAppCommand(uint16 cmd) { - QByteArray msg; - msg.append(ePayload_Sync); // 0xA5 + for (std::size_t ii = 0; ii < 2; ii++) { + QByteArray msg; + msg.append(ePayload_Sync); // 0xA5 - // 2 bytes sequence #. - uint16_t seqNo = _MessageDispatcher.getSequenceNumber(); - msg.append((uint8)(seqNo >> 8)); - msg.append((uint8)(seqNo & 0xFF)); + // 2 bytes sequence #. + uint16_t seqNo = _MessageDispatcher.getSequenceNumber(); + msg.append((uint8)(seqNo >> 8)); + msg.append((uint8)(seqNo & 0xFF)); - // 2 byte msgID. - msg.append((uint8)(cmd & 0xFF)); - msg.append((uint8)((cmd >> 8) & 0xFF)); + // 2 byte msgID. + msg.append((uint8)(cmd & 0xFF)); + msg.append((uint8)((cmd >> 8) & 0xFF)); - // 1 byte payload size = 0. - msg.append((uint8)0); + // 1 byte payload size = 0. + msg.append((uint8)0); - // 1 byte app protocol CRC. - msg.append(crc8(msg.mid(1))); + // 1 byte app protocol CRC. + msg.append(crc8(msg.mid(1))); - // Pad 2 bytes zero. - msg.append((uint8)0); - msg.append((uint8)0); + // Pad 2 bytes zero. + msg.append((uint8)0); + msg.append((uint8)0); - // Send it. - // eChlid_UI_HD = 0x100, ///< UI => HD [Out] - // eChlid_UI_DG = 0x110, ///< UI => DG [Out] - _CanInterface.sendSWUpdateMsg(isHD ? eChlid_UI_HD : eChlid_UI_DG, (uint8_t *)msg.data(), 8); + // Send it. + // eChlid_UI_HD = 0x100, ///< UI => HD [Out] + // eChlid_UI_DG = 0x110, ///< UI => DG [Out] + _CanInterface.sendSWUpdateMsg(ii == 0 ? eChlid_UI_HD : eChlid_UI_DG, (uint8_t *)msg.data(), 8); + + // Sleep long enough to ensure FW acted on it. + // + // If it fails to act on it, the update will fail almost imediately and + // the user can retry, the likelyhood it fails is extremely small, likely 1:1k + // or less judging by seeing few RTRs in CAN bus traffic. + QThread::currentThread()->msleep(10); + } } /*!