/* C code for program timeout, generated by snc from ../timeout.stt */ #include #include #include #include #include "seq_snc.h" # line 26 "../timeout.stt" #include # line 28 "../timeout.stt" static void outputMessage(char* deviceName, char* message); /* Variable declarations */ struct seqg_vars { # line 31 "../timeout.stt" double val; # line 32 "../timeout.stt" double rbv; # line 33 "../timeout.stt" short doneMoving; # line 34 "../timeout.stt" short closedLoop; # line 35 "../timeout.stt" short closedLoopCmd; # line 36 "../timeout.stt" short lLimit; # line 38 "../timeout.stt" double retractPos; # line 39 "../timeout.stt" short timeoutEn; # line 40 "../timeout.stt" double timeOut; # line 41 "../timeout.stt" double longTimeOut; # line 42 "../timeout.stt" short retract; # line 43 "../timeout.stt" short DEBUG_T; # line 47 "../timeout.stt" char *deviceName; }; /* Function declarations */ #define seqg_var (*(struct seqg_vars *const *)seqg_env) /* Program init func */ static void seqg_init(PROG_ID seqg_env) { } /****** Code for state "init" in state set "timeoutSeq" ******/ /* Entry function for state "init" in state set "timeoutSeq" */ static void seqg_entry_timeoutSeq_0_init(SS_ID seqg_env) { # line 52 "../timeout.stt" if (seqg_var->DEBUG_T) # line 52 "../timeout.stt" outputMessage(seqg_var->deviceName, "Entering the Linmot Drive Timeout sequence program"); # line 55 "../timeout.stt" seqg_var->deviceName = seq_macValueGet(seqg_env, "motor"); } /* Event function for state "init" in state set "timeoutSeq" */ static seqBool seqg_event_timeoutSeq_0_init(SS_ID seqg_env, int *seqg_ptrn, int *seqg_pnst) { if (TRUE) { *seqg_pnst = 2; *seqg_ptrn = 0; return TRUE; } return FALSE; } /* Action function for state "init" in state set "timeoutSeq" */ static void seqg_action_timeoutSeq_0_init(SS_ID seqg_env, int seqg_trn, int *seqg_pnst) { switch(seqg_trn) { case 0: { } return; } } /****** Code for state "disabled" in state set "timeoutSeq" ******/ /* Entry function for state "disabled" in state set "timeoutSeq" */ static void seqg_entry_timeoutSeq_0_disabled(SS_ID seqg_env) { # line 66 "../timeout.stt" if (seqg_var->DEBUG_T) # line 66 "../timeout.stt" outputMessage(seqg_var->deviceName, "Entering the disable state"); } /* Event function for state "disabled" in state set "timeoutSeq" */ static seqBool seqg_event_timeoutSeq_0_disabled(SS_ID seqg_env, int *seqg_ptrn, int *seqg_pnst) { # line 69 "../timeout.stt" if (seqg_var->timeoutEn) { *seqg_pnst = 2; *seqg_ptrn = 0; return TRUE; } # line 75 "../timeout.stt" if (seqg_var->retract == 1) { *seqg_pnst = 2; *seqg_ptrn = 1; return TRUE; } return FALSE; } /* Action function for state "disabled" in state set "timeoutSeq" */ static void seqg_action_timeoutSeq_0_disabled(SS_ID seqg_env, int seqg_trn, int *seqg_pnst) { switch(seqg_trn) { case 0: { # line 71 "../timeout.stt" outputMessage(seqg_var->deviceName, "Automatic timeout enabled"); } return; case 1: { # line 76 "../timeout.stt" outputMessage(seqg_var->deviceName, "FWS retract triggered"); # line 77 "../timeout.stt" seqg_var->val = seqg_var->retractPos; # line 78 "../timeout.stt" seq_pvPutTmo(seqg_env, 0/*val*/, DEFAULT, DEFAULT_TIMEOUT); } return; } } /****** Code for state "wait" in state set "timeoutSeq" ******/ /* Entry function for state "wait" in state set "timeoutSeq" */ static void seqg_entry_timeoutSeq_0_wait(SS_ID seqg_env) { # line 84 "../timeout.stt" if (seqg_var->DEBUG_T) # line 84 "../timeout.stt" outputMessage(seqg_var->deviceName, "Entering the wait state"); # line 85 "../timeout.stt" seq_pvGetTmo(seqg_env, 3/*closedLoop*/, SYNC, DEFAULT_TIMEOUT); } /* Event function for state "wait" in state set "timeoutSeq" */ static seqBool seqg_event_timeoutSeq_0_wait(SS_ID seqg_env, int *seqg_ptrn, int *seqg_pnst) { # line 88 "../timeout.stt" if ((!seqg_var->timeoutEn) && (seqg_var->retract == 0)) { *seqg_pnst = 1; *seqg_ptrn = 0; return TRUE; } # line 93 "../timeout.stt" if (seqg_var->closedLoop == 0) { *seqg_pnst = 5; *seqg_ptrn = 1; return TRUE; } # line 97 "../timeout.stt" if ((seqg_var->rbv <= (seqg_var->retractPos + 50) || seqg_var->lLimit == 1) && seqg_var->doneMoving == 1) { *seqg_pnst = 3; *seqg_ptrn = 2; return TRUE; } # line 101 "../timeout.stt" if ((seqg_var->doneMoving == 1) && (seqg_var->retract == 0)) { *seqg_pnst = 4; *seqg_ptrn = 3; return TRUE; } return FALSE; } /* Action function for state "wait" in state set "timeoutSeq" */ static void seqg_action_timeoutSeq_0_wait(SS_ID seqg_env, int seqg_trn, int *seqg_pnst) { switch(seqg_trn) { case 0: { # line 90 "../timeout.stt" outputMessage(seqg_var->deviceName, "Disabling automatic timeout"); } return; case 1: { } return; case 2: { } return; case 3: { } return; } } /****** Code for state "retracted" in state set "timeoutSeq" ******/ /* Entry function for state "retracted" in state set "timeoutSeq" */ static void seqg_entry_timeoutSeq_0_retracted(SS_ID seqg_env) { # line 108 "../timeout.stt" if (seqg_var->DEBUG_T) # line 108 "../timeout.stt" outputMessage(seqg_var->deviceName, "Entering the retracted state"); } /* Event function for state "retracted" in state set "timeoutSeq" */ static seqBool seqg_event_timeoutSeq_0_retracted(SS_ID seqg_env, int *seqg_ptrn, int *seqg_pnst) { # line 111 "../timeout.stt" if (seqg_var->doneMoving == 0) { *seqg_pnst = 2; *seqg_ptrn = 0; return TRUE; } # line 115 "../timeout.stt" if (seq_delay(seqg_env, 0.5) && seqg_var->closedLoop == 0) { *seqg_pnst = 5; *seqg_ptrn = 1; return TRUE; } # line 120 "../timeout.stt" if (seqg_var->retract == 1) { *seqg_pnst = 5; *seqg_ptrn = 2; return TRUE; } # line 125 "../timeout.stt" if (seq_delay(seqg_env, seqg_var->timeOut)) { *seqg_pnst = 5; *seqg_ptrn = 3; return TRUE; } # line 130 "../timeout.stt" if ((!seqg_var->timeoutEn) && (seqg_var->retract == 0)) { *seqg_pnst = 1; *seqg_ptrn = 4; return TRUE; } return FALSE; } /* Action function for state "retracted" in state set "timeoutSeq" */ static void seqg_action_timeoutSeq_0_retracted(SS_ID seqg_env, int seqg_trn, int *seqg_pnst) { switch(seqg_trn) { case 0: { } return; case 1: { # line 116 "../timeout.stt" if (seqg_var->DEBUG_T) # line 116 "../timeout.stt" outputMessage(seqg_var->deviceName, "motor record is in open loop go to turnOff state"); } return; case 2: { # line 121 "../timeout.stt" if (seqg_var->DEBUG_T) # line 121 "../timeout.stt" outputMessage(seqg_var->deviceName, "motor retract on"); } return; case 3: { # line 126 "../timeout.stt" if (seqg_var->DEBUG_T) # line 126 "../timeout.stt" outputMessage(seqg_var->deviceName, "Timeout period has finished"); } return; case 4: { # line 132 "../timeout.stt" outputMessage(seqg_var->deviceName, "Disabling automatic timeout"); } return; } } /****** Code for state "longTimeOut" in state set "timeoutSeq" ******/ /* Entry function for state "longTimeOut" in state set "timeoutSeq" */ static void seqg_entry_timeoutSeq_0_longTimeOut(SS_ID seqg_env) { # line 138 "../timeout.stt" if (seqg_var->DEBUG_T) # line 138 "../timeout.stt" outputMessage(seqg_var->deviceName, "Entering the longTimeOut state"); } /* Event function for state "longTimeOut" in state set "timeoutSeq" */ static seqBool seqg_event_timeoutSeq_0_longTimeOut(SS_ID seqg_env, int *seqg_ptrn, int *seqg_pnst) { # line 141 "../timeout.stt" if (seqg_var->doneMoving == 0) { *seqg_pnst = 2; *seqg_ptrn = 0; return TRUE; } # line 145 "../timeout.stt" if (seqg_var->closedLoop == 0) { *seqg_pnst = 5; *seqg_ptrn = 1; return TRUE; } # line 149 "../timeout.stt" if (seqg_var->retract == 1) { *seqg_pnst = 2; *seqg_ptrn = 2; return TRUE; } # line 156 "../timeout.stt" if (seq_delay(seqg_env, seqg_var->longTimeOut)) { *seqg_pnst = 2; *seqg_ptrn = 3; return TRUE; } # line 165 "../timeout.stt" if ((!seqg_var->timeoutEn) && (seqg_var->retract == 0)) { *seqg_pnst = 1; *seqg_ptrn = 4; return TRUE; } return FALSE; } /* Action function for state "longTimeOut" in state set "timeoutSeq" */ static void seqg_action_timeoutSeq_0_longTimeOut(SS_ID seqg_env, int seqg_trn, int *seqg_pnst) { switch(seqg_trn) { case 0: { } return; case 1: { } return; case 2: { # line 151 "../timeout.stt" outputMessage(seqg_var->deviceName, "FWS retract triggered"); # line 152 "../timeout.stt" seqg_var->val = seqg_var->retractPos; # line 153 "../timeout.stt" seq_pvPutTmo(seqg_env, 0/*val*/, DEFAULT, DEFAULT_TIMEOUT); } return; case 3: { # line 158 "../timeout.stt" outputMessage(seqg_var->deviceName, "Automatic FWS retract triggered after long timeout"); # line 159 "../timeout.stt" seqg_var->retract = 1; # line 160 "../timeout.stt" seq_pvPutTmo(seqg_env, 10/*retract*/, DEFAULT, DEFAULT_TIMEOUT); # line 161 "../timeout.stt" seqg_var->val = seqg_var->retractPos; # line 162 "../timeout.stt" seq_pvPutTmo(seqg_env, 0/*val*/, DEFAULT, DEFAULT_TIMEOUT); } return; case 4: { # line 167 "../timeout.stt" outputMessage(seqg_var->deviceName, "Disabling automatic timeout"); } return; } } /****** Code for state "turnOff" in state set "timeoutSeq" ******/ /* Entry function for state "turnOff" in state set "timeoutSeq" */ static void seqg_entry_timeoutSeq_0_turnOff(SS_ID seqg_env) { # line 173 "../timeout.stt" if (seqg_var->DEBUG_T) # line 173 "../timeout.stt" outputMessage(seqg_var->deviceName, "Entering the turnOff state"); } /* Event function for state "turnOff" in state set "timeoutSeq" */ static seqBool seqg_event_timeoutSeq_0_turnOff(SS_ID seqg_env, int *seqg_ptrn, int *seqg_pnst) { if (TRUE) { *seqg_pnst = 6; *seqg_ptrn = 0; return TRUE; } return FALSE; } /* Action function for state "turnOff" in state set "timeoutSeq" */ static void seqg_action_timeoutSeq_0_turnOff(SS_ID seqg_env, int seqg_trn, int *seqg_pnst) { switch(seqg_trn) { case 0: { # line 178 "../timeout.stt" seqg_var->closedLoopCmd = 0; # line 179 "../timeout.stt" seq_pvPutTmo(seqg_env, 4/*closedLoopCmd*/, SYNC, DEFAULT_TIMEOUT); # line 181 "../timeout.stt" seqg_var->retract = 0; # line 182 "../timeout.stt" seq_pvPutTmo(seqg_env, 10/*retract*/, SYNC, DEFAULT_TIMEOUT); # line 183 "../timeout.stt" outputMessage(seqg_var->deviceName, "Linmot drive disabled, motor record in open loop, retract off"); } return; } } /****** Code for state "motorOff" in state set "timeoutSeq" ******/ /* Entry function for state "motorOff" in state set "timeoutSeq" */ static void seqg_entry_timeoutSeq_0_motorOff(SS_ID seqg_env) { # line 190 "../timeout.stt" if (seqg_var->DEBUG_T) # line 190 "../timeout.stt" outputMessage(seqg_var->deviceName, "Entering the motorOff state"); } /* Event function for state "motorOff" in state set "timeoutSeq" */ static seqBool seqg_event_timeoutSeq_0_motorOff(SS_ID seqg_env, int *seqg_ptrn, int *seqg_pnst) { # line 193 "../timeout.stt" if (!seqg_var->timeoutEn) { *seqg_pnst = 1; *seqg_ptrn = 0; return TRUE; } # line 198 "../timeout.stt" if (seq_delay(seqg_env, 1) && seqg_var->retract == 1) { *seqg_pnst = 5; *seqg_ptrn = 1; return TRUE; } # line 201 "../timeout.stt" if (seq_delay(seqg_env, 0.5) && seqg_var->closedLoop == 1) { *seqg_pnst = 2; *seqg_ptrn = 2; return TRUE; } return FALSE; } /* Action function for state "motorOff" in state set "timeoutSeq" */ static void seqg_action_timeoutSeq_0_motorOff(SS_ID seqg_env, int seqg_trn, int *seqg_pnst) { switch(seqg_trn) { case 0: { # line 195 "../timeout.stt" outputMessage(seqg_var->deviceName, "Disabling automatic timeout"); } return; case 1: { } return; case 2: { } return; } } #undef seqg_var /************************ Tables ************************/ /* Channel table */ static seqChan seqg_chans[] = { /* chName, offset, varName, varType, count, eventNum, efId, monitored, queueSize, queueIndex */ {"{motor}:MOTR.VAL", offsetof(struct seqg_vars, val), "val", P_DOUBLE, 1, 1, 0, 0, 0, 0}, {"{motor}:MOTR.RBV", offsetof(struct seqg_vars, rbv), "rbv", P_DOUBLE, 1, 2, 0, 1, 0, 0}, {"{motor}:MOTR.DMOV", offsetof(struct seqg_vars, doneMoving), "doneMoving", P_SHORT, 1, 3, 0, 1, 0, 0}, {"{motor}:MOTR.CNEN", offsetof(struct seqg_vars, closedLoop), "closedLoop", P_SHORT, 1, 4, 0, 1, 0, 0}, {"{motor}:MOTR.CNEN", offsetof(struct seqg_vars, closedLoopCmd), "closedLoopCmd", P_SHORT, 1, 5, 0, 1, 0, 0}, {"{motor}:MOTR.LLS", offsetof(struct seqg_vars, lLimit), "lLimit", P_SHORT, 1, 6, 0, 1, 0, 0}, {"{motor}:MOTR_RETRACT_POS", offsetof(struct seqg_vars, retractPos), "retractPos", P_DOUBLE, 1, 7, 0, 1, 0, 0}, {"{motor}:MOTR_TIMEOUTEN", offsetof(struct seqg_vars, timeoutEn), "timeoutEn", P_SHORT, 1, 8, 0, 1, 0, 0}, {"{motor}:MOTR_TIMEOUT", offsetof(struct seqg_vars, timeOut), "timeOut", P_DOUBLE, 1, 9, 0, 1, 0, 0}, {"{motor}:MOTR_LTIMEOUT", offsetof(struct seqg_vars, longTimeOut), "longTimeOut", P_DOUBLE, 1, 10, 0, 1, 0, 0}, {"{motor}:MOTR_RETRACT", offsetof(struct seqg_vars, retract), "retract", P_SHORT, 1, 11, 0, 1, 0, 0}, {"{motor}:MOTR_TIMEOUT_DBG", offsetof(struct seqg_vars, DEBUG_T), "DEBUG_T", P_SHORT, 1, 12, 0, 1, 0, 0}, }; /* Event masks for state set "timeoutSeq" */ static const seqMask seqg_mask_timeoutSeq_0_init[] = { 0x00000000, }; static const seqMask seqg_mask_timeoutSeq_0_disabled[] = { 0x00000900, }; static const seqMask seqg_mask_timeoutSeq_0_wait[] = { 0x000009dc, }; static const seqMask seqg_mask_timeoutSeq_0_retracted[] = { 0x00000b18, }; static const seqMask seqg_mask_timeoutSeq_0_longTimeOut[] = { 0x00000d18, }; static const seqMask seqg_mask_timeoutSeq_0_turnOff[] = { 0x00000000, }; static const seqMask seqg_mask_timeoutSeq_0_motorOff[] = { 0x00000910, }; /* State table for state set "timeoutSeq" */ static seqState seqg_states_timeoutSeq[] = { { /* state name */ "init", /* action function */ seqg_action_timeoutSeq_0_init, /* event function */ seqg_event_timeoutSeq_0_init, /* entry function */ seqg_entry_timeoutSeq_0_init, /* exit function */ 0, /* event mask array */ seqg_mask_timeoutSeq_0_init, /* state options */ (0) }, { /* state name */ "disabled", /* action function */ seqg_action_timeoutSeq_0_disabled, /* event function */ seqg_event_timeoutSeq_0_disabled, /* entry function */ seqg_entry_timeoutSeq_0_disabled, /* exit function */ 0, /* event mask array */ seqg_mask_timeoutSeq_0_disabled, /* state options */ (0) }, { /* state name */ "wait", /* action function */ seqg_action_timeoutSeq_0_wait, /* event function */ seqg_event_timeoutSeq_0_wait, /* entry function */ seqg_entry_timeoutSeq_0_wait, /* exit function */ 0, /* event mask array */ seqg_mask_timeoutSeq_0_wait, /* state options */ (0) }, { /* state name */ "retracted", /* action function */ seqg_action_timeoutSeq_0_retracted, /* event function */ seqg_event_timeoutSeq_0_retracted, /* entry function */ seqg_entry_timeoutSeq_0_retracted, /* exit function */ 0, /* event mask array */ seqg_mask_timeoutSeq_0_retracted, /* state options */ (0) }, { /* state name */ "longTimeOut", /* action function */ seqg_action_timeoutSeq_0_longTimeOut, /* event function */ seqg_event_timeoutSeq_0_longTimeOut, /* entry function */ seqg_entry_timeoutSeq_0_longTimeOut, /* exit function */ 0, /* event mask array */ seqg_mask_timeoutSeq_0_longTimeOut, /* state options */ (0) }, { /* state name */ "turnOff", /* action function */ seqg_action_timeoutSeq_0_turnOff, /* event function */ seqg_event_timeoutSeq_0_turnOff, /* entry function */ seqg_entry_timeoutSeq_0_turnOff, /* exit function */ 0, /* event mask array */ seqg_mask_timeoutSeq_0_turnOff, /* state options */ (0) }, { /* state name */ "motorOff", /* action function */ seqg_action_timeoutSeq_0_motorOff, /* event function */ seqg_event_timeoutSeq_0_motorOff, /* entry function */ seqg_entry_timeoutSeq_0_motorOff, /* exit function */ 0, /* event mask array */ seqg_mask_timeoutSeq_0_motorOff, /* state options */ (0) }, }; /* State set table */ static seqSS seqg_statesets[] = { { /* state set name */ "timeoutSeq", /* states */ seqg_states_timeoutSeq, /* number of states */ 7 }, }; /* Program table (global) */ seqProgram timeout = { /* magic number */ 2002004, /* program name */ "timeout", /* channels */ seqg_chans, /* num. channels */ 12, /* state sets */ seqg_statesets, /* num. state sets */ 1, /* user var size */ sizeof(struct seqg_vars), /* param */ "", /* num. event flags */ 0, /* encoded options */ (0 | OPT_DEBUG | OPT_NEWEF | OPT_REENT), /* init func */ seqg_init, /* entry func */ 0, /* exit func */ 0, /* num. queues */ 0 }; # line 209 "../timeout.stt" static void outputMessage(char* deviceName, char* message) { time_t t = time(NULL); struct tm tm = *localtime(&t); printf("%d-%.2d-%.2d %.2d:%.2d:%.2d: (Timeout) %s - %s\n", \ tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, \ deviceName, message); return; } /* Register sequencer commands and program */ #include "epicsExport.h" static void timeoutRegistrar (void) { seqRegisterSequencerCommands(); seqRegisterSequencerProgram (&timeout); } epicsExportRegistrar(timeoutRegistrar);