This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

duplicate and dropped packets on uart characteristic

I'm trying to move data over the uart characteristic. I followed the guidelines here devzone.nordicsemi.com/.../

In the main loop I am calling sd_ble_gatts_hvx until it returns buffers full, careful not to increment the buffer pointer until after it returns NRF_SUCCESS.

I am seeing that groups of 2-3 later packets are copied over some preceding packets. This causes some packets to be duplicated and some packets to be dropped. I tried making hvx_params into a static array so each time sd_ble_gatts_hvx gets a different copy that won't be overwritten or go out of scope. There isn't any other ble transmission outside of moving this data in the main loop.

The only way I can get this to work is to send 1 packet, wait for BLE_EVT_TX_COMPLETE, and then send the next packet. This way is unusable at 300 bytes per second. Getting 4kb/s doing it the other way with dup/dropped packets.

Heres my code, trying to send 51 packets, BLE_EVT_TX_COMPLETE event clears ble_busy and the char* pointer is to flash data that isn't changing or going out of scope. How could I be getting duplicate/dropped packets? I edited out other error handling in this code, I have not seen any kind of error except for buffers-full error.

void ble_send_buffer(char* buf)
{
	uint32_t err_code;
	char* bp = buf;
	uint16_t nsent = 0;
	while(nsent < 51)
	{
		ble_busy = 1;
		while(1)
		{
			err_code = ble_nus_string_send(&m_nus, (uint8_t*)bp, 20);
			if (err_code == BLE_ERROR_NO_TX_BUFFERS )
			{ 
                            break;
			} else if(err_code == NRF_SUCCESS)
			{
				nsent++;
				bp += 20;
				if(nsent == 51) break;
			}
		}
		while(ble_busy); //wait for tx complete after breaking
	}
}
Parents
  • @robotjosh: Testing your code here didn't show the issue. I was not able to recompile the nRFToolbox app because I don't have the iOS app development environment. I tested using Master Control panel tool on PC. And didn't see any duplicate or dropped packet.

    However, there is one bug in your code may cause the bp pointer goes out of bound is the condition "while(bytesleft > 0)". bytesleft is unsigned int, so it will not be negative at the end of the loop but go overflow and keep the loop going.

    Note that the sniffer also work with the PCA10028 DK, so if you have 2 kits you should be able to use the sniffer.

Reply
  • @robotjosh: Testing your code here didn't show the issue. I was not able to recompile the nRFToolbox app because I don't have the iOS app development environment. I tested using Master Control panel tool on PC. And didn't see any duplicate or dropped packet.

    However, there is one bug in your code may cause the bp pointer goes out of bound is the condition "while(bytesleft > 0)". bytesleft is unsigned int, so it will not be negative at the end of the loop but go overflow and keep the loop going.

    Note that the sniffer also work with the PCA10028 DK, so if you have 2 kits you should be able to use the sniffer.

Children
No Data
Related