Problem with crazyradio.set_address()

Firmware/software/electronics
Post Reply
e-Rok
Beginner
Posts: 25
Joined: Fri Sep 12, 2014 4:30 pm

Problem with crazyradio.set_address()

Post by e-Rok »

Hi all,

The function set_address(self, channel) in the crazyradio.py module has a hard coded requirement for the hex address to be 5 bytes long. However, each character in a hex address is 2 bytes, and the default address 0xE7E7E7E7E7 is 10 characters long. Therefore, the hex address length is actually 20 bytes long. The following is in crazyradio.py:

Code: Select all

 def set_address(self, address):
        """ Set the radio address to be used"""
        if len(address) != 5:
            raise Exception("Crazyradio: the radio address shall be 5"
                            " bytes long")

        _send_vendor_setup(self.handle, SET_RADIO_ADDRESS, 0, 0, address)
e-Rok
Beginner
Posts: 25
Joined: Fri Sep 12, 2014 4:30 pm

Re: Problem with crazyradio.set_address()

Post by e-Rok »

This is from the python terminal utility:

>>> x = hex(0xe7e7e7e7e7)
>>> print len(x)
12 #this confuses me.
whoenig
Expert
Posts: 395
Joined: Mon Oct 27, 2014 2:55 am

Re: Problem with crazyradio.set_address()

Post by whoenig »

You essentially look at a hex-string, not at a hex-number. Every "digit" in hex can be 0-F, which represents the numbers 0-16 in the decimal system. Therefore, every "hex digit" requires 4 bits to store. For your example this means:
0xe7e7e7e7e7: 0x is just the encoding to tell you it is hex, the number itself is
e7e7e7e7e7: This is 10 "hex digits", which means it requires 10*4=40 bits.
A byte can store 8 bits, i.e. 40/8=5 Byte, which is what the code is checking.
More details can be found here: http://en.wikipedia.org/wiki/Hexadecimal
Post Reply