PumpBusiness.c 4.1 KB

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