Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/org.eclipse.etrice.modellib.cpp/src-gen/room/basic/service')
-rw-r--r--runtime/org.eclipse.etrice.modellib.cpp/src-gen/room/basic/service/timing/ATimingService.cpp526
-rw-r--r--runtime/org.eclipse.etrice.modellib.cpp/src-gen/room/basic/service/timing/ATimingService.h524
-rw-r--r--runtime/org.eclipse.etrice.modellib.cpp/src-gen/room/basic/service/timing/PTimer.cpp484
-rw-r--r--runtime/org.eclipse.etrice.modellib.cpp/src-gen/room/basic/service/timing/PTimer.h278
4 files changed, 906 insertions, 906 deletions
diff --git a/runtime/org.eclipse.etrice.modellib.cpp/src-gen/room/basic/service/timing/ATimingService.cpp b/runtime/org.eclipse.etrice.modellib.cpp/src-gen/room/basic/service/timing/ATimingService.cpp
index 4e306ec55..1bbb17da9 100644
--- a/runtime/org.eclipse.etrice.modellib.cpp/src-gen/room/basic/service/timing/ATimingService.cpp
+++ b/runtime/org.eclipse.etrice.modellib.cpp/src-gen/room/basic/service/timing/ATimingService.cpp
@@ -1,263 +1,263 @@
-/**
- * @author generated by eTrice
- *
- * Source File of ActorClass ATimingService
- *
- */
-
-#include "ATimingService.h"
-#include "common/debugging/DebuggingService.h"
-#include <iostream>
-
-using namespace etRuntime;
-
-
-ATimingService::ATimingService(etRuntime::IRTObject* parent, std::string name, const std::vector<std::vector<etRuntime::Address> >& port_addr,
- const std::vector<std::vector<etRuntime::Address> >& peer_addr)
-: ActorClassBase( parent, name, port_addr[0][0], peer_addr[0][0]),
-timer(*this, this, "timer", IFITEM_timer, port_addr[IFITEM_timer], peer_addr[IFITEM_timer]),
-tcbs(),
-usedTcbsRoot(0),
-freeTcbsRoot(0)
-{
- history = new int[s_numberOfStates];
- for (int i = 0; i < s_numberOfStates; i++) {
- history[i] = NO_STATE;
- }
- setClassName("ATimingService");
- // initialize attributes
- for (int i=0;i<10;i++){
- tcbs[i] = etTimerControlBlock();
- }
-
- getMsgsvc()->addAsyncActor(*this);
-}
-
-void ATimingService::init(){
- initUser();
-}
-
-void ATimingService::start(){
- startUser();
-}
-
-void ATimingService::stop(){
- stopUser();
-}
-
-void ATimingService::destroy(){
-}
-
-
-std::string ATimingService::s_stateStrings[] = {"<no state>","<top>","Operational"
-};
-const int ATimingService::s_numberOfStates = 3;
-
-void ATimingService::setState(int new_state) {
- DebuggingService::getInstance().addActorState(*this, s_stateStrings[new_state]);
- if (s_stateStrings[new_state]!="Idle") {
- std::cout << getInstancePath() << " -> " << s_stateStrings[new_state] << std::endl;
- }
- m_state = new_state;
-}
-
-/* Entry and Exit Codes */
-void ATimingService::entry_Operational() {
- // prepare
-}
- void ATimingService::do_Operational() {
- // maintain timers
- etTimerControlBlock* temp;
- etTargetTime_t t;
-
- getTimeFromTarget(&t);
- while (usedTcbsRoot !=0 ){
- if (isTimeGreater(&t,&(usedTcbsRoot->expTime))){
- timer.get(usedTcbsRoot->portIdx).timeout();
- temp=usedTcbsRoot;
- usedTcbsRoot=usedTcbsRoot->next;
- if((temp->pTime.sec==0)&&(temp->pTime.nSec==0)){
- // single shot timer
- returnTcb(temp);
- }else{
- // periodic timer
- addTime(&temp->expTime,&temp->pTime);
- putTcbToUsedList(temp);
- }
- }else{
- break;
- }
- }
-}
-
-/* Action Codes */
-void ATimingService::action_TRANS_INITIAL_TO__Operational() {
- int i;
- usedTcbsRoot=0;
- freeTcbsRoot=&tcbs[0];
- tcbs[ET_NB_OF_TCBS-1].next=0;
- for (i=0;i<ET_NB_OF_TCBS-1;i++){
- tcbs[i].next=&tcbs[i+1];
- }
-}
-void ATimingService::action_TRANS_tr1_FROM_Operational_TO_Operational_BY_startTimeouttimer_tr1(const InterfaceItemBase* ifitem, uint32 time) {
- etTimerControlBlock* timer = getTcb();
- etTargetTime_t t;
- if (timer!= 0){
- t.sec=time/1000;
- t.nSec=(time%1000)*1000000L;
- timer->pTime.sec = 0;
- timer->pTime.nSec = 0;
- timer->portIdx=ifitem->getIdx();
- getTimeFromTarget(&(timer->expTime));
- addTime(&(timer->expTime),&t);
- putTcbToUsedList(timer);
- }
-}
-void ATimingService::action_TRANS_tr3_FROM_Operational_TO_Operational_BY_startTimertimer_tr3(const InterfaceItemBase* ifitem, uint32 time) {
- etTimerControlBlock* timer = getTcb();
- etTargetTime_t t;
- if (timer!= 0){
- t.sec=time/1000;
- t.nSec=(time%1000)*1000000L;
- timer->pTime = t;
- timer->portIdx=ifitem->getIdx();
- getTimeFromTarget(&(timer->expTime));
- addTime(&(timer->expTime),&t);
- putTcbToUsedList(timer);
- }
-}
-void ATimingService::action_TRANS_tr4_FROM_Operational_TO_Operational_BY_killtimer_tr4(const InterfaceItemBase* ifitem) {
- removeTcbFromUsedList(ifitem->getIdx());
-}
-
-/**
- * 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)
- */
-void ATimingService::exitTo(int current, int to, bool handler) {
- while (current!=to) {
- switch (current) {
- case STATE_Operational:
- this->history[STATE_TOP] = STATE_Operational;
- 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
- */
-int ATimingService::executeTransitionChain(int chain, const InterfaceItemBase* ifitem, void* generic_data) {
- switch (chain) {
- case CHAIN_TRANS_INITIAL_TO__Operational:
- {
- action_TRANS_INITIAL_TO__Operational();
- return STATE_Operational;
- }
- case CHAIN_TRANS_tr1_FROM_Operational_TO_Operational_BY_startTimeouttimer_tr1:
- {
- uint32 time = ((uint32) generic_data);
- action_TRANS_tr1_FROM_Operational_TO_Operational_BY_startTimeouttimer_tr1(ifitem, time);
- return STATE_Operational;
- }
- case CHAIN_TRANS_tr3_FROM_Operational_TO_Operational_BY_startTimertimer_tr3:
- {
- uint32 time = ((uint32) generic_data);
- action_TRANS_tr3_FROM_Operational_TO_Operational_BY_startTimertimer_tr3(ifitem, time);
- return STATE_Operational;
- }
- case CHAIN_TRANS_tr4_FROM_Operational_TO_Operational_BY_killtimer_tr4:
- {
- action_TRANS_tr4_FROM_Operational_TO_Operational_BY_killtimer_tr4(ifitem);
- return STATE_Operational;
- }
- }
- 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
- */
-int ATimingService::enterHistory(int state, bool handler, bool skip_entry) {
- while (true) {
- switch (state) {
- case STATE_Operational:
- if (!(skip_entry || handler)) entry_Operational();
- // in leaf state: return state id
- return STATE_Operational;
- case STATE_TOP:
- state = this->history[STATE_TOP];
- break;
- }
- skip_entry = false;
- }
- //return NO_STATE; // required by CDT but detected as unreachable by JDT because of while (true)
-}
-
-void ATimingService::executeInitTransition() {
- int chain = CHAIN_TRANS_INITIAL_TO__Operational;
- int next = ATimingService::executeTransitionChain(chain, 0, 0);
- next = ATimingService::enterHistory(next, false, false);
- setState(next);
-}
-
-/* receiveEvent contains the main implementation of the FSM */
-void ATimingService::receiveEvent(InterfaceItemBase* ifitem, int evt, void* generic_data) {
- int trigger = (ifitem==0)? POLLING : ifitem->getLocalId() + EVT_SHIFT*evt;
- int chain = NOT_CAUGHT;
- int catching_state = NO_STATE;
- bool is_handler = false;
- bool skip_entry = false;
-
- if (!handleSystemEvent(ifitem, evt, generic_data)) {
- switch (getState()) {
- case STATE_Operational:
- switch(trigger) {
- case POLLING:
- do_Operational();
- break;
- case TRIG_timer__startTimeout:
- {
- chain = CHAIN_TRANS_tr1_FROM_Operational_TO_Operational_BY_startTimeouttimer_tr1;
- catching_state = STATE_TOP;
- }
- break;
- case TRIG_timer__startTimer:
- {
- chain = CHAIN_TRANS_tr3_FROM_Operational_TO_Operational_BY_startTimertimer_tr3;
- catching_state = STATE_TOP;
- }
- break;
- case TRIG_timer__kill:
- {
- chain = CHAIN_TRANS_tr4_FROM_Operational_TO_Operational_BY_killtimer_tr4;
- catching_state = STATE_TOP;
- }
- break;
- }
- break;
- }
- }
- if (chain != NOT_CAUGHT) {
- ATimingService::exitTo(getState(), catching_state, is_handler);
- int next = ATimingService::executeTransitionChain(chain, ifitem, generic_data);
- next = ATimingService::enterHistory(next, is_handler, skip_entry);
- setState(next);
- }
-}
-
-//******************************************
-// END of generated code for FSM
-//******************************************
+/**
+ * @author generated by eTrice
+ *
+ * Source File of ActorClass ATimingService
+ *
+ */
+
+#include "ATimingService.h"
+#include "common/debugging/DebuggingService.h"
+#include <iostream>
+
+using namespace etRuntime;
+
+
+ATimingService::ATimingService(etRuntime::IRTObject* parent, std::string name, const std::vector<std::vector<etRuntime::Address> >& port_addr,
+ const std::vector<std::vector<etRuntime::Address> >& peer_addr)
+: ActorClassBase( parent, name, port_addr[0][0], peer_addr[0][0]),
+timer(*this, this, "timer", IFITEM_timer, port_addr[IFITEM_timer], peer_addr[IFITEM_timer]),
+tcbs(),
+usedTcbsRoot(0),
+freeTcbsRoot(0)
+{
+ history = new int[s_numberOfStates];
+ for (int i = 0; i < s_numberOfStates; i++) {
+ history[i] = NO_STATE;
+ }
+ setClassName("ATimingService");
+ // initialize attributes
+ for (int i=0;i<10;i++){
+ tcbs[i] = etTimerControlBlock();
+ }
+
+ getMsgsvc()->addAsyncActor(*this);
+}
+
+void ATimingService::init(){
+ initUser();
+}
+
+void ATimingService::start(){
+ startUser();
+}
+
+void ATimingService::stop(){
+ stopUser();
+}
+
+void ATimingService::destroy(){
+}
+
+
+std::string ATimingService::s_stateStrings[] = {"<no state>","<top>","Operational"
+};
+const int ATimingService::s_numberOfStates = 3;
+
+void ATimingService::setState(int new_state) {
+ DebuggingService::getInstance().addActorState(*this, s_stateStrings[new_state]);
+ if (s_stateStrings[new_state]!="Idle") {
+ std::cout << getInstancePath() << " -> " << s_stateStrings[new_state] << std::endl;
+ }
+ m_state = new_state;
+}
+
+/* Entry and Exit Codes */
+void ATimingService::entry_Operational() {
+ // prepare
+}
+ void ATimingService::do_Operational() {
+ // maintain timers
+ etTimerControlBlock* temp;
+ etTargetTime_t t;
+
+ getTimeFromTarget(&t);
+ while (usedTcbsRoot !=0 ){
+ if (isTimeGreater(&t,&(usedTcbsRoot->expTime))){
+ timer.get(usedTcbsRoot->portIdx).timeout();
+ temp=usedTcbsRoot;
+ usedTcbsRoot=usedTcbsRoot->next;
+ if((temp->pTime.sec==0)&&(temp->pTime.nSec==0)){
+ // single shot timer
+ returnTcb(temp);
+ }else{
+ // periodic timer
+ addTime(&temp->expTime,&temp->pTime);
+ putTcbToUsedList(temp);
+ }
+ }else{
+ break;
+ }
+ }
+}
+
+/* Action Codes */
+void ATimingService::action_TRANS_INITIAL_TO__Operational() {
+ int i;
+ usedTcbsRoot=0;
+ freeTcbsRoot=&tcbs[0];
+ tcbs[ET_NB_OF_TCBS-1].next=0;
+ for (i=0;i<ET_NB_OF_TCBS-1;i++){
+ tcbs[i].next=&tcbs[i+1];
+ }
+}
+void ATimingService::action_TRANS_tr1_FROM_Operational_TO_Operational_BY_startTimeouttimer_tr1(const InterfaceItemBase* ifitem, uint32 time) {
+ etTimerControlBlock* timer = getTcb();
+ etTargetTime_t t;
+ if (timer!= 0){
+ t.sec=time/1000;
+ t.nSec=(time%1000)*1000000L;
+ timer->pTime.sec = 0;
+ timer->pTime.nSec = 0;
+ timer->portIdx=ifitem->getIdx();
+ getTimeFromTarget(&(timer->expTime));
+ addTime(&(timer->expTime),&t);
+ putTcbToUsedList(timer);
+ }
+}
+void ATimingService::action_TRANS_tr3_FROM_Operational_TO_Operational_BY_startTimertimer_tr3(const InterfaceItemBase* ifitem, uint32 time) {
+ etTimerControlBlock* timer = getTcb();
+ etTargetTime_t t;
+ if (timer!= 0){
+ t.sec=time/1000;
+ t.nSec=(time%1000)*1000000L;
+ timer->pTime = t;
+ timer->portIdx=ifitem->getIdx();
+ getTimeFromTarget(&(timer->expTime));
+ addTime(&(timer->expTime),&t);
+ putTcbToUsedList(timer);
+ }
+}
+void ATimingService::action_TRANS_tr4_FROM_Operational_TO_Operational_BY_killtimer_tr4(const InterfaceItemBase* ifitem) {
+ removeTcbFromUsedList(ifitem->getIdx());
+}
+
+/**
+ * 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)
+ */
+void ATimingService::exitTo(int current, int to, bool handler) {
+ while (current!=to) {
+ switch (current) {
+ case STATE_Operational:
+ this->history[STATE_TOP] = STATE_Operational;
+ 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
+ */
+int ATimingService::executeTransitionChain(int chain, const InterfaceItemBase* ifitem, void* generic_data) {
+ switch (chain) {
+ case CHAIN_TRANS_INITIAL_TO__Operational:
+ {
+ action_TRANS_INITIAL_TO__Operational();
+ return STATE_Operational;
+ }
+ case CHAIN_TRANS_tr1_FROM_Operational_TO_Operational_BY_startTimeouttimer_tr1:
+ {
+ uint32 time = ((uint32) generic_data);
+ action_TRANS_tr1_FROM_Operational_TO_Operational_BY_startTimeouttimer_tr1(ifitem, time);
+ return STATE_Operational;
+ }
+ case CHAIN_TRANS_tr3_FROM_Operational_TO_Operational_BY_startTimertimer_tr3:
+ {
+ uint32 time = ((uint32) generic_data);
+ action_TRANS_tr3_FROM_Operational_TO_Operational_BY_startTimertimer_tr3(ifitem, time);
+ return STATE_Operational;
+ }
+ case CHAIN_TRANS_tr4_FROM_Operational_TO_Operational_BY_killtimer_tr4:
+ {
+ action_TRANS_tr4_FROM_Operational_TO_Operational_BY_killtimer_tr4(ifitem);
+ return STATE_Operational;
+ }
+ }
+ 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
+ */
+int ATimingService::enterHistory(int state, bool handler, bool skip_entry) {
+ while (true) {
+ switch (state) {
+ case STATE_Operational:
+ if (!(skip_entry || handler)) entry_Operational();
+ // in leaf state: return state id
+ return STATE_Operational;
+ case STATE_TOP:
+ state = this->history[STATE_TOP];
+ break;
+ }
+ skip_entry = false;
+ }
+ //return NO_STATE; // required by CDT but detected as unreachable by JDT because of while (true)
+}
+
+void ATimingService::executeInitTransition() {
+ int chain = CHAIN_TRANS_INITIAL_TO__Operational;
+ int next = ATimingService::executeTransitionChain(chain, 0, 0);
+ next = ATimingService::enterHistory(next, false, false);
+ setState(next);
+}
+
+/* receiveEvent contains the main implementation of the FSM */
+void ATimingService::receiveEvent(InterfaceItemBase* ifitem, int evt, void* generic_data) {
+ int trigger = (ifitem==0)? POLLING : ifitem->getLocalId() + EVT_SHIFT*evt;
+ int chain = NOT_CAUGHT;
+ int catching_state = NO_STATE;
+ bool is_handler = false;
+ bool skip_entry = false;
+
+ if (!handleSystemEvent(ifitem, evt, generic_data)) {
+ switch (getState()) {
+ case STATE_Operational:
+ switch(trigger) {
+ case POLLING:
+ do_Operational();
+ break;
+ case TRIG_timer__startTimeout:
+ {
+ chain = CHAIN_TRANS_tr1_FROM_Operational_TO_Operational_BY_startTimeouttimer_tr1;
+ catching_state = STATE_TOP;
+ }
+ break;
+ case TRIG_timer__startTimer:
+ {
+ chain = CHAIN_TRANS_tr3_FROM_Operational_TO_Operational_BY_startTimertimer_tr3;
+ catching_state = STATE_TOP;
+ }
+ break;
+ case TRIG_timer__kill:
+ {
+ chain = CHAIN_TRANS_tr4_FROM_Operational_TO_Operational_BY_killtimer_tr4;
+ catching_state = STATE_TOP;
+ }
+ break;
+ }
+ break;
+ }
+ }
+ if (chain != NOT_CAUGHT) {
+ ATimingService::exitTo(getState(), catching_state, is_handler);
+ int next = ATimingService::executeTransitionChain(chain, ifitem, generic_data);
+ next = ATimingService::enterHistory(next, is_handler, skip_entry);
+ setState(next);
+ }
+}
+
+//******************************************
+// END of generated code for FSM
+//******************************************
diff --git a/runtime/org.eclipse.etrice.modellib.cpp/src-gen/room/basic/service/timing/ATimingService.h b/runtime/org.eclipse.etrice.modellib.cpp/src-gen/room/basic/service/timing/ATimingService.h
index 035b8cd06..9b48f789f 100644
--- a/runtime/org.eclipse.etrice.modellib.cpp/src-gen/room/basic/service/timing/ATimingService.h
+++ b/runtime/org.eclipse.etrice.modellib.cpp/src-gen/room/basic/service/timing/ATimingService.h
@@ -1,262 +1,262 @@
- /**
- * @author generated by eTrice
- *
- * Header File of ActorClass ATimingService
- *
- */
-
- #ifndef _ATIMINGSERVICE_H_
- #define _ATIMINGSERVICE_H_
-
- #include "platforms/generic/etDatatypes.h"
- #include "common/messaging/IRTObject.h"
- #include "common/modelbase/PortBase.h"
- #include "common/modelbase/InterfaceItemBase.h"
- #include "common/modelbase/ActorClassBase.h"
- #include "common/modelbase/SubSystemClassBase.h"
- #include "common/messaging/Address.h"
- #include "common/messaging/IMessageReceiver.h"
- #include "common/debugging/DebuggingService.h"
- #include <string>
- #include <vector>
-
-
- #include "room/basic/service/timing/PTimer.h"
-
-
- /*--------------------- begin user code ---------------------*/
-
- #include "common/platform/etTimer.h"
- #define ET_NB_OF_TCBS 10
- typedef struct etTCB etTimerControlBlock;
- struct etTCB {
- etTargetTime_t expTime;
- etTargetTime_t pTime;
- int32 portIdx;
- etTimerControlBlock* next;
- };
-
- /*--------------------- end user code ---------------------*/
-
-
- class ATimingService : public etRuntime::ActorClassBase {
-
-
- protected:
- //--------------------- ports
- //--------------------- saps
- //--------------------- services
- PTimerReplPort timer;
-
- //--------------------- interface item IDs
- typedef enum {
- IFITEM_timer = 1,
- } interface_items;
-
- /*--------------------- attributes ---------------------*/
- etTimerControlBlock tcbs[10];
- etTimerControlBlock* usedTcbsRoot;
- etTimerControlBlock* freeTcbsRoot;
-
- /*--------------------- operations ---------------------*/
- etTimerControlBlock* getTcb() {
-
- etTimerControlBlock* temp = freeTcbsRoot;
-
- if(freeTcbsRoot!=0) {
- freeTcbsRoot=freeTcbsRoot->next;
- temp->next=0;
- }
- return temp;
- }
- void returnTcb(etTimerControlBlock* block) {
-
- block->next=freeTcbsRoot;
- freeTcbsRoot=block;
- }
- void removeTcbFromUsedList(int32 idx) {
-
- etTimerControlBlock* temp=usedTcbsRoot;
- etTimerControlBlock* temp2=usedTcbsRoot;
-
- if (temp==0) return;
-
- if (usedTcbsRoot->portIdx == idx){
- // element found, the first one
- usedTcbsRoot = usedTcbsRoot->next;
- returnTcb(temp);
- return;
- }
-
- temp=temp->next;
- while(temp!=0){
- if(temp->portIdx==idx){
- temp2->next=temp->next;
- returnTcb(temp);
- return;
- }else{
- // try next
- temp2=temp;
- temp=temp->next;
- }
- }
- }
- void putTcbToUsedList(etTimerControlBlock* block) {
-
- etTimerControlBlock* temp=usedTcbsRoot;
- etTimerControlBlock* temp2=usedTcbsRoot;
-
- if (temp==0){
- // list empty put new block to root
- block->next=0;
- usedTcbsRoot=block;
- return;
- }
-
- while(1){
- if (temp != 0){
- if (isTimeGreater(&block->expTime,&temp->expTime)){
- //try next position
- temp2=temp;
- temp=temp->next;
- }else{
- // right position found
- block->next=temp;
- if(temp==usedTcbsRoot){
- usedTcbsRoot=block;
- }else{
- temp2->next=block;
- }
- return;
- }
- }else{
- // end of list reached
- block->next=0;
- temp2->next=block;
- return;
- }
- }
- }
- bool isTimeGreater(etTargetTime_t* t1, etTargetTime_t* t2) {
-
- if (t1->sec > t2->sec) return TRUE;
- if (t1->sec < t2->sec) return FALSE;
- if (t1->nSec > t2->nSec) return TRUE;
- return FALSE;
- }
- void addTime(etTargetTime_t* t1, etTargetTime_t* t2) {
-
- t1->sec += t2->sec;
- t1->nSec += t2->nSec;
- while(t1->nSec >= 1000000000L){
- t1->sec++;
- t1->nSec-=1000000000L;
- }
- }
- void printList() {
-
- etTimerControlBlock* temp=usedTcbsRoot;
- printf("list: ");
- while (temp!=0){
- printf("(%ld,%ld),",temp->expTime.sec,temp->expTime.nSec);
- temp=temp->next;
- }
- printf("\n");
- }
-
- public:
- //--------------------- construction
- ATimingService(etRuntime::IRTObject* parent, std::string name, const std::vector<std::vector<etRuntime::Address> >& port_addr,
- const std::vector<std::vector<etRuntime::Address> >& peer_addr);
-
- //--------------------- port getters
- PTimerReplPort getTimer (){
- return this->timer;
- }
-
- //--------------------- lifecycle functions
- virtual void init();
- virtual void start();
- virtual void stop();
- virtual void destroy();
-
- /* state IDs */
- typedef enum {
- STATE_Operational = 2,
- } state_ids;
-
- /* transition chains */
- typedef enum {
- CHAIN_TRANS_INITIAL_TO__Operational = 1,
- CHAIN_TRANS_tr1_FROM_Operational_TO_Operational_BY_startTimeouttimer_tr1 = 2,
- CHAIN_TRANS_tr3_FROM_Operational_TO_Operational_BY_startTimertimer_tr3 = 3,
- CHAIN_TRANS_tr4_FROM_Operational_TO_Operational_BY_killtimer_tr4 = 4,
- } chain_ids;
-
- /* triggers */
- typedef enum {
- POLLING = 0,
- TRIG_timer__kill = IFITEM_timer + EVT_SHIFT*PTimer::IN_kill,
- TRIG_timer__startTimeout = IFITEM_timer + EVT_SHIFT*PTimer::IN_startTimeout,
- TRIG_timer__startTimer = IFITEM_timer + EVT_SHIFT*PTimer::IN_startTimer,
- } triggers;
-
- protected:
- static std::string s_stateStrings[];
- static const int s_numberOfStates;
-
- private:
- void setState(int new_state);
-
- /* Entry and Exit Codes */
- void entry_Operational();
- void do_Operational();
-
- /* Action Codes */
- void action_TRANS_INITIAL_TO__Operational();
- void action_TRANS_tr1_FROM_Operational_TO_Operational_BY_startTimeouttimer_tr1(const etRuntime::InterfaceItemBase* ifitem, uint32 time);
- void action_TRANS_tr3_FROM_Operational_TO_Operational_BY_startTimertimer_tr3(const etRuntime::InterfaceItemBase* ifitem, uint32 time);
- void action_TRANS_tr4_FROM_Operational_TO_Operational_BY_killtimer_tr4(const etRuntime::InterfaceItemBase* ifitem);
-
- private:
- /**
- * 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)
- */
- void exitTo(int current, int to, bool handler);
-
- /**
- * 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
- */
- int executeTransitionChain(int chain, const etRuntime::InterfaceItemBase* ifitem, void* generic_data);
-
- /**
- * 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
- */
- int enterHistory(int state, bool handler, bool skip_entry);
-
- public:
-
- void executeInitTransition();
-
- /* receiveEvent contains the main implementation of the FSM */
- void receiveEvent(etRuntime::InterfaceItemBase* ifitem, int evt, void* generic_data);
-
- /*--------------------- begin user code ---------------------*/
- //uc2
- /*--------------------- end user code ---------------------*/
-
- };
-
-
- #endif /* _ATIMINGSERVICE_H_ */
+ /**
+ * @author generated by eTrice
+ *
+ * Header File of ActorClass ATimingService
+ *
+ */
+
+ #ifndef _ATIMINGSERVICE_H_
+ #define _ATIMINGSERVICE_H_
+
+ #include "platforms/generic/etDatatypes.h"
+ #include "common/messaging/IRTObject.h"
+ #include "common/modelbase/PortBase.h"
+ #include "common/modelbase/InterfaceItemBase.h"
+ #include "common/modelbase/ActorClassBase.h"
+ #include "common/modelbase/SubSystemClassBase.h"
+ #include "common/messaging/Address.h"
+ #include "common/messaging/IMessageReceiver.h"
+ #include "common/debugging/DebuggingService.h"
+ #include <string>
+ #include <vector>
+
+
+ #include "room/basic/service/timing/PTimer.h"
+
+
+ /*--------------------- begin user code ---------------------*/
+
+ #include "common/platform/etTimer.h"
+ #define ET_NB_OF_TCBS 10
+ typedef struct etTCB etTimerControlBlock;
+ struct etTCB {
+ etTargetTime_t expTime;
+ etTargetTime_t pTime;
+ int32 portIdx;
+ etTimerControlBlock* next;
+ };
+
+ /*--------------------- end user code ---------------------*/
+
+
+ class ATimingService : public etRuntime::ActorClassBase {
+
+
+ protected:
+ //--------------------- ports
+ //--------------------- saps
+ //--------------------- services
+ PTimerReplPort timer;
+
+ //--------------------- interface item IDs
+ typedef enum {
+ IFITEM_timer = 1,
+ } interface_items;
+
+ /*--------------------- attributes ---------------------*/
+ etTimerControlBlock tcbs[10];
+ etTimerControlBlock* usedTcbsRoot;
+ etTimerControlBlock* freeTcbsRoot;
+
+ /*--------------------- operations ---------------------*/
+ etTimerControlBlock* getTcb() {
+
+ etTimerControlBlock* temp = freeTcbsRoot;
+
+ if(freeTcbsRoot!=0) {
+ freeTcbsRoot=freeTcbsRoot->next;
+ temp->next=0;
+ }
+ return temp;
+ }
+ void returnTcb(etTimerControlBlock* block) {
+
+ block->next=freeTcbsRoot;
+ freeTcbsRoot=block;
+ }
+ void removeTcbFromUsedList(int32 idx) {
+
+ etTimerControlBlock* temp=usedTcbsRoot;
+ etTimerControlBlock* temp2=usedTcbsRoot;
+
+ if (temp==0) return;
+
+ if (usedTcbsRoot->portIdx == idx){
+ // element found, the first one
+ usedTcbsRoot = usedTcbsRoot->next;
+ returnTcb(temp);
+ return;
+ }
+
+ temp=temp->next;
+ while(temp!=0){
+ if(temp->portIdx==idx){
+ temp2->next=temp->next;
+ returnTcb(temp);
+ return;
+ }else{
+ // try next
+ temp2=temp;
+ temp=temp->next;
+ }
+ }
+ }
+ void putTcbToUsedList(etTimerControlBlock* block) {
+
+ etTimerControlBlock* temp=usedTcbsRoot;
+ etTimerControlBlock* temp2=usedTcbsRoot;
+
+ if (temp==0){
+ // list empty put new block to root
+ block->next=0;
+ usedTcbsRoot=block;
+ return;
+ }
+
+ while(1){
+ if (temp != 0){
+ if (isTimeGreater(&block->expTime,&temp->expTime)){
+ //try next position
+ temp2=temp;
+ temp=temp->next;
+ }else{
+ // right position found
+ block->next=temp;
+ if(temp==usedTcbsRoot){
+ usedTcbsRoot=block;
+ }else{
+ temp2->next=block;
+ }
+ return;
+ }
+ }else{
+ // end of list reached
+ block->next=0;
+ temp2->next=block;
+ return;
+ }
+ }
+ }
+ bool isTimeGreater(etTargetTime_t* t1, etTargetTime_t* t2) {
+
+ if (t1->sec > t2->sec) return TRUE;
+ if (t1->sec < t2->sec) return FALSE;
+ if (t1->nSec > t2->nSec) return TRUE;
+ return FALSE;
+ }
+ void addTime(etTargetTime_t* t1, etTargetTime_t* t2) {
+
+ t1->sec += t2->sec;
+ t1->nSec += t2->nSec;
+ while(t1->nSec >= 1000000000L){
+ t1->sec++;
+ t1->nSec-=1000000000L;
+ }
+ }
+ void printList() {
+
+ etTimerControlBlock* temp=usedTcbsRoot;
+ printf("list: ");
+ while (temp!=0){
+ printf("(%ld,%ld),",temp->expTime.sec,temp->expTime.nSec);
+ temp=temp->next;
+ }
+ printf("\n");
+ }
+
+ public:
+ //--------------------- construction
+ ATimingService(etRuntime::IRTObject* parent, std::string name, const std::vector<std::vector<etRuntime::Address> >& port_addr,
+ const std::vector<std::vector<etRuntime::Address> >& peer_addr);
+
+ //--------------------- port getters
+ PTimerReplPort getTimer (){
+ return this->timer;
+ }
+
+ //--------------------- lifecycle functions
+ virtual void init();
+ virtual void start();
+ virtual void stop();
+ virtual void destroy();
+
+ /* state IDs */
+ typedef enum {
+ STATE_Operational = 2,
+ } state_ids;
+
+ /* transition chains */
+ typedef enum {
+ CHAIN_TRANS_INITIAL_TO__Operational = 1,
+ CHAIN_TRANS_tr1_FROM_Operational_TO_Operational_BY_startTimeouttimer_tr1 = 2,
+ CHAIN_TRANS_tr3_FROM_Operational_TO_Operational_BY_startTimertimer_tr3 = 3,
+ CHAIN_TRANS_tr4_FROM_Operational_TO_Operational_BY_killtimer_tr4 = 4,
+ } chain_ids;
+
+ /* triggers */
+ typedef enum {
+ POLLING = 0,
+ TRIG_timer__kill = IFITEM_timer + EVT_SHIFT*PTimer::IN_kill,
+ TRIG_timer__startTimeout = IFITEM_timer + EVT_SHIFT*PTimer::IN_startTimeout,
+ TRIG_timer__startTimer = IFITEM_timer + EVT_SHIFT*PTimer::IN_startTimer,
+ } triggers;
+
+ protected:
+ static std::string s_stateStrings[];
+ static const int s_numberOfStates;
+
+ private:
+ void setState(int new_state);
+
+ /* Entry and Exit Codes */
+ void entry_Operational();
+ void do_Operational();
+
+ /* Action Codes */
+ void action_TRANS_INITIAL_TO__Operational();
+ void action_TRANS_tr1_FROM_Operational_TO_Operational_BY_startTimeouttimer_tr1(const etRuntime::InterfaceItemBase* ifitem, uint32 time);
+ void action_TRANS_tr3_FROM_Operational_TO_Operational_BY_startTimertimer_tr3(const etRuntime::InterfaceItemBase* ifitem, uint32 time);
+ void action_TRANS_tr4_FROM_Operational_TO_Operational_BY_killtimer_tr4(const etRuntime::InterfaceItemBase* ifitem);
+
+ private:
+ /**
+ * 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)
+ */
+ void exitTo(int current, int to, bool handler);
+
+ /**
+ * 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
+ */
+ int executeTransitionChain(int chain, const etRuntime::InterfaceItemBase* ifitem, void* generic_data);
+
+ /**
+ * 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
+ */
+ int enterHistory(int state, bool handler, bool skip_entry);
+
+ public:
+
+ void executeInitTransition();
+
+ /* receiveEvent contains the main implementation of the FSM */
+ void receiveEvent(etRuntime::InterfaceItemBase* ifitem, int evt, void* generic_data);
+
+ /*--------------------- begin user code ---------------------*/
+ //uc2
+ /*--------------------- end user code ---------------------*/
+
+ };
+
+
+ #endif /* _ATIMINGSERVICE_H_ */
diff --git a/runtime/org.eclipse.etrice.modellib.cpp/src-gen/room/basic/service/timing/PTimer.cpp b/runtime/org.eclipse.etrice.modellib.cpp/src-gen/room/basic/service/timing/PTimer.cpp
index 4a8b04bc5..7672294d1 100644
--- a/runtime/org.eclipse.etrice.modellib.cpp/src-gen/room/basic/service/timing/PTimer.cpp
+++ b/runtime/org.eclipse.etrice.modellib.cpp/src-gen/room/basic/service/timing/PTimer.cpp
@@ -1,242 +1,242 @@
- /**
- * @author generated by eTrice
- *
- * Source File of ProtocolClass PTimer
- *
- */
-
- #include "PTimer.h"
- #include "common/debugging/DebuggingService.h"
- #include <iostream>
-
- using namespace etRuntime;
-
-
- /*--------------------- begin user code ---------------------*/
- //uc2
- /*--------------------- end user code ---------------------*/
-
- //------------------------------------------------------------------------------------------------------------
- // port class
- //------------------------------------------------------------------------------------------------------------
-
- PTimerPort::PTimerPort(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, Address addr, Address peerAddress, bool doRegistration)
- : PortBase(actor, parent, name, localId, 0, addr, peerAddress)
- {
- if (doRegistration) {
- DebuggingService::getInstance().addPortInstance(*this);
- }
- }
-
- PTimerPort::PTimerPort(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, int idx, Address addr, Address peerAddress, bool doRegistration)
- : PortBase(actor, parent, name, localId, idx, addr, peerAddress)
- {
- if (doRegistration) {
- DebuggingService::getInstance().addPortInstance(*this);
- }
- }
-
- void PTimerPort::receive(Message* msg) {
- if (! PTimer::isValidIncomingEvtID(msg->getEvtId())) {
- std::cout << "unknown" << std::endl;
- }
- else {
- if (msg->hasDebugFlagSet()) { // TODO: model switch for activation of this flag
- DebuggingService::getInstance().addMessageAsyncIn(getPeerAddress(), getAddress(), PTimer::getMessageString(msg->getEvtId()));
- }
-
- getEventReceiver().receiveEvent(this, msg->getEvtId(), msg->getData());
- }
- };
-
-
- // sent messages
- void PTimerPort::timeout() {
- DebuggingService::getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(),
- PTimer::getMessageString(PTimer::OUT_timeout));
- if (getPeerAddress().isValid()){
- getPeerMsgReceiver()->receive(new Message(getPeerAddress(), PTimer::OUT_timeout));
- }
- }
-
-
- //------------------------------------------------------------------------------------------------------------
- // replicated port class
- //------------------------------------------------------------------------------------------------------------
- PTimerReplPort::PTimerReplPort(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, std::vector<Address> addr, std::vector<Address> peerAddress)
- : m_replication(addr.size()),
- m_ports()
- {
- char numstr[10]; // enough to hold all numbers up to 32-bits
-
- m_ports = reinterpret_cast<PTimerPort*> (new char[sizeof(PTimerPort) * addr.size()]);
- for (int i = 0; i < m_replication; ++i) {
- snprintf(numstr, sizeof(numstr), "%d", i);
- //placement new to avoid copy construction, therefore no vector is used
- new (&m_ports[i]) PTimerPort(actor, parent, name + numstr, localId, i, addr[i], peerAddress[i]);
- }
- };
-
-
- // outgoing messages
- void PTimerReplPort::timeout(){
- for (int i=0; i<m_replication; ++i) {
- m_ports[i].timeout();
- }
- }
- //------------------------------------------------------------------------------------------------------------
- // conjugated port class
- //------------------------------------------------------------------------------------------------------------
-
- PTimerConjPort::PTimerConjPort(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, Address addr, Address peerAddress, bool doRegistration)
- : PortBase(actor, parent, name, localId, 0, addr, peerAddress),
- status(0)
- {
- // initialize attributes
- if (doRegistration) {
- DebuggingService::getInstance().addPortInstance(*this);
- }
- }
-
- PTimerConjPort::PTimerConjPort(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, int idx, Address addr, Address peerAddress, bool doRegistration)
- : PortBase(actor, parent, name, localId, idx, addr, peerAddress),
- status(0)
- {
- // initialize attributes
- if (doRegistration) {
- DebuggingService::getInstance().addPortInstance(*this);
- }
- }
-
- void PTimerConjPort::receive(Message* msg) {
- if (! PTimer::isValidOutgoingEvtID(msg->getEvtId())) {
- std::cout << "unknown" << std::endl;
- }
- else {
- if (msg->hasDebugFlagSet()) { // TODO: model switch for activation of this flag
- DebuggingService::getInstance().addMessageAsyncIn(getPeerAddress(), getAddress(), PTimer::getMessageString(msg->getEvtId()));
- }
-
- switch (msg->getEvtId()) {
- case PTimer::OUT_timeout:
- {
-
- //TODO: clear active bit in case of single shot timer
- if (status!=0){
- if (status==ET_TIMER_RUNNING){
- // single shot timer
- status=0;
- }
- // msg to fsm
- getEventReceiver().receiveEvent(this, msg->getEvtId(), msg->getData());
- }
- }
- break;
- default:
- getEventReceiver().receiveEvent(this, msg->getEvtId(), msg->getData());
- break;
- }
- }
- };
-
- /*--------------------- operations ---------------------*/
-
- // sent messages
- void PTimerConjPort::startTimer(uint32 time) {
-
- if (status==0){
- status=ET_TIMER_RUNNING | ET_TIMER_PERIODIC;
- DebuggingService::getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(),
- PTimer::getMessageString(PTimer::IN_startTimer));
- if (getPeerAddress().isValid()){
- getPeerMsgReceiver()->receive(new Message(getPeerAddress(),PTimer::IN_startTimer,
- reinterpret_cast<void*>(time),
- sizeof(uint32)));
- }
- }
- }
-
- void PTimerConjPort::startTimeout(uint32 time) {
-
- if (status==0){
- status = ET_TIMER_RUNNING;
- DebuggingService::getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(),
- PTimer::getMessageString(PTimer::IN_startTimeout));
- if (getPeerAddress().isValid()){
- getPeerMsgReceiver()->receive(new Message(getPeerAddress(),PTimer::IN_startTimeout,
- reinterpret_cast<void*>(time),
- sizeof(uint32)));
- }
- }
- }
-
- void PTimerConjPort::kill() {
-
- if (status!=0){
- status=0;
- DebuggingService::getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(),
- PTimer::getMessageString(PTimer::IN_kill));
- if (getPeerAddress().isValid()){
- getPeerMsgReceiver()->receive(new Message(getPeerAddress(),PTimer::IN_kill, 0, 0));
- }
- }
- }
-
-
- //------------------------------------------------------------------------------------------------------------
- // conjugated replicated port class
- //------------------------------------------------------------------------------------------------------------
- PTimerConjReplPort::PTimerConjReplPort(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, std::vector<Address> addr, std::vector<Address> peerAddress)
- : m_replication(addr.size()),
- m_ports()
- {
- char numstr[10]; // enough to hold all numbers up to 32-bits
-
- m_ports = reinterpret_cast<PTimerConjPort*> (new char[sizeof(PTimerConjPort) * addr.size()]);
- for (int i = 0; i < m_replication; ++i) {
- snprintf(numstr, sizeof(numstr), "%d", i);
- //placement new to avoid copy construction, therefore no vector is used
- new (&m_ports[i]) PTimerConjPort(actor, parent, name + numstr, localId, i, addr[i], peerAddress[i]);
- }
- };
-
-
- // outgoing messages
- void PTimerConjReplPort::startTimer(uint32 time){
- for (int i=0; i<m_replication; ++i) {
- m_ports[i].startTimer( time);
- }
- }
- void PTimerConjReplPort::startTimeout(uint32 time){
- for (int i=0; i<m_replication; ++i) {
- m_ports[i].startTimeout( time);
- }
- }
- void PTimerConjReplPort::kill(){
- for (int i=0; i<m_replication; ++i) {
- m_ports[i].kill();
- }
- }
-
- /*--------------------- debug helpers */
-
- /* message names as strings for debugging (generate MSC) */
- std::string PTimer::s_messageStrings[]
- = {"MIN",
- "timeout",
- "startTimer",
- "startTimeout",
- "kill",
- "MAX"};
-
- std::string PTimer::getMessageString(int msg_id) {
- if ((MSG_MIN < msg_id ) && ( msg_id < MSG_MAX )) {
- return s_messageStrings[msg_id];
- } else {
- // id out of range
- return "Message ID out of range";
- }
- }
-
-
-
+ /**
+ * @author generated by eTrice
+ *
+ * Source File of ProtocolClass PTimer
+ *
+ */
+
+ #include "PTimer.h"
+ #include "common/debugging/DebuggingService.h"
+ #include <iostream>
+
+ using namespace etRuntime;
+
+
+ /*--------------------- begin user code ---------------------*/
+ //uc2
+ /*--------------------- end user code ---------------------*/
+
+ //------------------------------------------------------------------------------------------------------------
+ // port class
+ //------------------------------------------------------------------------------------------------------------
+
+ PTimerPort::PTimerPort(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, Address addr, Address peerAddress, bool doRegistration)
+ : PortBase(actor, parent, name, localId, 0, addr, peerAddress)
+ {
+ if (doRegistration) {
+ DebuggingService::getInstance().addPortInstance(*this);
+ }
+ }
+
+ PTimerPort::PTimerPort(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, int idx, Address addr, Address peerAddress, bool doRegistration)
+ : PortBase(actor, parent, name, localId, idx, addr, peerAddress)
+ {
+ if (doRegistration) {
+ DebuggingService::getInstance().addPortInstance(*this);
+ }
+ }
+
+ void PTimerPort::receive(Message* msg) {
+ if (! PTimer::isValidIncomingEvtID(msg->getEvtId())) {
+ std::cout << "unknown" << std::endl;
+ }
+ else {
+ if (msg->hasDebugFlagSet()) { // TODO: model switch for activation of this flag
+ DebuggingService::getInstance().addMessageAsyncIn(getPeerAddress(), getAddress(), PTimer::getMessageString(msg->getEvtId()));
+ }
+
+ getEventReceiver().receiveEvent(this, msg->getEvtId(), msg->getData());
+ }
+ };
+
+
+ // sent messages
+ void PTimerPort::timeout() {
+ DebuggingService::getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(),
+ PTimer::getMessageString(PTimer::OUT_timeout));
+ if (getPeerAddress().isValid()){
+ getPeerMsgReceiver()->receive(new Message(getPeerAddress(), PTimer::OUT_timeout));
+ }
+ }
+
+
+ //------------------------------------------------------------------------------------------------------------
+ // replicated port class
+ //------------------------------------------------------------------------------------------------------------
+ PTimerReplPort::PTimerReplPort(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, std::vector<Address> addr, std::vector<Address> peerAddress)
+ : m_replication(addr.size()),
+ m_ports()
+ {
+ char numstr[10]; // enough to hold all numbers up to 32-bits
+
+ m_ports = reinterpret_cast<PTimerPort*> (new char[sizeof(PTimerPort) * addr.size()]);
+ for (int i = 0; i < m_replication; ++i) {
+ snprintf(numstr, sizeof(numstr), "%d", i);
+ //placement new to avoid copy construction, therefore no vector is used
+ new (&m_ports[i]) PTimerPort(actor, parent, name + numstr, localId, i, addr[i], peerAddress[i]);
+ }
+ };
+
+
+ // outgoing messages
+ void PTimerReplPort::timeout(){
+ for (int i=0; i<m_replication; ++i) {
+ m_ports[i].timeout();
+ }
+ }
+ //------------------------------------------------------------------------------------------------------------
+ // conjugated port class
+ //------------------------------------------------------------------------------------------------------------
+
+ PTimerConjPort::PTimerConjPort(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, Address addr, Address peerAddress, bool doRegistration)
+ : PortBase(actor, parent, name, localId, 0, addr, peerAddress),
+ status(0)
+ {
+ // initialize attributes
+ if (doRegistration) {
+ DebuggingService::getInstance().addPortInstance(*this);
+ }
+ }
+
+ PTimerConjPort::PTimerConjPort(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, int idx, Address addr, Address peerAddress, bool doRegistration)
+ : PortBase(actor, parent, name, localId, idx, addr, peerAddress),
+ status(0)
+ {
+ // initialize attributes
+ if (doRegistration) {
+ DebuggingService::getInstance().addPortInstance(*this);
+ }
+ }
+
+ void PTimerConjPort::receive(Message* msg) {
+ if (! PTimer::isValidOutgoingEvtID(msg->getEvtId())) {
+ std::cout << "unknown" << std::endl;
+ }
+ else {
+ if (msg->hasDebugFlagSet()) { // TODO: model switch for activation of this flag
+ DebuggingService::getInstance().addMessageAsyncIn(getPeerAddress(), getAddress(), PTimer::getMessageString(msg->getEvtId()));
+ }
+
+ switch (msg->getEvtId()) {
+ case PTimer::OUT_timeout:
+ {
+
+ //TODO: clear active bit in case of single shot timer
+ if (status!=0){
+ if (status==ET_TIMER_RUNNING){
+ // single shot timer
+ status=0;
+ }
+ // msg to fsm
+ getEventReceiver().receiveEvent(this, msg->getEvtId(), msg->getData());
+ }
+ }
+ break;
+ default:
+ getEventReceiver().receiveEvent(this, msg->getEvtId(), msg->getData());
+ break;
+ }
+ }
+ };
+
+ /*--------------------- operations ---------------------*/
+
+ // sent messages
+ void PTimerConjPort::startTimer(uint32 time) {
+
+ if (status==0){
+ status=ET_TIMER_RUNNING | ET_TIMER_PERIODIC;
+ DebuggingService::getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(),
+ PTimer::getMessageString(PTimer::IN_startTimer));
+ if (getPeerAddress().isValid()){
+ getPeerMsgReceiver()->receive(new Message(getPeerAddress(),PTimer::IN_startTimer,
+ reinterpret_cast<void*>(time),
+ sizeof(uint32)));
+ }
+ }
+ }
+
+ void PTimerConjPort::startTimeout(uint32 time) {
+
+ if (status==0){
+ status = ET_TIMER_RUNNING;
+ DebuggingService::getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(),
+ PTimer::getMessageString(PTimer::IN_startTimeout));
+ if (getPeerAddress().isValid()){
+ getPeerMsgReceiver()->receive(new Message(getPeerAddress(),PTimer::IN_startTimeout,
+ reinterpret_cast<void*>(time),
+ sizeof(uint32)));
+ }
+ }
+ }
+
+ void PTimerConjPort::kill() {
+
+ if (status!=0){
+ status=0;
+ DebuggingService::getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(),
+ PTimer::getMessageString(PTimer::IN_kill));
+ if (getPeerAddress().isValid()){
+ getPeerMsgReceiver()->receive(new Message(getPeerAddress(),PTimer::IN_kill, 0, 0));
+ }
+ }
+ }
+
+
+ //------------------------------------------------------------------------------------------------------------
+ // conjugated replicated port class
+ //------------------------------------------------------------------------------------------------------------
+ PTimerConjReplPort::PTimerConjReplPort(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, std::vector<Address> addr, std::vector<Address> peerAddress)
+ : m_replication(addr.size()),
+ m_ports()
+ {
+ char numstr[10]; // enough to hold all numbers up to 32-bits
+
+ m_ports = reinterpret_cast<PTimerConjPort*> (new char[sizeof(PTimerConjPort) * addr.size()]);
+ for (int i = 0; i < m_replication; ++i) {
+ snprintf(numstr, sizeof(numstr), "%d", i);
+ //placement new to avoid copy construction, therefore no vector is used
+ new (&m_ports[i]) PTimerConjPort(actor, parent, name + numstr, localId, i, addr[i], peerAddress[i]);
+ }
+ };
+
+
+ // outgoing messages
+ void PTimerConjReplPort::startTimer(uint32 time){
+ for (int i=0; i<m_replication; ++i) {
+ m_ports[i].startTimer( time);
+ }
+ }
+ void PTimerConjReplPort::startTimeout(uint32 time){
+ for (int i=0; i<m_replication; ++i) {
+ m_ports[i].startTimeout( time);
+ }
+ }
+ void PTimerConjReplPort::kill(){
+ for (int i=0; i<m_replication; ++i) {
+ m_ports[i].kill();
+ }
+ }
+
+ /*--------------------- debug helpers */
+
+ /* message names as strings for debugging (generate MSC) */
+ std::string PTimer::s_messageStrings[]
+ = {"MIN",
+ "timeout",
+ "startTimer",
+ "startTimeout",
+ "kill",
+ "MAX"};
+
+ std::string PTimer::getMessageString(int msg_id) {
+ if ((MSG_MIN < msg_id ) && ( msg_id < MSG_MAX )) {
+ return s_messageStrings[msg_id];
+ } else {
+ // id out of range
+ return "Message ID out of range";
+ }
+ }
+
+
+
diff --git a/runtime/org.eclipse.etrice.modellib.cpp/src-gen/room/basic/service/timing/PTimer.h b/runtime/org.eclipse.etrice.modellib.cpp/src-gen/room/basic/service/timing/PTimer.h
index 0ee3d1208..d98ea2520 100644
--- a/runtime/org.eclipse.etrice.modellib.cpp/src-gen/room/basic/service/timing/PTimer.h
+++ b/runtime/org.eclipse.etrice.modellib.cpp/src-gen/room/basic/service/timing/PTimer.h
@@ -1,139 +1,139 @@
-/**
- * @author generated by eTrice
- *
- * Header File of ProtocolClass PTimer
- *
- */
-
-#ifndef _PTIMER_H_
-#define _PTIMER_H_
-
-#include "platforms/generic/etDatatypes.h"
-#include "common/messaging/IRTObject.h"
-#include "common/modelbase/PortBase.h"
-#include "common/modelbase/InterfaceItemBase.h"
-#include "common/messaging/Address.h"
-#include "common/messaging/Message.h"
-#include <vector>
-#include <string>
-
-namespace etRuntime {
- class IEventReceiver;
-
-}
-
-/*--------------------- begin user code ---------------------*/
-
- #define ET_TIMER_RUNNING 0x01
- #define ET_TIMER_PERIODIC 0x02
-
-/*--------------------- end user code ---------------------*/
-
-
-class PTimer {
- public:
- /* message IDs */
- typedef enum {
- MSG_MIN = 0,
- OUT_timeout = 1,
- IN_startTimer = 2,
- IN_startTimeout = 3,
- IN_kill = 4,
- MSG_MAX = 5,
- } msg_ids;
- static bool isValidEvtID(int evtId) {
- return ((MSG_MIN < evtId) && (evtId < MSG_MAX));
- };
- static bool isValidOutgoingEvtID(int evtId) {
- return ((MSG_MIN < evtId) && (evtId < IN_startTimer));
- };
- static bool isValidIncomingEvtID(int evtId) {
- return ((IN_startTimer <= evtId) && (evtId < MSG_MAX));
- };
- static std::string getMessageString(int msg_id);
-
- private:
- static std::string s_messageStrings[];
- /*--------------------- begin user code ---------------------*/
- //uc2
- /*--------------------- end user code ---------------------*/
-};
-
-//------------------------------------------------------------------------------------------------------------
-// port class
-//------------------------------------------------------------------------------------------------------------
-class PTimerPort : public etRuntime::PortBase {
- public:
- // constructors
- PTimerPort(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, etRuntime::Address addr, etRuntime::Address peerAddress, bool doRegistration = true);
- PTimerPort(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, int idx, etRuntime::Address addr, etRuntime::Address peerAddress, bool doRegistration = true);
-
- virtual void receive(etRuntime::Message* m);
-
- // outgoing messages
- public: void timeout();
-};
-
-//------------------------------------------------------------------------------------------------------------
-// replicated port class
-//------------------------------------------------------------------------------------------------------------
-class PTimerReplPort {
- private:
- int m_replication;
- PTimerPort* m_ports; //dynamic array used instead of vector to avoid copy construction
-
- public:
- PTimerReplPort(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, std::vector<etRuntime::Address> addr, std::vector<etRuntime::Address> peerAddress);
- virtual ~PTimerReplPort() {};
-
- int getReplication() { return m_replication; }
- int getIndexOf(const etRuntime::InterfaceItemBase& ifitem){ return ifitem.getIdx(); }
- PTimerPort get(int i) {return m_ports[i];}
-
- // outgoing messages
- public: void timeout();
-
-};
-//------------------------------------------------------------------------------------------------------------
-// conjugated port class
-//------------------------------------------------------------------------------------------------------------
-class PTimerConjPort : public etRuntime::PortBase {
- public:
- // constructors
- PTimerConjPort(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, etRuntime::Address addr, etRuntime::Address peerAddress, bool doRegistration = true);
- PTimerConjPort(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, int idx, etRuntime::Address addr, etRuntime::Address peerAddress, bool doRegistration = true);
-
- virtual void receive(etRuntime::Message* m);
- /*--------------------- attributes ---------------------*/
- int8 status;
- /*--------------------- operations ---------------------*/
-
- // outgoing messages
- public: void startTimer(uint32 time);
- public: void startTimeout(uint32 time);
- public: void kill();
-};
-
-//------------------------------------------------------------------------------------------------------------
-// conjugated replicated port class
-//------------------------------------------------------------------------------------------------------------
-class PTimerConjReplPort {
- private:
- int m_replication;
- PTimerConjPort* m_ports; //dynamic array used instead of vector to avoid copy construction
-
- public:
- PTimerConjReplPort(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, std::vector<etRuntime::Address> addr, std::vector<etRuntime::Address> peerAddress);
- virtual ~PTimerConjReplPort() {};
-
- int getReplication() { return m_replication; }
- int getIndexOf(const etRuntime::InterfaceItemBase& ifitem){ return ifitem.getIdx(); }
- PTimerConjPort get(int i) {return m_ports[i];}
-
- // outgoing messages
- public: void startTimer(uint32 time);
- public: void startTimeout(uint32 time);
- public: void kill();
-
-};
-#endif /* _PTIMER_H_ */
+/**
+ * @author generated by eTrice
+ *
+ * Header File of ProtocolClass PTimer
+ *
+ */
+
+#ifndef _PTIMER_H_
+#define _PTIMER_H_
+
+#include "platforms/generic/etDatatypes.h"
+#include "common/messaging/IRTObject.h"
+#include "common/modelbase/PortBase.h"
+#include "common/modelbase/InterfaceItemBase.h"
+#include "common/messaging/Address.h"
+#include "common/messaging/Message.h"
+#include <vector>
+#include <string>
+
+namespace etRuntime {
+ class IEventReceiver;
+
+}
+
+/*--------------------- begin user code ---------------------*/
+
+ #define ET_TIMER_RUNNING 0x01
+ #define ET_TIMER_PERIODIC 0x02
+
+/*--------------------- end user code ---------------------*/
+
+
+class PTimer {
+ public:
+ /* message IDs */
+ typedef enum {
+ MSG_MIN = 0,
+ OUT_timeout = 1,
+ IN_startTimer = 2,
+ IN_startTimeout = 3,
+ IN_kill = 4,
+ MSG_MAX = 5,
+ } msg_ids;
+ static bool isValidEvtID(int evtId) {
+ return ((MSG_MIN < evtId) && (evtId < MSG_MAX));
+ };
+ static bool isValidOutgoingEvtID(int evtId) {
+ return ((MSG_MIN < evtId) && (evtId < IN_startTimer));
+ };
+ static bool isValidIncomingEvtID(int evtId) {
+ return ((IN_startTimer <= evtId) && (evtId < MSG_MAX));
+ };
+ static std::string getMessageString(int msg_id);
+
+ private:
+ static std::string s_messageStrings[];
+ /*--------------------- begin user code ---------------------*/
+ //uc2
+ /*--------------------- end user code ---------------------*/
+};
+
+//------------------------------------------------------------------------------------------------------------
+// port class
+//------------------------------------------------------------------------------------------------------------
+class PTimerPort : public etRuntime::PortBase {
+ public:
+ // constructors
+ PTimerPort(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, etRuntime::Address addr, etRuntime::Address peerAddress, bool doRegistration = true);
+ PTimerPort(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, int idx, etRuntime::Address addr, etRuntime::Address peerAddress, bool doRegistration = true);
+
+ virtual void receive(etRuntime::Message* m);
+
+ // outgoing messages
+ public: void timeout();
+};
+
+//------------------------------------------------------------------------------------------------------------
+// replicated port class
+//------------------------------------------------------------------------------------------------------------
+class PTimerReplPort {
+ private:
+ int m_replication;
+ PTimerPort* m_ports; //dynamic array used instead of vector to avoid copy construction
+
+ public:
+ PTimerReplPort(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, std::vector<etRuntime::Address> addr, std::vector<etRuntime::Address> peerAddress);
+ virtual ~PTimerReplPort() {};
+
+ int getReplication() { return m_replication; }
+ int getIndexOf(const etRuntime::InterfaceItemBase& ifitem){ return ifitem.getIdx(); }
+ PTimerPort get(int i) {return m_ports[i];}
+
+ // outgoing messages
+ public: void timeout();
+
+};
+//------------------------------------------------------------------------------------------------------------
+// conjugated port class
+//------------------------------------------------------------------------------------------------------------
+class PTimerConjPort : public etRuntime::PortBase {
+ public:
+ // constructors
+ PTimerConjPort(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, etRuntime::Address addr, etRuntime::Address peerAddress, bool doRegistration = true);
+ PTimerConjPort(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, int idx, etRuntime::Address addr, etRuntime::Address peerAddress, bool doRegistration = true);
+
+ virtual void receive(etRuntime::Message* m);
+ /*--------------------- attributes ---------------------*/
+ int8 status;
+ /*--------------------- operations ---------------------*/
+
+ // outgoing messages
+ public: void startTimer(uint32 time);
+ public: void startTimeout(uint32 time);
+ public: void kill();
+};
+
+//------------------------------------------------------------------------------------------------------------
+// conjugated replicated port class
+//------------------------------------------------------------------------------------------------------------
+class PTimerConjReplPort {
+ private:
+ int m_replication;
+ PTimerConjPort* m_ports; //dynamic array used instead of vector to avoid copy construction
+
+ public:
+ PTimerConjReplPort(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, std::vector<etRuntime::Address> addr, std::vector<etRuntime::Address> peerAddress);
+ virtual ~PTimerConjReplPort() {};
+
+ int getReplication() { return m_replication; }
+ int getIndexOf(const etRuntime::InterfaceItemBase& ifitem){ return ifitem.getIdx(); }
+ PTimerConjPort get(int i) {return m_ports[i];}
+
+ // outgoing messages
+ public: void startTimer(uint32 time);
+ public: void startTimeout(uint32 time);
+ public: void kill();
+
+};
+#endif /* _PTIMER_H_ */

Back to the top