PumpBusiness.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. #include "Regist.h"
  17. // 计时相关的变量
  18. static struct TIMER_Struct timer;
  19. uint8_t send_data_switch = 1; // 发送数据的开关,0表示发送数据
  20. uint8_t networkTest_Flag=0;//开机判断是否有信号,0是未知默认状态,1是失败状态,2是成功状态。
  21. uint8_t module_switch = 0;//4G模块开关 0正常,1是关闭标志
  22. static uint8_t test_switch=0; //0代表正常流程,1代表测试流程
  23. struct Pump_Params pump_params; // 泵参数
  24. static uint16_t Data_Number = 0; // 数据编号
  25. static uint16_t Data_success_Number = 0; // 成功包
  26. static uint16_t Data_fail_Number = 0; // 失败包
  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. #if BC260Y
  53. pump_params.networkType=2;
  54. #endif
  55. #if EC800M
  56. pump_params.networkType=1;
  57. #endif
  58. }
  59. // 刷新泵数据
  60. void Pump_Params_Refresh(void)
  61. {
  62. // 初始化参数
  63. Pump_Params_Init();
  64. pump_params.userId = 1000;
  65. pump_params.pumpType = 1;
  66. pump_params.infusionId = 234;
  67. pump_params.dataNumber = Data_Number;
  68. pump_params.electricity=99;
  69. pump_params.validTimes=10;
  70. pump_params.appendDose=3;
  71. pump_params.invalidTimes=4;
  72. pump_params.patientCode = 2000;
  73. pump_params.totalDose=11;
  74. pump_params.ward=2; // 编号124,病区。
  75. pump_params.bedNo=3; // 编号125,床号。
  76. pump_params.alarm_LowPower = 1;
  77. pump_params.alarm_Total = 1;
  78. pump_params.finishDose =20;
  79. pump_params.alarm_UnfilledPillBox = 1;
  80. pump_params.forcast_WillFinished =1;
  81. pump_params.forcast_InsufficientAnalgesia = 0;
  82. pump_params.forcast_LowPowerForecast = 0;
  83. }
  84. static uint32_t Business_wait_time = 1200; // 秒
  85. // 业务处理
  86. void PumpBusines_Handle(void)
  87. {
  88. // 没注册,直接返回
  89. if(regist_get_result() != Regist_Result_Success)
  90. {
  91. return;
  92. }
  93. // 定时发送数据
  94. // if(time_get_delay(&timer) > 1000 * Business_wait_time) // // 定时时间,20分钟
  95. // {
  96. // // 20分钟计时完成,处理业务
  97. // send_data_switch = 1; // 发送数据标志
  98. // time_clear(&timer); // 重新定时
  99. // Log_Printf_Debug("PumpBusines_Handle\r\n");
  100. // }
  101. // 发送标志位不为1直接返回
  102. if(send_data_switch != 1)
  103. {
  104. return;
  105. }
  106. // 发送
  107. if(UDP_Client_Status() == Client_Status_None)
  108. {
  109. if(test_switch==1 && Data_Number>=100)//测试模式只发100条数据
  110. {
  111. send_data_switch=0;
  112. return ;
  113. }
  114. // 数据编号加1
  115. Data_Number++;
  116. // 发送参数
  117. UDP_Client_Send(test_switch);
  118. }
  119. else if(UDP_Client_Status() == Client_Status_Sending) // 正在发送
  120. {
  121. // 客户端
  122. UDP_Client_Handle();
  123. }
  124. else if(UDP_Client_Status() == Client_Status_Success) // 成功
  125. {
  126. Log_Printf("发送成功:%s\r\n", UDP_Client_Get_Info());
  127. UDP_Client_Clear(); // 清除
  128. send_data_switch = 0; // 关闭发送
  129. Data_success_Number++;
  130. if(test_switch==1){
  131. Query_Signal(&RSRP1,&RSRQ2,&RSSI3,&SINR4);
  132. Log_Printf("\r\nRSRP1:%d,RSRQ2:%d,RSSI3:%d,SINR4:%d\r\n", RSRP1,RSRQ2,RSSI3,SINR4);
  133. }
  134. }
  135. else if(UDP_Client_Status() == Client_Status_Failure) // 失败
  136. {
  137. Log_Printf("发送失败:%s\r\n", UDP_Client_Get_Info());
  138. UDP_Client_Clear(); // 清除
  139. send_data_switch = 0; // 关闭发送
  140. Data_fail_Number++;
  141. }
  142. else
  143. {
  144. // 未知的状态
  145. }
  146. }
  147. // 循环执行
  148. void pump_business_loop_execution()
  149. {
  150. // 初始化
  151. Initialize_Handle();
  152. // 业务处理
  153. PumpBusines_Handle();
  154. // 未及时处理的AT指令
  155. AT_Handle();
  156. }