def remote_aggre(ser, remote, addr):
    success = 0

    # Arguments check
    if len(remote) != 16:
        print('Invalid remote node address')
        return success
    if len(addr) != 16:
        print('Invalid aggregator address')
        return success

    addr_b = mf.hexstr2byte(addr)
    remote_b = mf.hexstr2byte(remote)

    bytestr = pe.debug_setaddr(addr_b, remote_b)
    ser.write(bytestr)

    payload = b'\x00'
    while payload[0] != 0x8b:
        success, payload = pd.rxpacket_buffered(ser)
        if payload == b'':
            print('Serial timeout')
            return 0
        if success == 0:
            print('Error receiving response from Transmit request')
            return success
        if payload[0] == 0x8b:
            error = pd.decode_txstat(payload)
            if error == 1:
                print('Error reported by Transmit status')
                return 0

    print('Remote {} aggregator now set to {}'.format(remote, addr))
    success = 1
    return success
def gen_txreq(fid, dest, brad, opts, data):

    if len(fid) != 2:
        print('Error generating tx req: Frame ID')
        return b''
    bytestr = b'\x10' + hexstr2byte(fid)

    if len(dest) != 16:
        print('Error generating tx req: 64-bit dest addr')
        return bytestr
    bytestr = bytestr + hexstr2byte(dest) + b'\xff\xfe'

    if len(brad) != 2:
        print('Error generating tx req: Broadcast radius')
        return bytestr
    bytestr = bytestr + hexstr2byte(brad)

    if len(opts) != 2:
        print('Error generating tx req: Transmit options')
        return bytestr
    bytestr = bytestr + hexstr2byte(opts)

    if (len(data) % 2) != 0:
        print('Error generating tx req: RF data')
        return bytestr
    bytestr = bytestr + hexstr2byte(data)

    return bytestr
def remote_power(ser, remote, power):
    success = 0

    # Arguments check
    if len(remote) != 16:
        print('Invalid remote node address')
        return success
    if (power > 4) | (power < 0):
        print('Invalid XBee power')
        return success

    remote_b = mf.hexstr2byte(remote)
    power_b = (power).to_bytes(1, 'big')

    bytestr = pe.debug_power(power_b, remote_b)
    ser.write(bytestr)

    payload = b'\x00'
    while payload[0] != 0x8b:
        success, payload = pd.rxpacket_buffered(ser)
        if payload == b'':
            print('Serial timeout')
            return 0
        if success == 0:
            print('Error receiving response from Transmit request')
            return success
        if payload[0] == 0x8b:
            error = pd.decode_txstat(payload)
            if error == 1:
                print('Error reported by Transmit status')
                return 0

    print('Remote {} power now set to {}'.format(remote, power))
    success = 1
    return success
def remote_start(ser, remote, period):
    timeout_max = 5

    if period > 255:
        print('Invalid period')
        return 0
    remote_b = mf.hexstr2byte(remote)

    bytestr = pe.start_sensing(period, remote_b)
    ser.write(bytestr)

    timeouts = 0
    while 1:
        success, payload = pd.rxpacket_buffered(ser)

        if payload == b'':
            print('Serial timeout, Sending start again')
            timeouts = timeouts + 1
            ser.write(bytestr)

        else:
            if success == 1:
                success = pd.decode_startack(payload, remote_b)
                if success == 1:
                    print('Remote node {} started'.format(remote))
                    return success

        if timeouts == timeout_max:
            return 0
def remote_stop(ser, remote):
    timeout_max = 5
    remote_b = mf.hexstr2byte(remote)

    bytestr = pe.stop_sensing(remote_b)
    ser.write(bytestr)

    timeouts = 0
    while 1:
        success, payload = pd.rxpacket_buffered(ser)
        if payload == b'':
            print('Serial timeout, Sending stop again')
            timeouts = timeouts + 1
            ser.write(bytestr)
        else:
            if success == 1:
                success = pd.decode_stopack(payload, remote_b)
                if success == 1:
                    print('Remote node {} stopped'.format(remote))
                    return success

        if timeouts == timeout_max:
            return 0
Example #6
0
def cmdtest_addrconv(addrstr):
  return mf.hexstr2byte(addrstr)
Example #7
0
if args.portusb:
    dev = int(args.portusb)
else:
    dev = 0

print('Listening to channel 0x{}'.format(args.channel))

## Configure UART
print('** Step 1. Configuring local UART **')
#ser = c.cmdtest_uartsetup(0)
ser = c.cmdtest_uartsetup(dev)

## Set local channel channel
print('** Step 2. Setting local channel to 0x{} **'.format(args.channel))
ch = mf.hexstr2byte(args.channel)
tx_packet = pe.atcom_query('CH')
ser.write(tx_packet)
status, payload = pd.rxpacket(ser)
if status != 1:
    print('-- Error receiving internal packet (atcom_query)')
    quit()
status = pd.decode_payload(payload)
if status != 0:
    print('-- Error decoding internal packet (atcom_query)')
    quit()

tx_packet = pe.atcom_set('CH', ch)
ser.write(tx_packet)
status, payload = pd.rxpacket(ser)
status = pd.decode_payload(payload)
Example #8
0
import packet_decode as pd

## Parse arguments
parser = argparse.ArgumentParser()

parser.add_argument("nodeaddr", help="Node address (64-bit)")
parser.add_argument("-oc", "--oldchannel", help="Old channel (1 byte hex str)")
parser.add_argument("-nc", "--newchannel", help="New channel (1 byte hex str)")
parser.add_argument("-p", "--portusb", help="USB serial port number")

args = parser.parse_args()

print('Target node: 0x{}'.format(args.nodeaddr))

if args.oldchannel:
  ch_old = mf.hexstr2byte(args.oldchannel)
else:
  ch_old = b'\x0c'

if args.newchannel:
  ch_new = mf.hexstr2byte(args.newchannel)
else:
  ch_new = b'\x1a'

if args.portusb:
  dev = int(args.portusb)
else:
  dev = 0

print('-- Switching channel from 0x{} to 0x{}'.format(mf.hexstr(ch_old),mf.hexstr(ch_new))) 
print(' ')