# Python Test Scripts for Controlling Kirdy # Kirdy is written to be controlled via a json object based on miniconf rust crate # Json Field: # "rev": hw_rev # "laser_diode_cmd / thermostat_cmd": Check cmd_handler.rs for the list of cmds # "data_f32": Optional f32 Data field depending on cmd # "data_f64": Optional f64 Data field depending on cmd import socket import json import time # Kirdy IP and Port Number HOST = "192.168.1.132" PORT = 1337 ld_cmd = { "rev": 3, "laser_diode_cmd": "SetI", "data_f64": 0.0, } tec_power_down = { "rev": 3, "thermostat_cmd": "PowerDown", } tec_set_sh_t0_cmd = { "rev": 3, "thermostat_cmd": "SetShT0", "data_f64": 25.0, } tec_set_sh_r0_cmd = { "rev": 3, "thermostat_cmd": "SetShR0", "data_f64": 10.0 * 1000, } tec_set_sh_beta_cmd = { "rev": 3, "thermostat_cmd": "SetShBeta", "data_f64": 3900.0, } tec_set_temperature_setpoint_cmd = { "rev": 3, "thermostat_cmd": "SetTemperatureSetpoint", "data_f64": 45.0, } tec_set_pid_kp_cmd = { "rev": 3, "thermostat_cmd": "SetPidKp", "data_f64": 1.0, } tec_set_pid_ki_cmd = { "rev": 3, "thermostat_cmd": "SetPidKi", "data_f64": 0.01, } tec_set_pid_kd_cmd = { "rev": 3, "thermostat_cmd": "SetPidKd", "data_f64": 0.0, } tec_set_pid_out_min_cmd = { "rev": 3, "thermostat_cmd": "SetPidOutMin", "data_f64": -1.0, } tec_set_pid_out_max_cmd = { "rev": 3, "thermostat_cmd": "SetPidOutMax", "data_f64": 1.0, } tec_power_up = { "rev": 3, "thermostat_cmd": "PowerUp", } # Current version of cmd_handler cannot service multiple cmds in the same eth buffer delay = 0.25 with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: s.connect((HOST, PORT)) s.send(bytes(json.dumps(tec_power_down), "UTF-8")) time.sleep(delay) s.send(bytes(json.dumps(tec_set_sh_t0_cmd), "UTF-8")) time.sleep(delay) s.send(bytes(json.dumps(tec_set_sh_r0_cmd), "UTF-8")) time.sleep(delay) s.send(bytes(json.dumps(tec_set_sh_beta_cmd), "UTF-8")) time.sleep(delay) s.send(bytes(json.dumps(tec_set_temperature_setpoint_cmd), "UTF-8")) time.sleep(delay) s.send(bytes(json.dumps(tec_set_pid_kp_cmd), "UTF-8")) time.sleep(delay) s.send(bytes(json.dumps(tec_set_pid_ki_cmd), "UTF-8")) time.sleep(delay) s.send(bytes(json.dumps(tec_set_pid_kd_cmd), "UTF-8")) time.sleep(delay) s.send(bytes(json.dumps(tec_power_up), "UTF-8")) print("press enter to force thermostat to stop") input() s.send(bytes(json.dumps(tec_power_down), "UTF-8"))