Пример #1
0
def testRot13(destination, input):
  print "--- Input: ", input
  pynvc.sendcmd(destination, pynvc.APPMSG, [ord(c) for c in input])
  print "--- Sent"
  src, reply = pynvc.receive(5000) # Receive reply
  print "--- Received reply"
  pynvc.sendcmd(destination, pynvc.APPMSG_R, [pynvc.APPMSG_STATUS_ACK])
  print "Reply:", [chr(c) for c in reply[1:]] # Strip of the leading 0x7e (APPMSG) command
Пример #2
0
def getStatus(destination):
  pynvc.receive(10)
  pynvc.sendcmd(destination, pynvc.APPMSG, [3]);
  reply = pynvc.receive(100) # Receive reply
  if reply != None and reply[1] == 4:
    return reply[2:]
  else:
    reply = pynvc.receive(100) # Receive reply
    if reply != None and reply[1] == 4:
      return reply[2:]
    else:
      return None
Пример #3
0
def testWuClass(destination):

  pynvc.sendcmd(destination, pynvc.WKPF_GET_WUCLASS_LIST, [0x05, 0x05]);
  print "--- Sent get"
  src, reply = pynvc.checkedReceive([pynvc.WKPF_GET_WUCLASS_LIST_R], 5000) # Receive reply: should be a WKPF_GET_WUCLASS_LIST_R
  print "--- Received reply"
  print "Reply:", [chr(c) for c in reply[1:]] 

	#wuclass:00~02,property:00~01
	#seq=05 05, wuclassID=00 02, roleID=a1, propertyID=01, value=aabbccdd
  pynvc.sendcmd(destination, pynvc.WKPF_WRITE_PROPERTY, [0x05, 0x05, 0x00, 0x02, 0xa1, 0x01, 0xaa, 0xbb, 0xcc, 0xdd]);
  print "--- Sent write"
  src, reply = pynvc.checkedReceive([pynvc.WKPF_WRITE_PROPERTY_R], 5000) # Receive reply: should be a WKPF_WRITE_PROPERTY
  print "--- Received reply"
  print "Reply:", [chr(c) for c in reply[1:]] 


  pynvc.sendcmd(destination, pynvc.WKPF_READ_PROPERTY, [0x05, 0x05, 0x00, 0x02, 0xa1, 0x00]);
  print "--- Sent read"
  src, reply = pynvc.checkedReceive([pynvc.WKPF_READ_PROPERTY_R], 5000) # Receive reply: should be a WKPF_READ_PROPERTY_R
  print "--- Received reply"
  print "Reply:", [chr(c) for c in reply[1:]] 
Пример #4
0
def setLamp(destination, input):
  pynvc.sendcmd(destination, pynvc.APPMSG, [1, input])
Пример #5
0
def getRunLevelTest(destination):
  pynvc.sendcmd(destination, pynvc.GETRUNLVL)
  src, received_data = pynvc.receive(5000)
  if not received_data == None:
    print "Received runlevel:", received_data[1]
Пример #6
0
def reprogramNvmdefault(destination, filename):
  MESSAGESIZE = 16
  src, reply = pynvc.sendWithRetryAndCheckedReceive(destination=destination,
                                                command=pynvc.REPRG_OPEN,
                                                allowedReplies=[pynvc.REPRG_OPEN_R],
                                                quitOnFailure=True)
  pagesize = reply[1]*256 + reply[2]

  lines = [" " + l.replace('0x','').replace(',','').replace('\n','') for l in open(filename).readlines() if l.startswith('0x')]
  bytecode = []
  for l in lines:
    for b in l.split():
      bytecode.append(int(b, 16))

  print "Uploading", len(bytecode), "bytes."

  pos = 0
  while not pos == len(bytecode):
    payload_pos = [pos/256, pos%256]
    payload_data = bytecode[pos:pos+MESSAGESIZE]
    print "Uploading bytes", pos, "to", pos+MESSAGESIZE, "of", len(bytecode)
    if pos/pagesize == (pos+len(payload_data))/pagesize:
      pynvc.sendcmd(destination, pynvc.REPRG_WRITE, payload_pos+payload_data)
      pos += len(payload_data)
    else:
      # Send last packet of this page and wait for a REPRG_WRITE_R_RETRANSMIT after each full page
      src, reply = pynvc.sendWithRetryAndCheckedReceive(destination=destination,
                                                    command=pynvc.REPRG_WRITE,
                                                    allowedReplies=[pynvc.REPRG_WRITE_R_OK, pynvc.REPRG_WRITE_R_RETRANSMIT],
                                                    payload=payload_pos+payload_data)
      print "Page boundary reached, wait for REPRG_WRITE_R_OK or REPRG_WRITE_R_RETRANSMIT"
      if reply[0] == pynvc.REPRG_WRITE_R_OK:
        print "Received REPRG_WRITE_R_OK in reply to packet writing at", payload_pos
        pos += len(payload_data)
      elif reply[0] == pynvc.REPRG_WRITE_R_RETRANSMIT:
        pos = reply[1]*256 + reply[2]
        print "===========>Received REPRG_WRITE_R_RETRANSMIT request to retransmit from ", pos
      else:
        print "No reply received. Code update failed. :-("
        return False

    # Send REPRG_COMMIT after last packet
    if pos == len(bytecode):
      src, reply = pynvc.sendWithRetryAndCheckedReceive(
                        destination=destination,
                        command=pynvc.REPRG_COMMIT,
                        allowedReplies=[pynvc.REPRG_COMMIT_R_RETRANSMIT,
                                        pynvc.REPRG_COMMIT_R_FAILED,
                                        pynvc.REPRG_COMMIT_R_OK],
                        payload=[pos/256, pos%256])
      if reply[0] == pynvc.REPRG_COMMIT_R_OK:
        print reply
        print "Commit OK."
      elif reply[0] == pynvc.REPRG_COMMIT_R_RETRANSMIT:
        pos = reply[1]*256 + reply[2]
        print "===========>Received REPRG_COMMIT_R_RETRANSMIT request to retransmit from ", pos
      else:
        print "Commit failed."
        return False
  src, reply = pynvc.sendWithRetryAndCheckedReceive(destination=destination,
                                                    command=pynvc.SETRUNLVL,
                                                    allowedReplies=[pynvc.SETRUNLVL_R],
                                                    payload=[pynvc.RUNLVL_RESET])
  if reply == None:
    print "Going to runlevel reset failed. :-("
    return False;
  else:
    return True;
Пример #7
0
def reprogramNvmdefault(destination, filename):
    MESSAGESIZE = 16
    reply = pynvc.sendWithRetryAndCheckedReceive(
        destination=destination, command=pynvc.REPRG_OPEN, allowedReplies=[pynvc.REPRG_OPEN_R], quitOnFailure=True
    )
    pagesize = reply[1] * 256 + reply[2]

    lines = [
        " " + l.replace("0x", "").replace(",", "").replace("\n", "")
        for l in open(filename).readlines()
        if l.startswith("0x")
    ]
    bytecode = []
    for l in lines:
        for b in l.split():
            bytecode.append(int(b, 16))

    print "Uploading", len(bytecode), "bytes."

    packetLost = False

    pos = 0
    while not pos == len(bytecode):
        payload_pos = [pos / 256, pos % 256]
        payload_data = bytecode[pos : pos + MESSAGESIZE]
        if pos / pagesize == (pos + len(payload_data)) / pagesize:
            if packetLost == False and pos == 32:
                print "------------->Simulating packet loss"
                # drop this one packet
                packetLost = True
            else:
                pynvc.sendcmd(destination, pynvc.REPRG_WRITE, payload_pos + payload_data)
            pos += len(payload_data)
        else:
            # Send last packet of this page and wait for a REPRG_WRITE_R_RETRANSMIT after each full page
            reply = pynvc.sendWithRetryAndCheckedReceive(
                destination=destination,
                command=pynvc.REPRG_WRITE,
                allowedReplies=[pynvc.REPRG_WRITE_R_OK, pynvc.REPRG_WRITE_R_RETRANSMIT],
                payload=payload_pos + payload_data,
                quitOnFailure=True,
            )
            print "Page boundary reached, wait for REPRG_WRITE_R_OK or REPRG_WRITE_R_RETRANSMIT"
            if reply[0] == pynvc.REPRG_WRITE_R_OK:
                print "Received REPRG_WRITE_R_OK in reply to packet writing at", payload_pos
                pos += len(payload_data)
            else:
                pos = reply[1] * 256 + reply[2]
                print "===========>Received REPRG_WRITE_R_RETRANSMIT request to retransmit from ", pos

        # Send REPRG_COMMIT after last packet
        if pos == len(bytecode):
            reply = pynvc.sendWithRetryAndCheckedReceive(
                destination=destination,
                command=pynvc.REPRG_COMMIT,
                allowedReplies=[pynvc.REPRG_COMMIT_R_RETRANSMIT, pynvc.REPRG_COMMIT_R_FAILED, pynvc.REPRG_COMMIT_R_OK],
                payload=[pos / 256, pos % 256],
                quitOnFailure=True,
            )
            if reply[0] == pynvc.REPRG_COMMIT_R_OK:
                print reply
                print "Commit OK."
            elif reply[0] == pynvc.REPRG_COMMIT_R_RETRANSMIT:
                pos = reply[1] * 256 + reply[2]
                print "===========>Received REPRG_COMMIT_R_RETRANSMIT request to retransmit from ", pos
            else:
                print "Commit failed."
                quit()
    pynvc.sendcmd(destination, pynvc.SETRUNLVL, [pynvc.RUNLVL_RESET])