The In-Memory Mock Mapping Adapter mocks the behavior of a mapping service from within the memory of the Freyja application. This enables a minimal example scenario when working with Freyja. This library contains an implementation of the MappingAdapter
trait from freyja-common
.
This adapter supports the following configuration settings:
values
: a list of mappings to use. Each entry in the list is an object with the following properties:begin
: an integer indicating when to enable thevalue
end
: an optional integer indicating when to disable thevalue
. Set tonull
if you never want the value to "turn off"value
: a mapping that should be emitted at some point during the application's lifetime. This has the following properties:source
: the ID of the entity that will be used as the source for this mapping. This should match something that's retrievable with thefind_by_id
API of the digital twin adapter that you're using.target
: a set of key-value pairs that will be passed to the cloud adapter. This is completely free-form, and will potentially be used by the cloud adapter to help with addressing the correct digital twin instance and/or properties for upstream data emissions.interval_ms
: the interval (in milliseconds) at which the entity should be queried for changesemit_on_change
: a boolean indicating whether data emission should be skipped if the value hasn't changed since the last emission. Set totrue
to enable this behavior.conversion
: a conversion that should be applied. Set tonull
if no conversion is needed. Otherwise the conversion is configured with themul
andoffset
properties, and the valuey
that is emitted is calculated asy = mul * x + offset
. Note that conversions are only supported for signal values which can be parsed asf64
.
This adapter supports config overrides. The override filename is mock_mapping_config.json
, and the default config is located at res/mock_mapping_config.default.json
.
The adapter maintains an internal count, and only mappings satisfying the condition begin <= count [< end]
will be returned in the get_mapping
API. This count is incremented every time the check_for_work
API is invoked. This will also affect the check_for_work
API, which returns true if the set of mappings has changed since the last time it was called. This effectively means that the state can potentially change with each loop of the cartographer.