/* C code for program ringBuffSave2, generated by snc from ../ringBuffSave2.stt */ #include #include #include #include #include "seq_snc.h" # line 5 "../ringBuffSave2.stt" #include # line 6 "../ringBuffSave2.stt" #include # line 7 "../ringBuffSave2.stt" #include # line 8 "../ringBuffSave2.stt" static void getTimestampString(char *ts_string, int num); # line 9 "../ringBuffSave2.stt" static void save_file(char *dir, char *file_name, double rate, int post_trig_delay, int length, int adc0[], int adc1[], int adc2[], int adc3[]); # line 29 "../ringBuffSave2.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 adc0[], int adc1[], int adc2[], int adc3[]) { 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, "adc0"); for(i=0; i<1024; i++) fprintf(file, ", %d", adc0[i]); fprintf(file, "\n"); fprintf(file, "adc1"); for(i=0; i<1024; i++) fprintf(file, ", %d", adc1[i]); fprintf(file, "\n"); fprintf(file, "adc2"); for(i=0; i<1024; i++) fprintf(file, ", %d", adc2[i]); fprintf(file, "\n"); fprintf(file, "adc3"); for(i=0; i<1024; i++) fprintf(file, ", %d", adc3[i]); fprintf(file, "\n"); fclose(file); } /* Variable declarations */ struct seqg_vars { # line 11 "../ringBuffSave2.stt" double rate; # line 12 "../ringBuffSave2.stt" int post_trig_delay; # line 13 "../ringBuffSave2.stt" int adc0[1024]; # line 13 "../ringBuffSave2.stt" int adc1[1024]; # line 13 "../ringBuffSave2.stt" int adc2[1024]; # line 13 "../ringBuffSave2.stt" int adc3[1024]; # line 15 "../ringBuffSave2.stt" int log; # line 17 "../ringBuffSave2.stt" char *dir_name; # line 18 "../ringBuffSave2.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 84 "../ringBuffSave2.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 85 "../ringBuffSave2.stt" seqg_var->dir_name = seq_macValueGet(seqg_env, "DIR") ? seq_macValueGet(seqg_env, "DIR") : "/tmp"; # line 86 "../ringBuffSave2.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 92 "../ringBuffSave2.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 99 "../ringBuffSave2.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 101 "../ringBuffSave2.stt" save_file (pVar->dir_name, pVar->file_prefix, pVar->rate, pVar->post_trig_delay, 1024, pVar->adc0, pVar->adc1, pVar->adc2, pVar->adc3); # line 102 "../ringBuffSave2.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:ADC0", offsetof(struct seqg_vars, adc0), "adc0", P_INT, 1024, 3, 0, 1, 0, 0}, {"{NAME}:RBUF:ADC1", offsetof(struct seqg_vars, adc1), "adc1", P_INT, 1024, 4, 0, 1, 0, 0}, {"{NAME}:RBUF:ADC2", offsetof(struct seqg_vars, adc2), "adc2", P_INT, 1024, 5, 0, 1, 0, 0}, {"{NAME}:RBUF:ADC3", offsetof(struct seqg_vars, adc3), "adc3", P_INT, 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 ringBuffSave2 = { /* magic number */ 2002004, /* program name */ "ringBuffSave2", /* 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 ringBuffSave2Registrar (void) { seqRegisterSequencerCommands(); seqRegisterSequencerProgram (&ringBuffSave2); } epicsExportRegistrar(ringBuffSave2Registrar);