|
|
@@ -23,6 +23,7 @@
|
|
|
#include <ymodem.h>
|
|
|
#include "beep.h"
|
|
|
#include <selfcheck.h>
|
|
|
+#include <s2j.h>
|
|
|
#define DBG_ENABLE
|
|
|
#define DBG_COLOR
|
|
|
#define DBG_TAG "dtu"
|
|
|
@@ -378,6 +379,51 @@ int dtu_data_play(void)
|
|
|
return RT_EOK;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+void get_iso8601_utc_time(char *buffer, size_t buffer_size,uint8_t time_h) {
|
|
|
+ time_t now_seconds;
|
|
|
+ struct tm *timeinfo;
|
|
|
+ // 获取当前时间(秒)
|
|
|
+ time(&now_seconds);
|
|
|
+ // 将 time_t 转换为 UTC 时间的 struct tm
|
|
|
+ timeinfo = gmtime(&now_seconds);
|
|
|
+ // 获取当前时间的毫秒部分
|
|
|
+ long milliseconds = rt_tick_get() % RT_TICK_PER_SECOND * (1000 / RT_TICK_PER_SECOND);
|
|
|
+ if(time_h<=23)
|
|
|
+ {
|
|
|
+ //工作结束在第二天
|
|
|
+ if(device_status.startBar>time_h)
|
|
|
+ {
|
|
|
+ // 格式化时间为 ISO 8601 标准 (UTC),在第二天日期需要+1
|
|
|
+ // 创建一个新的 tm 结构体并复制当前时间信息
|
|
|
+ struct tm next_day = *timeinfo;
|
|
|
+ // 增加一天
|
|
|
+ next_day.tm_mday += 1;
|
|
|
+ // 标准化时间结构体
|
|
|
+ mktime(&next_day);
|
|
|
+ // 使用标准化后的时间
|
|
|
+ timeinfo = &next_day;
|
|
|
+ }
|
|
|
+ // 格式化时间为 ISO 8601 标准 (UTC),并添加毫秒部分
|
|
|
+ snprintf(buffer, buffer_size, "%04d-%02d-%02dT%02d:00:00.000Z",
|
|
|
+ timeinfo->tm_year + 1900,
|
|
|
+ timeinfo->tm_mon + 1,
|
|
|
+ timeinfo->tm_mday,
|
|
|
+ time_h);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ // 格式化时间为 ISO 8601 标准 (UTC),并添加毫秒部分
|
|
|
+ snprintf(buffer, buffer_size, "%04d-%02d-%02dT%02d:%02d:%02d.%03ldZ",
|
|
|
+ timeinfo->tm_year + 1900,
|
|
|
+ timeinfo->tm_mon + 1,
|
|
|
+ timeinfo->tm_mday,
|
|
|
+ timeinfo->tm_hour,
|
|
|
+ timeinfo->tm_min,
|
|
|
+ timeinfo->tm_sec,milliseconds);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
char * makeJson_ReadInfo()
|
|
|
{
|
|
|
cJSON * rJsonRoot = NULL;
|
|
|
@@ -676,6 +722,7 @@ char *makeJson_C01_Warn(uint16_t code,double process)
|
|
|
cJSON_Delete(pJsonRoot);
|
|
|
return w;
|
|
|
}
|
|
|
+
|
|
|
/*生成JSON数据*/
|
|
|
char * makeJson()
|
|
|
{
|
|
|
@@ -710,22 +757,6 @@ char * makeJson()
|
|
|
rt_kprintf("cJSON pJsonRoot NULL!!!\n");
|
|
|
return NULL;
|
|
|
}
|
|
|
- if(strstr(device_status.project,"A7_DTU_V3")!=RT_NULL)
|
|
|
- {
|
|
|
- cJSON_AddStringToObject(pJsonRoot, "cmd", "read_data");
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- cJSON_AddStringToObject(pJsonRoot, "cmd", "data");
|
|
|
- }
|
|
|
-
|
|
|
- cJSON * pSubJson = NULL;
|
|
|
- pSubJson = cJSON_CreateObject();
|
|
|
- if(NULL==pSubJson)
|
|
|
- {
|
|
|
- rt_kprintf("cJSON pSubJson NULL!!!\n");
|
|
|
- return NULL;
|
|
|
- }
|
|
|
memset(device_status.driver,0,sizeof(device_status.driver));
|
|
|
if(device_status.version_type==1)
|
|
|
{
|
|
|
@@ -742,7 +773,60 @@ char * makeJson()
|
|
|
}
|
|
|
else if (device_status.version_type==5) {
|
|
|
rt_sprintf(device_status.driver,"%s-%s",VERSION_V5,device_status.driver_4g);
|
|
|
+ cJSON_AddStringToObject(pJsonRoot, "DEVICE_SERIAL_NUMBER", device_status.imei);
|
|
|
+ cJSON_AddStringToObject(pJsonRoot, "VERSION", device_status.driver);
|
|
|
+ cJSON_AddStringToObject(pJsonRoot, "SIGNAL", device_status.csq);
|
|
|
+ cJSON_AddStringToObject(pJsonRoot, "SIM", device_status.iccid);
|
|
|
+ static char iso8601_time[32]; // 确保缓冲区足够大以容纳时间字符串
|
|
|
+ get_iso8601_utc_time(iso8601_time, sizeof(iso8601_time),24);
|
|
|
+ cJSON_AddStringToObject(pJsonRoot, "UPDATE_DATE", iso8601_time);
|
|
|
+ cJSON_AddStringToObject(pJsonRoot, "STATUS", "STATUS_ONLINE");
|
|
|
+ cJSON_AddStringToObject(pJsonRoot, "STATUS_DESCRIPTION","设备运行正常");
|
|
|
+ cJSON_AddStringToObject(pJsonRoot, "LOCATION","113.0,34.0");
|
|
|
+ static char iso8601_time_s[32]; // 确保缓冲区足够大以容纳时间字符串
|
|
|
+ get_iso8601_utc_time(iso8601_time_s, sizeof(iso8601_time_s),device_status.startBar);
|
|
|
+ cJSON_AddStringToObject(pJsonRoot, "START_TIME",iso8601_time_s);
|
|
|
+ get_iso8601_utc_time(iso8601_time_s, sizeof(iso8601_time_s),device_status.stopBar);
|
|
|
+ cJSON_AddStringToObject(pJsonRoot, "END_TIME",iso8601_time_s);
|
|
|
+
|
|
|
+ cJSON_AddNumberToObject(pJsonRoot, "CONTRIL", !device_status.timeSwitch);
|
|
|
+ cJSON_AddNumberToObject(pJsonRoot, "TT", device_status.sunBar);
|
|
|
+ cJSON_AddNumberToObject(pJsonRoot, "WS", device_status.work_status);
|
|
|
+ cJSON_AddNumberToObject(pJsonRoot, "TPS", device_status.tpl);
|
|
|
+ cJSON_AddNumberToObject(pJsonRoot, "RPS", device_status.rain_status);
|
|
|
+ cJSON_AddNumberToObject(pJsonRoot, "LPS", device_status.sun_status);
|
|
|
+ cJSON_AddNumberToObject(pJsonRoot, "TEMPERATURE", 20.2);
|
|
|
+ cJSON_AddNumberToObject(pJsonRoot, "HUMIDITY", 60.2);
|
|
|
+ char *p = cJSON_PrintUnformatted(pJsonRoot);
|
|
|
+ if(NULL == p)
|
|
|
+ {
|
|
|
+ cJSON_Delete(pJsonRoot);
|
|
|
+ rt_kprintf("cJSON_Delete NULL!!!\n");
|
|
|
+ return NULL;
|
|
|
+ }
|
|
|
+ cJSON_Delete(pJsonRoot);
|
|
|
+ return p;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ cJSON * pSubJson = NULL;
|
|
|
+ pSubJson = cJSON_CreateObject();
|
|
|
+ if(NULL==pSubJson)
|
|
|
+ {
|
|
|
+ rt_kprintf("cJSON pSubJson NULL!!!\n");
|
|
|
+ return NULL;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(strstr(device_status.project,"A7_DTU_V3")!=RT_NULL)
|
|
|
+ {
|
|
|
+ cJSON_AddStringToObject(pJsonRoot, "cmd", "read_data");
|
|
|
}
|
|
|
+ else
|
|
|
+ {
|
|
|
+ cJSON_AddStringToObject(pJsonRoot, "cmd", "data");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
if(device_status.sensor_485_sta!=0)
|
|
|
{
|
|
|
if(strstr(device_status.driver,"485")==RT_NULL)
|