### CMake Installation Commands Source: https://github.com/hoylabs/opendtu-onbattery/blob/development/lib/Frozen/README.rst Build and install the Frozen library using CMake. The commands create a build directory, configure with release build type, and install to the system. ```sh > mkdir build > cd build > cmake -D CMAKE_BUILD_TYPE=Release .. > make install ``` -------------------------------- ### Install ascii command Source: https://github.com/hoylabs/opendtu-onbattery/wiki/VE.Direct-Interface Install the 'ascii' command-line tool, required if the command 'ascii -t "$CHAR"|head -n1|cut -d' ' -f4' returns 'Command ascii not found'. ```bash sudo apt install ascii ``` -------------------------------- ### Running tests and benchmarks with Makefiles Source: https://github.com/hoylabs/opendtu-onbattery/blob/development/lib/Frozen/README.rst Commands to run tests and benchmarks using hand-written Makefiles. Requires GOOGLE_BENCHMARK_PREFIX to point to the Google Benchmark installation directory. ```sh > # running tests > make -C tests check > # running benchmarks > make -C benchmarks GOOGLE_BENCHMARK_PREFIX= ``` -------------------------------- ### Set CAN0 bitrate command Source: https://github.com/hoylabs/opendtu-onbattery/wiki/Pylontech-battery Command to set the CAN0 interface bitrate to 500000 before starting the Pylontech emulator. ```bash sudo ip link set can0 up type can bitrate 500000 ``` -------------------------------- ### Tasmota Status Response JSON Source: https://github.com/hoylabs/opendtu-onbattery/wiki/Power-Meter Example output from the Tasmota command `http://192.168.xxx.xxx/cm?cmnd=status%208` showing available meter values. The value `aktuelle_Wirkleistung` is the power reading to extract. ```json { "StatusSNS": { "Time": "2023-12-10T20:17:41", "Wohnung": { "server_id": "0a01415041010557ff7d", "total_kwh": 819.9, "export_total_kwh": 251.48, "aktuelle_Wirkleistung": 557, "freq": 50, "amp_p1": 0.98, "amp_p2": 0.45, "amp_p3": 1.46, "curr_w_p1": 184, "curr_w_p2": 82, "curr_w_p3": 289, "volt_p1": 240.8, "volt_p2": 240.9, "volt_p3": 241.3, "phase_angle_l2_l1": 238, "phase_angle_l3_l1": 118, "phase_angle_p1": 330, "phase_angle_p2": 325, "phase_angle_p3": 333 } } } ``` -------------------------------- ### Tasmota JSON Path for Power Source: https://github.com/hoylabs/opendtu-onbattery/wiki/Power-Meter The JSON path to enter in the power meter configuration to extract the active power value from the Tasmota response. ```text StatusSNS/Wohnung/aktuelle_Wirkleistung ``` -------------------------------- ### Custom hash function for frozen::unordered_set Source: https://github.com/hoylabs/opendtu-onbattery/blob/development/lib/Frozen/README.rst Defines a custom hash functor for frozen::unordered_set to handle data that doesn't suit the default hash functions. The example creates a set with two elements using the custom hash. ```c++ struct olaf { constexpr std::size_t operator()(frozen::string const &value, std::size_t seed) const { return seed ^ value[0];} }; constexpr frozen::unordered_set hans = { "a", "b" }; ``` -------------------------------- ### Build and run tests with make Source: https://github.com/hoylabs/opendtu-onbattery/blob/development/test/README.md Commands to build, run, and clean up the test suite for the OverscalingCalculator. ```bash # Build and run all tests make test # Build only make all # Clean up make clean ``` -------------------------------- ### Waveshare RS485 CAN HAT config.txt lines Source: https://github.com/hoylabs/opendtu-onbattery/wiki/Pylontech-battery Configuration lines for the Waveshare RS485 CAN HAT with a 12M crystal, to be added to config.txt on a Raspberry Pi. ```text dtparam=spi=on dtoverlay=mcp2515-can0,oscillator=12000000,interrupt=25,spimaxfrequency=2000000 ``` -------------------------------- ### DRY Initialization with frozen::make_set Source: https://github.com/hoylabs/opendtu-onbattery/blob/development/lib/Frozen/README.rst Use the make_set helper to initialize a frozen::set with a more concise syntax. Similar make_X functions exist for all frozen containers. ```C++ #include constexpr auto some_ints = frozen::make_set({1,2,3,5}); ``` -------------------------------- ### Run pylon_can.py script Source: https://github.com/hoylabs/opendtu-onbattery/wiki/Pylontech-battery Command to run the Pylontech emulator script. ```bash python pylon_can.py ``` -------------------------------- ### CMake static configuration build system Source: https://github.com/hoylabs/opendtu-onbattery/blob/development/lib/Frozen/README.rst Commands to configure, build, test, and benchmark with CMake using a static configuration. The generator can be "Unix Makefiles" or "Ninja". Enables benchmarks with -D frozen.benchmark=ON. ```sh > mkdir build > cd build > cmake -D CMAKE_BUILD_TYPE=Release \ -D frozen.benchmark=ON \ -G <"Unix Makefiles" or "Ninja"> .. > # building the tests and benchmarks... > make # ... with make > ninja # ... with ninja > cmake --build . # ... with cmake > # running the tests... > make test # ... with make > ninja test # ... with ninja > cmake --build . --target test # ... with cmake > ctest # ... with ctest > # running the benchmarks... > make benchmark # ... with make > ninja benchmark # ... with ninja > cmake --build . --target benchmark # ... with cmake ``` -------------------------------- ### CMake IDE build system with test and benchmark targets Source: https://github.com/hoylabs/opendtu-onbattery/blob/development/lib/Frozen/README.rst Commands to configure and drive an IDE build system (Xcode or Visual Studio 15 2017) with CMake, including building, testing, and benchmarking in Release configuration. ```sh > mkdir build > cd build > cmake -D frozen.benchmark=ON -G <"Xcode" or "Visual Studio 15 2017"> .. > # using cmake to drive the IDE build, test, and benchmark > cmake --build . --config Release > cmake --build . --target test > cmake --build . --target benchmark ``` -------------------------------- ### Run victron_emulator.sh with serial interface Source: https://github.com/hoylabs/opendtu-onbattery/wiki/VE.Direct-Interface Command to run the VE.Direct emulator script with a serial interface parameter, e.g., /dev/ttyUSB1 or /dev/serial1. If called without a parameter, it outputs the data frame on screen. ```bash ./victron_emulator.sh /dev/ttyUSB1 ``` ```bash ./victron_emulator.sh /dev/serial1 ``` -------------------------------- ### pin_mapping.json for Huawei+Battery Source: https://github.com/hoylabs/opendtu-onbattery/wiki/Huawei-AC-PSU Configuration file for setting GPIO mappings for Huawei, Victron, Ethernet, and battery connections. Note for firmware versions before 2025.xx.xx: huawei.power must be set to an unused GPIO pin even if not used, otherwise communication won't work. ```json [ { "name": "Huawei+Battery", "nrf24": { "miso": 19, "mosi": 23, "clk": 18, "irq": 16, "en": 4, "cs": 5 }, "huawei": { "miso": 12, "mosi": 13, "clk": 26, "irq": 25, "power": 33, "cs": 15 }, "victron": { "rx": 22, "tx": 21 }, "eth": { "enabled": false }, "battery": { "rx": 27, "tx": 14 } } ] ``` -------------------------------- ### Run victron_emulator.sh on Raspberry Pi 2 Source: https://github.com/hoylabs/opendtu-onbattery/wiki/VE.Direct-Interface Command to run the VE.Direct emulator script on a Raspberry Pi 2, using /dev/serial0 as the serial interface. This is noted as working on the Raspberry Pi 2. ```bash cd VICTRON/ ``` ```bash ./victron_emulator.sh /dev/serial0 ``` -------------------------------- ### constexpr frozen::unordered_map with String Keys Source: https://github.com/hoylabs/opendtu-onbattery/blob/development/lib/Frozen/README.rst Create a constexpr unordered_map with frozen::string keys and access a value with at(). Demonstrates built-in string support and constexpr initialization. ```C++ #include #include constexpr frozen::unordered_map olaf = { {"19", 19}, {"31", 31}, }; constexpr auto val = olaf.at("19"); ``` -------------------------------- ### Edit pylon_cyc.py to use can0 Source: https://github.com/hoylabs/opendtu-onbattery/wiki/Pylontech-battery Lines to edit in pylon_cyc.py to change the interface from vcan0 to can0. ```python for interface, channel in [ ('socketcan', 'vcan0'), ``` ```python for interface, channel in [ ('socketcan', 'can0'), ``` -------------------------------- ### Configure Pytes Battery CAN Protocol via Serial Console Source: https://github.com/hoylabs/opendtu-onbattery/wiki/Pytes-Battery For advanced users, configure the CAN protocol on Pytes batteries using a Cisco-compatible serial to USB cable. Commands set the protocol to VICTRON. ```bash login config setprt VICTRON logout ``` -------------------------------- ### constinit frozen::unordered_map with Mutable Values Source: https://github.com/hoylabs/opendtu-onbattery/blob/development/lib/Frozen/README.rst Initialize a constinit unordered_map with immutable keys but mutable values, and update values at runtime. Requires C++14 and constinit support. ```C++ #include #include static constinit frozen::unordered_map voice = { {"Anna", "???"}, {"Elsa", "???"} }; int main() { voice.at("Anna") = "Kristen"; voice.at("Elsa") = "Idina"; } ``` -------------------------------- ### Basic constexpr frozen::set Usage Source: https://github.com/hoylabs/opendtu-onbattery/blob/development/lib/Frozen/README.rst Initialize a frozen::set with constexpr and use its count method. The constructor and methods are constexpr, enabling compile-time evaluation. ```C++ #include constexpr frozen::set some_ints = {1,2,3,5}; constexpr bool letitgo = some_ints.count(8); extern int n; bool letitgoooooo = some_ints.count(n); ``` -------------------------------- ### Custom Hash Function for frozen::elsa Source: https://github.com/hoylabs/opendtu-onbattery/blob/development/lib/Frozen/README.rst Specialize the frozen::elsa structure to provide a custom hash function. The operator takes a value and a seed, and should have good statistical properties to avoid collisions. ```C++ template struct elsa { // in case of collisions, different seeds are tried constexpr std::size_t operator()(T const &value, std::size_t seed) const; }; ``` -------------------------------- ### constexpr Template with frozen::set Source: https://github.com/hoylabs/opendtu-onbattery/blob/development/lib/Frozen/README.rst Use frozen::set in a template with constexpr to conditionally enable a function based on set membership. Demonstrates compile-time evaluation in template parameters. ```C++ #include template std::enable_if_t< frozen::set{{1,11,111}}.count(N), int> foo(); ``` -------------------------------- ### Clang constexpr evaluation error message Source: https://github.com/hoylabs/opendtu-onbattery/blob/development/lib/Frozen/README.rst Shows the error message when constexpr evaluation hits the maximum step limit, possibly indicating an infinite loop. Increase Clang's thresholds with -fconstexpr-steps=1000000000 or change the hash functions. ```none [...] note: constexpr evaluation hit maximum step limit; possible infinite loop? ```