/* * handle_bus.c * * Created on: 2025年11月26日 * Author: wulianwei */ #include #include "tr_protocol.h" #include "nim_config.h" /** * 处理采集信号 */ #define COUNT_SIZE 75 #define CHANNEL_COUNT 4 //采集通道总数 /** * 处理波形数据并上报到GUI */ void handleSign(unsigned char *s, unsigned short sl) { ConsolePuts("handle signal data from usb\n", -1); struct Frame { unsigned char sign; unsigned char d1[3]; unsigned char d2[3]; unsigned char d3[3]; unsigned char d4[3]; }; short FRAME_LEN = sizeof(struct Frame); if (sl % FRAME_LEN > 0) { ConsolePuts("长度不匹配\n", -1); return; } int dataCount = sl / FRAME_LEN; //每个通道数据量, 每三个字节代表一个采集信号. 大端模式. float *const fdata = malloc(sizeof(float) * dataCount*CHANNEL_COUNT*2); memset(fdata,0,sizeof(float) * dataCount*CHANNEL_COUNT*2); float *const cd1 = fdata+dataCount*0; float *const cd2 = fdata+dataCount*1; float *const cd3 = fdata+dataCount*2; float *const cd4 = fdata+dataCount*3; float *const fd1 = fdata+dataCount*4; float *const fd2 = fdata+dataCount*5; float *const fd3 = fdata+dataCount*6;; float *const fd4 = fdata+dataCount*7; float* sd1 = cd1; float* sd2 = cd2; float* sd3 = cd3;; float* sd4 = cd4; const int FULL = 0x007fffff; const float FFULL = (float) FULL; struct Frame *fm = NULL; int i = 0; for (i = 0; i < dataCount; i++) { fm = (struct Frame*) (s + FRAME_LEN * i); int origenData1 = fm->d1[0] << 24 | fm->d1[1] << 16 | fm->d1[2] << 8; *(cd1 + i) = ((float) (origenData1 >> 8) / FFULL) * 5000000+530; //将采集数据转成uV //ConsolePrintf("%f,\n",*(cd1 + i)); int origenData2 = fm->d2[0] << 24 | fm->d2[1] << 16 | fm->d2[2] << 8; *(cd2 + i) = ((float) (origenData2 >> 8) / FFULL) * 5000000+470; //将采集数据转成uV int origenData3 = fm->d3[0] << 24 | fm->d3[1] << 16 | fm->d3[2] << 8; *(cd3 + i) = ((float) (origenData3 >> 8) / FFULL) * 5000000+450; //将采集数据转成uV int origenData4 = fm->d4[0] << 24 | fm->d4[1] << 16 | fm->d4[2] << 8; *(cd4 + i) = ((float) (origenData4 >> 8) / FFULL) * 5000000+440; //将采集数据转成uV } if (!(fm->sign & 0x01)) { emg_denoised(cd1, dataCount, 1000, fd1); sd1 = fd1; } if (!(fm->sign & 0x02)) { emg_denoised(cd2, dataCount, 1000, fd2); sd2 = fd2; } if (!(fm->sign & 0x04)) { emg_denoised(cd3, dataCount, 1000, fd3); sd3 = fd3; } if (!(fm->sign & 0x08)) { emg_denoised(cd4, dataCount, 1000, fd4); sd4 = fd4; } lwip_udp_send_gui_signal2(cd1,cd2,cd3,cd4, fm->sign,dataCount); // lwip_udp_send_vofa4(cd1, cd2 , cd3 ,cd4 , dataCount); free(fdata); } /** * 处理gui下发的数据 */ void handleGUI(unsigned char *s, unsigned short sl) { ConsolePuts("\n===handle from gui\n", -1); ConsolePutsHexStr(s, sl); unsigned char check = 0; int a = ProtocolGetOption(s,sl,99,&check); if(check == 1) { unsigned char udpAdd[8] = {0}; trProtocol verPro; ProtocolInit(&verPro); ProtocolSetDestAddress(&verPro,3); ProtocolSetSourceAddress(&verPro,1); ProtocolSetType(&verPro,2); ProtocolSetOptionChar(&verPro, 100, 1); ProtocolSetPayload(&verPro,sizeof(udpAdd),udpAdd); ProtocolPackage(&verPro); ConsolePuts("\n===dsp to gui version\n", -1); ConsolePutsHexStr(verPro.message, verPro.length); lwip_tcp_send_gui(verPro.message,verPro.length); } else if(check == 3) { touch_closegui(); } } /** * 上报界面盒在线状态 */ void handleUSBLineStatus(unsigned char status) { trProtocol verPro; ProtocolInit(&verPro); ProtocolSetDestAddress(&verPro,3); ProtocolSetSourceAddress(&verPro,1); ProtocolSetType(&verPro,2); ProtocolSetOptionChar(&verPro, 99, 4); ProtocolSetOptionChar(&verPro, 123, status); ProtocolPackage(&verPro); ConsolePuts("\n===dsp to gui usb line status\n", -1); ConsolePutsHexStr(verPro.message, verPro.length); lwip_tcp_send_gui(verPro.message,verPro.length); }