EasyTransfer library issue

So…I created a simple set of apps using the EasyTransfer library by Bill Porter. The library is available via the web IDE. It works fine when my struct consists of a couple int’s and a char array of up to about 45 bytes and then it stops working if I go larger than that. The documentation indicates the struct can be no more than 256 bytes (I assume due to using unit8_t for pointers). Any thoughts on why I might be running in to trouble with structs greater than about 45 bytes? I am using the version of the library that’s designed for serial communications.

Just to be clear, it appears the data is sent, but it appears not to be received (or at least accepted as valid).

What exactly does that mean?
No transfer at all, gibberish data, truncated, stall, SOS, …
Is the Particle the receiver or sender side?

Pointers are always four byte long on these µCs

@ctmorrison, can you post your code or at least the struct definition?

Hi @ScruffR “stops working” (yes, a bit vague) means the transmitting Photon appears to run as normal sending data to the other Photon (their Rx and Tx lines are crossed), but the receiving Photon does not get/accept the data. The code for the Tx & Rx Photons is the sample code included with the library. That code worked fine even with the addition of a small (20) character array. I then merely changed the length of the array to a larger value and the Rx Photon no longer gets/accepts the data. Others are having the same issue

By looking at the code, the “pointer” I’m referring to is the variable used in the library to index through the struct that’s passed. It’s declared as a uint8_t, a one byte variable. Perhaps my choice of words was poor.

[update] I’ve downloaded the library files and re-created the programs in Particle Dev with a slew of print statements in the library .cpp file. I’m now wondering if there’s a Rx buffer issue, as I appear to be falling out of the bottom of the receive function . Is there Rx buffer size for Serial1?

[more update] I hacked the receive function a bit and now confirm that I’m getting a false return on _stream->available prior to having read in the expected number of bytes being sent. I believe this confirms I’m either running out of buffer or the data isn’t being sent fast enough?

Just saw the buffer size for Serial1 is 64 bytes, so that’s likely the issue.

@peekay123, after looking at another topics about Serial buffering in which you responded, I believe the while() technique is employed in the EasyTransfer library. I modified the code a bit to check to see if I had received all intended bytes. However, the Serial1.available() returned a false value even though there were still expected bytes as determined by the sent length (which is being correctly received).

My understanding is that the Photon that Tx’s the data will be blocked when it’s output buffer is full. So…I’m assuming the Tx end works as desired. However, on the Rx end I seem to run out of available data before the expected number of bytes have been received.

Here’s the ReceiveData() function from the EasyTransfer library. The function is falling out the bottom with FALSE and I was able to see (via a slew of print statements) that the while() loop after the header bytes were found is ending due to _stream->available() yielding FALSE. So…I’m at a loss as to how to “fix” the EasyTransfer library.

boolean EasyTransfer::receiveData(){

	//start off by looking for the header bytes. If they were already found in a previous call, skip it.
	if(rx_len == 0){
		//this size check may be redundant due to the size check below, but for now I'll leave it the way it is.
		if(_stream->available() >= 3){
			//this will block until a 0x06 is found or buffer size becomes less then 3.
			while(_stream->read() != 0x06) {
				//This will trash any preamble junk in the serial buffer
				//but we need to make sure there is enough in the buffer to process while we trash the rest
				//if the buffer becomes too empty, we will escape and try again on the next call
				if(_stream->available() < 3)
				return false;
			}
			if (_stream->read() == 0x85){
				rx_len = _stream->read();
				//make sure the binary structs on both Arduinos are the same size.
				if(rx_len != size){
					rx_len = 0;
					return false;
				}
			}
		}
	}

	//we get here if we already found the header bytes, the struct size matched what we know, and now we are byte aligned.
	if(rx_len != 0){
		while(_stream->available() && rx_array_inx <= rx_len){
			rx_buffer[rx_array_inx++] = _stream->read();
		}
		
		if(rx_len == (rx_array_inx-1)){
			//seem to have got whole message
			//last uint8_t is CS
			calc_CS = rx_len;
			for (int i = 0; i<rx_len; i++){
				calc_CS^=rx_buffer[i];
			} 
			
			if(calc_CS == rx_buffer[rx_array_inx-1]){//CS good
				memcpy(address,rx_buffer,size);
				rx_len = 0;
				rx_array_inx = 0;
				return true;
			}
			
			else{
				//failed checksum, need to clear this out anyway
				rx_len = 0;
				rx_array_inx = 0;
				return false;
			}
			
		}
	}

	return false;
}

Could the solution be this simple??? I slowed the baud rate down to 1200, increased the character array to 180 bytes and it’s working fine.

[update] I’m up to my desired 200 char array and it’s working just fine. Hmmmm…]

1 Like