PumpBusiness.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. #include "stm32f10x.h"
  2. #include <stdio.h>
  3. #include <stdarg.h>
  4. #include <string.h>
  5. #include <stdlib.h>
  6. #include "PumpBusiness.h"
  7. #include "Usart1.h"
  8. #include "AT.h"
  9. #include "INflash.h"
  10. #include "LowPower.h"
  11. #include "UDP_Client5.h"
  12. // 计时相关的变量
  13. uint8_t Business_time_flag = 0;
  14. uint32_t Business_timer_ms = 0;
  15. uint32_t Business_wait_time = 1200; // 秒
  16. uint8_t resend_counter = 0;//nb失败重发标志
  17. uint8_t send_data_switch = 1; // 发送数据的开关,0表示发送数据
  18. uint8_t networkTest_Flag=0;//开机判断是否有信号,0是未知默认状态,1是失败状态,2是成功状态。
  19. struct Pump_Params pump_params; // 泵参数
  20. uint8_t test_switch=0; //0代表正常流程,1代表测试流程
  21. static uint16_t Data_Number = 0; // 数据编号
  22. static uint16_t Data_success_Number = 0; // 成功包
  23. static uint16_t Data_fail_Number = 0; // 失败包
  24. extern Coefficient_Data flashdata;
  25. int RSRP1=0;
  26. int RSRQ2=0;
  27. int RSSI3=0;
  28. int SINR4=0;
  29. // 泵参数初始化
  30. void Pump_Params_Init(void)
  31. {
  32. pump_params.userId = 0;
  33. pump_params.pumpType = 0;
  34. pump_params.infusionId = 0;
  35. pump_params.appendDose=0;
  36. //报警初始化
  37. pump_params.alarm_BubbleOrAneroid = 0;
  38. pump_params.alarm_Blocked = 0;
  39. pump_params.alarm_Total = 0;
  40. pump_params.alarm_Ultimate = 0;
  41. pump_params.alarm_LowPower = 0;
  42. pump_params.alarm_Finished = 0;
  43. pump_params.alarm_MotorOutofcontrol = 0;
  44. pump_params.alarm_MechanicalBreakdown = 0;
  45. pump_params.alarm_UnfilledPillBox = 0;
  46. //预报初始化
  47. pump_params.forcast_WillFinished = 0;
  48. pump_params.forcast_InsufficientAnalgesia = 0;
  49. pump_params.forcast_LowPowerForecast = 0;
  50. }
  51. // 刷新泵数据
  52. void Pump_Params_Refresh(void)
  53. {
  54. pump_params.userId = 1000;
  55. pump_params.pumpType = 1;
  56. pump_params.infusionId = 234;
  57. pump_params.dataNumber = Data_Number;
  58. pump_params.electricity=99;
  59. pump_params.validTimes=10;
  60. pump_params.appendDose=3;
  61. pump_params.invalidTimes=4;
  62. pump_params.patientCode = 2000;
  63. pump_params.totalDose=11;
  64. pump_params.ward=2; // 编号124,病区。
  65. pump_params.bedNo=3; // 编号125,床号。
  66. pump_params.alarm_LowPower = 1;
  67. pump_params.alarm_Total = 1;
  68. pump_params.finishDose =20;
  69. pump_params.alarm_UnfilledPillBox = 1;
  70. pump_params.forcast_WillFinished =1;
  71. pump_params.forcast_InsufficientAnalgesia = 0;
  72. pump_params.forcast_LowPowerForecast = 0;
  73. }
  74. // 业务处理
  75. void PumpBusines_Handle(void)
  76. {
  77. // 定时发送数据
  78. if(Business_time_flag == 0)
  79. {
  80. Business_timer_ms = 0; // 初始化计时变量
  81. Business_time_flag = 1;
  82. }
  83. else if(Business_timer_ms > 1000 * Business_wait_time) // // 定时时间,20分钟
  84. {
  85. // 20分钟计时完成,处理业务
  86. send_data_switch = 1; // 发送数据标志
  87. }
  88. // 发送数据的逻辑
  89. if(send_data_switch == 1 && set_mincfun_flag ==1)
  90. {
  91. if(UDP_Client5_Status() == Client_Status_None)
  92. {
  93. if(test_switch==1&&Data_Number>=100)
  94. {
  95. send_data_switch=0;
  96. return ;
  97. }
  98. Data_Number++; // 数据编号加1
  99. Business_time_flag = 0; // 继续定时
  100. // 初始化参数
  101. Pump_Params_Init();
  102. // 发送参数
  103. UDP_Client5_Send(pump_params,test_switch);
  104. }
  105. else if(UDP_Client5_Status() == Client_Status_Success) // 成功
  106. {
  107. Log_Printf("发送成功:%s\r\n", UDP_Client5.info);
  108. UDP_Client5_Clear(); // 清除
  109. send_data_switch = 0; // 关闭发送
  110. Data_success_Number++;
  111. resend_counter =0;
  112. if(test_switch==1){
  113. Query_Signal(&RSRP1,&RSRQ2,&RSSI3,&SINR4);
  114. Log_Printf("\r\nRSRP1:%d,RSRQ2:%d,RSSI3:%d,SINR4:%d\r\n", RSRP1,RSRQ2,RSSI3,SINR4);
  115. }
  116. }
  117. else if(UDP_Client5_Status() == Client_Status_Failure) // 失败
  118. {
  119. Log_Printf("发送失败:%s\r\n", UDP_Client5.info);
  120. UDP_Client5_Clear(); // 清除
  121. #if NBFLAG
  122. resend_counter++;
  123. if(resend_counter<=3)
  124. {
  125. send_data_switch = 1; // 失败重发
  126. Data_success_Number--;
  127. Data_Number--;
  128. }
  129. else
  130. {
  131. send_data_switch = 0; // 关闭发送
  132. // resend_counter=4;
  133. }
  134. #endif
  135. #if _4GFLAG
  136. send_data_switch = 0; // 关闭发送
  137. #endif
  138. Data_fail_Number++;
  139. }
  140. }
  141. }
  142. // 循环执行
  143. void pump_business_loop_execution()
  144. {
  145. Power_Handle();
  146. #if _4GFLAG
  147. if(module_switch==1) return;
  148. #endif
  149. if(networkTest_Flag==2)
  150. {
  151. //信号显示开
  152. }
  153. else if(networkTest_Flag ==1)
  154. {
  155. //信号显示关
  156. }
  157. if(flashdata.read_flag==0)return;//注册失败或flash存储失败
  158. //if(network_switch==1)return;//关闭网络状态
  159. // 业务处理
  160. PumpBusines_Handle();
  161. //// // 客户端
  162. UDP_Client5_Handle();
  163. // // 处理AT指令
  164. AT_Handle();
  165. //
  166. }