VILLASframework
Modular co-simulation framework
|
VILLASnode supports hook functions to filter or manipulate samples while their are forwarded. These functions are in C-code. A plugin mechanism makes it easy for the user to new hook functions.
During this lab we will use the following hook functions:
Name | Description |
---|---|
average | Calculates average over some signals. |
cast | Cast signal types. |
restart | Call restart hooks for current path. |
ts | Overwrite origin timestamp of samples with receive timestamp. |
stats | Collect statistics for the current path. |
decimate | Downsamping by integer factor. |
dp | Transform to/from dynamic phasor. |
ebm | Energy based metric. |
fix | Fix received data by adding missing fields. |
fix_ts | Update timestamps of sample if not set. |
gate | Skip samples only if an enable signal is under a specified threshold. |
jitter | Hook to calculate jitter between GTNET-SKT GPS timestamp and Villas node NTP timestamp. |
limit_rate | Limits the rate of sending signals. |
skip_first | Skip the first samples. |
stats_send | Send path statistics to another node. |
drop | Drop messages with reordered sequence numbers. |
convert | Convert message from / to floating-point / integer. |
scale | Scale signals by a factor and add offset. |
shift_seq | Shift sequence number of samples. |
map | Remap values and / or add header, timestamp values to the sample. |
print | Print the message to stdout. |
shift_ts | Shift timestamps of samples. |
A full list of supported hook functions is documented here: Hook-types
A hook function can be used in two ways:
villas hook
to process samples from standard streams.villas node
daemon.When used with villas hook
we can pass options to the hook function as optional parameters to the invocation of villas hook
:
When used with villas node
the hook is configured as part of a path:
Hook functions are chainable:
Every sample has three timestamps associated with it:
origin
received
sent
Use the mode
parameter to select the timestamp which should be shifted.
There is another related hook function called fix_ts
which will only overwrite the the timestamp if the source has not provided one (timestamp must is 0.0
).
This invocation reduces the sending rate by a factor of 10. The resulting rate is: 1000 / 10 = 100
.
This invocation reduces the sending rate by a factor of 10. The resulting rate is: 1000 / 10 = 100
.
This function skips values based on the enable signal which is set using one of the following modes. above below rising_edge falling_edge
The 'above' mode allows only the signal values which are greater than the threshold. By default the threshold is set to 0. Similarly the 'below' mode allows only the signal values which are lesser than the threshold. This can be visualized in the waveforms below:
The modes rising edge and falling edge allow signal values to pass on rising edge and falling edge respectively. It is demonstrated by the examples and waveforms below:
This invocation convertes values 5-8 to a integer number with a gain factor of 1000:
Note: villas hook
by default prints the processed stream of samples already to the screen. Therefore, every sample appears now twice on the screen. This hook only makes sense when used together with villas none
.
Have a look at the following skeleton code: https://git.rwth-aachen.de/acs/public/villas/node/blob/master/plugins/example_hook.cpp
Go to [lab 9] =>(node-lab-9)