'                       Noise
'                       -----

' version 2     (colour)
' 4 May 95


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

sgen = VAL(sgcode$)
'sgen = 1
'atten$ = "27"

DIM b(30)
SCREEN 9
COLOR 14, 1
CLS
OPEN "ieeectrl" FOR RANDOM AS #1
OPEN "ieeedata" FOR RANDOM AS #2
PRINT #1, "init" + CHR$(13)
PRINT #1, "clear" + CHR$(13)
PRINT #1, "to 10 end=13 eos=13" + CHR$(13)

ON ERROR GOTO bug

OPEN "COM2:9600,N,8,2" FOR RANDOM AS #3
OPEN "c:\qb\gpr\res\file" FOR APPEND AS #4
SLEEP 10


GOTO test

bug:
CLS
BEEP
PRINT "Buggered!!"
SLEEP
GOTO test

END

mar:
IF sgen = 2 THEN RETURN
  PRINT #1, "3" + CHR$(13)
  ON ERROR GOTO bug
  PRINT #2, mar$ + CHR$(13)
RETURN
 
adret:

IF sgen = 1 THEN RETURN
  PRINT #1, "3" + CHR$(13)
  ON ERROR GOTO bug
  PRINT #2, adret$ + CHR$(13)
RETURN

att:
  PRINT #1, atten$ + CHR$(13)
  ON ERROR GOTO bug
  PRINT #2, att$ + CHR$(13)
RETURN


test:
att$ = "A 100,": GOSUB att
mar$ = "*rst": GOSUB mar
SLEEP 2
mar$ = "rflv:OFF": GOSUB mar
adret$ = "F 10e6": GOSUB adret
adret$ = "A -70": GOSUB adret
gpr$ = "REM": GOSUB gpr

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

rec$ = LEFT$(r$, 4)
sn$ = RIGHT$(r$, 5)
fw$ = MID$(r$, 5, 5)
COLOR 15
PRINT " Receiver Type..... GPR"; rec$
PRINT " Serial No........."; sn$
PRINT " Firmware Version.."; fw$

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

PRINT #4, "Noise Floor"

freq:
i = 1
DO
  READ b(i)
  i = i + 1
LOOP UNTIL i = 14

noise:

COLOR 14
LOCATE 6, 20: PRINT "-------------- Noise Floor --------------"
COLOR 15
LOCATE 7, 20: PRINT "  7.5 kHz         15 kHz         25 kHz          120kHz"
LOCATE 8, 3
COLOR 11
PRINT " Test Freqency "

fail(1) = -3: ofs(1) = 12500
fail(2) = 0: ofs(2) = 25000
fail(3) = 2.5: ofs(3) = 50000
fail(4) = 9: ofs(4) = 150000

fr = 1
DO

  lp = 1
  DO
    rescol = 10
    fail$ = " "
    bw = lp
   
    rc$ = RIGHT$(rec$, 1)
    IF rc$ = "1" THEN
      IF bw = 4 THEN bw = 3

      IF lp = 3 THEN
        GOSUB bypass
        GOTO result
      END IF
    END IF
    
    IF rc$ = "0" OR rc$ = "6" THEN
      IF lp = 3 OR lp = 4 THEN
        IF bw > 2 THEN bw = 2
        GOSUB bypass
        GOTO result
      END IF
    END IF


    bw$ = STR$(bw)
    gpr$ = "BW " + bw$
    GOSUB gpr
   
    LOCATE 9 + fr, 5
    COLOR 11
    PRINT USING "###"; b(fr);
    PRINT " MHz"
 
    rc43$ = LEFT$(rec$, 2)
    IF rc43$ = "43" THEN
      IF fr = 6 OR fr = 7 OR fr = 8 THEN
        GOSUB bypass
        GOTO result
      END IF
    END IF
  
    b# = b(fr) * 1000000
    ofs = 0

       nlev(1) = -22
       nlev(2) = -16
       nlev(3) = -10
       nlev(4) = -5


birdy:
    bdy = 1
    bird(2) = 10
    DO
      f# = b# + ofs
      freq$(bdy) = STR$(f#)

      gpr$ = "FR " + freq$(bdy): GOSUB gpr
      IF bdy = 1 THEN
        gpr$ = "CL": GOSUB gpr
        SLEEP 6
fault:
        gpr$ = "RS": GOSUB gpr
        fu = 3
        DO
          fu$ = MID$(r$, fu, 1)
          IF fu$ <> "-" THEN
            IF fu$ = "L" THEN fault$ = "Battery"
            IF fu$ = "O" THEN fault$ = "Un Lock"
            IF fu$ = "R" THEN fault$ = "Range"
            IF fu$ = "U" THEN fault$ = "Un Cal"
            IF fu$ = "V" THEN fault$ = "Overload"
            BEEP
            LOCATE 22, 15
            COLOR 12
            PRINT "GPR "; fault$; " Fault at "; b(fr); " MHz"
            GOSUB bypass
            GOTO result
          END IF
          fu = fu + 1
        LOOP UNTIL fu = 8

      END IF
      gpr$ = "SG": GOSUB gpr
      bird(bdy) = VAL(r$)
   
      IF bird(1) < nlev(lp) THEN bdy = 4
      bdy = bdy + 1
      ofs = ofs + ofs(lp)

    LOOP UNTIL bdy >= 3
 
    IF bird(1) <= bird(2) THEN
      lev = bird(1)
      freq$ = freq$(1)
      flg$ = " "
    ELSE
      lev = bird(2)
      freq$ = freq$(2)
      flg$ = "*"
    END IF

    IF lev > fail(lp) THEN
      fail$ = "!"
      rescol = 12
    END IF
   
    COLOR rescol
    LOCATE 9 + fr, 5 + (lp * 15)
    PRINT USING "###.##"; lev;
    PRINT " dB"; CHR$(230); "V";
    PRINT flg$; fail$
   
result:
    PRINT #4, r$
    PRINT #4, flg$
    PRINT #4, fail$

    lp = lp + 1
  LOOP UNTIL lp = 5

  fail(1) = -11.5
  fail(2) = -8.5
  fail(3) = -6
  fail(4) = .5

  fr = fr + 1
LOOP UNTIL fr = 14

gpr$ = "BW 1": GOSUB gpr
gpr$ = "LOC": GOSUB gpr
SLEEP 4
PRINT #4, "noise end"


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

END

keypress:
k$ = "x"
DO
k$ = INKEY$
LOOP UNTIL k$ = " "
LOCATE 23, 15
PRINT ""
RETURN

bypass:
   flg$ = "-"
   r$ = "----"
   COLOR 13
   LOCATE 9 + fr, 5 + (lp * 15)
   PRINT r$
RETURN

gpr:

PRINT #3, gpr$
SLEEP 1
INPUT #3, r$
er$ = LEFT$(r$, 1)
  IF er$ <> "E" THEN RETURN
  IF gpr$ = "REM" THEN RETURN

  BEEP
   COLOR 15
   PRINT TAB(20); "GPR error code      "; gpr$
  BEEP
  SLEEP

RETURN

DATA 20,50,105,150,210,240,325,390,451,610,720,910,999

