| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- #include "stm32f10x.h"
- #include <stdio.h>
- #include <stdarg.h>
- #include <string.h>
- #include <stdlib.h>
- #include "PumpBusiness.h"
- #include "Usart1.h"
- #include "CONFIG.h"
- #include "INflash.h"
- #include "Initialize.h"
- #include "UDP_Client.h"
- #include "Timer_Module.h"
- #include "Log_Module.h"
- #include "At_Module.h"
- #include "Pump_Dicts_Util.h"
- #include "Regist.h"
- // 计时相关的变量
- static struct TIMER_Struct timer;
- uint8_t send_data_switch = 1; // 发送数据的开关,0表示发送数据
- uint8_t networkTest_Flag=0;//开机判断是否有信号,0是未知默认状态,1是失败状态,2是成功状态。
- uint8_t module_switch = 0;//4G模块开关 0正常,1是关闭标志
- static uint8_t test_switch=0; //0代表正常流程,1代表测试流程
- struct Pump_Params pump_params; // 泵参数
- static uint16_t Data_Number = 0; // 数据编号
- static uint16_t Data_success_Number = 0; // 成功包
- static uint16_t Data_fail_Number = 0; // 失败包
- int RSRP1=0;
- int RSRQ2=0;
- int RSSI3=0;
- int SINR4=0;
- // 泵参数初始化
- void Pump_Params_Init(void)
- {
- pump_params.userId = 0;
- pump_params.pumpType = 0;
- pump_params.infusionId = 0;
- pump_params.appendDose=0;
-
- //报警初始化
- pump_params.alarm_BubbleOrAneroid = 0;
- pump_params.alarm_Blocked = 0;
- pump_params.alarm_Total = 0;
- pump_params.alarm_Ultimate = 0;
- pump_params.alarm_LowPower = 0;
- pump_params.alarm_Finished = 0;
- pump_params.alarm_MotorOutofcontrol = 0;
- pump_params.alarm_MechanicalBreakdown = 0;
- pump_params.alarm_UnfilledPillBox = 0;
-
- //预报初始化
- pump_params.forcast_WillFinished = 0;
- pump_params.forcast_InsufficientAnalgesia = 0;
- pump_params.forcast_LowPowerForecast = 0;
-
- #if BC260Y
- pump_params.networkType=2;
- #endif
-
- #if EC800M
- pump_params.networkType=1;
- #endif
- }
- // 刷新泵数据
- void Pump_Params_Refresh(void)
- {
- // 初始化参数
- Pump_Params_Init();
-
- pump_params.userId = 1000;
- pump_params.pumpType = 1;
- pump_params.infusionId = 234;
-
- pump_params.dataNumber = Data_Number;
- pump_params.electricity=99;
- pump_params.validTimes=10;
- pump_params.appendDose=3;
- pump_params.invalidTimes=4;
- pump_params.patientCode = 2000;
- pump_params.totalDose=11;
- pump_params.ward=2; // 编号124,病区。
- pump_params.bedNo=3; // 编号125,床号。
- pump_params.alarm_LowPower = 1;
- pump_params.alarm_Total = 1;
- pump_params.finishDose =20;
- pump_params.alarm_UnfilledPillBox = 1;
- pump_params.forcast_WillFinished =1;
- pump_params.forcast_InsufficientAnalgesia = 0;
- pump_params.forcast_LowPowerForecast = 0;
- }
- static uint32_t Business_wait_time = 1200; // 秒
- // 业务处理
- void PumpBusines_Handle(void)
- {
- // 没注册,直接返回
- if(regist_get_result() != Regist_Result_Success)
- {
- return;
- }
-
- // 定时发送数据
- // if(time_get_delay(&timer) > 1000 * Business_wait_time) // // 定时时间,20分钟
- // {
- // // 20分钟计时完成,处理业务
- // send_data_switch = 1; // 发送数据标志
- // time_clear(&timer); // 重新定时
- // Log_Printf_Debug("PumpBusines_Handle\r\n");
- // }
-
- // 发送标志位不为1直接返回
- if(send_data_switch != 1)
- {
- return;
- }
- // 发送
- if(UDP_Client_Status() == Client_Status_None)
- {
- if(test_switch==1 && Data_Number>=100)//测试模式只发100条数据
- {
- send_data_switch=0;
- return ;
- }
- // 数据编号加1
- Data_Number++;
- // 发送参数
- UDP_Client_Send(test_switch);
- }
- else if(UDP_Client_Status() == Client_Status_Sending) // 正在发送
- {
- // 客户端
- UDP_Client_Handle();
- }
- else if(UDP_Client_Status() == Client_Status_Success) // 成功
- {
- Log_Printf("发送成功:%s\r\n", UDP_Client_Get_Info());
- UDP_Client_Clear(); // 清除
-
- send_data_switch = 0; // 关闭发送
- Data_success_Number++;
- if(test_switch==1){
- Query_Signal(&RSRP1,&RSRQ2,&RSSI3,&SINR4);
- Log_Printf("\r\nRSRP1:%d,RSRQ2:%d,RSSI3:%d,SINR4:%d\r\n", RSRP1,RSRQ2,RSSI3,SINR4);
- }
- }
- else if(UDP_Client_Status() == Client_Status_Failure) // 失败
- {
- Log_Printf("发送失败:%s\r\n", UDP_Client_Get_Info());
- UDP_Client_Clear(); // 清除
- send_data_switch = 0; // 关闭发送
- Data_fail_Number++;
- }
- else
- {
- // 未知的状态
-
- }
-
- }
- // 循环执行
- void pump_business_loop_execution()
- {
- // 初始化
- Initialize_Handle();
- // 业务处理
- PumpBusines_Handle();
- // 未及时处理的AT指令
- AT_Handle();
- }
|