Configuration memory write handler.
- Copyright
- Copyright (c) 2024, Jim Kueneman All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Two-phase dispatch for write commands across all standard address spaces. Supports plain write, write-under-mask (read-modify-write), and firmware upgrade writes. Optional per-space handler overrides and delayed reply support are provided.
- Author
- Jim Kueneman
- Date
- 9 Mar 2026
- See also
- MemoryConfigurationS.pdf
Send write request targeting Config (0xFD) on another node.
- Parameters
-
Send write request targeting Config (0xFD) on another node.
Algorithm:
- Load write reply OK message header
- Call _write_data to perform the actual write operation
This function handles writes to the primary configuration data storage space. The actual write is delegated to the config_memory_write callback which can implement any storage mechanism (EEPROM, flash, RAM, etc.).
Use cases:
- Writing configuration values to non-volatile storage
- Responding to configuration tool write requests
* @param statemachine_info Pointer to state machine context for message generation
*
* @param config_mem_write_request_info Pointer to request info with address, byte count, and data buffer
*
- Warning
- Both parameters must not be NULL
-
config_memory_write callback must be implemented
- Attention
- Writes may affect node behavior - ensure data is validated before writing
- See also
- _write_data
-
OpenLcbUtilities_load_config_mem_reply_write_ok_message_header
Write to Train Fn Config (0xF9): updates in-RAM functions[].
- Parameters
-
Write to Train Fn Config (0xF9): updates in-RAM functions[].
Algorithm:
- Load write reply OK message header
- Get train state for the node
- If train state exists:
- Iterate over incoming bytes
- For each byte, calculate function index (address / 2) and byte selector (address % 2)
- Byte selector 0 = high byte (big-endian), byte selector 1 = low byte
- Update the corresponding byte of the function value
- Fire on_function_changed notifier for each function whose bytes were touched
- Set outgoing message as valid
This function writes function values into the train_state_t.functions[] array from datagram data using big-endian byte order. Function N's 16-bit value occupies byte offsets N*2 (high byte) and N*2+1 (low byte). Bulk writes spanning multiple functions are supported.
After storing the values, this fires the same on_function_changed notifier that Set Function commands use, ensuring consistent application behavior regardless of whether the function was set via Train Control command or via Memory Config write to 0xF9.
Use cases:
- Writing function values from configuration tools (JMRI)
- Bulk writing multiple function values in a single datagram
* @param statemachine_info Pointer to state machine context for message generation
*
* @param config_mem_write_request_info Pointer to request info with address, data, and byte count
*
- Warning
- Both parameters must not be NULL
-
Node must have train_state initialized via OpenLcbApplicationTrain_setup()
- See also
- OpenLcbUtilities_load_config_mem_reply_write_ok_message_header