Example #1
0
def cmdtest_local_atquery(ser,at):
  from packet_encode import atcom_query
  from packet_decode import rxpacket
  tx_packet = atcom_query(at) 
  print('Tx Packet: {}'.format(mf.hexstr(tx_packet)))
  print('-----')
  ser.write(tx_packet)
  status, payload = rxpacket(ser) 
  print('Payload: {}'.format(mf.hexstr(payload))) 
  pd.decode_payload(payload)
  print('-----')
Example #2
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)
if status != 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