-- Title: tstRF12sub.jal  to be included by tstRF12main.jal
-- Author H.v.Broekhuyzen (henk@henkzelf.nl)
-- Compiler: >=2.4m
--
-- This file is part of jallib  (http://jallib.googlecode.com)
-- Released under the BSD license (http://www.opensource.org/licenses/bsd-license.php)
--
-- Description: This files forms, together with tstRF12main.jal, tstRFcom.jal
--              and T0comInIsr.jal the test- and experiment- framework for
--              the files: spi_rf12b.jal and spi_sw_master.jal
--
-- Function: subroutines for the test-frame. Included by tstRF12main.jal
--

--*********************************************************************
procedure ReportCommandRecognised() is
  ComFlag = 0
  serial_hw_write(CFG_ControllerID)
end procedure
-- ***********************************************************************
Procedure Command_l() is  ; set length to send by command e
  if ComValIn > MaxPayloadSize then
    ComValIn = MaxPayloadSize
  end if
  LengthToSend = ComValIn
end procedure
-- ***********************************************************************
Procedure Command_t() is  ;  timeout (in ms) for response (used in command e)
  if ComValIn < 0 then
    ComValIn = 0
  elsif ComValIn > 6000 then
    ComValIn = 6000 ; prevent overflow
  end if
  TimeOutTicks = ComValIn * 5
end procedure

-- ***********************************************************************
procedure CheckForParameterCommand() is
  if ComFlag != 0 then
    case CommandIn of
    "b" : block ; bandwith in Receiver Control Command  (init sets 4)
                ; 1= 400, 2=340, 3=270,4=200, 5=134, 6=67 kHz
            SPI_RF12B_set_Bandwidth(ComValIn)
            Comflag = 0
          end block
    "d" : block ;   ;  dataRate Command
            SPI_RF12B_set_Datarate(ComValIn)
            Comflag = 0
          end block
    "f" : block ;  Frequency Setting Command
            SPI_RF12B_set_Frequency(ComValIn)
            Comflag = 0
          end block
    "l" : block ;  Set length to send by command e
            Command_l()
            Comflag = 0
          end block
    "p" : block ;  Set PrintInEchotestMasK
            PrintInEchotestMasK = ComValIn
            Comflag = 0
          end block
    "s" : block ;  report Status log (last one is now)
            SPI_RF12B_readStatus()
            SPI_RF12B_print_status_history()
            Comflag = 0
          end block
    "t" : block ;  timeout (in ms) for response (used in command e)
            Command_t()
            Comflag = 0
          end block
    "W" : block ;  Define waittime for command E (delay in send-back)
            Reply_delay = ComValIn
            Comflag = 0
          end block
    "w" : block ;  Define waittime for command e and T (delay in loop)
            Loop_delay = ComValIn
            Comflag = 0
          end block
    end case
  end if
end procedure
