#include /* module preset */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include union REGS inregs,outregs; /* counter[47] channel of presets (1 to 10) counter[27] prepow[0-9] combined power output dac[0] counter[43] prebeam[0-9] beam voltage dac[1] counter[41] mag 1 current dac[2] counter[42] mag 2 current dac[3] counter[35] predriv[0-9] drive level dac[4] counter[36] prebal[0-9] drive balance dac[5] counter[37] prepha[0-9] drive phase dac[6] counter[38] preoff[0-9] feed-fwd offset dac[7] counter[39] pregain[0-9] feed-fwd gain */ /***************************************************************************/ table(void) /* define pre-set power level parameters */ { char string[30]; int fail=0,i,index,k,m=0,n=0,nold=0,mold=0,slot,x,y; if(inlog()||inhist()||insimu()) { clkey(); goto abort; } if(parse[4]!=CR) { slot=atoi(&parse[4]); /* slot number */ if(slot<1||slot>10) goto failed; index=slot-1; n=comma(2)-comma(1)-1; /* argument length */ if(n>0) { prepow[index]=atoi(&parse[comma(1)+1]); } n=comma(3)-comma(2)-1; /* argument length */ if(n>0) { prebeam[index]=atoi(&parse[comma(2)+1]); } n=comma(4)-comma(3)-1; /* argument length */ if(n>0) { predriv[index]=atoi(&parse[comma(3)+1]); } n=comma(5)-comma(4)-1; /* argument length */ if(n>0) { prebal[index]=atoi(&parse[comma(4)+1]); } n=comma(6)-comma(5)-1; /* argument length */ if(n>0) { prepha[index]=atoi(&parse[comma(5)+1]); } n=comma(7)-comma(6)-1; /* argument length */ if(n>0) { preoff[index]=atoi(&parse[comma(6)+1]); } n=comma(8)-comma(7)-1; /* argument length */ if(n>0) { pregain[index]=atoi(&parse[comma(7)+1]); } clkey(); goto abort; } clear(); /* clear entire screen */ font(1); text(PALEBLUE,60,479,"PRESET POWER LEVELS"); txnumber(); text(WHITE,10,420,"SELECT"); tex(80,440,"OUTPUT"); tex(80,420,"POWER"); tex(145,440,"BEAM"); tex(140,420,"VOLTAGE"); tex(200,440,"DRIVE"); tex(200,420,"POWER"); tex(270,440,"DRIVE"); tex(260,420,"BALANCE"); tex(320,440,"DRIVE"); tex(320,420,"PHASE"); tex(380,440,"FEED-FORWARD"); tex(380,420,"OFFSET"); tex(440,420,"GAIN"); rect(DARKGREY,0,200,15,405); for(i=0;i<=9;i++) { y=400-20*i; text(WHITE,2,y,itoa(i+1,numb,10)); /* sequence */ texcolor(PALEBLUE); if(i!=counter[47]-1) tex(20,y,"--"); else tex(20,y,"ON"); tex(80,y,itoa(prepow[i],numb,10)); tex(140,y,itoa(prebeam[i],numb,10)); tex(200,y,itoa(predriv[i],numb,10)); tex(260,y,itoa(prebal[i],numb,10)); tex(320,y,itoa(prepha[i],numb,10)); tex(380,y,itoa(preoff[i],numb,10)); tex(440,y,itoa(pregain[i],numb,10)); } loop: clkey(); message(WHITE,"USE CURSOR KEYS OR CLICK LEFT TO SELECT, Esc TO EXIT"); onmouse(); while(!kbhit()) { odapc(); switch(click()) /* mouse button */ { case 1: /* left click */ x=outregs.x.cx; y=479-outregs.x.dx; m=(x-20)/60; if(m>7) m=0; n=(400-y)/20; if(n>9||n<0) n=0; goto exec; case 3: /* both click */ k=ESC; goto cursor; } } k=caps(); if(k>128) cursor: switch(k) { case LEFT: --m; if(m==-1) m=7; /* wrap */ break; case RIGHT: ++m; if(m==8) m=0; /* wrap */ break; case UP: --n; if(n==-1) n=9; /* wrap */ break; case DOWN: ++n; if(n==10) n=0; /* wrap */ break; case HOME: n=0; break; case END: n=9; break; default: goto key; } else { key: keyboard[0]=k; if(k<128) prompt(keyboard); goto abort; } exec: x=20+mold*60; y=400-20*nold; offmouse(); rect(BLACK,x,y,x+50,y-10); texcolor(PALEBLUE); switch(mold) { case 0: if(nold!=counter[47]-1) tex(20,y,"--"); else tex(20,y,"ON"); break; case 1: tex(x,y,itoa(prepow[nold],numb,10)); break; case 2: tex(x,y,itoa(prebeam[nold],numb,10)); break; case 3: tex(x,y,itoa(predriv[nold],numb,10)); break; case 4: tex(x,y,itoa(prebal[nold],numb,10)); break; case 5: tex(x,y,itoa(prepha[nold],numb,10)); break; case 6: tex(x,y,itoa(preoff[nold],numb,10)); break; case 7: tex(x,y,itoa(pregain[nold],numb,10)); break; } nold=n; x=20+60*m; y=400-20*n; rect(BLUE,x,y,x+50,y-10); texcolor(WHITE); switch(m) { case 0: if(n!=counter[47]-1) tex(20,y,"--"); else tex(20,y,"ON"); break; case 1: tex(x,y,itoa(prepow[n],numb,10)); break; case 2: tex(x,y,itoa(prebeam[n],numb,10)); break; case 3: tex(x,y,itoa(predriv[n],numb,10)); break; case 4: tex(x,y,itoa(prebal[n],numb,10)); break; case 5: tex(x,y,itoa(prepha[n],numb,10)); break; case 6: tex(x,y,itoa(preoff[n],numb,10)); break; case 7: tex(x,y,itoa(pregain[n],numb,10)); break; } mold=m; switch(m) { case 0: prompt("select power level (CR or double-click left)"); break; case 1: prompt("enter power level (20 to 1200 kw)"); break; case 2: prompt("enter beam voltage (0 to 67 kv)"); /* (RS) */ break; case 3: prompt("enter drive dac uA (0 to 20000)"); break; case 4: prompt("enter drive balance dac uA (0 to 20000)"); break; case 5: prompt("enter drive phase dac uA (0 to 20000)"); break; case 6: prompt("enter feed-forward offset dac uA (0 to 20000)"); break; case 7: prompt("enter feed-forward gain dac uA (0 to 20000)"); break; } onmouse(); while(!kbhit()) { odapc(); switch(click()) /* mouse button */ { case 1: /* left click */ x=outregs.x.cx; y=479-outregs.x.dx; m=(x-20)/60; if(m>7) m=0; n=(400-y)/20; if(n>9||n<0) n=0; goto exec; case 3: /* both click */ k=ESC; goto cursor; case 4: /* double click left */ k=CR; goto exec2; } } k=caps(); if(k>128) goto cursor; if(k==ESC) goto abort; keyboard[0]=k; prompt(keyboard); if(k!=CR) while(console()!=CR); exec2: offmouse(); switch(m) { case 0: counter[47]=n+1; rect(BLACK,20,200,70,400); /* erase old values */ for(i=0;i<10;i++) { if(i!=counter[47]-1) text(WHITE,20,400-20*i,"--"); else text(GREEN,20,400-20*i,"ON"); } break; case 1: prepow[n]=atoi(keyboard); break; case 2: prebeam[n]=atoi(keyboard); break; case 3: predriv[n]=atoi(keyboard); break; case 4: prebal[n]=atoi(keyboard); break; case 5: prepha[n]=atoi(keyboard); break; case 6: preoff[n]=atoi(keyboard); break; case 7: pregain[n]=atoi(keyboard); break; } if(m) { rect(BLACK,x,y,x+50,y-10); /* erase old value */ keyboard[10]=0; /* avoid excess chars */ text(GREEN,x,y,keyboard); /* display new value */ } goto loop; failed: clkey(); illarg(); fail=1; status[12]|=0x01; /* command failed */ abort: savpreset(); /* update hard drive */ savemisc(); refresh=1; return(fail); } /***************************************************************************/ storepow(void) /* store preset power level parameters */ { int fail=0,i; i=atoi(&parse[4])-1; if(i<0||i>9) { illarg(); fail=1; goto abort; } if(status[14]&0x01) prepow[i]=avmet[16]; /* waster forward power */ else prepow[i]=avmet[23]; /* antenna forward power */ prebeam[i]=counter[43]/hvfac; /* beam voltage (RS) */ predriv[i]=counter[35]; /* drive level dac ma */ prebal[i]=counter[36]; /* drive balance dac ma */ prepha[i]=counter[37]; /* drive phase dac ma */ preoff[i]=counter[38]; /* feed-forward offset dac ma */ pregain[i]=counter[39]; /* feed-forward gain dac ma */ abort: return(fail); } /*****************************************************************************/ setpower(chl) /* set DACs to pre-set values */ { int fail=0; if(chl<1||chl>10) /* channel number out of range? */ { warn("ILLEGAL PRE-SET CHANNEL"); fail=1; goto abort; } counter[47]=chl; counter[27]=prepow[chl-1]; counter[43]=prebeam[chl-1]*hvfac; counter[28]=prebeam[chl-1]; counter[35]=predriv[chl-1]; counter[36]=prebal[chl-1]; counter[37]=prepha[chl-1]; counter[38]=preoff[chl-1]; counter[39]=pregain[chl-1]; setdacs(); abort: return(fail); } /*****************************************************************************/ setdacs(void) /* set DACs to previous values */ { int fail1,fail2; fail1=ttd(11,4,counter[43]); /* beam voltage */ fail1|=ttd(11,2,counter[41]); /* mag 1 current */ fail1|=ttd(11,3,counter[42]); /* mag 2 current */ if(fail1) warn("HVPS TTI DAC FAIL"); fail2=ttd(6,2,counter[35]); /* drive level */ fail2|=ttd(6,3,counter[36]); /* drive balance */ fail2|=ttd(6,4,counter[37]); /* drive phase */ fail2|=ttd(6,5,counter[38]); /* feed-forward offset */ fail2|=ttd(6,6,counter[39]); /* feed-forward gain */ if(fail2) warn("DOME TTI DAC FAIL"); return(fail1|fail2); } /****************************************************************************/ setfeeds(kv) /* set feed-forward DACs to closest values */ { int fail=0,offset,gain,olraw; average(); if(raw[2]<1000) { fail=1; goto abort; } prompt("SETTING FEED-FORWARD"); counter[75]=0; olraw=raw[2]; tenths(2); average(); average(); while((olraw>raw[2]+8)||(olraw