diff options
author | Thomas Schuetz | 2011-11-18 16:31:48 +0000 |
---|---|---|
committer | Thomas Schuetz | 2011-11-18 16:31:48 +0000 |
commit | 1f3255a8fd2c6199261fe128c199ca62c2c0b92b (patch) | |
tree | 8f0425ac4a2d3e2938b7ee9190a19aa87d2aaf35 /examples/org.eclipse.etrice.tutorials/src-gen | |
parent | 20f5f3911005bbce952f5bb00b7d1f4cbbd32328 (diff) | |
download | org.eclipse.etrice-1f3255a8fd2c6199261fe128c199ca62c2c0b92b.tar.gz org.eclipse.etrice-1f3255a8fd2c6199261fe128c199ca62c2c0b92b.tar.xz org.eclipse.etrice-1f3255a8fd2c6199261fe128c199ca62c2c0b92b.zip |
[tutorials] regenerated tutorials
Diffstat (limited to 'examples/org.eclipse.etrice.tutorials/src-gen')
13 files changed, 938 insertions, 26 deletions
diff --git a/examples/org.eclipse.etrice.tutorials/src-gen/Blinky/Blinky.java b/examples/org.eclipse.etrice.tutorials/src-gen/Blinky/Blinky.java index 513782f81..7e27cd585 100644 --- a/examples/org.eclipse.etrice.tutorials/src-gen/Blinky/Blinky.java +++ b/examples/org.eclipse.etrice.tutorials/src-gen/Blinky/Blinky.java @@ -273,7 +273,7 @@ public class Blinky extends ActorClassBase { // state has a sub graph
// with init transition
if (history[STATE_blinking]==NO_STATE) {
- state = executeTransitionChain(CHAIN_TRANS_INITIAL_TO__off, null, null);
+ state = executeTransitionChain(CHAIN_blinking_TRANS_INITIAL_TO__on, null, null);
}
else {
state = history[STATE_blinking];
@@ -300,11 +300,11 @@ public class Blinky extends ActorClassBase { protected void entry_blinking_on() {
timer.Start(1000);
carLights.setState(TrafficLight3.YELLOW);
- }
+ }
protected void entry_blinking_off() {
timer.Start(1000);
carLights.setState(TrafficLight3.OFF);
- }
+ }
//*** Action Codes
protected void action_TRANS_INITIAL_TO__off() {
@@ -312,11 +312,11 @@ public class Blinky extends ActorClassBase { pedLights = light.getPedLights();
carLights.setState(TrafficLight3.OFF);
pedLights.setState(TrafficLight2.OFF);
- }
+ }
protected void action_TRANS_blinking_TO_off_BY_stopControlPort(InterfaceItemBase ifitem) {
timer.Kill();
carLights.setState(TrafficLight3.OFF);
- }
+ }
//******************************************
// END of generated code for FSM
diff --git a/examples/org.eclipse.etrice.tutorials/src-gen/Blinky/BlinkyController.java b/examples/org.eclipse.etrice.tutorials/src-gen/Blinky/BlinkyController.java index 24d32080e..dffe3c354 100644 --- a/examples/org.eclipse.etrice.tutorials/src-gen/Blinky/BlinkyController.java +++ b/examples/org.eclipse.etrice.tutorials/src-gen/Blinky/BlinkyController.java @@ -226,15 +226,15 @@ public class BlinkyController extends ActorClassBase { protected void action_TRANS_INITIAL_TO__on() {
timer.Start(5000);
ControlPort.start();
- }
+ }
protected void action_TRANS_on_TO_off_BY_timeoutTicktimer(InterfaceItemBase ifitem) {
ControlPort.stop();
timer.Start(5000);
- }
+ }
protected void action_TRANS_off_TO_on_BY_timeoutTicktimer(InterfaceItemBase ifitem) {
ControlPort.start();
timer.Start(5000);
- }
+ }
//******************************************
// END of generated code for FSM
diff --git a/examples/org.eclipse.etrice.tutorials/src-gen/HelloWorld/HelloWorldTop.java b/examples/org.eclipse.etrice.tutorials/src-gen/HelloWorld/HelloWorldTop.java index 4f54b1ca5..51cc093ce 100644 --- a/examples/org.eclipse.etrice.tutorials/src-gen/HelloWorld/HelloWorldTop.java +++ b/examples/org.eclipse.etrice.tutorials/src-gen/HelloWorld/HelloWorldTop.java @@ -176,7 +176,7 @@ public class HelloWorldTop extends ActorClassBase { //*** Action Codes
protected void action_TRANS_INITIAL_TO__state0() {
System.out.println("HelloWorld !");
- }
+ }
//******************************************
// END of generated code for FSM
diff --git a/examples/org.eclipse.etrice.tutorials/src-gen/PedLightsController/Controller.java b/examples/org.eclipse.etrice.tutorials/src-gen/PedLightsController/Controller.java index 8f038a523..3037c7a26 100644 --- a/examples/org.eclipse.etrice.tutorials/src-gen/PedLightsController/Controller.java +++ b/examples/org.eclipse.etrice.tutorials/src-gen/PedLightsController/Controller.java @@ -330,31 +330,31 @@ public class Controller extends ActorClassBase { timer.Start(700);
ControlPort.setCarLights(TrafficLight3.GREEN);
ControlPort.setPedLights(TrafficLight2.RED);
- }
+ }
protected void action_TRANS_carsGreen_TO_carsYellow_BY_timeoutTicktimer(InterfaceItemBase ifitem) {
timer.Start(700);
ControlPort.setCarLights(TrafficLight3.YELLOW);
ControlPort.setPedLights(TrafficLight2.RED);
- }
+ }
protected void action_TRANS_carsYellow_TO_carsRed_BY_timeoutTicktimer(InterfaceItemBase ifitem) {
timer.Start(1500);
ControlPort.setCarLights(TrafficLight3.RED);
ControlPort.setPedLights(TrafficLight2.GREEN);
- }
+ }
protected void action_TRANS_carsRed_TO_carsYellowRed_BY_timeoutTicktimer(InterfaceItemBase ifitem) {
timer.Start(700);
ControlPort.setCarLights(TrafficLight3.YELLOW_RED);
ControlPort.setPedLights(TrafficLight2.RED);
- }
+ }
protected void action_TRANS_carsYellowRed_TO_carsGreen2_BY_timeoutTicktimer(InterfaceItemBase ifitem) {
timer.Start(700);
ControlPort.setCarLights(TrafficLight3.GREEN);
ControlPort.setPedLights(TrafficLight2.RED);
- }
+ }
protected void action_TRANS_carsGreen2_TO_off_BY_timeoutTicktimer(InterfaceItemBase ifitem) {
ControlPort.setCarLights(TrafficLight3.OFF);
ControlPort.setPedLights(TrafficLight2.OFF);
- }
+ }
//******************************************
// END of generated code for FSM
diff --git a/examples/org.eclipse.etrice.tutorials/src-gen/PedLightsController/GuiAdapter.java b/examples/org.eclipse.etrice.tutorials/src-gen/PedLightsController/GuiAdapter.java index 226447134..013f10642 100644 --- a/examples/org.eclipse.etrice.tutorials/src-gen/PedLightsController/GuiAdapter.java +++ b/examples/org.eclipse.etrice.tutorials/src-gen/PedLightsController/GuiAdapter.java @@ -225,13 +225,13 @@ public class GuiAdapter extends ActorClassBase { carLights.setState(TrafficLight3.OFF);
pedLights.setState(TrafficLight2.OFF);
lights.setPort(ControlPort);
- }
+ }
protected void action_TRANS_running_TO_running_BY_setCarLightsControlPort_tr0(InterfaceItemBase ifitem, int state) {
carLights.setState(state);
- }
+ }
protected void action_TRANS_running_TO_running_BY_setPedLightsControlPort_tr1(InterfaceItemBase ifitem, int state) {
pedLights.setState(state);
- }
+ }
//******************************************
// END of generated code for FSM
diff --git a/examples/org.eclipse.etrice.tutorials/src-gen/PingPong/MrPingActor.java b/examples/org.eclipse.etrice.tutorials/src-gen/PingPong/MrPingActor.java new file mode 100644 index 000000000..7a181849c --- /dev/null +++ b/examples/org.eclipse.etrice.tutorials/src-gen/PingPong/MrPingActor.java @@ -0,0 +1,240 @@ +package PingPong; + +import org.eclipse.etrice.runtime.java.messaging.Address; +import org.eclipse.etrice.runtime.java.messaging.IRTObject; +import org.eclipse.etrice.runtime.java.messaging.IMessageReceiver; +import org.eclipse.etrice.runtime.java.modelbase.ActorClassBase; +import org.eclipse.etrice.runtime.java.modelbase.SubSystemClassBase; +import org.eclipse.etrice.runtime.java.modelbase.InterfaceItemBase; +import org.eclipse.etrice.runtime.java.debugging.DebuggingService; + +import room.basic.service.timing.*; + +import room.basic.service.timing.PTimeout.*; +import PingPong.PingPongProtocol.*; + + + +public class MrPingActor extends ActorClassBase { + + + //--------------------- ports + protected PingPongProtocolConjPortRepl PingPongPort = null; + //--------------------- saps + protected PTimeoutConjPort timer = null; + //--------------------- services + + //--------------------- interface item IDs + protected static final int IFITEM_PingPongPort = 1; + protected static final int IFITEM_timer = 2; + + //--------------------- attributes + //--------------------- operations + + //--------------------- construction + public MrPingActor(IRTObject parent, String name, Address[][] port_addr, Address[][] peer_addr){ + super(parent, name, port_addr[0][0], peer_addr[0][0]); + setClassName("MrPingActor"); + + // initialize attributes + + // own ports + PingPongPort = new PingPongProtocolConjPortRepl(this, "PingPongPort", IFITEM_PingPongPort, port_addr[IFITEM_PingPongPort], peer_addr[IFITEM_PingPongPort]); + // own saps + timer = new PTimeoutConjPort(this, "timer", IFITEM_timer, 0, port_addr[IFITEM_timer][0], peer_addr[IFITEM_timer][0]); + // own service implementations + } + + + //--------------------- lifecycle functions + public void init(){ + initUser(); + } + + public void start(){ + startUser(); + } + + public void stop(){ + stopUser(); + } + + public void destroy(){ + destroyUser(); + } + + //****************************************** + // START of generated code for FSM + //****************************************** + + // State IDs for FSM + protected static final int STATE_waitForTimer = 2; + protected static final int STATE_waitForPong = 3; + protected static final String stateStrings[] = {"<no state>","<top>","waitForTimer", + "waitForPong" + }; + + // history + // TODOHRR: history defined in ActorClassBase, init in constructor + // history = new int[5]; + // for (int i = 0; i < history.length; i++) { + // history[i] = NO_STATE; + // } + protected int history[] = {NO_STATE,NO_STATE,NO_STATE,NO_STATE}; + + // transition chains + protected static final int CHAIN_TRANS_INITIAL_TO__waitForTimer = 1; + protected static final int CHAIN_TRANS_waitForPong_TO_waitForTimer_BY_pongPingPongPort = 2; + protected static final int CHAIN_TRANS_waitForTimer_TO_waitForPong_BY_timeoutTicktimer = 3; + + // triggers for FSM + protected static final int TRIG_PingPongPort__pong = IFITEM_PingPongPort + EVT_SHIFT*PingPongProtocol.OUT_pong; + protected static final int TRIG_timer__timeoutTick = IFITEM_timer + EVT_SHIFT*PTimeout.OUT_timeoutTick; + + // receiveEvent contains the main implementation of the FSM + @Override + public void receiveEvent(InterfaceItemBase ifitem, int evt, Object generic_data) { + int trigger = ifitem.getLocalId() + EVT_SHIFT*evt; + int chain = NOT_CAUGHT; + int catching_state = NO_STATE; + boolean is_handler = false; + boolean skip_entry = false; + + if (!handleSystemEvent(ifitem, evt, generic_data)) { + switch (state) { + case STATE_waitForTimer: + switch(trigger) { + case TRIG_timer__timeoutTick: + { + chain = CHAIN_TRANS_waitForTimer_TO_waitForPong_BY_timeoutTicktimer; + catching_state = STATE_TOP; + } + break; + } + break; + case STATE_waitForPong: + switch(trigger) { + case TRIG_PingPongPort__pong: + { + chain = CHAIN_TRANS_waitForPong_TO_waitForTimer_BY_pongPingPongPort; + catching_state = STATE_TOP; + } + break; + } + break; + } + } + if (chain != NOT_CAUGHT) { + exitTo(state, catching_state, is_handler); + int next = executeTransitionChain(chain, ifitem, generic_data); + next = enterHistory(next, is_handler, skip_entry); + setState(next); + } + } + + private void setState(int new_state) { + DebuggingService.getInstance().addActorState(this,stateStrings[new_state]); + if (stateStrings[new_state]!="Idle") { + // TODOTS: model switch for activation + System.out.println(getInstancePath() + " -> " + stateStrings[new_state]); + } + this.state = new_state; + } + + @Override + public void executeInitTransition() { + int chain = CHAIN_TRANS_INITIAL_TO__waitForTimer; + int next = executeTransitionChain(chain, null, null); + next = enterHistory(next, false, false); + setState(next); + } + + /** + * calls exit codes while exiting from the current state to one of its + * parent states while remembering the history + * @param current - the current state + * @param to - the final parent state + * @param handler - entry and exit codes are called only if not handler (for handler TransitionPoints) + */ + private void exitTo(int current, int to, boolean handler) { + while (current!=to) { + switch (current) { + case STATE_waitForTimer: + history[STATE_TOP] = STATE_waitForTimer; + current = STATE_TOP; + break; + case STATE_waitForPong: + history[STATE_TOP] = STATE_waitForPong; + current = STATE_TOP; + break; + } + } + } + /** + * calls action, entry and exit codes along a transition chain. The generic data are cast to typed data + * matching the trigger of this chain. The ID of the final state is returned + * @param chain - the chain ID + * @param generic_data - the generic data pointer + * @return the ID of the final state + */ + private int executeTransitionChain(int chain, InterfaceItemBase ifitem, Object generic_data) { + switch (chain) { + case CHAIN_TRANS_INITIAL_TO__waitForTimer: + { + action_TRANS_INITIAL_TO__waitForTimer(); + return STATE_waitForTimer; + } + case CHAIN_TRANS_waitForTimer_TO_waitForPong_BY_timeoutTicktimer: + { + action_TRANS_waitForTimer_TO_waitForPong_BY_timeoutTicktimer(ifitem); + return STATE_waitForPong; + } + case CHAIN_TRANS_waitForPong_TO_waitForTimer_BY_pongPingPongPort: + { + action_TRANS_waitForPong_TO_waitForTimer_BY_pongPingPongPort(ifitem); + return STATE_waitForTimer; + } + } + return NO_STATE; + } + /** + * calls entry codes while entering a state's history. The ID of the final leaf state is returned + * @param state - the state which is entered + * @param handler - entry code is executed if not handler + * @return - the ID of the final leaf state + */ + private int enterHistory(int state, boolean handler, boolean skip_entry) { + while (true) { + switch (state) { + case STATE_waitForTimer: + // in leaf state: return state id + return STATE_waitForTimer; + case STATE_waitForPong: + // in leaf state: return state id + return STATE_waitForPong; + case STATE_TOP: + state = history[STATE_TOP]; + break; + } + skip_entry = false; + } + //return NO_STATE; // required by CDT but detected as unreachable by JDT because of while (true) + } + + //*** Entry and Exit Codes + + //*** Action Codes + protected void action_TRANS_INITIAL_TO__waitForTimer() { + timer.Start(1000); + } + protected void action_TRANS_waitForTimer_TO_waitForPong_BY_timeoutTicktimer(InterfaceItemBase ifitem) { + PingPongPort.ping(); + } + protected void action_TRANS_waitForPong_TO_waitForTimer_BY_pongPingPongPort(InterfaceItemBase ifitem) { + timer.Start(1000); + } + + //****************************************** + // END of generated code for FSM + //****************************************** +}; diff --git a/examples/org.eclipse.etrice.tutorials/src-gen/PingPong/MrPongActor1.java b/examples/org.eclipse.etrice.tutorials/src-gen/PingPong/MrPongActor1.java new file mode 100644 index 000000000..75f9d9f6a --- /dev/null +++ b/examples/org.eclipse.etrice.tutorials/src-gen/PingPong/MrPongActor1.java @@ -0,0 +1,202 @@ +package PingPong; + +import org.eclipse.etrice.runtime.java.messaging.Address; +import org.eclipse.etrice.runtime.java.messaging.IRTObject; +import org.eclipse.etrice.runtime.java.messaging.IMessageReceiver; +import org.eclipse.etrice.runtime.java.modelbase.ActorClassBase; +import org.eclipse.etrice.runtime.java.modelbase.SubSystemClassBase; +import org.eclipse.etrice.runtime.java.modelbase.InterfaceItemBase; +import org.eclipse.etrice.runtime.java.debugging.DebuggingService; + + +import PingPong.PingPongProtocol.*; + + + +public class MrPongActor1 extends ActorClassBase { + + + //--------------------- ports + protected PingPongProtocolPort PingPongPort = null; + //--------------------- saps + //--------------------- services + + //--------------------- interface item IDs + protected static final int IFITEM_PingPongPort = 1; + + //--------------------- attributes + //--------------------- operations + + //--------------------- construction + public MrPongActor1(IRTObject parent, String name, Address[][] port_addr, Address[][] peer_addr){ + super(parent, name, port_addr[0][0], peer_addr[0][0]); + setClassName("MrPongActor1"); + + // initialize attributes + + // own ports + PingPongPort = new PingPongProtocolPort(this, "PingPongPort", IFITEM_PingPongPort, 0, port_addr[IFITEM_PingPongPort][0], peer_addr[IFITEM_PingPongPort][0]); + // own saps + // own service implementations + } + + + //--------------------- lifecycle functions + public void init(){ + initUser(); + } + + public void start(){ + startUser(); + } + + public void stop(){ + stopUser(); + } + + public void destroy(){ + destroyUser(); + } + + //****************************************** + // START of generated code for FSM + //****************************************** + + // State IDs for FSM + protected static final int STATE_waitForPing = 2; + protected static final String stateStrings[] = {"<no state>","<top>","waitForPing" + }; + + // history + // TODOHRR: history defined in ActorClassBase, init in constructor + // history = new int[5]; + // for (int i = 0; i < history.length; i++) { + // history[i] = NO_STATE; + // } + protected int history[] = {NO_STATE,NO_STATE,NO_STATE}; + + // transition chains + protected static final int CHAIN_TRANS_INITIAL_TO__waitForPing = 1; + protected static final int CHAIN_TRANS_waitForPing_TO_waitForPing_BY_pingPingPongPort_myTrigger = 2; + + // triggers for FSM + protected static final int TRIG_PingPongPort__ping = IFITEM_PingPongPort + EVT_SHIFT*PingPongProtocol.IN_ping; + + // receiveEvent contains the main implementation of the FSM + @Override + public void receiveEvent(InterfaceItemBase ifitem, int evt, Object generic_data) { + int trigger = ifitem.getLocalId() + EVT_SHIFT*evt; + int chain = NOT_CAUGHT; + int catching_state = NO_STATE; + boolean is_handler = false; + boolean skip_entry = false; + + if (!handleSystemEvent(ifitem, evt, generic_data)) { + switch (state) { + case STATE_waitForPing: + switch(trigger) { + case TRIG_PingPongPort__ping: + { + chain = CHAIN_TRANS_waitForPing_TO_waitForPing_BY_pingPingPongPort_myTrigger; + catching_state = STATE_TOP; + } + break; + } + break; + } + } + if (chain != NOT_CAUGHT) { + exitTo(state, catching_state, is_handler); + int next = executeTransitionChain(chain, ifitem, generic_data); + next = enterHistory(next, is_handler, skip_entry); + setState(next); + } + } + + private void setState(int new_state) { + DebuggingService.getInstance().addActorState(this,stateStrings[new_state]); + if (stateStrings[new_state]!="Idle") { + // TODOTS: model switch for activation + System.out.println(getInstancePath() + " -> " + stateStrings[new_state]); + } + this.state = new_state; + } + + @Override + public void executeInitTransition() { + int chain = CHAIN_TRANS_INITIAL_TO__waitForPing; + int next = executeTransitionChain(chain, null, null); + next = enterHistory(next, false, false); + setState(next); + } + + /** + * calls exit codes while exiting from the current state to one of its + * parent states while remembering the history + * @param current - the current state + * @param to - the final parent state + * @param handler - entry and exit codes are called only if not handler (for handler TransitionPoints) + */ + private void exitTo(int current, int to, boolean handler) { + while (current!=to) { + switch (current) { + case STATE_waitForPing: + history[STATE_TOP] = STATE_waitForPing; + current = STATE_TOP; + break; + } + } + } + /** + * calls action, entry and exit codes along a transition chain. The generic data are cast to typed data + * matching the trigger of this chain. The ID of the final state is returned + * @param chain - the chain ID + * @param generic_data - the generic data pointer + * @return the ID of the final state + */ + private int executeTransitionChain(int chain, InterfaceItemBase ifitem, Object generic_data) { + switch (chain) { + case CHAIN_TRANS_INITIAL_TO__waitForPing: + { + return STATE_waitForPing; + } + case CHAIN_TRANS_waitForPing_TO_waitForPing_BY_pingPingPongPort_myTrigger: + { + action_TRANS_waitForPing_TO_waitForPing_BY_pingPingPongPort_myTrigger(ifitem); + return STATE_waitForPing; + } + } + return NO_STATE; + } + /** + * calls entry codes while entering a state's history. The ID of the final leaf state is returned + * @param state - the state which is entered + * @param handler - entry code is executed if not handler + * @return - the ID of the final leaf state + */ + private int enterHistory(int state, boolean handler, boolean skip_entry) { + while (true) { + switch (state) { + case STATE_waitForPing: + // in leaf state: return state id + return STATE_waitForPing; + case STATE_TOP: + state = history[STATE_TOP]; + break; + } + skip_entry = false; + } + //return NO_STATE; // required by CDT but detected as unreachable by JDT because of while (true) + } + + //*** Entry and Exit Codes + + //*** Action Codes + protected void action_TRANS_waitForPing_TO_waitForPing_BY_pingPingPongPort_myTrigger(InterfaceItemBase ifitem) { + PingPongPort.pong(); + } + + //****************************************** + // END of generated code for FSM + //****************************************** +}; diff --git a/examples/org.eclipse.etrice.tutorials/src-gen/PingPong/PingPongProtocol.java b/examples/org.eclipse.etrice.tutorials/src-gen/PingPong/PingPongProtocol.java new file mode 100644 index 000000000..c958cecf3 --- /dev/null +++ b/examples/org.eclipse.etrice.tutorials/src-gen/PingPong/PingPongProtocol.java @@ -0,0 +1,213 @@ +package PingPong; + +import java.util.ArrayList; + +import org.eclipse.etrice.runtime.java.messaging.Address; +import org.eclipse.etrice.runtime.java.messaging.Message; +import org.eclipse.etrice.runtime.java.modelbase.*; +import org.eclipse.etrice.runtime.java.debugging.DebuggingService; + + + +public class PingPongProtocol { + // message IDs + // TODO: separate class for message IDs: class MSG{public static volatile int MSG_MIN = 0; ...} -> better structure + // error if msgID <= MSG_MIN + public static final int MSG_MIN = 0; + //IDs for outgoing messages + public static final int OUT_pong = 1; + //IDs for incoming messages + public static final int IN_ping = 2; + //error if msgID >= MSG_MAX + public static final int MSG_MAX = 3; + + + private static String messageStrings[] = {"MIN", "pong", "ping","MAX"}; + + public String getMessageString(int msg_id) { + if (msg_id<0 || msg_id>MSG_MAX+1){ + // id out of range + return "Message ID out of range"; + } + else{ + return messageStrings[msg_id]; + } + } + + + // port class + static public class PingPongProtocolPort extends PortBase { + // constructors + public PingPongProtocolPort(IEventReceiver actor, String name, int localId, Address addr, Address peerAddress) { + super(actor, name, localId, 0, addr, peerAddress); + DebuggingService.getInstance().addPortInstance(this); + } + public PingPongProtocolPort(IEventReceiver actor, String name, int localId, int idx, Address addr, Address peerAddress) { + super(actor, name, localId, idx, addr, peerAddress); + DebuggingService.getInstance().addPortInstance(this); + } + + @Override + public void receive(Message m) { + if (!(m instanceof EventMessage)) + return; + EventMessage msg = (EventMessage) m; + if (msg.getEvtId() <= 0 || msg.getEvtId() >= MSG_MAX) + System.out.println("unknown"); + else { + if (messageStrings[msg.getEvtId()] != "timerTick"){ + // TODOTS: model switch for activation + DebuggingService.getInstance().addMessageAsyncIn(getPeerAddress(), getAddress(), messageStrings[msg.getEvtId()]); + } + if (msg instanceof EventWithDataMessage) + getActor().receiveEvent(this, msg.getEvtId(), ((EventWithDataMessage)msg).getData()); + else + getActor().receiveEvent(this, msg.getEvtId(), null); + } + } + + + // sent messages + public void pong () + { + if (messageStrings[ OUT_pong] != "timerTick"){ + // TODOTS: model switch for activation + DebuggingService.getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(), messageStrings[OUT_pong]); + } + if (getPeerAddress()!=null) + getPeerMsgReceiver().receive(new EventMessage(getPeerAddress(), OUT_pong)); + } + } + + // replicated port class + static public class PingPongProtocolPortRepl { + private ArrayList<PingPongProtocolPort> ports; + private int replication; + + public PingPongProtocolPortRepl(IEventReceiver actor, String name, int localId, Address[] addr, + Address[] peerAddress) { + replication = addr.length; + ports = new ArrayList<PingPongProtocol.PingPongProtocolPort>(replication); + for (int i=0; i<replication; ++i) { + ports.add(new PingPongProtocolPort( + actor, name+i, localId, i, addr[i], peerAddress[i])); + } + } + + public int getReplication() { + return replication; + } + + public int getIndexOf(InterfaceItemBase ifitem){ + return ifitem.getIdx(); + } + + public PingPongProtocolPort get(int i) { + return ports.get(i); + } + + // outgoing messages + public void pong () + { + for (int i=0; i<replication; ++i) { + ports.get(i).pong() + ; + } + } + } + + // interface for port class + public interface IPingPongProtocolPort{ + // incoming messages + public void ping () + ; + } + + // port class + static public class PingPongProtocolConjPort extends PortBase { + // constructors + public PingPongProtocolConjPort(IEventReceiver actor, String name, int localId, Address addr, Address peerAddress) { + super(actor, name, localId, 0, addr, peerAddress); + DebuggingService.getInstance().addPortInstance(this); + } + public PingPongProtocolConjPort(IEventReceiver actor, String name, int localId, int idx, Address addr, Address peerAddress) { + super(actor, name, localId, idx, addr, peerAddress); + DebuggingService.getInstance().addPortInstance(this); + } + + @Override + public void receive(Message m) { + if (!(m instanceof EventMessage)) + return; + EventMessage msg = (EventMessage) m; + if (msg.getEvtId() <= 0 || msg.getEvtId() >= MSG_MAX) + System.out.println("unknown"); + else { + if (messageStrings[msg.getEvtId()] != "timerTick"){ + // TODOTS: model switch for activation + DebuggingService.getInstance().addMessageAsyncIn(getPeerAddress(), getAddress(), messageStrings[msg.getEvtId()]); + } + if (msg instanceof EventWithDataMessage) + getActor().receiveEvent(this, msg.getEvtId(), ((EventWithDataMessage)msg).getData()); + else + getActor().receiveEvent(this, msg.getEvtId(), null); + } + } + + + // sent messages + public void ping () + { + if (messageStrings[ IN_ping] != "timerTick"){ + // TODOTS: model switch for activation + DebuggingService.getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(), messageStrings[IN_ping]); + } + if (getPeerAddress()!=null) + getPeerMsgReceiver().receive(new EventMessage(getPeerAddress(), IN_ping)); + } + } + + // replicated port class + static public class PingPongProtocolConjPortRepl { + private ArrayList<PingPongProtocolConjPort> ports; + private int replication; + + public PingPongProtocolConjPortRepl(IEventReceiver actor, String name, int localId, Address[] addr, + Address[] peerAddress) { + replication = addr.length; + ports = new ArrayList<PingPongProtocol.PingPongProtocolConjPort>(replication); + for (int i=0; i<replication; ++i) { + ports.add(new PingPongProtocolConjPort( + actor, name+i, localId, i, addr[i], peerAddress[i])); + } + } + + public int getReplication() { + return replication; + } + + public int getIndexOf(InterfaceItemBase ifitem){ + return ifitem.getIdx(); + } + + public PingPongProtocolConjPort get(int i) { + return ports.get(i); + } + + // incoming messages + public void ping () + { + for (int i=0; i<replication; ++i) { + ports.get(i).ping() + ; + } + } + } + + // interface for port class + public interface IPingPongProtocolConjPort{ + // outgoing messages + public void pong () + ; + } +} diff --git a/examples/org.eclipse.etrice.tutorials/src-gen/PingPong/PingPongTop.java b/examples/org.eclipse.etrice.tutorials/src-gen/PingPong/PingPongTop.java new file mode 100644 index 000000000..58653cc27 --- /dev/null +++ b/examples/org.eclipse.etrice.tutorials/src-gen/PingPong/PingPongTop.java @@ -0,0 +1,66 @@ +package PingPong; + +import org.eclipse.etrice.runtime.java.messaging.Address; +import org.eclipse.etrice.runtime.java.messaging.IRTObject; +import org.eclipse.etrice.runtime.java.messaging.IMessageReceiver; +import org.eclipse.etrice.runtime.java.modelbase.ActorClassBase; +import org.eclipse.etrice.runtime.java.modelbase.SubSystemClassBase; +import org.eclipse.etrice.runtime.java.modelbase.InterfaceItemBase; +import org.eclipse.etrice.runtime.java.debugging.DebuggingService; + + + + + +public class PingPongTop extends ActorClassBase { + + + //--------------------- ports + //--------------------- saps + //--------------------- services + + //--------------------- interface item IDs + + //--------------------- attributes + //--------------------- operations + + //--------------------- construction + public PingPongTop(IRTObject parent, String name, Address[][] port_addr, Address[][] peer_addr){ + super(parent, name, port_addr[0][0], peer_addr[0][0]); + setClassName("PingPongTop"); + + // initialize attributes + + // own ports + // own saps + // own service implementations + } + + + //--------------------- lifecycle functions + public void init(){ + initUser(); + } + + public void start(){ + startUser(); + } + + public void stop(){ + stopUser(); + } + + public void destroy(){ + destroyUser(); + } + + //--------------------- no state machine + @Override + public void receiveEvent(InterfaceItemBase ifitem, int evt, Object data) { + handleSystemEvent(ifitem, evt, data); + } + + @Override + public void executeInitTransition(){ + } +}; diff --git a/examples/org.eclipse.etrice.tutorials/src-gen/PingPong/SubSystem_PingPong.java b/examples/org.eclipse.etrice.tutorials/src-gen/PingPong/SubSystem_PingPong.java new file mode 100644 index 000000000..476a389cf --- /dev/null +++ b/examples/org.eclipse.etrice.tutorials/src-gen/PingPong/SubSystem_PingPong.java @@ -0,0 +1,155 @@ +package PingPong; + +import org.eclipse.etrice.runtime.java.messaging.MessageService; +import org.eclipse.etrice.runtime.java.messaging.RTServices; +import org.eclipse.etrice.runtime.java.messaging.Address; +import org.eclipse.etrice.runtime.java.messaging.IRTObject; +import org.eclipse.etrice.runtime.java.messaging.RTSystemServicesProtocol.*; +import org.eclipse.etrice.runtime.java.modelbase.ActorClassBase; +import org.eclipse.etrice.runtime.java.modelbase.SubSystemClassBase; +import org.eclipse.etrice.runtime.java.modelbase.InterfaceItemBase; + +import room.basic.service.timing.*; + + + +public class SubSystem_PingPong extends SubSystemClassBase{ + + + public SubSystem_PingPong(IRTObject parent, String name) { + super(parent, name); + } + + @Override + public void receiveEvent(InterfaceItemBase ifitem, int evt, Object data){ + } + + @Override + public void instantiateMessageServices(){ + + RTServices.getInstance().getMsgSvcCtrl().addMsgSvc(new MessageService(this, new Address(0, 0, 0),"MessageService_Main")); + RTServices.getInstance().getMsgSvcCtrl().addMsgSvc(new MessageService(this, new Address(0, 1, 0),"MessageService_mrPingThread", 5)); + RTServices.getInstance().getMsgSvcCtrl().addMsgSvc(new MessageService(this, new Address(0, 2, 0),"MessageService_mrPong1Thread", 5)); + } + + @Override + public void instantiateActors(){ + // all addresses + // Addresses for the Subsystem Systemport + Address addr_item_SystemPort_0 = new Address(0,0,110); + Address addr_item_SystemPort_1 = new Address(0,0,111); + Address addr_item_SystemPort_2 = new Address(0,0,112); + Address addr_item_SystemPort_3 = new Address(0,0,113); + + // actor instance /SubSystem_PingPong/application itself => Systemport Address + // TODOTJ: For each Actor, multiple addresses should be generated (actor?, systemport, debugport) + Address addr_item__SubSystem_PingPong_application = new Address(0,0,101); + // interface items of /SubSystem_PingPong/application + // actor instance /SubSystem_PingPong/application/MrPing itself => Systemport Address + // TODOTJ: For each Actor, multiple addresses should be generated (actor?, systemport, debugport) + Address addr_item__SubSystem_PingPong_application_MrPing = new Address(0,1,102); + // interface items of /SubSystem_PingPong/application/MrPing + Address addr_item__SubSystem_PingPong_application_MrPing_PingPongPort = new Address(0,1,103); + Address addr_item__SubSystem_PingPong_application_MrPing_timer = new Address(0,1,105); + // actor instance /SubSystem_PingPong/application/MrPong1 itself => Systemport Address + // TODOTJ: For each Actor, multiple addresses should be generated (actor?, systemport, debugport) + Address addr_item__SubSystem_PingPong_application_MrPong1 = new Address(0,2,106); + // interface items of /SubSystem_PingPong/application/MrPong1 + Address addr_item__SubSystem_PingPong_application_MrPong1_PingPongPort = new Address(0,2,107); + // actor instance /SubSystem_PingPong/services itself => Systemport Address + // TODOTJ: For each Actor, multiple addresses should be generated (actor?, systemport, debugport) + Address addr_item__SubSystem_PingPong_services = new Address(0,0,108); + // interface items of /SubSystem_PingPong/services + Address addr_item__SubSystem_PingPong_services_timeout_0 = new Address(0,0,109); + + // instantiate all actor instances + instances = new ActorClassBase[4]; + instances[0] = new PingPongTop( + this, + "application", + // own interface item addresses + new Address[][] {{addr_item__SubSystem_PingPong_application} + }, + // peer interface item addresses + new Address[][] {{addr_item_SystemPort_0} + } + ); + instances[1] = new MrPingActor( + instances[0], + "MrPing", + // own interface item addresses + new Address[][] {{addr_item__SubSystem_PingPong_application_MrPing}, + { + addr_item__SubSystem_PingPong_application_MrPing_PingPongPort + }, + { + addr_item__SubSystem_PingPong_application_MrPing_timer + } + }, + // peer interface item addresses + new Address[][] {{addr_item_SystemPort_1}, + { + addr_item__SubSystem_PingPong_application_MrPong1_PingPongPort + }, + { + addr_item__SubSystem_PingPong_services_timeout_0 + } + } + ); + instances[2] = new MrPongActor1( + instances[0], + "MrPong1", + // own interface item addresses + new Address[][] {{addr_item__SubSystem_PingPong_application_MrPong1}, + { + addr_item__SubSystem_PingPong_application_MrPong1_PingPongPort + } + }, + // peer interface item addresses + new Address[][] {{addr_item_SystemPort_2}, + { + addr_item__SubSystem_PingPong_application_MrPing_PingPongPort + } + } + ); + instances[3] = new ATimingService( + this, + "services", + // own interface item addresses + new Address[][] {{addr_item__SubSystem_PingPong_services}, + { + }, + { + addr_item__SubSystem_PingPong_services_timeout_0 + } + }, + // peer interface item addresses + new Address[][] {{addr_item_SystemPort_3}, + { + }, + { + addr_item__SubSystem_PingPong_application_MrPing_timer + } + } + ); + + // create the subsystem system port + RTSystemPort = new RTSystemServicesProtocolConjPortRepl(this, "RTSystemPort", + 0, //local ID + // own addresses + new Address[]{ + addr_item_SystemPort_0, + addr_item_SystemPort_1, + addr_item_SystemPort_2, + addr_item_SystemPort_3 + }, + // peer addresses + new Address[]{ + addr_item__SubSystem_PingPong_application, + addr_item__SubSystem_PingPong_application_MrPing, + addr_item__SubSystem_PingPong_application_MrPong1, + addr_item__SubSystem_PingPong_services + }); + + } +}; diff --git a/examples/org.eclipse.etrice.tutorials/src-gen/PingPong/SubSystem_PingPongRunner.java b/examples/org.eclipse.etrice.tutorials/src-gen/PingPong/SubSystem_PingPongRunner.java new file mode 100644 index 000000000..f9dd5f51c --- /dev/null +++ b/examples/org.eclipse.etrice.tutorials/src-gen/PingPong/SubSystem_PingPongRunner.java @@ -0,0 +1,36 @@ +/** + * @author generated by eTrice + * + * this class contains the main function running component SubSystem_PingPong + * it instantiates SubSystem_PingPong and starts and ends the lifecycle + */ + +package PingPong; + +import org.eclipse.etrice.runtime.java.modelbase.SubSystemRunnerBase; + +class SubSystem_PingPongRunner extends SubSystemRunnerBase { + + static SubSystem_PingPong main_component = new SubSystem_PingPong(null, "SubSystem_PingPong"); + + /** + * main function + * creates component and starts and stops the lifecycle + */ + public static void main(String[] args) { + + System.out.println("*** T H E B E G I N ***"); + + main_component.init(); // lifecycle init + main_component.start(); // lifecycle start + + // application runs until quit + waitForQuit(); + + // end the lifecycle + main_component.stop(); // lifecycle stop + main_component.destroy(); // lifecycle destroy + + System.out.println("*** T H E E N D ***"); + } +}; diff --git a/examples/org.eclipse.etrice.tutorials/src-gen/SendingData/MrPing.java b/examples/org.eclipse.etrice.tutorials/src-gen/SendingData/MrPing.java index 5ea196049..0eefcb416 100644 --- a/examples/org.eclipse.etrice.tutorials/src-gen/SendingData/MrPing.java +++ b/examples/org.eclipse.etrice.tutorials/src-gen/SendingData/MrPing.java @@ -120,8 +120,8 @@ public class MrPing extends ActorClassBase { switch(trigger) {
case TRIG_PingPongPort__pongSimple:
{ int data = (Integer) generic_data;
- if (data < 10
- )
+ if (data < 10
+ )
{
chain = CHAIN_TRANS_waitForPongSimple_TO_waitForPongSimple_BY_pongSimplePingPongPort_wait1;
catching_state = STATE_TOP;
@@ -246,12 +246,12 @@ public class MrPing extends ActorClassBase { //*** Action Codes
protected void action_TRANS_waitForPong_TO_waitForPong_BY_pongPingPongPort_wait2(InterfaceItemBase ifitem, DemoData data) {
printData(data);
- }
+ }
protected void action_TRANS_waitForPongSimple_TO_waitForPongSimple_BY_pongSimplePingPongPort_wait1(InterfaceItemBase ifitem, int data) {
// keep in mind that MrPong increments
PingPongPort.pingSimple(data);
System.out.printf("data: %d\n",data);
- }
+ }
protected void action_TRANS_waitForPongSimple_TO_waitForPong_BY_pongSimplePingPongPort(InterfaceItemBase ifitem, int data) {
System.out.printf("data: %d\n",data);
@@ -265,10 +265,10 @@ public class MrPing extends ActorClassBase { d.stringVal="some contents";
d.float64Val=3.141234;
PingPongPort.ping(d);
- }
+ }
protected void action_TRANS_INITIAL_TO__waitForPongSimple() {
PingPongPort.pingSimple(0);
- }
+ }
//******************************************
// END of generated code for FSM
diff --git a/examples/org.eclipse.etrice.tutorials/src-gen/SendingData/MrPong.java b/examples/org.eclipse.etrice.tutorials/src-gen/SendingData/MrPong.java index a674ffeb2..f389e72bc 100644 --- a/examples/org.eclipse.etrice.tutorials/src-gen/SendingData/MrPong.java +++ b/examples/org.eclipse.etrice.tutorials/src-gen/SendingData/MrPong.java @@ -209,10 +209,10 @@ public class MrPong extends ActorClassBase { //*** Action Codes
protected void action_TRANS_looping_TO_looping_BY_pingPingPongPort_tr0(InterfaceItemBase ifitem, DemoData data) {
PingPongPort.pong(data);
- }
+ }
protected void action_TRANS_looping_TO_looping_BY_pingSimplePingPongPort_tr1(InterfaceItemBase ifitem, int data) {
PingPongPort.pongSimple(data+1);
- }
+ }
//******************************************
// END of generated code for FSM
|