Quellcode durchsuchen

增加开机网络测试

YunZhiNeng vor 1 Jahr
Ursprung
Commit
5325635a69
5 geänderte Dateien mit 108 neuen und 16 gelöschten Zeilen
  1. 2 2
      Drivers/AT.h
  2. 15 4
      Drivers/Business/PumpBusiness.c
  3. 2 1
      Drivers/Business/PumpBusiness.h
  4. 8 6
      Drivers/EC800M_UDP_Client5.c
  5. 81 3
      Drivers/LowPower.c

+ 2 - 2
Drivers/AT.h

@@ -1,8 +1,8 @@
 #ifndef __AT_H
 #define __AT_H
 #include <stdint.h>
-#define NBFLAG 200
-//#define _4GFLAG 100 //4G开关,不能数字开头
+//#define NBFLAG 200
+#define _4GFLAG 100 //4G开关,不能数字开头
 
 // AT指令状态
 enum AT_Status

+ 15 - 4
Drivers/Business/PumpBusiness.c

@@ -22,6 +22,7 @@ uint32_t Business_timer_ms = 0;
 uint32_t Business_wait_time = 1200; // 秒
 uint8_t resend_counter = 0;//nb失败重发标志
 uint8_t send_data_switch = 1; // 发送数据的开关,0表示发送数据
+uint8_t networkTest_Flag=0;//开机判断是否有信号,1有信号,0无信号。
 static struct Pump_Params pump_params; // 泵参数
 uint8_t test_switch=1; //0代表正常流程,1代表测试流程
 static uint16_t Data_Number = 0; // 数据编号
@@ -128,7 +129,17 @@ void PumpBusines_Handle(void)
 			// 初始化参数
 			Pump_Params_Init();
 			// 更新参数
-			Pump_Params_Refresh();
+//			Pump_Params_Refresh();
+			
+			if(test_switch==1&&Data_Number>=200)
+			{
+			   send_data_switch=0;
+				
+//				Data_Number =0;
+//				Data_success_Number=0;
+//				Data_fail_Number=0;
+				return ;
+			}
 			// 发送参数
 			UDP_Client5_Send(pump_params,test_switch);
 			
@@ -152,14 +163,14 @@ void PumpBusines_Handle(void)
 			UDP_Client5_Clear(); // 清除
 			#if  NBFLAG
 			resend_counter++;
-			if(resend_counter<=4)
+			if(resend_counter<=3)
 			{
 			send_data_switch = 1; // 失败重发
 			}
 			else
 			{
 			send_data_switch = 0; // 关闭发送
-			resend_counter=5;
+			resend_counter=4;
 			}
 			#endif
 			#if  _4GFLAG
@@ -183,7 +194,7 @@ void pump_business_loop_execution()
 	//if(network_switch==1)return;//关闭网络状态
 	// 业务处理
 	PumpBusines_Handle();
-	// 客户端
+//	// 客户端
 	UDP_Client5_Handle();
 	// 处理AT指令
 	AT_Handle();

+ 2 - 1
Drivers/Business/PumpBusiness.h

@@ -5,5 +5,6 @@
 
 // Ñ­»·Ö´ÐÐ
 void pump_business_loop_execution(void);
-
+ void Pump_Params_Refresh(void);
+ extern uint8_t networkTest_Flag;
 #endif

+ 8 - 6
Drivers/EC800M_UDP_Client5.c

@@ -15,6 +15,7 @@
 #include "ec800m.h"
 #include "pump_dicts.h"
 #include "INflash.h"
+#include "PumpBusiness.h"
 
 #if  _4GFLAG
 
@@ -482,11 +483,7 @@ void UDP_Client5_Handle(void)
 			{
 				if(cgreg_stat == 1)
 				{
-					// 参数赋值
-					pump_params.lac = cgreg_lac;
-					pump_params.ci = cgreg_ci;
-					// 编码
-					business_protocol_encode(pump_params, data, &data_length);
+					
 					// 下一步
 					if(test_flag == 0)
 					{
@@ -497,7 +494,7 @@ void UDP_Client5_Handle(void)
 						goto_step(STEP_QUERY_QENG_SERVINGCELL);
 					}
 				}
-				else if(query_cgreg_times > 10) // 最多查询20次
+				else if(query_cgreg_times > 20) // 最多查询20次
 				{
 					goto_failure("查询ps域次数过多");
 				}
@@ -576,6 +573,11 @@ void UDP_Client5_Handle(void)
 			}
 			break;
 		case STEP_JOIN_DATA_MESSAGE: // 拼接数据报文
+			pump_params.lac = cgreg_lac;
+			pump_params.ci = cgreg_ci;
+			Pump_Params_Refresh();
+					// 编码
+			business_protocol_encode(pump_params, data, &data_length);
 			join_data_message(data, data_length, coap_message, &coap_message_length);
 			goto_step(STEP_SET_QISDE_0);
 			break;

+ 81 - 3
Drivers/LowPower.c

@@ -18,7 +18,11 @@ enum PowerStep{
 	STEP_ENTER_SLEEP, // 进入睡眠
 	STEP_SET_SLEEP ,// 设置休眠模式
 	STEP_SET_CFUN_0, // 设置最小功能模式
+	STEP_SET_CFUN_1, // 设置全功能模式
+	STEP_WAIT_SET_CFUN_1, // 等待设置全功能模式结果
 	STEP_WAIT, // 等待
+	STEP_SET_CGREG_2, // 设置ps域允许上报网络注册和位置信息
+	STEP_QUERY_CGREG, // 查询网络注册状态
 	STEP_SUCCESS, // 成功
 	STEP_FAILURE, // 失败
 };
@@ -38,7 +42,12 @@ uint8_t Power_time_flag = 0;
 uint32_t Power_timer_ms = 0;
 uint32_t Power_wait_time = 10;
 
-uint8_t set_mincfun_flag=1;
+uint8_t set_mincfun_flag=0;
+static uint8_t cgreg_n; 
+static uint8_t cgreg_stat; 
+static uint16_t cgreg_lac; 
+static uint32_t cgreg_ci;
+static uint8_t query_cgreg_times = 0; // 查询网络状态的次数
 //// 声明函数。步骤跳转
 void pownext_step(enum PowerStep ns);
 // 发送流程
@@ -58,7 +67,25 @@ static void powerwait(void)
 		Power_time_flag = 0;
 	}
 }
+// 失败
+static void power_failure(char * info)
+{
+	Log_Printf_Debug("STEP: 数据发送失败,%s\r\n", info);
+//	UDP_Client5.status = Client_Status_Failure;
+//	strcpy(UDP_Client5.info, info);
+	networkTest_Flag=0;
+	pownext_step(STEP_SET_CFUN_0);
+}
 
+// 成功
+static void power_success(char * info)
+{
+	Log_Printf_Debug("STEP: 数据发送成功,%s\r\n", info);
+//	UDP_Client5.status = Client_Status_Success;
+//	strcpy(UDP_Client5.info, info);
+	networkTest_Flag=1;
+	pownext_step(STEP_SUCCESS);
+}
 
  //直接跳转到下一步
 static void pownext_step(enum PowerStep ns)
@@ -107,7 +134,7 @@ void Power_Handle(void)
 			if(result == Result_Success)
 			{
 				Log_Printf_Debug("设置休眠模式成功\r\n");
-					pownext_step(STEP_SET_CFUN_0);
+					pownext_wait_step(STEP_SET_CFUN_1,3);
 			}
 			else if(result == Result_Failed)
 			{
@@ -115,6 +142,55 @@ void Power_Handle(void)
 				pownext_step(STEP_FAILURE);
 			}
 			break;
+		case STEP_SET_CFUN_1:
+					result = ec800m.set_cfun(1);
+			if(result == Result_Success)
+			{
+				pownext_step(STEP_SET_CGREG_2);
+			}
+			else if(result == Result_Failed)
+			{
+				power_failure("设置全功能模式失败");
+			}
+			break;
+		case STEP_SET_CGREG_2: // 设置ps域
+			result = ec800m.set_cgreg(2);
+			if(result == Result_Success)
+			{
+				pownext_step(STEP_QUERY_CGREG);
+			}
+			else if(result == Result_Failed)
+			{
+				power_failure("设置ps域失败");
+			}
+			break;
+		case STEP_QUERY_CGREG: // 查询ps域
+			result = ec800m.query_cgreg(&cgreg_n, &cgreg_stat, &cgreg_lac, &cgreg_ci);
+			if(result == Result_Success)
+			{
+				if(cgreg_stat == 1)
+				{
+					
+					// 下一步
+			
+						pownext_step(STEP_SET_CFUN_0);
+					
+				}
+				else if(query_cgreg_times > 20) // 最多查询20次
+				{
+					power_failure("查询ps域次数过多");
+				}
+				else
+				{
+					pownext_wait_step(STEP_QUERY_CGREG,400);
+					query_cgreg_times++;
+				}
+			}
+			else if(result == Result_Failed)
+			{
+				power_failure("查询ps域失败");
+			}
+			break;
 		case STEP_SET_CFUN_0: // 设置最小功能模式
 			result = ec800m.set_cfun(0);
 			if(result == Result_Success)
@@ -127,6 +203,8 @@ void Power_Handle(void)
 			{
 				Log_Printf_Debug("设置最小功能模式失败\r\n");
 				pownext_step(STEP_FAILURE);
+//				power_failure("设置最小功能模式失败");
+//				pownext_wait_step(STEP_START, 5);
 			}
 			break;
 		case STEP_WAIT: // 等待
@@ -139,7 +217,7 @@ void Power_Handle(void)
 			break;
 		case STEP_FAILURE: // 失败
 			ec800m.enter_sleep();
-			pownext_wait_step(STEP_START, 5);
+			pownext_wait_step(STEP_SET_CFUN_0, 5);
 			break;
 		default:
 			break;