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