def scan_every(client): modules = [] for address in range(0, 128): print("Polling address: %d" % (address)) msg = HMTLprotocol.get_poll_msg(address) ret = client.send_and_ack(msg, True) if ret: handle_poll_resp(ret, modules) else: print("No response from: %d" % (address)) return modules
def scan_broadcast(client): modules = [] msg = HMTLprotocol.get_poll_msg(HMTLprotocol.BROADCAST) ret = client.send_and_ack(msg, False) while True: msg = client.get_response_data() if msg == None: break handle_poll_resp(msg, modules) return modules
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)