diff --git a/.vscode/settings.json b/.vscode/settings.json index 96229f9..2f961ec 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,8 +1,8 @@ { "python.formatting.provider": "black", - "python.linting.flake8Enabled": true, - "python.linting.mypyEnabled": true, - "python.linting.banditEnabled": true, + "python.linting.flake8Enabled": false, + "python.linting.mypyEnabled": false, + "python.linting.banditEnabled": false, "mypy.configFile": ".mypy.ini", "python.testing.unittestArgs": [ "-v", @@ -12,5 +12,8 @@ "test_*.py" ], "python.testing.pytestEnabled": false, - "python.testing.unittestEnabled": true + "python.testing.unittestEnabled": true, + "python.linting.enabled": true, + "python.linting.pylintEnabled": false, + "python.linting.prospectorEnabled": true } diff --git a/src/pydrs/base.py b/src/pydrs/base.py index a6315fd..b7fcc53 100644 --- a/src/pydrs/base.py +++ b/src/pydrs/base.py @@ -21,8 +21,29 @@ uint32_to_hex, ) +from .consts import ( + COM_FUNCTION, + COM_READ_VAR, + COM_REQUEST_CURVE, + COM_SEND_WFM_REF, + COM_WRITE_VAR, + NUM_MAX_COEFFS_DSP, + UDC_FIRMWARE_VERSION, + DP_MODULE_MAX_COEFF, + WRITE_DOUBLE_SIZE_PAYLOAD, + WRITE_FLOAT_SIZE_PAYLOAD, + type_size, + type_format, + size_curve_block, + num_coeffs_dsp_modules, + num_dsp_modules, + dsp_classes_names, + num_blocks_curves_fax, + num_blocks_curves_fbp, +) + # common_list -from .constants.common_list import ( +from .consts.common_list import ( list_ps_models, list_common_vars, list_curv, @@ -33,14 +54,14 @@ ) # fbp_const_list -from .constants.fbp_const_list import ( +from .consts.fbp_const_list import ( list_fbp_soft_interlocks, list_fbp_hard_interlocks, list_fbp_dclink_hard_interlocks, ) # fac_const_list -from .constants.fac_const_list import ( +from .consts.fac_const_list import ( list_fac_acdc_soft_interlocks, list_fac_acdc_hard_interlocks, list_fac_acdc_iib_is_interlocks, @@ -76,7 +97,7 @@ ) # fap_const_list -from .constants.fap_const_list import ( +from .consts.fap_const_list import ( list_fap_soft_interlocks, list_fap_hard_interlocks, list_fap_iib_interlocks, @@ -91,88 +112,12 @@ list_fap_225A_hard_interlocks, ) -UDC_FIRMWARE_VERSION = "0.42 2021-05-06" - -type_format = { - "uint8_t": "BBHBB", - "uint16_t": "BBHHB", - "uint32_t": "BBHIB", - "float": "BBHfB", -} - -bytes_format = {"Uint16": "H", "Uint32": "L", "Uint64": "Q", "float": "f"} - -type_size = {"uint8_t": 6, "uint16_t": 7, "uint32_t": 9, "float": 9} - -num_blocks_curves_fbp = [4, 4, 4] -num_blocks_curves_fax = [16, 16, 16] -size_curve_block = [1024, 1024, 1024] - -ufm_offset = { - "serial": 0, - "calibdate": 4, - "variant": 9, - "rburden": 10, - "calibtemp": 12, - "vin_gain": 14, - "vin_offset": 16, - "iin_gain": 18, - "iin_offset": 20, - "vref_p": 22, - "vref_n": 24, - "gnd": 26, -} - -hradc_variant = [ - "HRADC-FBP", - "HRADC-FAX-A", - "HRADC-FAX-B", - "HRADC-FAX-C", - "HRADC-FAX-D", -] - -hradc_input_types = [ - "GND", - "Vref_bipolar_p", - "Vref_bipolar_n", - "Temp", - "Vin_bipolar_p", - "Vin_bipolar_n", - "Iin_bipolar_p", - "Iin_bipolar_n", -] - -NUM_MAX_COEFFS_DSP = 12 -num_dsp_classes = 7 -num_dsp_modules = [4, 4, 4, 6, 8, 4, 2, 2] -num_coeffs_dsp_modules = [0, 1, 1, 4, 8, 16, 2] -dsp_classes_names = [ - "DSP_Error", - "DSP_SRLim", - "DSP_LPF", - "DSP_PI", - "DSP_IIR_2P2Z", - "DSP_IIR_3P3Z", - "DSP_VdcLink_FeedForward", - "DSP_Vect_Product", -] - logger = get_logger(name=__file__) class BaseDRS(object): def __init__(self): - self.master_add = "\x00" self.slave_add = "\x01" - self.b_cast_add = "\xFF" - self.com_write_var = "\x20" - self.write_float_size_payload = "\x00\x05" - self.write_double_size_payload = "\x00\x03" - self.com_read_var = "\x10\x00\x01" - self.com_request_curve = "\x40" - self.com_send_wfm_ref = "\x41" - self.com_function = "\x50" - self.dp_module_max_coeff = 16 print( "\n pyDRS - compatible UDC firmware version: " + UDC_FIRMWARE_VERSION + "\n" @@ -223,7 +168,7 @@ def timeout(self, new_timeout: float): # Função de leitura de variável def read_var(self, var_id: str, size: int): self._reset_input_buffer() - return self._transfer(self.com_read_var + var_id, size) + return self._transfer(COM_READ_VAR + var_id, size) """ ====================================================================== @@ -235,32 +180,28 @@ def read_var(self, var_id: str, size: int): def turn_on(self): payload_size = size_to_hex(1) # Payload: ID send_packet = ( - self.com_function + payload_size + index_to_hex(list_func.index("turn_on")) + COM_FUNCTION + payload_size + index_to_hex(list_func.index("turn_on")) ) return self._transfer(send_packet, 6) def turn_off(self): payload_size = size_to_hex(1) # Payload: ID send_packet = ( - self.com_function + payload_size + index_to_hex(list_func.index("turn_off")) + COM_FUNCTION + payload_size + index_to_hex(list_func.index("turn_off")) ) return self._transfer(send_packet, 6) def open_loop(self): payload_size = size_to_hex(1) # Payload: ID send_packet = ( - self.com_function - + payload_size - + index_to_hex(list_func.index("open_loop")) + COM_FUNCTION + payload_size + index_to_hex(list_func.index("open_loop")) ) return self._transfer(send_packet, 6) def closed_loop(self): payload_size = size_to_hex(1) # Payload: ID send_packet = ( - self.com_function - + payload_size - + index_to_hex(list_func.index("closed_loop")) + COM_FUNCTION + payload_size + index_to_hex(list_func.index("closed_loop")) ) return self._transfer(send_packet, 6) @@ -268,7 +209,7 @@ def reset_interlocks(self): """Resets interlocks on connected DRS device""" payload_size = size_to_hex(1) # Payload: ID send_packet = ( - self.com_function + COM_FUNCTION + payload_size + index_to_hex(list_func.index("reset_interlocks")) ) @@ -311,7 +252,7 @@ def set_slowref(self, setpoint): payload_size = size_to_hex(1 + 4) # Payload: ID + iSlowRef hex_setpoint = float_to_hex(setpoint) send_packet = ( - self.com_function + COM_FUNCTION + payload_size + index_to_hex(list_func.index("set_slowref")) + hex_setpoint @@ -325,7 +266,7 @@ def set_slowref_fbp(self, iRef1=0, iRef2=0, iRef3=0, iRef4=0): hex_iRef3 = float_to_hex(iRef3) hex_iRef4 = float_to_hex(iRef4) send_packet = ( - self.com_function + COM_FUNCTION + payload_size + index_to_hex(list_func.index("set_slowref_fbp")) + hex_iRef1 @@ -339,7 +280,7 @@ def set_slowref_readback_mon(self, setpoint): payload_size = size_to_hex(1 + 4) # Payload: ID + iSlowRef hex_setpoint = float_to_hex(setpoint) send_packet = ( - self.com_function + COM_FUNCTION + payload_size + index_to_hex(list_func.index("set_slowref_readback_mon")) + hex_setpoint @@ -355,7 +296,7 @@ def set_slowref_fbp_readback_mon(self, iRef1=0, iRef2=0, iRef3=0, iRef4=0): hex_iRef3 = float_to_hex(iRef3) hex_iRef4 = float_to_hex(iRef4) send_packet = ( - self.com_function + COM_FUNCTION + payload_size + index_to_hex(list_func.index("set_slowref_fbp_readback_mon")) + hex_iRef1 @@ -374,7 +315,7 @@ def set_slowref_readback_ref(self, setpoint): payload_size = size_to_hex(1 + 4) # Payload: ID + iSlowRef hex_setpoint = float_to_hex(setpoint) send_packet = ( - self.com_function + COM_FUNCTION + payload_size + index_to_hex(list_func.index("set_slowref_readback_ref")) + hex_setpoint @@ -390,7 +331,7 @@ def set_slowref_fbp_readback_ref(self, iRef1=0, iRef2=0, iRef3=0, iRef4=0): hex_iRef3 = float_to_hex(iRef3) hex_iRef4 = float_to_hex(iRef4) send_packet = ( - self.com_function + COM_FUNCTION + payload_size + index_to_hex(list_func.index("set_slowref_fbp_readback_ref")) + hex_iRef1 @@ -417,7 +358,7 @@ def set_param(self, param_id, n, value) -> bytes: hex_n = double_to_hex(n) hex_value = float_to_hex(value) send_packet = ( - self.com_function + COM_FUNCTION + payload_size + index_to_hex(list_func.index("set_param")) + hex_id @@ -440,7 +381,7 @@ def get_param(self, param_id, n=0): hex_id = double_to_hex(param_id) hex_n = double_to_hex(n) send_packet = ( - self.com_function + COM_FUNCTION + payload_size + index_to_hex(list_func.index("get_param")) + hex_id @@ -466,7 +407,7 @@ def save_param_eeprom(self, param_id, n=0, type_memory=2): hex_n = double_to_hex(n) hex_type = double_to_hex(type_memory) send_packet = ( - self.com_function + COM_FUNCTION + payload_size + index_to_hex(list_func.index("save_param_eeprom")) + hex_id @@ -489,7 +430,7 @@ def load_param_eeprom(self, param_id, n=0, type_memory=2): hex_n = double_to_hex(n) hex_type = double_to_hex(type_memory) send_packet = ( - self.com_function + COM_FUNCTION + payload_size + index_to_hex(list_func.index("load_param_eeprom")) + hex_id @@ -505,7 +446,7 @@ def save_param_bank(self, type_memory=2): payload_size = size_to_hex(1 + 2) # Payload: ID + memory type hex_type = double_to_hex(type_memory) send_packet = ( - self.com_function + COM_FUNCTION + payload_size + index_to_hex(list_func.index("save_param_bank")) + hex_type @@ -516,7 +457,7 @@ def load_param_bank(self, type_memory=2): payload_size = size_to_hex(1 + 2) # Payload: ID + memory type hex_type = double_to_hex(type_memory) send_packet = ( - self.com_function + COM_FUNCTION + payload_size + index_to_hex(list_func.index("load_param_bank")) + hex_type @@ -605,7 +546,7 @@ def set_dsp_coeffs( hex_dsp_id = double_to_hex(dsp_id) hex_coeffs = self.float_list_to_hex(coeffs_list_full) send_packet = ( - self.com_function + COM_FUNCTION + payload_size + index_to_hex(list_func.index("set_dsp_coeffs")) + hex_dsp_class @@ -620,7 +561,7 @@ def get_dsp_coeff(self, dsp_class, dsp_id, coeff): hex_dsp_id = double_to_hex(dsp_id) hex_coeff = double_to_hex(coeff) send_packet = ( - self.com_function + COM_FUNCTION + payload_size + index_to_hex(list_func.index("get_dsp_coeff")) + hex_dsp_class @@ -639,7 +580,7 @@ def save_dsp_coeffs_eeprom(self, dsp_class, dsp_id, type_memory=2) -> bytes: hex_dsp_id = double_to_hex(dsp_id) hex_type = double_to_hex(type_memory) send_packet = ( - self.com_function + COM_FUNCTION + payload_size + index_to_hex(list_func.index("save_dsp_coeffs_eeprom")) + hex_dsp_class @@ -654,7 +595,7 @@ def load_dsp_coeffs_eeprom(self, dsp_class, dsp_id, type_memory=2): hex_dsp_id = double_to_hex(dsp_id) hex_type = double_to_hex(type_memory) send_packet = ( - self.com_function + COM_FUNCTION + payload_size + index_to_hex(list_func.index("load_dsp_coeffs_eeprom")) + hex_dsp_class @@ -667,7 +608,7 @@ def save_dsp_modules_eeprom(self, type_memory=2) -> bytes: payload_size = size_to_hex(1 + 2) # Payload: ID + memory type hex_type = double_to_hex(type_memory) send_packet = ( - self.com_function + COM_FUNCTION + payload_size + index_to_hex(list_func.index("save_dsp_modules_eeprom")) + hex_type @@ -678,7 +619,7 @@ def load_dsp_modules_eeprom(self, type_memory=2) -> bytes: payload_size = size_to_hex(1 + 2) # Payload: ID + memory type hex_type = double_to_hex(type_memory) send_packet = ( - self.com_function + COM_FUNCTION + payload_size + index_to_hex(list_func.index("load_dsp_modules_eeprom")) + hex_type @@ -692,15 +633,13 @@ def reset_udc(self): if reply == "Y" or reply == "y": payload_size = size_to_hex(1) # Payload: ID send_packet = ( - self.com_function - + payload_size - + index_to_hex(list_func.index("reset_udc")) + COM_FUNCTION + payload_size + index_to_hex(list_func.index("reset_udc")) ) self._transfer_write(send_packet) def run_bsmp_func(self, id_func, print_msg=0) -> bytes: payload_size = size_to_hex(1) # Payload: ID - send_packet = self.com_function + payload_size + index_to_hex(id_func) + send_packet = COM_FUNCTION + payload_size + index_to_hex(id_func) reply_msg = self._transfer(send_packet, 6) if print_msg: print(reply_msg) @@ -726,7 +665,7 @@ def cfg_source_scope(self, p_source): payload_size = size_to_hex(1 + 4) # Payload: ID + p_source hex_op_mode = uint32_to_hex(p_source) send_packet = ( - self.com_function + COM_FUNCTION + payload_size + index_to_hex(list_func.index("cfg_source_scope")) + hex_op_mode @@ -737,7 +676,7 @@ def cfg_freq_scope(self, freq): payload_size = size_to_hex(1 + 4) # Payload: ID + freq hex_op_mode = float_to_hex(freq) send_packet = ( - self.com_function + COM_FUNCTION + payload_size + index_to_hex(list_func.index("cfg_freq_scope")) + hex_op_mode @@ -748,7 +687,7 @@ def cfg_duration_scope(self, duration): payload_size = size_to_hex(1 + 4) # Payload: ID + duration hex_op_mode = float_to_hex(duration) send_packet = ( - self.com_function + COM_FUNCTION + payload_size + index_to_hex(list_func.index("cfg_duration_scope")) + hex_op_mode @@ -758,18 +697,14 @@ def cfg_duration_scope(self, duration): def enable_scope(self): payload_size = size_to_hex(1) # Payload: ID send_packet = ( - self.com_function - + payload_size - + index_to_hex(list_func.index("enable_scope")) + COM_FUNCTION + payload_size + index_to_hex(list_func.index("enable_scope")) ) return self._transfer(send_packet, 6) def disable_scope(self): payload_size = size_to_hex(1) # Payload: ID send_packet = ( - self.com_function - + payload_size - + index_to_hex(list_func.index("disable_scope")) + COM_FUNCTION + payload_size + index_to_hex(list_func.index("disable_scope")) ) return self._transfer(send_packet, 6) @@ -784,9 +719,7 @@ def get_scope_vars(self): def sync_pulse(self): payload_size = size_to_hex(1) # Payload: ID send_packet = ( - self.com_function - + payload_size - + index_to_hex(list_func.index("sync_pulse")) + COM_FUNCTION + payload_size + index_to_hex(list_func.index("sync_pulse")) ) return self._transfer(send_packet, 6) @@ -794,7 +727,7 @@ def select_op_mode(self, op_mode): payload_size = size_to_hex(1 + 2) # Payload: ID + enable hex_op_mode = double_to_hex(list_op_mode.index(op_mode)) send_packet = ( - self.com_function + COM_FUNCTION + payload_size + index_to_hex(list_func.index("select_op_mode")) + hex_op_mode @@ -805,7 +738,7 @@ def set_serial_termination(self, term_enable): payload_size = size_to_hex(1 + 2) # Payload: ID + enable hex_enable = double_to_hex(term_enable) send_packet = ( - self.com_function + COM_FUNCTION + payload_size + index_to_hex(list_func.index("set_serial_termination")) + hex_enable @@ -816,7 +749,7 @@ def set_command_interface(self, interface): payload_size = size_to_hex(1 + 2) # Payload: ID + enable hex_interface = double_to_hex(interface) send_packet = ( - self.com_function + COM_FUNCTION + payload_size + index_to_hex(list_func.index("set_command_interface")) + hex_interface @@ -827,7 +760,7 @@ def unlock_udc(self, password): payload_size = size_to_hex(1 + 2) # Payload: ID + password hex_password = double_to_hex(password) send_packet = ( - self.com_function + COM_FUNCTION + payload_size + index_to_hex(list_func.index("unlock_udc")) + hex_password @@ -838,7 +771,7 @@ def lock_udc(self, password): payload_size = size_to_hex(1 + 2) # Payload: ID + password hex_password = double_to_hex(password) send_packet = ( - self.com_function + COM_FUNCTION + payload_size + index_to_hex(list_func.index("lock_udc")) + hex_password @@ -848,7 +781,7 @@ def lock_udc(self, password): def reset_counters(self): payload_size = size_to_hex(1) # Payload: ID send_packet = ( - self.com_function + COM_FUNCTION + payload_size + index_to_hex(list_func.index("reset_counters")) ) @@ -868,7 +801,7 @@ def cfg_siggen( hex_aux2 = float_to_hex(aux2) hex_aux3 = float_to_hex(aux3) send_packet = ( - self.com_function + COM_FUNCTION + payload_size + index_to_hex(list_func.index("cfg_siggen")) + hex_sig_type @@ -889,7 +822,7 @@ def set_siggen(self, freq, amplitude, offset): hex_amplitude = float_to_hex(amplitude) hex_offset = float_to_hex(offset) send_packet = ( - self.com_function + COM_FUNCTION + payload_size + index_to_hex(list_func.index("set_siggen")) + hex_freq @@ -901,16 +834,14 @@ def set_siggen(self, freq, amplitude, offset): def enable_siggen(self): payload_size = size_to_hex(1) # Payload: ID send_packet = ( - self.com_function - + payload_size - + index_to_hex(list_func.index("enable_siggen")) + COM_FUNCTION + payload_size + index_to_hex(list_func.index("enable_siggen")) ) return self._transfer(send_packet, 6) def disable_siggen(self): payload_size = size_to_hex(1) # Payload: ID send_packet = ( - self.com_function + COM_FUNCTION + payload_size + index_to_hex(list_func.index("disable_siggen")) ) @@ -926,7 +857,7 @@ def cfg_wfmref(self, idx, sync_mode, frequency, gain=1, offset=0): hex_gain = float_to_hex(gain) hex_offset = float_to_hex(offset) send_packet = ( - self.com_function + COM_FUNCTION + payload_size + index_to_hex(list_func.index("cfg_wfmref")) + hex_idx @@ -941,7 +872,7 @@ def select_wfmref(self, idx): payload_size = size_to_hex(1 + 2) # Payload: ID + idx hex_idx = double_to_hex(idx) send_packet = ( - self.com_function + COM_FUNCTION + payload_size + index_to_hex(list_func.index("select_wfmref")) + hex_idx @@ -951,9 +882,7 @@ def select_wfmref(self, idx): def reset_wfmref(self): payload_size = size_to_hex(1) # Payload: ID send_packet = ( - self.com_function - + payload_size - + index_to_hex(list_func.index("reset_wfmref")) + COM_FUNCTION + payload_size + index_to_hex(list_func.index("reset_wfmref")) ) return self._transfer(send_packet, 6) @@ -1055,8 +984,8 @@ def Write_sigGen_Freq(self, float_value): # TODO: Fix method name hex_float = float_to_hex(float_value) send_packet = ( - self.com_write_var - + self.write_float_size_payload + COM_WRITE_VAR + + WRITE_FLOAT_SIZE_PAYLOAD + index_to_hex(list_common_vars.index("sigGen_Freq")) + hex_float ) @@ -1066,8 +995,8 @@ def Write_sigGen_Amplitude(self, float_value): # TODO: Fix method name hex_float = float_to_hex(float_value) send_packet = ( - self.com_write_var - + self.write_float_size_payload + COM_WRITE_VAR + + WRITE_FLOAT_SIZE_PAYLOAD + index_to_hex(list_common_vars.index("sigGen_Amplitude")) + hex_float ) @@ -1077,8 +1006,8 @@ def Write_sigGen_Offset(self, float_value): # TODO: Fix method name hex_float = float_to_hex(float_value) send_packet = ( - self.com_write_var - + self.write_float_size_payload + COM_WRITE_VAR + + WRITE_FLOAT_SIZE_PAYLOAD + index_to_hex(list_common_vars.index("sigGen_Offset")) + hex_float ) @@ -1088,8 +1017,8 @@ def Write_sigGen_Aux(self, float_value): # TODO: Fix method name hex_float = float_to_hex(float_value) send_packet = ( - self.com_write_var - + self.write_float_size_payload + COM_WRITE_VAR + + WRITE_FLOAT_SIZE_PAYLOAD + index_to_hex(list_common_vars.index("sigGen_Aux")) + hex_float ) @@ -1099,8 +1028,8 @@ def Write_dp_ID(self, double_value): # TODO: Fix method name hex_double = double_to_hex(double_value) send_packet = ( - self.com_write_var - + self.write_double_size_payload + COM_WRITE_VAR + + WRITE_DOUBLE_SIZE_PAYLOAD + index_to_hex(list_common_vars.index("dp_ID")) + hex_double ) @@ -1110,8 +1039,8 @@ def Write_dp_Class(self, double_value): # TODO: Fix method name hex_double = double_to_hex(double_value) send_packet = ( - self.com_write_var - + self.write_double_size_payload + COM_WRITE_VAR + + WRITE_DOUBLE_SIZE_PAYLOAD + index_to_hex(list_common_vars.index("dp_Class")) + hex_double ) @@ -1125,7 +1054,7 @@ def Write_dp_Coeffs(self, list_float): # while(len(list_full) < self.dp_module_max_coeff): # list_full.append(0) - list_full = [0 for i in range(self.dp_module_max_coeff)] + list_full = [0 for i in range(DP_MODULE_MAX_COEFF)] list_full[: len(list_float)] = list_float[:] for float_value in list_full: @@ -1133,10 +1062,10 @@ def Write_dp_Coeffs(self, list_float): hex_float_list.append(hex_float) str_float_list = "".join(hex_float_list) payload_size = size_to_hex( - 1 + 4 * self.dp_module_max_coeff + 1 + 4 * DP_MODULE_MAX_COEFF ) # Payload: ID + 16floats send_packet = ( - self.com_write_var + COM_WRITE_VAR + payload_size + index_to_hex(list_common_vars.index("dp_Coeffs")) + str_float_list @@ -1158,7 +1087,7 @@ def send_wfmref_curve(self, block_idx, data): payload_size = struct.pack(">H", (len(val) * 4) + 3).decode("ISO-8859-1") curva_hex = "".join(val) send_packet = ( - self.com_send_wfm_ref + COM_SEND_WFM_REF + payload_size + index_to_hex(list_curv.index("wfmRef_Curve")) + block_hex @@ -1170,7 +1099,7 @@ def recv_wfmref_curve(self, block_idx): block_hex = struct.pack(">H", block_idx).decode("ISO-8859-1") payload_size = size_to_hex(1 + 2) # Payload: ID+Block_index send_packet = ( - self.com_request_curve + COM_REQUEST_CURVE + payload_size + index_to_hex(list_curv.index("wfmRef_Curve")) + block_hex @@ -1186,7 +1115,7 @@ def recv_samples_buffer(self): block_hex = struct.pack(">H", 0).decode("ISO-8859-1") payload_size = size_to_hex(1 + 2) # Payload: ID+Block_index send_packet = ( - self.com_request_curve + COM_REQUEST_CURVE + payload_size + index_to_hex(list_curv.index("samplesBuffer")) + block_hex @@ -1209,7 +1138,7 @@ def send_full_wfmref_curve(self, block_idx, data): payload_size = struct.pack(">H", (len(val) * 4) + 3).decode("ISO-8859-1") curva_hex = "".join(val) send_packet = ( - self.com_send_wfm_ref + COM_SEND_WFM_REF + payload_size + index_to_hex(list_curv.index("fullwfmRef_Curve")) + block_hex @@ -1221,7 +1150,7 @@ def recv_full_wfmref_curve(self, block_idx): block_hex = struct.pack(">H", block_idx).decode("ISO-8859-1") payload_size = size_to_hex(1 + 2) # Payload: ID+Block_index send_packet = ( - self.com_request_curve + COM_REQUEST_CURVE + payload_size + index_to_hex(list_curv.index("fullwfmRef_Curve")) + block_hex @@ -1236,7 +1165,7 @@ def recv_samples_buffer_blocks(self, block_idx): block_hex = struct.pack(">H", block_idx).decode("ISO-8859-1") payload_size = size_to_hex(1 + 2) # Payload: ID+Block_index send_packet = ( - self.com_request_curve + COM_REQUEST_CURVE + payload_size + index_to_hex(list_curv.index("samplesBuffer_blocks")) + block_hex @@ -1265,7 +1194,7 @@ def read_curve_block(self, curve_id, block_id): block_hex = struct.pack(">H", block_id).decode("ISO-8859-1") payload_size = size_to_hex(1 + 2) # Payload: curve_id + block_id send_packet = ( - self.com_request_curve + payload_size + index_to_hex(curve_id) + block_hex + COM_REQUEST_CURVE + payload_size + index_to_hex(curve_id) + block_hex ) # t0 = time.time() self._reset_input_buffer() @@ -1288,7 +1217,7 @@ def write_curve_block(self, curve_id, block_id, data): payload_size = struct.pack(">H", (len(val) * 4) + 3).decode("ISO-8859-1") curva_hex = "".join(val) send_packet = ( - self.com_send_wfm_ref + COM_SEND_WFM_REF + payload_size + index_to_hex(curve_id) + block_hex diff --git a/src/pydrs/constants/__init__.py b/src/pydrs/constants/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/src/pydrs/consts/__init__.py b/src/pydrs/consts/__init__.py index 8d15b2e..a903acd 100644 --- a/src/pydrs/consts/__init__.py +++ b/src/pydrs/consts/__init__.py @@ -1,3 +1,48 @@ +ETH_ANSWER_ERR = 22 +DP_MODULE_MAX_COEFF = 16 +NUM_MAX_COEFFS_DSP = 12 +NUM_DSP_CLASSES = 7 + +ETH_CMD_REQUEST = b"\x11" +COM_FUNCTION = "\x50" +COM_WRITE_VAR = "\x20" +WRITE_FLOAT_SIZE_PAYLOAD = "\x00\x05" +WRITE_DOUBLE_SIZE_PAYLOAD = "\x00\x03" +COM_READ_VAR = "\x10\x00\x01" +COM_REQUEST_CURVE = "\x40" +COM_SEND_WFM_REF = "\x41" + +UDC_FIRMWARE_VERSION = "0.42 2021-05-06" + +ufm_offset = { + "serial": 0, + "calibdate": 4, + "variant": 9, + "rburden": 10, + "calibtemp": 12, + "vin_gain": 14, + "vin_offset": 16, + "iin_gain": 18, + "iin_offset": 20, + "vref_p": 22, + "vref_n": 24, + "gnd": 26, +} + +type_format = { + "uint8_t": "BBHBB", + "uint16_t": "BBHHB", + "uint32_t": "BBHIB", + "float": "BBHfB", +} + +bytes_format = {"Uint16": "H", "Uint32": "L", "Uint64": "Q", "float": "f"} + +type_size = {"uint8_t": 6, "uint16_t": 7, "uint32_t": 9, "float": 9} + +num_blocks_curves_fax = [16, 16, 16] +size_curve_block = [1024, 1024, 1024] + ListVar = [ "iLoad1", "iLoad2", @@ -46,5 +91,37 @@ "wfmRef_SyncMode", ] -ETH_ANSWER_ERR = 22 -ETH_CMD_REQUEST = b"\x11" + +hradc_variant = [ + "HRADC-FBP", + "HRADC-FAX-A", + "HRADC-FAX-B", + "HRADC-FAX-C", + "HRADC-FAX-D", +] + +hradc_input_types = [ + "GND", + "Vref_bipolar_p", + "Vref_bipolar_n", + "Temp", + "Vin_bipolar_p", + "Vin_bipolar_n", + "Iin_bipolar_p", + "Iin_bipolar_n", +] + +num_dsp_modules = [4, 4, 4, 6, 8, 4, 2, 2] +num_coeffs_dsp_modules = [0, 1, 1, 4, 8, 16, 2] +dsp_classes_names = [ + "DSP_Error", + "DSP_SRLim", + "DSP_LPF", + "DSP_PI", + "DSP_IIR_2P2Z", + "DSP_IIR_3P3Z", + "DSP_VdcLink_FeedForward", + "DSP_Vect_Product", +] + +num_blocks_curves_fbp = [4, 4, 4] diff --git a/src/pydrs/constants/common_list.py b/src/pydrs/consts/common_list.py similarity index 100% rename from src/pydrs/constants/common_list.py rename to src/pydrs/consts/common_list.py diff --git a/src/pydrs/constants/fac_const_list.py b/src/pydrs/consts/fac_const_list.py similarity index 100% rename from src/pydrs/constants/fac_const_list.py rename to src/pydrs/consts/fac_const_list.py diff --git a/src/pydrs/constants/fap_const_list.py b/src/pydrs/consts/fap_const_list.py similarity index 100% rename from src/pydrs/constants/fap_const_list.py rename to src/pydrs/consts/fap_const_list.py diff --git a/src/pydrs/constants/fbp_const_list.py b/src/pydrs/consts/fbp_const_list.py similarity index 100% rename from src/pydrs/constants/fbp_const_list.py rename to src/pydrs/consts/fbp_const_list.py diff --git a/src/pydrs/pydrs.py b/src/pydrs/pydrs.py index b090678..b3c2263 100644 --- a/src/pydrs/pydrs.py +++ b/src/pydrs/pydrs.py @@ -94,7 +94,7 @@ def _get_reply(self, size: int = None) -> bytes: data_size = self._parse_reply_size(self.socket.recv(5)) payload = b"" - if size is not None and data_size != size: + if size is not None and (data_size - 1) != size: raise RuntimeError( "Received {} bytes when {} were expected".format(data_size, size) )