#include /* module stats9 */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include union REGS inregs,outregs; /* CONTEC CARD ADDRESS input 1 0x500 to 0x503 output 1 0x510 to 0x513 --------------------------------------------------------------------------- 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 */ /**************************************************************************/ void initirig() /* initialize the IRIG reader */ { struct dostime_t time; unsigned char isec; outp(0x200,0x00); /* select IRIG B */ outp(0x201,0x00); /* select channel 1, forward */ outp(0x202,0x00); /* low to high trigger */ outp(0x203,0x00); /* request time function */ inp(0x218); /* reset the reader */ _dos_gettime(&time); isec=time.second; if(isec>56) isec=0; wait: _dos_gettime(&time); if(time.second!=(isec+3)) goto wait; inp(0x210); /* clear the interrupt */ isec=time.second; if(isec>57) isec=0; again: _dos_gettime(&time); if(time.second!=(isec+2)) goto again; } /**************************************************************************/ void irig() /* read the IRIG reader and set dos time */ { struct dostime_t time; int i,byte,count,fifoflag,error=0; unsigned char ihour,imin,isec,ihsec; inp(0x208); /* reset the IRIG FIFO memory */ retry: inp(0x214); /* request time transfer to the FIFO */ _dos_gettime(&time); ihsec=time.hsecond; if(ihsec>98) ihsec=0; delay: _dos_gettime(&time); if(time.hsecond>=(ihsec+1)) goto delay; for(i=0;i<11;i++) { fifoflag=(inp(0x20C)&0x01); for(count=0;((count<1000)&&(fifoflag!=0x01));count++) /* wait for FIFO empty flag to clear */ { fifoflag=(inp(0x20C)&0x01); } if(count>999) goto quit; /* timed out */ byte=inp(0x204); /* read a time byte */ if((byte&0xFF)==0xF1) { error++; if(error==5) { goto quit; } prompt("time error"); goto retry; } else if((byte&0xF0)==0x30) ihour = (byte&0x0F)*10; else if((byte&0xF0)==0x40) ihour = ihour + (byte&0x0F); else if((byte&0xF0)==0x50) imin = (byte&0x0F)*10; else if((byte&0xF0)==0x60) imin = imin + (byte&0x0F); else if((byte&0xF0)==0x70) isec = (byte&0x0F)*10; else if((byte&0xF0)==0x80) isec = isec + (byte&0x0F); else if((byte&0xF0)==0x90) ihsec = (byte&0x0F)*10; else if((byte&0xF0)==0xA0) ihsec = ihsec + (byte&0x0F); } time.hour = ihour; time.minute = imin; time.second = isec; time.hsecond = ihsec; _dos_settime(&time); quit:; } /**************************************************************************/ stats(void) /* read status cards and put in buffer */ /* CONTEC PI-32L, tel. 408-436-0340 */ { unsigned char out=0,mask,byte,bit; int bad=0,fail[16],i; if(status[35]&0x80) goto sums; /* simulation mode */ if(histno||logno) goto abort; if(remo) { dataload(1); goto sums; } histen=0; /* note that the PI-32L inverts logic; a pulldown at input is read as a high */ /* faults, overloads, arcs are inverted in software */ /* the database assertion convention = 1 for closed interlock or active fault */ for(i=23;i<27;i++) status[i]=0; /*---------------------------------------------------------------------------*/ byte=inp(0x500); bit=byte&0x01; /* d0 = ops 24V */ status[23]|=bit; bit=byte&0x02; /* d1 = ops remote mode */ status[23]|=bit; bit=byte&0x04; /* d2 = ops reset pb */ status[23]|=bit; bit=byte&0x08; /* d3 = UPS on line */ status[23]|=bit; bit=byte&0x10; /* d4 = ops keying PM */ status[23]|=bit; bit=byte&0x20; /* d5 = ops keying AM */ status[23]|=bit; bit=byte&0x40; /* d6 = ops keying off */ status[23]|=bit; bit=byte&0x80; /* d7 = ops keying remote */ status[23]|=bit; /*---------------------------------------------------------------------------*/ byte=inp(0x501); bit=byte&0x01; /* d0 = user defined */ status[24]|=bit; bit=byte&0x02; /* d1 = */ status[24]|=bit; bit=byte&0x04; /* d2 = */ status[24]|=bit; bit=byte&0x08; /* d3 = */ status[24]|=bit; bit=byte&0x10; /* d4 = */ status[24]|=bit; bit=byte&0x20; /* d5 = */ status[24]|=bit; bit=byte&0x40; /* d6 = */ status[24]|=bit; bit=byte&0x80; /* d7 = */ status[24]|=bit; /*---------------------------------------------------------------------------*/ byte=inp(0x502); bit=byte&0x01; /* d0 = */ status[25]|=bit; bit=byte&0x02; /* d1 = */ status[25]|=bit; bit=byte&0x04; /* d2 = */ status[25]|=bit; bit=byte&0x08; /* d3 = */ status[25]|=bit; bit=byte&0x10; /* d4 = */ status[25]|=bit; bit=byte&0x20; /* d5 = */ status[25]|=bit; bit=byte&0x40; /* d6 = */ status[25]|=bit; bit=byte&0x80; /* d7 = */ status[25]|=bit; /*---------------------------------------------------------------------------*/ byte=inp(0x503); bit=byte&0x01; /* d0 = ops mute pb */ status[26]|=bit; bit=byte&0x02; /* d1 = ops hv on pb */ status[26]|=bit; bit=byte&0x04; /* d2 = ops hv off pb */ status[26]|=bit; bit=byte&0x08; /* d3 = ops odapc */ status[26]|=bit; bit=byte&0x10; /* d4 = ops keying CW */ status[26]|=bit; bit=byte&0x20; /* d5 = ops */ status[26]|=bit; bit=byte&0x40; /* d6 = ops */ status[26]|=bit; bit=byte&0x80; /* d7 = ops */ status[26]|=bit; /*---------------------------------------------------------------------------*/ if(test) goto sums; if(++counter[56]>1000) /* tti poll count */ { counter[56]=0; /* reset */ for(i=0;i<5;i++) counter[60+i]=0; /* reset tti counters */ counter[71]=0; } for(i=0;i<5;i++) if(fail[i]=tti(i+1,i*4)) /* read dome tti modules */ { if(++counter[60+i]>counter[55]) status[28]|=(0x01<counter[55]) status[29]|=0x08; /* fail */ } if(!fail[0]) /* tti 1 */ { status[2]^=0xFE; /* invert overloads and warnings */ status[3]^=0xCF; } if(!fail[1]) /* tti 2 */ { status[4]^=0x07; status[7]^=0xE0; } if(!fail[2]) /* tti 3 */ { status[8]^=0x20; status[10]^=0xFF; status[11]^=0xFF; } if(!fail[3]) /* tti 4 */ { status[12]^=0xFF; status[13]^=0xFF; status[14]^=0x02; } if(!fail[4]) /* tti 5 */ { status[18]^=0xFC; } if(!fail[11]) /* tti 12 */ { status[19]^=0x28; status[20]^=0x81; status[21]^=0x3F; } sums: if((status[12]&0x60) /* wg arc a */ ||(status[18]&0x30)) /* wg arc b */ status[37]|=0x40; /* wg arc sum */ else status[37]&=0xBF; /* wg arc sum */ if(status[39]||status[40] /* test fail */ ||status[41]||status[42]||status[44]||status[45]&0x3F) status[38]|=0x08; /* test sum */ else status[38]&=0xF7; if((status[19]&0x04) /* hvps door intlk */ &&(status[19]&0x10) /* hvps gnd stick */ &&!(status[19]&0x20) /* hvps oil */ &&(status[19]&0x80) /* hvps gnd switch */ &&(status[19]&0x01) /* hvps breaker proof */ &&!(status[21]&0x08)) /* hvps 480v (phase) fault */ status[27]|=0x80; /* hvps interlock summary */ else status[27]&=0x7F; if((status[20]&0x80) /* hvps DC overcurrent */ ||(status[21]&0x01)) /* hvps AC overcurrent */ status[29]|=0x20; /* hvps over-current summary */ else status[29]&=0xDF; if(!(status[21]&0x16) /* hvps mov, triggered, fired */ &&(status[22]&0x01) /* hvps fo rcvr A */ &&(status[22]&0x02) /* hvps fo rcvr B */ &&(status[22]&0x04) /* emergency off interlock */ &&!(status[20]&0x01) /* hvps breaker fault */ &&!(status[21]&0x20) /* hvps contactor status */ &&!(status[29]&0x20) /* hvps over-current summary */ &&(status[20]&0x02) /* crowbar heat on */ &&(status[20]&0x04) /* crowbar blower on */ &&(status[20]&0x08)) /* crowbar trigger ps on */ status[46]|=0x01; /* hvps crowbar ready summary */ else status[46]&=0xFE; if((status[10]&0xF0) /* reflected power */ ||(status[12]&0xFC) /* refl, turn fwd power, arcs A */ ||(status[18]&0x34) /* arcs B, turn fwd power */ ||(status[13]&0x01)) /* kly2 refl A */ status[29]|=0x80; /* RF fault sum */ else status[29]&=0x7F; if((status[8]&0x03)==0x03) /* kly1 & kly2 sel */ { if(status[0] /* first events */ ||status[1] /* first events */ ||status[2]&0x01 /* 35kw dl first event */ ||!((status[6]&0x0C)==0x0C) ||!((status[7]&0x0F)==0x0F) ||status[10] ||status[11] ||status[12] ||status[13] ||status[14]&0x02 ||!(status[46]&0x01)) /* hvps crowbar ready summary */ dogs|=0x03; /* special fault sum */ else dogs&=0xFC; } else if(status[8]&0x01) /* just kly1 sel */ { if(status[0] /* first events */ ||status[1] /* first events */ ||status[2]&0x01 ||!((status[6]&0x04)==0x04) ||!((status[7]&0x05)==0x05) ||status[10]&0x75 ||status[11]&0x55 ||status[12]&0xBF ||status[13]&0xAA ||status[14]&0x02 ||!(status[46]&0x01)) /* hvps crowbar ready summary */ dogs|=0x03; /* special fault sum */ else dogs&=0xFC; } else if(status[8]&0x02) /* just kly2 sel */ { if(status[0] ||status[1] ||status[2]&0x01 ||!((status[6]&0x08)==0x08) ||!((status[7]&0x0A)==0x0A) ||status[10]&0xBA ||status[11]&0xAA ||status[12]&0x5F ||status[13]&0xD5 ||status[14]&0x02 ||!(status[46]&0x01)) /* hvps crowbar ready summary */ dogs|=0x03; /* special fault sum */ else dogs&=0xFC; } else { /* no tube selected */ if(status[0] ||status[1] ||status[2]&0x01 ||status[10]&0x30 ||status[12]&0x1F ||status[13]&0x80 ||status[14]&0x02 ||!(status[46]&0x01)) /* hvps crowbar ready summary */ dogs|=0x03; /* special fault sum */ else dogs&=0xFC; } if((status[8]&0x03)==0x03) /* kly1 & kly2 sel */ { if((dogs&0x01) /* special fault sum */ ||!((status[6]&0xF0)==0xF0)) /* filament proofs */ dogs|=0x02; /* special fault sum */ else dogs&=0xFD; } else if(status[8]&0x01) /* just kly1 sel */ { if((dogs&0x01) /* special fault sum */ ||!((status[6]&0x50)==0x50)) /* filament proofs */ dogs|=0x02; /* special fault sum */ else dogs&=0xFD; } else if(status[8]&0x02) /* just kly2 sel */ { if((dogs&0x01) /* special fault sum */ ||!((status[6]&0xA0)==0xA0)) /* filament proofs */ dogs|=0x02; /* special fault sum */ else dogs&=0xFD; } else { /* no tube selected */ if(dogs&0x01) dogs|=0x02; /* special fault sum */ else dogs&=0xFC; } if((dogs&0x01) /* special fault sum */ ||(status[29]&0x80)) /* RF Fault Sum */ dogs|=0x01; /* special fault sum */ else dogs&=0xFE; if(dogs&0x03) status[36]|=0x10; /* fault sum */ else status[36]&=0xEF; if(status[2]&0xFE ||status[3]&0xCF ||status[4]&0x07 ||status[7]&0xE0) status[3]|=0x20; /* warning sum */ else status[3]&=0xDF; if(((status[8]&0xC4)==0xC4) /* interlocks */ &&((status[9]&0x03)==0x03) &&((status[27]&0x80)==0x80)) /* hvps interlock summary */ status[36]|=0x08; /* interlock sum */ else status[36]&=0xF7; if(((status[4]&0xB8)==0xB8) /* flow & pressure proofs */ &&((status[5]&0xFF)==0xFF) &&((status[6]&0x03)==0x03)) status[38]|=0x20; /* cooling flow sum */ else status[38]&=0xDF; if((status[13]&0xFE) ||(status[14]&0x02)) status[46]|=0x40; /* overtemp sum */ else status[46]&=0xBF; if(((status[38]&0x20)==0x20) &&(!(status[46]&0x40))) status[37]|=0x20; /* cooling sum */ else status[37]&=0xDF; if(status[28]||(status[29]&0x1F)) status[37]|=0x80; /* TTI sum */ else status[37]&=0x7F; i=0; if(!(status[23]&0x02)) /* ops not remote */ ++i; if(!(status[17]&0x20)) /* dome in local mode */ ++i; if(!(status[22]&0x10)) /* hvps in local mode */ ++i; if(i>1) status[45]|=0x40; /* illegal key position */ else status[45]&=0xBF; /* only one local mode */ if((i==0)&&(status[19]&0x02)) /* no local key and HV on */ highvolt(0); /* turn off HV */ if(!(status[23]&0x01) /* 24V ps dead */ ||(status[8]&0x20) /* dome keep-alive */ ||(status[19]&0x08) /* hvps keep-alive */ ||(status[27]&0x08) /* xoff time-out */ ||(status[35]&0x0F) /* password fail, COM fail */ ||(status[36]&0x03) /* command fail, logs full */ ||(status[38]&0x90) /* test over-ride, logs almost full */ ||(status[37]&0x80) /* TTI sum */ ||(status[45]&0xC0) /* declined CB test, illegal key position */ ||(status[46]&0x3E)) /* DOS error, trackball, tti init, hvps reset over-ride, hacker */ status[36]|=0x20; /* fail sum */ else status[36]&=0xDF; for(i=30;i<=34;i++) out|=status[i]; /* meter warnings */ if(out) status[36]|=0x04; /* out-of-bounds sum */ else status[36]&=0xFB; /*---------------------------------------------------------------------------*/ for(i=0;i=counter[25]) clocker(); abort: if(counter[29]) { time(&scrstart); counter[9]=0; /* reset screen-saver timer */ } return(counter[29]); } /*****************************************************************************/ dataload(arg) /* get data stream from main computer */ /* 6 calendar bytes: hours, minutes, seconds, month, day, year nb status bytes (checksum if arg = 1) 64 metering bytes (32 ints) checksum byte */ { unsigned char sum=0; int fail=0,i,index,byte,lower,upper,data[200]; if(kbhit()||keyboard[0]) goto abort; clrbuf1(); /* clear COM1 receive buffer */ if(arg==1) { index=nb+33; if(fail=command("DUMP1")) goto abort; } else { index=nb+51; if(fail=command("DUMP2")) goto abort; } startim(); /* start thousandths counter */ while(!getcnt1()) /* is COM1 buffer filling? */ if(delta()>3000) /* tx cpu not responding */ { fail=1; goto abort; } for(i=0;i9) /* hours */ itoa(data[0],tyme,10); else itoa(data[0],&tyme[1],10); if(data[1]>9) /* minutes */ itoa(data[1],&tyme[3],10); else itoa(data[1],&tyme[4],10); if(data[2]>9) /* seconds */ itoa(data[2],&tyme[6],10); else itoa(data[2],&tyme[7],10); tyme[2]=':'; tyme[5]=':'; strcpy(dayt,"00/00/00"); if(data[3]>9) /* month */ itoa(data[3],dayt,10); else itoa(data[3],&dayt[1],10); if(data[4]>9) /* day */ itoa(data[4],&dayt[3],10); else itoa(data[4],&dayt[4],10); if(data[5]>9) /* year */ itoa(data[5],&dayt[6],10); else itoa(data[5],&dayt[7],10); dayt[2]='/'; dayt[5]='/'; for(i=0;i>8; status[byte+2]=buf[1]&0x00FF; if(byte==0) { if(status[3]&0x10) { status[3]=(buf[1]&0xCF00)>>8; status[3]|=0x10; } else status[3]=(buf[1]&0xCF00)>>8; } else if(byte!=16) status[byte+3]=(buf[1]&0xFF00)>>8; mod_latch_clr(1,mod,&mask[0]); /* reset latched bits */ abort: return(fail); } /**************************************************************************/ respond(void) /* act on special status changes */ { char bit; int k,x1,y1,ticklim; if((status[36]&0x10)&&!logno&&!histno &&(!(status[35]&0x10)) /* not boot store */ &&(!(statup[36]&0x10))) /* new fault */ { control[0]|=0x01; outp(0x510,control[0]); /* ops sonalert */ tto(10,3,1); /* dome sonalert */ tto(13,16,1); /* hvps sonalert */ } else if(!(status[36]&0x10)&&!logno&&!histno &&((statup[36]&0x10))) /* fault cleared */ mute(4); if((status[29]&0x80)&&!logno&&!histno &&(!(dogs&0x02)) &&(!(status[35]&0x10)) /* not boot store */ &&(!(statup[29]&0x80))) /* new RF fault */ { ++counter[49]; /* fault counter */ counter[51]=0; /* timer */ if(counter[49]<=counter[48]) reset(); /* auto reset */ else status[29]|=0x40; /* lock-out */ } if(!(status[29]&0x80) /* RF fault sum */ &&(counter[51]>3276)) /* 3 minute limit */ { counter[49]=0; /* reset RF fault counter */ counter[51]=0; /* reset timer */ } bit=status[27]&0x80; /* hvps interlock summary */ if(bit) tto(10,5,1); else tto(10,5,0); bit=status[46]&0x01; /* crowbar ready summary */ if(bit) tto(9,11,1); else tto(9,11,0); bit=status[29]&0x20; /* hvps over-current sum */ if(bit) tto(9,10,0); else tto(9,10,1); bit=status[19]&0x02; /* hvps contactor */ if(bit) tto(9,14,1); else tto(9,14,0); bit=status[21]&0x02; /* crowbar fired */ if(bit) tto(10,1,1); else tto(10,1,0); if((status[21]&0x04) /* crowbar triggered */ &&(!(statup[21]&0x04))) counter[73]=1100; /* 1 minute recovery */ bit=status[20]&0x10; /* filament contactor */ if(bit) tto(10,8,1); else tto(10,8,0); bit=status[20]&0x20; /* magnet 1 contactor */ if(bit) tto(10,9,1); else tto(10,9,0); bit=status[20]&0x40; /* magnet 2 contactor */ if(bit) tto(10,10,1); else tto(10,10,0); if(status[21]&0x80) /* CB test PB */ crowbar(); /* Fire the CB */ if((status[23]&0x02) &&(!(status[14]&0x01))) /* ops in remote and antenna */ rfswitch(1); /* put tx on waster */ if(!(status[9]&0x10) /* hw filament timer not ready */ ||(counter[40]!=0)) /* sw filament timer not ready */ tto(10,6,0); if(filset) { if(!tto(10,6,1)) filset=0; } if(!(status[20]&0x10)&&!logno&&!histno) /* filament contactor proof */ counter[40]=27310; /* reset filament software timer */ if((status[19]&0x80)&&!logno&&!histno&&counter[79] &&!(statup[19]&0x80)&&!(status[23]&0x02)) /* hvps gnd sw pulled up */ { font(1); boxit3("HOT CROWBAR TEST?"); font(1); 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=='N') status[45]|=0x80; /* declined test */ else if(k=='Y') { status[45]&=0x7F; /* accepted test */ hottest(); } else { warn("Y or N only"); clrkey(); goto loop; } clrkey(); oldscrn=0; } }