/* SNC Version 2.0.11: Wed Nov 2 19:48:22 2011: sncExample.i */ /* Event flags */ /* Program "snctest" */ #include "seqCom.h" #define NUM_SS 1 #define NUM_CHANNELS 1 #define NUM_EVENTS 0 #define NUM_QUEUES 0 #define MAX_STRING_SIZE 40 #define ASYNC_OPT FALSE #define CONN_OPT TRUE #define DEBUG_OPT FALSE #define MAIN_OPT TRUE #define NEWEF_OPT TRUE #define REENT_OPT TRUE extern struct seqProgram snctest; /* Main program */ #include #include "epicsThread.h" #include "iocsh.h" int main(int argc,char *argv[]) { char * macro_def; epicsThreadId threadId; int callIocsh = 0; if(argc>1 && strcmp(argv[1],"-s")==0) { callIocsh=1; --argc; ++argv; } macro_def = (argc>1)?argv[1]:NULL; threadId = seq((void *)&snctest, macro_def, 0); if(callIocsh) { seqRegisterSequencerCommands(); iocsh(0); } else { epicsThreadExitMain(); } return(0); } /* Variable declarations */ struct UserVar { float v; }; /* Entry handler */ static void entry_handler(SS_ID ssId, struct UserVar *pVar) { } /* Code for state "low" in state set "ss1" */ /* Delay function for state "low" in state set "ss1" */ static void D_ss1_low(SS_ID ssId, struct UserVar *pVar) { # line 14 "../sncExample.st" # line 17 "../sncExample.st" seq_delayInit(ssId, 0, (.1)); } /* Event function for state "low" in state set "ss1" */ static long E_ss1_low(SS_ID ssId, struct UserVar *pVar, short *pTransNum, short *pNextState) { # line 14 "../sncExample.st" if ((pVar->v) > 5.0) { *pNextState = 1; *pTransNum = 0; return TRUE; } # line 17 "../sncExample.st" if (seq_delay(ssId, 0)) { *pNextState = 0; *pTransNum = 1; return TRUE; } return FALSE; } /* Action function for state "low" in state set "ss1" */ static void A_ss1_low(SS_ID ssId, struct UserVar *pVar, short transNum) { switch(transNum) { case 0: { # line 13 "../sncExample.st" printf("now changing to high\n"); } return; case 1: { } return; } } /* Code for state "high" in state set "ss1" */ /* Delay function for state "high" in state set "ss1" */ static void D_ss1_high(SS_ID ssId, struct UserVar *pVar) { # line 24 "../sncExample.st" # line 27 "../sncExample.st" seq_delayInit(ssId, 0, (.1)); } /* Event function for state "high" in state set "ss1" */ static long E_ss1_high(SS_ID ssId, struct UserVar *pVar, short *pTransNum, short *pNextState) { # line 24 "../sncExample.st" if ((pVar->v) <= 5.0) { *pNextState = 0; *pTransNum = 0; return TRUE; } # line 27 "../sncExample.st" if (seq_delay(ssId, 0)) { *pNextState = 1; *pTransNum = 1; return TRUE; } return FALSE; } /* Action function for state "high" in state set "ss1" */ static void A_ss1_high(SS_ID ssId, struct UserVar *pVar, short transNum) { switch(transNum) { case 0: { # line 23 "../sncExample.st" printf("changing to low\n"); } return; case 1: { } return; } } /* Exit handler */ static void exit_handler(SS_ID ssId, struct UserVar *pVar) { } /************************ Tables ***********************/ /* Database Blocks */ static struct seqChan seqChan[NUM_CHANNELS] = { {"{user}:xxxExample", (void *)OFFSET(struct UserVar, v), "v", "float", 1, 1, 0, 1, 0, 0, 0}, }; /* Event masks for state set ss1 */ /* Event mask for state low: */ static bitMask EM_ss1_low[] = { 0x00000002, }; /* Event mask for state high: */ static bitMask EM_ss1_high[] = { 0x00000002, }; /* State Blocks */ static struct seqState state_ss1[] = { /* State "low" */ { /* state name */ "low", /* action function */ (ACTION_FUNC) A_ss1_low, /* event function */ (EVENT_FUNC) E_ss1_low, /* delay function */ (DELAY_FUNC) D_ss1_low, /* entry function */ (ENTRY_FUNC) 0, /* exit function */ (EXIT_FUNC) 0, /* event mask array */ EM_ss1_low, /* state options */ (0)}, /* State "high" */ { /* state name */ "high", /* action function */ (ACTION_FUNC) A_ss1_high, /* event function */ (EVENT_FUNC) E_ss1_high, /* delay function */ (DELAY_FUNC) D_ss1_high, /* entry function */ (ENTRY_FUNC) 0, /* exit function */ (EXIT_FUNC) 0, /* event mask array */ EM_ss1_high, /* state options */ (0)}, }; /* State Set Blocks */ static struct seqSS seqSS[NUM_SS] = { /* State set "ss1" */ { /* ss name */ "ss1", /* ptr to state block */ state_ss1, /* number of states */ 2, /* error state */ -1}, }; /* Program parameter list */ static char prog_param[] = ""; /* State Program table (global) */ struct seqProgram snctest = { /* magic number */ 20000315, /* *name */ "snctest", /* *pChannels */ seqChan, /* numChans */ NUM_CHANNELS, /* *pSS */ seqSS, /* numSS */ NUM_SS, /* user variable size */ sizeof(struct UserVar), /* *pParams */ prog_param, /* numEvents */ NUM_EVENTS, /* encoded options */ (0 | OPT_CONN | OPT_NEWEF | OPT_REENT | OPT_MAIN), /* entry handler */ (ENTRY_FUNC) entry_handler, /* exit handler */ (EXIT_FUNC) exit_handler, /* numQueues */ NUM_QUEUES, }; /* Register sequencer commands and program */ void snctestRegistrar (void) { seqRegisterSequencerCommands(); seqRegisterSequencerProgram (&snctest); } epicsExportRegistrar(snctestRegistrar);