From 25ec73a58429054a5b8ae98ffd4de9ed3493f883 Mon Sep 17 00:00:00 2001 From: mysticbbs Date: Sat, 11 Aug 2012 12:50:14 -0400 Subject: [PATCH] Protocol updates --- mdl/m_protocol_base.pas | 19 +++++++++++++++++-- mdl/m_protocol_queue.pas | 1 + mdl/m_protocol_xmodem.pas | 24 ++++++++++++++++++++++-- mdl/m_protocol_ymodem.pas | 18 ++++++++++++++++++ mdl/m_protocol_zmodem.pas | 26 +++++++++++++++++--------- 5 files changed, 75 insertions(+), 13 deletions(-) diff --git a/mdl/m_protocol_base.pas b/mdl/m_protocol_base.pas index e11b7f8..0f4c264 100644 --- a/mdl/m_protocol_base.pas +++ b/mdl/m_protocol_base.pas @@ -36,6 +36,8 @@ Type Queue : TProtocolQueue; EndTransfer : Boolean; Connected : Boolean; + StatusCheck : Word; + StatusTimer : LongInt; ReceivePath : String; Constructor Create (Var C: TSocketClass; Var Q: TProtocolQueue); Virtual; @@ -44,6 +46,9 @@ Type Function AbortTransfer : Boolean; Procedure StatusUpdate (Starting, Ending: Boolean); Function ReadByteTimeOut (hSec: LongInt) : SmallInt; + + Procedure QueueReceive; Virtual; + Procedure QueueSend; Virtual; End; Implementation @@ -62,6 +67,8 @@ Begin ReceivePath := ''; StatusProc := NIL; AbortProc := @NoAbortProc; + StatusCheck := 100; + StatusTimer := 0; FillChar(Status, SizeOf(Status), 0); End; @@ -84,10 +91,10 @@ Begin Result := -1; If Client.DataWaiting Then Begin - Connected := Client.ReadBuf(Res, 1) <> -1; + Connected := Client.ReadBuf(Res, 1) >= 0; Result := Res; End Else - Case Client.WaitForData(HSec * 10) of + Case Client.WaitForData(hSec * 10) of -1 : Connected := False; 0 : ; Else @@ -104,4 +111,12 @@ Begin AbortTransfer := EndTransfer; End; +Procedure TProtocolBase.QueueReceive; +Begin +End; + +Procedure TProtocolBase.QueueSend; +Begin +End; + End. diff --git a/mdl/m_protocol_queue.pas b/mdl/m_protocol_queue.pas index 14afa18..a1d5e65 100644 --- a/mdl/m_protocol_queue.pas +++ b/mdl/m_protocol_queue.pas @@ -72,6 +72,7 @@ Begin Assign (F, fPath + fName); {$I-} Reset(F, 1); {$I+} + If IoResult = 0 Then Begin QData[QSize]^.FileSize := FileSize(F); QData[QSize]^.Status := QueuePending; diff --git a/mdl/m_protocol_xmodem.pas b/mdl/m_protocol_xmodem.pas index f9121ec..a5737b7 100644 --- a/mdl/m_protocol_xmodem.pas +++ b/mdl/m_protocol_xmodem.pas @@ -5,12 +5,32 @@ Unit m_Protocol_XModem; Interface Uses - m_Protocol_Base; + m_Socket_Class, + m_Protocol_Base, + m_Protocol_Queue; Type TProtocolXmodem = Class(TProtocolBase) + DoCRC : Boolean; + Do1K : Boolean; + + Constructor Create (Var C: TSocketClass; Var Q: TProtocolQueue); Override; + Destructor Destroy; Override; End; Implementation -End. \ No newline at end of file +Constructor TProtocolXmodem.Create (Var C: TSocketClass; Var Q: TProtocolQueue); +Begin + Inherited Create(C, Q); + + DoCRC := True; + Do1K := True; +End; + +Destructor TProtocolXmodem.Destroy; +Begin + Inherited Destroy; +End; + +End. diff --git a/mdl/m_protocol_ymodem.pas b/mdl/m_protocol_ymodem.pas index bba56dd..1a744e0 100644 --- a/mdl/m_protocol_ymodem.pas +++ b/mdl/m_protocol_ymodem.pas @@ -5,12 +5,30 @@ Unit m_Protocol_YModem; Interface Uses + m_Socket_Class, + m_Protocol_Queue, m_Protocol_Xmodem; Type TProtocolYmodem = Class(TProtocolXmodem) + UseG : Boolean; + + Constructor Create (Var C: TSocketClass; Var Q: TProtocolQueue); Override; + Destructor Destroy; Override; End; Implementation +Constructor TProtocolYModem.Create (Var C: TSocketClass; Var Q: TProtocolQueue); +Begin + Inherited Create(C, Q); + + UseG := False; +End; + +Destructor TProtocolYModem.Destroy; +Begin + Inherited Destroy; +End; + End. \ No newline at end of file diff --git a/mdl/m_protocol_zmodem.pas b/mdl/m_protocol_zmodem.pas index 875ca29..4a6261d 100644 --- a/mdl/m_protocol_zmodem.pas +++ b/mdl/m_protocol_zmodem.pas @@ -2,7 +2,7 @@ Unit m_Protocol_Zmodem; {$I M_OPS.PAS} -{.$DEFINE ZDEBUG} +{$DEFINE ZDEBUG} Interface @@ -21,8 +21,6 @@ Const ZBufSize = 1024; // 1024 only maybe 8k ZEDZAP someday ZAttnLen = 32; RxTimeOut : Word = 500; - StatusCheck : Word = 50; - StatusTimer : LongInt = 0; Type ZHdrType = Array[0..3] of Byte; @@ -49,8 +47,9 @@ Type Constructor Create (Var C: TSocketClass; Var Q: TProtocolQueue); Override; Destructor Destroy; Override; - Procedure QueueReceive; Virtual; - Procedure QueueSend; Virtual; + Procedure QueueReceive; Override; + Procedure QueueSend; Override; + Function ZInitReceiver : SmallInt; Function ZGetByte : SmallInt; Function ZDLRead : SmallInt; @@ -80,6 +79,7 @@ Implementation Const CANBRK = 4; EscAll = $0040; + ZCRC = 13; ZABORT = 7; ZRQINIT = 0; ZPAD = 42; @@ -843,7 +843,7 @@ Var Begin {$IFDEF ZDEBUG} ZLog(''); {$ENDIF} {$IFDEF ZDEBUG} ZLog('ZSendFile -> begin'); {$ENDIF} - {$IFDEF ZDEBUG} ZLog('ZSendFile -> file:' + Queue^.QData[Queue^.QPos]^.FName); {$ENDIF} + {$IFDEF ZDEBUG} ZLog('ZSendFile -> file:' + Queue.QData[Queue.QPos].FileName); {$ENDIF} Result := ZERROR; @@ -897,14 +897,22 @@ Begin ZFIN, ZTIMEOUT : Begin Close (WrkFile); + Exit; End; ZSKIP : Begin Close (WrkFile); ZSendFile := ZSKIP; + Exit; End; - ZRPOS : Goto start; + ZCRC : Begin + ZPutLong(FileCRC32(Status.FilePath + Status.FileName)); + ZSendHexHeader(ZCRC); + + Continue; + End; + ZRPOS : Goto Start; End; Until (C <> ZRINIT); Until False; @@ -1118,7 +1126,7 @@ Begin FillChar (TxHdr, SizeOf(TxHdr), 0); // zero out all flags - TxHdr[ZF0] := CANFDX OR CANOVIO OR CANFC32 {OR CANBRK}; + TxHdr[ZF0] := CANFDX OR CANOVIO OR CANFC32 OR CANBRK; If EscapeAll Then TxHdr[ZF0] := TxHdr[ZF0] or ESCALL; @@ -1673,4 +1681,4 @@ Begin StatusUpdate(False, True); End; -End. +End. \ No newline at end of file