|
1
|
-/**
|
|
|
|
2
|
- ********************************************************************
|
|
|
|
3
|
- * @file main.c
|
|
|
|
4
|
- * @brief
|
|
|
|
5
|
- *
|
|
|
|
6
|
- * @copyright (c) 2021 ZIYAN. All rights reserved.
|
|
|
|
7
|
- *
|
|
|
|
8
|
- * All information contained herein is, and remains, the property of ZIYAN.
|
|
|
|
9
|
- * The intellectual and technical concepts contained herein are proprietary
|
|
|
|
10
|
- * to ZIYAN and may be covered by U.S. and foreign patents, patents in process,
|
|
|
|
11
|
- * and protected by trade secret or copyright law. Dissemination of this
|
|
|
|
12
|
- * information, including but not limited to data and other proprietary
|
|
|
|
13
|
- * material(s) incorporated within the information, in any form, is strictly
|
|
|
|
14
|
- * prohibited without the express written consent of ZIYAN.
|
|
|
|
15
|
- *
|
|
|
|
16
|
- * If you receive this source code without ZIYAN’s authorization, you may not
|
|
|
|
17
|
- * further disseminate the information, and you must immediately remove the
|
|
|
|
18
|
- * source code and notify ZIYAN of its removal. ZIYAN reserves the right to pursue
|
|
|
|
19
|
- * legal actions against you for any loss(es) or damage(s) caused by your
|
|
|
|
20
|
- * failure to do so.
|
|
|
|
21
|
- *
|
|
|
|
22
|
- *********************************************************************
|
|
|
|
23
|
- */
|
|
|
|
24
|
-
|
|
|
|
25
|
-/* Includes ------------------------------------------------------------------*/
|
|
|
|
26
|
-#include <ziyan_platform.h>
|
|
|
|
27
|
-#include <ziyan_logger.h>
|
|
|
|
28
|
-#include <ziyan_core.h>
|
|
|
|
29
|
-#include <utils/util_misc.h>
|
|
|
|
30
|
-#include <errno.h>
|
|
|
|
31
|
-#include <signal.h>
|
|
|
|
32
|
-#include "monitor/sys_monitor.h"
|
|
|
|
33
|
-#include "osal/osal.h"
|
|
|
|
34
|
-#include "osal/osal_fs.h"
|
|
|
|
35
|
-#include "osal/osal_socket.h"
|
|
|
|
36
|
-#include "../hal/hal_uart.h"
|
|
|
|
37
|
-#include "../hal/hal_network.h"
|
|
|
|
38
|
-#include "../hal/hal_usb_bulk.h"
|
|
|
|
39
|
-#include "ziyan_sdk_app_info.h"
|
|
|
|
40
|
-#include "ziyan_aircraft_info.h"
|
|
|
|
41
|
-#include "widget/test_widget.h"
|
|
|
|
42
|
-#include "ziyan_sdk_config.h"
|
|
|
|
43
|
-
|
|
|
|
44
|
-#include "camera_emu/test_payload_cam_emu_base.h"
|
|
|
|
45
|
-
|
|
|
|
46
|
-#include "Zy_Expansion.h"
|
|
|
|
47
|
-#include "BaseConfig.h"
|
|
|
|
48
|
-
|
|
|
|
49
|
-/* Private constants ---------------------------------------------------------*/
|
|
|
|
50
|
-#define ZIYAN_LOG_PATH "Logs/ZIYAN"
|
|
|
|
51
|
-#define ZIYAN_LOG_INDEX_FILE_NAME "Logs/latest"
|
|
|
|
52
|
-#define ZIYAN_LOG_FOLDER_NAME "Logs"
|
|
|
|
53
|
-#define ZIYAN_LOG_PATH_MAX_SIZE (128)
|
|
|
|
54
|
-#define ZIYAN_LOG_FOLDER_NAME_MAX_SIZE (32)
|
|
|
|
55
|
-#define ZIYAN_LOG_MAX_COUNT (10)
|
|
|
|
56
|
-#define ZIYAN_SYSTEM_CMD_STR_MAX_SIZE (64)
|
|
|
|
57
|
-#define ZIYAN_SYSTEM_RESULT_STR_MAX_SIZE (128)
|
|
|
|
58
|
-
|
|
|
|
59
|
-#define ZIYAN_USE_WIDGET_INTERACTION 0
|
|
|
|
60
|
-
|
|
|
|
61
|
-/* Private types -------------------------------------------------------------*/
|
|
|
|
62
|
-typedef struct {
|
|
|
|
63
|
- pid_t tid;
|
|
|
|
64
|
- char name[16];
|
|
|
|
65
|
- float pcpu;
|
|
|
|
66
|
-} T_ThreadAttribute;
|
|
|
|
67
|
-
|
|
|
|
68
|
-/* Private values -------------------------------------------------------------*/
|
|
|
|
69
|
-static FILE *s_djiLogFile;
|
|
|
|
70
|
-static FILE *s_djiLogFileCnt;
|
|
|
|
71
|
-static pthread_t s_monitorThread = 0;
|
|
|
|
72
|
-
|
|
|
|
73
|
-/* Private functions declaration ---------------------------------------------*/
|
|
|
|
74
|
-static T_ZiyanReturnCode ZiyanUser_PrepareSystemEnvironment(void);
|
|
|
|
75
|
-static T_ZiyanReturnCode ZiyanUser_FillInUserInfo(T_ZiyanUserInfo *userInfo);
|
|
|
|
76
|
-static T_ZiyanReturnCode ZiyanUser_PrintConsole(const uint8_t *data, uint16_t dataLen);
|
|
|
|
77
|
-static T_ZiyanReturnCode ZiyanUser_LocalWrite(const uint8_t *data, uint16_t dataLen);
|
|
|
|
78
|
-static T_ZiyanReturnCode ZiyanUser_LocalWriteFsInit(const char *path);
|
|
|
|
79
|
-// static void *ZiyanUser_MonitorTask(void *argument);
|
|
|
|
80
|
-// static T_ZiyanReturnCode ZiyanTest_HighPowerApplyPinInit();
|
|
|
|
81
|
-// static T_ZiyanReturnCode ZiyanTest_WriteHighPowerApplyPin(E_ZiyanPowerManagementPinState pinState);
|
|
|
|
82
|
-static void ZiyanUser_NormalExitHandler(int signalNum);
|
|
|
|
83
|
-
|
|
|
|
84
|
-/* Exported functions definition ---------------------------------------------*/
|
|
|
|
85
|
-int main(int argc, char **argv)
|
|
|
|
86
|
-{
|
|
|
|
87
|
- T_ZiyanReturnCode returnCode;
|
|
|
|
88
|
- T_ZiyanUserInfo userInfo;
|
|
|
|
89
|
- T_ZiyanAircraftInfoBaseInfo aircraftInfoBaseInfo;
|
|
|
|
90
|
- T_ZiyanAircraftVersion aircraftInfoVersion;
|
|
|
|
91
|
- T_ZiyanFirmwareVersion firmwareVersion = {
|
|
|
|
92
|
- .majorVersion = 1,
|
|
|
|
93
|
- .minorVersion = 0,
|
|
|
|
94
|
- .modifyVersion = 0,
|
|
|
|
95
|
- .debugVersion = 0,
|
|
|
|
96
|
- };
|
|
|
|
97
|
-
|
|
|
|
98
|
- USER_UTIL_UNUSED(argc);
|
|
|
|
99
|
- USER_UTIL_UNUSED(argv);
|
|
|
|
100
|
-
|
|
|
|
101
|
- // attention: when the program is hand up ctrl-c will generate the coredump file
|
|
|
|
102
|
- // 注意:当程序挂起时,按下Ctrl-C会生成coredump文件
|
|
|
|
103
|
- signal(SIGTERM, ZiyanUser_NormalExitHandler);
|
|
|
|
104
|
-
|
|
|
|
105
|
- /*!< Step 1: Prepare system environment, such as osal, hal uart, console function and so on. */
|
|
|
|
106
|
- /*!< 步骤1:准备系统环境,例如osal、hal uart、控制台功能等 */
|
|
|
|
107
|
- returnCode = ZiyanUser_PrepareSystemEnvironment();
|
|
|
|
108
|
- if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
|
|
|
109
|
- USER_LOG_ERROR("Prepare system environment error");
|
|
|
|
110
|
- return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
|
|
|
111
|
- }
|
|
|
|
112
|
-
|
|
|
|
113
|
- USER_LOG_INFO("run main test: %d:%d", 111, __LINE__);
|
|
|
|
114
|
-
|
|
|
|
115
|
- /*!< Step 2: Fill your application information in dji_sdk_app_info.h and use this interface to fill it. */
|
|
|
|
116
|
- /*!< 步骤2:在dji_sdk_app_info.h中填写应用信息,并使用本接口填充信息 */
|
|
|
|
117
|
- returnCode = ZiyanUser_FillInUserInfo(&userInfo);
|
|
|
|
118
|
- if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
|
|
|
119
|
- USER_LOG_ERROR("Fill user info error, please check user info config");
|
|
|
|
120
|
- return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
|
|
|
121
|
- }
|
|
|
|
122
|
-
|
|
|
|
123
|
- // /*!< Step 3: Initialize the Payload SDK core by your application information. */
|
|
|
|
124
|
- // /*!< 步骤3:通过应用信息初始化Payload SDK核心 */
|
|
|
|
125
|
- returnCode = ZiyanCore_Init(&userInfo);
|
|
|
|
126
|
- if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
|
|
|
127
|
- USER_LOG_ERROR("Core init error");
|
|
|
|
128
|
- return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
|
|
|
129
|
- }
|
|
|
|
130
|
-
|
|
|
|
131
|
- returnCode = ZiyanAircraftInfo_GetBaseInfo(&aircraftInfoBaseInfo);
|
|
|
|
132
|
- if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
|
|
|
133
|
- USER_LOG_ERROR("get aircraft base info error");
|
|
|
|
134
|
- return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
|
|
|
135
|
- }
|
|
|
|
136
|
-
|
|
|
|
137
|
- // returnCode = ZiyanAircraftInfo_GetAircraftVersion(&aircraftInfoVersion);
|
|
|
|
138
|
- // if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
|
|
|
139
|
- // USER_LOG_ERROR("get aircraft version info error");
|
|
|
|
140
|
- // } else {
|
|
|
|
141
|
- // USER_LOG_INFO("Aircraft version is V%02d.%02d.%02d.%02d", aircraftInfoVersion.majorVersion,
|
|
|
|
142
|
- // aircraftInfoVersion.minorVersion, aircraftInfoVersion.modifyVersion,
|
|
|
|
143
|
- // aircraftInfoVersion.debugVersion);
|
|
|
|
144
|
- // }
|
|
|
|
145
|
-
|
|
|
|
146
|
- // returnCode = ZiyanCore_SetAlias("PSDK_APPALIAS");
|
|
|
|
147
|
- // if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
|
|
|
148
|
- // USER_LOG_ERROR("set alias error");
|
|
|
|
149
|
- // return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
|
|
|
150
|
- // }
|
|
|
|
151
|
-
|
|
|
|
152
|
- // returnCode = ZiyanCore_SetFirmwareVersion(firmwareVersion);
|
|
|
|
153
|
- // if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
|
|
|
154
|
- // USER_LOG_ERROR("set firmware version error");
|
|
|
|
155
|
- // return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
|
|
|
156
|
- // }
|
|
|
|
157
|
-
|
|
|
|
158
|
- // returnCode = ZiyanCore_SetSerialNumber("PSDK12345678XX");
|
|
|
|
159
|
- // if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
|
|
|
160
|
- // USER_LOG_ERROR("set serial number error");
|
|
|
|
161
|
- // return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
|
|
|
162
|
- // }
|
|
|
|
163
|
-
|
|
|
|
164
|
-// /*!< Step 4: Initialize the selected modules by macros in dji_sdk_config.h . */
|
|
|
|
165
|
-// /*!< 步骤4:通过dji_sdk_config.h中的宏初始化选中的模块 */
|
|
|
|
166
|
-// #ifdef CONFIG_MODULE_SAMPLE_POWER_MANAGEMENT_ON
|
|
|
|
167
|
-// T_ZiyanTestApplyHighPowerHandler applyHighPowerHandler = {
|
|
|
|
168
|
-// .pinInit = ZiyanTest_HighPowerApplyPinInit,
|
|
|
|
169
|
-// .pinWrite = ZiyanTest_WriteHighPowerApplyPin,
|
|
|
|
170
|
-// };
|
|
|
|
171
|
-
|
|
|
|
172
|
-// returnCode = ZiyanTest_RegApplyHighPowerHandler(&applyHighPowerHandler);
|
|
|
|
173
|
-// if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
|
|
|
174
|
-// USER_LOG_ERROR("regsiter apply high power handler error");
|
|
|
|
175
|
-// }
|
|
|
|
176
|
-
|
|
|
|
177
|
-// returnCode = ZiyanTest_PowerManagementStartService();
|
|
|
|
178
|
-// if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
|
|
|
179
|
-// USER_LOG_ERROR("power management init error");
|
|
|
|
180
|
-// }
|
|
|
|
181
|
-// #endif
|
|
|
|
182
|
-
|
|
|
|
183
|
-// #ifdef CONFIG_MODULE_SAMPLE_DATA_TRANSMISSION_ON
|
|
|
|
184
|
-// returnCode = ZiyanTest_DataTransmissionStartService();
|
|
|
|
185
|
-// if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
|
|
|
186
|
-// USER_LOG_ERROR("widget sample init error");
|
|
|
|
187
|
-// }
|
|
|
|
188
|
-// #endif
|
|
|
|
189
|
-
|
|
|
|
190
|
-// if (aircraftInfoBaseInfo.mountPosition == ZIYAN_MOUNT_POSITION_EXTENSION_PORT &&
|
|
|
|
191
|
-// aircraftInfoBaseInfo.aircraftType == ZIYAN_AIRCRAFT_TYPE_M300_RTK) {
|
|
|
|
192
|
-// returnCode = ZiyanTest_WidgetInteractionStartService();
|
|
|
|
193
|
-// if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
|
|
|
194
|
-// USER_LOG_ERROR("widget interaction sample init error");
|
|
|
|
195
|
-// }
|
|
|
|
196
|
-
|
|
|
|
197
|
-// returnCode = ZiyanTest_WidgetSpeakerStartService();
|
|
|
|
198
|
-// if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
|
|
|
199
|
-// USER_LOG_ERROR("widget speaker test init error");
|
|
|
|
200
|
-// }
|
|
|
|
201
|
-// } else {
|
|
|
|
202
|
-#ifdef CONFIG_MODULE_SAMPLE_CAMERA_EMU_ON
|
|
|
|
203
|
- returnCode = ZiyanTest_CameraEmuBaseStartService();
|
|
|
|
204
|
- if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
|
|
|
205
|
- USER_LOG_ERROR("camera emu common init error");
|
|
|
|
206
|
- }
|
|
|
|
207
|
-#endif
|
|
|
|
208
|
-
|
|
|
|
209
|
-#ifdef CONFIG_MODULE_SAMPLE_CAMERA_MEDIA_ON
|
|
|
|
210
|
- returnCode = ZiyanTest_CameraEmuMediaStartService();
|
|
|
|
211
|
- if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
|
|
|
212
|
- USER_LOG_ERROR("camera emu media init error");
|
|
|
|
213
|
- }
|
|
|
|
214
|
-#endif
|
|
|
|
215
|
-
|
|
|
|
216
|
-#ifdef CONFIG_MODULE_SAMPLE_FC_SUBSCRIPTION_ON
|
|
|
|
217
|
- returnCode = ZiyanTest_FcSubscriptionStartService();
|
|
|
|
218
|
- if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
|
|
|
219
|
- USER_LOG_ERROR("data subscription sample init error\n");
|
|
|
|
220
|
- }
|
|
|
|
221
|
-#endif
|
|
|
|
222
|
-
|
|
|
|
223
|
-#ifdef CONFIG_MODULE_SAMPLE_GIMBAL_EMU_ON
|
|
|
|
224
|
- if (aircraftInfoBaseInfo.ziyanAdapterType == ZIYAN_SDK_ADAPTER_TYPE_NONE ||
|
|
|
|
225
|
- aircraftInfoBaseInfo.ziyanAdapterType == ZIYAN_SDK_ADAPTER_TYPE_UNKNOWN) {
|
|
|
|
226
|
-
|
|
|
|
227
|
- if (ZiyanTest_GimbalStartService() != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
|
|
|
228
|
- USER_LOG_ERROR("psdk gimbal init error");
|
|
|
|
229
|
- }
|
|
|
|
230
|
- }
|
|
|
|
231
|
-#endif
|
|
|
|
232
|
-
|
|
|
|
233
|
-// #ifdef CONFIG_MODULE_SAMPLE_XPORT_ON
|
|
|
|
234
|
-// if (aircraftInfoBaseInfo.djiAdapterType == ZIYAN_SDK_ADAPTER_TYPE_XPORT) {
|
|
|
|
235
|
-// if (ZiyanTest_XPortStartService() != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
|
|
|
236
|
-// USER_LOG_ERROR("psdk xport init error");
|
|
|
|
237
|
-// }
|
|
|
|
238
|
-// }
|
|
|
|
239
|
-// #endif
|
|
|
|
240
|
-
|
|
|
|
241
|
- //配置拓展接口
|
|
|
|
242
|
- Zy_JZsdkToPsdk_ExpnasionInit();
|
|
|
|
243
|
-
|
|
|
|
244
|
- //自己配置
|
|
|
|
245
|
- Main_APP_Psdk();
|
|
|
|
246
|
-
|
|
|
|
247
|
-
|
|
|
|
248
|
-#ifdef CONFIG_MODULE_SAMPLE_WIDGET_ON
|
|
|
|
249
|
-#if ZIYAN_USE_WIDGET_INTERACTION
|
|
|
|
250
|
- returnCode = ZiyanTest_WidgetInteractionStartService();
|
|
|
|
251
|
- if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
|
|
|
252
|
- USER_LOG_ERROR("widget interaction test init error");
|
|
|
|
253
|
- }
|
|
|
|
254
|
-#else
|
|
|
|
255
|
- returnCode = ZiyanTest_WidgetStartService();
|
|
|
|
256
|
- if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
|
|
|
257
|
- USER_LOG_ERROR("widget sample init error");
|
|
|
|
258
|
- }
|
|
|
|
259
|
-#endif
|
|
|
|
260
|
-#endif
|
|
|
|
261
|
-
|
|
|
|
262
|
-#ifdef CONFIG_MODULE_SAMPLE_WIDGET_SPEAKER_ON
|
|
|
|
263
|
- returnCode = ZiyanTest_WidgetSpeakerStartService();
|
|
|
|
264
|
- if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
|
|
|
265
|
- USER_LOG_ERROR("widget speaker test init error");
|
|
|
|
266
|
- }
|
|
|
|
267
|
-#endif
|
|
|
|
268
|
-
|
|
|
|
269
|
-// #ifdef CONFIG_MODULE_SAMPLE_MOP_CHANNEL_ON
|
|
|
|
270
|
-// returnCode = ZiyanTest_MopChannelStartService();
|
|
|
|
271
|
-// if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
|
|
|
272
|
-// USER_LOG_ERROR("mop channel sample init error");
|
|
|
|
273
|
-// }
|
|
|
|
274
|
-// #endif
|
|
|
|
275
|
-
|
|
|
|
276
|
-// #ifdef CONFIG_MODULE_SAMPLE_PAYLOAD_COLLABORATION_ON
|
|
|
|
277
|
-// if (aircraftInfoBaseInfo.djiAdapterType == ZIYAN_SDK_ADAPTER_TYPE_SKYPORT_V2 ||
|
|
|
|
278
|
-// aircraftInfoBaseInfo.djiAdapterType == ZIYAN_SDK_ADAPTER_TYPE_XPORT) {
|
|
|
|
279
|
-// returnCode = ZiyanTest_PayloadCollaborationStartService();
|
|
|
|
280
|
-// if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
|
|
|
281
|
-// USER_LOG_ERROR("Payload collaboration sample init error\n");
|
|
|
|
282
|
-// }
|
|
|
|
283
|
-// }
|
|
|
|
284
|
-// #endif
|
|
|
|
285
|
-
|
|
|
|
286
|
-// #ifdef CONFIG_MODULE_SAMPLE_UPGRADE_ON
|
|
|
|
287
|
-// T_ZiyanTestUpgradePlatformOpt linuxUpgradePlatformOpt = {
|
|
|
|
288
|
-// .rebootSystem = ZiyanUpgradePlatformLinux_RebootSystem,
|
|
|
|
289
|
-// .cleanUpgradeProgramFileStoreArea = ZiyanUpgradePlatformLinux_CleanUpgradeProgramFileStoreArea,
|
|
|
|
290
|
-// .createUpgradeProgramFile = ZiyanUpgradePlatformLinux_CreateUpgradeProgramFile,
|
|
|
|
291
|
-// .writeUpgradeProgramFile = ZiyanUpgradePlatformLinux_WriteUpgradeProgramFile,
|
|
|
|
292
|
-// .readUpgradeProgramFile = ZiyanUpgradePlatformLinux_ReadUpgradeProgramFile,
|
|
|
|
293
|
-// .closeUpgradeProgramFile = ZiyanUpgradePlatformLinux_CloseUpgradeProgramFile,
|
|
|
|
294
|
-// .replaceOldProgram = ZiyanUpgradePlatformLinux_ReplaceOldProgram,
|
|
|
|
295
|
-// .setUpgradeRebootState = ZiyanUpgradePlatformLinux_SetUpgradeRebootState,
|
|
|
|
296
|
-// .getUpgradeRebootState = ZiyanUpgradePlatformLinux_GetUpgradeRebootState,
|
|
|
|
297
|
-// .cleanUpgradeRebootState = ZiyanUpgradePlatformLinux_CleanUpgradeRebootState,
|
|
|
|
298
|
-// };
|
|
|
|
299
|
-// T_ZiyanTestUpgradeConfig testUpgradeConfig = {
|
|
|
|
300
|
-// .firmwareVersion = firmwareVersion,
|
|
|
|
301
|
-// .transferType = ZIYAN_FIRMWARE_TRANSFER_TYPE_DCFTP,
|
|
|
|
302
|
-// .needReplaceProgramBeforeReboot = true
|
|
|
|
303
|
-// };
|
|
|
|
304
|
-// if (ZiyanTest_UpgradeStartService(&linuxUpgradePlatformOpt, testUpgradeConfig) !=
|
|
|
|
305
|
-// ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
|
|
|
306
|
-// USER_LOG_ERROR("psdk upgrade init error");
|
|
|
|
307
|
-// }
|
|
|
|
308
|
-// #endif
|
|
|
|
309
|
-
|
|
|
|
310
|
-// #ifdef CONFIG_MODULE_SAMPLE_HMS_CUSTOMIZATION_ON
|
|
|
|
311
|
-// returnCode = ZiyanTest_HmsCustomizationStartService();
|
|
|
|
312
|
-// if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
|
|
|
313
|
-// USER_LOG_ERROR("hms test init error");
|
|
|
|
314
|
-// }
|
|
|
|
315
|
-// #endif
|
|
|
|
316
|
-// }
|
|
|
|
317
|
-
|
|
|
|
318
|
-
|
|
|
|
319
|
- // /*!< Step 5: Tell the ZIYAN Pilot you are ready. */
|
|
|
|
320
|
- returnCode = ZiyanCore_ApplicationStart();
|
|
|
|
321
|
- if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
|
|
|
322
|
- USER_LOG_ERROR("start sdk application error");
|
|
|
|
323
|
- }
|
|
|
|
324
|
-
|
|
|
|
325
|
- // if (pthread_create(&s_monitorThread, NULL, ZiyanUser_MonitorTask, NULL) != 0) {
|
|
|
|
326
|
- // USER_LOG_ERROR("create monitor task fail.");
|
|
|
|
327
|
- // }
|
|
|
|
328
|
-
|
|
|
|
329
|
- // if (pthread_setname_np(s_monitorThread, "monitor task") != 0) {
|
|
|
|
330
|
- // USER_LOG_ERROR("set name for monitor task fail.");
|
|
|
|
331
|
- // }
|
|
|
|
332
|
-
|
|
|
|
333
|
- while (1) {
|
|
|
|
334
|
- sleep(1);
|
|
|
|
335
|
- }
|
|
|
|
336
|
-}
|
|
|
|
337
|
-
|
|
|
|
338
|
-/* Private functions definition-----------------------------------------------*/
|
|
|
|
339
|
-static T_ZiyanReturnCode ZiyanUser_PrepareSystemEnvironment(void)
|
|
|
|
340
|
-{
|
|
|
|
341
|
- T_ZiyanReturnCode returnCode;
|
|
|
|
342
|
- T_ZiyanOsalHandler osalHandler = {
|
|
|
|
343
|
- .TaskCreate = Osal_TaskCreate,
|
|
|
|
344
|
- .TaskDestroy = Osal_TaskDestroy,
|
|
|
|
345
|
- .TaskSleepMs = Osal_TaskSleepMs,
|
|
|
|
346
|
- .MutexCreate= Osal_MutexCreate,
|
|
|
|
347
|
- .MutexDestroy = Osal_MutexDestroy,
|
|
|
|
348
|
- .MutexLock = Osal_MutexLock,
|
|
|
|
349
|
- .MutexUnlock = Osal_MutexUnlock,
|
|
|
|
350
|
- .SemaphoreCreate = Osal_SemaphoreCreate,
|
|
|
|
351
|
- .SemaphoreDestroy = Osal_SemaphoreDestroy,
|
|
|
|
352
|
- .SemaphoreWait = Osal_SemaphoreWait,
|
|
|
|
353
|
- .SemaphoreTimedWait = Osal_SemaphoreTimedWait,
|
|
|
|
354
|
- .SemaphorePost = Osal_SemaphorePost,
|
|
|
|
355
|
- .Malloc = Osal_Malloc,
|
|
|
|
356
|
- .Free = Osal_Free,
|
|
|
|
357
|
- .GetRandomNum = Osal_GetRandomNum,
|
|
|
|
358
|
- .GetTimeMs = Osal_GetTimeMs,
|
|
|
|
359
|
- .GetTimeUs = Osal_GetTimeUs,
|
|
|
|
360
|
- };
|
|
|
|
361
|
-
|
|
|
|
362
|
- T_ZiyanLoggerConsole printConsole = {
|
|
|
|
363
|
- .func = ZiyanUser_PrintConsole,
|
|
|
|
364
|
- .consoleLevel = ZIYAN_LOGGER_CONSOLE_LOG_LEVEL_INFO,
|
|
|
|
365
|
- .isSupportColor = true,
|
|
|
|
366
|
- };
|
|
|
|
367
|
-
|
|
|
|
368
|
- T_ZiyanLoggerConsole localRecordConsole = {
|
|
|
|
369
|
- .consoleLevel = ZIYAN_LOGGER_CONSOLE_LOG_LEVEL_DEBUG,
|
|
|
|
370
|
- .func = ZiyanUser_LocalWrite,
|
|
|
|
371
|
- .isSupportColor = true,
|
|
|
|
372
|
- };
|
|
|
|
373
|
-
|
|
|
|
374
|
- T_ZiyanHalUartHandler uartHandler = {
|
|
|
|
375
|
- .UartInit = HalUart_Init,
|
|
|
|
376
|
- .UartDeInit = HalUart_DeInit,
|
|
|
|
377
|
- .UartWriteData = HalUart_WriteData,
|
|
|
|
378
|
- .UartReadData = HalUart_ReadData,
|
|
|
|
379
|
- .UartGetStatus = HalUart_GetStatus,
|
|
|
|
380
|
- };
|
|
|
|
381
|
-
|
|
|
|
382
|
- T_ZiyanHalNetworkHandler networkHandler = {
|
|
|
|
383
|
- .NetworkInit = HalNetWork_Init,
|
|
|
|
384
|
- .NetworkDeInit = HalNetWork_DeInit,
|
|
|
|
385
|
- .NetworkGetDeviceInfo = HalNetWork_GetDeviceInfo,
|
|
|
|
386
|
- };
|
|
|
|
387
|
-
|
|
|
|
388
|
- T_ZiyanHalUsbBulkHandler usbBulkHandler = {
|
|
|
|
389
|
- .UsbBulkInit = HalUsbBulk_Init,
|
|
|
|
390
|
- .UsbBulkDeInit = HalUsbBulk_DeInit,
|
|
|
|
391
|
- .UsbBulkWriteData = HalUsbBulk_WriteData,
|
|
|
|
392
|
- .UsbBulkReadData = HalUsbBulk_ReadData,
|
|
|
|
393
|
- .UsbBulkGetDeviceInfo = HalUsbBulk_GetDeviceInfo,
|
|
|
|
394
|
- };
|
|
|
|
395
|
-
|
|
|
|
396
|
- T_ZiyanFileSystemHandler fileSystemHandler = {
|
|
|
|
397
|
- .FileOpen = Osal_FileOpen,
|
|
|
|
398
|
- .FileClose = Osal_FileClose,
|
|
|
|
399
|
- .FileWrite = Osal_FileWrite,
|
|
|
|
400
|
- .FileRead = Osal_FileRead,
|
|
|
|
401
|
- .FileSync = Osal_FileSync,
|
|
|
|
402
|
- .FileSeek = Osal_FileSeek,
|
|
|
|
403
|
- .DirOpen = Osal_DirOpen,
|
|
|
|
404
|
- .DirClose = Osal_DirClose,
|
|
|
|
405
|
- .DirRead = Osal_DirRead,
|
|
|
|
406
|
- .Mkdir = Osal_Mkdir,
|
|
|
|
407
|
- .Unlink = Osal_Unlink,
|
|
|
|
408
|
- .Rename = Osal_Rename,
|
|
|
|
409
|
- .Stat = Osal_Stat,
|
|
|
|
410
|
- };
|
|
|
|
411
|
-
|
|
|
|
412
|
- T_ZiyanSocketHandler socketHandler = {
|
|
|
|
413
|
- .Socket = Osal_Socket,
|
|
|
|
414
|
- .Bind = Osal_Bind,
|
|
|
|
415
|
- .Close = Osal_Close,
|
|
|
|
416
|
- .UdpSendData = Osal_UdpSendData,
|
|
|
|
417
|
- .UdpRecvData = Osal_UdpRecvData,
|
|
|
|
418
|
- .TcpListen = Osal_TcpListen,
|
|
|
|
419
|
- .TcpAccept = Osal_TcpAccept,
|
|
|
|
420
|
- .TcpConnect = Osal_TcpConnect,
|
|
|
|
421
|
- .TcpSendData = Osal_TcpSendData,
|
|
|
|
422
|
- .TcpRecvData = Osal_TcpRecvData,
|
|
|
|
423
|
- };
|
|
|
|
424
|
-
|
|
|
|
425
|
- returnCode = ZiyanPlatform_RegOsalHandler(&osalHandler);
|
|
|
|
426
|
- if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
|
|
|
427
|
- printf("register osal handler error");
|
|
|
|
428
|
- return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
|
|
|
429
|
- }
|
|
|
|
430
|
-
|
|
|
|
431
|
- returnCode = ZiyanPlatform_RegHalUartHandler(&uartHandler);
|
|
|
|
432
|
- if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
|
|
|
433
|
- printf("register hal uart handler error");
|
|
|
|
434
|
- return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
|
|
|
435
|
- }
|
|
|
|
436
|
-
|
|
|
|
437
|
- if (ZiyanUser_LocalWriteFsInit(ZIYAN_LOG_PATH) != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
|
|
|
438
|
- printf("file system init error");
|
|
|
|
439
|
- return ZIYAN_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
|
|
|
|
440
|
- }
|
|
|
|
441
|
-
|
|
|
|
442
|
- returnCode = ZiyanLogger_AddConsole(&printConsole);
|
|
|
|
443
|
- if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
|
|
|
444
|
- printf("add printf console error");
|
|
|
|
445
|
- return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
|
|
|
446
|
- }
|
|
|
|
447
|
-
|
|
|
|
448
|
- returnCode = ZiyanLogger_AddConsole(&localRecordConsole);
|
|
|
|
449
|
- if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
|
|
|
450
|
- printf("add printf console error");
|
|
|
|
451
|
- return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
|
|
|
452
|
- }
|
|
|
|
453
|
-
|
|
|
|
454
|
-
|
|
|
|
455
|
-#if (CONFIG_HARDWARE_CONNECTION == ZIYAN_USE_UART_AND_USB_BULK_DEVICE)
|
|
|
|
456
|
- returnCode = ZiyanPlatform_RegHalUsbBulkHandler(&usbBulkHandler);
|
|
|
|
457
|
- if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
|
|
|
458
|
- printf("register hal usb bulk handler error");
|
|
|
|
459
|
- return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
|
|
|
460
|
- }
|
|
|
|
461
|
-#elif (CONFIG_HARDWARE_CONNECTION == ZIYAN_USE_UART_AND_NETWORK_DEVICE)
|
|
|
|
462
|
- returnCode = ZiyanPlatform_RegHalNetworkHandler(&networkHandler);
|
|
|
|
463
|
- if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
|
|
|
464
|
- printf("register hal network handler error");
|
|
|
|
465
|
- return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
|
|
|
466
|
- }
|
|
|
|
467
|
-
|
|
|
|
468
|
- //Attention: if you want to use camera stream view function, please uncomment it.
|
|
|
|
469
|
- returnCode = ZiyanPlatform_RegSocketHandler(&socketHandler);
|
|
|
|
470
|
- if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
|
|
|
471
|
- printf("register osal socket handler error");
|
|
|
|
472
|
- return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
|
|
|
473
|
- }
|
|
|
|
474
|
-#elif (CONFIG_HARDWARE_CONNECTION == ZIYAN_USE_ONLY_UART)
|
|
|
|
475
|
- /*!< Attention: Only use uart hardware connection.
|
|
|
|
476
|
- */
|
|
|
|
477
|
-#endif
|
|
|
|
478
|
-
|
|
|
|
479
|
- returnCode = ZiyanPlatform_RegFileSystemHandler(&fileSystemHandler);
|
|
|
|
480
|
- if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
|
|
|
481
|
- printf("register osal filesystem handler error");
|
|
|
|
482
|
- return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
|
|
|
483
|
- }
|
|
|
|
484
|
-
|
|
|
|
485
|
- return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
|
|
|
486
|
-}
|
|
|
|
487
|
-
|
|
|
|
488
|
-static T_ZiyanReturnCode ZiyanUser_FillInUserInfo(T_ZiyanUserInfo *userInfo)
|
|
|
|
489
|
-{
|
|
|
|
490
|
- if (userInfo == NULL) {
|
|
|
|
491
|
- return ZIYAN_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
|
|
|
492
|
- }
|
|
|
|
493
|
-
|
|
|
|
494
|
- memset(userInfo->appName, 0, sizeof(userInfo->appName));
|
|
|
|
495
|
- memset(userInfo->appId, 0, sizeof(userInfo->appId));
|
|
|
|
496
|
- memset(userInfo->appKey, 0, sizeof(userInfo->appKey));
|
|
|
|
497
|
- memset(userInfo->appLicense, 0, sizeof(userInfo->appLicense));
|
|
|
|
498
|
- memset(userInfo->developerAccount, 0, sizeof(userInfo->developerAccount));
|
|
|
|
499
|
- memset(userInfo->baudRate, 0, sizeof(userInfo->baudRate));
|
|
|
|
500
|
-
|
|
|
|
501
|
- if (strlen(USER_APP_NAME) >= sizeof(userInfo->appName) ||
|
|
|
|
502
|
- strlen(USER_APP_ID) > sizeof(userInfo->appId) ||
|
|
|
|
503
|
- strlen(USER_APP_KEY) > sizeof(userInfo->appKey) ||
|
|
|
|
504
|
- strlen(USER_APP_LICENSE) > sizeof(userInfo->appLicense) ||
|
|
|
|
505
|
- strlen(USER_DEVELOPER_ACCOUNT) >= sizeof(userInfo->developerAccount) ||
|
|
|
|
506
|
- strlen(USER_BAUD_RATE) > sizeof(userInfo->baudRate)) {
|
|
|
|
507
|
- USER_LOG_ERROR("Length of user information string is beyond limit. Please check.");
|
|
|
|
508
|
- sleep(1);
|
|
|
|
509
|
- return ZIYAN_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
|
|
|
510
|
- }
|
|
|
|
511
|
-
|
|
|
|
512
|
- if (!strcmp(USER_APP_NAME, "your_app_name") ||
|
|
|
|
513
|
- !strcmp(USER_APP_ID, "your_app_id") ||
|
|
|
|
514
|
- !strcmp(USER_APP_KEY, "your_app_key") ||
|
|
|
|
515
|
- !strcmp(USER_BAUD_RATE, "your_app_license") ||
|
|
|
|
516
|
- !strcmp(USER_DEVELOPER_ACCOUNT, "your_developer_account") ||
|
|
|
|
517
|
- !strcmp(USER_BAUD_RATE, "your_baud_rate")) {
|
|
|
|
518
|
- USER_LOG_ERROR(
|
|
|
|
519
|
- "Please fill in correct user information to 'samples/sample_c/platform/linux/manifold2/application/dji_sdk_app_info.h' file.");
|
|
|
|
520
|
- sleep(1);
|
|
|
|
521
|
- return ZIYAN_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
|
|
|
522
|
- }
|
|
|
|
523
|
-
|
|
|
|
524
|
- strncpy(userInfo->appName, USER_APP_NAME, sizeof(userInfo->appName) - 1);
|
|
|
|
525
|
- memcpy(userInfo->appId, USER_APP_ID, USER_UTIL_MIN(sizeof(userInfo->appId), strlen(USER_APP_ID)));
|
|
|
|
526
|
- memcpy(userInfo->appKey, USER_APP_KEY, USER_UTIL_MIN(sizeof(userInfo->appKey), strlen(USER_APP_KEY)));
|
|
|
|
527
|
- memcpy(userInfo->appLicense, USER_APP_LICENSE,
|
|
|
|
528
|
- USER_UTIL_MIN(sizeof(userInfo->appLicense), strlen(USER_APP_LICENSE)));
|
|
|
|
529
|
- memcpy(userInfo->baudRate, USER_BAUD_RATE, USER_UTIL_MIN(sizeof(userInfo->baudRate), strlen(USER_BAUD_RATE)));
|
|
|
|
530
|
- strncpy(userInfo->developerAccount, USER_DEVELOPER_ACCOUNT, sizeof(userInfo->developerAccount) - 1);
|
|
|
|
531
|
-
|
|
|
|
532
|
- return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
|
|
|
533
|
-}
|
|
|
|
534
|
-
|
|
|
|
535
|
-static T_ZiyanReturnCode ZiyanUser_PrintConsole(const uint8_t *data, uint16_t dataLen)
|
|
|
|
536
|
-{
|
|
|
|
537
|
- USER_UTIL_UNUSED(dataLen);
|
|
|
|
538
|
-
|
|
|
|
539
|
- printf("%s", data);
|
|
|
|
540
|
-
|
|
|
|
541
|
- return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
|
|
|
542
|
-}
|
|
|
|
543
|
-
|
|
|
|
544
|
-static T_ZiyanReturnCode ZiyanUser_LocalWrite(const uint8_t *data, uint16_t dataLen)
|
|
|
|
545
|
-{
|
|
|
|
546
|
- uint32_t realLen;
|
|
|
|
547
|
-
|
|
|
|
548
|
- if (s_djiLogFile == NULL) {
|
|
|
|
549
|
- return ZIYAN_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
|
|
|
|
550
|
- }
|
|
|
|
551
|
-
|
|
|
|
552
|
- realLen = fwrite(data, 1, dataLen, s_djiLogFile);
|
|
|
|
553
|
- fflush(s_djiLogFile);
|
|
|
|
554
|
- if (realLen == dataLen) {
|
|
|
|
555
|
- return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
|
|
|
556
|
- } else {
|
|
|
|
557
|
- return ZIYAN_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
|
|
|
|
558
|
- }
|
|
|
|
559
|
-}
|
|
|
|
560
|
-
|
|
|
|
561
|
-static T_ZiyanReturnCode ZiyanUser_LocalWriteFsInit(const char *path)
|
|
|
|
562
|
-{
|
|
|
|
563
|
- T_ZiyanReturnCode djiReturnCode = ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
|
|
|
564
|
- char filePath[ZIYAN_LOG_PATH_MAX_SIZE];
|
|
|
|
565
|
- char systemCmd[ZIYAN_SYSTEM_CMD_STR_MAX_SIZE];
|
|
|
|
566
|
- char folderName[ZIYAN_LOG_FOLDER_NAME_MAX_SIZE];
|
|
|
|
567
|
- time_t currentTime = time(NULL);
|
|
|
|
568
|
- struct tm *localTime = localtime(¤tTime);
|
|
|
|
569
|
- uint16_t logFileIndex = 0;
|
|
|
|
570
|
- uint16_t currentLogFileIndex;
|
|
|
|
571
|
- uint8_t ret;
|
|
|
|
572
|
-
|
|
|
|
573
|
- if (localTime == NULL) {
|
|
|
|
574
|
- printf("Get local time error.\r\n");
|
|
|
|
575
|
- return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
|
|
|
576
|
- }
|
|
|
|
577
|
-
|
|
|
|
578
|
- if (access(ZIYAN_LOG_FOLDER_NAME, F_OK) != 0) {
|
|
|
|
579
|
- sprintf(folderName, "mkdir %s", ZIYAN_LOG_FOLDER_NAME);
|
|
|
|
580
|
- ret = system(folderName);
|
|
|
|
581
|
- if (ret != 0) {
|
|
|
|
582
|
- return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
|
|
|
583
|
- }
|
|
|
|
584
|
- }
|
|
|
|
585
|
-
|
|
|
|
586
|
- s_djiLogFileCnt = fopen(ZIYAN_LOG_INDEX_FILE_NAME, "rb+");
|
|
|
|
587
|
- if (s_djiLogFileCnt == NULL) {
|
|
|
|
588
|
- s_djiLogFileCnt = fopen(ZIYAN_LOG_INDEX_FILE_NAME, "wb+");
|
|
|
|
589
|
- if (s_djiLogFileCnt == NULL) {
|
|
|
|
590
|
- return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
|
|
|
591
|
- }
|
|
|
|
592
|
- } else {
|
|
|
|
593
|
- ret = fseek(s_djiLogFileCnt, 0, SEEK_SET);
|
|
|
|
594
|
- if (ret != 0) {
|
|
|
|
595
|
- printf("Seek log count file error, ret: %d, errno: %d.\r\n", ret, errno);
|
|
|
|
596
|
- return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
|
|
|
597
|
- }
|
|
|
|
598
|
-
|
|
|
|
599
|
- ret = fread((uint16_t *) &logFileIndex, 1, sizeof(uint16_t), s_djiLogFileCnt);
|
|
|
|
600
|
- if (ret != sizeof(uint16_t)) {
|
|
|
|
601
|
- printf("Read log file index error.\r\n");
|
|
|
|
602
|
- }
|
|
|
|
603
|
- }
|
|
|
|
604
|
-
|
|
|
|
605
|
- currentLogFileIndex = logFileIndex;
|
|
|
|
606
|
- logFileIndex++;
|
|
|
|
607
|
-
|
|
|
|
608
|
- ret = fseek(s_djiLogFileCnt, 0, SEEK_SET);
|
|
|
|
609
|
- if (ret != 0) {
|
|
|
|
610
|
- printf("Seek log file error, ret: %d, errno: %d.\r\n", ret, errno);
|
|
|
|
611
|
- return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
|
|
|
612
|
- }
|
|
|
|
613
|
-
|
|
|
|
614
|
- ret = fwrite((uint16_t *) &logFileIndex, 1, sizeof(uint16_t), s_djiLogFileCnt);
|
|
|
|
615
|
- if (ret != sizeof(uint16_t)) {
|
|
|
|
616
|
- printf("Write log file index error.\r\n");
|
|
|
|
617
|
- fclose(s_djiLogFileCnt);
|
|
|
|
618
|
- return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
|
|
|
619
|
- }
|
|
|
|
620
|
-
|
|
|
|
621
|
- fclose(s_djiLogFileCnt);
|
|
|
|
622
|
-
|
|
|
|
623
|
- sprintf(filePath, "%s_%04d_%04d%02d%02d_%02d-%02d-%02d.log", path, currentLogFileIndex,
|
|
|
|
624
|
- localTime->tm_year + 1900, localTime->tm_mon + 1, localTime->tm_mday,
|
|
|
|
625
|
- localTime->tm_hour, localTime->tm_min, localTime->tm_sec);
|
|
|
|
626
|
-
|
|
|
|
627
|
- s_djiLogFile = fopen(filePath, "wb+");
|
|
|
|
628
|
- if (s_djiLogFile == NULL) {
|
|
|
|
629
|
- USER_LOG_ERROR("Open filepath time error.");
|
|
|
|
630
|
- return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
|
|
|
631
|
- }
|
|
|
|
632
|
-
|
|
|
|
633
|
- if (logFileIndex >= ZIYAN_LOG_MAX_COUNT) {
|
|
|
|
634
|
- sprintf(systemCmd, "rm -rf %s_%04d*.log", path, currentLogFileIndex - ZIYAN_LOG_MAX_COUNT);
|
|
|
|
635
|
- ret = system(systemCmd);
|
|
|
|
636
|
- if (ret != 0) {
|
|
|
|
637
|
- printf("Remove file error, ret:%d.\r\n", ret);
|
|
|
|
638
|
- return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
|
|
|
|
639
|
- }
|
|
|
|
640
|
- }
|
|
|
|
641
|
-
|
|
|
|
642
|
- return djiReturnCode;
|
|
|
|
643
|
-}
|
|
|
|
644
|
-
|
|
|
|
645
|
-// #pragma GCC diagnostic push
|
|
|
|
646
|
-// #pragma GCC diagnostic ignored "-Wmissing-noreturn"
|
|
|
|
647
|
-// #pragma GCC diagnostic ignored "-Wreturn-type"
|
|
|
|
648
|
-
|
|
|
|
649
|
-// static void *ZiyanUser_MonitorTask(void *argument)
|
|
|
|
650
|
-// {
|
|
|
|
651
|
-// unsigned int i = 0;
|
|
|
|
652
|
-// unsigned int threadCount = 0;
|
|
|
|
653
|
-// pid_t *tidList = NULL;
|
|
|
|
654
|
-// T_ThreadAttribute *threadAttribute = NULL;
|
|
|
|
655
|
-// T_ZiyanOsalHandler *osalHandler = ZiyanPlatform_GetOsalHandler();
|
|
|
|
656
|
-
|
|
|
|
657
|
-// USER_UTIL_UNUSED(argument);
|
|
|
|
658
|
-
|
|
|
|
659
|
-// while (1) {
|
|
|
|
660
|
-// threadCount = Monitor_GetThreadCountOfProcess(getpid());
|
|
|
|
661
|
-// tidList = osalHandler->Malloc(threadCount * sizeof(pid_t));
|
|
|
|
662
|
-// if (tidList == NULL) {
|
|
|
|
663
|
-// USER_LOG_ERROR("malloc fail.");
|
|
|
|
664
|
-// goto delay;
|
|
|
|
665
|
-// }
|
|
|
|
666
|
-// Monitor_GetTidListOfProcess(getpid(), tidList, threadCount);
|
|
|
|
667
|
-
|
|
|
|
668
|
-// threadAttribute = osalHandler->Malloc(threadCount * sizeof(T_ThreadAttribute));
|
|
|
|
669
|
-// if (threadAttribute == NULL) {
|
|
|
|
670
|
-// USER_LOG_ERROR("malloc fail.");
|
|
|
|
671
|
-// goto freeTidList;
|
|
|
|
672
|
-// }
|
|
|
|
673
|
-// for (i = 0; i < threadCount; ++i) {
|
|
|
|
674
|
-// threadAttribute[i].tid = tidList[i];
|
|
|
|
675
|
-// }
|
|
|
|
676
|
-
|
|
|
|
677
|
-// USER_LOG_DEBUG("thread pcpu:");
|
|
|
|
678
|
-// USER_LOG_DEBUG("tid\tname\tpcpu");
|
|
|
|
679
|
-// for (i = 0; i < threadCount; ++i) {
|
|
|
|
680
|
-// threadAttribute[i].pcpu = Monitor_GetPcpuOfThread(getpid(), tidList[i]);
|
|
|
|
681
|
-// Monitor_GetNameOfThread(getpid(), tidList[i], threadAttribute[i].name, sizeof(threadAttribute[i].name));
|
|
|
|
682
|
-// USER_LOG_DEBUG("%d\t%15s\t%f %%.", threadAttribute[i].tid, threadAttribute[i].name,
|
|
|
|
683
|
-// threadAttribute[i].pcpu);
|
|
|
|
684
|
-// }
|
|
|
|
685
|
-
|
|
|
|
686
|
-// USER_LOG_DEBUG("heap used: %d B.", Monitor_GetHeapUsed(getpid()));
|
|
|
|
687
|
-// USER_LOG_DEBUG("stack used: %d B.", Monitor_GetStackUsed(getpid()));
|
|
|
|
688
|
-
|
|
|
|
689
|
-// osalHandler->Free(threadAttribute);
|
|
|
|
690
|
-// freeTidList:
|
|
|
|
691
|
-// osalHandler->Free(tidList);
|
|
|
|
692
|
-
|
|
|
|
693
|
-// delay:
|
|
|
|
694
|
-// sleep(10);
|
|
|
|
695
|
-// }
|
|
|
|
696
|
-// }
|
|
|
|
697
|
-
|
|
|
|
698
|
-// // static T_ZiyanReturnCode ZiyanTest_HighPowerApplyPinInit()
|
|
|
|
699
|
-// // {
|
|
|
|
700
|
-// // return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
|
|
|
701
|
-// // }
|
|
|
|
702
|
-
|
|
|
|
703
|
-// // static T_ZiyanReturnCode ZiyanTest_WriteHighPowerApplyPin(E_ZiyanPowerManagementPinState pinState)
|
|
|
|
704
|
-// // {
|
|
|
|
705
|
-// // //attention: please pull up the HWPR pin state by hardware.
|
|
|
|
706
|
-// // return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
|
|
|
707
|
-// // }
|
|
|
|
708
|
-
|
|
|
|
709
|
-static void ZiyanUser_NormalExitHandler(int signalNum)
|
|
|
|
710
|
-{
|
|
|
|
711
|
- USER_UTIL_UNUSED(signalNum);
|
|
|
|
712
|
- exit(0);
|
|
|
|
713
|
-}
|
|
|
|
714
|
-
|
|
|
|
715
|
-#pragma GCC diagnostic pop
|
|
|
|
716
|
-
|
|
|
|
717
|
-/****************** (C) COPYRIGHT ZIYAN Innovations *****END OF FILE****/ |
|
|