'**************************************************************** '* Name : REMOTE_IF_P+.inc * '* Author : John Barrat * '* Notice : Copyright (c) 2004 John Barrat * '* : All Rights Reserved * '* Date : 08/12/2004 * '* Version : 1.0 * '* Notes : * '* : * '**************************************************************** 'Device = 18F252 'Get Commands ********************************************************************************** '^GDT#13#10 ' Response ^RDT,YYMMDD HHMMDD,DS#13#10 Where DS is the daylight saving state 'Set Commands ********************************************************************************** 'Change Time/Date '^SDT,YYMMDD HHMMSS,DS#13#10' Set new Date, Time and D-S mode ' Blank enried for any field will use the existing value 'Repeat Commands ******************************************************************************* 'Reset Command ********************************************************************************* '^XRX#13#10 ' Resets program to 0000 ' ' ********************************************************************************************** ' End of File Character Symbol RE_EOF $1013 ' End of Record Character Symbol RE_SEP "," ' Field Separator ' Record Types and Responses Character Pairs Symbol RE_DT $4454 ' (DT) Date/Time Record Symbol RE_OK $4F4B ' (OK) Command Acknowlegdement Symbol RE_SET $5253 ' (RS) Reset Program Symbol RE_VN $564E ' (VN) Send SW Version number Symbol RE_TSK $544B ' (TK) Enable/Disable Task list reporting Symbol RE_TR $5452 ' (TR) Send Task Rates locations Symbol RE_TA $5441 ' (TA) Send All Active Tasks ' Error Codes are held as a Word containing 2 ASCII bytes Symbol No_Err $3030 ' (00) is no error Symbol BOFlow $3031 ' (01) Buffer Overflow Symbol RFrErr $3032 ' (02) Framing Error Symbol StaErr $3033 ' (03) Start Char invalid Symbol CmdErr $3034 ' (04) Unrecognised Command Symbol HexErr $3036 ' (06) Invalid Hex decode Symbol RxTOErr $3037 ' (07) Receive record timeout Symbol RxORun $3038 ' (08) USART Rx Over run Symbol GtErr0 $3130 ' (10) Unrecognised Get Subcommand Symbol StErr0 $3230 ' (20) Unrecognised Set Subcommand Symbol StErr5 $3235 ' (25) Set Time/Date invalid Error Symbol StErr7 $3237 ' (27) Set Task Monitor Command Error Symbol XtErr0 $3430 ' (40) Unrecognised Reset Command Dim REM_TB1 As Byte ' Internal Byte Dim REM_TB2 As Byte ' Internal Byte Dim CmdWrd As Word ' Internal Word Dim INC_TS As Bit ' Add in Timestamp flag GoTo SkipRemote_IF RemoteInit: INC_TS = SwOff ' Switch off Time Stamp CmdWrd = 0 ' Clear Variables GoSub RB_ClearBuff ' Clear IP Buffer Pointers #IFNDEF INT_ENABLED ADDTask Get_Record, Rate1 ; Set in the Monitor task every Second #ENDIF Return #IFDEF PUT_TX_RECORD Put_Record: ' Place code for loading the TX FIFO if required Return #ENDIF ' Get Record Subroutine ************************************************************************ Get_Record: SMALL_MICRO_MODEL = On CmdWrd = No_Err ' Preset to OK If RB_OFL = True Then CmdWrd = BOFlow' Set Error code for Overflow If RB_FERR = True Then CmdWrd = RFrErr' Set Error code for Framing Error If RB_Orun = True Then CmdWrd = RxORun' Set Error code for RX Over run GoSub RB_GetFirstChar ' Check first Character in Buffer If RxChar <> "^" Then CmdWrd = StaErr ' If not "^" set error code If CmdWrd > No_Err Then GoTo SendErr ' If error report it and exit routine through SendErr ' Check for end of record marker CheckEnd: GoSub RB_GetLastChar ' get last Rx character and check for End of Record If RXChar <> LF Then Return ' If not end of record exit routine GoSub StopRXTmr ' Got End of Record so Stop Rx Timeout #IFNDEF INT_ENABLED REMTask Get_Record, Rate1 ' Stop monitoring until command processed (Polled mode) ADDTask Process_Record, Rate2 ' Add Process Command to Task List (Polled mode) Return ' and return #ENDIF ' Process Record subroutines ******************************************************************* ' Parses the command string and executes the commands or reports an error Process_Record: #IFNDEF INT_ENABLED REMTask Process_Record, Rate2 ; Remove this task as its once off #ENDIF GoSub RB_GetChar ' Skip Record start char (^) GoSub RB_GetChar ' Get the main command Select Case RXchar Case "G" ' GET Commands GoSub GetSubCmd ' Get the next 2 byte of the command Select Case CmdWrd ' Select action Case RE_VN: GoSub Send_Ver_Number ' Send Software Version number Case RE_DT: GoSub Send_Time_Date ' Get Time/Date Case RE_TR #IFDEF TASK_DEBUG GoSub SendRateLocs ' Send Task Rate Locations #ENDIF Case RE_TA #IFDEF TASK_DEBUG GoSub SendAllTasks ' Send all Tasks #ENDIF Case Else: CmdWrd = GtErr0: GoTo SendErr End Select Case "S" ' SET Commands GoSub GetSubCmd ' Get Sub Command Select Case CmdWrd ' Evaluate and execute or error Case RE_DT ' Set New Date and time For REM_TB1 = 6 To 0 Step -1 ' Load the new Date and time into Set Array If REM_TB1 <> 3 Then ' Skip the Weekday value as we calc on the fly GoSub RB_GetHex2: If RB_CERR = True Then SendHexErr SetRTCArry[REM_TB1] = RXByte ' Else GoSub RB_GetChar ' Skip Comma separator End If Next REM_TB1 GoSub RB_GetChar ' Skip Separator GoSub RB_GetHex2: If RB_CERR = True Then SendHexErr SetDSTime = RXByte.0 ' Set the daylight Saving bit GoSub ChkTimeAndDate ' Check Date & Time are a Valid If RTC_Cont = True Then SendDTErr ' Set Invalid Date or Time and exit via error GoSub RTCUpDate ' Should all be OK so update the RTC Case RE_TSK ' Enable/Disable Task reporting #IFDEF TASK_DEBUG GoSub RB_GetChar ' Get Command Value If RXChar & $F8 = $30 Then ' ("0" = All Off) "4" = ProcMon On RXChar = RXChar & $07 ' ("1" = RptTsks "5" + ProcMon On RptTsks = RxChar.0 ' ("2" = RptActTsks) "6" + ProcMon On RptActTsks = RXChar.1 ' ("3" = both On) "7" + ProcMon On RXChar = RXChar & $04 GoSub EnableProcMon [RXChar] ' Only pass on bit 4 Else CmdWrd = StErr7: GoTo SendErr' None of the above so exit via error End If #ENDIF Case Else ' Unrecognised subcommand CmdWrd = StErr0: GoTo SendErr ' Set Error message and exit via SendErr End Select CmdWrd = RE_OK: GoTo SendAck ' All OK so set up Send the Acknowledge Case "X" ' RESET Command #IFDEF REMRESET_ENABLED GoSub GetSubCmd If CmdWrd = RE_SET Then ' Only Option is RESET GoSub SaveMode ' Save Pump & Temp Mode and Display Defaults #IFDEF SPCV3 GoSub SaveContrast ' Save current Contrast setting #ENDIF HSerOut["R"] ' Send Acknowledgement Char and DelayMS 100 @ RESET ; Execute SW reset EndIf #ENDIF CmdWrd = XtErr0: GoTo SendErr ' Unrecognised code so report Error and exit Case Else CmdWrd = CmdErr: GoTo SendErr ' Set the Invalid Command and Send Error Message End Select GoTo EndCmd ' Send Error Messages ************************************************************************** SendDTErr: CmdWrd = StErr5: GoTo SendErr ' Set DateTime Error Value SendTOErr: CmdWrd = RxTOErr: GoTo SendErr ' set Timout Error value SendHexErr: CmdWrd = HexErr ' Set Invalid Hex Character Error SendErr: GoSub StopRXTmr ' Stop the Message timeout Clear MsgArry ' Clear message arry ready for response MsgArry[1] = "E" ' Response Character GoTo SendRsp SendAck: Clear MsgArry ' Clear message array ready for response MsgArry[1] = "A" ' Response Character SendRsp: MsgArry[0] = "^" ' Start of Record Char MsgArry[2] = CmdWrd.HighByte ' Set up the response MsgArry[3] = CmdWrd.LowByte ' values GoTo SendResponse ' Send Field and Return ' Gets the Function Sub command and places it in CmdWrd for easy processing GetSubCmd: GoSub RB_GetChar ' Get the Char CmdWrd.HighByte = RXchar ' and place first char in the High GoSub RB_GetChar ' Get next character and CmdWrd.LowByte = RXchar ' place it in the lower byte GoTo RB_GetChar ' Get next char and return through routine ' Generates the header string HdrStr: Clear MsgArry ' Clear message array ready for response MsgArry[0] = "^" ' Start of Record Char MsgArry[1] = "R" ' Response Character MsgArry[2] = CmdWrd.HighByte ' Set up the MsgArry[3] = CmdWrd.LowByte ' Record Type Return TimeStampStr: MsgArry = MsgArry + RE_SEP ' Add in initial separator For REM_TB2 = 6 To 0 Step -1 ' Step backwards through the RTC Array If REM_TB2 = 3 Then ' Skip the Weekday value and MsgArry = MsgArry + "," ' replace it with a comma Else ' Add in date and Time in "YYMMDD,DDMMSS" REM_TB1 = RTCArry[REM_TB2] MsgArry = MsgArry + Str$(HEX2, REM_TB1) EndIf Next REM_TB2 Return Send_Time_Date: CmdWrd = RE_DT ' Set the Record type GoSub HdrStr ' Generate Header GoSub TimeStampStr ' Generate Timestamp String MsgArry = MsgArry + RE_SEP + Str$(BIN, DSTime)' Add in the Summer Winter flag GoTo SendResponse ' Return through SendResponse Send_Ver_Number: CmdWrd = RE_VN ' Set Record Type GoSub HdrStr ' Generate header MsgArry = MsgArry + RE_SEP + PName ' Get Program Name and MsgArry = MsgArry + RE_SEP + VerNo ' Version Number and drop through to send message SendResponse: ' MsgArry = MsgArry + CR + LF ' Add in the terminating sequence HISerOut MsgArry ' an Send the response EndCmd: #IFNDEF INT_ENABLED ADDTask Get_Record, Rate1 ; Re-start monitoring now command processed #ENDIF GoSub RB_ClearBuff ' Reset pointers to top of Buffer Return ' Generic response handler - Adds CR-LF secquence and sends to output buffer SendMessage: ' MsgArry = MsgArry + CR + LF ' Add in the terminating sequence HISerOut MsgArry ' and send the message Return SMALL_MICRO_MODEL = Off SkipRemote_IF: