Created
December 18, 2013 17:21
-
-
Save tcheneau/8026274 to your computer and use it in GitHub Desktop.
Send the appropriate commands in order to set the parameters (e.g. short/long address) in a Redbee Econotag device. This script requires a modified version of the Econotag "linux-serial" firmware.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env python | |
# Tony Cheneau <tony.cheneau@nist.gov> | |
# Conditions Of Use | |
# | |
# This software was developed by employees of the National Institute of | |
# Standards and Technology (NIST), and others. | |
# This software has been contributed to the public domain. | |
# Pursuant to title 15 United States Code Section 105, works of NIST | |
# employees are not subject to copyright protection in the United States | |
# and are considered to be in the public domain. | |
# As a result, a formal license is not needed to use this software. | |
# | |
# This software is provided "AS IS." | |
# NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED | |
# OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF | |
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT | |
# AND DATA ACCURACY. NIST does not warrant or make any representations | |
# regarding the use of the software or the results thereof, including but | |
# not limited to the correctness, accuracy, reliability or usefulness of | |
# this software. | |
"""Assigns the PANID, short address and long address on an econotag | |
This requires a specific firmware, with the corresponding commands, | |
as well as the corresponding userspace""" | |
import sys,os,time | |
from termios import * | |
from test_DQ import * | |
RETRY = 0 | |
OK = 1 | |
def set_PANID(panid): | |
try: | |
panid = int(panid,16) | |
print 'Result of set_PANID ' + hex(cn.set_panid(chr((panid>>8)& 0xff) + chr(panid & 0xff))) | |
except: | |
print "wrong PANID value %s, a correct PAN ID would be : \"777\" (hex)" % panid | |
sys.exit(-1) | |
return OK | |
def set_short_address(saddr): | |
try: | |
saddr = int(saddr,16) | |
print 'Result of set_shortaddr ' + hex(cn.set_shortaddr(chr((saddr>>8)& 0xff) + chr(saddr & 0xff))) | |
except: | |
print "wrong short address, a correct short address would be: \"1\" (hex)" | |
sys.exit(-1) | |
return OK | |
def set_long_address(laddr): | |
laddr = laddr.replace(":","") | |
if len(laddr) != 16: | |
print "wrong long address %s, should be ba:be:ba:be:ba:be:ba:be or babebabebabebabe" % laddr | |
sys.exit(-1) | |
laddr = "".join([ chr(int(a + b,16)) for (a,b) in zip(laddr[::2], laddr[1::2]) ]) | |
try: | |
result = cn.set_longaddr(laddr) | |
print 'Result of set_long_addr ' + hex(result) | |
if result != 0: | |
print "Long address was not assigned properly" | |
return RETRY | |
except: | |
print "wrong long address" | |
return OK | |
if __name__ == "__main__": | |
if len(sys.argv) != 5: | |
print "usage: %s device PANID shortaddr longaddr" % sys.argv[0] | |
sys.exit(-1) | |
# prepare connection to the serial device | |
cn = DQ(sys.argv[1],baudrate=921600) | |
print 'Result of close ' + hex(cn.close()) | |
print 'Result of open ' + hex(cn.open()) | |
set_PANID(sys.argv[2]) | |
set_short_address(sys.argv[3]) | |
# long address might not get assigned properly on the first time | |
while RETRY == set_long_address(sys.argv[4]): | |
pass # do nothing | |
# properly disconnect from the serial device | |
cn.close() | |
sys.exit(2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment