'
'                      Intermod
'

'version 2 (colour)
'4 May 95

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

sgen = VAL(sgcode$)

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

DIM fr(20)
DIM r(13)
DIM r$(20)
DIM res$(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\gpr\res\file" FOR APPEND AS #4

 SLEEP 5
 GOTO test

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

RETURN

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

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

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

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


gpr:
   PRINT #3, gpr$
   SLEEP 1
   INPUT #3, r$
   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
gpr$ = "REM": GOSUB gpr
martop$ = "*RST": GOSUB martop
martop$ = "imode normal": GOSUB martop
martop$ = "mod:OFF": GOSUB martop
IF mart$ = "0" THEN martop$ = "FSTD ext10" ELSE martop$ = "FSTD ext10dir"
GOSUB martop

marbot$ = "*RST": GOSUB marbot
marbot$ = "imode normal": GOSUB marbot
marbot$ = "mod:OFF": GOSUB marbot
marbot$ = "FSTD int10": GOSUB marbot

SLEEP 2

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$
PRINT "Firmware version        "; fv$

COLOR 14
title$ = "Intermod"
LOCATE 5, 20
PRINT title$
PRINT #4, title$


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

lp = 1
DO
  READ fr(lp)
  lp = lp + 1
LOOP UNTIL lp = 12


lp = 1
DO
  adjlp = 1
  at$ = "A 0,": GOSUB at

' turn off sig gens
teststart:
  martop$ = "rflv:OFF": GOSUB martop
  marbot$ = "rflv:OFF": GOSUB marbot
  adrtop$ = "A -120": GOSUB adrtop
  adrbot$ = "A -120": GOSUB adrbot
 
  IF adjlp = 11 THEN
    at$ = "A 3,": GOSUB at
  END IF

  rescol = 13
  res$(lp) = "----"
 
  lev = 1
  rc43$ = LEFT$(rec$, 2)
  IF rc43$ = "43" THEN
    IF lp = 8 OR lp = 7 THEN GOTO result
  END IF
 
  fr1 = fr(lp)
 
birdy:
  bdy = 1
  ofs = .1
  bird(2) = 0
  DO
    gpf = fr1 + ofs
    gpf = gpf * 10000
    gpf&(bdy) = gpf * 100
    gpf$(bdy) = STR$(gpf&(bdy))

    gpr$ = "FR " + gpf$(bdy): GOSUB gpr
    SLEEP 6
    gpr$ = "CL": GOSUB gpr
    SLEEP 6
    gpr$ = "SG": GOSUB gpr
    bird(bdy) = VAL(r$)
      IF bird(1) < -22 THEN bdy = 4
    bdy = bdy + 1
    ofs = ofs + .0125
  LOOP UNTIL bdy >= 3
 
  IF bird(1) > bird(2) THEN
    bdy$ = "*"
    fr& = gpf&(2)
  ELSE
    bdy$ = " "
    fr& = gpf&(1)
  END IF
 
  fr& = fr& - 100000
  gpf$ = STR$(fr&)
  gpr$ = "FR" + gpf$: GOSUB gpr
  SLEEP 6
  gpr$ = "CL": GOSUB gpr
  SLEEP 6
  
fault:
  gpr$ = "RS": GOSUB gpr
  fu = 2
  DO
    uc$ = MID$(r$, fu, 1)
    IF uc$ <> "-" THEN
      BEEP
      LOCATE 7 + lp, 44
        IF uc$ = "U" THEN fault$ = "Un Cal"
        IF uc$ = "L" THEN fault$ = "Battery"
        IF uc$ = "O" THEN fault$ = "Lock"
        IF uc$ = "R" THEN fault$ = "Range"
        IF uc$ = "V" THEN fault$ = "Overload"
        COLOR 12
      PRINT "GPR ( "; fault$; " ) Fault at"; fr(lp); " MHz"
      BEEP
      lev = 1
      GOTO sigset
    END IF
    fu = fu + 1
  LOOP UNTIL fu = 8
 
sigset:
  fr1$ = STR$(fr&)
  fr2& = fr& + 50000
  fr3& = fr& + 100000
  fr2$ = STR$(fr2&)
  f3$ = STR$(fr3&)

  marbot$ = "cfrq " + fr1$ + " Hz": GOSUB marbot
  marbot$ = "rflv -30 dbm": GOSUB marbot
  martop$ = "cfrq " + fr2$ + " Hz": GOSUB martop
  martop$ = "rflv -30 dbm": GOSUB martop

  adrbot$ = "F" + fr1$: GOSUB adrbot
  adrtop$ = "F" + fr2$: GOSUB adrtop
 
  martop$ = "rflv:ON": GOSUB martop
  marbot$ = "rflv:ON": GOSUB marbot
  adrtop$ = "A -32": GOSUB adrtop
  adrbot$ = "A -32": GOSUB adrbot
  SLEEP 2

adj2:
 
    lv = 59
    sglev = -32
    adjlp = 1
    DO
      SLEEP 1
      gpr$ = "SG": GOSUB gpr
      adlev = VAL(r$)
      inlev = lv - adlev
      sglev = sglev + inlev
        sglev = sglev * 10
        sglev% = sglev
        sglev = sglev / 10

      IF inlev <> 0 THEN
        l$ = STR$(sglev)
        adrbot$ = "A" + l$: GOSUB adrbot
        marbot$ = "rflv " + l$ + " dbm": GOSUB marbot
        SLEEP 2
        sglev = sglev
      END IF
      adjlp = adjlp + 1
      IF adjlp = 11 THEN GOTO teststart
   
    LOOP UNTIL inlev = 0
    BEEP
   
    gpr$ = "FR " + fr2$
    GOSUB gpr
 
 
adj1:
    lv = 59
    sglev = -32
    adjlp = 1
    DO
     SLEEP 1
     gpr$ = "AT N": ' GOSUB gpr
     gpr$ = "SG": GOSUB gpr
     adlev! = VAL(r$)
     inlev! = lv - adlev!
     inlev! = sglev + inlev!

     IF adlev! <> lv THEN
       l$ = STR$(inlev!)
       adrtop$ = "A" + l$: GOSUB adrtop
       martop$ = "rflv " + l$ + " dbm": GOSUB martop
       SLEEP 2
       sglev = inlev!
     END IF
      adjlp = adjlp + 1
      IF adjlp = 11 THEN GOTO teststart

  LOOP UNTIL adlev! = lv
  BEEP
 
  gpr$ = "FR " + f3$
  GOSUB gpr
 
  lev = 0
  SLEEP 1
  gpr$ = "SG": GOSUB gpr
  res = 59 - VAL(r$)
  resl = VAL(r$)

result:
  COLOR 11
  LOCATE 7 + lp, 10
  PRINT fr(lp); " MHz";
  PRINT "  "; bdy$;
  PRINT TAB(30);
 
 
  IF lev = 1 THEN
     COLOR 13
     PRINT res$(lp);
     PRINT TAB(50);
     PRINT res$(lp)
     r$ = res$(lp)

  ELSE
    cr = 10
    COLOR cr
    PRINT USING "###.#"; resl;
    PRINT TAB(50);
    PRINT USING "###.#"; res;
    PRINT " dBæV"
    res$(lp) = STR$(res)
  END IF
 
  lev = 0
  frs$ = STR$(fr(lp))
  PRINT #4, frs$, r$, res$(lp)
  PRINT #4, bdy$
  lp = lp + 1
LOOP UNTIL lp = 12
    
martop$ = "*RST": GOSUB martop
marbot$ = "*RST": GOSUB marbot
at$ = "A 100,": GOSUB at
gpr$ = "LOC": GOSUB gpr

PRINT #4, "Inter end"
CLOSE

DATA 27,75,95,130,170,220,250,350,440,700,999
SLEEP 5

IF ctr$ = "1" THEN CHAIN "C:\qb\gpr\results"
CHAIN "c:\qb\gpr\menu"

END

