'                       Attenuators
'                       -----------

'version 2
' 4 May 95


COMMON sgcode$, atten$, sgen$, ch$, ctr$
CLOSE
sgcode$ = "1"
atten$ = "27"
sgen = VAL(sgcode$)

SCREEN 9
CLS
COLOR 14, 1

start:
' initial set up of gp-ib

 OPEN "ieeectrl" FOR RANDOM AS #1
 OPEN "ieeedata" FOR RANDOM AS #2
 IOCTL #1, "init" + CHR$(13)
 IOCTL #1, "clear" + CHR$(13)
 IOCTL #1, "to 10 end=13 eos=13" + CHR$(13)

 OPEN "com2:9600,n,8,2" FOR RANDOM AS #3
 OPEN "c:\qb\gpr\res\file" FOR APPEND AS #4

 SLEEP 5
 GOTO test

mar:
  IF sgen = 2 THEN RETURN
  COLOR 11
  IOCTL #1, "3" + CHR$(13)
  IOCTL #2, mar$ + CHR$(13)
RETURN

adret:
  IF sgen = 1 THEN RETURN
  IOCTL #1, "3" + CHR$(13)
  IOCTL #2, adret$ + CHR$(13)
  SLEEP 1
RETURN

at:
COLOR 13
  IOCTL #1, atten$ + CHR$(13)
  IOCTL #2, at$ + CHR$(13)
  SLEEP 1
RETURN

ip:
COLOR 14
   ip$ = IOCTL$(#2)
   ip# = VAL((MID$(ip$, s, e)))
RETURN

freqip:
mar$ = "cfrq?": GOSUB mar
s = 12
e = 14
GOSUB ip
ip# = ip# / 1000000
'PRINT ip#; " MHz"
RETURN

levip:
mar$ = "rflv?": GOSUB mar
s = 22
e = 6
GOSUB ip
u$ = MID$(ip$, 12, 4)
'PRINT ip#; u$
RETURN

freq:
  adfr = VAL(fr$)
  adfr = adfr * 1000000
  adret$ = "F " + STR$(adfr): GOSUB adret
  mar$ = "cfrq " + fr$ + " mhz": GOSUB mar
RETURN

lev:
  adret$ = "A " + l$: GOSUB adret
  mar$ = "rflv " + l$ + "dbm": GOSUB mar
RETURN

gpr:
COLOR 10
  PRINT #3, gpr$
  INPUT #3, r$
  SLEEP 1

er$ = LEFT$(r$, 1)
IF er$ <> "E" THEN RETURN
IF gpr$ = "REM" THEN RETURN

eror:
BEEP
COLOR 15
PRINT
PRINT "                 Error in GPR code   :    "; gpr$
BEEP
SLEEP
RETURN


test:
CLS
at$ = "A 100,": GOSUB at
gpr$ = "REM": GOSUB gpr
mar$ = "*RST": GOSUB mar
mar$ = "mod:OFF": GOSUB mar
mar$ = "imode normal": GOSUB mar
mar$ = "rflv:ON": GOSUB mar
SLEEP 3

gpr$ = "TS 6": GOSUB gpr
gpr$ = "VN": GOSUB gpr

rec$ = LEFT$(r$, 4)

'************************************************************
IF VAL(LEFT$(r$, 5)) = 4305 THEN rec$ = MID$(STR$(4301), 2, 4)
'************************************************************

sn$ = RIGHT$(r$, 4)
fv$ = MID$(r$, 5, 5)
COLOR 15
PRINT "Receiver type         GPR"; rec$
PRINT "Serial no.               "; sn$

fr$ = "40": GOSUB freq
l$ = "0": GOSUB lev
at$ = "A 62,": GOSUB at

gpr$ = "RD L": GOSUB gpr
gpr$ = "BW 1": GOSUB gpr
gpr$ = "FR 40000000": GOSUB gpr
SLEEP 10
zgpr$ = "CL": GOSUB gpr
SLEEP 5

att:
LOCATE 5, 20
COLOR 14
PRINT "Attenuators"
PRINT #4, "Attenutors"
PRINT

l$ = "0"
fail = 1.5
fr = 1
DO

  lp = 1
  lev = 45
  DO
    IF lp > 3 THEN
      at$ = "A 52,": GOSUB at
      SLEEP 2
      lev = 55
    END IF
    l$ = l$: GOSUB lev

adj:
    adjloop = 1
    lv = 0
    DO
      SLEEP 1
      gpr$ = "SG": GOSUB gpr
      gprlev = VAL(r$)
      IF gprlev <> lev THEN
        inlev = lev - gprlev
        sglev = lv + inlev
         
          slev = sglev * 10
          slev% = slev
          sglev = slev% / 10
       
        l$ = STR$(sglev)
        GOSUB lev
        lv = sglev
      END IF

      adjloop = adjloop + 1
      IF adjloop = 10 THEN
        l$ = STR$(sglev + .1)
        GOSUB lev
        gpr$ = "SG": GOSUB gpr
        gprlev = VAL(r$)
      END IF
      IF adjloop = 20 THEN
fail:
         DO
           LOCATE 15, 20
           COLOR 12
           PRINT "Error Has Occured !!"
           COLOR 14
           PRINT "Press Any Key to re-start test"
           'BEEP
         LOOP UNTIL INKEY$ <> ""
        
         GOTO test
      END IF
         
    LOOP UNTIL gprlev = lev
    BEEP
    SLEEP 1

    lp$ = STR$(lp)
    gpr$ = "AT" + lp$: GOSUB gpr
    gpr$ = "AT Y": GOSUB gpr
    SLEEP 3
    gpr$ = "SG": GOSUB gpr
    at = (lp * 10) + (lev - (VAL(r$)))
    f = lev - (VAL(r$))
      IF f > fail OR f < -fail THEN
          fail$ = "!"
          rescol = 12
        ELSE
          fail$ = " "
          rescol = 10
        END IF
   
    LOCATE 7 + lp, 10
    COLOR 11
    PRINT lp * 10
    LOCATE 7 + lp, 10 + (fr * 10)
    COLOR rescol
    PRINT USING "##.#"; at;
    PRINT ; "  "; fail$
    at$ = STR$(at)
    PRINT #4, STR$(lp * 10), at$
'    PRINT #4, fail$
    gpr$ = "AT N": GOSUB gpr
    lp = lp + 1
  LOOP UNTIL lp = 6

  at$ = "A 62,": GOSUB at
  fr$ = "950": GOSUB freq
  gpr$ = "FR 950000000": GOSUB gpr
  SLEEP 10
  gpr$ = "CL": GOSUB gpr
  SLEEP 6
  l$ = "0": GOSUB lev
  fr = fr + 1
LOOP UNTIL fr = 3


fixed:
  PRINT : PRINT
  COLOR 11
  PRINT "Fixed ";
  PRINT #4, "Fixed"

at$ = "A 62,": GOSUB at
fr$ = "40": GOSUB freq
l$ = "-2": GOSUB lev

gpr$ = "FR 40000000": GOSUB gpr
gpr$ = "CL": GOSUB gpr
SLEEP 5

 
  gpr$ = "AT 1": GOSUB gpr
  gpr$ = "AT Y": GOSUB gpr
  gpr$ = "AT F": GOSUB gpr
  SLEEP 1
  at$ = "A 37,": GOSUB at
  SLEEP 2
  l = -2
 
  DO
    fix$ = "Un - Satisfactory"
    c = 12
    l$ = STR$(l): GOSUB lev
    gpr$ = "RS": GOSUB gpr
    ol$ = RIGHT$(r$, 1)
    'PRINT ol$

    IF ol$ = "V" THEN
      IF l < -1.5 THEN
        c = 12
        fix$ = "Un - Satisfactory"
      ELSE
        fix$ = "Satisfactory"
        c = 10
      END IF
     
      'l = 1.6
    END IF

   
    l = l + .1
  LOOP UNTIL l > 1.6

fixres:
  COLOR c
  LOCATE 15, 25
  PRINT fix$
  PRINT #4, fix$

  
  at$ = "A 100,": GOSUB at
  gpr$ = "AT N": GOSUB gpr

PRINT #4, "att end"

mar$ = "*RST": GOSUB mar
gpr$ = "LOC": GOSUB gpr
SLEEP 4

CLOSE
IF ctr$ = "1" THEN CHAIN "c:\qb\gpr\ammod"
CHAIN "c:\qb\gpr\menu"
END





