|
|
@@ -49,7 +49,7 @@ rt_thread_t dtu_send_data = RT_NULL;
|
|
|
|
|
|
rt_device_t dtuserial; /*串口设备句柄*/
|
|
|
struct serial_configure dtuconfig = RT_SERIAL_CONFIG_DEFAULT; /*初始化配置参数*/
|
|
|
-static int num_updata = 60;
|
|
|
+
|
|
|
static uint8_t makejson_sta = 0;
|
|
|
|
|
|
static int DTU_uart2_init(void)
|
|
|
@@ -71,6 +71,7 @@ static int DTU_uart2_init(void)
|
|
|
/*数据发送*/
|
|
|
void DTU_Write(char *fmt, ...)
|
|
|
{
|
|
|
+ const char dtu_conf[4] = {device_status.vol,0x00,0x00,0x00};
|
|
|
va_list arg;
|
|
|
static char dtu_str[800];
|
|
|
rt_size_t str_length;
|
|
|
@@ -80,6 +81,14 @@ void DTU_Write(char *fmt, ...)
|
|
|
str_length = 800 - 1;
|
|
|
|
|
|
rt_device_write(dtuserial, 0, dtu_str, str_length);
|
|
|
+ if(strstr(dtu_str,"volume")!=RT_NULL)
|
|
|
+ {
|
|
|
+ rt_device_write(dtuserial,0,dtu_conf,4);
|
|
|
+ }
|
|
|
+ else if (strstr(dtu_str,"reset")!=RT_NULL) {
|
|
|
+ const char dtu_conf[4] = {7,0x00,0x00,0x00};
|
|
|
+ rt_device_write(dtuserial,0,dtu_conf,4);
|
|
|
+ }
|
|
|
va_end(arg);
|
|
|
memset(dtu_str,'\0',sizeof(dtu_str));
|
|
|
}
|
|
|
@@ -160,44 +169,29 @@ static void dtu_thread_entry_recv(void *parameter)
|
|
|
static void dtu_thread_entry_send(void *parameter)
|
|
|
{
|
|
|
|
|
|
- static uint8_t power_sta = 1;//开机置1
|
|
|
- static uint8_t dev_sta = 1;//开机置1
|
|
|
- rt_thread_delay(10000); //20S等待联网
|
|
|
- if(atoi(device_status.net)==1) num_updata = 0;
|
|
|
- while(1)
|
|
|
+ device_status.power_status = 1;
|
|
|
+ device_status.num_updata = 0;
|
|
|
+ rt_thread_delay(10000);
|
|
|
+ while(atoi(device_status.net)==0)
|
|
|
{
|
|
|
- if(num_updata!=0)
|
|
|
+ if(device_status.num_updata!=0)
|
|
|
{
|
|
|
- num_updata --;
|
|
|
-// //屏幕休眠
|
|
|
- if(num_updata==(device_status.dattim * 60-10))
|
|
|
+ device_status.num_updata--;
|
|
|
+ //屏幕休眠
|
|
|
+ if(device_status.num_updata==(device_status.dattim * 60-10))
|
|
|
{
|
|
|
HMI_WRITE("sleep=%d",1);
|
|
|
}
|
|
|
- if(Read_Real_Voltage()/100<12&&power_sta==1)
|
|
|
+ if(Read_Real_Voltage()/100<12&&device_status.power_status==1)
|
|
|
{
|
|
|
- rt_thread_delay(500);
|
|
|
- static char warn_power[20];
|
|
|
- sprintf(warn_power,"Power down");
|
|
|
- char * res_power_warn = makeJson_Warn(warn_power,"power");
|
|
|
- DTU_Write("%s",res_power_warn);
|
|
|
- rt_free(res_power_warn);
|
|
|
- power_sta = 0;
|
|
|
- num_updata=0;
|
|
|
- rt_thread_delay(2000);
|
|
|
+ DTU_Write("%s",makeJson_Warn("power down","power"));
|
|
|
+ device_status.power_status = 0;
|
|
|
+ rt_thread_delay(1500);
|
|
|
}
|
|
|
}
|
|
|
else {
|
|
|
char *readinfo = makeJson_ReadInfo();
|
|
|
LOG_I("upload data:%s\n",readinfo);
|
|
|
- if(dev_sta==1)
|
|
|
- {
|
|
|
- DTU_Write("%s",makeJson_Warn("turnon", "device_stm32"));
|
|
|
- dev_sta = 0;
|
|
|
- rt_thread_delay(500);
|
|
|
- }
|
|
|
- DTU_Write("%s",readinfo);
|
|
|
- rt_thread_delay(2000);
|
|
|
UpLoad_Data();
|
|
|
rt_free(readinfo);
|
|
|
if(atoi(device_status.fuse_voltage)<1)
|
|
|
@@ -209,8 +203,9 @@ static void dtu_thread_entry_send(void *parameter)
|
|
|
DTU_Write("%s",res_fuse_warn);
|
|
|
rt_free(res_fuse_warn);
|
|
|
}
|
|
|
- num_updata = device_status.dattim * 60;
|
|
|
+ device_status.num_updata = device_status.dattim * 60;
|
|
|
if(device_status.dattim==0) device_status.dattim=20; //数据上传时间间隔设置为0?
|
|
|
+ if(device_status.bat_status==0) device_status.power_status = 1; //解除欠压,清除标志位
|
|
|
}
|
|
|
rt_thread_mdelay(1000);
|
|
|
}
|
|
|
@@ -534,6 +529,7 @@ void parseDtu(char *json_string)
|
|
|
cJSON* iccid = NULL;
|
|
|
cJSON* imei = NULL;
|
|
|
cJSON* sim = NULL;
|
|
|
+ cJSON* volume = NULL;
|
|
|
cJSON* driver_4g = NULL; //版本号
|
|
|
cJSON* project = NULL; //Project
|
|
|
cJSON* ds = NULL; //设备状态
|
|
|
@@ -638,6 +634,7 @@ void parseDtu(char *json_string)
|
|
|
iccid = cJSON_GetObjectItem(item_ext,"iccid");
|
|
|
imei = cJSON_GetObjectItem(item_ext,"imei");
|
|
|
gps = cJSON_GetObjectItem(item_ext,"gps");
|
|
|
+ volume = cJSON_GetObjectItem(item_ext,"volume");
|
|
|
mqttcfg1 = cJSON_GetObjectItem(item_ext,"mqttcfg1");
|
|
|
mqttcfg2 = cJSON_GetObjectItem(item_ext,"mqttcfg2");
|
|
|
//如果DTU的IMEI和FLash中的不一样,保存到FLASH
|
|
|
@@ -703,6 +700,15 @@ void parseDtu(char *json_string)
|
|
|
else {
|
|
|
rt_sprintf(device_status.csq,"0");
|
|
|
}
|
|
|
+ //Volume
|
|
|
+ if(volume!=NULL&&atoi(volume->valuestring)>=0&&atoi(volume->valuestring)<=31)
|
|
|
+ {
|
|
|
+ device_status.vol = atoi(volume->valuestring);
|
|
|
+ rt_kprintf("设置音量:%d\n",device_status.vol);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ device_status.vol = 7;
|
|
|
+ }
|
|
|
//NET
|
|
|
if (net!=NULL&&atoi(net->valuestring)>=0&&atoi(net->valuestring)<=1)
|
|
|
{
|
|
|
@@ -743,11 +749,11 @@ void parseDtu(char *json_string)
|
|
|
sprintf(device_status.project,"%s",project->valuestring);
|
|
|
sprintf(device_status.mqttcfg1,"%s",mqttcfg1->valuestring);
|
|
|
sprintf(device_status.mqttcfg2,"%s",mqttcfg2->valuestring);
|
|
|
- if(num_updata==0)
|
|
|
+ if( device_status.num_updata==0)
|
|
|
{
|
|
|
Beep_Tip(100);
|
|
|
}
|
|
|
- else if(num_updata!=0&&device_status.hmi_fresh==2)
|
|
|
+ else if(device_status.num_updata!=0&&device_status.hmi_fresh==2)
|
|
|
{
|
|
|
if(strstr(device_status.project,"A7_DTU_V3")!=RT_NULL)
|
|
|
{
|