Virtual controller
The virtual controller service allows to define virtual units and sensors, which can be used for automation tests, demos and other related purposes.
Setup
Use the template EVA_DIR/share/svc-tpl/svc-tpl-controller-virtual.yml:
bus:
path: var/bus.ipc
command: svc/eva-controller-virtual
config:
# basic functionality
# auto-create virtual items on set/action
# set true for PLC simulation
auto_create: false
# define virtual items
items:
#- sensor:tests/temp
#- sensor:tests/hum
#- sensor:tests/pressure
#- sensor:tests/alarm
#- sensor:tests/voltage
#- sensor:tests/power
#- unit:tests/lamp
#- unit:tests/vent
#- unit:tests/door
#- unit:tests/u1
# advanced functionality (PLC tag/var table simulation)
# pull interval, in seconds
#pull_interval: 1
# pull mapping
#pull:
# - var: test_array1
# map:
# - idx: 0
# oid: sensor:tests/temp
# - idx: 1
# oid: sensor:tests/hum
# - var: test_var
# map:
# - oid: sensor:tests/pressure
# - var: unit.u1
# map:
# - oid: unit:tests/u1
# - var: unit.u2
# map:
# - oid: unit:tests/u2
# action mapping
#action_map:
#unit:tests/u1:
#var: unit.u1
#unit:tests/u2:
#var; unit.u2
user: nobody
workers: 1
Create the service using eva-shell:
eva svc create eva.controller.virt1 /opt/eva4/share/svc-tpl/svc-tpl-controller-virtual.yml
or using the bus CLI client:
cd /opt/eva4
cat DEPLOY.yml | ./bin/yml2mp | \
./sbin/bus ./var/bus.ipc rpc call eva.core svc.deploy -
(see eva.core::svc.deploy for more info)
EAPI methods
See EAPI commons for the common information about the bus, types, errors and RPC calls.
action
Description |
Executes a mapped unit action |
Parameters |
See Unit actions |
Returns |
See Unit actions |
get
Description |
Gets controller state of a virtual item |
Parameters |
required |
Returns |
Item state struct |
Name |
Type |
Description |
Required |
i |
String |
Item OID |
yes |
Return payload example:
{
"oid": "sensor:tests/voltage",
"status": 1,
"value": 25.43
}
list
Description |
Lists virtual items and their states |
Parameters |
none |
Returns |
List (struct) |
Return payload example:
[
{
"oid": "unit:tests/door",
"status": 0,
"value": null
},
{
"oid": "sensor:tests/temp",
"status": 1,
"value": 42.37
},
{
"oid": "sensor:tests/voltage",
"status": 1,
"value": 25.43
}
]
set
Description |
Sets controller state of a virtual item |
Parameters |
required |
Returns |
nothing |
Name |
Type |
Description |
Required |
i |
String |
Item OID |
yes |
status |
u16 |
Item status |
no |
value |
Any |
Item state value |
no |
var.destroy
Description |
Destroy virtual variable |
Parameters |
required |
Returns |
nothing |
Name |
Type |
Description |
Required |
i |
String |
Variable ID |
yes |
var.get
Description |
Get virtual variable value |
Parameters |
required |
Returns |
value, single or list |
Name |
Type |
Description |
Required |
i |
String |
Variable ID |
yes |
var.list
Description |
List virtual variables |
Parameters |
required |
Returns |
Virtual variables and their values |
Name |
Type |
Description |
Required |
full |
bool |
Full output (id/value) |
no |
Return payload example:
[
{
"id": "some.var1"
},
{
"id": "some.var2"
},
{
"id": "some.var3"
}
]
var.set
Description |
Set virtual variable value |
Parameters |
required |
Returns |
nothing |
Name |
Type |
Description |
Required |
i |
String |
Variable ID |
yes |
value |
Any |
value to set |
yes |
var.set_bulk
Description |
Set virtual variable values in bulk |
Parameters |
required |
Returns |
Operation status: failed-to-set vars list or an empty dict |
Name |
Type |
Description |
Required |
i |
Vec<String> |
variable IDs |
yes |
values |
Vec<Any> |
values to set |
yes |
Return payload example:
{
"failed": [ "var1" ]
}
Controller modes
The service works in two modes: Simple and PLC Simulation. The approach can be mixed in the service configuration (part of items can be mapped to virtual PLC variables while part can be mapped as simple virtual items).
Simple
If a simple configuration is used (no pull/action map), the service simulates virtual items, which states can be set via bus calls or actions.
The virtual items are mapped to EVA ICS node core as-is.
PLC simulation
When pull / action_map configuration fields are set, the service starts simulating fieldbus controller gateway behaviour, providing the same EAPI methods as fieldbus controllers to get/set PLC variables. This approach is useful when it is required to debug fieldbus mappings and events.
In PLC simulation mode item states/actions are mapped to virtual PLC variables.
The virtual variable table is stored in EVA ICS registry automatically at the service instance shutdown.
PLC variables/tag IDs can be set in any format. The variables support array indexing (VAR[idx] or VAR[start-end]) as well.
Note
In PLC simulation mode the service still uses virtual item table. It is recommended to set auto_create configuration field to true.