time(&rawtime);
timeinfo = localtime(&rawtime);
+ if (timeinfo == NULL) {
+ printf("Error: localtime() returned NULL\n");
+ snprintf(timestamp_str, max_len, "1970-01-01 00:00:00");
+ return;
+ }
snprintf(timestamp_str, max_len, "%04d-%02d-%02d %02d:%02d:%02d",
timeinfo->tm_year + 1900,
gettimeofday(&tv, NULL);
timeinfo = localtime(&tv.tv_sec);
+ if (timeinfo == NULL) {
+ printf("Error: localtime() returned NULL\n");
+ snprintf(timestamp_str, max_len, "1970-01-01 00:00:00.000");
+ return;
+ }
snprintf(timestamp_str, max_len, "%04d-%02d-%02d %02d:%02d:%02d.%03ld",
timeinfo->tm_year + 1900,
time(&rawtime); // 获取UTC时间戳
timeinfo = gmtime(&rawtime); // 转换为UTC时间(无时区偏移)
-
- utcTime.year = timeinfo->tm_year + 1900;
- utcTime.month = timeinfo->tm_mon + 1;
- utcTime.day = timeinfo->tm_mday;
- utcTime.hour = timeinfo->tm_hour;
- utcTime.minute = timeinfo->tm_min;
- utcTime.second = timeinfo->tm_sec;
+ if (timeinfo == NULL) {
+ printf("Error: gmtime() returned NULL\n");
+ return 0;
+ } else {
+ utcTime.year = timeinfo->tm_year + 1900;
+ utcTime.month = timeinfo->tm_mon + 1;
+ utcTime.day = timeinfo->tm_mday;
+ utcTime.hour = timeinfo->tm_hour;
+ utcTime.minute = timeinfo->tm_min;
+ utcTime.second = timeinfo->tm_sec;
+ }
printf("year[%d], mon[%d], day[%d], hour[%d], min[%d], sec[%d] \r\n",
utcTime.year,utcTime.month,utcTime.day,
uint16_t *type = (uint16_t *)g_gnssServiceBuff;
if (type[0] == MSG_TYPE_ASCII) {
-
- g_gnssServiceBuff[ret] = '\0';
+ // 确保ret在有效范围内再写入结束符
+ if (ret > 0 && ret < REPORT_MAX_BYTES) {
+ g_gnssServiceBuff[ret] = '\0';
+ } else {
+ printf("Error: Invalid ret value: %d, skipping this data\n", ret);
+ continue;
+ }
if (ret > MSG_CONTENT_IDX) {
char* pbuf = (char *)&g_gnssServiceBuff[MSG_CONTENT_IDX];
return;
}
- // 启动定时器(100ms间隔)
+ // 启动定时器(1000ms间隔)
int tick = osMs2Tick(1000);
osStatus_t ret = osTimerStart(g_stop_wait_timer, tick);
if (ret != osOK) {