yy1717
2022-12-08 f7a18ec4494b9c5c9ef3fd440bbf68ffc6425e18
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//
// 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