bglib icon indicating copy to clipboard operation
bglib copied to clipboard

Bug when parsing very long packets

Open mjbrown opened this issue 10 years ago • 0 comments

There is a bug in your C# and Python when parsing very long packets. I ran across it in my fork. Nobody has probably seen it before because seldom are there packets larger than 256 bytes. Here's the fixes in a diff:

diff --git a/MSVCSharp/BGLib.cs b/MSVCSharp/BGLib.cs index 55aac3c..8e42338 100644 --- a/MSVCSharp/BGLib.cs +++ b/MSVCSharp/BGLib.cs @@ -1816,7 +1816,7 @@ namespace Bluegiga { bgapiRXBuffer[bgapiRXBufferPos++] = ch; if (bgapiRXBufferPos == 2) { // just received "Length Low" byte, so store expected packet length

  •                bgapiRXDataLen = ch + ((bgapiRXBuffer[0] & 0x03) << 8);
    
  •                bgapiRXDataLen = ch + ((bgapiRXBuffer[0] & 0x07) << 8);
             } else if (bgapiRXBufferPos == bgapiRXDataLen + 4) {
                 // just received last expected byte
                 /*#ifdef DEBUG
    
    diff --git a/Python/bglib.py b/Python/bglib.py index aafadbb..15b5fac 100644 --- a/Python/bglib.py +++ b/Python/bglib.py @@ -664,7 +664,7 @@ class BGLib(object): self.bgapi_rx_buffer.append(b) elif len(self.bgapi_rx_buffer) == 1: self.bgapi_rx_buffer.append(b)
  •        self.bgapi_rx_expected_length = 4 + (self.bgapi_rx_buffer[0] & 0x07) + self.bgapi_rx_buffer[1]
    
  •        self.bgapi_rx_expected_length = 4 + (self.bgapi_rx_buffer[0] & 0x07)*256 + self.bgapi_rx_buffer[1]
     elif len(self.bgapi_rx_buffer) > 1:
         self.bgapi_rx_buffer.append(b)
    

mjbrown avatar Jan 03 '15 07:01 mjbrown