niolabs / python-xbee

Python tools for working with XBee radios
MIT License
101 stars 45 forks source link

Support for Route Record Indicator packets #16

Closed jamesleesaunders closed 8 years ago

jamesleesaunders commented 8 years ago

Adds support for API Route Record Indicator packets (Type a1). Currently if a Route Record Indicator packet is received then the Python XBee library would barf with error: "Unrecognized response packet with id byte \xa1"

Adding Route Record Indicator packet type to zigbee.py.

(Apologies for creating duplicate Pull Request - GitHub did not permit me to change the source branch for this pull request from master)

jamesleesaunders commented 8 years ago

Also consider whether it is necessary to 'break' (therefore hang the callback thread) if the library receives a packet type it does not recognise - should it rather just throw a warning (or something else more 'thread safe')? In the following section of code in base.py:

def run(self): """ run: None -> None

 This method overrides threading.Thread.run() and is automatically
 called when an instance is created with threading enabled.
 """
 while True:
     try:
         self._callback(self.wait_read_frame())
     except ThreadQuitException:
         # Expected termintation of thread due to self.halt()
         break
     except Exception as e:
         # Unexpected thread quit.
         if self._error_callback:
             self._error_callback(e)
             # break <---- is this necessary / appropriate?

Also see blog post here: http://axotron.se/blog/problems-with-python-xbee-2-2-3-package/

Jim

jamesleesaunders commented 8 years ago

Also improved error message thrown when received packet size does not match the expected packet size.

hansmosh commented 8 years ago

Re: the error callback.

Sounds good to me. I recently took over this repository from the original creator and haven't had the chance to really get into it yet. That error callback was the first feature I added after taking over the library because I wanted to know that I should attempt to re-connect after an xbee gets unplugged. I'm seeing now that in other situations (like this \xa1 frame), it makes sense to continue on an error.

jamesleesaunders commented 8 years ago

Thanks for merging this in @hansmosh @pmalmsten :-) Ref the broken URL and the error callback break... I will raise a separate PR to address these.