00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include <jsoc_main.h>
00036 #include <cmdparams.h>
00037 #include <drms.h>
00038 #include <drms_names.h>
00039 #include <stdio.h>
00040 #include <stdlib.h>
00041 #include <ctype.h>
00042 #include <strings.h>
00043 #include <errno.h>
00044 #include <sys/types.h>
00045 #include <sys/time.h>
00046 #include <sys/stat.h>
00047 #include <dirent.h>
00048 #include <unistd.h>
00049 #include <printk.h>
00050 #include <math.h>
00051 #include <signal.h>
00052 #include "packets.h"
00053 #include "imgdecode_iris.h"
00054 #include "decode_hk_vcdu.h"
00055 #include "decode_hk.h"
00056 #include "load_hk_config_files.h"
00057 #include "add_small_image.c"
00058 #include "mypng.h"
00059 #include "tdsignals.h"
00060 #include "quallev0_iris.h"
00061
00062 #define RESTART_CNT 2 //#of tlm files to process before restart
00063 #define MVDSFDIR "/sds/soc2pipe/iris/dsf/"
00064
00065
00066 #define TLMSERIESNAMEHMIAMES "iris_ground.tlm_ames"
00067 #define TLMSERIESNAMEHMI "iris.tlm"
00068
00069
00070 #define LEV0SERIESNAMEHMI "iris.lev0"
00071 #define LEV0SERIESNAMEHMIAMES "iris_ground.lev0_ames"
00072
00073 #define WDLOGDIR "/dds/logs"
00074 #define WDLOGFILE "wdlog"
00075
00076 #define H0LOGFILE "/usr/local/logs/lev0/ingest_lev0_iris.%s.%s.%s.log"
00077 #define PKTSZ 1788 //size of VCDU pkt
00078 #define DEFAULTDB "irisdb_sums" //the default db to connect to
00079 #define MAXFILES 65535 //max # of file can handle in tlmdir
00080 #define NUMTIMERS 8 //number of seperate timers avail
00081
00082 #define IMAGE_NUM_COMMIT 1
00083 #define TESTAPPID 0x199 //appid of test pattern packet
00084 #define TESTVALUE 0xc0b //first value in test pattern packet
00085 #define MAXERRMSGCNT 10 //max # of err msg before skip the tlm file
00086 #define NOTSPECIFIED "***NOTSPECIFIED***"
00087 #define ENVFILE "/home/prodtest/cvs/JSOC/proj/lev0/apps/SOURCE_ENV_FOR_HK_DECODE_IRIS"
00088 #define ENVFILEA "/home/prodtest/cvs/IRIS/proj/lev0/apps/SOURCE_ENV_FOR_HK_DECODE_AMES"
00089 #define ENVFILE_GND "/home/production/cvs/JSOC/proj/lev0/apps/SOURCE_ENV_FOR_HK_DECODE_GROUND"
00090
00091 extern int decode_next_hk_vcdu(unsigned short *tbuf, CCSDS_Packet_t **hk, unsigned int *Fsn);
00092 extern int write_hk_to_drms();
00093 extern void HMI_compute_exposure_times(DRMS_Record_t *rec, HK_Keyword_t *isp, int flg);
00094
00095 extern void sprint_time_ISOX (char *tstring, TIME t);
00096 static TIME SDO_to_DRMS_time(int sdo_s, int sdo_ss);
00097
00098 int nxlook[5][9] = {
00099 {1096, 0, 0, 0, 0, 0, 0, 0, 0},
00100 {0, 1096, 1096, 0, 1096, 0, 0, 0, 1096},
00101 {0, 548, 548, 0, 548, 0, 0, 0, 548},
00102 {0, 0, 0, 0, 0, 0, 0, 0, 0},
00103 {0, 274, 274, 0, 274, 0, 0, 0, 274}
00104 };
00105
00106 int nylook[5][9] = {
00107 {4144, 0, 0, 0, 0, 0, 0, 0, 0},
00108 {0, 4144, 2072, 0, 1036, 0, 0, 0, 518},
00109 {0, 4144, 2072, 0, 1036, 0, 0, 0, 518},
00110 {0, 0, 0, 0, 0, 0, 0, 0, 0},
00111 {0, 4144, 2072, 0, 1036, 0, 0, 0, 518}
00112 };
00113
00114 int nxlookTap[5][9] = {
00115 {1096, 0, 0, 0, 0, 0, 0, 0, 0},
00116 {0, 1096, 1096, 0, 1096, 0, 0, 0, 1096},
00117 {0, 548, 548, 0, 548, 0, 0, 0, 548},
00118 {0, 0, 0, 0, 0, 0, 0, 0, 0},
00119 {0, 274, 274, 0, 274, 0, 0, 0, 274}
00120 };
00121
00122 int nylookTap[5][9] = {
00123 {2072, 0, 0, 0, 0, 0, 0, 0, 0},
00124 {0, 2072, 1036, 0, 518, 0, 0, 0, 259},
00125 {0, 2072, 1036, 0, 518, 0, 0, 0, 259},
00126 {0, 0, 0, 0, 0, 0, 0, 0, 0},
00127 {0, 2072, 1036, 0, 518, 0, 0, 0, 259}
00128 };
00129
00130
00131 int nxlookdefault = 1096;
00132 int nylookdefault = 4144;
00133 int nxlookTapdefault = 1096;
00134 int nylookTapdefault = 2072;
00135
00136 struct nextimage {
00137 DRMS_Record_t *rsN;
00138 DRMS_Segment_t *segN;
00139 IMG *imgN;
00140 int fsnN;
00141 };
00142
00143 struct nextimage NextImage;
00144 static int OpenNextImg = 0;
00145
00146
00147 ModuleArgs_t module_args[] = {
00148 {ARG_STRING, "vc", NOTSPECIFIED, "Primary virt channel to listen to"},
00149 {ARG_STRING, "indir", NOTSPECIFIED, "directory containing the files to ingest"},
00150 {ARG_STRING, "outdir", NOTSPECIFIED, "directory to move the files to after the ingest"},
00151 {ARG_STRING, "pipedir", NOTSPECIFIED, "directory to get parc files from JSOC backend"},
00152 {ARG_STRING, "logfile", NOTSPECIFIED, "optional log file name. Will create one if not given"},
00153 {ARG_STRING, "envfile", ENVFILE, "env file name."},
00154 {ARG_STRING, "logroot", "/usr/local/logs", "optional log root directory"},
00155 {ARG_STRING, "dsout", "iris.lev0", "optional IRIS level 0 output series"},
00156 {ARG_STRING, "tlm_name", TLMSERIESNAMEHMI, "IRIS tlm output series"},
00157 {ARG_STRING, "bfsn", "1", "Skip FSN before"},
00158 {ARG_STRING, "efsn", "1073741823", "Skip FSN after"},
00159 {ARG_FLAG, "A", "0", "use Ames datasets"},
00160 {ARG_FLAG, "v", "0", "verbose flag"},
00161 {ARG_FLAG, "h", "0", "help flag"},
00162 {ARG_FLAG, "r", "0", "restart flag"},
00163 {ARG_FLAG, "l", "0", "wdlog flag"},
00164 {ARG_FLAG, "c", "0", "continue processing the current fsn after a imgdecode() error"},
00165 {ARG_END}
00166
00167 };
00168
00169 CmdParams_t cmdparams;
00170
00171 char *module_name = "ingest_lev0_iris";
00172
00173 typedef enum
00174 {
00175 kThreadSigErr_Success
00176 } ThreadSigErr_t;
00177 static short sumsptrl, sumspat;
00178 static int printflg = 0;
00179 static int errskip=0;
00180 static int seqerror = 0;
00181 static int retardskip=0;
00182 static int nx, ny, npix;
00183 static int gLoop = 1;
00184 static pthread_mutex_t mutex;
00185 static struct timeval tv0;
00186 static td_alarm_t talarm = 0;
00187 FILE *wdlogfp = NULL;
00188 FILE *h0logfp;
00189 static IMG Image, ImageOld;
00190 static IMG *Img, *ImgO, *ImgC;
00191 static CCSDS_Packet_t *Hk;
00192 static DRMS_Record_t *rs;
00193 static DRMS_Segment_t *segment;
00194 static DRMS_Array_t *segArray;
00195 static DRMS_RecordSet_t *rset;
00196 static DRMS_Record_t *rs_old, *rsc;
00197 static DRMS_Segment_t *segmentc;
00198 static DRMS_Array_t *cArray, *oldArray;
00199 static DRMS_SegmentDimInfo_t DimInfo;
00200 static TIME sdo_epoch;
00201 static char datestr[32];
00202 static char bld_vers[16];
00203
00204 static struct timeval first[NUMTIMERS], second[NUMTIMERS];
00205 static char Indir[300];
00206 static char *dsout, *logroot, hlogfile[256], *tlm_name;
00207 char wdlogname[128],oldwdlogname[128],Incmd[128];
00208
00209 int INVALtime;
00210 unsigned int bfsn = 1;
00211 unsigned int efsn = 0x3fffffff;
00212 unsigned int fsn = 0;
00213 unsigned int fsnx = 0;
00214 unsigned int fsnISP = 0;
00215 unsigned int fsnISPTOCLOSE = 0;
00216 unsigned int fsnISPX = 0;
00217 unsigned int fsnISP_noop = 0;
00218 unsigned int fsn_prev = 0;
00219 unsigned int ispfound = 0;
00220 unsigned int ispfoundreopen = 0;
00221 unsigned int fsn_pre_rexmit = 0;
00222 unsigned int fid = 0;
00223 unsigned int tapcode = 0;
00224 unsigned int cropid = 0;
00225 unsigned int isysn = 0;
00226
00227 short *rdat;
00228 short tmpdat[MAXPIXELS];
00229 long long vcdu_seq_num;
00230 long long vcdu_seq_num_next;
00231 long long total_missing_im_pdu;
00232 unsigned int vcdu_24_cnt, vcdu_24_cnt_next;
00233 int verbose;
00234 int grounddata = 0;
00235 int appid;
00236 int testid1, testid2;
00237 int hmiaiaflg;
00238 int whk_status;
00239 int total_tlm_vcdu;
00240 int total_missing_vcdu;
00241 int errmsgcnt, fileimgcnt;
00242 int cntsleeps = 0;
00243 int nofiletimeout = 0;
00244 int timeoutclose = 0;
00245 int paused = 0;
00246 int imagecnt = 0;
00247 int restartflg = 0;
00248 int amesflg = 0;
00249 int logflg = 0;
00250 int abortflg = 0;
00251 int conterr = 0;
00252 int sigalrmflg = 0;
00253 int ignoresigalrmflg = 0;
00254 int firstfound = 0;
00255 int ALRMSEC = 60;
00256 int sleep_interval = 2;
00257 char ispquery[256];
00258 char logname[128];
00259 char argvc[32], argindir[96], arglogfile[96], argoutdir[96], argpipedir[96];
00260 char timetag[32];
00261 char pchan[8];
00262 char rchan[8];
00263 char stopfile[80];
00264 char tlmseriesname[128];
00265 char lev0seriesname[128];
00266 char tlmnamekey[128];
00267 char tlmnamekeyfirst[128];
00268 char oldtlmdsnam[128];
00269 char *dbname = DEFAULTDB;
00270 char *username;
00271 char *tlmdir;
00272 char *outdir;
00273 char *pipedir;
00274 char *logfile;
00275 char *vc;
00276 DRMS_RecordSet_t *RSISP, *RSISPTO;
00277 struct stat stbuf;
00278 struct p_r_chans {
00279 char *pchan;
00280 char *rchan;
00281 int instru;
00282 };
00283 typedef struct p_r_chans P_R_CHANS;
00284
00285 P_R_CHANS p_r_chan_pairs[] = {
00286
00287
00288
00289
00290
00291
00292 {"VC03", "VC05", 0},
00293 {"n/a", "n/a"}
00294 };
00295
00296 struct namesort {
00297 char *name;
00298 };
00299 typedef struct namesort NAMESORT;
00300
00301
00302 int nice_intro ()
00303 {
00304 int usage = cmdparams_get_int (&cmdparams, "h", NULL);
00305 if (usage)
00306 {
00307 printf ("Usage:\ningest_lev0_irisdc [-vh] "
00308 "vc=<virt chan> indir=</dir> [outdir=</dir>] [pipedir=</dir>] [logfile=<file>]\n"
00309 " -h: help - show this message then exit\n"
00310 " -v: verbose\n"
00311
00312 " -l: keep logs under /dds (usually do for front end only)\n"
00313 " -c: continue processing the current fsn after a imgdecode() error\n"
00314 " -r: restart. only used when we restart ourselves periodically\n"
00315 " -A: Ames. Use Ames ds e.g. iris_ground.tlm_ames\n"
00316 "vc= primary virt channel to listen to e.g. VC02\n"
00317 "indir= directory containing the files to ingest\n"
00318 "outdir= optional dir to copy the files to after the ingest\n"
00319 " Do not specify this when run in the backend (cl1n001) so rm can be done\n"
00320 "pipedir= optional dir to get .parc files from JSOC backend\n"
00321 "logfile= optional log file name. Will create one if not given\n");
00322 return(1);
00323 }
00324 verbose = cmdparams_get_int (&cmdparams, "v", NULL);
00325
00326 conterr = cmdparams_get_int (&cmdparams, "c", NULL);
00327 restartflg = cmdparams_get_int (&cmdparams, "r", NULL);
00328 amesflg = cmdparams_get_int (&cmdparams, "A", NULL);
00329 logflg = cmdparams_get_int (&cmdparams, "l", NULL);
00330 return (0);
00331 }
00332
00333 TIME SDO_to_DRMS_time(int sdo_s, int sdo_ss)
00334 {
00335 static int firstcall = 1;
00336 if (firstcall)
00337 {
00338 firstcall = 0;
00339 }
00340
00341 return(sdo_epoch + (TIME)sdo_s + (TIME)(sdo_ss)/65536.0);
00342 }
00343
00344
00345 char *do_datestr() {
00346 time_t tval;
00347 struct tm *t_ptr;
00348
00349 tval = time(NULL);
00350 t_ptr = localtime(&tval);
00351 sprintf(datestr, "%d.%02d.%02d_%02d:%02d:%02d",
00352 (t_ptr->tm_year+1900), (t_ptr->tm_mon+1),
00353 t_ptr->tm_mday, t_ptr->tm_hour, t_ptr->tm_min, t_ptr->tm_sec);
00354 return(datestr);
00355 }
00356
00357
00358 char *gettimetag()
00359 {
00360 struct timeval tvalr;
00361 struct tm *t_ptr;
00362
00363 gettimeofday(&tvalr, NULL);
00364 t_ptr = localtime((const time_t *)&tvalr);
00365 sprintf(timetag, "%04d.%02d.%02d.%02d%02d%02d",
00366 (t_ptr->tm_year+1900), (t_ptr->tm_mon+1), t_ptr->tm_mday, t_ptr->tm_hour, t_ptr->tm_min, t_ptr->tm_sec);
00367 return(timetag);
00368 }
00369
00370
00371 void BeginTimer(int n)
00372 {
00373 gettimeofday (&first[n], NULL);
00374 }
00375
00376 float EndTimer(int n)
00377 {
00378 gettimeofday (&second[n], NULL);
00379 if (first[n].tv_usec > second[n].tv_usec) {
00380 second[n].tv_usec += 1000000;
00381 second[n].tv_sec--;
00382 }
00383 return (float) (second[n].tv_sec-first[n].tv_sec) +
00384 (float) (second[n].tv_usec-first[n].tv_usec)/1000000.0;
00385 }
00386
00387
00388 int h0log(const char *fmt, ...)
00389 {
00390 va_list args;
00391 char string[32768];
00392
00393 va_start(args, fmt);
00394 vsprintf(string, fmt, args);
00395 if(h0logfp) {
00396 fprintf(h0logfp, string);
00397 fflush(h0logfp);
00398 } else {
00399 printf(string);
00400 fflush(stdout);
00401 }
00402 va_end(args);
00403 return(0);
00404 }
00405
00406 int send_mail(char *fmt, ...)
00407 {
00408 va_list args;
00409 char string[1024], cmd[1024];
00410
00411 va_start(args, fmt);
00412 vsprintf(string, fmt, args);
00413 sprintf(cmd, "echo \"%s\" | Mail -s \"ingest_lev0_iris mail\" %s",
00414 string, username);
00415 system(cmd);
00416 va_end(args);
00417 return(0);
00418 }
00419
00420
00421 void do_quallev0(DRMS_Record_t *rs, IMG *img, int fsn)
00422 {
00423 char *iissloop, *cdark, *cled;
00424 char *hseqerr, *aistate;
00425 char wave_str[16];
00426 int status, isqfsn, asqfsn;
00427 float percentd;
00428 uint32_t missvals, datav;
00429 uint32_t hcf1encd, hcf2encd, hps1encd, hps2encd, hps3encd;
00430 uint32_t hwt1encd, hwt2encd, hwt3encd, hwt4encd;
00431 uint32_t hcf1pos, hcf2pos, hpl1pos, hpl2pos, hpl3pos, hwl1pos, hwl2pos;
00432 uint32_t hwl3pos, hwl4pos;
00433 uint32_t aiawvlen, aifwen, aiasen;
00434 short aifiltyp;
00435 uint32_t quallev0 = 0;
00436 uint32_t qmiss = 0;
00437
00438 if(img->overflow) quallev0 = quallev0 | Q_OVFL;
00439 if(img->headerr) quallev0 = quallev0 | Q_HDRERR;
00440 if(img->nerrors) quallev0 = quallev0 | Q_CMPERR;
00441 if(img->last_pix_err) quallev0 = quallev0 | Q_LPXERR;
00442 if(img->reopened) quallev0 = quallev0 | Q_REOPENED;
00443 missvals = img->totalvals - img->datavals;
00444 if(missvals > 0) quallev0 = quallev0 | Q_MISS0;
00445 datav = img->totalvals;
00446 if(missvals > (uint32_t)(datav * 0.01)) quallev0 = quallev0 | Q_MISS1;
00447 if(missvals > (uint32_t)(datav * 0.05)) quallev0 = quallev0 | Q_MISS2;
00448 if(missvals > (uint32_t)(datav * 0.25)) quallev0 = quallev0 | Q_MISS3;
00449 if(missvals == datav) quallev0 = quallev0 | Q_MISSI;
00450 if(img->datavals == 0) quallev0 = quallev0 | Q_MISSALL;
00451
00452
00453
00454
00455
00456
00457
00458
00459 if(fsn == 469769216) quallev0 = quallev0 | Q_CORRUPT;
00460 if(INVALtime) quallev0 = quallev0 | Q_INVALTIME;
00461 if(cdark = drms_getkey_string(rs, "IMG_TYPE", &status)) {
00462 if(!strcmp(cdark, "DARK")) quallev0 = quallev0 | Q_DARK;
00463 free(cdark);
00464 }
00465 if(cled = drms_getkey_string(rs, "IMG_TYPE", &status)) {
00466 if(!strcmp(cled, "LED")) quallev0 = quallev0 | Q_LED;
00467 free(cled);
00468 }
00469 isqfsn = drms_getkey_int(rs, "ISQFSN", &status);
00470 if(status || (fsn != isqfsn)) quallev0 = quallev0 | Q_NOISP;
00471 if(iissloop = drms_getkey_string(rs, "IISSLOOP", &status)) {
00472 if(!strcmp(iissloop, "OPEN")) quallev0 = quallev0 | Q_ISSOPEN;
00473 free(iissloop);
00474 }
00475 drms_setkey_int(rs, "QUALITY", quallev0);
00476 drms_setkey_string(rs, "BLD_VERS", bld_vers);
00477 percentd = (float)((100.0 * (float)img->datavals)/(float)img->totalvals);
00478 drms_setkey_float(rs, "PERCENTD", percentd);
00479 }
00480
00481
00482 void close_image(DRMS_Record_t *rs, DRMS_Segment_t *seg, DRMS_Array_t *array,
00483 IMG *img, int fsn)
00484 {
00485 DRMS_RecordSet_t *rsisp;
00486 DRMS_Record_t *rsispr;
00487 STAT stat;
00488 int status, n, k, ival, i, j, nnx, nny;
00489 int drms_status = 0;
00490 short sval;
00491 uint32_t missvals;
00492 long long cmdx, lval;
00493 TIME cmdxd;
00494 char *cptr, *iname;
00495 char tlmdsname[128];
00496 char queryext[256];
00497 char recdir[DRMS_MAXPATHLEN];
00498
00499 if(!img->initialized) {
00500 printk("**No image to close in close_image() for fsn = %u\n", fsn);
00501 return;
00502 }
00503 printk("*Closing image for fsn = %u\n", fsn);
00504 if(seqerror) {
00505 printk("**Sequence error during fsn %u. No closed image\n", fsn);
00506 seqerror = 0;
00507
00508 }
00509 if(ispfoundreopen != fsn) {
00510 if(ispfound != fsn) {
00511 printk("**No ISP found for fsn %u. No closed image\n", fsn);
00512 return;
00513 }
00514 }
00515 else ispfoundreopen = 0;
00516 if(imgstat_iris(img, &stat)) {
00517 printk("**Error on imgstat_iris() for fsn = %u\n", fsn);
00518 }
00519 else {
00520 drms_setkey_short(rs, "DATAMIN", stat.min);
00521 drms_setkey_short(rs, "DATAMAX", stat.max);
00522 drms_setkey_short(rs, "DATAMEDN", stat.median);
00523 drms_setkey_float(rs, "DATAMEAN", stat.mean);
00524 drms_setkey_float(rs, "DATARMS", stat.rms);
00525 drms_setkey_float(rs, "DATASKEW", stat.skew);
00526 drms_setkey_float(rs, "DATAKURT", stat.kurt);
00527 }
00528
00529 if(hmiaiaflg) {
00530 drms_setkey_int(rs, "CAMERA", (img->telnum)+1);
00531 cmdx = drms_getkey_longlong(rs, "AIMGSHCE", &status);
00532 if (0 == cmdx) drms_setkey_int(rs, "AIMGTYP", 1);
00533 }
00534 else {
00535
00536
00537
00538
00539 }
00540 drms_setkey_int(rs, "IMGAPID", img->apid);
00541 drms_setkey_int(rs, "CROPID", img->cropid);
00542 drms_setkey_int(rs, "ISYSN", img->isysn);
00543 if(drms_setkey_int(rs, "LUTID", img->luid)) {
00544 printk("ERROR on setkey_int for LUTID\n");
00545 }
00546 status = drms_setkey_short(rs, "SUMSPTRL", sumsptrl);
00547 status = drms_setkey_short(rs, "SUMSPAT", sumspat);
00548 drms_setkey_int(rs, "TAPCODE", img->tap);
00549
00550 n = (img->N) & 0x1F;
00551 n = n << 3;
00552 k = (img->K) & 0x07;
00553 if(img->N == 16) {
00554 drms_setkey_int(rs, "COMPID", 0);
00555 drms_setkey_int(rs, "BITSELID", 0);
00556 }
00557 else {
00558 drms_setkey_int(rs, "COMPID", n+k);
00559 drms_setkey_int(rs, "BITSELID", img->R);
00560 }
00561 drms_setkey_int(rs, "FID", img->fid);
00562 drms_setkey_int(rs, "TOTVALS", img->totalvals);
00563 drms_setkey_int(rs, "DATAVALS", img->datavals);
00564 drms_setkey_int(rs, "NPACKETS", img->npackets);
00565 drms_setkey_int(rs, "NERRORS", img->nerrors);
00566 drms_setkey_short(rs, "EOIERROR", img->last_pix_err);
00567 drms_setkey_short(rs, "HEADRERR", img->headerr);
00568 drms_setkey_short(rs, "OVERFLOW", img->overflow);
00569 missvals = img->totalvals - img->datavals;
00570 drms_setkey_int(rs, "MISSVALS", missvals);
00571 snprintf(tlmdsname, 128, "%s[%s]", tlmseriesname, tlmnamekeyfirst);
00572 drms_setkey_string(rs, "TLMDSNAM", tlmdsname);
00573 unsigned int pts = img->first_packet_time >> 16;
00574 int ptss = img->first_packet_time & 0xffff;
00575 TIME fpt = SDO_to_DRMS_time(pts, ptss);
00576 drms_setkey_double(rs, "IMGFPT", fpt);
00577 drms_setkey_double(rs, "DATE", CURRENT_SYSTEM_TIME);
00578 do_quallev0(rs, img, fsn);
00579 if(!timeoutclose) {
00580 rsisp = RSISP;
00581 }
00582 else {
00583 timeoutclose = 0;
00584
00585 sprintf(queryext, "%s[? I_SQ_FRAME_SN=%d ?]", ispquery, fsn);
00586 printk("queryext = %s\n", queryext);
00587 rsisp = drms_open_records(drms_env, queryext, &drms_status);
00588 }
00589
00590 if(!rsisp || !rsisp->n || !rsisp->records || (fsn != fsnISP && !fsnISP_noop)) {
00591 printk("ERROR: Can't open isp record to put keywords in lev0.\n");
00592 printk(" The ISP was not received prior to the image for fsn %lu\n", fsn);
00593 printk(" Look for 'seq num out of sequence' error in log\n");
00594 printk("drms_status=%d, rsisp=%lu, fsn=%lu, fsnISP=%lu, fsnISP_noop=%lu\n",
00595 drms_status, rsisp, fsn, fsnISP, fsnISP_noop);
00596 printk(" **ERROR: Can't close_image() for fsn = %u\n", fsn);
00597 img->initialized = 0;
00598 return;
00599 }
00600 else if(rsisp->n > 2 || rsisp->n < 0) {
00601 printk("ERROR: Got bad drms_open_records() pointer for isp. fsn=%lu\n", fsn);
00602 printk(" Look for 'seq num out of sequence' error in log\n");
00603 printk(" **ERROR: Can't close_image() fsn=%u\n", fsn);
00604 img->initialized = 0;
00605 return;
00606 }
00607 else {
00608 fsnISP_noop = 0;
00609 rsispr = rsisp->records[0];
00610
00611
00612
00613
00614
00615
00616 iname = getenv("HK_ISP_IRIS_DSNAME");
00617 status = drms_setkey_string(rs, "ISPSNAME", iname);
00618 iname = drms_getkey_string(rsispr, "PACKET_VERSION_NUMBER",&status);
00619 status = drms_setkey_string(rs, "ISPPKTVN", iname);
00620 iname = drms_getkey_string(rsispr, "HK_SOURCE",&status);
00621 status = drms_setkey_string(rs, "HKSOURCE", iname);
00622 cmdxd = drms_getkey_double(rsispr, "PACKET_TIME", &status);
00623 status = drms_setkey_double(rs, "ISPPKTIM", cmdxd);
00624 cmdx = drms_getkey_longlong(rsispr, "APID56_TIMECODE_SEC", &status);
00625 status = drms_setkey_longlong(rs, "ITCS56", cmdx);
00626 cmdx = drms_getkey_longlong(rsispr, "APID56_TIMECODE_SSEC", &status);
00627 status = drms_setkey_longlong(rs, "ITCSS56", cmdx);
00628 ival = drms_getkey_int(rsispr, "APID56_APID_VERSION", &status);
00629 status = drms_setkey_int(rs, "IVER56", ival);
00630 sval = drms_getkey_short(rsispr, "I_SQ_ISYS_NUM", &status);
00631 status = drms_setkey_short(rs, "ISQISYSN", sval);
00632 ival = drms_getkey_int(rsispr, "I_SQ_FRAME_SN", &status);
00633 status = drms_setkey_int(rs, "ISQFSN", ival);
00634
00635
00636 sval = drms_getkey_short(rsispr, "I_IMG_CRS_ID", &status);
00637 status = drms_setkey_short(rs, "IICRSID", sval);
00638
00639
00640 ival = drms_getkey_int(rsispr, "I_IMG_OBSLIST_ID", &status);
00641 status = drms_setkey_int(rs, "IIOBSLID", ival);
00642
00643
00644 ival = drms_getkey_int(rsispr, "I_IMG_FRMLIST_ID", &status);
00645 status = drms_setkey_int(rs, "IIFRMLID", ival);
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655 iname = drms_getkey_string(rsispr, "I_ISS_LOOP",&status);
00656 status = drms_setkey_string(rs, "IISSLOOP", iname);
00657 sval = drms_getkey_short(rsispr, "I_IMG_CFG_DELAY_1", &status);
00658 status = drms_setkey_short(rs, "IIMGCFD1", sval);
00659 sval = drms_getkey_short(rsispr, "I_IMG_CFG_DELAY_2", &status);
00660 status = drms_setkey_short(rs, "IIMGCFD2", sval);
00661 sval = drms_getkey_short(rsispr, "I_IMG_CFG_DELAY_3", &status);
00662 status = drms_setkey_short(rs, "IIMGCFD3", sval);
00663 sval = drms_getkey_short(rsispr, "I_IMG_CFG_DELAY_4", &status);
00664 status = drms_setkey_short(rs, "IIMGCFD4", sval);
00665 sval = drms_getkey_short(rsispr, "I_GTP_SUNVECTOR_X", &status);
00666 status = drms_setkey_short(rs, "IGTPSVX", sval);
00667 sval = drms_getkey_short(rsispr, "I_GTP_SUNVECTOR_Y", &status);
00668 status = drms_setkey_short(rs, "IGTPSVY", sval);
00669 sval = drms_getkey_short(rsispr, "I_ISS_PZTOFFA", &status);
00670 status = drms_setkey_short(rs, "IISSPZTA", sval);
00671 sval = drms_getkey_short(rsispr, "I_ISS_PZTOFFB", &status);
00672 status = drms_setkey_short(rs, "IISSPZTB", sval);
00673 sval = drms_getkey_short(rsispr, "I_ISS_PZTOFFC", &status);
00674 status = drms_setkey_short(rs, "IISSPZTC", sval);
00675
00676
00677
00678
00679
00680 ival = drms_getkey_int(rsispr, "I_IMG_SH_CMDED_EXPOSURE", &status);
00681 status = drms_setkey_int(rs, "IIMGSHCE", ival);
00682 ival = drms_getkey_int(rsispr, "I_OBC_TIME_SH1_FUV_SEC", &status);
00683 status = drms_setkey_int(rs, "IIMGOTS1", ival);
00684 ival = drms_getkey_int(rsispr, "I_OBC_TIME_SH1_FUV_SS", &status);
00685 status = drms_setkey_int(rs, "IMGOTSS1", ival);
00686 ival = drms_getkey_int(rsispr, "I_MC_FUV_A_CLOSE_TIME", &status);
00687 status = drms_setkey_int(rs, "IFUVACT", ival);
00688 ival = drms_getkey_int(rsispr, "I_MC_FUV_A_OPEN_TIME", &status);
00689 status = drms_setkey_int(rs, "IFUVAOT", ival);
00690 ival = drms_getkey_int(rsispr, "I_MC_FUV_B_CLOSE_TIME", &status);
00691 status = drms_setkey_int(rs, "IFUVBCT", ival);
00692 ival = drms_getkey_int(rsispr, "I_MC_FUV_B_OPEN_TIME", &status);
00693 status = drms_setkey_int(rs, "IFUVBOT", ival);
00694 ival = drms_getkey_int(rsispr, "I_MC_FUV_C_CLOSE_TIME", &status);
00695 status = drms_setkey_int(rs, "IFUVCCT", ival);
00696 ival = drms_getkey_int(rsispr, "I_MC_FUV_C_OPEN_TIME", &status);
00697 status = drms_setkey_int(rs, "IFUVCOT", ival);
00698 ival = drms_getkey_int(rsispr, "I_MC_FUV_D_CLOSE_TIME", &status);
00699 status = drms_setkey_int(rs, "IFUVDCT", ival);
00700 ival = drms_getkey_int(rsispr, "I_MC_FUV_D_OPEN_TIME", &status);
00701 status = drms_setkey_int(rs, "IFUVDOT", ival);
00702 ival = drms_getkey_int(rsispr, "I_MC_FUV_E_CLOSE_TIME", &status);
00703 status = drms_setkey_int(rs, "IFUVECT", ival);
00704 ival = drms_getkey_int(rsispr, "I_MC_FUV_E_OPEN_TIME", &status);
00705 status = drms_setkey_int(rs, "IFUVEOT", ival);
00706 ival = drms_getkey_int(rsispr, "I_MC_FUV_F_CLOSE_TIME", &status);
00707 status = drms_setkey_int(rs, "IFUVFCT", ival);
00708 ival = drms_getkey_int(rsispr, "I_MC_FUV_F_OPEN_TIME", &status);
00709 status = drms_setkey_int(rs, "IFUVFOT", ival);
00710 ival = drms_getkey_int(rsispr, "I_OBC_TIME_SH2_NUV_SEC", &status);
00711 status = drms_setkey_int(rs, "IIMGOTS2", ival);
00712 ival = drms_getkey_int(rsispr, "I_OBC_TIME_SH2_NUV_SS", &status);
00713 status = drms_setkey_int(rs, "IMGOTSS2", ival);
00714 ival = drms_getkey_int(rsispr, "I_MC_NUV_A_CLOSE_TIME", &status);
00715 status = drms_setkey_int(rs, "INUVACT", ival);
00716 ival = drms_getkey_int(rsispr, "I_MC_NUV_A_OPEN_TIME", &status);
00717 status = drms_setkey_int(rs, "INUVAOT", ival);
00718 ival = drms_getkey_int(rsispr, "I_MC_NUV_B_CLOSE_TIME", &status);
00719 status = drms_setkey_int(rs, "INUVBCT", ival);
00720 ival = drms_getkey_int(rsispr, "I_MC_NUV_B_OPEN_TIME", &status);
00721 status = drms_setkey_int(rs, "INUVBOT", ival);
00722 ival = drms_getkey_int(rsispr, "I_MC_NUV_C_CLOSE_TIME", &status);
00723 status = drms_setkey_int(rs, "INUVCCT", ival);
00724 ival = drms_getkey_int(rsispr, "I_MC_NUV_C_OPEN_TIME", &status);
00725 status = drms_setkey_int(rs, "INUVCOT", ival);
00726 ival = drms_getkey_int(rsispr, "I_MC_NUV_D_CLOSE_TIME", &status);
00727 status = drms_setkey_int(rs, "INUVDCT", ival);
00728 ival = drms_getkey_int(rsispr, "I_MC_NUV_D_OPEN_TIME", &status);
00729 status = drms_setkey_int(rs, "INUVDOT", ival);
00730 ival = drms_getkey_int(rsispr, "I_MC_NUV_E_CLOSE_TIME", &status);
00731 status = drms_setkey_int(rs, "INUVECT", ival);
00732 ival = drms_getkey_int(rsispr, "I_MC_NUV_E_OPEN_TIME", &status);
00733 status = drms_setkey_int(rs, "INUVEOT", ival);
00734 ival = drms_getkey_int(rsispr, "I_OBC_TIME_SH3_SJI_SEC", &status);
00735 status = drms_setkey_int(rs, "IIMGOTS3", ival);
00736 ival = drms_getkey_int(rsispr, "I_OBC_TIME_SH3_SJI_SS", &status);
00737 status = drms_setkey_int(rs, "IMGOTSS3", ival);
00738 ival = drms_getkey_int(rsispr, "I_MC_SJI_A_CLOSE_TIME", &status);
00739 status = drms_setkey_int(rs, "ISJIACT", ival);
00740 ival = drms_getkey_int(rsispr, "I_MC_SJI_A_OPEN_TIME", &status);
00741 status = drms_setkey_int(rs, "ISJIAOT", ival);
00742 ival = drms_getkey_int(rsispr, "I_MC_SJI_B_CLOSE_TIME", &status);
00743 status = drms_setkey_int(rs, "ISJIBCT", ival);
00744 ival = drms_getkey_int(rsispr, "I_MC_SJI_B_OPEN_TIME", &status);
00745 status = drms_setkey_int(rs, "ISJIBOT", ival);
00746 ival = drms_getkey_int(rsispr, "I_MC_SJI_C_CLOSE_TIME", &status);
00747 status = drms_setkey_int(rs, "ISJICCT", ival);
00748 ival = drms_getkey_int(rsispr, "I_MC_SJI_C_OPEN_TIME", &status);
00749 status = drms_setkey_int(rs, "ISJICOT", ival);
00750 ival = drms_getkey_int(rsispr, "I_MC_SJI_D_CLOSE_TIME", &status);
00751 status = drms_setkey_int(rs, "ISJIDCT", ival);
00752 ival = drms_getkey_int(rsispr, "I_MC_SJI_D_OPEN_TIME", &status);
00753 status = drms_setkey_int(rs, "ISJIDOT", ival);
00754 ival = drms_getkey_int(rsispr, "I_MC_SJI_E_CLOSE_TIME", &status);
00755 status = drms_setkey_int(rs, "ISJIECT", ival);
00756 ival = drms_getkey_int(rsispr, "I_MC_SJI_E_OPEN_TIME", &status);
00757 status = drms_setkey_int(rs, "ISJIEOT", ival);
00758 ival = drms_getkey_int(rsispr, "I_IMG_AEC_TABLE_ID", &status);
00759 status = drms_setkey_int(rs, "IAECTID", ival);
00760 ival = drms_getkey_int(rsispr, "I_IMG_HIST_BIN_1", &status);
00761 status = drms_setkey_int(rs, "IIHIS1", ival);
00762 ival = drms_getkey_int(rsispr, "I_IMG_HIST_BIN_2", &status);
00763 status = drms_setkey_int(rs, "IIHIS2", ival);
00764 ival = drms_getkey_int(rsispr, "I_IMG_HIST_BIN_3", &status);
00765 status = drms_setkey_int(rs, "IIHIS3", ival);
00766 ival = drms_getkey_int(rsispr, "I_IMG_HIST_BIN_4", &status);
00767 status = drms_setkey_int(rs, "IIHIS4", ival);
00768 ival = drms_getkey_int(rsispr, "I_IMG_HIST_BIN_5", &status);
00769 status = drms_setkey_int(rs, "IIHIS5", ival);
00770 ival = drms_getkey_int(rsispr, "I_IMG_HIST_FSN", &status);
00771 status = drms_setkey_int(rs, "IIHISFSN", ival);
00772
00773 ival = drms_getkey_int(rsispr, "I_MC_FM_CMDED_POS", &status);
00774 status = drms_setkey_int(rs, "IFMCPOS", ival);
00775 ival = drms_getkey_int(rsispr, "I_MC_FM_POS", &status);
00776 status = drms_setkey_int(rs, "IFMPOS", ival);
00777 ival = drms_getkey_int(rsispr, "I_MC_FUV_ENCODER", &status);
00778 status = drms_setkey_int(rs, "IFUVENC", ival);
00779 ival = drms_getkey_int(rsispr, "I_MC_FW_CMDED_TGT", &status);
00780 status = drms_setkey_int(rs, "IFWCTGT", ival);
00781 ival = drms_getkey_int(rsispr, "I_MC_FW_ENCODER", &status);
00782 status = drms_setkey_int(rs, "IFWENC", ival);
00783 ival = drms_getkey_int(rsispr, "I_MC_FW_POS", &status);
00784 status = drms_setkey_int(rs, "IFWPOS", ival);
00785 sval = drms_getkey_short(rsispr, "I_GTP_BIAS_OFFSET_X", &status);
00786 status = drms_setkey_short(rs, "IGTPOFFX", sval);
00787 sval = drms_getkey_short(rsispr, "I_GTP_BIAS_OFFSET_Y", &status);
00788 status = drms_setkey_short(rs, "IGTPOFFY", sval);
00789 sval = drms_getkey_short(rsispr, "I_IMG_FRAME_TYPE", &status);
00790 status = drms_setkey_short(rs, "IIFRMTYP", sval);
00791 iname = drms_getkey_string(rsispr, "I_LED1_HW",&status);
00792 status = drms_setkey_string(rs, "ILED1HWS", iname);
00793 iname = drms_getkey_string(rsispr, "I_LED1_SW",&status);
00794 status = drms_setkey_string(rs, "ILED1SWS", iname);
00795 iname = drms_getkey_string(rsispr, "I_LED2_HW",&status);
00796 status = drms_setkey_string(rs, "ILED2HWS", iname);
00797 iname = drms_getkey_string(rsispr, "I_LED2_SW",&status);
00798 status = drms_setkey_string(rs, "ILED2SWS", iname);
00799 iname = drms_getkey_string(rsispr, "I_LED3_HW",&status);
00800 status = drms_setkey_string(rs, "ILED3HWS", iname);
00801 iname = drms_getkey_string(rsispr, "I_LED3_SW",&status);
00802 status = drms_setkey_string(rs, "ILED3SWS", iname);
00803 ival = drms_getkey_int(rsispr, "I_MC_NUV_ENCODER", &status);
00804 status = drms_setkey_int(rs, "INUVENC", ival);
00805 sval = drms_getkey_short(rsispr, "I_RT_PZTOFFA", &status);
00806 status = drms_setkey_short(rs, "IRTPZTA", sval);
00807 sval = drms_getkey_short(rsispr, "I_RT_PZTOFFB", &status);
00808 status = drms_setkey_short(rs, "IRTPZTB", sval);
00809 sval = drms_getkey_short(rsispr, "I_RT_PZTOFFC", &status);
00810 status = drms_setkey_short(rs, "IRTPZTC", sval);
00811 ival = drms_getkey_int(rsispr, "I_MC_SJI_ENCODER", &status);
00812 status = drms_setkey_int(rs, "ISJIENC", ival);
00813 sval = drms_getkey_short(rsispr, "I_HR_BIT_ID", &status);
00814 status = drms_setkey_short(rs, "ISQBITID", sval);
00815 sval = drms_getkey_short(rsispr, "I_HR_COMP_ID", &status);
00816 status = drms_setkey_short(rs, "ISQCMPID", sval);
00817 sval = drms_getkey_short(rsispr, "I_HR_TAP_CODE", &status);
00818 status = drms_setkey_short(rs, "IISQTAP", sval);
00819 sval = drms_getkey_short(rsispr, "I_WB_PZTOFFA", &status);
00820 status = drms_setkey_short(rs, "IWBPZTA", sval);
00821 sval = drms_getkey_short(rsispr, "I_WB_PZTOFFB", &status);
00822 status = drms_setkey_short(rs, "IWBPZTB", sval);
00823 sval = drms_getkey_short(rsispr, "I_WB_PZTOFFC", &status);
00824 status = drms_setkey_short(rs, "IWBPZTC", sval);
00825 ival = drms_getkey_int(rsispr, "I_MC_WM1_CMDED_DELAY", &status);
00826 status = drms_setkey_int(rs, "IWM1CDEL", ival);
00827 ival = drms_getkey_int(rsispr, "I_MC_WM1_POS", &status);
00828 status = drms_setkey_int(rs, "IWM1CPOS", ival);
00829 ival = drms_getkey_int(rsispr, "I_MC_WM1_CMDED_TGT", &status);
00830 status = drms_setkey_int(rs, "IWM1CTGT", ival);
00831 ival = drms_getkey_int(rsispr, "I_MC_WM1_ENCODER", &status);
00832 status = drms_setkey_int(rs, "IWM1ENC", ival);
00833 ival = drms_getkey_int(rsispr, "I_MC_WM2_CMDED_DELAY", &status);
00834 status = drms_setkey_int(rs, "IWM2CDEL", ival);
00835 ival = drms_getkey_int(rsispr, "I_MC_WM2_POS", &status);
00836 status = drms_setkey_int(rs, "IWM2CPOS", ival);
00837 ival = drms_getkey_int(rsispr, "I_MC_WM2_CMDED_TGT", &status);
00838 status = drms_setkey_int(rs, "IWM2CTGT", ival);
00839 ival = drms_getkey_int(rsispr, "I_MC_WM2_ENCODER", &status);
00840 status = drms_setkey_int(rs, "IWM2ENC", ival);
00841 ival = drms_getkey_int(rsispr, "I_TAT_ACS_STATUS", &status);
00842 status = drms_setkey_int(rs, "ITACSSTS", ival);
00843
00844 ival = drms_getkey_int(rsispr, "I_ISS_CONTROL", &status);
00845 status = drms_setkey_int(rs, "IISSCTRL", ival);
00846 sval = drms_getkey_short(rsispr, "I_ISS_DIODES", &status);
00847 status = drms_setkey_short(rs, "IISSDIOD", sval);
00848 sval = drms_getkey_short(rsispr, "I_ISS_OFFSET_RANGE", &status);
00849 status = drms_setkey_short(rs, "IISSOFFR", sval);
00850 sval = drms_getkey_short(rsispr, "I_ISS_SOURCE", &status);
00851 status = drms_setkey_short(rs, "IISS_SRC", sval);
00852 ival = drms_getkey_int(rsispr, "I_ISS_X_ERROR", &status);
00853 status = drms_setkey_int(rs, "ISXER", ival);
00854 ival = drms_getkey_int(rsispr, "I_ISS_X_ERROR_AVG", &status);
00855 status = drms_setkey_int(rs, "ISXERAVG", ival);
00856 ival = drms_getkey_int(rsispr, "I_ISS_X_ERROR_MAX", &status);
00857 status = drms_setkey_int(rs, "ISXERMAX", ival);
00858 ival = drms_getkey_int(rsispr, "I_ISS_X_ERROR_MIN", &status);
00859 status = drms_setkey_int(rs, "ISXERMIN", ival);
00860 ival = drms_getkey_int(rsispr, "I_ISS_Y_ERROR", &status);
00861 status = drms_setkey_int(rs, "ISYER,", ival);
00862 ival = drms_getkey_int(rsispr, "I_ISS_Y_ERROR_AVG", &status);
00863 status = drms_setkey_int(rs, "ISYERAVG", ival);
00864 ival = drms_getkey_int(rsispr, "I_ISS_Y_ERROR_MAX", &status);
00865 status = drms_setkey_int(rs, "ISYERMAX", ival);
00866 ival = drms_getkey_int(rsispr, "I_ISS_Y_ERROR_MIN", &status);
00867 status = drms_setkey_int(rs, "ISYERMIN", ival);
00868 sval = drms_getkey_short(rsispr, "I_MC_FUV_CMDED_DELAY", &status);
00869 status = drms_setkey_short(rs, "IFUVCDEL", sval);
00870 sval = drms_getkey_short(rsispr, "I_MC_FUV_CMDED_EXP", &status);
00871 status = drms_setkey_short(rs, "IFUVCEXP", sval);
00872 sval = drms_getkey_short(rsispr, "I_MC_NUV_CMDED_DELAY", &status);
00873 status = drms_setkey_short(rs, "INUVCDEL", sval);
00874 sval = drms_getkey_short(rsispr, "I_MC_NUV_CMDED_EXP", &status);
00875 status = drms_setkey_short(rs, "INUVCEXP", sval);
00876 sval = drms_getkey_short(rsispr, "I_MC_SJI_CMDED_DELAY", &status);
00877 status = drms_setkey_short(rs, "ISJICDEL", sval);
00878 sval = drms_getkey_short(rsispr, "I_MC_SJI_CMDED_EXP", &status);
00879 status = drms_setkey_short(rs, "ISJICEXP", sval);
00880 ival = drms_getkey_int(rsispr, "I_SQ_FLT_N_REPEAT", &status);
00881 status = drms_setkey_int(rs, "IIFLNRPT", ival);
00882 ival = drms_getkey_int(rsispr, "I_SQ_FLT_REPEAT", &status);
00883 status = drms_setkey_int(rs, "IIFLRPT", ival);
00884 ival = drms_getkey_int(rsispr, "I_SQ_OLT_N_REPEAT", &status);
00885 status = drms_setkey_int(rs, "IIOLNRPT", ival);
00886 ival = drms_getkey_int(rsispr, "I_SQ_OLT_REPEAT", &status);
00887 status = drms_setkey_int(rs, "IIOLRPT", ival);
00888
00889
00890 lval = drms_getkey_longlong(rsispr, "I_SQ_FUV_FDBT_ID", &status);
00891 status = drms_setkey_longlong(rs, "IIFUVFDB", lval);
00892
00893
00894 lval = drms_getkey_longlong(rsispr, "I_SQ_NUV_FDBT_ID", &status);
00895 status = drms_setkey_longlong(rs, "IINUVFDB", lval);
00896
00897
00898 lval = drms_getkey_longlong(rsispr, "I_SQ_SJI_FDBT_ID", &status);
00899 status = drms_setkey_longlong(rs, "IISJIFDB", lval);
00900 ival = drms_getkey_int(rsispr, "I_SQ_FDBT_IDX", &status);
00901 status = drms_setkey_int(rs, "ISQFDBTI", ival);
00902 sval = drms_getkey_short(rsispr, "I_SQ_OWT_ID", &status);
00903 status = drms_setkey_short(rs, "ISQOWTID", sval);
00904 sval = drms_getkey_short(rsispr, "I_SQ_SRT_ID", &status);
00905 status = drms_setkey_short(rs, "ISQSRTID", sval);
00906
00907
00908
00909 iname = drms_getkey_string(rsispr, "I_AEC_FLAG",&status);
00910 status = drms_setkey_string(rs, "IAECFLAG", iname);
00911 iname = drms_getkey_string(rsispr, "I_AEC_EV_FLAG",&status);
00912 status = drms_setkey_string(rs, "IAECEVFL", iname);
00913 iname = drms_getkey_string(rsispr, "I_AEC_FLARE_FLAG",&status);
00914 status = drms_setkey_string(rs, "IAECFLFL", iname);
00915 ival = drms_getkey_int(rsispr, "I_AEC_ENA_MSK", &status);
00916 status = drms_setkey_int(rs, "IAECENAM", ival);
00917 ival = drms_getkey_int(rsispr, "I_AEC_LAPSE_TIME", &status);
00918 status = drms_setkey_int(rs, "IAECLTIM", ival);
00919 ival = drms_getkey_int(rsispr, "I_AEC_EV_LAPSE_TIME", &status);
00920 status = drms_setkey_int(rs, "IAECEVLT", ival);
00921 ival = drms_getkey_int(rsispr, "I_SQ_FLT_IDX", &status);
00922 status = drms_setkey_int(rs, "ISQFLTDX", ival);
00923 ival = drms_getkey_int(rsispr, "I_SQ_FLT_N_IDX", &status);
00924 status = drms_setkey_int(rs, "ISQFLTNX", ival);
00925 ival = drms_getkey_int(rsispr, "I_SQ_OLT_IDX", &status);
00926 status = drms_setkey_int(rs, "ISQOLTDX", ival);
00927 ival = drms_getkey_int(rsispr, "I_SQ_OLT_N_IDX", &status);
00928 status = drms_setkey_int(rs, "ISQOLTNX", ival);
00929 ival = drms_getkey_int(rsispr, "I_SQ_PZT_A", &status);
00930 status = drms_setkey_int(rs, "ISQPZTA", ival);
00931 ival = drms_getkey_int(rsispr, "I_SQ_PZT_B", &status);
00932 status = drms_setkey_int(rs, "ISQPZTB", ival);
00933 ival = drms_getkey_int(rsispr, "I_SQ_PZT_C", &status);
00934 status = drms_setkey_int(rs, "ISQPZTC", ival);
00935 ival = drms_getkey_int(rsispr, "I_SQ_ORB_PERIOD", &status);
00936 status = drms_setkey_int(rs, "ISQORBPD", ival);
00937 ival = drms_getkey_int(rsispr, "I_SQ_ORB_EQ_SEC", &status);
00938 status = drms_setkey_int(rs, "ISQORBSE", ival);
00939 ival = drms_getkey_int(rsispr, "I_SQ_ORB_EQ_SUB", &status);
00940 status = drms_setkey_int(rs, "ISQORBSU", ival);
00941
00942 lval = drms_getkey_longlong(rsispr, "I_SQ_OLT_ID", &status);
00943 status = drms_setkey_longlong(rs, "ISQOLTID,", lval);
00944 lval = drms_getkey_longlong(rsispr, "I_SQ_FLT_ID", &status);
00945 status = drms_setkey_longlong(rs, "ISQFLTID,", lval);
00946
00947 int isqisysn = drms_getkey_int(rsispr, "I_SQ_ISYS_NUM", &status);
00948 long long iifuvfdb = drms_getkey_longlong(rsispr, "I_SQ_FUV_FDBT_ID",&status);
00949 long long iinuvfdb = drms_getkey_longlong(rsispr, "I_SQ_NUV_FDBT_ID",&status);
00950 long long iisjifdb = drms_getkey_longlong(rsispr, "I_SQ_SJI_FDBT_ID",&status);
00951 switch (isqisysn) {
00952 case 0:
00953 drms_setkey_longlong(rs, "IIFDBID", iifuvfdb);
00954 break;
00955 case 1:
00956 drms_setkey_longlong(rs, "IIFDBID", iinuvfdb);
00957 break;
00958 case 2:
00959 drms_setkey_longlong(rs, "IIFDBID", iisjifdb);
00960 break;
00961 }
00962
00963
00964 drms_close_records(rsisp, DRMS_INSERT_RECORD);
00965
00966
00967 }
00968
00969 nnx = img->nx;
00970 nny = img->ny;
00971 npix = nnx * nny;
00972 for(i=0; i < nny; ++i) {
00973 for(j=0; j < nnx; ++j)
00974 tmpdat[i*nnx+j] = img->dat[j*nny+i];
00975 }
00976 memcpy(img->dat, tmpdat, 2*npix);
00977 status = drms_segment_writewithkeys(seg, array, 0);
00978
00979 if (status) {
00980 printk("ERROR: drms_segment_write error=%d for fsn=%u\n", status, fsn);
00981 printk("ABORT: close_image(). No drms_close_record() done\n");
00982 array->data = NULL;
00983 if(array) drms_free_array(array);
00984 img->initialized = 0;
00985 return;
00986 }
00987 add_small_array(rs, array, 8, 16);
00988
00989 drms_record_directory(rs, recdir, 1);
00990
00991 printf("recdir from ingest_lev0_iris:<%s>\n",recdir);
00992 if(wdlogfp)
00993 {
00994 fprintf(wdlogfp,"%s\n",recdir);
00995 fflush(wdlogfp);
00996 sprintf(Incmd,"/bin/rm -f %s/%09u.fits",Indir,fsn);
00997 system(Incmd);
00998
00999 sprintf(Incmd,"ln -s %s/image.fits %s/%09u.fits",recdir,Indir,fsn);
01000 h0log("%s\n",Incmd);
01001 system(Incmd);
01002 }
01003
01004
01005 array->data = NULL;
01006 if(array) drms_free_array(array);
01007 if((status = drms_close_record(rs, DRMS_INSERT_RECORD))) {
01008 printk("**ERROR: drms_close_record failed for %s fsn=%u\n",
01009 lev0seriesname, fsn);
01010 }
01011 img->initialized = 0;
01012
01013 }
01014
01015
01016 void abortit(int stat)
01017 {
01018 printk("***Abort in progress ...\n");
01019 printk("**Exit ingest_lev0_iris w/ status = %d\n", stat);
01020 if (h0logfp) fclose(h0logfp);
01021 exit(stat);
01022 }
01023
01024
01025 int compare_names(const void *a, const void *b)
01026 {
01027 NAMESORT *x=(NAMESORT *)a, *y=(NAMESORT *)b;
01028 return(strcmp(x->name+4, y->name+4));
01029 }
01030
01031 unsigned short MDI_getshort (unsigned char *c)
01032 {
01033 unsigned short s = 0;
01034
01035 s = (unsigned short) *c++ << 8;
01036 s |= (unsigned short) *c;
01037 return s;
01038 }
01039
01040
01041 int fsn_normal_new_image()
01042 {
01043 int dstatus, i;
01044
01045
01046 Img->initialized = 0;
01047 Img->reopened = 0;
01048 errmsgcnt = 0;
01049 fsn_prev = fsnx;
01050 sprintf(tlmnamekeyfirst, "%s", tlmnamekey);
01051 rs = drms_create_record(drms_env, lev0seriesname, DRMS_PERMANENT, &dstatus);
01052 if(dstatus) {
01053 if(dstatus == DRMS_ERROR_SUMOPEN) {
01054 printk("**ERROR: DRMS can't open w/SUMS. Aborting...\n");
01055 abortit(4);
01056 }
01057 printk("**ERROR: Can't create record for %s fsn=%u\n", lev0seriesname, fsnx);
01058 NextImage.rsN = 0;
01059 return(1);
01060 }
01061 dstatus = drms_setkey_int(rs, "FSN", fsnx);
01062 if(!(segment = drms_segment_lookup(rs, "image"))) {
01063 printk("No drms_segment_lookup(rs, image)\n");
01064 NextImage.rsN = 0;
01065 return(1);
01066 }
01067
01068
01069
01070
01071
01072
01073
01074
01075
01076
01077
01078 #if 0
01079 Img->datavals = 0;
01080 Img->npackets = 0;
01081 Img->nerrors = 0;
01082 Img->last_pix_err = 0;
01083 Img->first_packet_time = UINT64_MAX;
01084 for (i = 0; i < MAXPIXELS; ++i)
01085 Img->dat[i] = BLANK;
01086 for (i = 0; i < MAXHIST; ++i)
01087 Img->hist[i] = 0;
01088 #endif
01089
01090 imgdecode_iris_init_hack(Img);
01091
01092 rdat = Img->dat;
01093
01094
01095
01096
01097
01098 ImgC = Img;
01099
01100 NextImage.rsN = rs;
01101 NextImage.segN = segment;
01102 NextImage.imgN = Img;
01103 NextImage.fsnN = fsnx;
01104 OpenNextImg = 1;
01105 return(0);
01106 }
01107
01108
01109
01110 int fsn_change_normal()
01111 {
01112 int dstatus, rstatus, compid, n, k;
01113 int i, j, nnx, nny;
01114 char reopen_dsname[256];
01115 char *cptr;
01116
01117 printk("*FSN has changed from %u to %u\n", fsn_prev, fsnx);
01118 if(fsnx < fsn_prev) {
01119 retardskip = 1;
01120 printk("**FSN retardation. Skip %u until normal increase\n", fsnx);
01121 }
01122 else retardskip = 0;
01123 printflg = 0;
01124 if(fsn_prev == 0) {
01125 errmsgcnt = 0;
01126 errskip = 0;
01127 fsn_prev = fsnx;
01128
01129
01130
01131 snprintf(reopen_dsname, 256, "%s[%u]", dsout, fsnx);
01132 printk("Open normal prev ds: %s\n", reopen_dsname);
01133 rset = drms_open_records(drms_env, reopen_dsname, &rstatus);
01134 if(rstatus) {
01135 printk("Can't do drms_open_records(%s)\n", reopen_dsname);
01136 return(1);
01137 }
01138 if(!rset || (rset->n == 0) || rstatus) {
01139 startnew:
01140 printk("No prev ds\n");
01141 fsn_normal_new_image();
01142 }
01143 else {
01144 ispfoundreopen = fsnx;
01145 Img->initialized = 1;
01146 Img->reopened = 1;
01147 Img->fsn = fsnx;
01148 Img->apid = appid;
01149 rs_old = rset->records[0];
01150 rs = drms_clone_record(rs_old, DRMS_PERMANENT, DRMS_COPY_SEGMENTS, &rstatus);
01151 if(rstatus || !rs) {
01152 printk("Can't do drms_clone_record()\n");
01153 goto startnew;
01154
01155 }
01156 drms_close_records(rset, DRMS_FREE_RECORD);
01157 rstatus = drms_setkey_int(rs, "FSN", fsnx);
01158 Img->telnum = drms_getkey_int(rs, "CAMERA", &rstatus);
01159 Img->telnum--;
01160 Img->cropid = drms_getkey_int(rs, "CROPID", &rstatus);
01161 Img->isysn = drms_getkey_int(rs, "ISYSN", &rstatus);
01162 Img->fid = drms_getkey_int(rs, "FID", &rstatus);
01163 Img->luid = drms_getkey_int(rs, "LUTID", &rstatus);
01164 if(rstatus) {
01165 Img->luid = 0;
01166 printk("ERROR on getkey_int for LUTID\n");
01167 }
01168 Img->tap = drms_getkey_int(rs, "TAPCODE", &rstatus);
01169 compid = drms_getkey_int(rs, "COMPID", &rstatus);
01170 if(compid == 0) {
01171 n = 16; k = 0;
01172 }
01173 else {
01174 k = compid & 0x07;
01175 n = compid >> 3;
01176 n = n & 0x1F;
01177 }
01178 Img->N = n;
01179 Img->K = k;
01180 Img->R = drms_getkey_int(rs, "BITSELID", &rstatus);
01181 Img->overflow = drms_getkey_int(rs, "OVERFLOW", &rstatus);
01182 Img->headerr = drms_getkey_int(rs, "HEADRERR", &rstatus);
01183 Img->totalvals = drms_getkey_int(rs, "TOTVALS", &rstatus);
01184 Img->datavals = drms_getkey_int(rs, "DATAVALS", &rstatus);
01185 Img->npackets = drms_getkey_int(rs, "NPACKETS", &rstatus);
01186 Img->nerrors = drms_getkey_int(rs, "NERRORS", &rstatus);
01187 Img->last_pix_err = drms_getkey_int(rs, "EOIERROR", &rstatus);
01188
01189 TIME fpt = drms_getkey_double(rs, "IMGFPT", &rstatus);
01190 Img->first_packet_time = round(65536.0*(fpt - sdo_epoch));
01191 if(Img->first_packet_time == 0)
01192 Img->first_packet_time = UINT64_MAX;
01193 snprintf(oldtlmdsnam, 128, "%s", drms_getkey_string(rs, "TLMDSNAM",&rstatus));
01194 cptr = strstr(oldtlmdsnam, "VC");
01195 if(cptr)
01196 snprintf(tlmnamekeyfirst, 23, "%s", cptr);
01197 else
01198 sprintf(tlmnamekeyfirst, "%s", "UNK");
01199 segment = drms_segment_lookupnum(rs, 0);
01200 if(!segment) {
01201 printk("Can't do drms_segment_lookupnum()\n");
01202 return(1);
01203 }
01204 cArray = drms_segment_read(segment, DRMS_TYPE_SHORT, &rstatus);
01205 if(rstatus || !cArray) {
01206 printk("Can't do drms_segment_read()\n");
01207 return(1);
01208 }
01209 short *adata = (short *)cArray->data;
01210
01211 memcpy(Img->dat, adata, 2*segment->axis[0]*segment->axis[1]);
01212 rdat = Img->dat;
01213
01214 nnx = segment->axis[0];
01215 nny = segment->axis[1];
01216 npix = nnx * nny;
01217 for(i=0; i < nnx; ++i) {
01218 for(j=0; j < nny; ++j)
01219 tmpdat[i*nny+j] = Img->dat[j*nnx+i];
01220 }
01221 memcpy(Img->dat, tmpdat, 2*npix);
01222
01223 segArray = drms_array_create(DRMS_TYPE_SHORT,
01224 segment->info->naxis,
01225 segment->axis,
01226 rdat,
01227 &dstatus);
01228 if(dstatus || !segArray) {
01229 printk("Can't do drms_array_create()\n");
01230 return(1);
01231 }
01232 ImgC = Img;
01233 drms_free_array(cArray);
01234 }
01235 }
01236 else {
01237 if(errskip) {
01238 errskip = 0;
01239 printk("*Skip Closing image for fsn = %u\n", fsn_prev);
01240 }
01241 else {
01242 if(rs && segArray) {
01243 close_image(rs, segment, segArray, Img, fsn_prev);
01244
01245 if(imagecnt++ >= IMAGE_NUM_COMMIT) {
01246 printk("drms_server_end_transaction()\n");
01247 drms_server_end_transaction(drms_env, 0 , 0);
01248 printk("drms_server_begin_transaction()\n");
01249 drms_server_begin_transaction(drms_env);
01250 imagecnt = 0;
01251 }
01252 fileimgcnt++;
01253 }
01254 else {
01255 printk("**ERROR: Null record ptr for an opened image fsn=%u\n",fsn_prev);
01256 }
01257 }
01258 if(fsn_normal_new_image()) {
01259 printk("**ERROR: Can't create new image\n");
01260 return(1);
01261 }
01262 }
01263
01264 return(0);
01265 }
01266
01267
01268
01269 int fsn_change_rexmit()
01270 {
01271 char rexmit_dsname[256];
01272 int rstatus, dstatus, compid, n, k;
01273 int i, j, nnx, nny;
01274 char *cptr;
01275
01276 if(fsn_prev != 0) {
01277 if(rsc) {
01278 if(errskip) {
01279 errskip = 0;
01280 printk("*Skip Closing image for fsn = %u\n", fsn_prev);
01281 }
01282 else {
01283 close_image(rsc, segmentc, oldArray, ImgO, fsn_prev);
01284 imagecnt++;
01285 fileimgcnt++;
01286 }
01287 }
01288 else {
01289 printk("**ERROR: Null record ptr for an rexmit image fsn=%u\n",fsn_prev);
01290 }
01291 }
01292 errmsgcnt = 0;
01293 fsn_prev = fsnx;
01294
01295
01296
01297 snprintf(rexmit_dsname, 256, "%s[%u]", dsout, fsnx);
01298 printk("Open prev ds: %s\n", rexmit_dsname);
01299 rset = drms_open_records(drms_env, rexmit_dsname, &rstatus);
01300 if(rstatus) {
01301 printk("Can't do drms_open_records(%s)\n", rexmit_dsname);
01302 return(1);
01303 }
01304 if(!rset || (rset->n == 0) || rstatus) {
01305 startnew:
01306 printk("No prev ds\n");
01307 ImgO->initialized = 0;
01308 ImgO->reopened = 0;
01309
01310 imgdecode_iris_init_hack(ImgO);
01311 sprintf(tlmnamekeyfirst, "%s", tlmnamekey);
01312 rsc = drms_create_record(drms_env, lev0seriesname, DRMS_PERMANENT, &rstatus);
01313 if(rstatus) {
01314 if(rstatus == DRMS_ERROR_SUMOPEN) {
01315 printk("**ERROR: DRMS can't open w/SUMS. Aborting...\n");
01316 abortit(4);
01317 }
01318 printk("Can't create record for %s fsn=%u\n", lev0seriesname, fsnx);
01319 return(1);
01320 }
01321 rstatus = drms_setkey_int(rsc, "FSN", fsnx);
01322 if(!(segmentc = drms_segment_lookup(rsc, "image"))) {
01323 printk("No drms_segment_lookup(rsc, image)\n");
01324 return(1);
01325 }
01326 rstatus = drms_segment_setdims(segmentc, &DimInfo);
01327 rdat = ImgO->dat;
01328 oldArray = drms_array_create(DRMS_TYPE_SHORT,
01329 segmentc->info->naxis,
01330 segmentc->axis,
01331 rdat,
01332 &dstatus);
01333 if(dstatus || !oldArray) {
01334 printk("Can't do drms_array_create(%s)\n", rexmit_dsname);
01335 return(1);
01336 }
01337 }
01338 else {
01339 ispfound = fsnx;
01340 ispfoundreopen = fsnx;
01341 ImgO->initialized = 1;
01342 ImgO->reopened = 1;
01343 ImgO->fsn = fsnx;
01344 ImgO->apid = appid;
01345 rs_old = rset->records[0];
01346 rsc = drms_clone_record(rs_old, DRMS_PERMANENT, DRMS_COPY_SEGMENTS, &rstatus);
01347 if(rstatus) {
01348 printk("Can't do drms_clone_record()\n");
01349 printk("Assume this was a temp ds and the segments are now gone...\n");
01350 goto startnew;
01351
01352 }
01353 drms_close_records(rset, DRMS_FREE_RECORD);
01354 rstatus = drms_setkey_int(rsc, "FSN", fsnx);
01355 ImgO->telnum = drms_getkey_int(rsc, "CAMERA", &rstatus);
01356 ImgO->telnum--;
01357 ImgO->cropid = drms_getkey_int(rsc, "CROPID", &rstatus);
01358 ImgO->isysn = drms_getkey_int(rsc, "ISYSN", &rstatus);
01359 ImgO->fid = drms_getkey_int(rsc, "FID", &rstatus);
01360 ImgO->luid = drms_getkey_int(rsc, "LUTID", &rstatus);
01361 ImgO->tap = drms_getkey_int(rsc, "TAPCODE", &rstatus);
01362 compid = drms_getkey_int(rsc, "COMPID", &rstatus);
01363 if(compid == 0) {
01364 n = 16; k = 0;
01365 }
01366 else {
01367 k = compid & 0x07;
01368 n = compid >> 3;
01369 n = n & 0x1F;
01370 }
01371 ImgO->N = n;
01372 ImgO->K = k;
01373 ImgO->R = drms_getkey_int(rsc, "BITSELID", &rstatus);
01374 ImgO->overflow = drms_getkey_int(rsc, "OVERFLOW", &rstatus);
01375 ImgO->headerr = drms_getkey_int(rsc, "HEADRERR", &rstatus);
01376 ImgO->totalvals = drms_getkey_int(rsc, "TOTVALS", &rstatus);
01377 ImgO->datavals = drms_getkey_int(rsc, "DATAVALS", &rstatus);
01378 ImgO->npackets = drms_getkey_int(rsc, "NPACKETS", &rstatus);
01379 ImgO->nerrors = drms_getkey_int(rsc, "NERRORS", &rstatus);
01380 ImgO->last_pix_err = drms_getkey_int(rsc, "EOIERROR", &rstatus);
01381
01382 TIME fpt = drms_getkey_double(rsc, "IMGFPT", &rstatus);
01383 ImgO->first_packet_time = round(65536.0*(fpt - sdo_epoch));
01384 if(ImgO->first_packet_time == 0)
01385 ImgO->first_packet_time = UINT64_MAX;
01386 snprintf(oldtlmdsnam, 128, "%s", drms_getkey_string(rsc, "TLMDSNAM",&rstatus));
01387 cptr = strstr(oldtlmdsnam, "VC");
01388 if(cptr)
01389 snprintf(tlmnamekeyfirst, 23, "%s", cptr);
01390 else
01391 sprintf(tlmnamekeyfirst, "%s", "UNK");
01392 segmentc = drms_segment_lookupnum(rsc, 0);
01393 if(!segmentc) {
01394 printk("Can't do drms_segment_lookupnum()\n");
01395 return(1);
01396 }
01397 cArray = drms_segment_read(segmentc, DRMS_TYPE_SHORT, &rstatus);
01398 if(rstatus) {
01399 printk("Can't do drms_segment_read()\n");
01400 return(1);
01401 }
01402 short *adata = (short *)cArray->data;
01403
01404 memcpy(ImgO->dat, adata, 2*segmentc->axis[0]*segmentc->axis[1]);
01405 rdat = ImgO->dat;
01406
01407 nnx = segmentc->axis[0];
01408 nny = segmentc->axis[1];
01409 npix = nnx * nny;
01410 for(i=0; i < nnx; ++i) {
01411 for(j=0; j < nny; ++j)
01412 tmpdat[i*nny+j] = Img->dat[j*nnx+i];
01413 }
01414 memcpy(ImgO->dat, tmpdat, 2*npix);
01415
01416 oldArray = drms_array_create(DRMS_TYPE_SHORT,
01417 segmentc->info->naxis,
01418 segmentc->axis,
01419 rdat,
01420 &dstatus);
01421 if(dstatus || !oldArray) {
01422 printk("Can't do drms_array_create()\n");
01423 return(1);
01424 }
01425 drms_free_array(cArray);
01426 }
01427 ImgC = ImgO;
01428 return(0);
01429 }
01430
01431
01432 int get_tlm(char *file, int rexmit, int higherver)
01433 {
01434 FILE *fpin;
01435 unsigned char cbuf[PKTSZ];
01436 long long gap_42_cnt;
01437 int status, rstatus, fpkt_cnt, i, j, sync_bad_cnt;
01438 int datval, eflg, firstflg, dstatus, ntmp;
01439 unsigned int cnt1, cnt2, cnt3, gap_24_cnt, nxbits, nybits;
01440 int zero_pn;
01441 unsigned short pksync1, pksync2;
01442 float ftmp;
01443 int decode_status=0;
01444 unsigned int Fsn;
01445
01446 if(!(fpin = fopen(file, "r"))) {
01447 printk("*Can't open tlm file %s\n", file);
01448 return(1);
01449 }
01450 BeginTimer(1);
01451 printk("*Processing tlm file %s\n", file);
01452 fpkt_cnt = sync_bad_cnt = eflg = errmsgcnt = fileimgcnt = 0;
01453 zero_pn = gap_24_cnt = gap_42_cnt = 0;
01454 firstflg = 1;
01455 if(rexmit || higherver) {
01456 if(Img->initialized) {
01457 if(rs) {
01458 close_image(rs, segment, segArray, Img, fsn_prev);
01459 printk("drms_server_end_transaction()\n");
01460 drms_server_end_transaction(drms_env, 0 , 0);
01461 printk("drms_server_begin_transaction()\n");
01462 drms_server_begin_transaction(drms_env);
01463 imagecnt = 0;
01464 }
01465 else
01466 printk("**ERROR: Null record ptr for an opened image fsn=%u\n",fsn_prev);
01467 }
01468 fsn_pre_rexmit = fsn_prev;
01469 fsn_prev = 0;
01470 }
01471
01472 while((status = fread(cbuf,sizeof(char),PKTSZ,fpin) ) == PKTSZ) {
01473 pksync1 = MDI_getshort(cbuf);
01474 pksync2 = MDI_getshort(cbuf+2);
01475 if((pksync1 == 0) && (pksync2 == 0)) {
01476 if(!zero_pn) {
01477 printk("*0 PN code at pkt# %d\n", fpkt_cnt);
01478 printk("*Subsequent ones will be ignored until non-0 again\n");
01479 zero_pn = 1;
01480 }
01481 fpkt_cnt++;
01482 continue;
01483 }
01484 if((pksync1 != 0x1acf) || (pksync2 != 0xfc1d)) {
01485 printk("*Lost sync at VCDU pkt# %d. pksync1=%x pksync2=%x\n",
01486 fpkt_cnt, pksync1, pksync2);
01487 fpkt_cnt++;
01488 eflg++;
01489 if(sync_bad_cnt++ > 4) {
01490 printk("**Too many out of sync packets.\n");
01491
01492 return(0);
01493 }
01494 printk(" Will attempt to press on...\n");
01495 zero_pn = 0;
01496 continue;
01497 }
01498 if(firstflg) {
01499 printk("*VCDU pkt# %d sync = %x %x\n", fpkt_cnt, pksync1, pksync2);
01500 }
01501 fpkt_cnt++;
01502
01503 cnt1 = MDI_getshort(cbuf+6);
01504 cnt2 = MDI_getshort(cbuf+8);
01505 cnt2 = (cnt2 >> 8)& 0xFF;
01506 cnt2 = ((cnt1 << 8)& 0xFF00) + cnt2;
01507 cnt1 = (cnt1 >> 8)& 0xFF;
01508 vcdu_24_cnt = (cnt1*65536) + cnt2;
01509 if(vcdu_24_cnt_next != vcdu_24_cnt) {
01510 printk("*VCDU 24bit seq num out of sequence. exp: %u rec: %u\n",
01511 vcdu_24_cnt_next, vcdu_24_cnt);
01512 if(vcdu_24_cnt_next != 0) seqerror = 1;
01513 if(vcdu_24_cnt_next > vcdu_24_cnt) {
01514 printk("*NOTE: VCDU 24 bit counter retarded\n");
01515 printk("*NOTE: gap report will be inaccurate (tbd)\n");
01516 }
01517 if(!firstflg) {
01518 gap_24_cnt += vcdu_24_cnt - vcdu_24_cnt_next;
01519 }
01520 }
01521 vcdu_24_cnt_next = vcdu_24_cnt + 1;
01522
01523 cnt1 = MDI_getshort(cbuf+10);
01524 cnt2 = MDI_getshort(cbuf+12);
01525 cnt3 = MDI_getshort(cbuf+14);
01526 cnt1 = cnt1 & 0x03ff;
01527 vcdu_seq_num = (cnt1*4294967296) + (cnt2*65536) + cnt3;
01528
01529 if(vcdu_seq_num_next != vcdu_seq_num) {
01530 printk("*IM_PDU seq num out of sequence. exp: %lld rec: %lld\n",
01531 vcdu_seq_num_next, vcdu_seq_num);
01532 if(vcdu_seq_num_next != 0) seqerror = 1;
01533 if(vcdu_seq_num_next > vcdu_seq_num) {
01534 printk("*NOTE: IM_PDU 42 bit counter retarded\n");
01535 printk("*NOTE: gap report will be inaccurate\n");
01536 }
01537 if(!firstflg) {
01538 gap_42_cnt += vcdu_seq_num - vcdu_seq_num_next;
01539 }
01540 eflg++;
01541 }
01542 firstflg = 0;
01543 vcdu_seq_num_next = vcdu_seq_num + 1;
01544
01545 appid = MDI_getshort(cbuf+18);
01546 appid = appid & 0x07ff;
01547 if(hmiaiaflg) {
01548
01549 testid1 = 507; testid2 = 517;
01550 }
01551 else {
01552
01553 testid1 = 407; testid2 = 417;
01554 }
01555
01556 if((appid == testid1) || (appid == testid2)) {
01557 if(errmsgcnt++ < MAXERRMSGCNT) {
01558 printk("*Test ApID of %0x found for IM_PDU Cntr = %lld\n",
01559 appid, vcdu_seq_num);
01560 for(i=0, j=TESTVALUE; i < 877; i=i+2, j++) {
01561 datval = MDI_getshort(cbuf+32+i);
01562 if(datval != j) {
01563 printk("*Test data value=%0x, expected=%0x for IM_PDU Cntr=%lld\n",
01564 datval, j, vcdu_seq_num);
01565 printk("*File = %s\n", file);
01566 eflg++;
01567 break;
01568 }
01569 }
01570 }
01571 continue;
01572 }
01573
01574 if(appid == APID_IRIS_TIME) {
01575 int fsn = ((((((cbuf[48] & 0x3f) << 8) | cbuf[49]) << 8) |
01576 cbuf[50]) << 8) | cbuf[51];
01577 if (fsn < bfsn) continue;
01578 if (fsn > efsn) {
01579 abortflg = 1;
01580 return 0;
01581 }
01582 }
01583
01584
01585
01586
01587
01588 if(appid == APID_IRIS_SCIENCE)
01589 {
01590 cnt1 = MDI_getshort(cbuf+32);
01591 cnt2 = MDI_getshort(cbuf+34);
01592 isysn = (unsigned int)(cnt1<<16)+(unsigned int)(cnt2);
01593 isysn = isysn & 0xc0000000;
01594 isysn = (unsigned int)(isysn >> 30);
01595
01596 cnt1 = MDI_getshort(cbuf+40);
01597 cropid = (unsigned int)(cnt1 >> 4);
01598 cnt1 = MDI_getshort(cbuf+42);
01599 tapcode = (unsigned int)(cnt1 >> 12);
01600
01601 cnt1 = MDI_getshort(cbuf+36);
01602 nxbits = (unsigned int)(cnt1 >> 4) & 0x0f;
01603 nybits = (unsigned int)cnt1 & 0x0f;
01604 sumsptrl = (short)nybits;
01605 sumspat = (short)nxbits;
01606
01607
01608
01609 if((tapcode == 10) || (tapcode == 9) || (tapcode == 0 && cropid>0 && isysn !=
01610 0)) {
01611 nx = nxlookTap[nxbits][nybits];
01612 ny = nylookTap[nxbits][nybits];
01613 if(nx == 0) {
01614 nx = nxlookTapdefault;
01615 ny = nylookTapdefault;
01616 printk("WARNING: nxbits/nybits=%d/%d gave invalid nx of 0 for fsn=%u. Use default\n",
01617 nxbits, nybits, fsnx);
01618 }
01619 if(ny == 0) {
01620 nx = nxlookTapdefault;
01621 ny = nylookTapdefault;
01622 printk("WARNING: nxbits/nybits=%d/%d gave invalid ny of 0 for fsn=%u. Use default\n",
01623 nxbits, nybits, fsnx);
01624 }
01625 }
01626 else {
01627 nx = nxlook[nxbits][nybits];
01628 ny = nylook[nxbits][nybits];
01629 if(nx == 0) {
01630 nx = nxlookdefault;
01631 printk("WARNING: nxbits/nybits=%d/%d gave invalid nx of 0 for fsn=%u. Use default\n",
01632 nxbits, nybits, fsnx);
01633 }
01634 if(ny == 0) {
01635 ny = nylookdefault;
01636 printk("WARNING: nxbits/nybits=%d/%d gave invalid ny of 0 for fsn=%u. Use default\n",
01637 nxbits, nybits, fsnx);
01638 }
01639 }
01640
01641 ntmp = nx;
01642 nx = ny;
01643 ny = ntmp;
01644 if(!printflg) {
01645 printflg = 1;
01646 printk("nx/ny = %d/%d for fsn = %u\n", nx, ny, fsnx);
01647 printk("*FSN %u tapcode=%d cropid=%d\n", fsnx, tapcode, cropid);
01648 }
01649 DimInfo.naxis = 2;
01650 DimInfo.axis[0] = nx;
01651 DimInfo.axis[1] = ny;
01652 cnt1 = MDI_getshort(cbuf+32);
01653 cnt2 = MDI_getshort(cbuf+34);
01654 fsnx = (unsigned int)(cnt1<<16)+(unsigned int)(cnt2);
01655 fsnx = fsnx & 0x3fffffff;
01656 if(fsnx == 0) continue;
01657 if(fsnx < bfsn) continue;
01658 if(fsnx > efsn) continue;
01659 if(tapcode == 10) {
01660
01661 fsnx++;
01662 fsnISP = fsnx;
01663 fsnISP_noop = 1;
01664 }
01665 if(OpenNextImg) {
01666 rs = NextImage.rsN;
01667 segment = NextImage.segN;
01668 ImgC = NextImage.imgN;
01669 if(drms_segment_setdims(segment, &DimInfo)) {
01670 printk("No drms_segment_setdims(segment, &DimInfo)\n");
01671 return(1);
01672 }
01673 segArray = drms_array_create(DRMS_TYPE_SHORT,
01674 segment->info->naxis,
01675 segment->axis,
01676 rdat,
01677 &dstatus);
01678 if(dstatus || !segArray) {
01679 printk("Can't do drms_array_create()\n");
01680 return(1);
01681 }
01682 OpenNextImg = 0;
01683 }
01684 if(rexmit || higherver) {
01685 if(fsnx != fsn_prev) {
01686 imgdecode_iris_init_hack(ImgO);
01687 imgdecode_iris_init_hack(Img);
01688 if(fsn_change_rexmit()) {
01689 printk("***FATAL ERROR in fsn_change_rexmit()\n");
01690 return(1);
01691 }
01692 }
01693 else {
01694 ImgC->apid = appid;
01695 }
01696 }
01697 else {
01698 if(fsnx != fsn_prev) {
01699 imgdecode_iris_init_hack(ImgO);
01700 imgdecode_iris_init_hack(Img);
01701 if(fsnx < fsn_prev) {
01702 printk("**WARNING: ISP out of order with image data\n");
01703 RSISP = 0;
01704 }
01705 if(fsn_change_normal()) {
01706 printk("***FATAL ERROR in fsn_change_normal()\n");
01707 return(1);
01708 }
01709 }
01710 }
01711
01712 if(errskip || retardskip) { continue; }
01713 ImgC->nx = nx;
01714 ImgC->ny = ny;
01715 rstatus = imgdecode_iris((unsigned short *)(cbuf+10), ImgC);
01716 switch(rstatus) {
01717 case 0:
01718
01719 break;
01720 case IMGDECODE_DECOMPRESS_ERROR:
01721 if(errmsgcnt++ < MAXERRMSGCNT)
01722 printk("*imgdecode_iris() ret: IMGDECODE_DECOMPRESS_ERROR\n");
01723 break;
01724 case IMGDECODE_TOO_MANY_PIXELS:
01725 if(errmsgcnt++ < MAXERRMSGCNT)
01726 printk("*imgdecode_iris() ret: IMGDECODE_TOO_MANY_PIXELS\n");
01727 break;
01728 case IMGDECODE_BAD_N:
01729 if(errmsgcnt++ < MAXERRMSGCNT)
01730 printk("*imgdecode_iris() ret: IMGDECODE_BAD_N\n");
01731 break;
01732 case IMGDECODE_BAD_APID:
01733 if(errmsgcnt++ < MAXERRMSGCNT)
01734 printk("*imgdecode_iris() ret: IMGDECODE_BAD_APID\n");
01735 break;
01736 case IMGDECODE_NO_LOOKUP_TABLE:
01737 if(errmsgcnt++ < MAXERRMSGCNT)
01738 printk("*imgdecode_iris() ret: IMGDECODE_NO_LOOKUP_TABLE\n");
01739 break;
01740 case IMGDECODE_LOOKUP_ID_MISMATCH:
01741 if(errmsgcnt++ < MAXERRMSGCNT)
01742 printk("*imgdecode_iris() ret: IMGDECODE_LOOKUP_ID_MISMATCH\n");
01743 break;
01744 case IMGDECODE_BAD_LOOKUP_TABLE:
01745 if(errmsgcnt++ < MAXERRMSGCNT)
01746 printk("*imgdecode_iris() ret: IMGDECODE_BAD_LOOKUP_TABLE\n");
01747 break;
01748 case IMGDECODE_NO_CROP_TABLE:
01749 if(errmsgcnt++ < MAXERRMSGCNT)
01750 printk("*imgdecode_iris() ret: IMGDECODE_NO_CROP_TABLE\n");
01751 break;
01752 case IMGDECODE_CROP_ID_MISMATCH:
01753 if(errmsgcnt++ < MAXERRMSGCNT)
01754 printk("*imgdecode_iris() ret: IMGDECODE_CROP_ID_MISMATCH\n");
01755 break;
01756 case IMGDECODE_BAD_CROP_GEOMETRY:
01757 if(errmsgcnt++ < MAXERRMSGCNT)
01758 printk("*imgdecode_iris() ret: IMGDECODE_BAD_CROP_GEOMETRY\n");
01759 break;
01760 case IMGDECODE_BAD_CROP_TABLE:
01761 if(errmsgcnt++ < MAXERRMSGCNT)
01762 printk("*imgdecode_iris() ret: IMGDECODE_BAD_CROP_TABLE\n");
01763 break;
01764 case IMGDECODE_BAD_CROP_SKIP_TAKE:
01765 if(errmsgcnt++ < MAXERRMSGCNT)
01766 printk("*imgdecode_iris() ret: IMGDECODE_BAD_CROP_SKIP_TAKE\n");
01767 break;
01768 case IMGDECODE_BAD_OFFSET:
01769 if(errmsgcnt++ < MAXERRMSGCNT)
01770 printk("*imgdecode_iris() ret: IMGDECODE_BAD_OFFSET\n");
01771 break;
01772 case IMGDECODE_OUT_OF_MEMORY:
01773 if(errmsgcnt++ < MAXERRMSGCNT)
01774 printk("*imgdecode_iris() ret: IMGDECODE_OUT_OF_MEMORY\n");
01775 break;
01776 default:
01777 if(errmsgcnt++ < MAXERRMSGCNT)
01778 printk("*imgdecode_iris() ret: unknown err status = %d:\n", rstatus);
01779 break;
01780 }
01781 if(rstatus) {
01782 if(!conterr) {
01783 errskip = 1;
01784 printk("*FSN imgdecode() error. Skip fsn=%u\n", fsnx);
01785 }
01786 else printk("*FSN imgdecode() error. Continue processing fsn=%u\n", fsnx);
01787 }
01788 }
01789 else {
01790
01791 decode_status = decode_next_hk_vcdu((unsigned short *)(cbuf+10), &Hk, &Fsn);
01792
01793 switch (decode_status) {
01794 case SUCCESS_HK_NEED_TO_WTD_CTD:
01795 printk("*ISP found for fsn = %u\n", Fsn);
01796 ispfound = fsnISPX;
01797 fsnISP = fsnISPX;
01798 fsnISPX = Fsn;
01799 fsnx = Fsn;
01800 if(rexmit || higherver) {
01801 if(fsnx != fsn_prev) {
01802 if(fsn_change_rexmit()) {
01803 printk("***FATAL ERROR in fsn_change_rexmit()\n");
01804 return(1);
01805 }
01806 }
01807
01808 HMI_compute_exposure_times(rsc, Hk->keywords, hmiaiaflg);
01809 printk("Call write_hk_to_drms() after SUCCESS_HK_NEED_TO_WTD_CTD for rexmit\n");
01810 whk_status = write_hk_to_drms(rsc, &Hk);
01811
01812
01813
01814
01815
01816 }
01817 else {
01818 if(fsnx != fsn_prev) {
01819 if(fsn_change_normal()) {
01820 printk("***FATAL ERROR in fsn_change_normal()\n");
01821 return(1);
01822 }
01823 }
01824
01825 HMI_compute_exposure_times(rs, Hk->keywords, hmiaiaflg);
01826 printk("Calling write_hk_to_drms() after SUCCESS_HK_NEED_TO_WTD_CTD for normal fsn change\n");
01827 whk_status = write_hk_to_drms(rs, &Hk);
01828
01829
01830
01831
01832
01833 }
01834 hk_ccsds_free(&Hk);
01835 rstatus=0;
01836 break;
01837 case SUCCESS_HK_NEED_TO_CTD:
01838
01839
01840 break;
01841 case SUCCESS_SKIP_IMAGE:
01842 printk("decode_next_hk_vcdu() ret:Warning:SUCCESS_SKIP_IMAGE\n");
01843 break;
01844 case SUCCESS_SKIP_PROCESSING_APID:
01845 printk("decode_next_hk_vcdu() ret:Warning:SUCCESS_SKIP_PROCESSING_APID:\n");
01846 break;
01847 case ERROR_HK_FAILED_GETTING_FSN:
01848 printk("decode_next_hk_vcdu() ret:Warning:ERROR_HK_FAILED_GETTING_FSN:\n");
01849 break;
01850 case ERROR_NODATA:
01851 printk("decode_next_hk_vcdu() ret:Warning:ERROR_NODATA\n");
01852 break;
01853 case ERROR_HK_ENVIRONMENT_VARS_NOT_SET:
01854 printk("decode_next_hk_vcdu() ret:ERROR:ERROR_HK_ENVIRONMENT_VARS_NOT_SET\n");
01855 break;
01856 case ERROR_HK_FAILED_OPEN_DAYFILE:
01857 printk("decode_next_hk_vcdu() ret:ERROR:ERROR_HK_FAILED_OPEN_DAYFILE\n");
01858 break;
01859 default:
01860 printk("decode_next_hk_vcdu() ret:Warning:Unexpected return code for decode_status:<%d>:\n", decode_status);
01861 break;
01862 }
01863 }
01864 }
01865 fclose(fpin);
01866 if(!eflg) {
01867 printk("*No errors in tlm file\n");
01868 }
01869 if(rexmit || higherver) {
01870 if(rsc) {
01871 close_image(rsc, segmentc, oldArray, ImgO, fsnx);
01872 printk("drms_server_end_transaction()\n");
01873 drms_server_end_transaction(drms_env, 0 , 0);
01874 printk("drms_server_begin_transaction()\n\n");
01875 drms_server_begin_transaction(drms_env);
01876 imagecnt = 0;
01877 fileimgcnt++;
01878
01879 fsn_prev = 0;
01880 rsc = 0;
01881 }
01882 }
01883 ftmp = EndTimer(1);
01884 printk("%s\n**Processed %s\n**with %d images and %d VCDUs in %f sec\n\n",
01885 do_datestr(),file, fileimgcnt, fpkt_cnt, ftmp);
01886
01887
01888
01889
01890
01891
01892
01893
01894
01895
01896
01897
01898
01899
01900 if(fpkt_cnt != total_tlm_vcdu) {
01901 printk("**WARNING: Found #vcdu=%d; expected=%d\n", fpkt_cnt, total_tlm_vcdu);
01902 }
01903
01904
01905
01906
01907 if(gap_42_cnt != total_missing_im_pdu) {
01908 printk("**WARNING: IM_PDU 42bit cntr gaps=%lld; expected=%lld\n",
01909 gap_42_cnt, total_missing_im_pdu);
01910 }
01911 ignoresigalrmflg = 1;
01912 return(0);
01913 }
01914
01915
01916
01917
01918 void do_ingest()
01919 {
01920 FILE *fp;
01921 DRMS_Record_t *rs_tlm;
01922 DIR *dfd;
01923 NAMESORT *nameptr;
01924 struct dirent *dp;
01925 int i, j, status, mvstat;
01926 int rexmit, higherversion;
01927 char path[DRMS_MAXPATHLEN];
01928 char name[128], line[128], tlmfile[128], tlmname[96];
01929 char cmd[256], xxname[128], vername[16];
01930 char *token, *filename;
01931
01932 if((dfd=opendir(tlmdir)) == NULL) {
01933 printk("**Can't opendir(%s) to find files\n", tlmdir);
01934 abortit(3);
01935 }
01936 i = 0;
01937 if((nameptr = (NAMESORT *)malloc(MAXFILES * sizeof(NAMESORT))) == NULL) {
01938 printk("***Can't alloc memory for file name sort\n");
01939 abortit(3);
01940 }
01941
01942 while((dp=readdir(dfd)) != NULL) {
01943
01944
01945
01946 if(strstr(dp->d_name, pchan) || strstr(dp->d_name, rchan) || strstr(dp->d_name, ".dsf")) {
01947 nameptr[i++].name = strdup(dp->d_name);
01948 if(i >= MAXFILES) {
01949 printk("***Fatal error. Too many (%d) files in %s\n", MAXFILES, tlmdir);
01950 printf("***Fatal error. Too many (%d) files in %s\n", MAXFILES, tlmdir);
01951 abortit(3);
01952 }
01953 cntsleeps = 0;
01954 if(timeoutclose) {
01955
01956
01957 fsnISP = fsnISPTOCLOSE;
01958 }
01959 }
01960 }
01961 closedir(dfd);
01962 if(i == 0) {
01963 free(nameptr);
01964 return;
01965 }
01966 qsort(nameptr, i, sizeof(NAMESORT), &compare_names);
01967 nofiletimeout = atoi(getenv("FLUSH_2SEC_COUNT"));
01968
01969 for(j=0; j < i; j++) {
01970
01971
01973
01974 if(strstr(nameptr[j].name, ".dsf")) {
01975
01976
01977 sprintf(cmd, "/bin/mv -f %s/%s %s", tlmdir, nameptr[j].name, MVDSFDIR);
01978 printk("*mv dsf file to %s\n", MVDSFDIR);
01979 printk("%s\n", cmd);
01980 if(system(cmd)) {
01981 printk("***Error on: %s\n", cmd);
01982 }
01983 }
01984
01985 if(!strstr(nameptr[j].name, ".qac")) {
01986 free(nameptr[j].name);
01987 continue;
01988 }
01989 rexmit = higherversion = 0;
01990 if(strstr(nameptr[j].name, ".qacx")) {
01991 rexmit = 1;
01992 }
01993 sprintf(name, "%s/%s", tlmdir, nameptr[j].name);
01994 printk("%s\n*Found qac file:\n* %s\n", do_datestr(), name);
01995 if(!(fp=fopen(name, "r"))) {
01996 printk("***Can't open %s\n", name);
01997 free(nameptr[j].name);
01998 continue;
01999 }
02000
02001 while(fgets(line, 256, fp)) {
02002 if(line[0] == '#' || line[0] == '\n') continue;
02003 if(strstr(line, "TLM_FILE_NAME=")) {
02004 token = (char *)strtok(line, "=");
02005 token = (char *)strtok(NULL, "\n");
02006 printk("tlm file is %s\n", token);
02007 sprintf(tlmfile, "%s/%s", tlmdir, token);
02008 sprintf(tlmname, "%s", token);
02009 }
02010 else if(strstr(line, "TLM_FILE_SIZE=")) {
02011 token = (char *)strtok(line, "=");
02012 token = (char *)strtok(NULL, "=");
02013 printk("*tlm file size is %s", token);
02014 }
02015 else if((strstr(line, "TOTAL_TLM_IM_PDU=")) || (strstr(line, "TOTAL_VCDU="))) {
02016 token = (char *)strtok(line, "=");
02017 token = (char *)strtok(NULL, "\n");
02018 total_tlm_vcdu = atoi(token);
02019 }
02020 else if(strstr(line, "TOTAL_MISSING_VCDU=")) {
02021 token = (char *)strtok(line, "=");
02022 token = (char *)strtok(NULL, "\n");
02023 total_missing_vcdu = atoi(token);
02024 }
02025 else if(strstr(line, "TOTAL_MISSING_IM_PDU=")) {
02026 token = (char *)strtok(line, "=");
02027 token = (char *)strtok(NULL, "\n");
02028 total_missing_im_pdu = atol(token);
02029 break;
02030 }
02031 }
02032 fclose(fp);
02033
02034 strcpy((char *)tlmnamekey, (char *)tlmname);
02035 filename = (char *)rindex(tlmname, '.');
02036 if(!filename) {
02037 printk("**ERROR: Bad formed tlm name in qac file\n");
02038 printk(" tlm name = %s\n", tlmname);
02039 continue;
02040 }
02041 *filename = 0;
02042 *((char *)tlmnamekey+22) = 0;
02043 rs_tlm = drms_create_record(drms_env, tlmseriesname,
02044 DRMS_PERMANENT, &status);
02045 if(status) {
02046 if(status == DRMS_ERROR_SUMOPEN) {
02047 printk("**ERROR: DRMS can't open w/SUMS. Aborting...\n");
02048 abortit(4);
02049 }
02050 printk("***Can't create record for %s. Status=%d\n", tlmseriesname, status);
02051 continue;
02052 }
02053 if((status = drms_setkey_string(rs_tlm, "filename", tlmnamekey))) {
02054 printk("**ERROR: drms_setkey_string failed for 'filename'\n");
02055 }
02056 drms_record_directory(rs_tlm, path, 0);
02057 if(!*path) {
02058 printk("***ERROR: No path to segment for %s\n", tlmseriesname);
02059 continue;
02060 }
02061
02062 sprintf(cmd, "/bin/cp -p %s %s", name, path);
02063 printk("*cp qac to %s\n", path);
02064 printk("%s\n", cmd);
02065 if(status = system(cmd)) {
02066 printk("**ERROR: %d errno=%d on: %s\n", status, errno, cmd);
02067 if(WIFEXITED(status)) {
02068 if(mvstat = WEXITSTATUS(status)) {
02069 printk("**ERROR: cp exit status = %d\n", mvstat);
02070 }
02071 }
02072 }
02073 sprintf(cmd, "/bin/cp -p %s %s", tlmfile, path);
02074 printk("*cp tlm to %s\n", path);
02075 printk("%s\n", cmd);
02076 if(status = system(cmd)) {
02077 printk("**ERROR: %d errno=%d on: %s\n", status, errno, cmd);
02078 if(WIFEXITED(status)) {
02079 if(mvstat = WEXITSTATUS(status)) {
02080 printk("**ERROR: cp exit status = %d\n", mvstat);
02081 }
02082 }
02083 sprintf(cmd, "/bin/mv -f %s %s", name, "/sds/reject/iris");
02084 printk("%s\n", cmd);
02085 if(status = system(cmd)) {
02086 printk("**ERROR: on mv\n");
02087 }
02088 printk("**Continue after ERROR on cp of tlm file\n");
02089 continue;
02090 }
02091 if(outdir) {
02092 sprintf(cmd, "/bin/mv -f %s %s", name, outdir);
02093 printk("*mv qac file to %s\n", outdir);
02094 printk("%s\n", cmd);
02095 if(system(cmd)) {
02096 printk("***Error on: %s\n", cmd);
02097 }
02098 sprintf(cmd, "/bin/mv -f %s %s", tlmfile, outdir);
02099 printk("*mv tlm file to %s\n", outdir);
02100 printk("%s\n", cmd);
02101 if(system(cmd)) {
02102 printk("***Error on: %s\n", cmd);
02103 }
02104 }
02105 else {
02106 sprintf(cmd, "/bin/rm -f %s", name);
02107 printk("%s\n", cmd);
02108 if(status = system(cmd)) {
02109 printk("**ERROR: %d errno=%d on: %s\n", status, errno, cmd);
02110 send_mail("ERROR: %s. We must be able to rm these files\n", cmd);
02111 if(WIFEXITED(status)) {
02112 if(mvstat = WEXITSTATUS(status)) {
02113 printk("**ERROR: rm exit status = %d\n", mvstat);
02114 }
02115 }
02116 }
02117 sprintf(cmd, "/bin/rm -f %s", tlmfile);
02118 printk("%s\n", cmd);
02119 if(status = system(cmd)) {
02120 printk("**ERROR: %d errno=%d on: %s\n", status, errno, cmd);
02121 send_mail("ERROR: %s. We must be able to rm these files\n", cmd);
02122 if(WIFEXITED(status)) {
02123 if(mvstat = WEXITSTATUS(status)) {
02124 printk("**ERROR: rm exit status = %d\n", mvstat);
02125 }
02126 }
02127 printk("**Continue after ERROR on rm of tlm file\n");
02128 continue;
02129 }
02130 }
02131 if((status = drms_close_record(rs_tlm, DRMS_INSERT_RECORD))) {
02132 printk("**ERROR: drms_close_record failed for %s\n", tlmseriesname);
02133 }
02134
02135 sprintf(xxname, "%s/%s.tlm", path, tlmname);
02136 filename = (char *)rindex(tlmname, '_');
02137 sprintf(vername, "%s", filename);
02138 if(strcmp(vername, "_00")) {
02139 higherversion = 1;
02140 printk("Higher version tlm found: %s.tlm\n", tlmname);
02141 }
02142 firstfound = 1;
02143 if(get_tlm(xxname, rexmit, higherversion)) {
02144 printk("***Error in lev0 extraction for %s\n", xxname);
02145
02146
02147 }
02148 if((stat(stopfile, &stbuf) == 0) || abortflg) { break; }
02149 }
02150 free(nameptr);
02151 }
02152
02153
02154
02155
02156
02157
02158
02159
02160
02161
02162
02163
02164
02165
02166
02167
02168
02169
02170
02171 void do_pipe2soc() {
02172 DIR *dfd;
02173 struct dirent *dp;
02174 FILE *fp;
02175 int ptape_fn, complete;
02176 char line[128], fname[128], cmd[128];
02177 char *su_name, *ptape_id, *ptape_date;
02178
02179 if((dfd=opendir(pipedir)) == NULL) {
02180 printk("**Can't opendir(%s) to find files\n", pipedir);
02181 return;
02182 }
02183 while((dp=readdir(dfd)) != NULL) {
02184 if(strstr(dp->d_name, ".parc")) {
02185 sprintf(fname, "%s/%s", pipedir, dp->d_name);
02186 if(!(fp=fopen(fname, "r"))) {
02187 printk("***Can't open %s\n", fname);
02188 continue;
02189 }
02190 printk("Found parc file: %s\n", fname);
02191 complete = 1;
02192 while(fgets(line, 128, fp)) {
02193 if(line[0] == '#' || line[0] == '\n') continue;
02194 printk("%s", line);
02195 su_name = (char *)strtok(line, " ");
02196 ptape_id = (char *)strtok(NULL, " ");
02197
02198 errno = 0;
02199 ptape_fn = (int)strtol((char *)strtok(NULL, " "), (char **) NULL, 10);
02200 if(errno) continue;
02201 ptape_date = (char *)strtok(NULL, "\n");
02202 if(SUMLIB_SafeTapeUpdate(su_name,ptape_id,ptape_fn,ptape_date)) {
02203 printk("**ERROR in SUMLIB_SafeTapeUpdate(%s...)\n", su_name);
02204 complete = 0;
02205 }
02206 }
02207 fclose(fp);
02208 if(complete) {
02209 sprintf(cmd, "/bin/rm -f %s", fname);
02210 }
02211 else {
02212 sprintf(cmd, "/bin/mv -f %s %s/err/", fname, pipedir);
02213 }
02214 printk("%s\n", cmd);
02215 system(cmd);
02216 }
02217 }
02218 closedir(dfd);
02219 }
02220
02221
02222 void setup()
02223 {
02224 FILE *fp;
02225 int i;
02226 char string[128], cwdbuf[128], idstr[256];
02227 char envfile[100], s1[256],s2[256],s3[256], line[256];
02228 ThreadSigErr_t error = kThreadSigErr_Success;
02229
02230
02231 sdo_epoch = sscan_time("1958.01.01_00:00:00_TAI");
02232 do_datestr();
02233 printk_set(h0log, h0log);
02234 printk("%s\n", datestr);
02235 getcwd(cwdbuf, 126);
02236 sprintf(idstr, "Cwd: %s\nCall: ", cwdbuf);
02237 if(grounddata)
02238 sprintf(string, "ingest_lev0_irisdc -g started as pid=%d user=%s\n", getpid(), username);
02239 else
02240 sprintf(string, "ingest_lev0_irisdc [-A] started as pid=%d user=%s\n", getpid(), username);
02241 strcat(idstr, string);
02242 printk("*%s", idstr);
02243 if(restartflg) printk("-r ");
02244 sprintf(argvc, "vc=%s", vc);
02245 sprintf(argindir, "indir=%s", tlmdir);
02246 sprintf(arglogfile, "logfile=%s", logname);
02247 if(outdir) {
02248 sprintf(argoutdir, "outdir=%s", outdir);
02249 printk("%s %s %s %s\n", argvc, argindir, argoutdir, arglogfile);
02250 }
02251 else {
02252 printk("%s %s %s\n", argvc, argindir, arglogfile);
02253 }
02254 if(pipedir) {
02255 sprintf(argpipedir, "pipedir=%s", pipedir);
02256 printk("Also check for .parc files in %s\n", argpipedir);
02257 }
02258 strcpy(pchan, vc);
02259 sprintf(stopfile, "%s/lev0/%s_stop", logroot, pchan);
02260 sprintf(string, "/bin/rm -f %s", stopfile);
02261 system(string);
02262 for(i=0; ; i++) {
02263 if(!strcmp(p_r_chan_pairs[i].pchan, pchan)) {
02264 strcpy(rchan, p_r_chan_pairs[i].rchan);
02265 hmiaiaflg = p_r_chan_pairs[i].instru;
02266 break;
02267 }
02268 if(!strcmp(p_r_chan_pairs[i].pchan, "n/a")) {
02269 printk("!!ERROR: Invalid VCid (%s) specified\n", pchan);
02270 fprintf(stderr, "!!ERROR: Invalid VCid (%s) specified. Abort\n", pchan);
02271 abortit(1);
02272 }
02273 }
02274 if(hmiaiaflg) {
02275
02276
02277
02278
02279
02280
02281
02282
02283 }
02284 else {
02285 if(grounddata) {
02286
02287
02288 }
02289 else {
02290 if(amesflg) {
02291 sprintf(tlmseriesname, "%s", TLMSERIESNAMEHMIAMES);
02292 sprintf(lev0seriesname, "%s", LEV0SERIESNAMEHMIAMES);
02293 }
02294 else {
02295 snprintf(tlmseriesname, 128, "%s", tlm_name);
02296 snprintf(lev0seriesname, 128, "%s", dsout);
02297 }
02298 }
02299 }
02300 sprintf(bld_vers, "%s", jsoc_version);
02301 umask(002);
02302 Image.initialized = 0;
02303 ImageOld.initialized = 0;
02304 Img = &Image;
02305 ImgO = &ImageOld;
02306
02307
02308 imgdecode_iris_init_hack(Img);
02309 imgdecode_iris_init_hack(ImgO);
02310
02311
02312
02313 if(grounddata) strcpy(envfile, ENVFILE_GND );
02314 else {
02315 if(amesflg) strcpy(envfile, ENVFILEA);
02316 else strncpy(envfile, (char *)cmdparams_get_str(&cmdparams,
02317 "envfile", NULL), 100);
02318 }
02319
02320 if(!(fp=fopen(envfile, "r"))) {
02321 printk("***Can't open %s. Check setting is correct\n", envfile);
02322 exit(0);
02323 }
02324
02325 while( fgets(line, MAXLINE_IN_FILE, fp) != NULL )
02326 {
02327 if (!strncmp(line, "#", 1)) {
02328 continue;
02329 }
02330 else {
02331 sscanf(line, "%s %s %s ", s1,s2,s3);
02332
02333 setenv(s2, s3, 1);
02334 }
02335 }
02336 fclose(fp);
02337 if(!restartflg) {
02338 printk("tlmseriesname=%s\nlev0seriesname=%s\nispseriesname=%s\n",
02339 tlmseriesname, lev0seriesname, getenv("HK_ISP_IRIS_DSNAME"));
02340 }
02341
02342
02343 if(logflg) {
02344 sprintf(wdlogname,"%s_%s",WDLOGDIR,pchan);
02345 printf("making directory: %s\n", wdlogname);
02346 mkdir(wdlogname,0777);
02347 sprintf(wdlogname,"%s_%s/%s",WDLOGDIR,pchan,WDLOGFILE);
02348 sprintf(oldwdlogname,"%s_%s/%s.old",WDLOGDIR,pchan,WDLOGFILE);
02349 rename(wdlogname,oldwdlogname);
02350 if((wdlogfp=fopen(wdlogname,"w")) == NULL)
02351 {
02352 h0log("Can't open the log file %s\n", wdlogname);
02353 }
02354 else
02355 {
02356 fprintf(wdlogfp, "#image file of lev0 ds by hmi_lev0 %s\n", datestr);
02357 sprintf(Indir,"%s_%s/%s",WDLOGDIR,pchan,datestr);
02358 if(mkdir(Indir,0775))
02359 {
02360 h0log("Can't mkdir %s. Proceed without it\n",Indir);
02361 }
02362 }
02363
02364 }
02365 }
02366
02367
02368 int DoIt(void)
02369 {
02370 pid_t pid;
02371 int wflg = 1;
02372 char *args[6];
02373 char callcmd[256];
02374
02375 if (nice_intro())
02376 return (0);
02377 if(!(username = (char *)getenv("USER"))) username = "nouser";
02378 vc = (char *)cmdparams_get_str(&cmdparams, "vc", NULL);
02379 tlmdir = (char *)cmdparams_get_str(&cmdparams, "indir", NULL);
02380 outdir = (char *)cmdparams_get_str(&cmdparams, "outdir", NULL);
02381 pipedir = (char *)cmdparams_get_str(&cmdparams, "pipedir", NULL);
02382 logfile = (char *)cmdparams_get_str(&cmdparams, "logfile", NULL);
02383 logroot = strdup(cmdparams_get_str(&cmdparams, "logroot", NULL));
02384 dsout = strdup(cmdparams_get_str(&cmdparams, "dsout", NULL));
02385 tlm_name = strdup(cmdparams_get_str(&cmdparams, "tlm_name", NULL));
02386 bfsn = cmdparams_get_int(&cmdparams, "bfsn", NULL);
02387 efsn = cmdparams_get_int(&cmdparams, "efsn", NULL);
02388 sprintf(hlogfile, "%s/lev0/ingest_lev0.%%s.%%s.%%s.log", logroot);
02389 if (strcmp(vc, NOTSPECIFIED) == 0) {
02390 fprintf(stderr, "'vc' virt channel must be specified. Abort\n");
02391 return(1);
02392 }
02393 if (strcmp(tlmdir, NOTSPECIFIED) == 0) {
02394 fprintf(stderr, "'indir' must be specified. Abort\n");
02395 return(1);
02396 }
02397 if (strcmp(outdir, NOTSPECIFIED) == 0) {
02398 outdir = NULL;
02399 }
02400 if (strcmp(pipedir, NOTSPECIFIED) == 0) {
02401 pipedir = NULL;
02402 }
02403 else {
02404 if(DS_ConnectDB_Q(dbname)) {
02405 printk("**Can't connect to DB %s\n", dbname);
02406 printk("**ERROR: Will not be able to process .parc files\n");
02407 pipedir = NULL;
02408 }
02409 }
02410 if (strcmp(logfile, NOTSPECIFIED) == 0) {
02411 sprintf(logname, hlogfile, username, vc, gettimetag());
02412 }
02413 else {
02414 sprintf(logname, "%s", logfile);
02415 }
02416 if(restartflg) {
02417
02418 if((h0logfp=fopen(logname, "a")) == NULL)
02419 fprintf(stderr, "**Can't open for append the log file %s\n", logname);
02420 }
02421 else {
02422 if((h0logfp=fopen(logname, "w")) == NULL)
02423 fprintf(stderr, "**Can't open the log file %s\n", logname);
02424 }
02425 setup();
02426 while(wflg) {
02427 do_ingest();
02428 if(pipedir) do_pipe2soc();
02429 if((stat(stopfile, &stbuf) == 0) || abortflg) {
02430 printk("Abort or Found file: %s. Terminate.\n", stopfile);
02431 if(abortflg) send_mail("Abort for ingest_lev0_iris for %s\n", pchan);
02432
02433 if(Image.initialized) {
02434 if(rs) {
02435 close_image(rs, segment, segArray, &Image, fsn_prev);
02436 }
02437 }
02438 else {
02439 printk("*No image to close on exit\n");
02440 }
02441
02442
02443 drms_server_end_transaction(drms_env, 0 , 0);
02444
02445
02446
02447
02448 snprintf(callcmd, 256, "touch %s/lev0/%s_exit", logroot, pchan);
02449 system(callcmd);
02450 wflg = 0;
02451 continue;
02452 }
02453 sleep(sleep_interval);
02454 if(cntsleeps == 0) {
02455 if(paused) {
02456 paused = 0;
02457
02458 }
02459 }
02460 else {
02461 if(cntsleeps >= nofiletimeout) {
02462
02463 if(Image.initialized) {
02464 if(rs) {
02465 printf("Data flow stopped for %d sec. Closing current image.\n",
02466 nofiletimeout*2);
02467 printk("Data flow stopped for %d sec. Closing current image.\n",
02468 nofiletimeout*2);
02469 RSISP = RSISPTO;
02470 fsnISPTOCLOSE = fsnISP;
02471 fsnISP = fsnISPX;
02472 ispfound = fsnISPX;
02473 close_image(rs, segment, segArray, &Image, fsn_prev);
02474 timeoutclose = 1;
02475 drms_server_end_transaction(drms_env, 0 , 0);
02476 drms_server_begin_transaction(drms_env);
02477 fsn_prev = 0;
02478 rs = NULL;
02479 }
02480 }
02481 else {
02482
02483 }
02484 }
02485 }
02486 cntsleeps++;
02487 if(cntsleeps > 300) {
02488 if(!paused) {
02489
02490 paused = 1;
02491 }
02492 }
02493 }
02494 if(pipedir) DS_DisConnectDB_Q();
02495 return(0);
02496 }
02497