/* SNC Version 2.0.11: Wed Nov 2 19:48:22 2011: ../bpmDisp.stt */ /* Event flags */ #define ef_ev1 1 #define ef_ev2 2 #define ef_get_data 3 #define ef_check 4 #define ef_put_data 5 /* Program "bpmDisp" */ #include "seqCom.h" #define NUM_SS 4 #define NUM_CHANNELS 31 #define NUM_EVENTS 5 #define NUM_QUEUES 0 #define MAX_STRING_SIZE 40 #define ASYNC_OPT FALSE #define CONN_OPT FALSE #define DEBUG_OPT FALSE #define MAIN_OPT FALSE #define NEWEF_OPT TRUE #define REENT_OPT FALSE extern struct seqProgram bpmDisp; /* Variable declarations */ static double wf_in[12][2800]; static double wf_out[12][2800]; static double t[12]; static short wf_in_conn[12]; static int nsig; static char *nsig_s; static short i; static short j; static short k; static short getcnt; static double ev1; static double ev2; static float tdly; static float tdiff; static unsigned long tcnt; static short dbug; static short nochk; static double tmax; static double tmin; /* Not used (avoids compilation warnings) */ struct UserVar { int dummy; }; /* C code definitions */ # line 38 "../bpmDisp.stt" # line 39 "../bpmDisp.stt" #include # line 40 "../bpmDisp.stt" #include # line 41 "../bpmDisp.stt" #include # line 42 "../bpmDisp.stt" #include # line 43 "../bpmDisp.stt" #include # line 44 "../bpmDisp.stt" #include "errlog.h" # line 45 "../bpmDisp.stt" # line 46 "../bpmDisp.stt" #define MIN(a,b) ((a>b) ? b : a) # line 47 "../bpmDisp.stt" #define MAX(a,b) ((a>b) ? a : b) # line 48 "../bpmDisp.stt" # line 49 "../bpmDisp.stt" #define INITWAIT 3 /* Wait on startup for online PVs to connect */ # line 50 "../bpmDisp.stt" #define NELM 2800 # line 50 "../bpmDisp.stt" # line 97 "../bpmDisp.stt" # line 98 "../bpmDisp.stt" /* Signal timestamps; epicsTimeStamp data type */ # line 99 "../bpmDisp.stt" TS_STAMP ts[12]; # line 100 "../bpmDisp.stt" # line 101 "../bpmDisp.stt" /* Previous timestamps; epicsTimeStamp data type */ # line 102 "../bpmDisp.stt" TS_STAMP lts[12]; # line 103 "../bpmDisp.stt" # line 104 "../bpmDisp.stt" /* Data timestamp has changed */ # line 105 "../bpmDisp.stt" short newts[12]; # line 105 "../bpmDisp.stt" /* Entry handler */ static void entry_handler(SS_ID ssId, struct UserVar *pVar) { } /* Code for state "init" in state set "timer" */ /* Delay function for state "init" in state set "timer" */ static void D_timer_init(SS_ID ssId, struct UserVar *pVar) { # line 209 "../bpmDisp.stt" seq_delayInit(ssId, 0, (INITWAIT)); } /* Event function for state "init" in state set "timer" */ static long E_timer_init(SS_ID ssId, struct UserVar *pVar, short *pTransNum, short *pNextState) { # line 209 "../bpmDisp.stt" if (seq_delay(ssId, 0)) { *pNextState = 1; *pTransNum = 0; return TRUE; } return FALSE; } /* Action function for state "init" in state set "timer" */ static void A_timer_init(SS_ID ssId, struct UserVar *pVar, short transNum) { switch(transNum) { case 0: { # line 207 "../bpmDisp.stt" nsig_s = seq_macValueGet(ssId, "N"); # line 209 "../bpmDisp.stt" nsig = atoi(nsig_s); } return; } } /* Code for state "init_timer" in state set "timer" */ /* Delay function for state "init_timer" in state set "timer" */ static void D_timer_init_timer(SS_ID ssId, struct UserVar *pVar) { # line 214 "../bpmDisp.stt" } /* Event function for state "init_timer" in state set "timer" */ static long E_timer_init_timer(SS_ID ssId, struct UserVar *pVar, short *pTransNum, short *pNextState) { # line 214 "../bpmDisp.stt" if (seq_efTestAndClear(ssId, ef_ev1) || seq_efTestAndClear(ssId, ef_ev2)) { *pNextState = 2; *pTransNum = 0; return TRUE; } return FALSE; } /* Action function for state "init_timer" in state set "timer" */ static void A_timer_init_timer(SS_ID ssId, struct UserVar *pVar, short transNum) { switch(transNum) { case 0: { } return; } } /* Code for state "run_timer" in state set "timer" */ /* Delay function for state "run_timer" in state set "timer" */ static void D_timer_run_timer(SS_ID ssId, struct UserVar *pVar) { # line 230 "../bpmDisp.stt" } /* Event function for state "run_timer" in state set "timer" */ static long E_timer_run_timer(SS_ID ssId, struct UserVar *pVar, short *pTransNum, short *pNextState) { # line 230 "../bpmDisp.stt" if (TRUE) { *pNextState = 1; *pTransNum = 0; return TRUE; } return FALSE; } /* Action function for state "run_timer" in state set "timer" */ static void A_timer_run_timer(SS_ID ssId, struct UserVar *pVar, short transNum) { switch(transNum) { case 0: { # line 220 "../bpmDisp.stt" getcnt = 1; # line 225 "../bpmDisp.stt" for (k = 1; k < (1 / tdly); k++) { seq_efSet(ssId, ef_get_data); epicsThreadSleep(tdly); } # line 226 "../bpmDisp.stt" seq_efSet(ssId, ef_get_data); # line 228 "../bpmDisp.stt" seq_efTestAndClear(ssId, ef_ev1); seq_efTestAndClear(ssId, ef_ev2); } return; } } /* Code for state "init" in state set "acq_data" */ /* Delay function for state "init" in state set "acq_data" */ static void D_acq_data_init(SS_ID ssId, struct UserVar *pVar) { # line 251 "../bpmDisp.stt" } /* Event function for state "init" in state set "acq_data" */ static long E_acq_data_init(SS_ID ssId, struct UserVar *pVar, short *pTransNum, short *pNextState) { # line 251 "../bpmDisp.stt" if (seq_efTestAndClear(ssId, ef_get_data)) { *pNextState = 1; *pTransNum = 0; return TRUE; } return FALSE; } /* Action function for state "init" in state set "acq_data" */ static void A_acq_data_init(SS_ID ssId, struct UserVar *pVar, short transNum) { switch(transNum) { case 0: { } return; } } /* Code for state "get_data" in state set "acq_data" */ /* Delay function for state "get_data" in state set "acq_data" */ static void D_acq_data_get_data(SS_ID ssId, struct UserVar *pVar) { # line 273 "../bpmDisp.stt" } /* Event function for state "get_data" in state set "acq_data" */ static long E_acq_data_get_data(SS_ID ssId, struct UserVar *pVar, short *pTransNum, short *pNextState) { # line 273 "../bpmDisp.stt" if (TRUE) { *pNextState = 0; *pTransNum = 0; return TRUE; } return FALSE; } /* Action function for state "get_data" in state set "acq_data" */ static void A_acq_data_get_data(SS_ID ssId, struct UserVar *pVar, short transNum) { switch(transNum) { case 0: { # line 271 "../bpmDisp.stt" for (i = 0; i < nsig; i++) { wf_in_conn[i] = seq_pvConnected(ssId, 0 /* wf_in */ + (i)); if (wf_in_conn[i]) { seq_pvGet(ssId, 0 /* wf_in */ + (i), 0); } else { if (dbug) { printf("%i: PV not connected\n", i); } } } # line 272 "../bpmDisp.stt" seq_efSet(ssId, ef_check); } return; } } /* Code for state "check" in state set "check_data" */ /* Delay function for state "check" in state set "check_data" */ static void D_check_data_check(SS_ID ssId, struct UserVar *pVar) { # line 384 "../bpmDisp.stt" } /* Event function for state "check" in state set "check_data" */ static long E_check_data_check(SS_ID ssId, struct UserVar *pVar, short *pTransNum, short *pNextState) { # line 384 "../bpmDisp.stt" if (seq_efTestAndClear(ssId, ef_check)) { *pNextState = 0; *pTransNum = 0; return TRUE; } return FALSE; } /* Action function for state "check" in state set "check_data" */ static void A_check_data_check(SS_ID ssId, struct UserVar *pVar, short transNum) { switch(transNum) { case 0: { # line 305 "../bpmDisp.stt" tmax = 0; tmin = 0; # line 347 "../bpmDisp.stt" for (i = 0; i < nsig; i++) { if (wf_in_conn[i]) { ts[i] = seq_pvTimeStamp(ssId, 0 /* wf_in */ + (i)); t[i] = ts[i] . secPastEpoch + ts[i] . nsec * 1e-9; if (dbug) { printf("%i: TS seconds is %i\n", i, ts[i] . secPastEpoch); printf("%i: TS nanoseconds is %i\n", i, ts[i] . nsec); printf("%i: TS is %f\n\n", i, t[i]); } if (!(ts[i] . secPastEpoch == lts[i] . secPastEpoch && ts[i] . nsec == lts[i] . nsec)) { newts[i] = 1; } else { newts[i] = 0; } if (newts[i]) { tmax = MAX(tmax, t[i]); tmin = MAX(tmin, t[i]); } lts[i] = ts[i]; } } # line 349 "../bpmDisp.stt" tdiff = tmax - tmin; seq_pvPut(ssId, 27 /* tdiff */, 0); # line 357 "../bpmDisp.stt" if (tdiff == 0) { seq_efSet(ssId, ef_put_data); } # line 382 "../bpmDisp.stt" else { seq_pvGet(ssId, 28 /* tcnt */, 0); tcnt++; seq_pvPut(ssId, 28 /* tcnt */, 0); if (dbug) { printf("%i: Timestamps differ. Max - min = %f\n", i, tdiff); printf("%i: Try %i\n to get synchronous data", i, getcnt); } if (nochk && (getcnt == 3)) { seq_efSet(ssId, ef_put_data); if (dbug) { printf("%i: Set put data flag. nochks is %i; getcnt is %i\n", i, nochk, getcnt); } } else { seq_efSet(ssId, ef_get_data); } } } return; } } /* Code for state "init" in state set "put_data" */ /* Delay function for state "init" in state set "put_data" */ static void D_put_data_init(SS_ID ssId, struct UserVar *pVar) { # line 410 "../bpmDisp.stt" } /* Event function for state "init" in state set "put_data" */ static long E_put_data_init(SS_ID ssId, struct UserVar *pVar, short *pTransNum, short *pNextState) { # line 410 "../bpmDisp.stt" if (seq_efTestAndClear(ssId, ef_put_data)) { *pNextState = 1; *pTransNum = 0; return TRUE; } return FALSE; } /* Action function for state "init" in state set "put_data" */ static void A_put_data_init(SS_ID ssId, struct UserVar *pVar, short transNum) { switch(transNum) { case 0: { } return; } } /* Code for state "put" in state set "put_data" */ /* Delay function for state "put" in state set "put_data" */ static void D_put_data_put(SS_ID ssId, struct UserVar *pVar) { # line 436 "../bpmDisp.stt" } /* Event function for state "put" in state set "put_data" */ static long E_put_data_put(SS_ID ssId, struct UserVar *pVar, short *pTransNum, short *pNextState) { # line 436 "../bpmDisp.stt" if (TRUE) { *pNextState = 0; *pTransNum = 0; return TRUE; } return FALSE; } /* Action function for state "put" in state set "put_data" */ static void A_put_data_put(SS_ID ssId, struct UserVar *pVar, short transNum) { switch(transNum) { case 0: { # line 435 "../bpmDisp.stt" for (i = 0; i < nsig; i++) { if (newts[i] && wf_in_conn[i]) { for (j = 0; j < NELM; j++) { wf_out[i][j] = wf_in[i][j]; } seq_pvPut(ssId, 12 /* wf_out */ + (i), 0); } else { if (dbug) { printf("%i: Didn't put data. newts is %i. PVconn is %i.\n", i, newts[i], wf_in_conn[i]); } } } } return; } } /* Exit handler */ static void exit_handler(SS_ID ssId, struct UserVar *pVar) { } /************************ Tables ***********************/ /* Database Blocks */ static struct seqChan seqChan[NUM_CHANNELS] = { {"{SIG0}HSTBR", (void *)&wf_in[0][0], "wf_in[0][0]", "double", 2800, 6, 0, 0, 0, 0, 0}, {"{SIG1}HSTBR", (void *)&wf_in[1][0], "wf_in[1][0]", "double", 2800, 7, 0, 0, 0, 0, 0}, {"{SIG2}HSTBR", (void *)&wf_in[2][0], "wf_in[2][0]", "double", 2800, 8, 0, 0, 0, 0, 0}, {"{SIG3}HSTBR", (void *)&wf_in[3][0], "wf_in[3][0]", "double", 2800, 9, 0, 0, 0, 0, 0}, {"{SIG4}HSTBR", (void *)&wf_in[4][0], "wf_in[4][0]", "double", 2800, 10, 0, 0, 0, 0, 0}, {"{SIG5}HSTBR", (void *)&wf_in[5][0], "wf_in[5][0]", "double", 2800, 11, 0, 0, 0, 0, 0}, {"{SIG6}HSTBR", (void *)&wf_in[6][0], "wf_in[6][0]", "double", 2800, 12, 0, 0, 0, 0, 0}, {"{SIG7}HSTBR", (void *)&wf_in[7][0], "wf_in[7][0]", "double", 2800, 13, 0, 0, 0, 0, 0}, {"{SIG8}HSTBR", (void *)&wf_in[8][0], "wf_in[8][0]", "double", 2800, 14, 0, 0, 0, 0, 0}, {"{SIG9}HSTBR", (void *)&wf_in[9][0], "wf_in[9][0]", "double", 2800, 15, 0, 0, 0, 0, 0}, {"{SIG10}HSTBR", (void *)&wf_in[10][0], "wf_in[10][0]", "double", 2800, 16, 0, 0, 0, 0, 0}, {"{SIG11}HSTBR", (void *)&wf_in[11][0], "wf_in[11][0]", "double", 2800, 17, 0, 0, 0, 0, 0}, {"{SIG0}HSTBRDSP", (void *)&wf_out[0][0], "wf_out[0][0]", "double", 2800, 18, 0, 0, 0, 0, 0}, {"{SIG1}HSTBRDSP", (void *)&wf_out[1][0], "wf_out[1][0]", "double", 2800, 19, 0, 0, 0, 0, 0}, {"{SIG2}HSTBRDSP", (void *)&wf_out[2][0], "wf_out[2][0]", "double", 2800, 20, 0, 0, 0, 0, 0}, {"{SIG3}HSTBRDSP", (void *)&wf_out[3][0], "wf_out[3][0]", "double", 2800, 21, 0, 0, 0, 0, 0}, {"{SIG4}HSTBRDSP", (void *)&wf_out[4][0], "wf_out[4][0]", "double", 2800, 22, 0, 0, 0, 0, 0}, {"{SIG5}HSTBRDSP", (void *)&wf_out[5][0], "wf_out[5][0]", "double", 2800, 23, 0, 0, 0, 0, 0}, {"{SIG6}HSTBRDSP", (void *)&wf_out[6][0], "wf_out[6][0]", "double", 2800, 24, 0, 0, 0, 0, 0}, {"{SIG7}HSTBRDSP", (void *)&wf_out[7][0], "wf_out[7][0]", "double", 2800, 25, 0, 0, 0, 0, 0}, {"{SIG8}HSTBRDSP", (void *)&wf_out[8][0], "wf_out[8][0]", "double", 2800, 26, 0, 0, 0, 0, 0}, {"{SIG9}HSTBRDSP", (void *)&wf_out[9][0], "wf_out[9][0]", "double", 2800, 27, 0, 0, 0, 0, 0}, {"{SIG10}HSTBRDSP", (void *)&wf_out[10][0], "wf_out[10][0]", "double", 2800, 28, 0, 0, 0, 0, 0}, {"{SIG11}HSTBRDSP", (void *)&wf_out[11][0], "wf_out[11][0]", "double", 2800, 29, 0, 0, 0, 0, 0}, {"{SIG1}1H", (void *)&ev1, "ev1", "double", 1, 30, 1, 1, 0, 0, 0}, {"{SIG2}1H", (void *)&ev2, "ev2", "double", 1, 31, 2, 1, 0, 0, 0}, {"{IOC}SEQ_TDLY", (void *)&tdly, "tdly", "float", 1, 32, 0, 1, 0, 0, 0}, {"{IOC}SEQ_TDIFF", (void *)&tdiff, "tdiff", "float", 1, 33, 0, 1, 0, 0, 0}, {"{IOC}SEQ_TDIFFCNT", (void *)&tcnt, "tcnt", "unsigned long", 1, 34, 0, 1, 0, 0, 0}, {"{IOC}SEQ_DEBUG", (void *)&dbug, "dbug", "short", 1, 35, 0, 1, 0, 0, 0}, {"{IOC}SEQ_CHK", (void *)&nochk, "nochk", "short", 1, 36, 0, 1, 0, 0, 0}, }; /* Event masks for state set timer */ /* Event mask for state init: */ static bitMask EM_timer_init[] = { 0x00000000, 0x00000000, }; /* Event mask for state init_timer: */ static bitMask EM_timer_init_timer[] = { 0x00000006, 0x00000000, }; /* Event mask for state run_timer: */ static bitMask EM_timer_run_timer[] = { 0x00000000, 0x00000000, }; /* State Blocks */ static struct seqState state_timer[] = { /* State "init" */ { /* state name */ "init", /* action function */ (ACTION_FUNC) A_timer_init, /* event function */ (EVENT_FUNC) E_timer_init, /* delay function */ (DELAY_FUNC) D_timer_init, /* entry function */ (ENTRY_FUNC) 0, /* exit function */ (EXIT_FUNC) 0, /* event mask array */ EM_timer_init, /* state options */ (0)}, /* State "init_timer" */ { /* state name */ "init_timer", /* action function */ (ACTION_FUNC) A_timer_init_timer, /* event function */ (EVENT_FUNC) E_timer_init_timer, /* delay function */ (DELAY_FUNC) D_timer_init_timer, /* entry function */ (ENTRY_FUNC) 0, /* exit function */ (EXIT_FUNC) 0, /* event mask array */ EM_timer_init_timer, /* state options */ (0)}, /* State "run_timer" */ { /* state name */ "run_timer", /* action function */ (ACTION_FUNC) A_timer_run_timer, /* event function */ (EVENT_FUNC) E_timer_run_timer, /* delay function */ (DELAY_FUNC) D_timer_run_timer, /* entry function */ (ENTRY_FUNC) 0, /* exit function */ (EXIT_FUNC) 0, /* event mask array */ EM_timer_run_timer, /* state options */ (0)}, }; /* Event masks for state set acq_data */ /* Event mask for state init: */ static bitMask EM_acq_data_init[] = { 0x00000008, 0x00000000, }; /* Event mask for state get_data: */ static bitMask EM_acq_data_get_data[] = { 0x00000000, 0x00000000, }; /* State Blocks */ static struct seqState state_acq_data[] = { /* State "init" */ { /* state name */ "init", /* action function */ (ACTION_FUNC) A_acq_data_init, /* event function */ (EVENT_FUNC) E_acq_data_init, /* delay function */ (DELAY_FUNC) D_acq_data_init, /* entry function */ (ENTRY_FUNC) 0, /* exit function */ (EXIT_FUNC) 0, /* event mask array */ EM_acq_data_init, /* state options */ (0)}, /* State "get_data" */ { /* state name */ "get_data", /* action function */ (ACTION_FUNC) A_acq_data_get_data, /* event function */ (EVENT_FUNC) E_acq_data_get_data, /* delay function */ (DELAY_FUNC) D_acq_data_get_data, /* entry function */ (ENTRY_FUNC) 0, /* exit function */ (EXIT_FUNC) 0, /* event mask array */ EM_acq_data_get_data, /* state options */ (0)}, }; /* Event masks for state set check_data */ /* Event mask for state check: */ static bitMask EM_check_data_check[] = { 0x00000010, 0x00000000, }; /* State Blocks */ static struct seqState state_check_data[] = { /* State "check" */ { /* state name */ "check", /* action function */ (ACTION_FUNC) A_check_data_check, /* event function */ (EVENT_FUNC) E_check_data_check, /* delay function */ (DELAY_FUNC) D_check_data_check, /* entry function */ (ENTRY_FUNC) 0, /* exit function */ (EXIT_FUNC) 0, /* event mask array */ EM_check_data_check, /* state options */ (0)}, }; /* Event masks for state set put_data */ /* Event mask for state init: */ static bitMask EM_put_data_init[] = { 0x00000020, 0x00000000, }; /* Event mask for state put: */ static bitMask EM_put_data_put[] = { 0x00000000, 0x00000000, }; /* State Blocks */ static struct seqState state_put_data[] = { /* State "init" */ { /* state name */ "init", /* action function */ (ACTION_FUNC) A_put_data_init, /* event function */ (EVENT_FUNC) E_put_data_init, /* delay function */ (DELAY_FUNC) D_put_data_init, /* entry function */ (ENTRY_FUNC) 0, /* exit function */ (EXIT_FUNC) 0, /* event mask array */ EM_put_data_init, /* state options */ (0)}, /* State "put" */ { /* state name */ "put", /* action function */ (ACTION_FUNC) A_put_data_put, /* event function */ (EVENT_FUNC) E_put_data_put, /* delay function */ (DELAY_FUNC) D_put_data_put, /* entry function */ (ENTRY_FUNC) 0, /* exit function */ (EXIT_FUNC) 0, /* event mask array */ EM_put_data_put, /* state options */ (0)}, }; /* State Set Blocks */ static struct seqSS seqSS[NUM_SS] = { /* State set "timer" */ { /* ss name */ "timer", /* ptr to state block */ state_timer, /* number of states */ 3, /* error state */ -1}, /* State set "acq_data" */ { /* ss name */ "acq_data", /* ptr to state block */ state_acq_data, /* number of states */ 2, /* error state */ -1}, /* State set "check_data" */ { /* ss name */ "check_data", /* ptr to state block */ state_check_data, /* number of states */ 1, /* error state */ -1}, /* State set "put_data" */ { /* ss name */ "put_data", /* ptr to state block */ state_put_data, /* number of states */ 2, /* error state */ -1}, }; /* Program parameter list */ static char prog_param[] = ""; /* State Program table (global) */ struct seqProgram bpmDisp = { /* magic number */ 20000315, /* *name */ "bpmDisp", /* *pChannels */ seqChan, /* numChans */ NUM_CHANNELS, /* *pSS */ seqSS, /* numSS */ NUM_SS, /* user variable size */ 0, /* *pParams */ prog_param, /* numEvents */ NUM_EVENTS, /* encoded options */ (0 | OPT_NEWEF), /* entry handler */ (ENTRY_FUNC) entry_handler, /* exit handler */ (EXIT_FUNC) exit_handler, /* numQueues */ NUM_QUEUES, }; /* Register sequencer commands and program */ void bpmDispRegistrar (void) { seqRegisterSequencerCommands(); seqRegisterSequencerProgram (&bpmDisp); } epicsExportRegistrar(bpmDispRegistrar);