#include /* module control9 */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include union REGS inregs,outregs; /*mods: 22jul03 pjp002 ..increased magnet startup 200 (10 secs) to 900 (45 secs) 15oct03 pjp003 .. increased magnet startup 200 (10 secs) to 900 (45 secs) */ /*--------------------------------------------------------------------------- meter signal names V1 MAGNET VOLTAGE 0 V2 MAGNET VOLTAGE 1 BEAM VOLTAGE 2 V1 MAGNET CURRENT 3 V2 MAGNET CURRENT 4 BODY CURRENT 5 V1 FILAMENT VOLTAGE 6 V2 FILAMENT VOLTAGE 7 V1 FILAMENT CURRENT 8 V2 FILAMENT CURRENT 9 V1 COLLECTOR CURRENT 10 V2 COLLECTOR CURRENT 11 V1 VACION CURRENT 12 V2 VACION CURRENT 13 SPARE 14 SPARE 15 WASTER FWD POWER 16 V1 FWD POWER 17 V1 RFL POWER 18 V2 FWD POWER 19 V2 RFL POWER 20 WASTER RFL POWER 21 TURNSTILE DL POWER 22 ANTENNA FWD POWER 23 ANTENNA RFL POWER 24 V1 RF DRIVE POWER 25 V2 RF DRIVE POWER 26 FLOW RATE 27 DELTA TEMP 28 KLY2 COLLECTOR FLOW 29 SPARE 30 SPARE 31 --------------------------------------------------------------------------- calculation names CALORIMETRIC POWER 0 KLYSTRON 1 VSWR 1 KLYSTRON 2 VSWR 2 WASTER VSWR 3 ANTENNA VSWR 4 TOTAL DRIVE POWER 5 SPARE 6 TOTAL BEAM CURRENT 7 TOTAL KLY POWER DISS 8 AVG MAGNET VOLTAGE 9 AVG MAGNET CURRENT 10 AVG FILAMENT VOLTAGE 11 AVG FILAMENT CURRENT 12 --------------------------------------------------------------------------- TTI modules 1 DOME STATUS 2 DOME STATUS 3 DOME STATUS 4 DOME STATUS 5 DOME STATUS 6 DOME DAC 7 DOME METERING 8 DOME METERING 9 DOME CONTROL 10 DOME CONTROL 11 HVPS DAC 12 HVPS STATUS 13 HVPS CONTROL A9 outputs 1 antenna/dl select (high/low) 2 cooling on/off 3 test A0 4 test A1 5 test A2 6 test T0 7 test T1 8 test T2 9 test strobe 10 hvps over-current sum 11 hvps crowbar ready status 12 kly 1 arc test 13 waveguide switch combiner/dl select 14 hvps contactor closed 15 kly 2 arc test 16 rf drive on A10 outputs 1 crowbar fired 2 reset 3 alarm off/on 4 spare 5 hvps interlock sum 6 filament timer 7 keep-alive 8 filament contactor closed 9 kly 1 magnet contactor closed 10 kly 2 magnet contactor closed 11 spare 12 spare 13 spare 14 spare 15 spare 16 spare --------------------------------------------------------------------------- counter[47] channel of presets (1 to 10) counter[27] prepow[1-10] combined power output dac[0] counter[43] prebeam[1-10] beam voltage dac[1] counter[41] mag 1 current dac[2] counter[42] mag 2 current dac[3] counter[35] predriv[1-10] drive level dac[4] counter[36] prebal[1-10] drive balance dac[5] counter[37] prepha[1-10] drive phase dac[6] counter[38] preoff[1-10] feed-fwd offset dac[7] counter[39] pregain[1-10] feed-fwd gain */ /*****************************************************************************/ power(void) /* adjust RF power output */ { int fail,uA,j,jj,olraw,min=999,i=20,kw,diff,offset,gain; char string[40]; if(inlog()||inhist()||insimu()) goto abort; if(fail=status[45]&0x40) /* illegal key position */ { warn("ILLEGAL KEY POSITION"); goto abort; } if(parse[4]==CR) kw=counter[27]; /* use previous value */ else { if(arg(1,1200)) goto abort; kw=atoi(&parse[4]); if(kw<11) { strcpy(string,"PRESET POWER "); strcat(string,&parse[4]); prompt(string); setpower(kw); kw=counter[27]; goto abort; } else if(status[19]&0x02) /* hv on? */ { for(j=0;j<=9;j++) /* find closest pre-set */ { diff=abs(kw-prepow[j]); if(diffraw[2]+8)||(olraw=0) uA=dac[0]*1.01; /* increase */ else uA=dac[0]/1.01; /* decrease */ dac[0]=uA; /* set dac variable */ counter[43]=uA; /* store value */ fail=ttd(11,4,uA); /* adjust hv */ olraw=raw[2]; tenths(7); average(); while((olraw>raw[2]+8)||(olraw=20000) /* limit (RS) */ uA=20000; counter[36]=uA; dac[4]=uA; fail=ttd(6,3,uA); } abort: clkey(); return(fail); } /*****************************************************************************/ phasebal(n) { char string[40]; char *echo[]= { "PHASE BALANCE LOWER ", "PHASE BALANCE RAISE ", 0 }; int fail=0,uA; double mul; if(inlog()||inhist()||insimu()) goto abort; if(fail=status[45]&0x40) /* illegal key position */ { warn("ILLEGAL KEY POSITION"); goto abort; } if(!((status[3]&0x10)&&(status[4]&0x40))) { warn("CAN'T ADJUST PHASE BALANCE WHEN RF OFF"); fail=1; goto abort; } strcpy(string,echo[n]); strcat(string,itoa(counter[53],numb,10)); prompt(string); if(remo) string1(parse); else { mul=1+(double)counter[53]/100; if(n) uA=dac[5]*mul; /* raise */ else uA=dac[5]/mul; /* lower */ if(uA>=20000) /* limit (RS) */ uA=20000; counter[37]=uA; dac[5]=uA; fail=ttd(6,4,uA); } abort: clkey(); return(fail); } /*****************************************************************************/ offset(n) /* adjust feed-forward offset */ { char string[40]; char *echo[]= { "FEED-FORWARD OFFSET LOWER ", "FEED-FORWARD OFFSET RAISE ", 0 }; int fail=0,uA; double mul; if(inlog()||inhist()||insimu()) goto abort; if(fail=status[45]&0x40) /* illegal key position */ { warn("ILLEGAL KEY POSITION"); goto abort; } if(!((status[3]&0x10)&&(status[4]&0x40))) { warn("CAN'T ADJUST OFFSET WHEN RF OFF"); fail=1; goto abort; } strcpy(string,echo[n]); strcat(string,itoa(counter[53],numb,10)); prompt(string); if(remo) string1(parse); else { mul=1+(double)counter[53]/100; if(n) uA=dac[6]*mul; /* raise */ else uA=dac[6]/mul; /* lower */ counter[38]=uA; fail=ttd(6,5,uA); } abort: clkey(); return(fail); } /*****************************************************************************/ gain(n) /* adjust feed-forward gain */ { char string[40]; char *echo[]= { "FEED-FORWARD GAIN LOWER ", "FEED-FORWARD GAIN RAISE ", 0 }; int fail=0,uA; double mul; if(inlog()||inhist()||insimu()) goto abort; if(fail=status[45]&0x40) /* illegal key position */ { warn("ILLEGAL KEY POSITION"); goto abort; } if(!((status[3]&0x10)&&(status[4]&0x40))) { warn("CAN'T ADJUST GAIN WHEN RF OFF"); fail=1; goto abort; } strcpy(string,echo[n]); strcat(string,itoa(counter[53],numb,10)); prompt(string); if(remo) string1(parse); else { mul=1+(double)counter[53]/100; if(n) uA=dac[7]*mul; /* raise */ else uA=dac[7]/mul; /* lower */ counter[39]=uA; fail=ttd(6,6,uA); } abort: clkey(); return(fail); } /*****************************************************************************/ filament(n) { char string[40]; char *echo[]= { "FILAMENT STOP", "FILAMENT START", "FILAMENT LOWER ", "FILAMENT RAISE ", 0 }; int fail=0; if(veriflag||inlog()||inhist()||insimu()) goto abort; if((comseq==1)&&(trynum==3)) { trynum=0; comseq=0; warn("COMMAND FAIL"); status[36]|=0x02; goto abort; } else if(comseq==1) trynum++; if(fail=status[45]&0x40) /* illegal key position */ { warn("ILLEGAL KEY POSITION"); goto abort; } strcpy(string,echo[n]); if(n>1) strcat(string,itoa(counter[53],numb,10)); prompt(string); if(remo) string1(parse); else switch(n) { case 0: tto(13,11,0); /* stop */ tto(10,6,0); /* dome hv disable */ veriflag=2; anordig=0; statchk=0x00; statmask=0x01; statnum=20; chkcount=10; rflag=1; /* prevent reset */ break; case 1: if(!comseq) { trynum=1; comseq=1; } counter[52]=0; if(!(!(status[14]&0x02) &&(status[5]&0x08))) /* socket cooling */ { cooling(1); goto abort; } tto(13,11,1); /* start */ if(comseq==1) comseq=0; veriflag=2; anordig=0; statchk=0x10; statmask=0x10; statnum=20; chkcount=10; break; case 2: if(!(status[20]&0x10)) /* fil contactor (RS) */ goto abort; if(status[8]&0x01) /*kly 1 sel (RS) */ { metnum=6; oldval=raw[6]; } else { metnum=7; oldval=raw[7]; } ttm(13,8,1,counter[53]); /* lower */ anordig=1; chkcount=1; veriflag=2; updn=0; break; case 3: if(!(status[20]&0x10)) /* fil contactor (RS) */ goto abort; if(status[8]&0x01) /*kly 1 sel (RS) */ { metnum=6; oldval=raw[6]; } else { metnum=7; oldval=raw[7]; } ttm(13,7,1,counter[53]); /* raise */ anordig=1; chkcount=1; veriflag=2; updn=1; break; } abort: clkey(); return(fail); } /*****************************************************************************/ filramp(void) /* ramp up filament voltage and current */ { int fail; if(fail=status[45]&0x40) /* illegal key position */ goto abort; if((status[37]&0x80) /* TTI sum */ ||!(status[5]&0x08)) /* socket cooling (RS) */ goto abort; if(status[20]&0x10) /* fil contactor (RS) */ { if((raw[8]<20250) &&(raw[9]<20250) /* 20 amps (RS)*/ &&(raw[6]<16420) &&(raw[7]<16420) /* 10.5 volts (RS)*/ &&(counter[40]>0)) /* fil timer (RS) */ { filrcount=10; /* raise filament (RS) */ tto(13,7,1); } else if((((status[8]&0x01)&&!(status[6]&0x40) &&(avmet[6]>100)) ||((status[8]&0x02)&&!(status[6]&0x80) &&(avmet[7]>100)))&&!(dogs&0x01)) /* special fault sum */ reset2(); } abort: return(fail); } /*****************************************************************************/ driver(n) { char string[40]; char *echo[]= { "DRIVER STOP", "DRIVER START", "DRIVER LOWER ", "DRIVER RAISE ", 0 }; int fail=0,uA; double mul; if(veriflag||inlog()||inhist()||insimu()) goto abort; if(fail=status[45]&0x40) /* illegal key position */ { warn("ILLEGAL KEY POSITION"); goto abort; } strcpy(string,echo[n]); if(n>1) strcat(string,itoa(counter[53],numb,10)); prompt(string); if(remo) string1(parse); else { mul=1+(double)counter[53]/100; switch(n) { case 0: tto(9,16,0); /* stop */ veriflag=2; anordig=0; statnum=3; statmask=0x10; statchk=0x00; chkcount=2; break; case 1: tto(9,16,1); /* start */ veriflag=2; anordig=0; statnum=3; statmask=0x10; statchk=0x10; statnum2=4; statmask2=0x40; statchk2=0x40; chkcount=2; break; case 2: uA=dac[3]*mul; /* lower */ counter[35]=uA; veriflag=2; anordig=1; updn=0; chkcount=20; metnum=25; oldval=raw[25]; fail=ttd(6,2,uA); break; case 3: uA=dac[3]/mul; /* raise */ counter[35]=uA; veriflag=2; anordig=1; updn=1; chkcount=20; metnum=25; oldval=raw[25]; fail=ttd(6,2,uA); break; } } abort: clkey(); return(fail); } /*****************************************************************************/ highvolt(n) /* beam voltage */ { char string[40]; char *echo[]= { "HIGH VOLTAGE STOP", "HIGH VOLTAGE START", "HIGH VOLTAGE LOWER ", "HIGH VOLTAGE RAISE ", 0 }; int fail=0,uA,kv; double mul; if(!n) goto doit; if(!(comseq==0||comseq==10)||veriflag||inlog()||inhist()||insimu()) goto abort; if(fail=status[45]&0x40) /* illegal key position */ { warn("ILLEGAL KEY POSITION"); goto abort; } doit: strcpy(string,echo[n]); if(n>1) strcat(string,itoa(counter[53],numb,10)); prompt(string); if(remo) string1(parse); else { mul=1+(double)counter[53]/100; switch(n) { case 0: tto(13,12,0); /* stop */ veriflag=2; anordig=0; statchk=0x00; statmask=0x02; statnum=19; chkcount=12; rflag=1; /* prevent reset */ break; case 1: if(counter[73]) { warn("CROWBAR RECOVERY"); break; } if(status[37]&0x80) { warn("TTI FAILURE"); break; } if((!(status[38]&0x08) /* autotest passed */ ||(status[38]&0x80))) /* test fail over-ride */ { tto(13,12,1); /* start */ veriflag=2; anordig=0; statchk=0x02; statmask=0x02; statnum=19; chkcount=27; } else warn("AUTOTEST LOCK-OUT"); break; case 2: uA=dac[0]/mul; /* lower */ counter[43]=uA; veriflag=2; anordig=1; updn=0; chkcount=20; metnum=2; oldval=raw[2]; fail=ttd(11,4,uA); if(!fail) { kv=avmet[2]; setfeeds(kv); } break; case 3: uA=dac[0]*mul; /* raise */ counter[43]=uA; veriflag=2; anordig=1; updn=1; chkcount=20; metnum=2; oldval=raw[2]; fail=ttd(11,4,uA); if(!fail) { kv=avmet[2]; setfeeds(kv); } break; } } abort: clkey(); return(fail); } /*****************************************************************************/ magnet1(n) /* magnet 1 voltage */ { char string[40]; char *echo[]= { "MAGNET 1 VOLTAGE STOP", "MAGNET 1 VOLTAGE START", "MAGNET 1 CURRENT LOWER ", "MAGNET 1 CURRENT RAISE ", 0 }; int fail=0,uA; double mul; if(veriflag||inlog()||inhist()||insimu()) goto abort; if(comseq==2) /* (RS) */ if(trynum++==3) /* (RS) */ { /* (RS) */ trynum=0; /* (RS) */ comseq=0; /* (RS) */ warn("COMMAND FAIL"); /* (RS) */ status[36]|=0x02; /* (RS) */ goto abort; /* (RS) */ } /* (RS) */ if(fail=status[45]&0x40) /* illegal key position */ { warn("ILLEGAL KEY POSITION"); goto abort; } strcpy(string,echo[n]); if(n>1) { strcat(string,itoa(counter[53],numb,10)); if(!(status[20]&0x20)) { warn("CANNOT CHANGE MAGNET SETTINGS WHEN OFF"); goto abort; } } prompt(string); if(remo) string1(parse); else { mul=1+(double)counter[53]/100; switch(n) { case 0: tto(13,9,0); /* stop */ veriflag=2; /* (RS) */ anordig=0; /* (RS) */ statchk=0x00; /* (RS) */ statmask=0x20; /* (RS) */ statnum=20; /* (RS) */ chkcount=10; /* (RS) */ rflag=1; /* prevent reset */ break; case 1: if(!comseq) /* (RS) */ { /* (RS) */ trynum=1; /* (RS) */ comseq=2; /* (RS) */ } /* (RS) */ counter[52]=0; if(!(!(status[13]&0x08) &&(status[5]&0x40))) /* magnet 1 cooling */ { /* (RS) */ cooling(1); /* (RS) */ goto abort; /* (RS) */ } /* (RS) */ if(comseq==2) /* (RS) */ comseq=0; /* (RS) */ tto(13,9,1); /* start */ veriflag=2; /* (RS) */ anordig=0; /* (RS) */ statchk=0x20; /* (RS) */ statmask=0x20; /* (RS) */ statnum=20; /* (RS) */ /* chkcount=200;*/ /* (RS) */ chkcount=900; /* pjp003*/ break; case 2: if(!(status[20]&0x20)) /* mag1 on (RS) */ goto abort; uA=dac[1]/mul; /* lower */ counter[41]=uA; veriflag=2; /* (RS) */ updn=0; /* (RS) */ anordig=1; /* (RS) */ chkcount=10; /* (RS) */ metnum=3; /* (RS) */ oldval=raw[3]; /* (RS) */ fail=ttd(11,2,uA); break; case 3: if(!(status[20]&0x20)) /* mag1 on (RS) */ goto abort; uA=dac[1]*mul; /* raise */ counter[41]=uA; veriflag=2; /* (RS) */ updn=1; /* (RS) */ anordig=1; /* (RS) */ chkcount=10; /* (RS) */ metnum=3; /* (RS) */ oldval=raw[3]; /* (RS) */ fail=ttd(11,2,uA); break; } } abort: clkey(); return(fail); } /*****************************************************************************/ magnet2(n) /* magnet 2 voltage */ { char string[40]; char *echo[]= { "MAGNET 2 VOLTAGE STOP", "MAGNET 2 VOLTAGE START", "MAGNET 2 CURRENT LOWER ", "MAGNET 2 CURRENT RAISE ", 0 }; int fail=0,uA; double mul; if(veriflag||inlog()||inhist()||insimu()) goto abort; if(comseq==3) /* (RS) */ if(trynum++==3) /* (RS) */ { /* (RS) */ trynum=0; /* (RS) */ comseq=0; /* (RS) */ warn("COMMAND FAIL"); /* (RS) */ status[36]|=0x02; /* (RS) */ goto abort; /* (RS) */ } /* (RS) */ if(fail=status[45]&0x40) /* illegal key position */ { warn("ILLEGAL KEY POSITION"); goto abort; } strcpy(string,echo[n]); if(n>1) { strcat(string,itoa(counter[53],numb,10)); if(!(status[20]&0x40)) { warn("CANNOT CHANGE MAGNET SETTINGS WHEN OFF"); goto abort; } } prompt(string); if(remo) string1(parse); else { mul=1+(double)counter[53]/100; switch(n) { case 0: tto(13,10,0); /* stop */ veriflag=2; /* (RS) */ anordig=0; /* (RS) */ statchk=0x00; /* (RS) */ statmask=0x40; /* (RS) */ statnum=20; /* (RS) */ chkcount=10; /* (RS) */ rflag=1; /* prevent reset */ break; case 1: if(!comseq) /* (RS) */ { /* (RS) */ trynum=1; /* (RS) */ comseq=3; /* (RS) */ } /* (RS) */ counter[52]=0; if(!(!(status[13]&0x10) &&(status[5]&0x80))) /* magnet 2 cooling */ { /* (RS) */ cooling(1); /* (RS) */ goto abort; /* (RS) */ } /* (RS) */ if(comseq==3) /* (RS) */ comseq=0; /* (RS) */ tto(13,10,1); /* start */ veriflag=2; /* (RS) */ anordig=0; /* (RS) */ statchk=0x40; /* (RS) */ statmask=0x40; /* (RS) */ statnum=20; /* (RS) */ /* chkcount=200; */ /* (RS) */ chkcount=900; /* pjp002 22jul03*/ break; case 2: if(!(status[20]&0x40)) /* mag2 on (RS) */ goto abort; uA=dac[2]/mul; /* lower */ counter[42]=uA; veriflag=2; /* (RS) */ updn=0; /* (RS) */ anordig=1; /* (RS) */ chkcount=10; /* (RS) */ metnum=4; /* (RS) */ oldval=raw[4]; /* (RS) */ fail=ttd(11,3,uA); break; case 3: if(!(status[20]&0x40)) /* mag2 on (RS) */ goto abort; uA=dac[2]*mul; /* raise */ counter[42]=uA; veriflag=2; /* (RS) */ updn=1; /* (RS) */ anordig=1; /* (RS) */ chkcount=10; /* (RS) */ metnum=4; /* (RS) */ oldval=raw[4]; /* (RS) */ fail=ttd(11,3,uA); break; } } abort: clkey(); return(fail); } /*****************************************************************************/ metprint(void) /* print meter readings */ { int i=0; double expon; int dec[39]= { 0,0,1,1,1,0,1, 1,1,1,1,1,2,2, 0,0,0,0,2,0,2, 1,1,0,1,2,2,0, 2,0,0,2,2,2,2, 1,1,1,0 }; char string1[80]; char *unit[]= { "VOLTS","VOLTS","KV","AMPS","AMPS","mA", "VOLTS","VOLTS","AMPS","AMPS","AMPS","AMPS", "uA","uA"," "," ","KW","KW","KW","KW", "KW","KW","KW","KW","KW","WATTS","WATTS", "GPM","DEG C","GPM","KW","VSWR","VSWR", "VSWR","VSWR"," "," ","AMPS","KW",0 }; strcpy(string1,"METER READINGS"); fprintf(stdprn,"%47s %13s\r\n",string1,dayt); fprintf(stdprn,"%61s\r\n",tyme); fprintf(stdprn,"\r\n"); for(i=0;i<=38;i++) { if(i==14||i==15||i==35||i==36); else if(i==12) { if(avmet[12]>0) expon=exp((double)EXP*((double)(avmet[12])/100)); else expon=0; itoa((int)expon,numb,10); addec(dec[i]); strcpy(string1,numb); fprintf(stdprn,"%27s %8s %6s\r\n",metlist[i],string1,unit[i]); } else if(i==13) { if(avmet[13]>0) expon=exp((double)EXP*((double)(avmet[13])/100)); else expon=0; itoa((int)expon,numb,10); addec(dec[i]); strcpy(string1,numb); fprintf(stdprn,"%27s %8s %6s\r\n",metlist[i],string1,unit[i]); } else if(i>29) { ltoa(calc[i-30],numb,10); addec(dec[i]); strcpy(string1,numb); fprintf(stdprn,"%27s %8s %6s\r\n",calclist[i-30],string1,unit[i]); } else { itoa(avmet[i],numb,10); addec(dec[i]); strcpy(string1,numb); fprintf(stdprn,"%27s %8s %6s\r\n",metlist[i],string1,unit[i]); } } fprintf(stdprn,"\f"); clkey(); } /*****************************************************************************/ void hottest(void) /* test the crowbar with high voltage */ { int fail=0,uA,kv; double mul; if(veriflag||inlog()||inhist()||insimu()) goto abort; if(comseq==10) { if(trynum++==5) { trynum=0; comseq=0; warn("HOT TEST FAIL"); status[36]|=0x02; goto abort; } } else { comseq=10; trynum=0; prompt("HOT CROWBAR TEST SEQUENCE STARTED"); pause(1); } if(remo) string1(parse); else { if(!counter[79]) { comseq=0; trynum=0; goto abort; } if(!(status[7]&0x10)) /* high voltage on? */ { highvolt(1); /* turn on high voltage */ goto abort; } else if(meter[2]>485) /* is hv too high? */ { prompt("LOWERING THE BEAM VOLTAGE"); veriflag=2; anordig=1; updn=0; chkcount=100; metnum=2; oldval=raw[2]; counter[28]=43; adjhv(43); /* set the beam voltage */ goto abort; } else if(meter[2]<430) /* is hv too low? */ { prompt("RAISING THE BEAM VOLTAGE"); veriflag=2; anordig=1; updn=1; chkcount=100; metnum=2; oldval=raw[2]; counter[28]=45; adjhv(45); /* set the beam voltage */ goto abort; } if(!crowbar()) { prompt("HOT TEST PASSED"); pause(1); counter[79]=0; tto(13,12,0); /* turn off hv request */ reset2(); } } comseq=0; trynum=0; abort: clkey(); } /*****************************************************************************/ reset(void) /* send reset command to control circuit, etc */ { int i,fail,k,x1,y1,fault,hack=0; if(inlog()||inhist()||insimu()) goto abort; if(fail=status[45]&0x40) /* illegal key position */ { warn("ILLEGAL KEY POSITION"); goto abort; } if(remo) string1(parse); else { fault=(status[21]&0x20) /* hvps contactor fault */ ||(status[20]&0x01); /* hvps breaker fault */ ttm(10,2,0,1); /* reset dome control ckt */ oldscrn=0; /* force a refresh (RS) */ if(fault) { boxit3("OVER-RIDE HVPS CONTACTOR/BREAKER FAULT?"); loop: while(!kbhit()) { odapc(); if(click()==1) { x1=outregs.x.cx; y1=479-outregs.x.dx; if(y1>140||y1<120) goto loop; if(x1>220&&x1<240) { k='Y'; goto skip; } if(x1>400&&x1<420) { k='N'; goto skip; } } } k=caps(); skip: if(k=='Y') { boxit("ENTER CIPHER"); for(i=0;i<=3;i++) { k=caps(); if(k!=codec[i]) hack=1; } if(hack) status[46]|=0x02; else status[46]|=0x04; /* over-ride */ } else goto bypass_hvps; /* (RS) */ } if(!hack) ttm(13,5,0,1); /* reset hvps control ckt */ } bypass_hvps: rs232res(0); /* reset COM1, COM2, COM3 */ if(!hack) status[46]&=0xFD; /* reset hacker warn */ if(!fault) status[46]&=0xFB; /* reset over-ride warn */ status[46]&=0x5F; /* reset out-of-paper, DOS err */ status[38]&=0xEE; /* reset logs almost full, keyboard time-out */ status[37]&=0x1F; /* reset summaries */ status[36]&=0xDC; /* reset logs full, cmd fail */ status[35]&=0xF0; /* reset pass & COM fail */ status[29]=0; /* reset TTI fails */ status[28]=0; for(i=0;i<13;i++) counter[60+i]=0; /* reset TTI time-out counters */ status[27]&=0xF7; /* reset xoff time-out */ prompt("RESET INDICATORS & FAULT FLAGS"); abort: clkey(); return(fail); } /*****************************************************************************/ reset2(void) /* send reset command to control circuits (RS) */ { int fault=0; if(logno||histno||insimu()) goto abort; fault=(status[21]&0x20) /* hvps contactor fault */ ||(status[20]&0x01); /* hvps breaker fault */ ttm(10,2,0,1); /* reset dome control ckt */ if(!fault) ttm(13,5,0,1); /* reset hvps control ckt */ abort: return(fault); } /*****************************************************************************/ void seqdecode(void) /* decode sequence of commands */ { int bit; if(veriflag||!comseq||inlog()||inhist()||insimu()) goto end; switch(comseq) { case 1: /* filament on */ filament(1); break; case 2: /* magnet 1 on */ magnet1(1); break; case 3: /* magnet 2 on */ magnet2(1); break; case 4: /* standby */ standby(); break; case 5: /* cooling off */ cooling(0); break; case 6: /* both magnets on */ if(trynum++>4) { trynum=0; comseq=0; warn("MAGS COMMAND FAILED"); break; } else if(status[20]&0x40) /* mag2 on? */ { counter[52]=0; comseq=0; break; } else if(status[20]&0x20) /* mag1 on? */ { magnet2(1); break; } else if((status[4]&0x30)==0x30) /* cooling on? */ { magnet1(1); break; } else { cooling(1); break; } case 7: /* both magnets off */ if(trynum++>5) { trynum=0; comseq=0; warn("MAGNET OFF SEQUENCE FAIL"); break; } read_d_chan(1,13,12,(void *)&bit,'o'); /* read HV request */ if(bit) /* HV requested */ { highvolt(0); /* turn off hv */ break; } read_d_chan(1,13,9,(void *)&bit,'o'); /* read mag1 request */ if(bit) /* mag1 on */ { magnet1(0); /* turn it off */ break; } read_d_chan(1,13,10,(void *)&bit,'o'); /* read mag2 request */ if(bit) /* mag2 on */ { magnet2(0); /* turn it off */ break; } else /* mags are off */ { comseq=0; prompt("MAGNETS ARE OFF"); break; } case 8: /* long range receive */ wgswitch(1); /* dummy load */ comseq=0; break; case 9: /* long range transmit */ wgswitch(0); /* combiner */ comseq=0; break; case 10: /* hot crowbar test */ hottest(); break; } end:; } /*****************************************************************************/ standby(void) /* send standby command to control circuit */ { int fail; if(veriflag||inlog()||inhist()||insimu()) /* (RS) */ goto abort; if(comseq==4) /* (RS) */ { /* (RS) */ if(trynum++==6) /* (RS) */ { /* (RS) */ trynum=0; /* (RS) */ comseq=0; /* (RS) */ warn("COMMAND FAIL"); /* (RS) */ status[36]|=0x02; /* (RS) */ goto abort; /* (RS) */ } /* (RS) */ } /* (RS) */ else { /* (RS) */ comseq=4; /* (RS) */ trynum=0; /* (RS) */ } /* (RS) */ if(fail=status[45]&0x40) /* illegal key position */ { warn("ILLEGAL KEY POSITION"); goto abort; } if(remo) string1(parse); else { counter[52]=0; if(!(status[38]&0x20)) /* (RS) */ { cooling(1); /* turn on cooling (RS) */ goto abort; } if(!(status[20]&0x10)) /* (RS) */ { filament(1); /* turn on filaments (RS) */ goto abort; } if((status[8]&0x01) /* Kly1 selected (RS) */ &&(!(status[20]&0x20))) /* mag1 not on (RS) */ { magnet1(1); /* turn on mag1 (RS) */ goto abort; } if((status[8]&0x02) /* Kly2 selected (RS) */ &&(!(status[20]&0x40))) /* mag2 not on (RS) */ { magnet2(1); /* turn on mag2 (RS) */ goto abort; } } comseq=0; /* (RS) */ trynum=0; /* (RS) */ prompt("STANDBY"); abort: clkey(); return(fail); } /*****************************************************************************/ sonalert(on) /* turn on/off alarms */ { int fail,i; if(inlog()||inhist()||insimu()) goto abort; if(fail=status[45]&0x40) /* illegal key position */ { warn("ILLEGAL KEY POSITION"); goto abort; } if(remo) { string1(parse); goto abort; } i=atoi(&parse[4]); /* argument */ if(on) alarm(i); else mute(i); abort: clkey(); } /*****************************************************************************/ mute(i) /* mute sonalert(s) */ { int fail; if(fail=status[45]&0x40) /* illegal key position */ { warn("ILLEGAL KEY POSITION"); goto abort; } switch(i) { case 0: /* mute all sonalerts */ control[0]&=0xFE; outp(0x510,control[0]); /* mute ops sonalert */ tto(10,3,0); /* mute dome sonalert */ tto(13,16,0); /* mute hvps sonalert */ status[27]|=0x70; break; case 1: /* mute ops sonalert */ control[0]&=0xFE; outp(0x510,control[0]); status[27]|=0x10; break; case 2: /* mute dome sonalert */ tto(10,3,0); status[27]|=0x20; break; case 3: /* mute hvps sonalert */ tto(13,16,0); status[27]|=0x40; break; case 4: /* turn off all sonalerts */ control[0]&=0xFE; outp(0x510,control[0]); /* ops sonalert */ tto(10,3,0); /* dome sonalert */ tto(13,16,0); /* hvps sonalert */ status[27]&=0x8F; /* clear mute status */ break; default: illarg(); } prompt("MUTE ALARM"); abort: clkey(); return(fail); } /*****************************************************************************/ alarm(i) /* turn on sonalert(s) */ { int fail; if(fail=status[45]&0x40) /* illegal key position */ { warn("ILLEGAL KEY POSITION"); goto abort; } switch(i) { case 0: /* turn on all sonalerts */ control[0]|=0x01; outp(0x510,control[0]); /* turn on ops sonalert */ tto(10,3,1); /* turn on dome sonalert */ tto(13,16,1); /* turn on hvps sonalert */ status[27]&=0x8F; break; case 1: /* turn on ops sonalert */ control[0]|=0x01; outp(0x510,control[0]); status[27]&=0xEF; break; case 2: /* turn on dome sonalert */ tto(10,3,1); status[27]&=0xDF; break; case 3: /* turn on hvps sonalert */ tto(13,16,1); status[27]&=0xBF; break; default: illarg(); } prompt("ALARM ON"); abort: return(fail); } /*****************************************************************************/ initout(void) /* initialize PO-32L output cards */ /* most commands are asserted with a high bit, which saturates the open-collector output transistor. pins 1,20 are ground. pins 18,37 are Vcc. pin 19 is not used. */ { control[0]=0x00; control[1]=0x00; control[2]=0x00; control[3]=0x00; } /**************************************************************************/ tto(mod,chl,data) /* tti module output */ { int fail; if(test) goto abort; if(++counter[57]>1000) /*(RS)*/ { counter[57]=0; counter[68]=0; counter[69]=0; counter[72]=0; } fail=writ_d_chan(1,mod,chl,data,'o'); if(fail) if(++counter[59+mod]>counter[55]) status[29]|=(0x10>>(13-mod)); abort: return(fail); } /**************************************************************************/ ttm(mod,chl,data,ten) /* momentary tti module output */ { int fail; if(test) goto abort; fail=tto(mod,chl,data); tenths(ten); /* duration in tenths of seconds */ fail|=tto(mod,chl,data^0x01); abort: return(fail); } /**************************************************************************/ ttd(mod,chl,data) /* tti dac module output */ { int fail=0,value; if(test) goto abort; if(++counter[58]>10) /* dac access count (RS) */ { counter[58]=0; counter[65]=0; counter[70]=0; } if(data<0||data>20000) /* 20 mA max */ { fail=1; warn("ILLEGAL DAC VALUE"); goto abort; } value=(long)(32760L*data)/20000L; /* 20 mA = 32760 */ fail=writ_a_chan(1,mod,chl,value,'o'); if(fail) { if(++counter[59+mod]>2) /*(RS)*/ { if(mod==6) status[28]|=0x20; /* dome */ else status[29]|=0x04; /* hvps */ } } abort: return(fail); } /**************************************************************************/ verifz(void) /* verify command execution */ { int fail=0; if((veriflag!=1)||(anordig==1)) goto abort; if((statnum==19)&&(statmask==0x02)&&(statchk==0x02) /* hvon */ &&((status[36]&0x10)||(!(status[36]&0x08)))) /* fault or intlk sum */ { veriflag=0; rflag=0; warn("COMMAND FAIL"); status[36]|=0x02; goto abort; } if(!rflag) { reset2(); rflag=1; goto abort; } rflag=0; if(fail=((status[statnum]&statmask)!=statchk)) { warn("COMMAND FAIL"); status[36]|=0x02; } if(statnum2) { if(fail=((status[statnum2]&statmask2)!=statchk2)) { warn("COMMAND FAIL"); status[36]|=0x02; } statnum2=0; } veriflag=0; abort: return(fail); } /**************************************************************************/ verifa(void) /* verify analog change */ { int fail=0; if((veriflag!=1)||(anordig==0)) goto abort; if(updn) { if(fail=(raw[metnum]<=oldval)) { warn("COMMAND FAIL"); status[36]|=0x02; } } else { if(fail=(raw[metnum]>=oldval)) { warn("COMMAND FAIL"); status[36]|=0x02; } } veriflag=0; abort: return(fail); } /**************************************************************************/ verify(byte,mask,state) /* verify command execution */ { int fail=0; thous(500); stats(); /* update status */ if((status[byte]&mask)!=state) { warn("COMMAND FAIL"); status[36]|=0x02; fail=1; } return(fail); } /**************************************************************************/ verimet(meter,up) /* verify increase (n=1), decrease (n=0) */ { int i,olmet,fail=0; long avraw=0; olmet=raw[meter]; /* save old value */ thous(1000); for(i=0;i<8;i++) { txmet(meter); /* get new value */ avraw+=raw[meter]; } avraw/=8; if(up) { if(avraw>olmet) /* increase */ goto abort; else { warn("COMMAND FAIL"); status[36]|=0x02; fail=1; } } else { if(avraw