diff --git a/software/energy_manager.ini b/software/energy_manager.ini index 415c8dd38..41033be3d 100644 --- a/software/energy_manager.ini +++ b/software/energy_manager.ini @@ -78,6 +78,7 @@ custom_frontend_modules = Device Name Energy Manager EM V1 Power Manager + Modbus TCP Client Meters Meters EM Meters API diff --git a/software/energy_manager_v2.ini b/software/energy_manager_v2.ini index 94003ac15..f806eed9f 100644 --- a/software/energy_manager_v2.ini +++ b/software/energy_manager_v2.ini @@ -78,6 +78,7 @@ custom_frontend_modules = Device Name Energy Manager EM V2 Power Manager + Modbus TCP Client Meters Meters EM Meters API diff --git a/software/pio_hooks.py b/software/pio_hooks.py index 49f1a8e49..e9b3b2170 100644 --- a/software/pio_hooks.py +++ b/software/pio_hooks.py @@ -474,28 +474,51 @@ def hyphenate_translation(translation, parent_key=None, lang=None): def repair_rtc_dir(): path = os.path.abspath("src/modules/rtc") - try: - os.remove(os.path.join(path, "real_time_clock_v2_bricklet_firmware_bin.digest")) - os.remove(os.path.join(path, "real_time_clock_v2_bricklet_firmware_bin.embedded.cpp")) - os.remove(os.path.join(path, "real_time_clock_v2_bricklet_firmware_bin.embedded.h")) - except: - pass + for name in ["real_time_clock_v2_bricklet_firmware_bin.digest", + "real_time_clock_v2_bricklet_firmware_bin.embedded.cpp", + "real_time_clock_v2_bricklet_firmware_bin.embedded.h"]: + try: + os.remove(os.path.join(path, name)) + except FileNotFoundError: + pass def repair_firmware_update_dir(): path = os.path.abspath("src/modules/firmware_update") - try: - os.remove(os.path.join(path, "recovery_html.digest")) - os.remove(os.path.join(path, "recovery_html.embedded.cpp")) - os.remove(os.path.join(path, "recovery_html.embedded.h")) - except: - pass + for name in ["recovery_html.digest", + "recovery_html.embedded.cpp", + "recovery_html.embedded.h", + "signature_public_key.embedded.cpp", + "signature_public_key.embedded.h"]: + try: + os.remove(os.path.join(path, name)) + except FileNotFoundError: + pass - try: - os.remove(os.path.join(path, "signature_public_key.embedded.cpp")) - os.remove(os.path.join(path, "signature_public_key.embedded.h")) - except: - pass +def repair_meters_modbus_tcp_dir(): + path = os.path.abspath("src/modules/meters_modbus_tcp") + + for name in ["modbus_register_type.enum.cpp", + "modbus_register_type.enum.h", + "modbus_register_address_mode.enum.cpp", + "modbus_register_address_mode.enum.h", + "Modbus Value Type.uint8.enum", + "modbus_value_type.enum.cpp", + "modbus_value_type.enum.h"]: + try: + os.remove(os.path.join(path, name)) + except FileNotFoundError: + pass + + path = os.path.abspath("web/src/modules/meters_modbus_tcp") + + for name in ["modbus_register_type.enum.ts", + "modbus_register_address_mode.enum.ts", + "modbus_value_type.enum.ts"]: + try: + os.remove(os.path.join(path, name)) + except FileNotFoundError: + pass def find_module_space(modules, name_space): index = 0 @@ -518,6 +541,7 @@ def main(): repair_rtc_dir() repair_firmware_update_dir() + repair_meters_modbus_tcp_dir() check_call([env.subst('$PYTHONEXE'), "-u", "update_packages.py"]) diff --git a/software/src/modules/meters_modbus_tcp/.gitignore b/software/src/modules/meters_modbus_tcp/.gitignore index 57f256a37..21081b72d 100644 --- a/software/src/modules/meters_modbus_tcp/.gitignore +++ b/software/src/modules/meters_modbus_tcp/.gitignore @@ -1,2 +1 @@ -Modbus Value Type.uint8.enum meters_modbus_tcp_defs.inc diff --git a/software/src/modules/meters_modbus_tcp/meter_modbus_tcp.cpp b/software/src/modules/meters_modbus_tcp/meter_modbus_tcp.cpp index 85d0c805d..a0b1f1dde 100644 --- a/software/src/modules/meters_modbus_tcp/meter_modbus_tcp.cpp +++ b/software/src/modules/meters_modbus_tcp/meter_modbus_tcp.cpp @@ -24,8 +24,8 @@ #include "event_log_prefix.h" #include "module_dependencies.h" -#include "modbus_tcp_tools.h" -#include "modbus_register_address_mode.enum.h" +#include "modules/modbus_tcp_client/modbus_tcp_tools.h" +#include "modules/modbus_tcp_client/modbus_register_address_mode.enum.h" #include "meters_modbus_tcp_defs.inc" #include "gcc_warnings.h" diff --git a/software/src/modules/meters_modbus_tcp/meter_modbus_tcp.h b/software/src/modules/meters_modbus_tcp/meter_modbus_tcp.h index 64d315b60..bc55b8daa 100644 --- a/software/src/modules/meters_modbus_tcp/meter_modbus_tcp.h +++ b/software/src/modules/meters_modbus_tcp/meter_modbus_tcp.h @@ -22,13 +22,13 @@ #include -#include "generic_modbus_tcp_client.h" +#include "modules/modbus_tcp_client/generic_modbus_tcp_client.h" #include "modules/meters/imeter.h" #include "modules/meters/meter_value_id.h" #include "config.h" #include "meters_modbus_tcp.h" -#include "modbus_register_type.enum.h" -#include "modbus_value_type.enum.h" +#include "modules/modbus_tcp_client/modbus_register_type.enum.h" +#include "modules/modbus_tcp_client/modbus_value_type.enum.h" #include "meter_modbus_tcp_table_id.enum.h" #include "sungrow_hybrid_inverter_virtual_meter.enum.h" #include "sungrow_string_inverter_virtual_meter.enum.h" diff --git a/software/src/modules/meters_modbus_tcp/meters_modbus_tcp.cpp b/software/src/modules/meters_modbus_tcp/meters_modbus_tcp.cpp index fca5f09e7..ad80a5374 100644 --- a/software/src/modules/meters_modbus_tcp/meters_modbus_tcp.cpp +++ b/software/src/modules/meters_modbus_tcp/meters_modbus_tcp.cpp @@ -26,7 +26,7 @@ #include "meter_modbus_tcp.h" #include "modules/meters/meter_value_id.h" #include "tools.h" -#include "modbus_register_address_mode.enum.h" +#include "modules/modbus_tcp_client/modbus_register_address_mode.enum.h" #include "gcc_warnings.h" diff --git a/software/src/modules/meters_modbus_tcp/prepare.py b/software/src/modules/meters_modbus_tcp/prepare.py index 02c330ac1..1311a08d0 100644 --- a/software/src/modules/meters_modbus_tcp/prepare.py +++ b/software/src/modules/meters_modbus_tcp/prepare.py @@ -18,37 +18,6 @@ from software import util -def make_modbus_value_type(register_count, is_signed, is_float, register_order_is_le): - assert 1 <= register_count <= 4, register_count - - # bit [0..2] bit [3] bit [4] bit [5] - return register_count | ((1 if is_signed else 0) << 3) | ((1 if is_float else 0) << 4) | ((1 if register_order_is_le else 0) << 5) - - -modbus_value_types = [ - ('None', 0), - ('U16', make_modbus_value_type(1, False, False, False)), - ('S16', make_modbus_value_type(1, True, False, False)), - ('U32BE', make_modbus_value_type(2, False, False, False)), - ('U32LE', make_modbus_value_type(2, False, False, True)), - ('S32BE', make_modbus_value_type(2, True, False, False)), - ('S32LE', make_modbus_value_type(2, True, False, True)), - ('F32BE', make_modbus_value_type(2, True, True, False)), - ('F32LE', make_modbus_value_type(2, True, True, True)), - ('U64BE', make_modbus_value_type(4, False, False, False)), - ('U64LE', make_modbus_value_type(4, False, False, True)), - ('S64BE', make_modbus_value_type(4, True, False, False)), - ('S64LE', make_modbus_value_type(4, True, False, True)), - ('F64BE', make_modbus_value_type(4, True, True, False)), - ('F64LE', make_modbus_value_type(4, True, True, True)), -] - -with open('Modbus Value Type.uint8.enum', 'w', encoding='utf-8') as f: - f.write('# WARNING: This file is generated\n') - - for item in modbus_value_types: - f.write(f'{item[0]} = {item[1]}\n') - specs = sungrow.specs + solarmax.specs + victron_energy.specs + deye.specs + alpha_ess.specs + shelly.specs + goodwe.specs \ + solax.specs + fronius.specs + hailei.specs + fox_ess.specs + siemens.specs + carlo_gavazzi.specs spec_values = [] diff --git a/software/src/modules/meters_sun_spec/meter_sun_spec.cpp b/software/src/modules/meters_sun_spec/meter_sun_spec.cpp index aa452ab09..abaebe835 100644 --- a/software/src/modules/meters_sun_spec/meter_sun_spec.cpp +++ b/software/src/modules/meters_sun_spec/meter_sun_spec.cpp @@ -21,7 +21,7 @@ #include "event_log_prefix.h" #include "module_dependencies.h" -#include "modules/meters_modbus_tcp/modbus_tcp_tools.h" +#include "modules/modbus_tcp_client/modbus_tcp_tools.h" #include "modules/meters_sun_spec/models/model_001.h" #include "gcc_warnings.h" diff --git a/software/src/modules/meters_sun_spec/meter_sun_spec.h b/software/src/modules/meters_sun_spec/meter_sun_spec.h index 7d9837caa..ed23b4e08 100644 --- a/software/src/modules/meters_sun_spec/meter_sun_spec.h +++ b/software/src/modules/meters_sun_spec/meter_sun_spec.h @@ -22,8 +22,8 @@ #include #include "modules/meters/imeter.h" -#include "modules/meters_modbus_tcp/generic_modbus_tcp_client.h" -#include "modules/meters_modbus_tcp/modbus_tcp_tools.h" +#include "modules/modbus_tcp_client/generic_modbus_tcp_client.h" +#include "modules/modbus_tcp_client/modbus_tcp_tools.h" #include "config.h" #include "model_parser.h" diff --git a/software/src/modules/meters_sun_spec/meters_sun_spec.h b/software/src/modules/meters_sun_spec/meters_sun_spec.h index fc8926606..266176fef 100644 --- a/software/src/modules/meters_sun_spec/meters_sun_spec.h +++ b/software/src/modules/meters_sun_spec/meters_sun_spec.h @@ -26,7 +26,7 @@ #include "module.h" #include "modules/meters/meter_generator.h" -#include "modules/meters_modbus_tcp/modbus_tcp_tools.h" +#include "modules/modbus_tcp_client/modbus_tcp_tools.h" #include "config.h" #if defined(__GNUC__) diff --git a/software/src/modules/modbus_tcp_client/.gitignore b/software/src/modules/modbus_tcp_client/.gitignore new file mode 100644 index 000000000..f03016426 --- /dev/null +++ b/software/src/modules/modbus_tcp_client/.gitignore @@ -0,0 +1 @@ +Modbus Value Type.uint8.enum diff --git a/software/src/modules/meters_modbus_tcp/Modbus Register Address Mode.uint8.enum b/software/src/modules/modbus_tcp_client/Modbus Register Address Mode.uint8.enum similarity index 100% rename from software/src/modules/meters_modbus_tcp/Modbus Register Address Mode.uint8.enum rename to software/src/modules/modbus_tcp_client/Modbus Register Address Mode.uint8.enum diff --git a/software/src/modules/meters_modbus_tcp/Modbus Register Type.uint8.enum b/software/src/modules/modbus_tcp_client/Modbus Register Type.uint8.enum similarity index 100% rename from software/src/modules/meters_modbus_tcp/Modbus Register Type.uint8.enum rename to software/src/modules/modbus_tcp_client/Modbus Register Type.uint8.enum diff --git a/software/src/modules/meters_modbus_tcp/generic_modbus_tcp_client.cpp b/software/src/modules/modbus_tcp_client/generic_modbus_tcp_client.cpp similarity index 100% rename from software/src/modules/meters_modbus_tcp/generic_modbus_tcp_client.cpp rename to software/src/modules/modbus_tcp_client/generic_modbus_tcp_client.cpp diff --git a/software/src/modules/meters_modbus_tcp/generic_modbus_tcp_client.h b/software/src/modules/modbus_tcp_client/generic_modbus_tcp_client.h similarity index 96% rename from software/src/modules/meters_modbus_tcp/generic_modbus_tcp_client.h rename to software/src/modules/modbus_tcp_client/generic_modbus_tcp_client.h index 0e4d0367f..c068aa53a 100644 --- a/software/src/modules/meters_modbus_tcp/generic_modbus_tcp_client.h +++ b/software/src/modules/modbus_tcp_client/generic_modbus_tcp_client.h @@ -22,7 +22,7 @@ #include #include -#include "modules/modbus_tcp_client/generic_tcp_client_pool_connector.h" +#include "generic_tcp_client_pool_connector.h" #include "modbus_register_type.enum.h" #include "tools.h" diff --git a/software/src/modules/meters_modbus_tcp/modbus_tcp_tools.cpp b/software/src/modules/modbus_tcp_client/modbus_tcp_tools.cpp similarity index 100% rename from software/src/modules/meters_modbus_tcp/modbus_tcp_tools.cpp rename to software/src/modules/modbus_tcp_client/modbus_tcp_tools.cpp diff --git a/software/src/modules/meters_modbus_tcp/modbus_tcp_tools.h b/software/src/modules/modbus_tcp_client/modbus_tcp_tools.h similarity index 100% rename from software/src/modules/meters_modbus_tcp/modbus_tcp_tools.h rename to software/src/modules/modbus_tcp_client/modbus_tcp_tools.h diff --git a/software/src/modules/modbus_tcp_client/prepare.py b/software/src/modules/modbus_tcp_client/prepare.py new file mode 100644 index 000000000..42c318d7b --- /dev/null +++ b/software/src/modules/modbus_tcp_client/prepare.py @@ -0,0 +1,37 @@ +import sys +import tinkerforge_util as tfutil + +tfutil.create_parent_module(__file__, 'software') + +from software import util + +def make_modbus_value_type(register_count, is_signed, is_float, register_order_is_le): + assert 1 <= register_count <= 4, register_count + + # bit [0..2] bit [3] bit [4] bit [5] + return register_count | ((1 if is_signed else 0) << 3) | ((1 if is_float else 0) << 4) | ((1 if register_order_is_le else 0) << 5) + + +modbus_value_types = [ + ('None', 0), + ('U16', make_modbus_value_type(1, False, False, False)), + ('S16', make_modbus_value_type(1, True, False, False)), + ('U32BE', make_modbus_value_type(2, False, False, False)), + ('U32LE', make_modbus_value_type(2, False, False, True)), + ('S32BE', make_modbus_value_type(2, True, False, False)), + ('S32LE', make_modbus_value_type(2, True, False, True)), + ('F32BE', make_modbus_value_type(2, True, True, False)), + ('F32LE', make_modbus_value_type(2, True, True, True)), + ('U64BE', make_modbus_value_type(4, False, False, False)), + ('U64LE', make_modbus_value_type(4, False, False, True)), + ('S64BE', make_modbus_value_type(4, True, False, False)), + ('S64LE', make_modbus_value_type(4, True, False, True)), + ('F64BE', make_modbus_value_type(4, True, True, False)), + ('F64LE', make_modbus_value_type(4, True, True, True)), +] + +with open('Modbus Value Type.uint8.enum', 'w', encoding='utf-8') as f: + f.write('# WARNING: This file is generated\n') + + for item in modbus_value_types: + f.write(f'{item[0]} = {item[1]}\n') diff --git a/software/warp.ini b/software/warp.ini index 0004e33ff..7cc23d055 100644 --- a/software/warp.ini +++ b/software/warp.ini @@ -78,6 +78,7 @@ custom_backend_modules = ESP32 Brick custom_frontend_modules = Device Name EVSE Common + Modbus TCP Client Meters Meters RS485 Bricklet Meters API diff --git a/software/warp2.ini b/software/warp2.ini index c3507137b..d6e6e195c 100644 --- a/software/warp2.ini +++ b/software/warp2.ini @@ -93,6 +93,7 @@ custom_backend_modules = ESP32 Ethernet Brick custom_frontend_modules = Device Name EVSE Common EVSE V2 + Modbus TCP Client Meters Meters EVSE V2 Meters API diff --git a/software/web/src/modules/meters_modbus_tcp/plugin_meters_config.tsx b/software/web/src/modules/meters_modbus_tcp/plugin_meters_config.tsx index 1a75313b9..d6e0a4a78 100644 --- a/software/web/src/modules/meters_modbus_tcp/plugin_meters_config.tsx +++ b/software/web/src/modules/meters_modbus_tcp/plugin_meters_config.tsx @@ -24,9 +24,9 @@ import { MeterClassID } from "../meters/meter_class_id.enum"; import { MeterConfig } from "../meters/types"; import { MeterValueIDSelector, get_meter_value_id_name } from "../meters_api/plugin_meters_config"; import { MeterModbusTCPTableID } from "./meter_modbus_tcp_table_id.enum"; -import { ModbusRegisterType } from "./modbus_register_type.enum"; -import { ModbusRegisterAddressMode } from "./modbus_register_address_mode.enum"; -import { ModbusValueType } from "./modbus_value_type.enum"; +import { ModbusRegisterType } from "../modbus_tcp_client/modbus_register_type.enum"; +import { ModbusRegisterAddressMode } from "../modbus_tcp_client/modbus_register_address_mode.enum"; +import { ModbusValueType } from "../modbus_tcp_client/modbus_value_type.enum"; import { SungrowHybridInverterVirtualMeter } from "./sungrow_hybrid_inverter_virtual_meter.enum"; import { SungrowStringInverterVirtualMeter } from "./sungrow_string_inverter_virtual_meter.enum"; import { SolarmaxMaxStorageVirtualMeter } from "./solarmax_max_storage_virtual_meter.enum"; diff --git a/software/web/src/modules/modbus_tcp_client/module.ini b/software/web/src/modules/modbus_tcp_client/module.ini new file mode 100644 index 000000000..79c685b3d --- /dev/null +++ b/software/web/src/modules/modbus_tcp_client/module.ini @@ -0,0 +1 @@ +; Use empty module.ini to make git create this directory for pio_hooks.py to generate files into