/* C code for program ringBuffSave, generated by snc from ../ringBuffSave.stt */ #include #include #include #include #include "seq_snc.h" # line 5 "../ringBuffSave.stt" #include # line 6 "../ringBuffSave.stt" #include # line 7 "../ringBuffSave.stt" #include # line 8 "../ringBuffSave.stt" static void getTimestampString(char *ts_string, int num); # line 9 "../ringBuffSave.stt" static void save_file(char *dir, char *file_name, double rate, int post_trig_delay, int length, int red[], int green[], int blue[], double phase_err[]); # line 30 "../ringBuffSave.stt" static void getTimestampString(char *ts_string, int num) { epicsTimeStamp t; epicsTimeGetCurrent(&t); epicsTimeToStrftime(ts_string, num, "%Y%m%d_%H%M%S", &t); } static void save_file(char *dir, char *file_name, double rate, int post_trig_delay, int length, int red[], int green[], int blue[], double phase_err[]) { char ts_string[64]; char fname[512]; FILE *file; int i; getTimestampString(ts_string, 64); sprintf(fname, "%s/%s_%s.csv", dir, file_name, ts_string); file = fopen(fname, "w"); if(!file) { printf("could not open file (%s)\n", fname); return; } fprintf(file, "rate, %fMHz\n", rate); fprintf(file, "post_trig_delay, %d\n", post_trig_delay); fprintf(file, "length, %d\n", length); fprintf(file, "red"); for(i=0; i<1024; i++) fprintf(file, ", %d", red[i]); fprintf(file, "\n"); fprintf(file, "green"); for(i=0; i<1024; i++) fprintf(file, ", %d", green[i]); fprintf(file, "\n"); fprintf(file, "blue"); for(i=0; i<1024; i++) fprintf(file, ", %d", blue[i]); fprintf(file, "\n"); fprintf(file, "phase_err"); for(i=0; i<1024; i++) fprintf(file, ", %.8f", phase_err[i]); fprintf(file, "\n"); fclose(file); } /* Variable declarations */ struct seqg_vars { # line 11 "../ringBuffSave.stt" double rate; # line 12 "../ringBuffSave.stt" int post_trig_delay; # line 13 "../ringBuffSave.stt" int red[1024]; # line 13 "../ringBuffSave.stt" int green[1024]; # line 13 "../ringBuffSave.stt" int blue[1024]; # line 14 "../ringBuffSave.stt" double phase_err[1024]; # line 16 "../ringBuffSave.stt" int log; # line 18 "../ringBuffSave.stt" char *dir_name; # line 19 "../ringBuffSave.stt" char *file_prefix; }; /* 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 "ringBuffSave" ******/ /* Event function for state "init" in state set "ringBuffSave" */ static seqBool seqg_event_ringBuffSave_0_init(SS_ID seqg_env, int *seqg_ptrn, int *seqg_pnst) { # line 85 "../ringBuffSave.stt" if (1) { *seqg_pnst = 1; *seqg_ptrn = 0; return TRUE; } return FALSE; } /* Action function for state "init" in state set "ringBuffSave" */ static void seqg_action_ringBuffSave_0_init(SS_ID seqg_env, int seqg_trn, int *seqg_pnst) { switch(seqg_trn) { case 0: { # line 86 "../ringBuffSave.stt" seqg_var->dir_name = seq_macValueGet(seqg_env, "DIR") ? seq_macValueGet(seqg_env, "DIR") : "/tmp"; # line 87 "../ringBuffSave.stt" seqg_var->file_prefix = seq_macValueGet(seqg_env, "FILE") ? seq_macValueGet(seqg_env, "FILE") : "waveform_ringbuf"; } return; } } /****** Code for state "release" in state set "ringBuffSave" ******/ /* Event function for state "release" in state set "ringBuffSave" */ static seqBool seqg_event_ringBuffSave_0_release(SS_ID seqg_env, int *seqg_ptrn, int *seqg_pnst) { # line 93 "../ringBuffSave.stt" if (seqg_var->log) { *seqg_pnst = 2; *seqg_ptrn = 0; return TRUE; } return FALSE; } /* Action function for state "release" in state set "ringBuffSave" */ static void seqg_action_ringBuffSave_0_release(SS_ID seqg_env, int seqg_trn, int *seqg_pnst) { switch(seqg_trn) { case 0: { } return; } } /****** Code for state "push" in state set "ringBuffSave" ******/ /* Event function for state "push" in state set "ringBuffSave" */ static seqBool seqg_event_ringBuffSave_0_push(SS_ID seqg_env, int *seqg_ptrn, int *seqg_pnst) { # line 100 "../ringBuffSave.stt" if (!seqg_var->log) { *seqg_pnst = 1; *seqg_ptrn = 0; return TRUE; } return FALSE; } /* Action function for state "push" in state set "ringBuffSave" */ static void seqg_action_ringBuffSave_0_push(SS_ID seqg_env, int seqg_trn, int *seqg_pnst) { switch(seqg_trn) { case 0: { /* C code definitions */ # line 102 "../ringBuffSave.stt" save_file (pVar->dir_name, pVar->file_prefix, pVar->rate, pVar->post_trig_delay, 1024, pVar->red, pVar->green, pVar->blue, pVar->phase_err); # line 103 "../ringBuffSave.stt" epicsThreadSleep(2.); } return; } } #undef seqg_var /************************ Tables ************************/ /* Channel table */ static seqChan seqg_chans[] = { /* chName, offset, varName, varType, count, eventNum, efId, monitored, queueSize, queueIndex */ {"{NAME}:LOGRATE", offsetof(struct seqg_vars, rate), "rate", P_DOUBLE, 1, 1, 0, 1, 0, 0}, {"{NAME}:POSTTRIGDLY", offsetof(struct seqg_vars, post_trig_delay), "post_trig_delay", P_INT, 1, 2, 0, 1, 0, 0}, {"{NAME}:RBUF:RED", offsetof(struct seqg_vars, red), "red", P_INT, 1024, 3, 0, 1, 0, 0}, {"{NAME}:RBUF:GREEN", offsetof(struct seqg_vars, green), "green", P_INT, 1024, 4, 0, 1, 0, 0}, {"{NAME}:RBUF:BLUE", offsetof(struct seqg_vars, blue), "blue", P_INT, 1024, 5, 0, 1, 0, 0}, {"{NAME}:RBUF:PHASEERR", offsetof(struct seqg_vars, phase_err), "phase_err", P_DOUBLE, 1024, 6, 0, 1, 0, 0}, {"{NAME}:STOPLOG", offsetof(struct seqg_vars, log), "log", P_INT, 1, 7, 0, 1, 0, 0}, }; /* Event masks for state set "ringBuffSave" */ static const seqMask seqg_mask_ringBuffSave_0_init[] = { 0x00000000, }; static const seqMask seqg_mask_ringBuffSave_0_release[] = { 0x00000080, }; static const seqMask seqg_mask_ringBuffSave_0_push[] = { 0x00000080, }; /* State table for state set "ringBuffSave" */ static seqState seqg_states_ringBuffSave[] = { { /* state name */ "init", /* action function */ seqg_action_ringBuffSave_0_init, /* event function */ seqg_event_ringBuffSave_0_init, /* entry function */ 0, /* exit function */ 0, /* event mask array */ seqg_mask_ringBuffSave_0_init, /* state options */ (0) }, { /* state name */ "release", /* action function */ seqg_action_ringBuffSave_0_release, /* event function */ seqg_event_ringBuffSave_0_release, /* entry function */ 0, /* exit function */ 0, /* event mask array */ seqg_mask_ringBuffSave_0_release, /* state options */ (0) }, { /* state name */ "push", /* action function */ seqg_action_ringBuffSave_0_push, /* event function */ seqg_event_ringBuffSave_0_push, /* entry function */ 0, /* exit function */ 0, /* event mask array */ seqg_mask_ringBuffSave_0_push, /* state options */ (0) }, }; /* State set table */ static seqSS seqg_statesets[] = { { /* state set name */ "ringBuffSave", /* states */ seqg_states_ringBuffSave, /* number of states */ 3 }, }; /* Program table (global) */ seqProgram ringBuffSave = { /* magic number */ 2002004, /* program name */ "ringBuffSave", /* channels */ seqg_chans, /* num. channels */ 7, /* state sets */ seqg_statesets, /* num. state sets */ 1, /* user var size */ sizeof(struct seqg_vars), /* param */ "", /* num. event flags */ 0, /* encoded options */ (0 | OPT_NEWEF | OPT_REENT), /* init func */ seqg_init, /* entry func */ 0, /* exit func */ 0, /* num. queues */ 0 }; /* Register sequencer commands and program */ #include "epicsExport.h" static void ringBuffSaveRegistrar (void) { seqRegisterSequencerCommands(); seqRegisterSequencerProgram (&ringBuffSave); } epicsExportRegistrar(ringBuffSaveRegistrar);