// @(#) Version 1.0 // @(#) Created 5 Jan 2004 - Dennis Wang #include #include #include #include #include #define FALSE 0 #define TRUE 1 #define CMD_LINE_SIZE 80 #define EUVI 1 #define COR1 2 #define COR2 3 #define HI1 4 #define HI2 5 #define PARSEERR -1 struct cmdtype { bool rts; unsigned int year; unsigned int month; unsigned int daym; unsigned int hour; unsigned int minute; unsigned int second; unsigned int func; //function code 0 = invalid, 1 - n unsigned int nbyte; unsigned int cksum; char fname[13]; //Function Code F unsigned int imgcounter; unsigned int telescope; unsigned int osnum; unsigned int camtbl; unsigned int exptbl; unsigned int iptbl; bool fps; bool sync; unsigned int campaign_set; unsigned int fw1; //Function Code C,E,L,N unsigned int pol1; //Function Code C,E,L,N,S unsigned int expcmd1; //Function Code D,L unsigned int fw2; //Function Code E - Double Exposure unsigned int pol2; //Function Code E,S unsigned int expcmd2; unsigned int gtdata; //Function Code G unsigned int gtdownlink; unsigned int numimg; //Function Code H,S unsigned int cadence; //Function Code H,S unsigned int led; //Function Code L unsigned int npulse; //Function Code L unsigned int pol3,pol4; //Function Code S bool euvidoor; //Function Code 1,2 0=closed 1 =open bool cor1door; //Function Code 3,4 bool cor2door; //Function Code 5,6 } imgdata; int onebyte(char digit,int baseflag) { char numbuff[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; int icount = 0, maxsearch = 10; if(baseflag == 16) maxsearch = 16; if(baseflag == 36) maxsearch = 36; for(icount = 0; icount < maxsearch; icount++) if(numbuff[icount] == digit) return icount; return (PARSEERR); } int twobyte(char digit1,char digit2,int baseflag) { int ten,one; ten = onebyte(digit1,baseflag); one = onebyte(digit2,baseflag); if (ten > PARSEERR && one > PARSEERR) return ((baseflag*ten) + one); return (PARSEERR); } int fourbyte(char digit1,char digit2, char digit3, char digit4, int baseflag) { int thou,ten; thou = twobyte(digit1,digit2,baseflag); ten = twobyte(digit3,digit4,baseflag); if(thou > PARSEERR && ten > PARSEERR) return((baseflag*baseflag*thou) + ten); return (PARSEERR); } int readbyte(char *charptr, unsigned int numbytes, int baseflag) { unsigned int icount = 0; int sum = 0, digit = 0; for(icount = 0; icount < numbytes; icount++) { digit = onebyte( *charptr++, baseflag); if(digit != PARSEERR) sum = baseflag * sum + digit; else return (PARSEERR); } return(sum); } int readwheels(char *ptr, unsigned int telescope,unsigned int *fw, unsigned int *pw) { int filter=0, polar=0, digit1=0, digit2=0; if(telescope == EUVI) { filter = onebyte(*ptr++,10); if (filter > 3) { printf("Read Schedule: Bad FW error"); printf("= %u\n",filter); return(TRUE); } polar = onebyte(*ptr++,10); if (polar > 3) // QS { printf("Read Schedule: Bad QS error"); printf(" = %u\n",polar); return(TRUE); } } else filter = 0; if(telescope == COR1 || telescope == COR2) { digit1 = *ptr++; digit2 = *ptr++; polar = twobyte(digit1,digit2,10); if (polar > 23) { printf("Read Schedule: Bad PW error"); printf("= %u\n",polar); return(TRUE); } } printf("filter = %d polar = %d\n",filter,polar); *fw = filter; *pw = polar; return(FALSE); } int parse_cmd(char *cmdline) { char *ptr; char digit1,digit2,digit3,digit4,digit5; int icount=0,flen = 0,temp = 0; char strvar[80]; //function code char fcode[] = "FIBTCDEHLNS123456GA"; #ifdef IMGCTR unsigned short validnbyte[] = { 28,16,16,16,37,40,39,40,45,37,49,16,16,16,16,16,16,21,27}; #else unsigned short validnbyte[] = { 28,16,16,16,33,36,35,36,41,33,44,16,16,16,16,16,16,21,27}; #endif flen = strlen(fcode); // Temporary variables unsigned int computeck = 0, nrecv = 0; ptr = cmdline; if(*ptr == '#') return(FALSE); //comment line //compute checksum while(isprint(*ptr)) { nrecv++; if(nrecv != 15 && nrecv != 16) computeck = computeck + *ptr; ptr++; } computeck = computeck % 256; ptr = cmdline; //check for RTS if(*ptr == '-') { imgdata.rts = TRUE; imgdata.year = 0; imgdata.month = 0; ptr = ptr + 3; printf("RTS "); } else { imgdata.rts = FALSE; imgdata.year = onebyte( *ptr++,10); digit1 = *ptr++; digit2 = *ptr++; temp = twobyte(digit1,digit2,10); if ( temp == PARSEERR || temp < 1 || temp > 12) { printf("Read Schedule: Bad Month\n"); return(TRUE); } imgdata.month = temp; printf("ATS year=%u month=%02u ",imgdata.year,imgdata.month); } digit1 = *ptr++; digit2 = *ptr++; temp = twobyte(digit1,digit2,10); if ( temp == PARSEERR || temp > 31) { printf("Read Schedule: Bad Day of Month\n"); return(TRUE); } imgdata.daym = temp; digit1 = *ptr++; digit2 = *ptr++; temp = twobyte(digit1,digit2,10); if ( temp == PARSEERR || temp > 23) { printf("Read Schedule: Bad Hour\n"); return(TRUE); } imgdata.hour = temp; digit1 = *ptr++; digit2 = *ptr++; temp = twobyte(digit1,digit2,10); if ( temp == PARSEERR || temp > 59) { printf("Read Schedule: Bad Minute\n"); return(TRUE); } imgdata.minute = temp; digit1 = *ptr++; digit2 = *ptr++; temp = twobyte(digit1,digit2,10); if ( temp == PARSEERR || temp > 59) { printf("Read Schedule: Bad Second\n"); return(TRUE); } imgdata.second = temp; printf("day = %02u hour = %02u minute = %02u second = %02u\n", imgdata.daym,imgdata.hour,imgdata.minute,imgdata.second); imgdata.func = 0; for(icount = 1; icount <= flen; icount++) { if(*ptr == fcode[icount-1]) imgdata.func = icount; } if (imgdata.func == 0) { printf("Read Schedule: Bad Function Code\n"); return(TRUE); } printf("Function %c ",*ptr); ptr++; digit1 = *ptr++; digit2 = *ptr++; imgdata.nbyte = twobyte(digit1,digit2,10); digit1 = *ptr++; digit2 = *ptr++; imgdata.cksum = twobyte(digit1,digit2,16); printf("nbyte = %u cksum = %02X\n",imgdata.nbyte,imgdata.cksum); // verify number of bytes and checksum if(nrecv != imgdata.nbyte) { printf("Read Schedule: Bad number of bytes != Received Bytes"); printf("nrecv = %u nbyte = %u\n",nrecv, imgdata.nbyte); return(TRUE); } if(validnbyte[imgdata.func - 1] != imgdata.nbyte) { printf("Received Bytes != Expected Number of Bytes for Function\n"); printf("nrecv = %u nbyte = %u validnbyte = %u\n", nrecv, imgdata.nbyte, validnbyte[imgdata.func - 1]); return(TRUE); } if(computeck != imgdata.cksum) { printf("Read Schedule: Bad Checksum\n"); printf("Computed cksum %x expected cksum %x\n",computeck,imgdata.cksum); return(TRUE); } // Image Taking if(imgdata.func >= 5 && imgdata.func <= 11) { #ifdef IMGCTR digit1 = *ptr++; digit2 = *ptr++; digit3 = *ptr++; digit4 = *ptr++; temp = fourbyte(digit1,digit2,digit3,digit4,10); if (temp == PARSEERR) { printf("Read Schedule: Bad IMAGE Counter\n"); return(TRUE); } imgdata.imgcounter = (unsigned int) temp; #else imgdata.imgcounter = 0; #endif temp = onebyte(*ptr++, 10); if (temp < 1 || temp > 5) { printf("Read Schedule: Bad Telescope\n"); return(TRUE); } imgdata.telescope = (unsigned int) temp; digit1 = *ptr++; digit2 = *ptr++; digit3 = *ptr++; digit4 = *ptr++; temp = fourbyte(digit1,digit2,digit3,digit4,10); if (temp == PARSEERR) { printf("Read Schedule: Bad OS NUM\n"); return(TRUE); } imgdata.osnum = (unsigned int) temp; temp = onebyte(*ptr++,10); if (temp == PARSEERR || temp > 6) { printf("Read Schedule: Bad Camera Setup Table\n"); printf("camtbl = %u\n",temp); return(TRUE); } imgdata.camtbl = (unsigned int) temp; if(imgdata.func != 6 && imgdata.func != 9) { temp = onebyte(*ptr,10); if (temp == PARSEERR || temp > 6) { printf("Read Schedule: Bad Exposure Setup Table\n"); printf("exptbl = %u\n",temp); return(TRUE); } imgdata.exptbl = (unsigned int) temp; } else imgdata.exptbl = 0; ptr++; digit1 = *ptr++; digit2 = *ptr++; temp = twobyte(digit1,digit2,10); if (temp == PARSEERR || temp > 99) { printf("Read Schedule: Bad IP Setup Table\n"); printf("iptbl = %02u\n",imgdata.iptbl); return(TRUE); } imgdata.iptbl = (unsigned int) temp; temp = onebyte(*ptr++,10); if (temp != TRUE && temp != FALSE) { printf("Read Schedule: Bad FPS\n"); printf("fps %u\n",temp); return(TRUE); } imgdata.fps = temp; temp = onebyte(*ptr++,10); if (temp != TRUE && temp != FALSE) { printf("Read Schedule: Bad Sync\n"); printf("sync %u\n",temp); return(TRUE); } imgdata.sync = temp; digit1 = *ptr++; digit2 = *ptr++; digit3 = *ptr++; digit4 = *ptr++; temp = fourbyte(digit1,digit2,digit3,digit4,10); if (temp == PARSEERR) { printf("Read Schedule: Bad Campaign_set\n"); printf("campaign_set %u\n",temp); return(TRUE); } imgdata.campaign_set = temp; switch(imgdata.telescope) { case 1: strcpy(strvar,"EUVI"); break; case 2: strcpy(strvar,"COR1"); break; case 3: strcpy(strvar,"COR2"); break; case 4: strcpy(strvar,"HI-1"); break; case 5: strcpy(strvar,"HI-2"); break; default: strcpy(strvar,"BAD"); break; } printf("telesc = %u (%s) osnum = %04u\ncamtbl = %u ", imgdata.telescope,strvar,imgdata.osnum,imgdata.camtbl); printf("exptbl = %u iptbl = %02u fps = %u sync = %u campaign_set = %04u\n", imgdata.exptbl, imgdata.iptbl,imgdata.fps,imgdata.sync, imgdata.campaign_set); } //Last part switch(imgdata.func) { case 0: break; case 1: //Function Code F strncpy(imgdata.fname,ptr,12); printf("%s\n",imgdata.fname); break; case 2: //Function Code I,B,T case 3: case 4: break; case 5: //Function Code C if(readwheels(ptr,imgdata.telescope,&imgdata.fw1, &imgdata.pol1) == TRUE) { printf("Read Schedule: Func C error\n"); return(TRUE); } ptr += 2; break; case 6: //Function Code D temp = readbyte(ptr,5,10); if(temp != PARSEERR) imgdata.expcmd1 = (unsigned int) temp; printf(" expcmd1 = %u\n", imgdata.expcmd1); break; case 7: //Function Code E if(readwheels(ptr,imgdata.telescope,&imgdata.fw1, &imgdata.pol1) == TRUE) { printf("Read Schedule: Func E Error\n"); return(TRUE); } ptr += 2; if(readwheels(ptr,imgdata.telescope,&imgdata.fw2, &imgdata.pol2) == TRUE) { printf("Read Schedule: Func E error\n"); return(TRUE); } ptr += 2; break; case 8: //Function Code H if(imgdata.telescope == HI1 || imgdata.telescope == HI2) { temp = readbyte(ptr,2,10); if(temp == PARSEERR) { printf("Read Schedule: Func H Nimage\n"); return(TRUE); } imgdata.numimg = temp; ptr += 2; temp = readbyte(ptr,3,10); if(temp == PARSEERR) { printf("Read Schedule: Func H Cadence\n"); return(TRUE); } imgdata.cadence = temp; ptr += 3; printf(" numimg= %02u cadence = %03u\n", imgdata.numimg, imgdata.cadence); } else { printf("Read Schedule: SCIP Scheduled using Func H\n"); return(TRUE); } break; case 9: //Function Code L if(readwheels(ptr,imgdata.telescope,&imgdata.fw1, &imgdata.pol1) == TRUE) { printf("Read Schedule: Func L Wheel\n"); return(TRUE); } ptr += 2; temp = onebyte(*ptr++,10); if(temp == PARSEERR) { printf("Read Schedule: Func L LED\n"); return(TRUE); } imgdata.led = temp; if( imgdata.led > 3 || imgdata.led < 1) printf("Read Schedule: Bad LED %u",temp); temp = readbyte(ptr,7,10); if (temp == PARSEERR) { printf("Read Schedule: Func L NPULSE\n"); return(TRUE); } imgdata.npulse = temp; printf(" led=%d npulse = %u\n",imgdata.led, imgdata.npulse); break; case 10: //Function Code N if(readwheels(ptr,imgdata.telescope,&imgdata.fw1, &imgdata.pol1) == TRUE) { printf("Read Schedule: Func L Wheel\n"); return(TRUE); } break; case 11: //Function Code S if( imgdata.telescope == HI1 || imgdata.telescope == HI2) { printf("Read Schedule: HI telescope scheduled using Func S"); return(TRUE); } if (imgdata.telescope == EUVI) { temp = onebyte(*ptr++,10); if( temp == PARSEERR || temp > 4) { printf("Read Schedule: Func S FW error\n"); return(TRUE); } imgdata.fw1 = temp; } else ptr++; temp = onebyte(*ptr++,10); if(temp == PARSEERR || temp > 4) { printf("Read Schedule: Func S Nimage error %u\n",temp); return(TRUE); } imgdata.numimg = temp; temp = readbyte(ptr,3,10); if(temp == PARSEERR) { printf("Read Schedule: Func S Cadence error\n"); return(TRUE); } imgdata.cadence = temp; ptr += 3; for(icount = 0; icount < imgdata.numimg; icount++) { temp = readbyte(ptr,2,10); if(temp == PARSEERR || temp > 23) { printf("Read Schedule: Func S PW %u\n",temp); return(TRUE); } if(icount == 0) imgdata.pol1 = temp; if(icount == 1) imgdata.pol2 = temp; if(icount == 2) imgdata.pol3 = temp; if(icount == 3) imgdata.pol4 = temp; ptr += 2; } printf("fw1=%u numimg=%02u cadence = %03u pol1= %02u pol2= %02u pol3=%02u pol4= %02u\n", imgdata.fw1, imgdata.numimg, imgdata.cadence, imgdata.pol1, imgdata.pol2, imgdata.pol3, imgdata.pol4); break; case 12: //Function Code 1 imgdata.euvidoor = TRUE; printf("EUVI Door Open\n"); break; case 13: //Function Code 2 imgdata.euvidoor = FALSE; printf("EUVI Door Close\n"); break; case 14: //Function Code 3 imgdata.cor1door = TRUE; printf("COR1 Door Open\n"); break; case 15: //Function Code 4 imgdata.cor1door = FALSE; printf("COR1 Door Close\n"); break; case 16: //Function Code 5 imgdata.cor2door = TRUE; printf("COR2 Door Open\n"); break; case 17: //Function Code 6 imgdata.cor2door = FALSE; printf("COR2 Door Close\n"); break; case 18: //Function Code G temp = readbyte( ptr, 4, 10); if(temp == PARSEERR) { printf("Read Schedule: GT "); return(TRUE); } imgdata.gtdata = temp; ptr += 4; temp = onebyte(*ptr++,10); imgdata.gtdownlink = temp; printf("GT seconds = %u downlink = %u\n",imgdata.gtdata,imgdata.gtdownlink); break; case 19: //Function Code A strncpy(imgdata.fname,ptr,11); printf("%s\n",imgdata.fname); break; } return(FALSE); } int read_file( char *filename) { FILE *infd; char cmdline[CMD_LINE_SIZE]; char comment; int nread = 0; infd = fopen( filename,"r"); if (infd == NULL) { perror("File Open Error"); return(1); } // parse while((nread = fscanf(infd,"%s",cmdline)) != EOF) { if(cmdline[0] == '#') { printf("%s",cmdline); while( (comment = fgetc(infd)) != '\n') printf("%c",comment); printf("\n"); } else { printf("%s\n",cmdline); parse_cmd(cmdline); fscanf(infd,"\n",cmdline); printf("\n"); } } fclose(infd); return(0); } int main(int argc, char **argv) { int icount = 0; if (argc <= 1) { printf("Usage: $0 filename\n",argv[0]); return(1); } else { for (icount = 1 ; icount < argc; icount++) { printf("Reading file %d %s\n",icount, argv[icount]); read_file(argv[icount]); } } return(0); }