Git Product home page Git Product logo

wloggerdaemon's Issues

data in buffer object from usb device being truncated

I ran into an issue when I was taking a look at the project. Got it compiled and running, my RMS300A detected just fine, talking to couchdb on another machine just fine. Problem is that I was only getting a reading every once in a while...the rest of the time I was getting a ton of debug error messages saying that it was "Discarding reading with wrong length or wrong checksum". The data included after the error message looked like a fragmented data stream to me. So, looking into it, I determined that I was getting situations where I had the 0xFF 0xFF marker in the middle of the buffer, but what was left when it passed off to the postReadingAndPrepareForNew in src/WMR100NDeviceController.m was the beginning of a new packet of data. This was getting dropped so the next time I came to process it, it was missing the beginning of data.

For example, here are some of the "data" included after the error message. You'll note a distict pattern:
<42301c01 35003000 305401>
<301c0135 00300030 5401>
<1c013500 30003054 01>

What appeared to be happening was the beginning of the packet was being chopped off. So I stepped through the code in WMR100NDeviceController. Inside the inputReport method, I found the culprit. What was happening was this:

  • find the 0xFF 0xFF marker in buffer
  • make a copy of the data up to that marker in the 'new' object
  • pass that object off to be processed
    (here's the key)
  • clear contents of buffer by setting the size 0...even if data existed after the 0xFF 0xFF marker

Ideally it would have been nice if the NSMutableObject class gave us a way to drop data off the front and shift it, but alas it does not...we're just allowed to truncate it. My fix went like this:

  • find the 0xFF 0xFF marker in buffer
  • make a copy of the data up to that marker in the 'new' object
  • pass that off to be processed
    (up to this point we're the same, changes happen beginning next)
  • if there is data after the 2nd 0xFF, get a pointer to the buffer's data and use memmove to copy starting at the first bit of data after the 2nd 0xFF marker to the beginning (memmove uses a non-destructive copy method).
  • truncate the buffer to the length that's left (the buffer can end with 0xFF 0xFF).

Here's my hacked solution (grr the webform mangled my patch data...no way to attach a file apparently...):

change the line in inputReport method inside WMR100NDeviceController.m (line 150 in the 2009-12-05 version):
[buffer setLength:0];
to:
if ((i + 2) < len) { // if data exists after the 0xFF 0xFF marker
char *bufferData=[buffer mutableBytes];
memmove(bufferData,(bufferData + i + 2),(len - i - 2));
}
[buffer setLength:(len - i - 2)];

This seems to have fixed my issue. Comments?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.