/*! * * Copyright (c) 2023 Diality Inc. - All Rights Reserved. * * \copyright * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * * \file UiSwUpdate.h * \author (last) Phil Braica * \date (last) 23-Jan-2023 * \author (original) Phil Braica * \date (original) 23-Jan-2023 * */ #ifndef UI_SW_UPDATE_H_ #define UI_SW_UPDATE_H_ #include "HalStdTypes.h" #include "MsgLink.h" #include "UpdateProtocol.h" #include "UiProtocol.h" #include "UiUpdateStatus.h" #include #include namespace SwUpdate { /** Forward declare. */ class IDataProvider; class IEnterBootLoader; /*! * This class uses a thread plus a waitable condition variable * to impliment a linear procedure to update one firmware * "target". It uses "ID" slots for commands so that in theory * multiple updaters running in paralell won't conflict. * * Note that this is deliberately NOT a statemachine even * though it could be coded as one. Statemachines have overhead * waiting for events and the goal is to have virtually zero * time between events and in theory never really yielding unless * the Firmware image gets too busy. */ class UiSwUpdate { public: /*! * \brief Create the instance. * * \return Instance reference. */ static UiSwUpdate & instance(); // Start updating. bool start( std::vector& dataProviders, SwUpdate::IEnterBootLoader* pEnterBL); /*! * \brief Is it completed? * * \return True if completed. */ bool completedAll(); /*! * \brief Abort update. */ void abort(); /*! * \brief Current estimated progress. * * \return Vector of statuses. */ std::vector progress(); /*! * \brief Receive and check if matched. * * \param msgId Can message ID. * \param pData Data pointer. * * \return True if message was consumed. */ bool receive(uint16 msgId, uint8 * pData); /*! * \brief This chains updates together, as a protocol completes, it calls this. * * \param ok The task completed ok. * \param pCompleted Which protocol completed. */ void taskCompleted(bool ok, UiProtocol* pCompleted); protected: /*! * \brief Constructor. * * \param target Target to go after for update. */ UiSwUpdate(); /*! * \brief Destructor (virtual). */ virtual ~UiSwUpdate(); std::map _all; ///< All of them, key by kind. std::vector _tasks; ///< Tasks to do. UiProtocol _hdUpdate; ///< HD update. UiProtocol _hdFpgaUpdate; ///< HD FPGA update. UiProtocol _dgUpdate; ///< DG update. UiProtocol _dgFpgaUpdate; ///< DG FPGA update. UiProtocolFile _fileUpdate; ///< Files UI & Linux are done with this. std::mutex _mutexApi; ///< Mutex so API calls are thread safe. }; } //namespace SwUpdate #endif // UI_SW_UPDATE_H_