diff options
author | Thomas Schuetz | 2013-07-04 15:26:05 +0000 |
---|---|---|
committer | Thomas Schuetz | 2013-07-04 15:26:05 +0000 |
commit | a87f64917729115cd3876125bb1d1ef0ace36638 (patch) | |
tree | 9f4f7bc99a488f7d046a0e32d94ca1ff196ab4af /examples/org.eclipse.etrice.tutorials.simulators.trafficlight.example/src-gen/trafficlight/connector | |
parent | 66522cebc52744803349b6683f3dbc3922ebd241 (diff) | |
download | org.eclipse.etrice-a87f64917729115cd3876125bb1d1ef0ace36638.tar.gz org.eclipse.etrice-a87f64917729115cd3876125bb1d1ef0ace36638.tar.xz org.eclipse.etrice-a87f64917729115cd3876125bb1d1ef0ace36638.zip |
[tutorials] restructured tutorials, minor changes to modellibs in java
and c
Change-Id: Ib2c80b9764efb080cf041af9c716867f5caec127
Diffstat (limited to 'examples/org.eclipse.etrice.tutorials.simulators.trafficlight.example/src-gen/trafficlight/connector')
6 files changed, 0 insertions, 1306 deletions
diff --git a/examples/org.eclipse.etrice.tutorials.simulators.trafficlight.example/src-gen/trafficlight/connector/DMqttConfig.java b/examples/org.eclipse.etrice.tutorials.simulators.trafficlight.example/src-gen/trafficlight/connector/DMqttConfig.java deleted file mode 100644 index 937b501b0..000000000 --- a/examples/org.eclipse.etrice.tutorials.simulators.trafficlight.example/src-gen/trafficlight/connector/DMqttConfig.java +++ /dev/null @@ -1,55 +0,0 @@ -package trafficlight.connector; - -import static org.eclipse.etrice.runtime.java.etunit.EtUnit.*; - - - - -public class DMqttConfig { - - - /*--------------------- attributes ---------------------*/ - String url; - String id; - - /* --------------------- attribute setters and getters */ - public void setUrl (String url) { - this.url = url; - } - public String getUrl () { - return this.url; - } - public void setId (String id) { - this.id = id; - } - public String getId () { - return this.id; - } - - /*--------------------- operations ---------------------*/ - - // default constructor - public DMqttConfig() { - super(); - - // initialize attributes - this.setUrl(""); - this.setId(""); - } - - // constructor using fields - public DMqttConfig(String url, String id) { - super(); - - this.url = url; - this.id = id; - } - - // deep copy - public DMqttConfig deepCopy() { - DMqttConfig copy = new DMqttConfig(); - copy.url = url; - copy.id = id; - return copy; - } -}; diff --git a/examples/org.eclipse.etrice.tutorials.simulators.trafficlight.example/src-gen/trafficlight/connector/DMqttMessage.java b/examples/org.eclipse.etrice.tutorials.simulators.trafficlight.example/src-gen/trafficlight/connector/DMqttMessage.java deleted file mode 100644 index bb1d196e6..000000000 --- a/examples/org.eclipse.etrice.tutorials.simulators.trafficlight.example/src-gen/trafficlight/connector/DMqttMessage.java +++ /dev/null @@ -1,73 +0,0 @@ -package trafficlight.connector; - -import static org.eclipse.etrice.runtime.java.etunit.EtUnit.*; - - - - -public class DMqttMessage { - - - /*--------------------- attributes ---------------------*/ - String topic; - String payload; - boolean retained; - int qos; - - /* --------------------- attribute setters and getters */ - public void setTopic (String topic) { - this.topic = topic; - } - public String getTopic () { - return this.topic; - } - public void setPayload (String payload) { - this.payload = payload; - } - public String getPayload () { - return this.payload; - } - public void setRetained (boolean retained) { - this.retained = retained; - } - public boolean getRetained () { - return this.retained; - } - public void setQos (int qos) { - this.qos = qos; - } - public int getQos () { - return this.qos; - } - - /*--------------------- operations ---------------------*/ - - // default constructor - public DMqttMessage() { - super(); - - // initialize attributes - this.setTopic(""); - this.setPayload(""); - } - - // constructor using fields - public DMqttMessage(String topic, String payload, boolean retained, int qos) { - super(); - - this.topic = topic; - this.payload = payload; - this.retained = retained; - this.qos = qos; - } - - // deep copy - public DMqttMessage deepCopy() { - DMqttMessage copy = new DMqttMessage(); - copy.topic = topic; - copy.payload = payload; - copy.retained = retained; - copy.qos = qos; - return copy; - } -}; diff --git a/examples/org.eclipse.etrice.tutorials.simulators.trafficlight.example/src-gen/trafficlight/connector/MqttWrapperActor.java b/examples/org.eclipse.etrice.tutorials.simulators.trafficlight.example/src-gen/trafficlight/connector/MqttWrapperActor.java deleted file mode 100644 index c80c15bbb..000000000 --- a/examples/org.eclipse.etrice.tutorials.simulators.trafficlight.example/src-gen/trafficlight/connector/MqttWrapperActor.java +++ /dev/null @@ -1,286 +0,0 @@ -package trafficlight.connector; - -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 static org.eclipse.etrice.runtime.java.etunit.EtUnit.*; - - -import trafficlight.connector.PMqtt.*; - -/*--------------------- begin user code ---------------------*/ -import de.protos.etrice.automation.m2m.mqtt.*; -/*--------------------- end user code ---------------------*/ - - -public class MqttWrapperActor extends ActorClassBase { - - - //--------------------- ports - protected PMqttPort fct = null; - - //--------------------- saps - - //--------------------- services - - //--------------------- interface item IDs - public static final int IFITEM_fct = 1; - - /*--------------------- attributes ---------------------*/ - MqttWrapper connectionMQTT; - boolean open; - /*--------------------- operations ---------------------*/ - public void MqttWrapperActor_dtor() { - connectionMQTT.disconnect(); - } - - //--------------------- construction - public MqttWrapperActor(IRTObject parent, String name) { - super(parent, name); - setClassName("MqttWrapperActor"); - - // initialize attributes - this.setConnectionMQTT(new MqttWrapper()); - this.setOpen(false); - - // own ports - fct = new PMqttPort(this, "fct", IFITEM_fct); - - // own saps - - // own service implementations - - // sub actors - - } - - /* --------------------- attribute setters and getters */ - public void setConnectionMQTT (MqttWrapper connectionMQTT) { - this.connectionMQTT = connectionMQTT; - } - public MqttWrapper getConnectionMQTT () { - return this.connectionMQTT; - } - public void setOpen (boolean open) { - this.open = open; - } - public boolean getOpen () { - return this.open; - } - - - //--------------------- port getters - public PMqttPort getFct (){ - return this.fct; - } - - //--------------------- lifecycle functions - public void stop(){ - stopUser(); - super.stop(); - } - - public void destroy(){ - MqttWrapperActor_dtor(); - super.destroy(); - } - - /* state IDs */ - public static final int STATE_NotInitialized = 2; - public static final int STATE_Connected = 3; - public static final int STATE_MAX = 4; - - /* transition chains */ - public static final int CHAIN_TRANS_INITIAL_TO__NotInitialized = 1; - public static final int CHAIN_TRANS_tr0_FROM_NotInitialized_TO_cp0_BY_connectfct = 2; - public static final int CHAIN_TRANS_tr3_FROM_Connected_TO_Connected_BY_publishfct_tr3 = 3; - - /* triggers */ - public static final int POLLING = 0; - public static final int TRIG_fct__connect = IFITEM_fct + EVT_SHIFT*PMqtt.IN_connect; - public static final int TRIG_fct__publish = IFITEM_fct + EVT_SHIFT*PMqtt.IN_publish; - - // state names - protected static final String stateStrings[] = {"<no state>","<top>","NotInitialized", - "Connected" - }; - - // history - protected int history[] = {NO_STATE,NO_STATE,NO_STATE,NO_STATE}; - - private void setState(int new_state) { - DebuggingService.getInstance().addActorState(this,stateStrings[new_state]); - if (stateStrings[new_state]!="Idle") { - System.out.println("state switch of "+getInstancePath() + ": " - + stateStrings[this.state] + " -> " + stateStrings[new_state]); - } - this.state = new_state; - } - - /* Entry and Exit Codes */ - - /* Action Codes */ - protected void action_TRANS_tr0_FROM_NotInitialized_TO_cp0_BY_connectfct(InterfaceItemBase ifitem, DMqttConfig config) { - open=false; - connectionMQTT.connect(config.url, config.id); - //connectionMQTT.connect(new DMqttConfig("tcp://m2m.eclipse.org:1883", "eTrice-Paho-Tester")); - open=true; - } - protected void action_TRANS_tr2_FROM_cp0_TO_Connected_COND_tr2(InterfaceItemBase ifitem, DMqttConfig config) { - fct.connected(); - } - protected void action_TRANS_tr3_FROM_Connected_TO_Connected_BY_publishfct_tr3(InterfaceItemBase ifitem, DMqttMessage message) { - connectionMQTT.publishString(message.topic, message.payload, message.retained, message.qos); - } - - /** - * 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 - */ - private void exitTo(int current, int to) { - while (current!=to) { - switch (current) { - case STATE_NotInitialized: - this.history[STATE_TOP] = STATE_NotInitialized; - current = STATE_TOP; - break; - case STATE_Connected: - this.history[STATE_TOP] = STATE_Connected; - current = STATE_TOP; - break; - default: - /* should not occur */ - 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 either with a positive sign, that indicates to execute the state's entry code, or a negative sign vice versa - */ - private int executeTransitionChain(int chain, InterfaceItemBase ifitem, Object generic_data) { - switch (chain) { - case CHAIN_TRANS_INITIAL_TO__NotInitialized: - { - return STATE_NotInitialized; - } - case CHAIN_TRANS_tr0_FROM_NotInitialized_TO_cp0_BY_connectfct: - { - DMqttConfig config = (DMqttConfig) generic_data; - action_TRANS_tr0_FROM_NotInitialized_TO_cp0_BY_connectfct(ifitem, config); - if (open==true) { - action_TRANS_tr2_FROM_cp0_TO_Connected_COND_tr2(ifitem, config); - return STATE_Connected;} - else { - return STATE_NotInitialized;} - } - case CHAIN_TRANS_tr3_FROM_Connected_TO_Connected_BY_publishfct_tr3: - { - DMqttMessage message = (DMqttMessage) generic_data; - action_TRANS_tr3_FROM_Connected_TO_Connected_BY_publishfct_tr3(ifitem, message); - return STATE_Connected; - } - default: - /* should not occur */ - break; - } - 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 - * @return - the ID of the final leaf state - */ - private int enterHistory(int state) { - boolean skip_entry = false; - if (state >= STATE_MAX) { - state = (state - STATE_MAX); - skip_entry = true; - } - while (true) { - switch (state) { - case STATE_NotInitialized: - /* in leaf state: return state id */ - return STATE_NotInitialized; - case STATE_Connected: - /* in leaf state: return state id */ - return STATE_Connected; - case STATE_TOP: - state = this.history[STATE_TOP]; - break; - default: - /* should not occur */ - break; - } - skip_entry = false; - } - /* return NO_STATE; // required by CDT but detected as unreachable by JDT because of while (true) */ - } - - public void executeInitTransition() { - int chain = CHAIN_TRANS_INITIAL_TO__NotInitialized; - int next = executeTransitionChain(chain, null, null); - next = enterHistory(next); - setState(next); - } - - /* receiveEvent contains the main implementation of the FSM */ - 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; - - if (!handleSystemEvent(ifitem, evt, generic_data)) { - switch (getState()) { - case STATE_NotInitialized: - switch(trigger) { - case TRIG_fct__connect: - { - chain = CHAIN_TRANS_tr0_FROM_NotInitialized_TO_cp0_BY_connectfct; - catching_state = STATE_TOP; - } - break; - default: - /* should not occur */ - break; - } - break; - case STATE_Connected: - switch(trigger) { - case TRIG_fct__publish: - { - chain = CHAIN_TRANS_tr3_FROM_Connected_TO_Connected_BY_publishfct_tr3; - catching_state = STATE_TOP; - } - break; - default: - /* should not occur */ - break; - } - break; - default: - /* should not occur */ - break; - } - } - if (chain != NOT_CAUGHT) { - exitTo(getState(), catching_state); - { - int next = executeTransitionChain(chain, ifitem, generic_data); - next = enterHistory(next); - setState(next); - } - } - } -}; diff --git a/examples/org.eclipse.etrice.tutorials.simulators.trafficlight.example/src-gen/trafficlight/connector/PMqtt.java b/examples/org.eclipse.etrice.tutorials.simulators.trafficlight.example/src-gen/trafficlight/connector/PMqtt.java deleted file mode 100644 index b3a2b48f0..000000000 --- a/examples/org.eclipse.etrice.tutorials.simulators.trafficlight.example/src-gen/trafficlight/connector/PMqtt.java +++ /dev/null @@ -1,194 +0,0 @@ -package trafficlight.connector; - -import org.eclipse.etrice.runtime.java.messaging.Message; -import org.eclipse.etrice.runtime.java.modelbase.EventMessage; -import org.eclipse.etrice.runtime.java.modelbase.EventWithDataMessage; -import org.eclipse.etrice.runtime.java.modelbase.IEventReceiver; -import org.eclipse.etrice.runtime.java.modelbase.InterfaceItemBase; -import org.eclipse.etrice.runtime.java.modelbase.PortBase; -import org.eclipse.etrice.runtime.java.modelbase.ReplicatedPortBase; -import org.eclipse.etrice.runtime.java.debugging.DebuggingService; -import static org.eclipse.etrice.runtime.java.etunit.EtUnit.*; - - - -public class PMqtt { - // message IDs - public static final int MSG_MIN = 0; - public static final int OUT_connected = 1; - public static final int IN_connect = 2; - public static final int IN_publish = 3; - public static final int MSG_MAX = 4; - - - private static String messageStrings[] = {"MIN", "connected", "connect","publish","MAX"}; - - public String getMessageString(int msg_id) { - if (msg_id<MSG_MIN || 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 PMqttPort extends PortBase { - // constructors - public PMqttPort(IEventReceiver actor, String name, int localId) { - this(actor, name, localId, 0); - } - public PMqttPort(IEventReceiver actor, String name, int localId, int idx) { - super(actor, name, localId, idx); - DebuggingService.getInstance().addPortInstance(this); - } - - @Override - public void receive(Message m) { - if (!(m instanceof EventMessage)) - return; - EventMessage msg = (EventMessage) m; - if (0 < msg.getEvtId() && msg.getEvtId() < MSG_MAX) { - if (messageStrings[msg.getEvtId()] != "timerTick"){ - 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 connected() { - if (messageStrings[ OUT_connected] != "timerTick") { - DebuggingService.getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(), messageStrings[OUT_connected]); - } - if (getPeerAddress()!=null) - getPeerMsgReceiver().receive(new EventMessage(getPeerAddress(), OUT_connected)); - } - } - - // replicated port class - static public class PMqttReplPort extends ReplicatedPortBase { - - public PMqttReplPort(IEventReceiver actor, String name, int localId) { - super(actor, name, localId); - } - - public int getReplication() { - return getNInterfaceItems(); - } - - public int getIndexOf(InterfaceItemBase ifitem){ - return ifitem.getIdx(); - } - - public PMqttPort get(int idx) { - return (PMqttPort) getInterfaceItem(idx); - } - - protected InterfaceItemBase createInterfaceItem(IEventReceiver rcv, String name, int lid, int idx) { - return new PMqttPort(rcv, name, lid, idx); - } - - // outgoing messages - public void connected(){ - for (int i=0; i<getReplication(); ++i) { - get(i).connected(); - } - } - } - - - // port class - static public class PMqttConjPort extends PortBase { - // constructors - public PMqttConjPort(IEventReceiver actor, String name, int localId) { - this(actor, name, localId, 0); - } - public PMqttConjPort(IEventReceiver actor, String name, int localId, int idx) { - super(actor, name, localId, idx); - DebuggingService.getInstance().addPortInstance(this); - } - - @Override - public void receive(Message m) { - if (!(m instanceof EventMessage)) - return; - EventMessage msg = (EventMessage) m; - if (0 < msg.getEvtId() && msg.getEvtId() < MSG_MAX) { - if (messageStrings[msg.getEvtId()] != "timerTick"){ - 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 connect(DMqttConfig config) { - if (messageStrings[ IN_connect] != "timerTick") { - DebuggingService.getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(), messageStrings[IN_connect]); - } - if (getPeerAddress()!=null) - getPeerMsgReceiver().receive(new EventWithDataMessage(getPeerAddress(), IN_connect, config.deepCopy())); - } - public void connect(String url, String id) { - connect(new DMqttConfig(url, id)); - } - public void publish(DMqttMessage message) { - if (messageStrings[ IN_publish] != "timerTick") { - DebuggingService.getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(), messageStrings[IN_publish]); - } - if (getPeerAddress()!=null) - getPeerMsgReceiver().receive(new EventWithDataMessage(getPeerAddress(), IN_publish, message.deepCopy())); - } - public void publish(String topic, String payload, boolean retained, int qos) { - publish(new DMqttMessage(topic, payload, retained, qos)); - } - } - - // replicated port class - static public class PMqttConjReplPort extends ReplicatedPortBase { - - public PMqttConjReplPort(IEventReceiver actor, String name, int localId) { - super(actor, name, localId); - } - - public int getReplication() { - return getNInterfaceItems(); - } - - public int getIndexOf(InterfaceItemBase ifitem){ - return ifitem.getIdx(); - } - - public PMqttConjPort get(int idx) { - return (PMqttConjPort) getInterfaceItem(idx); - } - - protected InterfaceItemBase createInterfaceItem(IEventReceiver rcv, String name, int lid, int idx) { - return new PMqttConjPort(rcv, name, lid, idx); - } - - // incoming messages - public void connect(DMqttConfig config){ - for (int i=0; i<getReplication(); ++i) { - get(i).connect( config); - } - } - public void publish(DMqttMessage message){ - for (int i=0; i<getReplication(); ++i) { - get(i).publish( message); - } - } - } - -} diff --git a/examples/org.eclipse.etrice.tutorials.simulators.trafficlight.example/src-gen/trafficlight/connector/PTrafficLightInterface.java b/examples/org.eclipse.etrice.tutorials.simulators.trafficlight.example/src-gen/trafficlight/connector/PTrafficLightInterface.java deleted file mode 100644 index 3a6be752d..000000000 --- a/examples/org.eclipse.etrice.tutorials.simulators.trafficlight.example/src-gen/trafficlight/connector/PTrafficLightInterface.java +++ /dev/null @@ -1,279 +0,0 @@ -package trafficlight.connector; - -import org.eclipse.etrice.runtime.java.messaging.Message; -import org.eclipse.etrice.runtime.java.modelbase.EventMessage; -import org.eclipse.etrice.runtime.java.modelbase.EventWithDataMessage; -import org.eclipse.etrice.runtime.java.modelbase.IEventReceiver; -import org.eclipse.etrice.runtime.java.modelbase.InterfaceItemBase; -import org.eclipse.etrice.runtime.java.modelbase.PortBase; -import org.eclipse.etrice.runtime.java.modelbase.ReplicatedPortBase; -import org.eclipse.etrice.runtime.java.debugging.DebuggingService; -import static org.eclipse.etrice.runtime.java.etunit.EtUnit.*; - - - -public class PTrafficLightInterface { - // message IDs - public static final int MSG_MIN = 0; - public static final int OUT_initialized = 1; - public static final int OUT_request = 2; - public static final int IN_initialize = 3; - public static final int IN_pedRed = 4; - public static final int IN_pedGreen = 5; - public static final int IN_pedOff = 6; - public static final int IN_carRed = 7; - public static final int IN_carYellow = 8; - public static final int IN_carGreen = 9; - public static final int IN_carOff = 10; - public static final int MSG_MAX = 11; - - - private static String messageStrings[] = {"MIN", "initialized","request", "initialize","pedRed","pedGreen","pedOff","carRed","carYellow","carGreen","carOff","MAX"}; - - public String getMessageString(int msg_id) { - if (msg_id<MSG_MIN || 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 PTrafficLightInterfacePort extends PortBase { - // constructors - public PTrafficLightInterfacePort(IEventReceiver actor, String name, int localId) { - this(actor, name, localId, 0); - } - public PTrafficLightInterfacePort(IEventReceiver actor, String name, int localId, int idx) { - super(actor, name, localId, idx); - DebuggingService.getInstance().addPortInstance(this); - } - - @Override - public void receive(Message m) { - if (!(m instanceof EventMessage)) - return; - EventMessage msg = (EventMessage) m; - if (0 < msg.getEvtId() && msg.getEvtId() < MSG_MAX) { - if (messageStrings[msg.getEvtId()] != "timerTick"){ - 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 initialized() { - if (messageStrings[ OUT_initialized] != "timerTick") { - DebuggingService.getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(), messageStrings[OUT_initialized]); - } - if (getPeerAddress()!=null) - getPeerMsgReceiver().receive(new EventMessage(getPeerAddress(), OUT_initialized)); - } - public void request() { - if (messageStrings[ OUT_request] != "timerTick") { - DebuggingService.getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(), messageStrings[OUT_request]); - } - if (getPeerAddress()!=null) - getPeerMsgReceiver().receive(new EventMessage(getPeerAddress(), OUT_request)); - } - } - - // replicated port class - static public class PTrafficLightInterfaceReplPort extends ReplicatedPortBase { - - public PTrafficLightInterfaceReplPort(IEventReceiver actor, String name, int localId) { - super(actor, name, localId); - } - - public int getReplication() { - return getNInterfaceItems(); - } - - public int getIndexOf(InterfaceItemBase ifitem){ - return ifitem.getIdx(); - } - - public PTrafficLightInterfacePort get(int idx) { - return (PTrafficLightInterfacePort) getInterfaceItem(idx); - } - - protected InterfaceItemBase createInterfaceItem(IEventReceiver rcv, String name, int lid, int idx) { - return new PTrafficLightInterfacePort(rcv, name, lid, idx); - } - - // outgoing messages - public void initialized(){ - for (int i=0; i<getReplication(); ++i) { - get(i).initialized(); - } - } - public void request(){ - for (int i=0; i<getReplication(); ++i) { - get(i).request(); - } - } - } - - - // port class - static public class PTrafficLightInterfaceConjPort extends PortBase { - // constructors - public PTrafficLightInterfaceConjPort(IEventReceiver actor, String name, int localId) { - this(actor, name, localId, 0); - } - public PTrafficLightInterfaceConjPort(IEventReceiver actor, String name, int localId, int idx) { - super(actor, name, localId, idx); - DebuggingService.getInstance().addPortInstance(this); - } - - @Override - public void receive(Message m) { - if (!(m instanceof EventMessage)) - return; - EventMessage msg = (EventMessage) m; - if (0 < msg.getEvtId() && msg.getEvtId() < MSG_MAX) { - if (messageStrings[msg.getEvtId()] != "timerTick"){ - 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 initialize() { - if (messageStrings[ IN_initialize] != "timerTick") { - DebuggingService.getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(), messageStrings[IN_initialize]); - } - if (getPeerAddress()!=null) - getPeerMsgReceiver().receive(new EventMessage(getPeerAddress(), IN_initialize)); - } - public void pedRed() { - if (messageStrings[ IN_pedRed] != "timerTick") { - DebuggingService.getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(), messageStrings[IN_pedRed]); - } - if (getPeerAddress()!=null) - getPeerMsgReceiver().receive(new EventMessage(getPeerAddress(), IN_pedRed)); - } - public void pedGreen() { - if (messageStrings[ IN_pedGreen] != "timerTick") { - DebuggingService.getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(), messageStrings[IN_pedGreen]); - } - if (getPeerAddress()!=null) - getPeerMsgReceiver().receive(new EventMessage(getPeerAddress(), IN_pedGreen)); - } - public void pedOff() { - if (messageStrings[ IN_pedOff] != "timerTick") { - DebuggingService.getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(), messageStrings[IN_pedOff]); - } - if (getPeerAddress()!=null) - getPeerMsgReceiver().receive(new EventMessage(getPeerAddress(), IN_pedOff)); - } - public void carRed() { - if (messageStrings[ IN_carRed] != "timerTick") { - DebuggingService.getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(), messageStrings[IN_carRed]); - } - if (getPeerAddress()!=null) - getPeerMsgReceiver().receive(new EventMessage(getPeerAddress(), IN_carRed)); - } - public void carYellow() { - if (messageStrings[ IN_carYellow] != "timerTick") { - DebuggingService.getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(), messageStrings[IN_carYellow]); - } - if (getPeerAddress()!=null) - getPeerMsgReceiver().receive(new EventMessage(getPeerAddress(), IN_carYellow)); - } - public void carGreen() { - if (messageStrings[ IN_carGreen] != "timerTick") { - DebuggingService.getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(), messageStrings[IN_carGreen]); - } - if (getPeerAddress()!=null) - getPeerMsgReceiver().receive(new EventMessage(getPeerAddress(), IN_carGreen)); - } - public void carOff() { - if (messageStrings[ IN_carOff] != "timerTick") { - DebuggingService.getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(), messageStrings[IN_carOff]); - } - if (getPeerAddress()!=null) - getPeerMsgReceiver().receive(new EventMessage(getPeerAddress(), IN_carOff)); - } - } - - // replicated port class - static public class PTrafficLightInterfaceConjReplPort extends ReplicatedPortBase { - - public PTrafficLightInterfaceConjReplPort(IEventReceiver actor, String name, int localId) { - super(actor, name, localId); - } - - public int getReplication() { - return getNInterfaceItems(); - } - - public int getIndexOf(InterfaceItemBase ifitem){ - return ifitem.getIdx(); - } - - public PTrafficLightInterfaceConjPort get(int idx) { - return (PTrafficLightInterfaceConjPort) getInterfaceItem(idx); - } - - protected InterfaceItemBase createInterfaceItem(IEventReceiver rcv, String name, int lid, int idx) { - return new PTrafficLightInterfaceConjPort(rcv, name, lid, idx); - } - - // incoming messages - public void initialize(){ - for (int i=0; i<getReplication(); ++i) { - get(i).initialize(); - } - } - public void pedRed(){ - for (int i=0; i<getReplication(); ++i) { - get(i).pedRed(); - } - } - public void pedGreen(){ - for (int i=0; i<getReplication(); ++i) { - get(i).pedGreen(); - } - } - public void pedOff(){ - for (int i=0; i<getReplication(); ++i) { - get(i).pedOff(); - } - } - public void carRed(){ - for (int i=0; i<getReplication(); ++i) { - get(i).carRed(); - } - } - public void carYellow(){ - for (int i=0; i<getReplication(); ++i) { - get(i).carYellow(); - } - } - public void carGreen(){ - for (int i=0; i<getReplication(); ++i) { - get(i).carGreen(); - } - } - public void carOff(){ - for (int i=0; i<getReplication(); ++i) { - get(i).carOff(); - } - } - } - -} diff --git a/examples/org.eclipse.etrice.tutorials.simulators.trafficlight.example/src-gen/trafficlight/connector/TrafficLightInterface.java b/examples/org.eclipse.etrice.tutorials.simulators.trafficlight.example/src-gen/trafficlight/connector/TrafficLightInterface.java deleted file mode 100644 index 52d3fbf85..000000000 --- a/examples/org.eclipse.etrice.tutorials.simulators.trafficlight.example/src-gen/trafficlight/connector/TrafficLightInterface.java +++ /dev/null @@ -1,419 +0,0 @@ -package trafficlight.connector; - -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 static org.eclipse.etrice.runtime.java.etunit.EtUnit.*; - -import room.basic.service.tcp.*; - -import room.basic.service.tcp.PTcpControl.*; -import room.basic.service.tcp.PTcpPayload.*; -import trafficlight.connector.PTrafficLightInterface.*; - - - -public class TrafficLightInterface extends ActorClassBase { - - - //--------------------- ports - protected PTcpPayloadConjPort payload = null; - protected PTcpControlConjPort control = null; - protected PTrafficLightInterfacePort fct = null; - - //--------------------- saps - - //--------------------- services - - //--------------------- interface item IDs - public static final int IFITEM_payload = 1; - public static final int IFITEM_control = 2; - public static final int IFITEM_fct = 3; - - /*--------------------- attributes ---------------------*/ - DTcpControl tcpConfig; - /*--------------------- operations ---------------------*/ - public void sendString(String data) { - payload.send(new DTcpPayload(1, data.length(), data.getBytes())); - } - - //--------------------- construction - public TrafficLightInterface(IRTObject parent, String name) { - super(parent, name); - setClassName("TrafficLightInterface"); - - // initialize attributes - this.setTcpConfig(new DTcpControl()); - - // own ports - payload = new PTcpPayloadConjPort(this, "payload", IFITEM_payload); - control = new PTcpControlConjPort(this, "control", IFITEM_control); - fct = new PTrafficLightInterfacePort(this, "fct", IFITEM_fct); - - // own saps - - // own service implementations - - // sub actors - - } - - /* --------------------- attribute setters and getters */ - public void setTcpConfig (DTcpControl tcpConfig) { - this.tcpConfig = tcpConfig; - } - public DTcpControl getTcpConfig () { - return this.tcpConfig; - } - - - //--------------------- port getters - public PTcpPayloadConjPort getPayload (){ - return this.payload; - } - public PTcpControlConjPort getControl (){ - return this.control; - } - public PTrafficLightInterfacePort getFct (){ - return this.fct; - } - - //--------------------- lifecycle functions - public void stop(){ - stopUser(); - super.stop(); - } - - - /* state IDs */ - public static final int STATE_Uninitialized = 2; - public static final int STATE_Initializing = 3; - public static final int STATE_Running = 4; - public static final int STATE_MAX = 5; - - /* transition chains */ - public static final int CHAIN_TRANS_INITIAL_TO__Uninitialized = 1; - public static final int CHAIN_TRANS_tr0_FROM_Uninitialized_TO_Initializing_BY_initializefct = 2; - public static final int CHAIN_TRANS_tr1_FROM_Initializing_TO_Running_BY_establishedcontrol = 3; - public static final int CHAIN_TRANS_tr2_FROM_Running_TO_Running_BY_pedRedfct_tr2 = 4; - public static final int CHAIN_TRANS_tr3_FROM_Running_TO_Running_BY_pedOfffct_tr3 = 5; - public static final int CHAIN_TRANS_tr4_FROM_Running_TO_Running_BY_pedGreenfct_tr4 = 6; - public static final int CHAIN_TRANS_tr5_FROM_Running_TO_Running_BY_carRedfct_tr5 = 7; - public static final int CHAIN_TRANS_tr6_FROM_Running_TO_Running_BY_carYellowfct_tr6 = 8; - public static final int CHAIN_TRANS_tr7_FROM_Running_TO_Running_BY_carGreenfct_tr7 = 9; - public static final int CHAIN_TRANS_tr8_FROM_Running_TO_Running_BY_carOfffct_tr8 = 10; - public static final int CHAIN_TRANS_tr9_FROM_Running_TO_Running_BY_receivepayload_tr9 = 11; - - /* triggers */ - public static final int POLLING = 0; - public static final int TRIG_control__established = IFITEM_control + EVT_SHIFT*PTcpControl.OUT_established; - public static final int TRIG_fct__carGreen = IFITEM_fct + EVT_SHIFT*PTrafficLightInterface.IN_carGreen; - public static final int TRIG_fct__carOff = IFITEM_fct + EVT_SHIFT*PTrafficLightInterface.IN_carOff; - public static final int TRIG_fct__carRed = IFITEM_fct + EVT_SHIFT*PTrafficLightInterface.IN_carRed; - public static final int TRIG_fct__carYellow = IFITEM_fct + EVT_SHIFT*PTrafficLightInterface.IN_carYellow; - public static final int TRIG_fct__initialize = IFITEM_fct + EVT_SHIFT*PTrafficLightInterface.IN_initialize; - public static final int TRIG_fct__pedGreen = IFITEM_fct + EVT_SHIFT*PTrafficLightInterface.IN_pedGreen; - public static final int TRIG_fct__pedOff = IFITEM_fct + EVT_SHIFT*PTrafficLightInterface.IN_pedOff; - public static final int TRIG_fct__pedRed = IFITEM_fct + EVT_SHIFT*PTrafficLightInterface.IN_pedRed; - public static final int TRIG_payload__receive = IFITEM_payload + EVT_SHIFT*PTcpPayload.OUT_receive; - - // state names - protected static final String stateStrings[] = {"<no state>","<top>","Uninitialized", - "Initializing", - "Running" - }; - - // history - protected int history[] = {NO_STATE,NO_STATE,NO_STATE,NO_STATE,NO_STATE}; - - private void setState(int new_state) { - DebuggingService.getInstance().addActorState(this,stateStrings[new_state]); - if (stateStrings[new_state]!="Idle") { - System.out.println("state switch of "+getInstancePath() + ": " - + stateStrings[this.state] + " -> " + stateStrings[new_state]); - } - this.state = new_state; - } - - /* Entry and Exit Codes */ - - /* Action Codes */ - protected void action_TRANS_tr0_FROM_Uninitialized_TO_Initializing_BY_initializefct(InterfaceItemBase ifitem) { - control.open(tcpConfig); - } - protected void action_TRANS_tr1_FROM_Initializing_TO_Running_BY_establishedcontrol(InterfaceItemBase ifitem) { - fct.initialized(); - } - protected void action_TRANS_tr2_FROM_Running_TO_Running_BY_pedRedfct_tr2(InterfaceItemBase ifitem) { - sendString(new String("pedLights=red\n")); - } - protected void action_TRANS_tr3_FROM_Running_TO_Running_BY_pedOfffct_tr3(InterfaceItemBase ifitem) { - sendString(new String("pedLights=off\n")); - } - protected void action_TRANS_tr4_FROM_Running_TO_Running_BY_pedGreenfct_tr4(InterfaceItemBase ifitem) { - sendString(new String("pedLights=green\n")); - } - protected void action_TRANS_tr5_FROM_Running_TO_Running_BY_carRedfct_tr5(InterfaceItemBase ifitem) { - sendString(new String("carLights=red\n")); - } - protected void action_TRANS_tr6_FROM_Running_TO_Running_BY_carYellowfct_tr6(InterfaceItemBase ifitem) { - sendString(new String("carLights=yellow\n")); - } - protected void action_TRANS_tr7_FROM_Running_TO_Running_BY_carGreenfct_tr7(InterfaceItemBase ifitem) { - sendString(new String("carLights=green\n")); - } - protected void action_TRANS_tr8_FROM_Running_TO_Running_BY_carOfffct_tr8(InterfaceItemBase ifitem) { - sendString(new String("carLights=off\n")); - } - protected void action_TRANS_tr9_FROM_Running_TO_Running_BY_receivepayload_tr9(InterfaceItemBase ifitem, DTcpPayload data) { - fct.request(); - } - - /** - * 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 - */ - private void exitTo(int current, int to) { - while (current!=to) { - switch (current) { - case STATE_Uninitialized: - this.history[STATE_TOP] = STATE_Uninitialized; - current = STATE_TOP; - break; - case STATE_Initializing: - this.history[STATE_TOP] = STATE_Initializing; - current = STATE_TOP; - break; - case STATE_Running: - this.history[STATE_TOP] = STATE_Running; - current = STATE_TOP; - break; - default: - /* should not occur */ - 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 either with a positive sign, that indicates to execute the state's entry code, or a negative sign vice versa - */ - private int executeTransitionChain(int chain, InterfaceItemBase ifitem, Object generic_data) { - switch (chain) { - case CHAIN_TRANS_INITIAL_TO__Uninitialized: - { - return STATE_Uninitialized; - } - case CHAIN_TRANS_tr0_FROM_Uninitialized_TO_Initializing_BY_initializefct: - { - action_TRANS_tr0_FROM_Uninitialized_TO_Initializing_BY_initializefct(ifitem); - return STATE_Initializing; - } - case CHAIN_TRANS_tr1_FROM_Initializing_TO_Running_BY_establishedcontrol: - { - action_TRANS_tr1_FROM_Initializing_TO_Running_BY_establishedcontrol(ifitem); - return STATE_Running; - } - case CHAIN_TRANS_tr2_FROM_Running_TO_Running_BY_pedRedfct_tr2: - { - action_TRANS_tr2_FROM_Running_TO_Running_BY_pedRedfct_tr2(ifitem); - return STATE_Running; - } - case CHAIN_TRANS_tr3_FROM_Running_TO_Running_BY_pedOfffct_tr3: - { - action_TRANS_tr3_FROM_Running_TO_Running_BY_pedOfffct_tr3(ifitem); - return STATE_Running; - } - case CHAIN_TRANS_tr4_FROM_Running_TO_Running_BY_pedGreenfct_tr4: - { - action_TRANS_tr4_FROM_Running_TO_Running_BY_pedGreenfct_tr4(ifitem); - return STATE_Running; - } - case CHAIN_TRANS_tr5_FROM_Running_TO_Running_BY_carRedfct_tr5: - { - action_TRANS_tr5_FROM_Running_TO_Running_BY_carRedfct_tr5(ifitem); - return STATE_Running; - } - case CHAIN_TRANS_tr6_FROM_Running_TO_Running_BY_carYellowfct_tr6: - { - action_TRANS_tr6_FROM_Running_TO_Running_BY_carYellowfct_tr6(ifitem); - return STATE_Running; - } - case CHAIN_TRANS_tr7_FROM_Running_TO_Running_BY_carGreenfct_tr7: - { - action_TRANS_tr7_FROM_Running_TO_Running_BY_carGreenfct_tr7(ifitem); - return STATE_Running; - } - case CHAIN_TRANS_tr8_FROM_Running_TO_Running_BY_carOfffct_tr8: - { - action_TRANS_tr8_FROM_Running_TO_Running_BY_carOfffct_tr8(ifitem); - return STATE_Running; - } - case CHAIN_TRANS_tr9_FROM_Running_TO_Running_BY_receivepayload_tr9: - { - DTcpPayload data = (DTcpPayload) generic_data; - action_TRANS_tr9_FROM_Running_TO_Running_BY_receivepayload_tr9(ifitem, data); - return STATE_Running; - } - default: - /* should not occur */ - break; - } - 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 - * @return - the ID of the final leaf state - */ - private int enterHistory(int state) { - boolean skip_entry = false; - if (state >= STATE_MAX) { - state = (state - STATE_MAX); - skip_entry = true; - } - while (true) { - switch (state) { - case STATE_Uninitialized: - /* in leaf state: return state id */ - return STATE_Uninitialized; - case STATE_Initializing: - /* in leaf state: return state id */ - return STATE_Initializing; - case STATE_Running: - /* in leaf state: return state id */ - return STATE_Running; - case STATE_TOP: - state = this.history[STATE_TOP]; - break; - default: - /* should not occur */ - break; - } - skip_entry = false; - } - /* return NO_STATE; // required by CDT but detected as unreachable by JDT because of while (true) */ - } - - public void executeInitTransition() { - int chain = CHAIN_TRANS_INITIAL_TO__Uninitialized; - int next = executeTransitionChain(chain, null, null); - next = enterHistory(next); - setState(next); - } - - /* receiveEvent contains the main implementation of the FSM */ - 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; - - if (!handleSystemEvent(ifitem, evt, generic_data)) { - switch (getState()) { - case STATE_Uninitialized: - switch(trigger) { - case TRIG_fct__initialize: - { - chain = CHAIN_TRANS_tr0_FROM_Uninitialized_TO_Initializing_BY_initializefct; - catching_state = STATE_TOP; - } - break; - default: - /* should not occur */ - break; - } - break; - case STATE_Initializing: - switch(trigger) { - case TRIG_control__established: - { - chain = CHAIN_TRANS_tr1_FROM_Initializing_TO_Running_BY_establishedcontrol; - catching_state = STATE_TOP; - } - break; - default: - /* should not occur */ - break; - } - break; - case STATE_Running: - switch(trigger) { - case TRIG_fct__pedRed: - { - chain = CHAIN_TRANS_tr2_FROM_Running_TO_Running_BY_pedRedfct_tr2; - catching_state = STATE_TOP; - } - break; - case TRIG_fct__pedOff: - { - chain = CHAIN_TRANS_tr3_FROM_Running_TO_Running_BY_pedOfffct_tr3; - catching_state = STATE_TOP; - } - break; - case TRIG_fct__pedGreen: - { - chain = CHAIN_TRANS_tr4_FROM_Running_TO_Running_BY_pedGreenfct_tr4; - catching_state = STATE_TOP; - } - break; - case TRIG_fct__carRed: - { - chain = CHAIN_TRANS_tr5_FROM_Running_TO_Running_BY_carRedfct_tr5; - catching_state = STATE_TOP; - } - break; - case TRIG_fct__carYellow: - { - chain = CHAIN_TRANS_tr6_FROM_Running_TO_Running_BY_carYellowfct_tr6; - catching_state = STATE_TOP; - } - break; - case TRIG_fct__carGreen: - { - chain = CHAIN_TRANS_tr7_FROM_Running_TO_Running_BY_carGreenfct_tr7; - catching_state = STATE_TOP; - } - break; - case TRIG_fct__carOff: - { - chain = CHAIN_TRANS_tr8_FROM_Running_TO_Running_BY_carOfffct_tr8; - catching_state = STATE_TOP; - } - break; - case TRIG_payload__receive: - { - chain = CHAIN_TRANS_tr9_FROM_Running_TO_Running_BY_receivepayload_tr9; - catching_state = STATE_TOP; - } - break; - default: - /* should not occur */ - break; - } - break; - default: - /* should not occur */ - break; - } - } - if (chain != NOT_CAUGHT) { - exitTo(getState(), catching_state); - { - int next = executeTransitionChain(chain, ifitem, generic_data); - next = enterHistory(next); - setState(next); - } - } - } -}; |