From c7b7298bbc3d631953c4cfe3cfc3d674a9d6089b Mon Sep 17 00:00:00 2001 From: tangchao0503 <735056338@qq.com> Date: Mon, 26 Dec 2022 17:20:31 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E8=AE=A2=E9=98=85psdk=E4=B8=AD=E7=9A=84gp?= =?UTF-8?q?s=E6=97=A5=E6=9C=9F=E5=92=8C=E6=97=B6=E9=97=B4=EF=BC=88?= =?UTF-8?q?=E6=A0=BC=E6=9E=97=E5=A8=81=E6=B2=BB=E6=97=B6=E9=97=B4=EF=BC=89?= =?UTF-8?q?=EF=BC=8C=E5=B9=B6=E8=BD=AC=E6=8D=A2=E4=B8=BA=E5=8C=97=E4=BA=AC?= =?UTF-8?q?=E6=97=B6=E9=97=B4=EF=BC=8C=E9=80=9A=E8=BF=87date=20-s=E5=91=BD?= =?UTF-8?q?=E4=BB=A4=E8=AE=BE=E7=BD=AElinux=E7=B3=BB=E7=BB=9F=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E4=B8=BA=E5=8C=97=E4=BA=AC=E6=97=B6=E9=97=B4=EF=BC=9B?= =?UTF-8?q?=202.=20=E4=BF=AE=E6=94=B9=E7=95=8C=E9=9D=A2=EF=BC=8C=E6=98=BE?= =?UTF-8?q?=E7=A4=BAsbg=E6=83=AF=E5=AF=BC=E5=8D=AB=E6=98=9F=E9=A2=97?= =?UTF-8?q?=E6=95=B0=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../camera_media_emu/test_payload_cam_media.c | 10 +- .../test_data_subscription.c | 202 ++++++++++++++++++ .../test_data_subscription.h | 14 ++ sample/api_sample/widget/test_widget.c | 13 +- .../cn_big_screen/widget_config.json | 4 +- .../linux/manifold2/hal/hal_network.c | 2 +- 6 files changed, 234 insertions(+), 11 deletions(-) diff --git a/sample/api_sample/camera_media_emu/test_payload_cam_media.c b/sample/api_sample/camera_media_emu/test_payload_cam_media.c index a8e5708..a747e7e 100644 --- a/sample/api_sample/camera_media_emu/test_payload_cam_media.c +++ b/sample/api_sample/camera_media_emu/test_payload_cam_media.c @@ -201,11 +201,11 @@ T_PsdkReturnCode PsdkTest_CameraMediaInit(void) } //创建线程执行用户自定义函数!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -// if (PsdkOsal_TaskCreate(&s_userSendVideoThread, UserCameraMedia_SendVideoTask_tc, "user_camera_media_task", 2048, -// NULL) != PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { -// PsdkLogger_UserLogError("user send video task create error."); -// return PSDK_ERROR_SYSTEM_MODULE_CODE_UNKNOWN; -// } + if (PsdkOsal_TaskCreate(&s_userSendVideoThread, UserCameraMedia_SendVideoTask, "user_camera_media_task", 2048, + NULL) != PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { + PsdkLogger_UserLogError("user send video task create error."); + return PSDK_ERROR_SYSTEM_MODULE_CODE_UNKNOWN; + } return PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS; } diff --git a/sample/api_sample/data_subscription/test_data_subscription.c b/sample/api_sample/data_subscription/test_data_subscription.c index 9d7b4d3..09ab1d8 100644 --- a/sample/api_sample/data_subscription/test_data_subscription.c +++ b/sample/api_sample/data_subscription/test_data_subscription.c @@ -42,6 +42,8 @@ static void *UserDataSubscription_Task(void *arg); static T_PsdkReturnCode PsdkTest_DataSubscriptionReceiveQuaternionCallback(const uint8_t *data, uint16_t dataSize, const T_PsdkDataSubscriptiontTimestamp *timestamp); +static char* uitoa(unsigned int n, char *s); +static int GMT_toLocalTime(unsigned long gmt_time,unsigned int* year,unsigned int* month,unsigned int* day,unsigned int* hour,unsigned int* minute,unsigned int* sec); /* Private variables ---------------------------------------------------------*/ static T_PsdkTaskHandle s_userDataSubscriptionThread; @@ -81,6 +83,22 @@ T_PsdkReturnCode PsdkTest_DataSubscriptionInit(void) return PSDK_ERROR_SYSTEM_MODULE_CODE_UNKNOWN; } + //订阅gps日期 + //要先订阅消息(PsdkDataSubscription_RegTopicSync),才能获取消息(PsdkDataSubscription_GetValueOfTopicWithTimestamp) + psdkStat = PsdkDataSubscription_RegTopicSync(PSDK_DATA_SUBSCRIPTION_TOPIC_GPS_DATE, 1,NULL); + if (psdkStat != PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { + PsdkLogger_UserLogError("Subscribe topic QUATERNION error."); + return PSDK_ERROR_SYSTEM_MODULE_CODE_UNKNOWN; + } + + //订阅gps时间 + //要先订阅消息(PsdkDataSubscription_RegTopicSync),才能获取消息(PsdkDataSubscription_GetValueOfTopicWithTimestamp) + psdkStat = PsdkDataSubscription_RegTopicSync(PSDK_DATA_SUBSCRIPTION_TOPIC_GPS_TIME, 1,NULL); + if (psdkStat != PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { + PsdkLogger_UserLogError("Subscribe topic QUATERNION error."); + return PSDK_ERROR_SYSTEM_MODULE_CODE_UNKNOWN; + } + //创建用户任务 //要先订阅消息(PsdkDataSubscription_RegTopicSync),才能获取消息(PsdkDataSubscription_GetValueOfTopicWithTimestamp) if (PsdkOsal_TaskCreate(&s_userDataSubscriptionThread, UserDataSubscription_Task, "user_subscription_task", @@ -107,9 +125,13 @@ static void *UserDataSubscription_Task(void *arg) T_PsdkDataSubscriptionVelocity velocity = {0}; T_PsdkDataSubscriptiontTimestamp timestamp = {0}; T_PsdkDataSubscriptionGpsPosition gpsPosition = {0}; + T_PsdkDataSubscriptionGpsDate gpsDate={0}; + T_PsdkDataSubscriptionGpsTime gpsTime={0}; USER_UTIL_UNUSED(arg); + int counter = 0; + bool isGetGpsDate_time = true; while (1) { PsdkOsal_TaskSleepMs(1000 / DATA_SUBSCRIPTION_TASK_FREQ); @@ -147,9 +169,189 @@ static void *UserDataSubscription_Task(void *arg) } else { PsdkLogger_UserLogDebug("gps position: x %d y %d z %d.", gpsPosition.x, gpsPosition.y, gpsPosition.z); }//PsdkLogger_UserLogInfo + + + + psdkStat = PsdkDataSubscription_GetValueOfTopicWithTimestamp(PSDK_DATA_SUBSCRIPTION_TOPIC_GPS_DATE, + (uint8_t *) &gpsDate, + sizeof(T_PsdkDataSubscriptionGpsDate), + ×tamp); + if (psdkStat != PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { + PsdkLogger_UserLogError("get value of topic gps DATE error."); + isGetGpsDate_time = false; + } else { + PsdkLogger_UserLogDebug("timestamp: millisecond %u microsecond %u.", timestamp.millisecond, + timestamp.microsecond); + PsdkLogger_UserLogDebug("gps DATE: %d.", gpsDate); + }//PsdkLogger_UserLogInfo + + psdkStat = PsdkDataSubscription_GetValueOfTopicWithTimestamp(PSDK_DATA_SUBSCRIPTION_TOPIC_GPS_TIME, + (uint8_t *) &gpsTime, + sizeof(T_PsdkDataSubscriptionGpsTime), + ×tamp); + if (psdkStat != PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { + PsdkLogger_UserLogError("get value of topic gps TIME error."); + isGetGpsDate_time = false; + } else { + PsdkLogger_UserLogDebug("gps TIME: %d.", gpsTime); + }//PsdkLogger_UserLogInfo + + + if(counter>1 &&counter<10 && isGetGpsDate_time)//避免dji的bug:第一次获取的gpsDate和gpsTime都为0 + { + char *gpsDate_str = (char *)malloc(sizeof(char)*50); + char *gpsTime_str = (char *)malloc(sizeof(char)*20); + + + uitoa(gpsDate,gpsDate_str); + uitoa(gpsTime,gpsTime_str); + strcat(gpsDate_str, gpsTime_str); +// printf("pingjie----------------------------------------------:%s\n",gpsDate_str); + + + char *year = (char *)malloc(sizeof(char)*10); + char *mon = (char *)malloc(sizeof(char)*10); + char *mday = (char *)malloc(sizeof(char)*10); + char *hour = (char *)malloc(sizeof(char)*10); + char *min = (char *)malloc(sizeof(char)*10); + char *sec = (char *)malloc(sizeof(char)*10); + + strncpy(year, gpsDate_str, 4); + strncpy(mon, gpsDate_str+4, 2); + strncpy(mday, gpsDate_str+6, 2); + if(gpsTime >= 100000)//dji时间格式为hhmmss,但是当时间小于上午10点时,小时位(hh)只有1位:21923(2:19:23); + { + strncpy(hour, gpsTime_str, 2); + strncpy(min, gpsTime_str+2, 2); + strncpy(sec, gpsTime_str+4, 2); + } + else + { + strncpy(hour, gpsTime_str, 1); + strncpy(min, gpsTime_str+1, 2); + strncpy(sec, gpsTime_str+3, 2); + } + + +// printf("year:%s\n",year); +// printf("mon:%s\n",mon); +// printf("mday:%s\n",mday); +// printf("hour:%s\n",hour); +// printf("min:%s\n",min); +// printf("sec:%s\n",sec); + + struct tm info; + info.tm_year = atoi(year) - 1900;; + info.tm_mon = atoi(mon) - 1; + info.tm_mday = atoi(mday); + info.tm_hour = atoi(hour); + info.tm_min = atoi(min); + info.tm_sec = atoi(sec); + info.tm_isdst = -1; + + int gmt_time = mktime(&info); + + LocalTimeInfo LocalTime; + + GMT_toLocalTime(gmt_time,&LocalTime.year,&LocalTime.month,&LocalTime.day,&LocalTime.hour,&LocalTime.minute,&LocalTime.second); +// printf("MyLocalTime=%d-%d-%d %d:%d:%d\n",LocalTime.year,LocalTime.month,LocalTime.day,LocalTime.hour,LocalTime.minute,LocalTime.second); + + char *timeParam = (char *)malloc(sizeof(char)*500); + sprintf(timeParam,"%d-%d-%d %d:%d:%d",LocalTime.year,LocalTime.month,LocalTime.day,LocalTime.hour,LocalTime.minute,LocalTime.second); +// printf("----------: %s",timeParam); + + char *command = (char *)malloc(sizeof(char)*100); + + strcat(command, "date -s \""); + strcat(command, timeParam); + strcat(command, "\""); + +// printf("command---:%s\n",command); + system(command); + } + counter++; } } +char* uitoa(unsigned int n, char *s) +{ + int i, j; + i = 0; + char buf[20]; + memset(buf, 0, sizeof(buf)); + do{ + buf[i++] = n % 10 + '0';//取下一个数字 + } while ((n /= 10)>0);//删除该数字 + i -= 1; + for (j = 0; i >= 0; j++, i--)//生成的数字是逆序的,所以要逆序输出 + s[j] = buf[i]; + s[j] = '\0'; + return s; +} + +/*格林威治时间就是1970年01月01日00时00分00秒起至现在的总秒数*/ +/*通过格林威治时间,计算本地时间*/ +int GMT_toLocalTime(unsigned long gmt_time,unsigned int* year,unsigned int* month,unsigned int* day,unsigned int* hour,unsigned int* minute,unsigned int* sec) +{ + int TIME_ZONE = 8; + unsigned long gmtTime = gmt_time + TIME_ZONE * 60 * 60; + int leap_years = 0; + int month_days[] = {31, 28, 31,30,31, 30,31,31, 30,31,30,31}; + int i =0; + int days; + + *sec = (int)(gmtTime%60);//秒钟数 + gmtTime = gmtTime/60;//总共有多少分钟 + + *minute = (int)(gmtTime%60); + gmtTime = gmtTime/60;//总共有多少小时 + + *hour = (int)(gmtTime%24); + gmtTime = gmtTime/24;//总共有多少天 + + //去掉小时分钟秒钟后,转换成从公元元年开始到现在的天数 + //不包括今天 + gmtTime += 719162; +// 首先不考虑闰年计算年份和天数 +// 计算年份 + *year = (int)(gmtTime/365); +// days = (从公元元年开始到year的闰年个数 + 当前年份已经度过的天数)除以365后的余数 + days = (int)(gmtTime%365); + while(1) + { + //总共有多少个闰年,天数要相应的减去这些天数 + leap_years = (*year)/4 - (*year)/100; //计算普通闰年 + leap_years += (*year)/400; //加上世纪闰年 + if(days < leap_years) + { + days+=365; + (*year)--; + }else break; + } + days -= leap_years; + (*year)++; + days++; + //计算今年总共度过了多少秒 + if(((*year)%4 == 0 && (*year) % 100!=0) || (*year)%400==0) month_days[1] = 29;//今年是闰年,修改二月份为29天 + *month = 1; + for(i=0;i<12;i++) + { + if(days <= month_days[i]) + { + break; + } + else + { + days -=month_days[i]; + (*month)++; + } + } + *day =days; + return 0; +} + + + #ifndef __CC_ARM #pragma GCC diagnostic pop #endif diff --git a/sample/api_sample/data_subscription/test_data_subscription.h b/sample/api_sample/data_subscription/test_data_subscription.h index 8228c1e..17bcfe4 100644 --- a/sample/api_sample/data_subscription/test_data_subscription.h +++ b/sample/api_sample/data_subscription/test_data_subscription.h @@ -33,6 +33,20 @@ #include "psdk_typedef.h" #include "psdk_data_subscription.h" +#include +#include +#include + +typedef struct LocalTimeInformation +{ + unsigned int year; + unsigned int month; + unsigned int day; + unsigned int hour; + unsigned int minute; + unsigned int second; +}LocalTimeInfo; + #ifdef __cplusplus extern "C" { #endif diff --git a/sample/api_sample/widget/test_widget.c b/sample/api_sample/widget/test_widget.c index 7d65d5e..1401805 100644 --- a/sample/api_sample/widget/test_widget.c +++ b/sample/api_sample/widget/test_widget.c @@ -79,6 +79,7 @@ static int s_stateOfFile=0; static char * s_strStateOfSbg="未打开"; static char * s_strSbgAccuracy="1000"; +static char * s_strSbgSatelliteCounter="0"; static char * s_strSbgSolutionMode="UNINITIALIZED"; static char * s_strStateOfXimea="未打开"; @@ -268,7 +269,7 @@ static void *PsdkTest_WidgetTask(void *arg) //snprintf(message, PSDK_WIDGET_FLOATING_WINDOW_MSG_MAX_LEN, "System time: %u ms;\nMAG: %d;\nIMAGER: %d;\nIMU: %d;\nFile: %d;\n", sysTimeMs, s_sbgMagState, s_stateOfXimea, s_stateOfSbg, s_stateOfFile); - snprintf(message, PSDK_WIDGET_FLOATING_WINDOW_MSG_MAX_LEN, "System time: %u ms;\n光谱仪: %s;\n惯导: %s;\n精度: %s;\n", sysTimeMs, s_strStateOfXimea, s_strStateOfSbg, s_strSbgAccuracy); + snprintf(message, PSDK_WIDGET_FLOATING_WINDOW_MSG_MAX_LEN, "System time: %u ms;\n光谱仪: %s;\n惯导: %s;\n精度: %s;\n卫星: %s;\n", sysTimeMs, s_strStateOfXimea, s_strStateOfSbg, s_strSbgAccuracy, s_strSbgSatelliteCounter); psdkStat = PsdkWidgetFloatingWindow_ShowMessage(message); if (psdkStat != PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { @@ -330,9 +331,14 @@ static void *PsdkTest_IrisRecordSystemChanged(void *arg)// //printf("You got a message (%s%) from client.\nIt's ip is%s, port is %d.\n",buf,inet_ntoa(client.sin_addr),htons(client.sin_port)); - char * result[2]; + char * result[3]; result[0] = strtok( buf, "," ); result[1] = strtok( NULL, "," ); + result[2] = strtok( NULL, "," ); + +// printf("result[0]: %s\n", result[0]); +// printf("result[1]: %s\n\n", result[1]); +// printf("result[2]: %s\n\n", result[2]); if (strcmp(result[0],"sbg") == 0) @@ -361,9 +367,10 @@ static void *PsdkTest_IrisRecordSystemChanged(void *arg)// } else if (strcmp(result[0],"Accuracy") == 0) { - +// printf("惯导定位精度为: %s\n\n", result[1]); s_strSbgAccuracy=result[1]; + s_strSbgSatelliteCounter=result[2]; // s_sbgMagState = atoi(result[1]); diff --git a/sample/api_sample/widget/widget_file/cn_big_screen/widget_config.json b/sample/api_sample/widget/widget_file/cn_big_screen/widget_config.json index 2314bf8..0ba2bee 100644 --- a/sample/api_sample/widget/widget_file/cn_big_screen/widget_config.json +++ b/sample/api_sample/widget/widget_file/cn_big_screen/widget_config.json @@ -104,10 +104,10 @@ "item_name": "等待指令" }, { - "item_name": "无" + "item_name": "重启图传" }, { - "item_name": "重启电脑" + "item_name": "重启300TC" }, { "item_name": "关机" diff --git a/sample/platform/linux/manifold2/hal/hal_network.c b/sample/platform/linux/manifold2/hal/hal_network.c index 66df06d..f501aaa 100644 --- a/sample/platform/linux/manifold2/hal/hal_network.c +++ b/sample/platform/linux/manifold2/hal/hal_network.c @@ -32,7 +32,7 @@ #include "psdk_logger.h" /* Private constants ---------------------------------------------------------*/ -#define LINUX_NETWORK_DEV "eth0"//enx00e04c360a7d +#define LINUX_NETWORK_DEV "eth1"//enx00e04c360a7d #define LINUX_CMD_STR_MAX_SIZE (128) /* Private types -------------------------------------------------------------*/