
'
'                      Level Accuracy
'                      --------------       ( Bandwidth )
'version 3
'4 May 95


COMMON sgcode$, atten$, sgen$, ch$, ctr$

sgen = VAL(sgcode$)

'sgen$ = "CH_039"
'sgen = 1
'atten$ = "27"

CLOSE
'

DIM r$(3, 20)
DIM r(3, 20)
DIM fr(20)
DIM xx$(20)

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
 OPEN "c:\qb\gpr4200\siggen\" + sgen$ FOR INPUT AS #5

lp = 1
DO
  INPUT #5, xx$(lp)
  lp = lp + 1
LOOP UNTIL lp = 10

sgfr$(1) = LEFT$(xx$(5), 3): sglv$(1) = RIGHT$(xx$(5), 5)
sgfr$(2) = LEFT$(xx$(9), 3): sglv$(2) = RIGHT$(xx$(9), 5)

 SLEEP 5
 GOTO test


mar:
 IF sgen = 2 THEN RETURN

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

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

at:
COLOR 13
  IOCTL #1, atten$ + CHR$(13)
  IOCTL #2, at$ + CHR$(13)
'  LOCATE 18, 50
'  PRINT at$
'  BEEP
  SLEEP 1
'  LOCATE 18, 50
'  PRINT "            "
  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)
mar$ = "cfrq " + fr$ + " mhz"

GOSUB adret
GOSUB mar
RETURN

lev:
adret$ = "A " + l$
GOSUB adret

mar$ = "rflv " + l$ + "dbm"
GOSUB mar
RETURN

gpr:

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
gpr$ = "REM":  GOSUB gpr

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

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

COLOR 14
title$ = "Bandwidth Level Accuracy"
PRINT #4, title$
LOCATE 5, 20
PRINT title$


gpr$ = "LD 2": GOSUB gpr
at$ = "A87,": GOSUB at
gpr$ = "FR 150000000": GOSUB gpr
SLEEP 5
fr$ = sgfr$(1): GOSUB freq
l$ = sglv$(1): GOSUB lev

fail = 1.5
lp = 1
DO
  LOCATE 7 + lp, 2
  COLOR 11
  PRINT fr$; " MHz"
  PRINT #4, fr$
 
  bwlp = 1
  DO
    fail$ = ""
    bw = bwlp
    rc$ = RIGHT$(rec$, 1)
    IF rc$ = "1" THEN
      IF bw = 4 THEN bw = 3
      IF bwlp = 3 THEN
        r$ = "----"
        GOTO result
      END IF
    END IF
   
    IF rc$ = "0" THEN
      IF bwlp > 2 THEN
        bw = 2
        r$ = "----"
        GOTO result
      END IF
    END IF

    gpr$ = "LD 2": GOSUB gpr
    gpr$ = "BW" + STR$(bw): GOSUB gpr
    BEEP
   SLEEP 5
    gpr$ = "CL": GOSUB gpr
    SLEEP 5
    gpr$ = "SG": GOSUB gpr

result:
    IF r$ = "----" THEN
      unit$ = " "
      COLOR 7
      LOCATE 7 + lp, (bwlp * 10) + 4
      PRINT r$
      GOTO sres
    ELSE
      COLOR 10
      unit$ = " dBæV"
    END IF
   
    LOCATE 7 + lp, (bwlp * 10) + 4
    res = VAL(r$)
    f = 20 - res
    IF f > fail OR f < -fail THEN
      fail$ = "!"
      COLOR 12
    ELSE
      fail$ = " "
      COLOR 10
    END IF

    PRINT USING "###.#"; res;
    PRINT fail$
sres:
    PRINT #4, r$
    PRINT #4, fail$
    bw = bw + 1
    bwlp = bwlp + 1
    
  LOOP UNTIL bwlp = 5


avpeak:

'
'                             Detector Level
'                             --------------

  PRINT #4, "Detector Level "

  det = 3
  DO
    det$ = STR$(det)
    gpr$ = "BW 1": GOSUB gpr
    gpr$ = "LD" + det$: GOSUB gpr
    gpr$ = "CL": GOSUB gpr
    SLEEP 5
  
average:
  av = 1
  DO
    gpr$ = "SG": GOSUB gpr
    res(av) = VAL(r$)
    SLEEP 1
    av = av + 1
  LOOP UNTIL av = 6
  aver! = res(1) + res(2) + res(3) + res(4) + res(5)
  aver! = aver! / 5
  f = 20 - aver!
  IF f > fail OR f < -fail THEN fail$ = "!" ELSE fail$ = " "

  COLOR 10
    LOCATE 7 + lp, (det * 10) + 24
    PRINT USING "###.#"; aver!;
    PRINT fail$
    aver$ = STR$(aver!)
    PRINT #4, aver$
    PRINT #4, fail$
    det = det + 1
  LOOP UNTIL det = 5

  gpr$ = "LD 2": GOSUB gpr
  fr$ = sgfr$(2): GOSUB freq
  l$ = sglv$(2): GOSUB lev

  gpr$ = "FR 230000000": GOSUB gpr
  lp = lp + 1
LOOP UNTIL lp = 3

gpr$ = "BW 1": GOSUB gpr
gpr$ = "LD 2": GOSUB gpr
gpr$ = "LOC": GOSUB gpr
mar$ = "*RST": GOSUB mar

PRINT #4, "bla end"
CLOSE

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

END









