예제 #1
0
def CommandHelp(ser):
    printMessage(0, "\n|----------|-------------------------------|")
    printMessage(0, "|{:10}| {:30}|".format("COMMAND", "DESCRIPTION"))
    printMessage(0, "|----------|-------------------------------|")
    for i, val in enumerate(lCommand):
        printMessage(0, "|{:10}| {:30}|".format(val[0], val[2]))
        printMessage(0, "|----------|-------------------------------|")
예제 #2
0
def UserLoopCommand(ser):
    key = "N/A"

    printMessage(15, "\n{}".format("Write 'quit' to stop the script\n\n"))
    while key != "quit":
        command = "N/A"
        key = input("{:15} ".format("\n>>> Command"))

        if key == "quit":
            printMessage(15, "Exiting the script")
            break
        else:
            UserSendCommand(ser, key)
    return 0
예제 #3
0
def sendPacket(ser, data):
	ser.flushInput()
	s_data =  struct.pack("B", len(data))
	printMessage(0, "{:15}{}".format("> Payload",data))
	#print(str(bytes(data)).replace("\\x"," 0x").replace("'","")[1:])
	printMessage(0, "> Sending...")
	ser.write(UART_HEADER)
	printMessage(0, "{:15}{}".format("> Received",ser.readline().decode(encoding='UTF-8')).strip())	
	ser.write(s_data) #length
	printMessage(0, "{:15}{}".format("> Received",str(ser.readline())[2:-3])) #need to remove one 'b and \n'
	for i in range(len(data)):
		ser.write(struct.pack("B", data[i]))
	#TODO CRC
	ser.write(UART_FOOTER)
	printMessage(0, "{:15}{}".format("> Received",ser.readline().decode(encoding='UTF-8')).strip())	
	printMessage(0, "{:15}{}".format("> Response",ser.readline().decode(encoding='UTF-8')).strip())