DJI Onboard SDK  4.0
dji_file_mgr_impl.hpp
Go to the documentation of this file.
1 
29 #ifndef DJI_FILE_MGR_IMPL_HPP
30 #define DJI_FILE_MGR_IMPL_HPP
31 
32 #include <sys/mman.h>
33 #include <sys/types.h>
34 #include <sys/stat.h>
35 #include <fcntl.h>
36 #include <unistd.h>
37 #include <memory>
38 #include <atomic>
39 #include "dji_error.hpp"
40 #include "osdk_command.h"
42 #include "commondatarangehandler.h"
43 #include "downloadbufferqueue.h"
44 #include "dji_file_mgr_define.hpp"
45 #include "dji_file_mgr.hpp"
46 #include "mmap_file_buffer.hpp"
47 
48 #if 0
49 #include "commondatarangehandler.h"
50 #include "downloadbufferqueue.h"
51 #endif
52 
53 namespace DJI {
54 namespace OSDK {
55 
56 typedef enum DownloadStateEnum : int {
57  DOWNLOAD_IDLE,
58  RECVING_FILE_LIST,
59  RECVING_FILE_DATA,
60  MAX_INDEX_CNT,
61 } DownloadStateEnum;
62 
63 // Forward Declaration
64 class Linker;
65 
66 class DownloadListHandler {
67  public:
68  DownloadListHandler();
69  ~DownloadListHandler();
70  public:
71  CommonDataRangeHandler *range_handler_;
72  DownloadBufferQueue *download_buffer_;
73  FileMgr::FileListReqCBType reqCB;
74  void* reqCBUserData;
75  std::atomic<int> downloadState;
76  std::atomic<uint32_t> updateTimeMs;
77 };
78 
79 class DownloadDataHandler {
80  public:
81  DownloadDataHandler();
82  ~DownloadDataHandler();
83  public:
84  CommonDataRangeHandler *range_handler_;
85  MmapFileBuffer *mmap_file_buffer_;
86  FileMgr::FileDataReqCBType reqCB;
87  void* reqCBUserData;
88  std::atomic<uint32_t> updateTimeMs;
89  std::string downloadPath;
90  std::atomic<int> downloadState;
91  std::atomic<int> curTargetFileIndex;
92 };
93 
94 class FileMgrImpl {
95  public:
96  FileMgrImpl(Linker *linker, E_OSDKCommandDeiveType type, uint8_t index);
97  ~FileMgrImpl();
98 
99  ErrorCode::ErrorCodeType startReqFileList(FileMgr::FileListReqCBType cb, void* userData);
100  ErrorCode::ErrorCodeType startReqFileData(int fileIndex, std::string localPath, FileMgr::FileDataReqCBType cb, void* userData);
101 
102  void HandlePushPack(dji_general_transfer_msg_ack *rsp);
103  ErrorCode::ErrorCodeType SendReqFileListPack();
104  ErrorCode::ErrorCodeType SendReqFileDataPack(int fileIndex) ;
105 
106  private:
107  ErrorCode::ErrorCodeType SendAbortPack(DJI_GENERAL_DOWNLOAD_FILE_TASK_TYPE taskId);
108  ErrorCode::ErrorCodeType SendACKPack(DJI_GENERAL_DOWNLOAD_FILE_TASK_TYPE taskId, dji_download_ack *ack);
109  ErrorCode::ErrorCodeType SendMissedAckPack(DJI_GENERAL_DOWNLOAD_FILE_TASK_TYPE taskId);
110 
111  private:
112  DownloadListHandler *fileListHandler;
113  DownloadDataHandler *fileDataHandler;
114 
115  Linker *linker;
116  E_OSDKCommandDeiveType type;
117  uint8_t index;
118 
119  private:
120  //typedef void (*FileDataReqCBType)(E_OsdkStat ret_code, dji_general_transfer_msg_ack* ackData);
121  //static void internalFileDataReqCB(E_OsdkStat ret_code, void *userData);
122  typedef struct ConsumeDataBuffer {
123  uint8_t data[1024];
124  uint16_t index;
125  } ConsumeDataBuffer;
126  ConsumeDataBuffer ConsumeChunk(DataPointer data_pointer, size_t &chunk_index, size_t consumSize);
127  FilePackage parseFileList(std::list<DataPointer> fullDataList);
128  bool parseFileData(dji_general_transfer_msg_ack *rsp);
129 
130  private:
131  void OnReceiveAbortPack(dji_general_transfer_msg_ack *rsp);
132  void OnReceiveUrgePack(dji_general_transfer_msg_ack *rsp);
133  void OnReceiveDataPack(dji_general_transfer_msg_ack *rsp);
134 
135  void fileListRawDataCB(dji_general_transfer_msg_ack *rsp);
136  void fileDataRawDataCB(dji_general_transfer_msg_ack *rsp);
137 
138  uint16_t createNextReqSessionId() {return reqSessionId++;};
139  uint16_t getCurReqSessionId() {return reqSessionId;};
140  static std::atomic<uint16_t> reqSessionId;
141  T_OsdkTaskHandle reqFileListHandle;
142  T_OsdkTaskHandle reqFileDataHandle;
143  static void fileListMonitorTask(void *arg);
144  static void fileDataMonitorTask(void *arg);
145  void printFileDownloadStatus();
146  //只是用于测试
147  private:
148 
149  FILE *fp = NULL;
150  int fd;
151  void *fdAddr;
152  uint64_t fdAddrSize;
153  uint64_t fdAddrIndex;
154  uint64_t tempSize = 0;
155 
156 };
157 
158 }
159 }
160 
161 #endif // DJI_FILE_MGR_IMPL_HPP
int64_t ErrorCodeType
Unified error type.
Definition: dji_error.hpp:144
void * T_OsdkTaskHandle
Platform handle of thread task operation.
Definition: osdk_platform.h:51
Data struct defination for file manager.
Implementation for file manager.
handle array of characters
Definition: commondatarangehandler.h:14
All DJI OSDK OpenProtocol ACK Error Codes.