openyou / libfitbit

Library for accessing and transfering data from the Fitbit health device
http://www.openyou.org
BSD 3-Clause "New" or "Revised" License
422 stars 66 forks source link

Create protocol::_recieve_message() with protocol level operations above libusb #18

Closed marcushall42 closed 12 years ago

marcushall42 commented 12 years ago

The bulk of this change is to create a _receive_message() method at the protocol level that performs framing and checksum validation. The underlying libusb _receive() method is invoked as needed to retrieve data which may contain multiple packets or partial packets. The SYNC characters (ANT protocol says a4 or a5 is valid sync) are used to determine the beginning of a packet. Any data beyond the end of the current packet is saved for the next invocation. Timeouts from libusb are tolerated, but after four timeouts any packets received already are processed and any other data is discarded.

I am submitting this for consideration. It works for me.

qdot commented 12 years ago

Oh yeah, that state machine I always meant to write and forgot about. :D

Thanks so much for doing this! I'll try to get it reviewed and in ASAP. :)