コード例 #1
0
def remote_query(ser, remote, param):
    success = 0

    command_dict = {
        'PL': b'QP',
        'CH': b'QC',
        'A': b'QA',
        'T': b'QT',
        'WR': b'DW',
        'S': b'QS'
    }

    data = command_dict[param]
    payload = pe.gen_txreq('01', remote, '00', '00', mf.hexstr(data))
    bytestr = pe.gen_headtail(payload)
    ser.write(bytestr)

    while success == 0:

        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
            else:
                success = 1
        else:
            success = 0

    # Read Transmitted values
    success = 0

    print('Remote node response:')

    while success == 0:

        success, payload = pd.rxpacket_buffered(ser)
        #print('payload: {}'.format(payload))

        if payload == b'':
            print('Serial timeout')
            return 0

        if payload[0] == 0x90:
            #print('-- received packet')
            pd.decode_rxpacket(payload)
            success = 1
        else:
            success = 0
コード例 #2
0
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
コード例 #3
0
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
コード例 #4
0
def remote_nodeloc(ser, remote, loc):
    success = 0
    maxlen = 20

    length = len(loc)
    if length > maxlen:
        print('Exceeded maximum node loc length')
        return 0
    length_b = (length).to_bytes(1, 'big')

    data = b'DL' + length_b + bytes(loc, 'ascii')
    payload = pe.gen_txreq('01', remote, '00', '00', mf.hexstr(data))
    bytestr = pe.gen_headtail(payload)
    ser.write(bytestr)

    while success == 0:
        success, payload = pd.rxpacket_buffered(ser)
        if payload == b'':
            print('Serial timeout')
            return 0
        else:
            if success == 1:
                if payload[0] == 0x8b:
                    error = pd.decode_txstat(payload)
                    if error == 0:
                        print('Remote node {} node loc set'.format(remote))
                        return 1

            success = 0
コード例 #5
0
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
コード例 #6
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
コード例 #7
0
def config(device, power, channel):
    ser = serial.Serial(port=device, timeout=5)

    # Set power
    if (power > 4) | (power < 0):
        print('Invalid power')
        return ser
    bytestr = pe.atcom_set('PL', (power).to_bytes(1, 'big'))
    ser.write(bytestr)
    payload = b'\x00'
    while payload[0] != 0x88:
        success, payload = pd.rxpacket_buffered(ser)
        if payload == b'':
            print('Serial timeout')
            return ser
        if success == 0:
            print('Error receiving response from AT set PL')
            return ser
        if payload[0] == 0x88:
            error = pd.decode_atcomres(payload)
            if error == 1:
                print('Error reported by AT command response')
                return success

    print('Set power {}: success'.format(power))

    # Set channel
    if (channel > 26) | (channel < 11):
        print('Invalid channel')
        return ser
    bytestr = pe.atcom_set('CH', (channel).to_bytes(1, 'big'))
    ser.write(bytestr)
    payload = b'\x00'
    while payload[0] != 0x88:
        success, payload = pd.rxpacket_buffered(ser)
        if payload == b'':
            print('Serial timeout')
            return ser
        if success == 0:
            print('Error receiving response from AT set CH')
            return ser
        if payload[0] == 0x88:
            error = pd.decode_atcomres(payload)
            if error == 1:
                print('Error reported by AT command response')
                return success

    print('Set channel {}: success'.format(channel))

    # Write to NVM
    bytestr = pe.atcom_query('WR')
    ser.write(bytestr)
    payload = b'\x00'
    while payload[0] != 0x88:
        success, payload = pd.rxpacket_buffered(ser)
        if payload == b'':
            print('Serial timeout')
            return ser
        if success == 0:
            print('Error receiving response from AT query WR')
            return ser
        if payload[0] == 0x88:
            error = pd.decode_atcomres(payload)
            if error == 1:
                print('Error reported by AT command response')
                return success

    print('Configuration saved to NVM')

    return ser
コード例 #8
0
    timeout_max = int(args.timeout)
else:
    timeout_max = 5

## Configure UART
print('** Step 1. Configuring local UART **')
#ser = c.cmdtest_uartsetup(port=dev,timeout=5)
device = '/dev/ttyUSB' + str(dev)
ser = serial.Serial(port=device, timeout=5)
remote = c.cmdtest_addrconv(args.nodeaddr)

## Set channel
print('** Step 2. Setting local channel to 0x{} **'.format(mf.hexstr(ch)))
tx_packet = pe.atcom_query('CH')
ser.write(tx_packet)
status, payload = pd.rxpacket_buffered(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_buffered(ser)
status = pd.decode_payload(payload)
if status != 0:
    print('-- Error setting AT parameter CH')
    quit()