PumpBusiness.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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 "CONFIG.h"
  9. #include "INflash.h"
  10. #include "Initialize.h"
  11. #include "UDP_Client.h"
  12. #include "Timer_Module.h"
  13. #include "Log_Module.h"
  14. #include "At_Module.h"
  15. #include "Pump_Dicts_Util.h"
  16. // 计时相关的变量
  17. static struct TIMER_Struct timer;
  18. uint8_t resend_counter = 0;//nb失败重发标志
  19. uint8_t send_data_switch = 1; // 发送数据的开关,0表示发送数据
  20. uint8_t networkTest_Flag=0;//开机判断是否有信号,0是未知默认状态,1是失败状态,2是成功状态。
  21. struct Pump_Params pump_params; // 泵参数
  22. uint8_t test_switch=0; //0代表正常流程,1代表测试流程
  23. static uint16_t Data_Number = 0; // 数据编号
  24. static uint16_t Data_success_Number = 0; // 成功包
  25. static uint16_t Data_fail_Number = 0; // 失败包
  26. extern Coefficient_Data flashdata;
  27. int RSRP1=0;
  28. int RSRQ2=0;
  29. int RSSI3=0;
  30. int SINR4=0;
  31. // 泵参数初始化
  32. void Pump_Params_Init(void)
  33. {
  34. pump_params.userId = 0;
  35. pump_params.pumpType = 0;
  36. pump_params.infusionId = 0;
  37. pump_params.appendDose=0;
  38. //报警初始化
  39. pump_params.alarm_BubbleOrAneroid = 0;
  40. pump_params.alarm_Blocked = 0;
  41. pump_params.alarm_Total = 0;
  42. pump_params.alarm_Ultimate = 0;
  43. pump_params.alarm_LowPower = 0;
  44. pump_params.alarm_Finished = 0;
  45. pump_params.alarm_MotorOutofcontrol = 0;
  46. pump_params.alarm_MechanicalBreakdown = 0;
  47. pump_params.alarm_UnfilledPillBox = 0;
  48. //预报初始化
  49. pump_params.forcast_WillFinished = 0;
  50. pump_params.forcast_InsufficientAnalgesia = 0;
  51. pump_params.forcast_LowPowerForecast = 0;
  52. }
  53. // 刷新泵数据
  54. void Pump_Params_Refresh(void)
  55. {
  56. // 初始化参数
  57. Pump_Params_Init();
  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. static uint32_t Business_wait_time = 1200; // 秒
  79. // 业务处理
  80. void PumpBusines_Handle(void)
  81. {
  82. // 定时发送数据
  83. if(time_get_delay(&timer) > 1000 * Business_wait_time) // // 定时时间,20分钟
  84. {
  85. // 20分钟计时完成,处理业务
  86. send_data_switch = 1; // 发送数据标志
  87. time_clear(&timer); // 重新定时
  88. Log_Printf_Debug("PumpBusines_Handle\r\n");
  89. }
  90. // 发送标志位不为1直接返回
  91. if(send_data_switch != 1)
  92. {
  93. return;
  94. }
  95. // //没有初始化成功前不发送数据
  96. // if(get_initialize_status()!=1)
  97. // {
  98. // return;
  99. // }
  100. // 发送
  101. if(UDP_Client_Status() == Client_Status_None)
  102. {
  103. if(test_switch==1&&Data_Number>=100)
  104. {
  105. send_data_switch=0;
  106. return ;
  107. }
  108. // 数据编号加1
  109. Data_Number++;
  110. // 发送参数
  111. UDP_Client_Send(test_switch);
  112. }
  113. else if(UDP_Client_Status() == Client_Status_Sending) // 正在发送
  114. {
  115. // 客户端
  116. UDP_Client_Handle();
  117. }
  118. else if(UDP_Client_Status() == Client_Status_Success) // 成功
  119. {
  120. Log_Printf("发送成功:%s\r\n", UDP_Client_Get_Info());
  121. UDP_Client_Clear(); // 清除
  122. send_data_switch = 0; // 关闭发送
  123. Data_success_Number++;
  124. resend_counter =0;
  125. if(test_switch==1){
  126. Query_Signal(&RSRP1,&RSRQ2,&RSSI3,&SINR4);
  127. Log_Printf("\r\nRSRP1:%d,RSRQ2:%d,RSSI3:%d,SINR4:%d\r\n", RSRP1,RSRQ2,RSSI3,SINR4);
  128. }
  129. }
  130. else if(UDP_Client_Status() == Client_Status_Failure) // 失败
  131. {
  132. Log_Printf("发送失败:%s\r\n", UDP_Client_Get_Info());
  133. UDP_Client_Clear(); // 清除
  134. // #if BC260Y
  135. // resend_counter++;
  136. // if(resend_counter<=3)
  137. // {
  138. // send_data_switch = 1; // 失败重发
  139. // Data_success_Number--;
  140. // Data_Number--;
  141. // }
  142. // else
  143. // {
  144. // send_data_switch = 0; // 关闭发送
  145. //// resend_counter=4;
  146. // }
  147. // #endif
  148. // #if EC800M
  149. send_data_switch = 0; // 关闭发送
  150. // #endif
  151. Data_fail_Number++;
  152. }
  153. else
  154. {
  155. // 未知的状态
  156. }
  157. }
  158. // 循环执行
  159. void pump_business_loop_execution()
  160. {
  161. Power_Handle();
  162. #if EC800M
  163. // if(module_switch==1) return;
  164. #endif
  165. if(networkTest_Flag==2)
  166. {
  167. //信号显示开
  168. }
  169. else if(networkTest_Flag ==1)
  170. {
  171. //信号显示关
  172. }
  173. // if(flashdata.read_flag==0)return;//注册失败或flash存储失败
  174. //if(network_switch==1)return;//关闭网络状态
  175. // 业务处理
  176. PumpBusines_Handle();
  177. // // 处理AT指令
  178. AT_Handle();
  179. //
  180. }