00001
00002
00003 #include <jsoc_main.h>
00004 #include <cmdparams.h>
00005 #include <drms.h>
00006 #include <drms_names.h>
00007 #include <stdio.h>
00008 #include <stdlib.h>
00009 #include <ctype.h>
00010 #include <strings.h>
00011 #include <sys/types.h>
00012 #include <sys/time.h>
00013 #include <sys/stat.h>
00014 #include <dirent.h>
00015 #include <unistd.h>
00016 #include <printk.h>
00017 #include "packets.h"
00018 #include "imgdecode.h"
00019 #include "decode_hk_vcdu.h"
00020 #include "decode_hk.h"
00021 #include "load_hk_config_files.h"
00022
00023 #define LEV0SERIESNAMEHMI "su_production.lev0_test"
00024 #define TLMSERIESNAMEHMI "su_production.tlm_test"
00025 #define LEV0SERIESNAMEAIA "su_production.lev0_test_aia"
00026 #define TLMSERIESNAMEAIA "su_production.tlm_test_aia"
00027
00028
00029
00030
00031 #define H0LOGFILE "/usr/local/logs/lev0/ingest_lev0.%s.%s.%s.log"
00032 #define PKTSZ 1788 //size of VCDU pkt
00033 #define MAXFILES 512 //max # of file can handle in tlmdir
00034 #define NUMTIMERS 8 //number of seperate timers avail
00035 #define IMAGE_NUM_COMMIT 12 //number of complete images until commit
00036 #define TESTAPPID 0x199 //appid of test pattern packet
00037 #define TESTVALUE 0xc0b //first value in test pattern packet
00038 #define MAXERRMSGCNT 10 //max # of err msg before skip the tlm file
00039 #define NOTSPECIFIED "***NOTSPECIFIED***"
00040 #define ENVFILE "/home/production/cvs/JSOC/proj/lev0/apps/SOURCE_ENV_FOR_HK_DECODE"
00041
00042 extern int decode_next_hk_vcdu(unsigned short *tbuf, CCSDS_Packet_t **hk, unsigned int *Fsn);
00043 extern int write_hk_to_drms();
00044 extern void HMI_compute_exposure_times(DRMS_Record_t *rec, HK_Keyword_t *isp, int flg);
00045 extern int set_HMI_mech_values(DRMS_Record_t *rec);
00046 extern TIME SDO_to_DRMS_time(int sdo_s, int sdo_ss);
00047
00048 char *module_name = "test0";
00049
00050 FILE *h0logfp;
00051 IMG Image, ImageOld;
00052 IMG *Img;
00053 static CCSDS_Packet_t *Hk;
00054 static DRMS_Record_t *rs;
00055 static DRMS_Segment_t *segment;
00056 static DRMS_Array_t *segArray;
00057 static DRMS_RecordSet_t *rset;
00058 static DRMS_Record_t *rs_old, *rsc;
00059 static DRMS_Segment_t *segmentc;
00060 static DRMS_Array_t *cArray, *oldArray;
00061 static char datestr[32];
00062 static struct timeval first[NUMTIMERS], second[NUMTIMERS];
00063
00064 unsigned int fsn = 0;
00065 unsigned int fsnx = 0;
00066 unsigned int fsn_prev = 0;
00067 unsigned int fsn_pre_rexmit = 0;
00068 unsigned int fid = 0;
00069
00070 short *rdat;
00071 long long vcdu_seq_num;
00072 long long vcdu_seq_num_next;
00073 long long total_missing_im_pdu;
00074 unsigned int vcdu_24_cnt, vcdu_24_cnt_next;
00075 int verbose;
00076 int appid;
00077 int hmiaiaflg;
00078 int whk_status;
00079 int total_tlm_vcdu;
00080 int total_missing_vcdu;
00081 int errmsgcnt, fileimgcnt;
00082 int imagecnt = 0;
00083 int tmpcnt = 0;
00084 int callcnt = 0;
00085 int ALRMSEC = 70;
00086 char timetag[32];
00087 char pchan[8];
00088 char rchan[8];
00089 char tlmseriesname[96];
00090 char lev0seriesname[96];
00091 char tlmnamekey[96];
00092 char tlmnamekeyfirst[96];
00093 char *username;
00094 char *tlmdir;
00095 char *outdir;
00096 char *logfile;
00097 char *vc;
00098 struct p_r_chans {
00099 char *pchan;
00100 char *rchan;
00101 int instru;
00102 };
00103 typedef struct p_r_chans P_R_CHANS;
00104
00105 P_R_CHANS p_r_chan_pairs[] = {
00106 {"VC01", "VC09", 1},
00107 {"VC04", "VC12", 1},
00108 {"VC02", "VC10", 0},
00109 {"VC05", "VC13", 0},
00110 {"n/a", "n/a"}
00111 };
00112
00113
00114 ModuleArgs_t module_args[] = {
00115 {ARG_STRING, "vc", NOTSPECIFIED, "Primary virt channel to listen to"},
00116 {ARG_STRING, "indir", NOTSPECIFIED, "directory containing the files to ingest"},
00117 {ARG_STRING, "outdir", NOTSPECIFIED, "directory to move the files to after the ingest"},
00118 {ARG_STRING, "logfile", NOTSPECIFIED, "optional log file name. Will create one if not given"},
00119 {ARG_FLAG, "v", "0", "verbose flag"},
00120 {ARG_FLAG, "h", "0", "help flag"},
00121 {ARG_END}
00122 };
00123
00124 CmdParams_t cmdparams;
00125
00126
00127 char *gettimetag()
00128 {
00129 struct timeval tvalr;
00130 struct tm *t_ptr;
00131
00132 gettimeofday(&tvalr, NULL);
00133 t_ptr = localtime((const time_t *)&tvalr);
00134 sprintf(timetag, "%04d.%02d.%02d.%02d%02d%02d",
00135 (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);
00136 return(timetag);
00137 }
00138
00139
00140 void BeginTimer(int n)
00141 {
00142 gettimeofday (&first[n], NULL);
00143 }
00144
00145 float EndTimer(int n)
00146 {
00147 gettimeofday (&second[n], NULL);
00148 if (first[n].tv_usec > second[n].tv_usec) {
00149 second[n].tv_usec += 1000000;
00150 second[n].tv_sec--;
00151 }
00152 return (float) (second[n].tv_sec-first[n].tv_sec) +
00153 (float) (second[n].tv_usec-first[n].tv_usec)/1000000.0;
00154 }
00155
00156
00157 void abortit(int stat)
00158 {
00159 printf("***Abort in progress ...\n");
00160 printf("**Exit test0 w/ status = %d\n", stat);
00161 exit(stat);
00162 }
00163
00164
00165
00166
00167 void alrm_sig(int sig)
00168 {
00169 signal(SIGALRM, alrm_sig);
00170 printf("alrm_sig: drms_server_end_transaction()\n");
00171 drms_server_end_transaction(drms_env, 0 , 0);
00172 printf("alrm_sig: drms_server_begin_transaction()\n");
00173 drms_server_begin_transaction(drms_env);
00174 }
00175
00176
00177
00178
00179 void do_ingest()
00180 {
00181 DRMS_Record_t *rs_tlm;
00182 int i, j, status;
00183 pid_t pid;
00184 char *args[5];
00185 char path[DRMS_MAXPATHLEN];
00186 char name[128], line[128], tlmfile[128], tlmname[96];
00187 char cmd[128], xxname[128], vername[16];
00188 char *token, *filename;
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201 sprintf(name, "%s", "/dds/stage/VC05_2008_148_15_51_05_00078703ab8_1c298_00.qac");
00202 sprintf(tlmfile, "%s", "/dds/stage/VC05_2008_148_15_51_05_00078703ab8_1c298_00.tlm");
00203 sprintf(tlmname, "%s", "VC05_2008_148_15_51_05_00078703ab8_1c298_00");
00204 sprintf(tlmseriesname, "%s", TLMSERIESNAMEHMI);
00205 for(j=0; j < 10; j++) {
00206 rs_tlm = drms_create_record(drms_env, tlmseriesname,
00207 DRMS_PERMANENT, &status);
00208 if(status) {
00209 printf("***Can't create record for %s\n\n", tlmseriesname);
00210
00211 abortit(3);
00212 }
00213 printf("create_record ok for %d calls\n", ++callcnt);
00214 strcpy((char *)tlmnamekey, (char *)tlmname);
00215 if((status = drms_setkey_string(rs_tlm, "filename", tlmnamekey))) {
00216 printf("**ERROR: drms_setkey_string failed for 'filename'\n");
00217 }
00218 drms_record_directory(rs_tlm, path, 0);
00219 if(!*path) {
00220 printf("***ERROR: No path to segment for %s\n", tlmseriesname);
00221 abortit(3);
00222 }
00223 sprintf(cmd, "/bin/cp %s %s", name, path);
00224 printf("*cp qac to %s\n", path);
00225
00226 if(status = system(cmd)) {
00227 printf("**ERROR: %d on: %s\n", status, cmd);
00228 }
00229
00230
00231
00232
00233
00234
00235
00236
00237 if((status = drms_close_record(rs_tlm, DRMS_INSERT_RECORD))) {
00238 printf("**ERROR: drms_close_record failed for %s\n", tlmseriesname);
00239 }
00240
00241 if(tmpcnt++ >= 2) {
00242 printf("drms_server_end_transaction()\n");
00243 drms_server_end_transaction(drms_env, 0 , 0);
00244 printf("drms_server_begin_transaction()\n");
00245 drms_server_begin_transaction(drms_env);
00246 tmpcnt = 0;
00247 }
00248 }
00249 alarm(3);
00250 printf("sleep(6)\n");
00251 sleep(6);
00252 }
00253
00254
00255 int DoIt(void)
00256 {
00257 signal(SIGALRM, alrm_sig);
00258 while(1) {
00259 do_ingest();
00260
00261
00262
00263
00264
00265
00266 }
00267 }
00268