handle_bus.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. * handle_bus.c
  3. *
  4. * Created on: 2025年11月26日
  5. * Author: wulianwei
  6. */
  7. #include <stdlib.h>
  8. #include "tr_protocol.h"
  9. #include "nim_config.h"
  10. /**
  11. * 处理采集信号
  12. */
  13. #define COUNT_SIZE 75
  14. #define CHANNEL_COUNT 4 //采集通道总数
  15. /**
  16. * 处理波形数据并上报到GUI
  17. */
  18. void handleSign(unsigned char *s, unsigned short sl)
  19. {
  20. ConsolePuts("handle signal data from usb\n", -1);
  21. struct Frame
  22. {
  23. unsigned char sign;
  24. unsigned char d1[3];
  25. unsigned char d2[3];
  26. unsigned char d3[3];
  27. unsigned char d4[3];
  28. };
  29. short FRAME_LEN = sizeof(struct Frame);
  30. if (sl % FRAME_LEN > 0)
  31. {
  32. ConsolePuts("长度不匹配\n", -1);
  33. return;
  34. }
  35. int dataCount = sl / FRAME_LEN; //每个通道数据量, 每三个字节代表一个采集信号. 大端模式.
  36. float *const fdata = malloc(sizeof(float) * dataCount*CHANNEL_COUNT*2);
  37. memset(fdata,0,sizeof(float) * dataCount*CHANNEL_COUNT*2);
  38. float *const cd1 = fdata+dataCount*0;
  39. float *const cd2 = fdata+dataCount*1;
  40. float *const cd3 = fdata+dataCount*2;
  41. float *const cd4 = fdata+dataCount*3;
  42. float *const fd1 = fdata+dataCount*4;
  43. float *const fd2 = fdata+dataCount*5;
  44. float *const fd3 = fdata+dataCount*6;;
  45. float *const fd4 = fdata+dataCount*7;
  46. float* sd1 = cd1;
  47. float* sd2 = cd2;
  48. float* sd3 = cd3;;
  49. float* sd4 = cd4;
  50. const int FULL = 0x007fffff;
  51. const float FFULL = (float) FULL;
  52. struct Frame *fm = NULL;
  53. int i = 0;
  54. for (i = 0; i < dataCount; i++)
  55. {
  56. fm = (struct Frame*) (s + FRAME_LEN * i);
  57. int origenData1 = fm->d1[0] << 24 | fm->d1[1] << 16 | fm->d1[2] << 8;
  58. *(cd1 + i) = ((float) (origenData1 >> 8) / FFULL) * 5000000+530; //将采集数据转成uV
  59. //ConsolePrintf("%f,\n",*(cd1 + i));
  60. int origenData2 = fm->d2[0] << 24 | fm->d2[1] << 16 | fm->d2[2] << 8;
  61. *(cd2 + i) = ((float) (origenData2 >> 8) / FFULL) * 5000000+470; //将采集数据转成uV
  62. int origenData3 = fm->d3[0] << 24 | fm->d3[1] << 16 | fm->d3[2] << 8;
  63. *(cd3 + i) = ((float) (origenData3 >> 8) / FFULL) * 5000000+450; //将采集数据转成uV
  64. int origenData4 = fm->d4[0] << 24 | fm->d4[1] << 16 | fm->d4[2] << 8;
  65. *(cd4 + i) = ((float) (origenData4 >> 8) / FFULL) * 5000000+440; //将采集数据转成uV
  66. }
  67. if (!(fm->sign & 0x01))
  68. {
  69. emg_denoised(cd1, dataCount, 1000, fd1);
  70. sd1 = fd1;
  71. }
  72. if (!(fm->sign & 0x02))
  73. {
  74. emg_denoised(cd2, dataCount, 1000, fd2);
  75. sd2 = fd2;
  76. }
  77. if (!(fm->sign & 0x04))
  78. {
  79. emg_denoised(cd3, dataCount, 1000, fd3);
  80. sd3 = fd3;
  81. }
  82. if (!(fm->sign & 0x08))
  83. {
  84. emg_denoised(cd4, dataCount, 1000, fd4);
  85. sd4 = fd4;
  86. }
  87. lwip_udp_send_gui_signal2(cd1,cd2,cd3,cd4, fm->sign,dataCount);
  88. // lwip_udp_send_vofa4(cd1, cd2 , cd3 ,cd4 , dataCount);
  89. free(fdata);
  90. }
  91. /**
  92. * 处理gui下发的数据
  93. */
  94. void handleGUI(unsigned char *s, unsigned short sl)
  95. {
  96. ConsolePuts("\n===handle from gui\n", -1);
  97. ConsolePutsHexStr(s, sl);
  98. unsigned char check = 0;
  99. int a = ProtocolGetOption(s,sl,99,&check);
  100. if(check == 1)
  101. {
  102. unsigned char udpAdd[8] = {0};
  103. trProtocol verPro;
  104. ProtocolInit(&verPro);
  105. ProtocolSetDestAddress(&verPro,3);
  106. ProtocolSetSourceAddress(&verPro,1);
  107. ProtocolSetType(&verPro,2);
  108. ProtocolSetOptionChar(&verPro, 100, 1);
  109. ProtocolSetPayload(&verPro,sizeof(udpAdd),udpAdd);
  110. ProtocolPackage(&verPro);
  111. ConsolePuts("\n===dsp to gui version\n", -1);
  112. ConsolePutsHexStr(verPro.message, verPro.length);
  113. lwip_tcp_send_gui(verPro.message,verPro.length);
  114. }
  115. else if(check == 3)
  116. {
  117. touch_closegui();
  118. }
  119. }
  120. /**
  121. * 上报界面盒在线状态
  122. */
  123. void handleUSBLineStatus(unsigned char status)
  124. {
  125. trProtocol verPro;
  126. ProtocolInit(&verPro);
  127. ProtocolSetDestAddress(&verPro,3);
  128. ProtocolSetSourceAddress(&verPro,1);
  129. ProtocolSetType(&verPro,2);
  130. ProtocolSetOptionChar(&verPro, 99, 4);
  131. ProtocolSetOptionChar(&verPro, 123, status);
  132. ProtocolPackage(&verPro);
  133. ConsolePuts("\n===dsp to gui usb line status\n", -1);
  134. ConsolePutsHexStr(verPro.message, verPro.length);
  135. lwip_tcp_send_gui(verPro.message,verPro.length);
  136. }