EPICSCAClient
The MARTe2 EPICSCAClient allows triggering messages based on the values of EPICS Channel Access (CA) process variables (PVs).
Warning
The EPICSCAClient is only available in distributions where EPICS Channel Access is installed.
In this example, the EPICSCAClient is used to:
Trigger
StateMachinetransitions based on PV values.Monitor the application status by publishing state updates to EPICS.
Makefile.cfg. 1+EPICSCA = {
2 Class = EPICS::EPICSCAClient
3 StackSize = 1048576
4 CPUs = 0x1
5 AutoStart = 0
6 +PV_STATUS = {
7 Class = EPICS::EPICSPV
8 PVName = XSTR(MARTE2-TUTORIAL-USERNAME-APP-STATUS)
9 PVType = uint32
10 }
11 +PV_COMMAND = {
12 Class = EPICS::EPICSPV
13 PVName = XSTR(MARTE2-TUTORIAL-USERNAME-APP-COMMAND)
14 PVType = uint32
15 Event = {
16 Destination = StateMachine
17 PVValue = Function
18 FunctionMap = {{"2", "GOTO_WAVEFORM_REF"}, {"1", "GOTO_CONSTANT_REF"}, {"0", "GOTO_SWITCH_OFF"}}
19 }
20 }
21}
The StateMachine is configured to send a message every time the state changes, allowing external systems (via EPICS) to track the application status.
ENTER substate). 1+StateMachine = {
2 Class = StateMachine
3 +CONSTANT_REF = {
4 Class = ReferenceContainer
5 +ENTER = {
6 Class = ReferenceContainer
7 +InformStatusUpdate = {
8 Class = Message
9 Destination = "EPICSCA.PV_STATUS"
10 Function = CAPut
11 Mode = ExpectsReply
12 +Parameters = {
13 Class = ConfigurationDatabase
14 param1 = 1
15 }
16 }
17 }
18 +WAVEFORM_REF = {
19 Class = ReferenceContainer
20 +ENTER = {
21 Class = ReferenceContainer
22 +InformStatusUpdate = {
23 Class = Message
24 Destination = "EPICSCA.PV_STATUS"
25 Function = CAPut
26 Mode = ExpectsReply
27 +Parameters = {
28 Class = ConfigurationDatabase
29 param1 = 2
30 }
31 }
32 }
33 +ENTER = {
34 Class = ReferenceContainer
35 +InformStatusUpdate = {
36 Class = Message
37 Destination = "EPICSCA.PV_STATUS"
38 Function = CAPut
39 Mode = ExpectsReply
40 +Parameters = {
41 Class = ConfigurationDatabase
42 param1 = 0
43 }
44 }
45 }
Running the application
Start the
softIOCin a separate terminal:
../Test/Integrated/GenerateEPICSSoftIOCDb.sh
softIoc -d ../Test/Integrated/MassSpring-1.db
Start the MARTe2 application:
make -C ../Configurations/MassSpring/ -f Makefile.cfg
./MARTeApp.sh -f ../Configurations/MassSpring/RTApp-MassSpring-56_Gen.cfg -l RealTimeLoader -m StateMachine::START
Verify that the application runs correctly. The log should show entries similar to:
$ |E=Information|TM=13:35:40 (7271154714286675)|o=StateMachine|O=0x000000000247CED0|C=StateMachine|T=|P=x86-linux|f=virtual MARTe::ErrorManagement::ErrorType MARTe::StateMachine::SendMultipleMessagesAndWaitReply(MARTe::ReferenceContainer, const MARTe::TimeoutType&)|F=StateMachine.cpp:340|D=In state (INITIAL) triggered message (StartNextStateExecutionRTApp)
$ |E=Information|TM=13:35:40 (7271154714327563)|o=StateMachine|O=0x000000000247CED0|C=StateMachine|T=|P=x86-linux|f=virtual MARTe::ErrorMManagement::ErrorType MARTe::StateMachine::SendMultipleMessagesAndWaitReply(MARTe::ReferenceContainer, const MARTe::TimeoutType&)|F=StateMachine.cpp:340|D=In state (WAVEFORM_REF) triggered message (InformStatusUpdate)
$ |E=Information|TM=13:35:41 (7271155716506427)|o=|O=0x0000000002540BE0|C=LoggerBroker|T=|P=x86-linux|f=virtual bool MARTe::LoggerBroker::Execute()|F=LoggerBroker.cpp:152|D=Time [0:0]:1000000
$ |E=Information|TM=13:35:41 (7271155716512697)|o=|O=0x0000000002540BE0|C=LoggerBroker|T=|P=x86-linux|f=virtual bool MARTe::LoggerBroker::Execute()|F=LoggerBroker.cpp:152|D=ReferencePosition [0:0]:0.400000
...
Open another terminal and change the application state by writing to the command PV:
caput MARTE2-TUTORIAL-USERNAME-APP-COMMAND 0
caput MARTE2-TUTORIAL-USERNAME-APP-COMMAND 1
Replace USERNAME with your username in capital letters.
Monitor the application state:
camonitor MARTE2-TUTORIAL-USERNAME-APP-STATUS
The PV should update (e.g. value 1), indicating a state change.
At the same time, the application log will reflect the new behaviour. For example, when switching to a constant reference state:
|E=Information|TM=13:40:35 (7271449679705588)|o=|O=0x0000000001C6DBE0|C=LoggerBroker|T=|P=x86-linux|f=virtual bool MARTe::LoggerBroker::Execute()|F=LoggerBroker.cpp:152|D=ReferencePosition [0:0]:2.000000