
'                       Linearity
'                       ---------

'version 3
'4 may 95


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

CLOSE


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\gpr4200\res\file" FOR APPEND AS #4

 SLEEP 5
 GOTO test

adret:
  IF sgen = 1 THEN RETURN

  IOCTL #1, "3" + CHR$(13)
  IOCTL #2, adret$ + CHR$(13)
RETURN

mar:
  IF sgen = 2 THEN RETURN

  COLOR 11
  IOCTL #1, "3" + CHR$(13)
  IOCTL #2, mar$ + CHR$(13)
' PRINT mar$
RETURN

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

ip:
COLOR 14
   ip$ = IOCTL$(#2)
'   PRINT ip$
   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:
at$ = "A 100,": GOSUB at
mar$ = "*RST": GOSUB mar
mar$ = "rflv:ON": GOSUB mar
mar$ = "MOD:off": GOSUB mar
gpr$ = "REM":  GOSUB gpr

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

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


gpr$ = "BW 1": GOSUB gpr
gpr$ = "RD L": GOSUB gpr
SLEEP 1

birdy:
fr(1) = 150
fr(2) = 150.0125
bdy = 1
bird(2) = 0

DO
  gpf = fr(bdy) * 10000
  gpf& = gpf * 100
  gpf$(bdy) = STR$(gpf&)
  gpr$ = "FR" + gpf$(bdy): GOSUB gpr
  SLEEP 10
  gpr$ = "CL": GOSUB gpr
  SLEEP 5
  gpr$ = "SG": GOSUB gpr
  bird(bdy) = VAL(r$)
    IF bird(1) < -22 THEN bdy = 4
  bdy = bdy + 1
LOOP UNTIL bdy >= 3
 
  IF bird(1) <= bird(2) THEN
    fr = fr(1)
    gpf$ = gpf$(1)
    bdy$ = " "
    IF bdy = 3 THEN
      gpr$ = "FR" + gpf$: GOSUB gpr
      SLEEP 10
      gpr$ = "CL": GOSUB gpr
      SLEEP 5
    END IF
  ELSE
    fr = fr(2)
    gpf$ = gpf$(2)
    bdy$ = "*"
  END IF

fr$ = STR$(fr): GOSUB freq
l$ = "0": GOSUB lev
at$ = "A 87,": GOSUB at

SLEEP 2
adjust:
lv = 0
DO
  SLEEP 1
  gpr$ = "SG"
  GOSUB gpr
   
  adlev! = VAL(r$)
  inlev! = 20 - adlev!
  inlev! = lv + inlev!
 
  IF inlev! <> 0 THEN
    l$ = STR$(inlev!)
    GOSUB lev
    lv = inlev!
  END IF

LOOP UNTIL adlev! = 20!

COLOR 14
LOCATE 5, 20
PRINT "Linearity"
PRINT
PRINT #4, "Linearity"

fail = -11.5
at = 1
DO
  atv = at * 10
  IF at = 9 THEN
    atv = (at * 10) - 1
  END IF

  actual = -30 + atv
  atv = 137 - atv
  atv$ = STR$(atv)
  
  at$ = "A" + atv$ + ",": GOSUB at
  SLEEP 4
  gpr$ = "SG": GOSUB gpr
  COLOR 11
  PRINT TAB(10); actual; TAB(20);
  res = VAL(r$)
 
  IF at = 1 THEN
    IF res > -11.5 THEN fail$ = "!" ELSE fail$ = " "
  ELSE
    fail = 1.5
    f = actual - res
    IF f > fail OR f < -fail THEN fail$ = "!" ELSE fail$ = " "
  END IF
  IF fail$ = "!" THEN rescol = 12 ELSE rescol = 10

  COLOR rescol
  PRINT USING "###.#"; res;
  PRINT " dBæV  "; fail$
  PRINT #4, r$
'  PRINT #4, fail$

  at = at + 1
LOOP UNTIL at = 10

IF bdy$ = "*" THEN
  PRINT : PRINT TAB(20); "* 'birdy' at this test"
END IF
PRINT #4, bdy$

oload:
COLOR 11
PRINT
PRINT "Over Load Threshold"
PRINT
PRINT #4, "Overload"

at$ = "A 87,": GOSUB at
l$ = "-10.0": GOSUB lev
SLEEP 2

at$ = "A 0,": GOSUB at
SLEEP 5

l = -10!
DO
  l$ = STR$(l): GOSUB lev
  SLEEP 1
  gpr$ = "RS": GOSUB gpr
  SLEEP 1
  ol$ = RIGHT$(r$, 1)
  IF ol$ = "V" THEN GOTO result

  l = l + .1
LOOP UNTIL l > 8

result:
  res = 107 - (0 - l)
  IF res < 98.5 OR res > 101.5 THEN
    fail$ = "!"
    rescol = 12
  ELSE
    fail$ = " "
    rescol = 10
  END IF
  COLOR rescol
  PRINT USING "###.#"; res;
  PRINT " "; fail$
  res$ = STR$(res)
  PRINT #4, res$
  SLEEP 4
   
  l$ = "0": GOSUB lev
  at$ = "A 87,": GOSUB at
  gpr$ = "LOC": GOSUB gpr
  mar$ = "*RST": GOSUB mar

 PRINT #4, "lin end"

 CLOSE
IF ctr$ = "1" THEN CHAIN "c:\qb\gpr4200\att"
CHAIN "c:\qb\gpr4200\menu"

END

