Packet loss when transmitting using Bluetooth

I use the Bluetooth serial port to transmit data. There is data output but it cannot be output in real time. Because multiple data packets are transmitted, is it because my unpacking process affects the drawing? Here is my parsing code:

if(CES_Pkt_ID==CES_CMDIF_PKT_ECG_ID){
              ces_pkt_ecg_bytes[0] = CES_Pkt_Data_Counter[0];//ECG
              ces_pkt_ecg_bytes[1] = CES_Pkt_Data_Counter[1];
              ces_pkt_ecg_bytes[2] = CES_Pkt_Data_Counter[2];//Filterecg
              ces_pkt_ecg_bytes[3] = CES_Pkt_Data_Counter[3];
              
              ces_pkt_HR_bytes[0] = CES_Pkt_Data_Counter[4];//  HR
              ces_pkt_HR_bytes[1] = CES_Pkt_Data_Counter[5];
              
              ces_pkt_resp_bytes[0] = CES_Pkt_Data_Counter[6];//RESP
              ces_pkt_resp_bytes[1] = CES_Pkt_Data_Counter[7];
              ces_pkt_resp_bytes[2] = CES_Pkt_Data_Counter[8];//FilterRESP
              ces_pkt_resp_bytes[3] = CES_Pkt_Data_Counter[9];
              
              ces_pkt_RR_bytes[0] = CES_Pkt_Data_Counter[10];//RR
              ces_pkt_RR_bytes[1] = CES_Pkt_Data_Counter[11];
              
              int data1 = ces_pkt_ecg_bytes[0] | ces_pkt_ecg_bytes[1]<<8; //reversePacket(CES_Pkt_ECG_Counter, CES_Pkt_ECG_Counter.length-1);
              data1 <<= 16;
              data1 >>= 16;
              rawecg = data1; // ecg,resp, hr,filecg,filresp, rr;  
              
              int data2 = ces_pkt_ecg_bytes[2] | ces_pkt_ecg_bytes[3]<<8; //reversePacket(CES_Pkt_ECG_Counter, CES_Pkt_ECG_Counter.length-1);
              data2 <<= 16;
              data2 >>= 16;
              ecg = data2; // ecg,resp, hr,filecg,filresp, rr;  
              
              int data3 = ces_pkt_HR_bytes[0] | ces_pkt_HR_bytes[1]<<8; //reversePacket(CES_Pkt_ECG_Counter, CES_Pkt_ECG_Counter.length-1);
              data3 <<= 16;
              data3 >>= 16;
              hr = data3; // ecg,resp, hr,filecg,filresp, rr;  
              
              int data4 = ces_pkt_resp_bytes[0] | ces_pkt_resp_bytes[1]<<8; //reversePacket(CES_Pkt_ECG_Counter, CES_Pkt_ECG_Counter.length-1);
              data4 <<= 16;
              data4 >>= 16;
              rawresp = data4; // ecg,resp, hr,filecg,filresp, rr;  
              
              int data5 = ces_pkt_resp_bytes[2] | ces_pkt_resp_bytes[3]<<8; //reversePacket(CES_Pkt_ECG_Counter, CES_Pkt_ECG_Counter.length-1);
              data5 <<= 16;
              data5 >>= 16;
              resp = data5; // ecg,resp, hr,filecg,filresp, rr;  
              
              int data6 = ces_pkt_RR_bytes[0] | ces_pkt_RR_bytes[1]<<8; //reversePacket(CES_Pkt_ECG_Counter, CES_Pkt_ECG_Counter.length-1);
              data6 <<= 16;
              data6 >>= 16;
              rr = data6; // ecg,resp, hr,filecg,filresp, rr;  
              
              ECGLabelText.setText(hr+ " ");
              RESPLabelText.setText(rr + " ");
        }
        else if(CES_Pkt_ID==CES_CMDIF_PKT_GSR_ID){
              ces_pkt_gsr_bytes[0] = CES_Pkt_Data_Counter[0];//gsr
              ces_pkt_gsr_bytes[1] = CES_Pkt_Data_Counter[1];
              
              int data = ces_pkt_gsr_bytes[0] | ces_pkt_gsr_bytes[1]<<8; //reversePacket(CES_Pkt_ECG_Counter, CES_Pkt_ECG_Counter.length-1);
              data <<= 16;
              data >>= 16;
              gsr = data; // ecg,resp, hr,filecg,filresp, rr;  
        }
        // Assigning the values for the graph buffers

        //time = time+1;
        //xdata[arrayIndex] = time;
        ecgdata[arrayIndex] = (float)ecg;
        arrayIndex++;
        respdata[arrayIndex1] = (float) resp;
        arrayIndex1++;
        //filter_GSRdata=GSR.filteredConductance((float) gsr);
        gsrdata[arrayIndex2] = (float) gsr;
        arrayIndex2++;
        
       
        
        if (arrayIndex == pSize)
        {  
          arrayIndex = 0;
          //time = 0; 
        }
        if (arrayIndex1 == pSize)
        {  
          arrayIndex1 = 0;
        }
        if (arrayIndex2 == pSize)
        {  
          arrayIndex2 = 0;
        }

Hi @cola, Please would you give an outline description or diagram of the system. What is sending over bluetooth? what triggers the send, and where is that code running? Are messages going both ways?

I have solve my problem. Since my data analysis is performed in one thread, the thread is blocked. Although there is data, the data will be lost and the drawing will not be smooth.

1 Like