agkalkin / xbee-arduino

Automatically exported from code.google.com/p/xbee-arduino
GNU General Public License v2.0
0 stars 0 forks source link

XBeeResponse reset issue - temporary fix included #23

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Reusing an XBee Response object

What is the expected output? What do you see instead?
The Arduino resets

What version of the product are you using? On what operating system?
0.3

Please provide any additional information below.
The Library behaves strangely while resetting the FrameData buffer to zero. 
After about 70 bytes the arduino will reset.
Intermediate Fix: only reset the amount of bytes the last frame did use:

void XBeeResponse::reset() {
    init();
    _apiId = 0;
    _msbLength = 0;
    _lsbLength = 0;
    _checksum = 0;

        // FIX for reset routine
    int counter = 0;
    if (_frameLength < MAX_FRAME_DATA_SIZE)
        counter = _frameLength;
    else
        counter = MAX_FRAME_DATA_SIZE;

    _frameLength = 0;

    _errorCode = NO_ERROR;

    for (int i = 0; i < counter; i++) {
        getFrameData()[i] = 0;
    }
}

Original issue reported on code.google.com by Megahulk...@googlemail.com on 24 Feb 2012 at 9:49

GoogleCodeExporter commented 8 years ago
I've just been looking at this code. I haven't worked out why resetting the 
bytes in the frame buffer causes the arduino to reset; however I've looked at 
the way readPacket works, and I can't see any reason why these bytes need to be 
set to zero at all, given that there is a _frameLength variable to indicate 
which bytes have been read into the current response.

I've tried simply commenting out the 'for' loop in the original version, and at 
a first glance this seems to work OK.

The patch is to change XBeeResponse::reset() to look like this:

void XBeeResponse::reset() {
  init();
  _apiId = 0;
  _msbLength = 0;
  _lsbLength = 0;
  _checksum = 0;
  _frameLength = 0;

  _errorCode = NO_ERROR;
/* REMOVED.
  for (int i = 0; i < MAX_FRAME_DATA_SIZE; i++) {
    getFrameData()[i] = 0;
  }*/
}

(From line 739 in the 0.3 version of the library)

Original comment by highfel...@gmail.com on 5 Oct 2012 at 8:13

GoogleCodeExporter commented 8 years ago
Thanks guys for identifying the issue and the fix. I removed the reset and 
checked into subversion.

Original comment by andrew.rapp@gmail.com on 6 Oct 2012 at 8:10

GoogleCodeExporter commented 8 years ago
Hi, it also happened to me. I've just commented that pieec of code in the reset 
procedure and now the Arduino does not reset itself.

Do you know a reason for this? as I partner is developing similar software and 
it doesn't happen to him.

Regards

Original comment by Javier.B...@gmail.com on 10 Jan 2013 at 2:41

GoogleCodeExporter commented 8 years ago
I'm not working on this anymore. I never worked out why it was happening, just 
the workaround I posted.

Original comment by highfel...@gmail.com on 10 Jan 2013 at 3:31

GoogleCodeExporter commented 8 years ago
Please try version 0.5

Original comment by andrew.rapp@gmail.com on 2 Feb 2014 at 6:39