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