//
|
// Created by Administrator on 2022/11/28.
|
//
|
|
#ifndef MYAPPLICATION3_DFU_H
|
#define MYAPPLICATION3_DFU_H
|
|
#include <cstdint>
|
#include <mutex>
|
#include <atomic>
|
#include <condition_variable>
|
|
#define DFU_SHORT_WAIT 0
|
#define DFU_LONG_WAIT 1
|
#define DFU_END 2
|
|
const int DFU_MAX_TRY = 3;
|
const int DFU_FILE_BLOCK_SIZE = 896;
|
|
class Dfu {
|
public:
|
typedef void (*SendDfuPtr)(int fileLen, int sentLen, int blockLen, const uint8_t *data);
|
Dfu(SendDfuPtr fun, const uint8_t *data, int length);
|
~Dfu();
|
void RemoteAck(const uint8_t *data, int length);
|
void Run(void);
|
SendDfuPtr SendDfuFile = nullptr;
|
private:
|
uint8_t *dfuFile = nullptr;
|
uint8_t *dfuFileBitmap = nullptr;
|
int dfuFileLength = 0;
|
int dfuTryCnt = 0;
|
int GoNextDfu(void);
|
bool dfuCancel = false;
|
std::atomic_bool expired;
|
std::mutex cv_mtx;
|
std::condition_variable cv;
|
};
|
|
#endif //MYAPPLICATION3_DFU_H
|