/* * tr_queue_handler.c * * Created on: 2025年8月22日 * Author: 龙三郎 */ #include "tr_queue.h" #include #include "nim_config.h" #include "algorithm/emg_util.h" #include "uartStdio.h" #include "usbhspecific.h" #include #include "tr_protocol.h" extern struct udp_pcb *upcb; void handleSign(unsigned char *s, unsigned short sl); void handleSign2(unsigned char *s, unsigned short sl); void handleGUI(unsigned char *s, unsigned short sl); /** * 数据转发业务处理,需要进行转发的数据在这个里面处理 * params da 目的地址 */ void dataForwardedHandle(unsigned char *s, unsigned short sl, unsigned char da) { // printf("进入到数据转发!\r\n"); ConsolePuts("\n===dataForwardedHandle\n", -1); ConsolePutsHexStr(s, sl); if (da == F4_ADDRESS) { // 执行发送到F4的逻辑 USBHSPECIFICWrite(s, sl); } else if (da == GUI_ADDRESS) { // 执行发送到GUI的逻辑 lwip_tcp_send_gui(s, sl); } else if (da == UART_ADDRESS) { // 执行发送到串口的逻辑 UARTwrite((const char*) s, sl); } } /** * 不需要转发的数据。即其他模块发送给本模块的数据。 * params sa 数据源地址 * params type 数据类型 */ void dataNotForwardedHandle(unsigned char *s, unsigned short sl, unsigned char sa, unsigned char type) { // printf("进入到数据处理!\r\n"); if (sa == F4_ADDRESS) { // 处理从F4发来的数据 handleSign(s + 8, sl - 8); } else if (sa == GUI_ADDRESS) { // 处理从gui发来的数据 handleGUI(s,sl); } else if (sa == UART_ADDRESS) { // 处理从uart发来的数据 // ConsolePrintf("got it!!!\n"); } // if(type == TYPE_DEFAULT) // { // // 执行自定义数据的逻辑 // } // else if(type == TYPE_WAVEFORM) // { // // 执行波形数据的逻辑 // } // else if(type == TYPE_COMMAND) // { // // 执行指令数据的逻辑 // } } /** * 处理采集信号 */ #define COUNT_SIZE 75 #define CHANNEL_COUNT 4 //采集通道总数 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); 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 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 } // memcpy(fd1, cd1, dataCount); // memcpy(fd2, cd2, dataCount); // memcpy(fd3, cd3, dataCount); // memcpy(fd4, cd4, dataCount); 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(sd1,sd2,sd3,sd4, fm->sign,dataCount); free(fdata); } void handleSign2(unsigned char *s, unsigned short sl) { ConsolePuts("===handle signal 2 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); 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; //将采集数据转成mV int origenData2 = fm->d2[0] << 24 | fm->d2[1] << 16 | fm->d2[2] << 8; *(cd2 + i) = ((float) (origenData2 >> 8) / FFULL) * 5000000+470; //将采集数据转成mV int origenData3 = fm->d3[0] << 24 | fm->d3[1] << 16 | fm->d3[2] << 8; *(cd3 + i) = ((float) (origenData3 >> 8) / FFULL) * 5000000+450; //将采集数据转成mV int origenData4 = fm->d4[0] << 24 | fm->d4[1] << 16 | fm->d4[2] << 8; *(cd4 + i) = ((float) (origenData4 >> 8) / FFULL) * 5000000+440; //将采集数据转成mV } // memcpy(fd1, cd1, dataCount); // memcpy(fd2, cd2, dataCount); // memcpy(fd3, cd3, dataCount); // memcpy(fd4, cd4, dataCount); 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_vofa4(sd1, sd2 , sd3 ,sd4 , dataCount); free(fdata); } 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(); } }