Beispiel #1
0
def main():

    handle_args()

    client = HMTLClient(options)

    msg = None
    expect_response = False

    if (options.commandtype == "value"):
        print("Sending value message.  Address=%d Output=%d Value=%d" %
              (options.hmtladdress, options.output, int(options.commandvalue)))
        msg = HMTLprotocol.get_value_msg(options.hmtladdress,
                                         options.output,
                                         int(options.commandvalue))
    elif (options.commandtype == "rgb"):
        (r,g,b) = options.commandvalue.split(",")
        print("Sending RGB message.  Address=%d Output=%d Value=%d,%d,%d" %
              (options.hmtladdress, options.output, int(r), int(g), int(b)))
        msg = HMTLprotocol.get_rgb_msg(options.hmtladdress,
                                       options.output,
                                       int(r), int(g), int(b))

    elif (options.commandtype == "blink"):
        (a,b,c,d, e,f,g,h) = options.commandvalue.split(",")
        print("Sending BLINK message. Address=%d Output=%d on_period=%d on_value=%s off_period=%d off_values=%s" % (options.hmtladdress, options.output, int(a), [int(b),int(c),int(d)],
                                         int(e), [int(f),int(g),int(h)]))
        msg = HMTLprotocol.get_program_blink_msg(options.hmtladdress,
                                         options.output,
                                         int(a), [int(b),int(c),int(d)],
                                         int(e), [int(f),int(g),int(h)])
    elif (options.commandtype == "timedchange"):
        (a, b,c,d, e,f,g,) = options.commandvalue.split(",")
        print("Sending TIMED CHANGE message. Address=%d Output=%d change_period=%d start_value=%s stop_values=%s" % (options.hmtladdress, options.output, int(a), [int(b),int(c),int(d)],
                                                                                                          [int(e),int(f),int(g)]))
        msg = HMTLprotocol.get_program_timed_change_msg(options.hmtladdress,
                                        options.output,
                                        int(a),
                                        [int(b),int(c),int(d)],
                                        [int(e),int(f),int(g)])
    elif (options.commandtype == "levelvalue"):
        print("Sending LEVEL VALUE message. Address=%d Output=%d" % (options.hmtladdress, options.output))
        msg = HMTLprotocol.get_program_level_value_msg(options.hmtladdress,
                                                       options.output)
    elif (options.commandtype == "soundvalue"):
        print("Sending SOUND VALUE message. Address=%d Output=%d" % (options.hmtladdress, options.output))
        msg = HMTLprotocol.get_program_sound_value_msg(options.hmtladdress,
                                                       options.output)

    elif (options.commandtype == "none"):
        print("Sending NONE message.  Output=%d" % (options.output))
        msg = HMTLprotocol.get_program_none_msg(options.hmtladdress,
                                                options.output)
    elif (options.commandtype == "poll"):
        print("Sending poll message.  Address=%d" %
              (options.hmtladdress))
        msg = HMTLprotocol.get_poll_msg(options.hmtladdress)
        expect_response = True
    elif (options.commandtype == "setaddr"):
        (device_id, new_address) = options.commandvalue.split(",")
        print("Sending set address message.  Address=%d Device=%d NewAddress=%d" %
              (options.hmtladdress, int(device_id), int(new_address)))
        msg = HMTLprotocol.get_set_addr_msg(options.hmtladdress, 
                                            int(device_id), int(new_address))
    elif (options.commandtype == "fade"):
        (a, b,c,d, e,f,g,) = options.commandvalue.split(",")
        print("Sending FADE message. Address=%d Output=%d fade_period=%d start_value=%s stop_values=%s" % 
              (options.hmtladdress, options.output,
               int(a), 
               [int(b),int(c),int(d)],
               [int(e),int(f),int(g)]))
        msg = HMTLprotocol.get_program_fade_msg(options.hmtladdress,
                                        options.output,
                                        int(a),
                                        [int(b),int(c),int(d)],
                                        [int(e),int(f),int(g)])


    if (msg != None):
        starttime = time.time()
        client.send_and_ack(msg, expect_response)
        endtime = time.time()
        print("Sent and acked in %.6fs" % (endtime - starttime))

    if (options.killserver):
        # Send an exit message to the server
        print("Sending EXIT message to server")
        client.send_exit()

    client.close()

    print("Done.")
    exit(0)