Unpacking results of Hardware and Firmware revisions

I am trying to make sense of the the data returned from HV and VR commands.

vr = zigbee.ddo_get_param(XB_DESTINATION,‘VR’)
hv = zigbee.ddo_get_param(XB_DESTINATION,‘HV’)
print struct.unpack(“H”,hv])[0]
print struct.unpack(“H”,vr)[0]

This displays 17689 and 16680, the XBee manual for VR states;

VR Firmware Version. Read firmware version of the module.
The firmware version returns 4 hexadecimal values (2 bytes) “ABCD”. Digits ABC are the main release number and D is the revision number from the main release. “B” is a variant designator.
XBee and XBee-PRO ZB modules return:
0x2xxx versions.
XBee and XBee-PRO ZNet modules return:
0x1xxx versions. ZNet firmware is not compatible with ZB firmware.

How do I relate this to the value returned?

Any help would be appreciated, thanks.

Do have a reason for this need?

To just detect the module type or mesh/stack support level, use the DD command.
http://www.digi.com/wiki/developer/index.php/XBee_Product_Codes

I don’t think the hardware and version values are regular enough to “decode” in a smart, universal way - in the end you’ll end up with a large switch-statement with lots of constants & any new XBee will force you to change your code.

As part of an admin screen function to add additional sensors to my application I wanted to list this information. it may help with diagnostics etc if a particular sensor is problematic. I use DD to determine sensor type but would like to include at least firmware revision.

Thanks for your reply.

You may use a couple of methods in order to interpret the integers returned by the DDO commands you have unpacked. However, I would strongly recommend asserting that unpack use big-endian ordering for the integers. You may do this by prepending your format string with a “>” character. This makes your code:

vr = zigbee.ddo_get_param(XB_DESTINATION,‘VR’)
hv = zigbee.ddo_get_param(XB_DESTINATION,‘HV’)
print struct.unpack(“>H”,hv)[0]
print struct.unpack(“>H”,vr)[0]

Printing:

6469
10305

You may then use hex():

print hex(struct.unpack(“>H”,hv)[0])
print hex(struct.unpack(“>H”,vr)[0])

0x1945
0x2841

Or a more complex format string:

print “hv = %04x” % struct.unpack(“>H”,hv)[0]
print “vr = %04x” % struct.unpack(“>H”,vr)[0]

Printing:

hv = 1945
vr = 2841

Jordan

Exactly what I needed to know - thanks.