'###################################################################################################################################### ' W0IVJ TELEPHONE INTERFACE SOFTWARE ' Version 2.5 ' 021212 '##################################################################################################################################### Public Const ToneDecodeReady as Byte = 5 'tone decoder ready pin Public Const SerialClock as Byte = 6 'serial clock for tone decoder and voice annunciator pin Public Const ToneDecode as Byte = 7 'tone decode address data serial input pin Public Const RingDetector as Byte = 8 'ring detector pin (low = ringing) Public Const HangUp as Byte = 9 'hang up detector pin Public Const VoiceOut as Byte = 10 'voice annunciator enable pin Public Const VoiceOutAddress as Byte = 11 'voice annunciator address data serial output pin 'com3 receive data pin Public Const Com3Tx as Byte = 12 'com 3 transmit data pin Public Const Com3Rx as Byte = 13 'com 3 transmit data pin Public Const RelayPower as Byte = 14 'relay power enable pin Public Const Audio as Byte = 15 'audio connect relay pin Public Const VoiceEnable as Byte = 16 'voice annunciator enable relay pin Public Const Answer as Byte = 17 'answer relay pin Public Const Tranceiver as Byte = 18 'tranceiver on relay pin Public Const Amplifier as Byte = 19 'amplifier on relay pin Public Const VoiceMessageEnd as Byte = 20 'voice annunciator end-of-message pin (low = end) Public AnswerFlag as Boolean 'true when interface has answered the phone Public TransceiverKeyed as Boolean 'true when transceiver is keyed Public AmpOn as Boolean 'true when amplifier is on Public SetUpMode as Boolean 'double digit command flag Public VfoA as Boolean 'true when VFO A is selected Dim OCom3(1 To 25) as Byte 'output com buffer Dim ICom3(1 To 25) as Byte 'input com buffer Sub Main() Dim Tones as Boolean 'tones present flag Dim Reset as Boolean 'reset condition flag Dim BadTone as Boolean 'bad tone flag Dim DecodedTone as Byte 'decoded tone value Dim PassWord as Boolean 'password flag Dim PassWordOne as Byte 'first tone in password Dim PassWordTwo as Byte 'second tone in password Dim StartTime as Single 'start of the time out sequence Dim MaxTime as Single 'maximum time allowed before time out Dim ElapsedTime as Single 'elapsed time since start time Dim AddrArray(1 TO 15) as Integer Call OpenQueue(Ocom3, 25) 'open com3 output queue Call OpenQueue(ICom3, 25) 'open com3 input queue Call DefineCom3(Com3Rx, Com3Tx, bx10001000) 'define com3 parameters Call OpenCom(3, 4800, ICom3, OCom3) 'open com3 port at 4800 baud MaxTime = 8.0 'time out time = 30 seconds ElapsedTime = 0.0 'initialize elapsed time TransceiverKeyed = False 'flag tranceiver not keyed AmpOn = False 'flag amplifier as off PassWordOne = 1 'first tone in password PassWordTwo = 9 'second tone in password Call PutPin(SerialClock, bxOutPutLow) 'initialize serial clock pin Do Tones = False 'set for no tones Reset = False 'set for no reset condition AnswerFlag = False Password = False Call PutPin(RelayPower, bxOutPutHigh) 'make relay power control pin high Call PutPin(VoiceOut, bxOutPutHigh) 'make voice enable pin high Call LineStatus(Tones, Reset) 'look for ringing or tones If (Tones = False) AND (Reset = False) Then Call PulseOut(RelayPower, 1, 0) 'turn on relay power Call PutPin(Answer, bxOutPutHigh) 'interface answers the phone AnswerFlag = True 'set answer flag Call Delay(0.5) 'wait 1/2 second Call PutPin(Audio, bxOutPutHigh) 'connect audio circuits to phone line Call PutPin(VoiceEnable, bxOutPutHigh) 'mute mic and xcvr audio AddrArray(1) = 1 AddrArray(2) = 48 ' "Password" Call VoiceResponse(AddrArray) 'give voice response Call PutPin(VoiceEnable, bxOutPutLow) 'unmute mic and xcvr audio Call PutPin(Audio, bxOutPutLow) 'disconnect audio circuits from phone line ElseIf (Tones = True) AND (Reset = False) Then PassWord = False Do Call ToneDecoder(DecodedTone, BadTone, Reset) 'decode tone If BadTone = False Then If DecodedTone = PassWordOne Then StartTime = Timer 'start timer Call ToneDecoder(DecodedTone, BadTone, Reset) 'decode tones Call TimeCheck(StartTime, ElapsedTime) 'check elapsed time since start If (BadTone = False) AND (ElapsedTime <= MaxTime) Then If DecodedTone = PassWordTwo Then PassWord = True 'set password ok flag End If End If End If End If Loop Until (PassWord = True) OR (Reset = True) End If If PassWord = True Then Call PulseOut(RelayPower, 1, 0) 'turn on relay power Call PutPin(Answer, bxOutPutHigh) 'interface answers the phone AnswerFlag = True 'set answer flag Call PutPin(Audio, bxOutPutHigh) 'connect audio circuits to phone line Call Delay(0.5) 'wait 1/2 second Call PutPin(VoiceEnable, bxOutPutHigh) 'mute mic and xcvr audio AddrArray(1) = 4 AddrArray(2) = 49 ' "W0IVJ Remote" AddrArray(3) = 46 ' "------------" AddrArray(4) = 44 ' "command" AddrArray(5) = 30 ' "mode" Call VoiceResponse(AddrArray) 'give voice response Call PutPin(VoiceEnable, bxOutPutLow) 'unmute mic and xcvr audio SetUpMode = True Do Select Case SetUpMode Case True Call PutPin(VoiceEnable, bxOutPutHigh) 'connect voice annuciator to line, mute mic Call DoubleToneCommand(SetUpMode, Reset, AddrArray) Case False Call PutPin(VoiceEnable, bxOutPutLow) 'connect transceiver audio to line, activate mic Call SingleToneCommand(SetUpMode, Reset, AddrArray) End Select Loop Until Reset = True End If If (Reset = True) AND (AnswerFlag = True) Then Call TerminateSession() End If Loop End Sub '************************************************************* 'The routine LineStatus checks the phone line for rings or tones. If rings 'are detected they are counted. If the maximum number of rings are detected, 'the interface sets the Tone Flag to False and exits. 'If the tones are detected, the interface sets the Tone Flag to True and exits. 'The program stays in this routine until either the maximum number of rings 'occurs, tones are detected, or the timeout occurs which sets Reset = True Sub LineStatus(Tones as Boolean, Reset as Boolean) Dim RingCount as Byte 'ring counter Dim Ringing as Boolean 'ringing flag Dim MaxRings as Boolean 'maximum number of ring flag Dim StartTime as Single 'start of the time out sequence Dim MaxTime as Single 'maximum time allowed before time out Dim MaxRingCount as Byte 'maximum rings allowed before answer Dim ElapsedTime as Single 'elapsed time since start time MaxRingCount = 5 'set maximum number of rings before answer MaxTime = 30.0 'time out time = 30 seconds ElapsedTime = 0.0 'initialize elapsed time RingCount = MaxRingCount 'maximum rings allowed before answer Ringing = False 'initialize ringing flag Do Do If (GetPin(RingDetector) = 0) AND (AnswerFlag = False) Then Ringing = True 'set flag if ring detected ElseIf GetPin(ToneDecodeReady) = 0 Then Call PutPin(VoiceEnable, bxOutPutHigh) 'mute mic Tones = True 'set flag if tone detected RingCount = MaxRingCount 'set so elapsed time will not be checked ElseIf ElapsedTime >= MaxTime Then Reset = True 'set reset flag if time out occurs ElseIf GetPin(HangUp) = 1 Then If AnswerFlag = True Then Reset = True End If End If If RingCount < MaxRingCount Then Call TimeCheck(StartTime, ElapsedTime) 'check elapsed time since start End If Loop Until (Ringing = True) OR (Tones = True) OR (Reset = True) 'fall out of loop if any single condition is met If Ringing = True Then Do Loop Until GetPin(RingDetector) = 1 'wait for ring to quit If RingCount = MaxRingCount Then StartTime = Timer 'set start time End If RingCount = RingCount - 1 'tally ring Ringing = False 'reset ring flag End If Loop Until (RingCount = 0) OR (Tones = True) OR (Reset = True) 'fall out of loop if any single condition is met End Sub '******************************************************************************************** 'The routine ToneDecoder decodes the telephone touch tone that has been detected. 'The ToneDecodeReady goes low when a tone is detected and goes back high when the tone 'is valid. If 10 seconds has elapsed between detectio and validation, the tone is BadToneed, 'and the Reset = True flag is set. Sub ToneDecoder(DecodedTone as Byte, BadTone as Boolean, Reset as Boolean) Dim StartTime as Single 'start of the time out sequence Dim MaxTime as Single 'maximum time allowed before time out Dim ElapsedTime as Single 'elapsed time since start time MaxTime = 10.0 'time out time = 10 seconds ElapsedTime = 0.0 'initialize elapsed time BadTone = False StartTime = Timer Do If AnswerFlag = True Then If GetPin(HangUp) = 1 Then Reset = True End If ElseIf AnswerFlag = False Then Call TimeCheck(StartTime, ElapsedTime) 'check elapsed time since start If (ElapsedTime >= MaxTime) AND (GetPin(HangUp) = 1) Then Reset = True End If End If Loop Until (GetPin(ToneDecodeReady) = 0) OR (Reset = True) If Reset = False Then StartTime = Timer 'start time out Do Call TimeCheck(StartTime, ElapsedTime) 'check elapsed time since start If ElapsedTime >= MaxTime Then BadTone = True End if Loop Until (GetPin(ToneDecodeReady) = 1) OR (BadTone = True) If BadTone = False Then DecodedTone = (ShiftIn(ToneDecode, SerialClock, 8)) \ 2 'correct for extra shift on register If (DecodedTone >= 1) AND (DecodedTone <= 12) Then BadTone = False Else BadTone = True End If End If If SetUpMode = False Then Call PutPin(VoiceEnable, bxOutPutLow) 'reactivate mic and transceiver audio End If End If End Sub '********************************************************************************************* 'The routine TerminateSession resets all relays and waits for a hang up signal. Sub TerminateSession() Call PutPin(Answer, bxOutPutHigh) 'interface answers the phone Call Delay(0.5) 'wait 1/2 second Call PutPin(Audio, bxOutPutLow) 'reset audio relay Call PutPin(VoiceEnable, bxOutPutLow) 'reset voice annunciator relay Call PutPin(Tranceiver, bxOutPutLow) 'reset tranceiver relay Call PutPin(Amplifier, bxOutPutLow) 'reset amplifier relay Do Loop Until GetPin(HangUp) = 1 'wait for hang up Call PutPin(Answer, bxOutPutLow) 'reset answer relay End Sub '********************************************************************************************** 'The routine TimeCheck reads the elapsed time since start time Sub TimeCheck(StartTime as Single, ElapsedTime as Single) ElapsedTime = Timer - StartTime 'calculate elapsed time since start If ElapsedTime < 0.0 Then ElapsedTime = ElapsedTime + 86400.0 'correct for midnight roll over End If End Sub '********************************************************************************************** 'The routine SingleToneCommand inputs single tones and executes the command associated with them. Sub SingleToneCommand(SetUpMode as Boolean, Reset as Boolean, AddrArray() as Integer) Dim BadTone as Boolean Dim DecodedTone as Byte Dim XCommand as String Dim ComArg as String Dim ComArgNum as Integer Dim M as Byte Dim N as Integer Dim BadComm as Boolean Dim CArg as Byte Dim Reading as Byte Dim ReadingPeak as Byte BadComm = False Call ToneDecoder(DecodedTone, BadTone, Reset) 'decode tone If Reset = False Then Select Case DecodedTone Case 1 Do Call PutQueueStr(OCom3, "UP;") 'send tune up command to transceiver Call Delay(0.1) 'delay for slow tuning Loop Until (GetPin(ToneDecodeReady) = 0) OR (Reset = True) 'any tone or hangup stops tuning If Reset = False Then Call PutPin(VoiceEnable, bxOutPutHigh) 'mute mic and xcvr audio Do 'delay until tone quits Loop Until GetPin(ToneDecodeReady) = 1 Call PutPin(VoiceEnable, bxOutPutlow) 'reactivate mic and xcvr audio End If Case 2 'set flag for setup mode SetUpMode = True Case 3 Do Call PutQueueStr(OCom3, "DN;") 'send tune down command to transceiver Call Delay(0.1) 'delay for slow tuning Loop Until (GetPin(ToneDecodeReady) = 0) OR (Reset = True) 'any tone or hangup stops tuning If Reset = False Then Call PutPin(VoiceEnable, bxOutPutHigh) 'mute mic and xcvr audio Do 'delay until tone quits Loop Until GetPin(ToneDecodeReady) = 1 Call PutPin(VoiceEnable, bxOutPutlow) 'reactivate mic and xcvr audio End If Case 4 'give VFO A frequency XCommand = "FR0;" 'compile the command Call TransCommNoResp(BadComm, XCommand) 'send command with no response VfoA = True 'set VFO A flag Call Delay(0.2) XCommand = "FA;" 'compile the command ComArgNum = 14 Call TransCommResp(ComArg, ComArgNum, BadComm, XCommand) 'send the command and get the response If BadComm = False Then ComArg = Mid(ComArg, 4, 1) 'get msb of frequency CArg = Asc(ComArg) - 48 'convert to a number Select Case CArg Case 0 XCommand = "MD1;" Call TransCommNoResp(BadComm, XCommand) 'send command with no response Case Else XCommand = "MD2;" Call TransCommNoResp(BadComm, XCommand) 'send command with no response End Select End If If BadComm = True Then Call CommandError(AddrArray) 'set up command error response Call VoiceResponse(AddrArray) 'give voice response End If Case 5 'get S meter reading Call PutPin(VoiceEnable, bxOutPutHigh) 'mute mic and xcvr audio ReadingPeak = 0 For M = 1 to 10 XCommand = "SM;" For N = 1 TO 5 Call PutQueueStr(OCom3, XCommand) 'send a command to set the correct vfo or memory to transmit ComArgNum = 7 Call CommandResponse(ComArg, ComArgNum, BadComm) 'receive the response from the tranceiver Next If BadComm = True Then Exit For End If Call Meter(ComArg, Reading) 'get meter reading If Reading > ReadingPeak Then ReadingPeak = Reading 'get peak meter readings End If Next If BadComm = False Then If TransceiverKeyed = False Then Call SMeter(ReadingPeak, AddrArray) 'compute S-meter reading ElseIf TransceiverKeyed = True Then Call PowerMeter(ReadingPeak, AddrArray) 'compute power reading End If ElseIf BadComm = True Then Call CommandError(AddrArray) End If Call VoiceResponse(AddrArray) 'give voice response Call PutPin(VoiceEnable, bxOutPutLow) 'unmute mic and xcvr audio Case 6 'give VFO B frequency For N = 1 TO 5 XCommand = "FR1;" 'compile the command Call PutQueueStr(OCom3, XCommand) 'send a command to put VFO B in receive Next VfoA = False 'set VFO B flag Call Delay(0.2) XCommand = "FB;" 'compile the command ComArgNum = 14 Call TransCommResp(ComArg, ComArgNum, BadComm, XCommand) 'send the command and get the response If BadComm = False Then ComArg = Mid(ComArg, 4, 1) 'get msb of frequency CArg = Asc(ComArg) - 48 'convert to a number Select Case CArg Case 0 XCommand = "MD1;" Call TransCommNoResp(BadComm, XCommand) 'send command with no response Case Else XCommand = "MD2;" Call TransCommNoResp(BadComm, XCommand) 'send command with no response End Select End If If BadComm = True Then Call PutPin(VoiceEnable, bxOutPutHigh) 'mute mic and xcvr audio Call CommandError(AddrArray) 'set up command error response Call VoiceResponse(AddrArray) 'give voice response Call PutPin(VoiceEnable, bxOutPutLow) 'unmute mic and xcvr audio End If Case 7 Do Call PutQueueStr(OCom3, "UP;") 'send tune up command to transceiver Loop Until (GetPin(ToneDecodeReady) = 0) OR (Reset = True) 'any tone or hangup stops tuning If Reset = False Then Call PutPin(VoiceEnable, bxOutPutHigh) 'mute mic and xcvr audio Do 'delay until tone quits Loop Until GetPin(ToneDecodeReady) = 1 Call PutPin(VoiceEnable, bxOutPutlow) 'reactivate mic and xcvr audio End If Case 8 Call PutPin(VoiceEnable, bxOutPutHigh) 'mute mic and xcvr audio AddrArray(2) = 27 ' "vfo" If VfoA = True Then AddrArray(3) = 25 ' "a" XCommand = "FA;" ElseIf VfoA = False Then AddrArray(3) = 26 ' "b" XCommand = "FB;" End If AddrArray(4) = 23 ' "is" ComArgNum = 14 Call TransCommResp(ComArg, ComArgNum, BadComm, XCommand) 'send the command and get the response If BadComm = False Then Call FreqArgAddr(ComArg, AddrArray, XCommand) 'compile the voice frequency readback ElseIf BadComm = True Then Call CommandError(AddrArray) End If Call VoiceResponse(AddrArray) 'give voice response Call PutPin(VoiceEnable, bxOutPutLow) 'unmute mic and xcvr audio Case 9 Do Call PutQueueStr(OCom3, "DN;") 'send tune down command to transceiver Loop Until (GetPin(ToneDecodeReady) = 0) OR (Reset = True) 'any tone or hangup stops tuning If Reset = False Then Call PutPin(VoiceEnable, bxOutPutHigh) 'mute mic and xcvr audio Do 'delay until tone quits Loop Until GetPin(ToneDecodeReady) = 1 Call PutPin(VoiceEnable, bxOutPutlow) 'reactivate mic and xcvr audio End If Case 10 'read power reading Call PutPin(VoiceEnable, bxOutPutHigh) 'mute mic and xcvr audio XCommand = "MD5;" 'change mode to AM Call TransCommNoResp(BadComm, XCommand) 'send command with no response If BadComm = False Then Call Delay(0.2) XCommand = "TX;" 'key transceiver Call TransCommNoResp(BadComm, XCommand) 'send command with no response Call Delay(1.0) 'delay 1 second for power settle ReadingPeak = 0 For M = 1 to 10 XCommand = "SM;" ComArgNum = 7 Call TransCommResp(ComArg, ComArgNum, BadComm, XCommand) 'send the command and get the response If BadComm = True Then Exit For End If Call Meter(ComArg, Reading) 'get meter reading If Reading > ReadingPeak Then ReadingPeak = Reading 'get peak meter readings End If Next End If If BadComm = False Then Call PowerMeter(ReadingPeak, AddrArray) 'compute power reading XCommand = "RX;" 'unkey transceiver Call TransCommNoResp(BadComm, XCommand) 'send command with no response If BadComm = False Then If VfoA = True Then XCommand = "FA;" 'frequency of VFO A ElseIf VfoA = False Then XCommand = "FB;" 'frequency of VFO B End If ComArgNum = 14 Call TransCommResp(ComArg, ComArgNum, BadComm, XCommand) 'send the command and get the response If BadComm = False Then ComArg = Mid(ComArg, 4, 1) 'get msb of frequency CArg = Asc(ComArg) - 48 'convert to a number Select Case CArg Case 0 XCommand = "MD1;" Call TransCommNoResp(BadComm, XCommand) 'send command with no response Case Else XCommand = "MD2;" Call TransCommNoResp(BadComm, XCommand) 'send command with no response End Select End If End If End If If BadComm = True Then Call CommandError(AddrArray) 'set up command error response End If Call VoiceResponse(AddrArray) 'give voice response Call PutPin(VoiceEnable, bxOutPutLow) 'unmute mic and xcvr audio Case 11 'key or unkey the transmitter If TransceiverKeyed = False Then Call PutQueueStr(OCom3, "TX;") 'key TransceiverKeyed = True 'flag transceiver keyed ElseIf TransceiverKeyed = True Then Call PutQueueStr(OCom3, "RX;") 'unkey TransceiverKeyed = False 'flag transceiver unkeyed End If Case 12 'turn amplifier on or off Call PutPin(VoiceEnable, bxOutPutHigh) 'mute mic and xcvr audio If AmpOn = False Then Call PutPin(Amplifier, bxOutPutHigh) 'turn amplifier on AmpOn = True 'flag amplifier on AddrArray(1) = 1 AddrArray(2) = 20 ' "on" Call VoiceResponse(AddrArray) ElseIf AmpOn = True Then Call PutPin(Amplifier, bxOutPutLow) 'turn amplifier off AmpOn = False 'flag amplifier off AddrArray(1) = 1 AddrArray(2) = 21 ' "off" Call VoiceResponse(AddrArray) End If Call PutPin(VoiceEnable, bxOutPutLow) 'unmute mic and xcvr audio End Select End If End Sub '********************************************************************************************** 'The routine DoubleToneCommand inputs single tones and executes the command associated with them. 'The command is two numbers followed by an argument if an argument is required. All commands are 'terminated by # which is decoded as 12. Sub DoubleToneCommand(SetUpMode as Boolean, Reset as Boolean, AddrArray() as Integer) Dim BadTone as Boolean Dim BadComm as Boolean Dim DecodedTone as Byte Dim Command as Byte Dim CommandString as String Dim Cmd1 as String * 1 Dim Cmd2 as String * 1 Dim SL as Integer Dim N as Integer Dim M as Byte Dim Commd1 as Byte Dim Commd2 as Byte Dim CArg as Byte Dim CArg2 as Byte Dim ComArg as String Dim ComArgNum as Integer Dim XCommand as String Dim Reading as Byte Dim ReadingPeak as Byte BadComm = False 'initialize flag CommandString = "" 'initialize string AddrArray(1) = 0 'set number of words in response sentence N = 0 'initialize command element counter Do Call ToneDecoder(DecodedTone, BadTone, Reset) If (BadTone = False) AND (Reset = False) Then If DecodedTone <> 12 Then Select Case DecodedTone Case 1 TO 9 'convert tone to string Cmd1 = CStr(DecodedTone) Case 10 'fill last character with zero Cmd1 = "0" Case 11 'put in decimal place Cmd1 = "*" End Select CommandString = CommandString & Cmd1 N = N + 1 End If End If Loop Until (DecodedTone = 12) OR (Reset = True) OR (N > 11) If N > 11 Then CommandString = "88" End If If Reset = False Then ComArg = " " 'set com argument to default space SL = Len(CommandString) 'compute length of the command string Cmd1 = Mid(CommandString, 1, 1) 'extract first digit of command Cmd2 = Mid(CommandString, 2, 1) 'extract second digit of command Commd1 = Asc(Cmd1) - 48 'convert first digit to a number Commd2 = Asc(Cmd2) - 48 'convert second digit to a number Command = (10 * Commd1) + Commd2 'build two digit command as a number If SL - 2 <> 0 Then ComArg = Mid(CommandString, 3, (SL - 2)) 'extract the command argument if there is one End If Select Case Command 'the following executes the command Case 11 'VFO A frequency AddrArray(2) = 27 ' "vfo" AddrArray(3) = 25 ' "a" AddrArray(4) = 23 ' "is" If (SL - 2) = 0 Then XCommand = "FA;" 'compile the command ComArgNum = 14 'number of characters in response Call TransCommResp(ComArg, ComArgNum, BadComm, XCommand) 'send the command and get the response ElseIf ((SL-2) >= 2) OR ((SL-2) <= 9) Then Call ComArgFormat(ComArg, CommandString) 'format the command argument into the proper format Xcommand = "FA" & ComArg & ";" 'send a command to set the frequency in VFO A Call TransCommNoResp(BadComm, XCommand) 'send command with no response If BadComm = False Then Call Delay(0.2) 'delay for acceptance of command XCommand = "FA;" 'compile the command ComArgNum = 14 'number of characters in response Call TransCommResp(ComArg, ComArgNum, BadComm, XCommand) 'send the command and get the response End If ElseIf SL > 9 Then BadComm = True End If If BadComm = False Then Call FreqArgAddr(ComArg, AddrArray, XCommand) 'compile the voice frequency readback ElseIf BadComm = True Then Call CommandError(AddrArray) End If Call VoiceResponse(AddrArray) 'give voice response Case 12 'VFO B frequency AddrArray(2) = 27 ' "vfo" AddrArray(3) = 26 ' "b" AddrArray(4) = 23 ' "is" If (SL - 2) = 0 Then XCommand = "FB;" 'compile the command ComArgNum = 14 'number of characters in response Call TransCommResp(ComArg, ComArgNum, BadComm, XCommand) 'send the command and get the response ElseIf ((SL-2) >= 2) OR ((SL-2) <= 9) Then Call ComArgFormat(ComArg, CommandString) 'format the comm argument into the proper format XCommand = "FB" & ComArg & ";" 'send a command to set the frequency in VFO B Call TransCommNoResp(BadComm, XCommand) 'send command with no response If BadComm = False Then Call Delay(0.2) 'delay for acceptance of command XCommand = "FB;" 'compile the command ComArgNum = 14 'number of characters in response Call TransCommResp(ComArg, ComArgNum, BadComm, XCommand) 'send the command and get the response End If ElseIf SL > 9 Then BadComm = True End If If BadComm = False Then Call FreqArgAddr(ComArg, AddrArray, XCommand) 'compile the voice frequency readback ElseIf BadComm = True Then Call CommandError(AddrArray) End If Call VoiceResponse(AddrArray) 'give voice response Case 13 'mode XCommand = "MD" & ComArg & ";" 'compile the command Call TransCommNoResp(BadComm, XCommand) 'send command with no response CArg = Asc(ComArg) - 48 'convert to a number Select Case CArg Case 1 ' "mode is lower sideband" AddrArray(1)= 4 AddrArray(2)= 30 AddrArray(3)= 23 AddrArray(4)= 14 AddrArray(5)= 34 Case 2 ' "mode is upper sideband" AddrArray(1)= 4 AddrArray(2)= 30 AddrArray(3)= 23 AddrArray(4)= 15 AddrArray(5)= 34 Case 3 ' "mode is cw" AddrArray(1)= 3 AddrArray(2)= 30 AddrArray(3)= 23 AddrArray(4)= 18 Case 4 ' "mode is fm" AddrArray(1)= 3 AddrArray(2)= 30 AddrArray(3)= 23 AddrArray(4)= 17 Case 5 ' "mode is am" AddrArray(1)= 3 AddrArray(2)= 30 AddrArray(3)= 23 AddrArray(4)= 16 Case 6 ' "mode is fsk" AddrArray(1)= 3 AddrArray(2)= 30 AddrArray(3)= 23 AddrArray(4)= 19 End Select Call VoiceResponse(AddrArray) 'give voice response Case 14 Call PutPin(VoiceEnable, bxOutPutLow) 'reactivate mic and xcvr audio Call Delay(0.5) 'delay for 1/2 second for relay XCommand = "UP;" 'tune up command Do Call TransCommNoResp(BadComm, XCommand) 'send command with no response Loop Until (GetPin(ToneDecodeReady) = 0) OR (Reset = True) 'any tone or hangup stops tuning If Reset = False Then Call PutPin(VoiceEnable, bxOutPutHigh) 'mute mic and xcvr audio Do 'delay until tone quits Loop Until GetPin(ToneDecodeReady) = 1 Call PutPin(VoiceEnable, bxOutPutlow) 'reactivate mic and xcvr audio End If SetUpMode = False 'set to single tone command mode Case 15 Call PutPin(VoiceEnable, bxOutPutLow) 'reactivate mic and xcvr audio Call Delay(0.5) 'delay for 1/2 second for relay XCommand = "DN;" 'tune down command Do Call TransCommNoResp(BadComm, XCommand) 'send command with no response Loop Until (GetPin(ToneDecodeReady) = 0) OR (Reset = True) 'any tone or hangup stops tuning If Reset = False Then Call PutPin(VoiceEnable, bxOutPutHigh) 'mute mic and xcvr audio Do 'delay until tone quits Loop Until GetPin(ToneDecodeReady) = 1 Call PutPin(VoiceEnable, bxOutPutlow) 'reactivate mic and xcvr audio End If SetUpMode = False 'set to single tone command mode Case 16 XCommand = "FR" & ComArg & ";" Call TransCommNoResp(BadComm, XCommand) 'send command with no response CArg = Asc(ComArg) - 48 'convert to a number Select Case CArg Case 0 ' "VFO A receive" AddrArray(1)= 3 AddrArray(2)= 27 AddrArray(3)= 25 AddrArray(4)= 28 Case 1 ' "VFO B receive" AddrArray(1)= 3 AddrArray(2)= 27 AddrArray(3)= 26 AddrArray(4)= 28 Case 2 ' "memory receive" AddrArray(1)= 2 AddrArray(2)= 31 AddrArray(3)= 28 End Select Call VoiceResponse(AddrArray) 'give voice response Case 17 XCommand = "FT" & ComArg & ";" Call TransCommNoResp(BadComm, XCommand) 'send command with no response CArg = Asc(ComArg) - 48 'convert to a number Select Case CArg Case 0 ' "VFO A transmit" AddrArray(1)= 3 AddrArray(2)= 27 AddrArray(3)= 25 AddrArray(4)= 29 Case 1 ' "VFO B transmit" AddrArray(1)= 3 AddrArray(2)= 27 AddrArray(3)= 26 AddrArray(4)= 29 Case 2 ' "memory transmit AddrArray(1)= 2 AddrArray(2)= 31 AddrArray(3)= 29 End Select Call VoiceResponse(AddrArray) 'give voice response Case 18 If (SL - 2) = 0 Then XCommand = "MX;" 'compile the command ComArgNum = 4 Call TransCommResp(ComArg, ComArgNum, BadComm, XCommand) 'send the command and get the response If BadComm = False Then CArg = Asc(ComArg) - 48 'convert to a number Select Case CArg Case 0 ' "AIP off" AddrArray(1)= 2 AddrArray(2)= 13 AddrArray(3)= 21 Case 1 ' "AIP on" AddrArray(1)= 2 AddrArray(2)= 13 AddrArray(3)= 20 Case Else BadComm = True End Select End If ElseIf (SL - 2) = 1 Then XCommand = "MX" & ComArg & ";" Call TransCommNoResp(BadComm, XCommand) 'send command with no response If BadComm = False Then CArg = Asc(ComArg) - 48 'convert to a number Select Case CArg Case 0 ' "AIP off" AddrArray(1)= 2 AddrArray(2)= 13 AddrArray(3)= 21 Case 1 ' "AIP on" AddrArray(1)= 2 AddrArray(2)= 13 AddrArray(3)= 20 Case Else BadComm = True End Select End If ElseIf (SL -2) > 1 Then BadComm = True End If If BadComm = True Then ' "command error" AddrArray(1) = 2 AddrArray(2) = 44 AddrArray(3) = 45 End If Call VoiceResponse(AddrArray) 'give voice response Case 19 ReadingPeak = 0 For M = 1 to 10 XCommand = "SM;" ComArgNum = 7 Call TransCommResp(ComArg, ComArgNum, BadComm, XCommand) 'send the command and get the response If BadComm = True Then Exit For End If Call Meter(ComArg, Reading) 'get meter reading If Reading > ReadingPeak Then ReadingPeak = Reading 'get peak meter readings End If Next If BadComm = False Then If TransceiverKeyed = False Then Call SMeter(ReadingPeak, AddrArray) 'compute S-meter reading ElseIf TransceiverKeyed = True Then Call PowerMeter(ReadingPeak, AddrArray) 'compute power reading End If ElseIf BadComm = True Then Call CommandError(AddrArray) End If Call VoiceResponse(AddrArray) 'give voice response Case 20 BadComm = False If (SL - 2) = 0 Then XCommand = "FL;" ComArgNum = 9 Call TransCommResp(ComArg, ComArgNum, BadComm, XCommand) 'send the command and get the response If BadComm = False Then Call FilterVoice(ComArg, AddrArray, BadComm) 'generate a voice response sentence for filter status End If ElseIf (SL - 2) = 1 Then XCommand = "FL" & ComArg & ";" Call TransCommNoResp(BadComm, XCommand) 'send command with no response ElseIf (SL -2) <> 1 Then BadComm = True End If If BadComm = True Then ' "command error" Call CommandError(AddrArray) End If Call VoiceResponse(AddrArray) 'give voice response Case 21 If (SL - 2) = 1 Then Commd1 = Asc(ComArg) - 48 'convert argument to a number Select Case Commd1 Case 1 ComArg = "002002" Case 2 ComArg = "002005" Case 3 ComArg = "002007" Case 4 ComArg = "002009" End Select XCommand = "FL" & ComArg & ";" Call TransCommNoResp(BadComm, XCommand) 'send command with no response If BadComm = False Then Call FilterVoice(ComArg, AddrArray, BadComm) 'generate a voice response sentence for filter status End If ElseIf (SL - 2) <> 1 Then BadComm = True End If If BadComm = True Then Call CommandError(AddrArray) End If Call VoiceResponse(AddrArray) 'give voice response Case 22 If (SL - 2) = 1 Then Commd1 = Asc(ComArg) - 48 'convert argument to a number Select Case Commd1 Case 1 ComArg = "005002" Case 2 ComArg = "005005" Case 3 ComArg = "005007" Case 4 ComArg = "005009" End Select XCommand = "FL" & ComArg & ";" Call TransCommNoResp(BadComm, XCommand) 'send command with no response If BadComm = False Then Call FilterVoice(ComArg, AddrArray, BadComm) 'generate a voice response sentence for filter status End If ElseIf (SL - 2) <> 1 Then BadComm = True End If If BadComm = True Then Call CommandError(AddrArray) End If Call VoiceResponse(AddrArray) 'give voice response Case 23 If (SL - 2) = 1 Then Commd1 = Asc(ComArg) - 48 'convert argument to a number Select Case Commd1 Case 1 ComArg = "007002" Case 2 ComArg = "007005" Case 3 ComArg = "007007" Case 4 ComArg = "007009" End Select XCommand = "FL" & ComArg & ";" Call TransCommNoResp(BadComm, XCommand) 'send command with no response If BadComm = False Then Call FilterVoice(ComArg, AddrArray, BadComm) 'generate a voice response sentence for filter status End If ElseIf (SL - 2) <> 1 Then BadComm = True End If If BadComm = True Then Call CommandError(AddrArray) End If Call VoiceResponse(AddrArray) 'give voice response Case 24 If (SL - 2) = 1 Then Commd1 = Asc(ComArg) - 48 'convert argument to a number Select Case Commd1 Case 1 ComArg = "009002" Case 2 ComArg = "009005" Case 3 ComArg = "009007" Case 4 ComArg = "009009" End Select XCommand = "FL" & ComArg & ";" Call TransCommNoResp(BadComm, XCommand) 'send command with no response If BadComm = False Then Call FilterVoice(ComArg, AddrArray, BadComm) 'generate a voice response sentence for filter status End If ElseIf (SL - 2) <> 1 Then BadComm = True End If If BadComm = True Then Call CommandError(AddrArray) End If Call VoiceResponse(AddrArray) 'give voice response Case 30 BadComm = False If (SL - 2) = 0 Then XCommand = "RM;" ComArgNum = 8 Call TransCommResp(ComArg, ComArgNum, BadComm, XCommand) 'send the command and get the response If BadComm = False Then Call MeterVoice(ComArg, AddrArray, BadComm) 'generate a voise response sentence for the meter reading End If ElseIf (SL - 2) = 1 Then XCommand = "RM" & ComArg & ";" Call TransCommNoResp(BadComm, XCommand) 'send command with no response If BadComm = False Then CArg = Asc(ComArg) - 48 'convert to a number Select Case CArg Case 0 ' "no meter" AddrArray(1) = 2 AddrArray(2) = 40 AddrArray(3) = 39 Case 1 ' "meter is SWR" AddrArray(1) = 3 AddrArray(2) = 39 AddrArray(3) = 23 AddrArray(4) = 38 Case 3 ' "meter is ALC AddrArray(1) = 3 AddrArray(2) = 39 AddrArray(3) = 23 AddrArray(4) = 37 Case 6 ' "meter is DB" AddrArray(1) = 3 AddrArray(2) = 39 AddrArray(3) = 23 AddrArray(4) = 12 Case Else BadComm = True End Select End If ElseIf (SL -2) <> 1 Then BadComm = True End If If BadComm = True Then ' "command error" Call CommandError(AddrArray) End If Call VoiceResponse(AddrArray) 'give voice response Case 40 XCommand = "MD5;" 'change mode to AM Call TransCommNoResp(BadComm, XCommand) 'send command with no response If BadComm = False Then Call Delay(0.2) XCommand = "TX;" 'key transceiver Call TransCommNoResp(BadComm, XCommand) 'send command with no response Call Delay(1.0) 'delay 1 second for power settle ReadingPeak = 0 For M = 1 to 10 XCommand = "SM;" ComArgNum = 7 Call TransCommResp(ComArg, ComArgNum, BadComm, XCommand) 'send the command and get the response If BadComm = True Then Exit For End If Call Meter(ComArg, Reading) 'get meter reading If Reading > ReadingPeak Then ReadingPeak = Reading 'get peak meter readings End If Next End If If BadComm = False Then Call PowerMeter(ReadingPeak, AddrArray) 'compute power reading XCommand = "RX;" 'unkey transceiver Call TransCommNoResp(BadComm, XCommand) 'send command with no response If BadComm = False Then If VfoA = True Then XCommand = "FA;" 'frequency of VFO A ElseIf VfoA = False Then XCommand = "FB;" 'frequency of VFO B End If ComArgNum = 14 Call TransCommResp(ComArg, ComArgNum, BadComm, XCommand) 'send the command and get the response If BadComm = False Then ComArg = Mid(ComArg, 4, 1) 'get msb of frequency CArg = Asc(ComArg) - 48 'convert to a number Select Case CArg Case 0 XCommand = "MD1;" Call TransCommNoResp(BadComm, XCommand) 'send command with no response Case Else XCommand = "MD2;" Call TransCommNoResp(BadComm, XCommand) 'send command with no response End Select End If End If End If If BadComm = True Then Call CommandError(AddrArray) 'set up command error response End If Call VoiceResponse(AddrArray) 'give voice response Case 41 'turn on tranceiver Call PutPin(Tranceiver, bxOutPutHigh) AddrArray(1) = 1 AddrArray(2) = 20 ' "on" Call VoiceResponse(AddrArray) Case 42 'turn off tranceiver Call PutPin(Tranceiver, bxOutPutLow) AddrArray(1) = 1 AddrArray(2) = 21 ' "off" Call VoiceResponse(AddrArray) Case 43 'turn on amplifier Call PutPin(Amplifier, bxOutPutHigh) AddrArray(1) = 1 AddrArray(2) = 20 ' "on" Call VoiceResponse(AddrArray) Case 44 'turn off amplifier Call PutPin(Amplifier, bxOutPutLow) AddrArray(1) = 1 AddrArray(2) = 21 ' "off" Call VoiceResponse(AddrArray) Case 88 Call CommandError(AddrArray) Call VoiceResponse(AddrArray) Case 99 SetUpMode = False Case Else Call CommandError(AddrArray) Call VoiceResponse(AddrArray) End Select End If End Sub '************************************************************************************************ 'The routine TransCommResp sends the compiled command XCommand to the transceiver and returns a response Sub TransCommResp(ComArg as String, ComArgNum as Integer, BadComm as Boolean, XCommand as String) Dim N as Byte N = 5 Do Call PutQueueStr(OCom3, XCommand) 'send the command Call CommandResponse(ComArg, ComArgNum, BadComm) 'receive the response from the tranceiver N = N - 1 Loop Until (N = 0) OR (BadComm = False) End Sub '*********************************************************************************************** 'The routine TransCommNoResp sends the compiled command XCommand to the transceiver Sub TransCommNoResp(BadComm as Boolean, XCommand as String) Dim N as Byte Dim CChar as Byte N = 5 Do If StatusQueue(ICom3) = True Then 'empty input buffer if necessary Do Call GetQueue(ICom3, CChar, 1) 'get character and discard Loop Until StatusQueue(ICom3) = False End if Call PutQueueStr(OCom3, XCommand) 'send command Call Delay(0.1) 'delay 100 msec N = N -1 'decrement loop counter Loop Until (N = 0) OR (StatusQueue(ICom3) = False) If StatusQueue(ICom3) = True Then BadComm = True End If End Sub '************************************************************************************************ 'The routine ComArgFormat takes the comm argument from the touch tones and formats it for the tranceiver Sub ComArgFormat(ComArg as String, CommandString as String) Dim SL as Integer Dim N as Integer Dim DP as Integer Dim CAC as Byte Dim ComArgChar as String * 1 Dim Suffix as String CommandString = "000" 'initialize intermediate string DP = 0 SL = Len(ComArg) 'get length of com argument For N = 1 TO SL ComArgChar = Mid(ComArg, N, 1) 'parse com argument one character at a time CAC = Asc(ComArgChar) If CAC <> 42 Then 'check decimal point character, * CommandString = CommandString & ComArgChar 'build new com argument without decimal marker ElseIf CAC = 42 Then DP = N 'mark decimal place End If Next If DP = 0 Then DP = SL End If DP = SL - DP 'compute number of places after decimal Select Case DP 'do fill after decimal depending where decimal place is Case 0 Suffix = "000" CommandString = CommandString & Suffix 'add fill after decimal place Case 1 Suffix = "00" CommandString = CommandString & Suffix 'add fill after decimal place Case 2 Suffix = "0" CommandString = CommandString & Suffix 'add fill after decimal place End Select SL = Len(CommandString ) Select Case SL 'add leading zeros to string if necessary Case 11 CommandString = CommandString Case 10 CommandString = "0" & CommandString Case 9 CommandString = "00" & CommandString Case 8 CommandString = "000" & CommandString End Select CommandString = Mid(CommandString, 1, 10) & "0" ComArg = CommandString 'set com argument to formatted com argument End Sub '************************************************************************************************* 'The routine CommandResponse receives the tranceiver serial string from COM3 until either the 'terminate character, semicolon, is received or the correct number of characters is received 'or the timeout period is exceeded. If an error occurs, Reset is set to True Sub CommandResponse(ComArg as String, ComArgNum as Integer, BadComm as Boolean) Dim ComChar as String Dim CChar as Byte Dim CArgNum as Byte Dim StartTime as Single Dim ElapsedTime as Single Dim MaxTime as Single CArgNum = CByte(ComArgNum) MaxTime = 1.0 StartTime = Timer ComArg = "" Do Call TimeCheck(StartTime, ElapsedTime) 'check elapsed time since start If StatusQueue(ICom3) = True Then Call GetQueue(ICom3, CChar, 1) 'get a character from the input buffer if present ComChar = Chr(CChar) 'convert byte to a character If CChar <> 59 Then 'if character is not a ";" then add to string ComArg = ComArg & ComChar 'build string End If CArgNum = CArgNum - 1 'decrement character counter End If Loop Until (CChar = 59) OR (ElapsedTime > Maxtime) OR (CArgNum = 0) If (CChar = 59) AND (CArgNum = 0) Then BadComm = False ComArg = Mid(ComArg, 3, ComArgNum - 3) 'strip off command Else BadComm = True End If End Sub '************************************************************************************************* 'The routine VoiceResponse takes the word address string, AddrArray, looks up the address of the 'word in the voice annunciator, and strings together the words for the appropriate voice response. Sub VoiceResponse(AddrArray() as Integer) Dim N as Integer, VoiceAddress as Integer, X as Integer, Y as Integer Dim VoiceAddress1 as Byte, VoiceAddress2 as Byte Dim WordAddr(0 TO 49) as Integer WordAddr(0) = 0 WordAddr(1) = 9 WordAddr(2) = 16 WordAddr(3) = 24 WordAddr(4) = 34 WordAddr(5) = 43 WordAddr(6) = 51 WordAddr(7) = 60 WordAddr(8) = 68 WordAddr(9) = 76 WordAddr(10) = 85 WordAddr(11) = 92 WordAddr(12) = 101 WordAddr(13) = 111 WordAddr(14) = 122 WordAddr(15) = 131 WordAddr(16) = 142 WordAddr(17) = 152 WordAddr(18) = 162 WordAddr(19) = 172 WordAddr(20) = 183 WordAddr(21) = 192 WordAddr(22) = 201 WordAddr(23) = 210 WordAddr(24) = 219 WordAddr(25) = 229 WordAddr(26) = 237 WordAddr(27) = 246 WordAddr(28) = 256 WordAddr(29) = 266 WordAddr(30) = 277 WordAddr(31) = 288 WordAddr(32) = 298 WordAddr(33) = 307 WordAddr(34) = 317 WordAddr(35) = 327 WordAddr(36) = 335 WordAddr(37) = 344 WordAddr(38) = 356 WordAddr(39) = 368 WordAddr(40) = 378 WordAddr(41) = 388 WordAddr(42) = 399 WordAddr(43) = 409 WordAddr(44) = 419 WordAddr(45) = 430 WordAddr(46) = 438 WordAddr(47) = 445 WordAddr(48) = 455 WordAddr(49) = 466 For N = 1 to AddrArray(1) X = WordAddr(AddrArray(N + 1)) If X >= 512 Then Y = X - 512 X = 2 ElseIf X >= 256 Then Y = X - 256 X = 1 ElseIf X >= 0 Then Y = X X = 0 End If VoiceAddress1 = CByte(X) VoiceAddress2 = CBYte(Y) Call ShiftOut(VoiceOutAddress, SerialClock, 8, VoiceAddress1) Call ShiftOut(VoiceOutAddress, SerialClock, 8, VoiceAddress2) Call PulseOut(VoiceOut, 10, 0) Do Loop Until GetPin(VoiceMessageEnd) = 0 Do Loop Until GetPin(VoiceMessageEnd) = 1 Next End Sub '************************************************************************************************ 'The routine ArgAddr takes the command argument ComArg from the frequency command or the response and turns it into 'the address string AddrArray for the voice annunciator. Sub FreqArgAddr(ComArg as String, AddrArray() as Integer, XCommand as String) Dim SL as Integer Dim N as Integer Dim VoiceAddress as Integer Dim DP as Integer Dim DPO as Integer Dim DPX as Integer Dim VAdr as Byte Dim ComArgChar as String *1 Dim CAC as Byte XCommand = Mid(ComArg, 4, 7) 'get important characters of frequency down to one hundredths of kHz DP = 2 'set decimal point for two numbers to the right of decimal ComArgChar = Mid(XCommand , 7, 1) 'get last character of frequency CAC = Asc(ComArgChar) - 48 'convert it to a number If CAC = 0 Then XCommand = Mid(XCommand, 1, 6) 'chop off last zero. at this point the LSN is tenths of kHz DP = 1 'set decimal point for one number to the right of decimal ComArgChar = Mid(XCommand, 6, 1) 'get last character of frequency CAC = Asc(ComArgChar) - 48 'convert it to a number If CAC = 0 then XCommand = Mid(XCommand, 1, 5) 'chop off last zero. at this point the LSN is ones of KHz DP = 0 'set decimal point for zero numbers to the right of decimal End If End If Do ComArgChar = Mid(XCommand, 1, 1) 'get first character of frequency CAC = Asc(ComArgChar) - 48 'convert it to a number If CAC = 0 Then SL = Len(XCommand) 'get length of frequency string XCommand = Mid(XCommand, 2, SL-1) 'chop off leading zero End If Loop Until CAC <> 0 SL = Len(XCommand) 'calculate length of modified frequency string AddrArray(1) = SL + 5 'set length of voice response words assuming a decimal point DPX = 1 If DP = 0 Then AddrArray(1) = SL + 4 'set length of voice response words with no decimal point DPX = 0 End If DPO = 0 For N = 1 to (SL + DPX) If N <> (SL - DP + 1) Then ComArgChar = Mid(XCommand, N - DPO, 1) 'parse com argument one character at a time VAdr = Asc(ComArgChar) - 48 'convert number string to the correct number VoiceAddress = CInt(VAdr) 'convert to integer AddrArray(N + 4) = VoiceAddress 'assign address to the array ElseIf N = (SL - DP + 1) Then DPO = 1 AddrArray(N + 4) = 24 'assign "point" address to array End If Next AddrArray(SL + 5 + DPX) = 33 'assign "kHz" address to array End Sub '************************************************************************************************ 'The routine Meter reads the tranceiver meter Sub Meter(ComArg as String, Reading as Byte) Dim IntStr as String Dim Num1 as Byte Dim Num2 as Byte IntStr = Mid(ComArg, 3, 1) 'get 10's digit of reading Num1 = Asc(IntStr) - 48 'convert to a number IntStr = Mid(ComArg, 4, 1) 'get 1's digit reading Num2 = Asc(IntStr) - 48 'convert to a number Reading = (10 * Num1) + Num2 'convert to a two digit number End Sub '************************************************************************************************ 'The routine SMeter takes the meter reading of the tranceiver and converts it to an S-meter reading Sub SMeter(ReadingPeak as Byte, AddrArray() as Integer) Dim Reading as Integer Dim SL as Integer Dim ReadingStr as String Dim ReadingS as Single Dim IntStr as String Dim Num1 as Integer Dim Num2 as Integer ReadingS = CSng(ReadingPeak) AddrArray(2) = 10 ' "S" If ReadingS <= 15.0 Then 'do if reading is S-9 or below ReadingS = ReadingS / 1.6666 'compute S-unit Reading = Cint(ReadingS) 'convert to integer AddrArray(3) = Reading 'assign to array AddrArray(1) = 2 ElseIf ReadingS >= 15.0 Then ReadingS = ReadingS - 15.0 'do if reading is above S-9 ReadingS = (ReadingS / 2.5) * 10.0 'compute db above S-9 Reading = CInt(ReadingS) 'convert to integer ReadingStr = CStr(Reading ) 'convert to string SL = Len(ReadingStr) 'compute length of string If SL = 1 Then 'do if db is one digit Num1 = CInt(Asc(ReadingStr) - 48) 'convert digit to integer AddrArray(3) = 9 ' "9" AddrArray(4) = 11 ' "plus" AddrArray(5) = Num1 ' single number of db AddrArray(6) = 12 ' "db" AddrArray(1) = 5 'assign number of words in voice response ElseIf SL = 2 Then 'do if db is two digits IntStr = Mid(ReadingStr, 1, 1) 'extract 10's digit Num1 = CInt(Asc(IntStr) - 48) 'convert to integer IntStr = Mid(ReadingStr, 2, 1) 'extract 1's digit Num2 = CInt(Asc(IntStr) - 48) 'convert to integer AddrArray(3) = 9 ' "9" AddrArray(4) = 11 ' "plus" AddrArray(5) = Num1 ' first digit of db AddrArray(6) = Num2 ' second digit of db AddrArray(7) = 12 ' "db" AddrArray(1) = 6 'assign number of words in voice response End If End If End Sub '************************************************************************************************ 'The routine PowerMeter takes the meter reading of the tranceiver and converts it to a power reading Sub PowerMeter(ReadingPeak as Byte, AddrArray() as Integer) Dim ReadingI as Integer Dim SL as Integer Dim X as Single Dim Y as Single Dim A as Single Dim B as Single Dim C as Single Dim D as single Dim ReadingStr as String * 2 Dim IntStr as String * 1 Dim Num1 as Integer Dim Num2 as Integer AddrArray(2) = 42 ' "output" AddrArray(3) = 41 ' "power" AddrArray(4) = 23 ' "is" X = CSng(ReadingPeak) 'set independent variable A = 0.018667 B = -0.416 C = 5.9093 D = -14.512 Y = (A * X * X * X) + (B * X * X) + (C * X) + D 'calculate power ReadingI = CInt(Y) 'convert to integer If ReadingI > 99 Then ReadingI = 99 End If ReadingStr = CStr(ReadingI) 'convert to string If ReadingI < 10 Then 'do if power is one digit AddrArray(5) = ReadingI ' single number of watts AddrArray(6) = 43 ' "watts" AddrArray(1) = 5 'assign number of words in voice response ElseIf ReadingI >= 10 Then 'do if power is two digits IntStr = Mid(ReadingStr, 1, 1) 'extract 10's digit Num1 = CInt(Asc(IntStr) - 48) 'convert to integer IntStr = Mid(ReadingStr, 2, 1) 'extract 1's digit Num2 = CInt(Asc(IntStr) - 48) 'convert to integer AddrArray(5) = Num1 ' first digit of watts AddrArray(6) = Num2 ' second digit of watts AddrArray(7) = 43 ' "watts" AddrArray(1) = 6 'assign number of words in voice response End If End Sub '*************************************************************************************************** 'The routine CommandError generates a voice response sentence indicating a command error Sub CommandError(AddrArray() as Integer) AddrArray(1) = 2 AddrArray(2) = 44 AddrArray(3) = 45 End Sub '*************************************************************************************************** 'The routine FilterVoice generates a voice response sentence indicating the filter status of the transceiver Sub FilterVoice(ComArg as String, AddrArray() as Integer, BadComm as Boolean) Dim CMArg as String Dim CArg1 as Byte Dim CArg2 as Byte BadComm = False CMArg = Mid(ComArg, 3, 1) 'get first part of argument CArg1 = Asc(CMArg) - 48 'convert to a number CMarg = Mid(ComArg, 6, 1) 'get second part of argument CArg2 = Asc(CMarg) - 48 'convert to number Select Case CArg1 Case 2 ' "filter 1 is through" AddrArray(2) = 22 AddrArray(3) = 1 AddrArray(4) = 23 AddrArray(5) = 32 AddrArray(6) = 46 Call SecondFilterVoice(CArg1, CArg2, AddrArray, BadComm) 'get second filter sentence Case 5 ' "filter 1 is 6 kilohertz" AddrArray(2) = 22 AddrArray(3) = 1 AddrArray(4) = 23 AddrArray(5) = 6 AddrArray(6) = 33 AddrArray(7) = 46 Call SecondFilterVoice(CArg1, CArg2, AddrArray, BadComm) 'get second filter sentence Case 7 ' "filter 1 is 2 point 4 kilohertz" AddrArray(2) = 22 AddrArray(3) = 1 AddrArray(4) = 23 AddrArray(5) = 2 AddrArray(6) = 24 AddrArray(7) = 4 AddrArray(8) = 33 AddrArray(9) = 46 Call SecondFilterVoice(CArg1, CArg2, AddrArray, BadComm) 'get second filter sentence Case 9 ' "filter 1 is 5 hundred hertz" AddrArray(2) = 22 AddrArray(3) = 1 AddrArray(4) = 23 AddrArray(5) = 5 AddrArray(6) = 36 AddrArray(7) = 35 AddrArray(8) = 46 Call SecondFilterVoice(CArg1, CArg2, AddrArray, BadComm) 'get second filter sentence Case Else BadComm = True End Select End Sub '************************************************************************************************************ 'The routine SecondFilterVoice generates the voice response sentence for the second filter Sub SecondFilterVoice(CArg1 as Byte, CArg2 as Byte, AddrArray() as Integer, BadComm as Boolean) Dim N as Integer BadComm = False Select Case CArg1 Case 2 N = 7 Case 5 N = 8 Case 7 N = 10 Case 9 N = 9 End Select Select Case CArg2 Case 2 ' "filter 2 is twelve kilohertz" AddrArray(N) = 22 AddrArray(N + 1) = 2 AddrArray(N + 2) = 23 AddrArray(N + 3) = 47 AddrArray(N + 4) = 33 AddrArray(1) = N + 3 Case 5 ' "filter 2 is 6 kilohertz" AddrArray(N) = 22 AddrArray(N + 1) = 2 AddrArray(N + 2) = 23 AddrArray(N + 3) = 6 AddrArray(N + 4) = 33 AddrArray(1) = N + 3 Case 7 ' "filter 2 is 2 point 4 kilohertz" AddrArray(N) = 22 AddrArray(N + 1) = 2 AddrArray(N + 2) = 23 AddrArray(N + 3) = 2 AddrArray(N + 4) = 24 AddrArray(N + 5) = 4 AddrArray(N + 6) = 33 AddrArray(1) = N + 5 Case 9 ' "filter 2 is 5 hundred hertz" AddrArray(N) = 22 AddrArray(N + 1) = 2 AddrArray(N + 2) = 23 AddrArray(N + 3) = 5 AddrArray(N + 4) = 36 AddrArray(N + 5) = 35 AddrArray(1) = N + 4 Case Else BadComm = True End Select End Sub '************************************************************************************************ 'The routine MeterVoice generates a voice response sentence for the meter reading Sub MeterVoice(ComArg as String, AddrArray() as Integer, BadComm as Boolean) Dim CMArg as String Dim CArg1 as Byte Dim CArg2 as Byte Dim CArg3 as Byte Dim Val as Byte Dim Num1 as Integer Dim Num2 as Integer BadComm = False CMArg = Mid(ComArg, 1, 1) 'get first part of argument CArg1 = Asc(CMArg) - 48 'convert to a number CMarg = Mid(ComArg, 4, 1) 'get second part of argument, first digit CArg2 = Asc(CMarg) - 48 'convert to number Num1 = CInt(CArg2) 'convert to integer CMarg = Mid(ComArg, 5, 1) 'get second part of argument, second digit CArg3 = Asc(CMarg) - 48 'convert to number Num2 = CInt(CArg3) 'convert to integer Val = (10 * CArg2) + CArg3 'convert to a value Select Case CArg1 Case 0 AddrArray(1) = 2 AddrArray(2) = 40 AddrArray(3) = 39 Case 1 AddrArray(1) = 4 AddrArray(2) = 38 AddrArray(3) = 23 AddrArray(4) = Num1 AddrArray(5) = Num2 Case 3 AddrArray(1) = 4 AddrArray(2) = 37 AddrArray(3) = 23 AddrArray(4) = Num1 AddrArray(5) = Num2 Case 6 AddrArray(1) = 4 AddrArray(2) = 12 AddrArray(3) = 23 AddrArray(4) = Num1 AddrArray(5) = Num2 Case Else BadComm = True End Select End Sub '**************************************************************************************************