|
|
@@ -25,9 +25,9 @@
|
|
|
|
|
|
#include "UDP_Client.h"
|
|
|
#include "CoAP_Util.h"
|
|
|
-
|
|
|
+#include "Timer_Module.h"
|
|
|
#include "mbedtls_util.h"
|
|
|
-
|
|
|
+#include "Regist.h"
|
|
|
#include "cJSON.h"
|
|
|
#include "bc260y.h"
|
|
|
#include "Pump_Dicts_Util.h"
|
|
|
@@ -35,7 +35,7 @@
|
|
|
#include "PumpBusiness.h"
|
|
|
#include "aliyuniot.h"
|
|
|
#include "Log_Module.h"
|
|
|
-
|
|
|
+#include "Initialize.h"
|
|
|
|
|
|
// 流程
|
|
|
enum Step{
|
|
|
@@ -78,14 +78,12 @@ enum Step{
|
|
|
static enum Step step = STEP_NONE;
|
|
|
// 下一步
|
|
|
static enum Step next_step = STEP_NONE;
|
|
|
-
|
|
|
+static uint8_t resend_counter = 0;//nb失败重发标志
|
|
|
// 客户端5
|
|
|
-struct COMM_Client_Struct UDP_Client5 = {
|
|
|
+struct COMM_Client_Struct udp_client = {
|
|
|
.status = Client_Status_None,
|
|
|
};
|
|
|
|
|
|
-// 注册后的参数
|
|
|
-extern Coefficient_Data flashdata;
|
|
|
|
|
|
// socket ID
|
|
|
static uint8_t connectID = 1;
|
|
|
@@ -104,11 +102,10 @@ static uint16_t data_length;
|
|
|
|
|
|
static uint8_t test_flag=0;
|
|
|
|
|
|
-extern struct AT_Struct AT;
|
|
|
+
|
|
|
// 计时相关的变量
|
|
|
-uint8_t Client5_time_flag = 0;
|
|
|
-uint32_t Client5_timer_ms = 0;
|
|
|
-uint32_t Client5_wait_time = 10;
|
|
|
+static struct TIMER_Struct timer;
|
|
|
+uint32_t wait_time = 10;
|
|
|
// 信号值
|
|
|
static struct Signal
|
|
|
{
|
|
|
@@ -132,54 +129,61 @@ void Query_Signal(int * RSRP, int * RSRQ, int * RSSI, int * SINR)
|
|
|
}
|
|
|
|
|
|
// 初始化
|
|
|
-void UDP_Client5_Init(void)
|
|
|
+void UDP_Client_Init(void)
|
|
|
{
|
|
|
-
|
|
|
- aliyuniot_set_device_params(flashdata.productKey,flashdata.deviceName,flashdata.deviceSecret);
|
|
|
+ aliyuniot_set_device_params(regist_get_aliyun_productKey(),regist_get_aliyun_deviceName(),regist_get_aliyun_deviceSecret());
|
|
|
+// aliyuniot_set_device_params(flashdata.productKey,flashdata.deviceName,flashdata.deviceSecret);
|
|
|
// 设置host
|
|
|
-
|
|
|
+ resend_counter=0;//失败重发置0
|
|
|
}
|
|
|
// 声明函数。步骤跳转
|
|
|
void goto_step(enum Step ns);
|
|
|
// 发送流程
|
|
|
-void UDP_Client5_Handle(void);
|
|
|
+void UDP_Client_Handle(void);
|
|
|
// 发送数据
|
|
|
-void UDP_Client5_Send(uint8_t test_switch)
|
|
|
+void UDP_Client_Send(uint8_t test_switch)
|
|
|
{
|
|
|
test_flag=test_switch;
|
|
|
if(step == STEP_NONE)
|
|
|
{
|
|
|
// 初始化
|
|
|
- UDP_Client5_Init();
|
|
|
+ UDP_Client_Init();
|
|
|
// 正在发送
|
|
|
- UDP_Client5.status = Client_Status_Sending;
|
|
|
+ udp_client.status = Client_Status_Sending;
|
|
|
// 流程开始
|
|
|
goto_step(STEP_START);
|
|
|
}
|
|
|
}
|
|
|
// 获取状态
|
|
|
-enum Client_Status UDP_Client5_Status(void)
|
|
|
+enum Client_Status UDP_Client_Status(void)
|
|
|
{
|
|
|
- if(UDP_Client5.status == Client_Status_None)
|
|
|
+ if(udp_client.status == Client_Status_None)
|
|
|
{
|
|
|
- return UDP_Client5.status;
|
|
|
+ return udp_client.status;
|
|
|
}
|
|
|
else if(step == STEP_FINISH)
|
|
|
{
|
|
|
- return UDP_Client5.status;
|
|
|
+ return udp_client.status;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return Client_Status_Sending;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+// 获取备注
|
|
|
+char * UDP_Client_Get_Info(void)
|
|
|
+{
|
|
|
+ return udp_client.info;
|
|
|
+}
|
|
|
+
|
|
|
// 清除
|
|
|
-void UDP_Client5_Clear(void)
|
|
|
+void UDP_Client_Clear(void)
|
|
|
{
|
|
|
// 流程置空
|
|
|
goto_step(STEP_NONE);
|
|
|
// 空闲
|
|
|
- UDP_Client5.status = Client_Status_None;
|
|
|
+ udp_client.status = Client_Status_None;
|
|
|
}
|
|
|
|
|
|
// 直接跳转到下一步
|
|
|
@@ -194,7 +198,7 @@ static void goto_step(enum Step ns)
|
|
|
static void goto_step_wait(enum Step ns, uint32_t t)
|
|
|
{
|
|
|
goto_step(STEP_WAIT); // 等待
|
|
|
- Client5_wait_time = t;
|
|
|
+ wait_time = t;
|
|
|
next_step = ns; // 等待之后跳转
|
|
|
}
|
|
|
|
|
|
@@ -208,32 +212,27 @@ static void goto_wait(uint32_t t)
|
|
|
static void goto_failure(char * info)
|
|
|
{
|
|
|
Log_Printf_Debug("STEP: 数据发送失败,%s\r\n", info);
|
|
|
- UDP_Client5.status = Client_Status_Failure;
|
|
|
- strcpy(UDP_Client5.info, info);
|
|
|
+ udp_client.status = Client_Status_Failure;
|
|
|
+ strcpy(udp_client.info, info);
|
|
|
goto_step(STEP_FAILURE);
|
|
|
}
|
|
|
|
|
|
// 成功
|
|
|
static void goto_success(char * info)
|
|
|
{
|
|
|
- Log_Printf_Debug("STEP: 数据发送成功,%s\r\n", info);
|
|
|
- UDP_Client5.status = Client_Status_Success;
|
|
|
- strcpy(UDP_Client5.info, info);
|
|
|
+ Log_Printf_Debug("STEP: 数据发送成功,%s\r\n", info);
|
|
|
+ udp_client.status = Client_Status_Success;
|
|
|
+ strcpy(udp_client.info, info);
|
|
|
goto_step(STEP_SUCCESS);
|
|
|
}
|
|
|
|
|
|
// 等待
|
|
|
static void wait(void)
|
|
|
{
|
|
|
- if(Client5_time_flag == 0)
|
|
|
- {
|
|
|
- Client5_timer_ms = 0;
|
|
|
- Client5_time_flag = 1;
|
|
|
- }
|
|
|
- else if(Client5_timer_ms > Client5_wait_time)
|
|
|
+ if(time_get_delay(&timer) > wait_time)
|
|
|
{
|
|
|
goto_step(next_step); // 进入下一步
|
|
|
- Client5_time_flag = 0;
|
|
|
+ time_clear(&timer);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -247,8 +246,15 @@ static uint8_t query_cgreg_times = 0; //
|
|
|
static uint8_t auth_times = 0; // 认证次数
|
|
|
static uint16_t socket_err = 0;
|
|
|
static uint8_t auth_or_data = 0;
|
|
|
-void UDP_Client5_Handle(void)
|
|
|
+void UDP_Client_Handle(void)
|
|
|
{
|
|
|
+ static enum Initialize_Result InitializeResult;
|
|
|
+ InitializeResult=get_initialize_status();
|
|
|
+ if(InitializeResult==Initialize_Result_Busy)
|
|
|
+ {
|
|
|
+ return ;
|
|
|
+
|
|
|
+ }
|
|
|
// 流程
|
|
|
switch(step)
|
|
|
{
|
|
|
@@ -463,7 +469,15 @@ void UDP_Client5_Handle(void)
|
|
|
goto_step(STEP_SET_SLEEP);
|
|
|
break;
|
|
|
case STEP_FAILURE: // 失败
|
|
|
+ if(resend_counter>=2){
|
|
|
goto_step(STEP_SET_SLEEP);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //重发2次
|
|
|
+ resend_counter++;
|
|
|
+ goto_step(STEP_SET_CFUN_1);
|
|
|
+ }
|
|
|
break;
|
|
|
case STEP_SET_SLEEP: // 设置休眠模式
|
|
|
result = bc260y.set_sleep(1);
|