Zmodem 8K
This commit is contained in:
parent
228f4b446a
commit
93337d2a25
|
@ -21,15 +21,16 @@ Uses
|
||||||
m_Protocol_Queue;
|
m_Protocol_Queue;
|
||||||
|
|
||||||
Const
|
Const
|
||||||
ZBufSize = 1024; // 1024 only maybe 8k ZEDZAP someday
|
|
||||||
ZAttnLen = 32;
|
ZAttnLen = 32;
|
||||||
|
MaxBufSize = 1024 * 8;
|
||||||
RxTimeOut : Word = 500;
|
RxTimeOut : Word = 500;
|
||||||
|
|
||||||
Type
|
Type
|
||||||
ZHdrType = Array[0..3] of Byte;
|
ZHdrType = Array[0..3] of Byte;
|
||||||
ZBufType = Array[0..ZBUFSIZE - 1] of Byte;
|
ZBufType = Array[0..MaxBufSize - 1] of Byte;
|
||||||
|
|
||||||
TProtocolZmodem = Class(TProtocolBase)
|
TProtocolZmodem = Class(TProtocolBase)
|
||||||
|
CurBufSize : Word;
|
||||||
UseCRC32 : Boolean;
|
UseCRC32 : Boolean;
|
||||||
EscapeAll : Boolean;
|
EscapeAll : Boolean;
|
||||||
LastSent : Byte;
|
LastSent : Byte;
|
||||||
|
@ -201,6 +202,7 @@ Begin
|
||||||
LastSent := 0;
|
LastSent := 0;
|
||||||
EscapeAll := False;
|
EscapeAll := False;
|
||||||
Attn := '';
|
Attn := '';
|
||||||
|
CurBufSize := 1024;
|
||||||
End;
|
End;
|
||||||
|
|
||||||
Destructor TProtocolZmodem.Destroy;
|
Destructor TProtocolZmodem.Destroy;
|
||||||
|
@ -250,7 +252,7 @@ Begin
|
||||||
ZPutHex (Lo(CRC));
|
ZPutHex (Lo(CRC));
|
||||||
|
|
||||||
Client.BufWriteChar (#13);
|
Client.BufWriteChar (#13);
|
||||||
Client.BufWriteChar (#10);
|
Client.BufWriteChar (Char(10 or $80));
|
||||||
|
|
||||||
If (FrameType <> ZFIN) And (FrameType <> ZACK) Then
|
If (FrameType <> ZFIN) And (FrameType <> ZACK) Then
|
||||||
Client.BufWriteChar (Char(XON));
|
Client.BufWriteChar (Char(XON));
|
||||||
|
@ -312,12 +314,12 @@ Begin
|
||||||
ZRUB0 : Result := $007F;
|
ZRUB0 : Result := $007F;
|
||||||
ZRUB1 : Result := $00FF;
|
ZRUB1 : Result := $00FF;
|
||||||
Else
|
Else
|
||||||
If ((Result AND $60) = $40) Then
|
// If ((Result AND $60) = $40) Then
|
||||||
Result := Result XOR $40
|
Result := Result XOR $40
|
||||||
Else Begin
|
// Else Begin
|
||||||
Result := ZERROR;
|
// Result := ZERROR;
|
||||||
{$IFDEF ZDEBUG} ZLog('ZDLRead -> Got ZERROR'); {$ENDIF}
|
// {$IFDEF ZDEBUG} ZLog('ZDLRead -> Got ZERROR'); {$ENDIF}
|
||||||
End;
|
// End;
|
||||||
End;
|
End;
|
||||||
|
|
||||||
{$IFDEF ZCHARLOG} ZLog('ZDLRead -> ' + HeaderType(Result)); {$ENDIF}
|
{$IFDEF ZCHARLOG} ZLog('ZDLRead -> ' + HeaderType(Result)); {$ENDIF}
|
||||||
|
@ -464,46 +466,6 @@ Begin
|
||||||
ZReceiveBinaryHeader32 := RxType;
|
ZReceiveBinaryHeader32 := RxType;
|
||||||
End;
|
End;
|
||||||
|
|
||||||
(*
|
|
||||||
//XON, XOFF, DLE, CTRLX, CR@CR...
|
|
||||||
//ALSO translate TELNET_IAC... optional?
|
|
||||||
Procedure TProtocolZmodem.SendEscaped (B: SmallInt);
|
|
||||||
Begin
|
|
||||||
Case B of
|
|
||||||
DLE,
|
|
||||||
DLEHI,
|
|
||||||
XON,
|
|
||||||
XONHI,
|
|
||||||
XOFF,
|
|
||||||
XOFFHI,
|
|
||||||
ZDLE : Begin
|
|
||||||
Client.BufWriteChar(Char(ZDLE));
|
|
||||||
LastSent := B XOR $40;
|
|
||||||
End;
|
|
||||||
13,
|
|
||||||
13 OR $80 : If (LastSent AND $7F = Ord('@')) Then Begin
|
|
||||||
Client.BufWriteChar(Char(ZDLE));
|
|
||||||
LastSent := B XOR $40;
|
|
||||||
End Else
|
|
||||||
LastSent := B;
|
|
||||||
255 : Begin
|
|
||||||
Client.BufWriteChar(Char(ZDLE));
|
|
||||||
LastSent := ZRUB1;
|
|
||||||
End;
|
|
||||||
|
|
||||||
Else
|
|
||||||
If (EscapeAll) and ((B AND $60) = 0) Then Begin
|
|
||||||
Client.BufWriteChar(Char(ZDLE));
|
|
||||||
LastSent := B XOR $40;
|
|
||||||
End Else
|
|
||||||
LastSent := B;
|
|
||||||
End;
|
|
||||||
|
|
||||||
Client.BufWriteChar(Char(LastSent));
|
|
||||||
End;
|
|
||||||
*)
|
|
||||||
|
|
||||||
(*
|
|
||||||
Procedure TProtocolZmodem.SendEscaped (B: SmallInt);
|
Procedure TProtocolZmodem.SendEscaped (B: SmallInt);
|
||||||
Begin
|
Begin
|
||||||
Case B of
|
Case B of
|
||||||
|
@ -538,42 +500,6 @@ Begin
|
||||||
|
|
||||||
Client.BufWriteChar(Char(LastSent));
|
Client.BufWriteChar(Char(LastSent));
|
||||||
End;
|
End;
|
||||||
*)
|
|
||||||
|
|
||||||
Procedure TProtocolZmodem.SendEscaped (B: SmallInt);
|
|
||||||
Begin
|
|
||||||
Case B of
|
|
||||||
DLE,
|
|
||||||
DLEHI,
|
|
||||||
XON,
|
|
||||||
XONHI,
|
|
||||||
XOFF,
|
|
||||||
XOFFHI,
|
|
||||||
ZDLE : Begin
|
|
||||||
Client.BufWriteChar(Char(ZDLE));
|
|
||||||
LastSent := B XOR $40;
|
|
||||||
End;
|
|
||||||
13,
|
|
||||||
13 OR $80 : If (LastSent AND $7F = Ord('@')) Then Begin
|
|
||||||
Client.BufWriteChar(Char(ZDLE));
|
|
||||||
LastSent := B XOR $40;
|
|
||||||
End Else
|
|
||||||
LastSent := B;
|
|
||||||
255 : Begin
|
|
||||||
Client.BufWriteChar(Char(ZDLE));
|
|
||||||
LastSent := ZRUB1;
|
|
||||||
End;
|
|
||||||
|
|
||||||
Else
|
|
||||||
If (EscapeAll) and ((B AND $60) = 0) Then Begin
|
|
||||||
Client.BufWriteChar(Char(ZDLE));
|
|
||||||
LastSent := B XOR $40;
|
|
||||||
End Else
|
|
||||||
LastSent := B;
|
|
||||||
End;
|
|
||||||
|
|
||||||
Client.BufWriteChar(Char(LastSent));
|
|
||||||
End;
|
|
||||||
|
|
||||||
Procedure TProtocolZmodem.ZSendBinaryHeader (FrameType : Byte);
|
Procedure TProtocolZmodem.ZSendBinaryHeader (FrameType : Byte);
|
||||||
Var
|
Var
|
||||||
|
@ -1071,7 +997,7 @@ Start:
|
||||||
FileDone := False;
|
FileDone := False;
|
||||||
GoodBlks := 0;
|
GoodBlks := 0;
|
||||||
GoodNeeded := 0;
|
GoodNeeded := 0;
|
||||||
RxBufLen := ZBufSize;
|
RxBufLen := CurBufSize;
|
||||||
|
|
||||||
Status.Position := RxPos;
|
Status.Position := RxPos;
|
||||||
Status.BlockSize := RxBufLen;
|
Status.BlockSize := RxBufLen;
|
||||||
|
@ -1120,11 +1046,11 @@ Start:
|
||||||
|
|
||||||
Inc (GoodBlks);
|
Inc (GoodBlks);
|
||||||
|
|
||||||
If (RxBufLen < ZBUFSIZE) And (GoodBlks > GoodNeeded) Then Begin
|
If (RxBufLen < CurBufSize) And (GoodBlks > GoodNeeded) Then Begin
|
||||||
If ((RxBufLen SHL 1) < ZBUFSIZE) Then
|
If ((RxBufLen SHL 1) < CurBufSize) Then
|
||||||
RxBufLen := RxBufLen SHL 1
|
RxBufLen := RxBufLen SHL 1
|
||||||
Else
|
Else
|
||||||
RxBufLen := ZBUFSIZE;
|
RxBufLen := CurBufSize;
|
||||||
|
|
||||||
GoodBlks := 0;
|
GoodBlks := 0;
|
||||||
End;
|
End;
|
||||||
|
@ -1303,7 +1229,7 @@ Again:
|
||||||
ZEOF : Continue;
|
ZEOF : Continue;
|
||||||
ZTIMEOUT: Continue;
|
ZTIMEOUT: Continue;
|
||||||
ZFILE : Begin
|
ZFILE : Begin
|
||||||
If ZReceiveData(RxBuf, ZBUFSIZE) = GOTCRCW Then Begin
|
If ZReceiveData(RxBuf, CurBufSize) = GOTCRCW Then Begin
|
||||||
ZInitSender := ZFILE;
|
ZInitSender := ZFILE;
|
||||||
Exit;
|
Exit;
|
||||||
End;
|
End;
|
||||||
|
@ -1349,7 +1275,7 @@ Again:
|
||||||
Goto Again;
|
Goto Again;
|
||||||
End;
|
End;
|
||||||
ZCOMMAND: Begin
|
ZCOMMAND: Begin
|
||||||
If ZReceiveData (RxBuf, ZBUFSIZE) = GOTCRCW Then Begin
|
If ZReceiveData (RxBuf, CurBufSize) = GOTCRCW Then Begin
|
||||||
ZPutLong (0);
|
ZPutLong (0);
|
||||||
|
|
||||||
Repeat
|
Repeat
|
||||||
|
@ -1520,7 +1446,7 @@ Label
|
||||||
NextHeader,
|
NextHeader,
|
||||||
MoreData;
|
MoreData;
|
||||||
Var
|
Var
|
||||||
Tmp : SmallInt;
|
Tmp : LongInt;
|
||||||
Str : String;
|
Str : String;
|
||||||
FName : String;
|
FName : String;
|
||||||
FSize : LongInt;
|
FSize : LongInt;
|
||||||
|
@ -1547,7 +1473,6 @@ Begin
|
||||||
|
|
||||||
While (RxBuf[Tmp] <> 32) and (RxBuf[Tmp] <> 0) Do Begin
|
While (RxBuf[Tmp] <> 32) and (RxBuf[Tmp] <> 0) Do Begin
|
||||||
Str := Str + Char(RxBuf[Tmp]);
|
Str := Str + Char(RxBuf[Tmp]);
|
||||||
// FSize := (FSize * 10) + RxBuf[Tmp] - $30;
|
|
||||||
Inc (Tmp);
|
Inc (Tmp);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
|
@ -1556,8 +1481,6 @@ Begin
|
||||||
{$IFDEF ZDEBUG} ZLog('ZRecvFile -> File:' + FName); {$ENDIF}
|
{$IFDEF ZDEBUG} ZLog('ZRecvFile -> File:' + FName); {$ENDIF}
|
||||||
{$IFDEF ZDEBUG} ZLog('ZRecvFile -> Size:' + strI2S(FSize)); {$ENDIF}
|
{$IFDEF ZDEBUG} ZLog('ZRecvFile -> Size:' + strI2S(FSize)); {$ENDIF}
|
||||||
|
|
||||||
// Client.PurgeInputData;
|
|
||||||
|
|
||||||
Queue.Add(ReceivePath, FName);
|
Queue.Add(ReceivePath, FName);
|
||||||
|
|
||||||
Queue.QData[Queue.QSize]^.FileSize := FSize;
|
Queue.QData[Queue.QSize]^.FileSize := FSize;
|
||||||
|
@ -1631,10 +1554,18 @@ Begin
|
||||||
|
|
||||||
{$IFDEF ZDEBUG} ZLog('ZRecvFile -> Sending ZRPOS ' + strI2S(RxBytes)); {$ENDIF}
|
{$IFDEF ZDEBUG} ZLog('ZRecvFile -> Sending ZRPOS ' + strI2S(RxBytes)); {$ENDIF}
|
||||||
|
|
||||||
|
Client.PurgeOutputData;
|
||||||
|
|
||||||
ZPutLong (RxBytes);
|
ZPutLong (RxBytes);
|
||||||
ZSendBinaryHeader (ZRPOS);
|
ZSendBinaryHeader (ZRPOS);
|
||||||
|
|
||||||
// purge input here?
|
// Client.BufFlush;
|
||||||
|
|
||||||
|
{$IFDEF UNIX}
|
||||||
|
Client.PurgeInputData(100);
|
||||||
|
{$ELSE}
|
||||||
|
Client.PurgeInputData(100);
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
NextHeader:
|
NextHeader:
|
||||||
|
|
||||||
|
@ -1654,7 +1585,8 @@ NextHeader:
|
||||||
End;
|
End;
|
||||||
End;
|
End;
|
||||||
ZFILE : Begin
|
ZFILE : Begin
|
||||||
ZReceiveData (RxBuf, ZBUFSIZE);
|
{$IFDEF ZDEBUG} ZLog('ZRecvFile -> Got ZFILE expected data sending ZRPOS'); {$ENDIF}
|
||||||
|
ZReceiveData(RxBuf, CurBufSize);
|
||||||
Continue;
|
Continue;
|
||||||
End;
|
End;
|
||||||
ZEOF : Begin
|
ZEOF : Begin
|
||||||
|
@ -1720,7 +1652,7 @@ MoreData:
|
||||||
StatusTimer := TimerSet(StatusCheck);
|
StatusTimer := TimerSet(StatusCheck);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
C := ZReceiveData(RxBuf, ZBUFSIZE);
|
C := ZReceiveData(RxBuf, CurBufSize);
|
||||||
|
|
||||||
{$IFDEF ZDEBUG} ZLog('ZRecvFile -> MoreData -> Got ' + HeaderType(C) + ' want data packet'); {$ENDIF}
|
{$IFDEF ZDEBUG} ZLog('ZRecvFile -> MoreData -> Got ' + HeaderType(C) + ' want data packet'); {$ENDIF}
|
||||||
|
|
||||||
|
@ -1824,7 +1756,7 @@ Begin
|
||||||
|
|
||||||
{$IFDEF ZDEBUG} ZLog('DoAbortSequence -> begin'); {$ENDIF}
|
{$IFDEF ZDEBUG} ZLog('DoAbortSequence -> begin'); {$ENDIF}
|
||||||
|
|
||||||
Client.PurgeInputData(False);
|
Client.PurgeInputData(0);
|
||||||
Client.PurgeOutputData;
|
Client.PurgeOutputData;
|
||||||
|
|
||||||
Client.BufWriteStr(Attn);
|
Client.BufWriteStr(Attn);
|
||||||
|
@ -1838,7 +1770,7 @@ Begin
|
||||||
|
|
||||||
StatusUpdate(True, False);
|
StatusUpdate(True, False);
|
||||||
|
|
||||||
RxBufLen := ZBufSize;
|
RxBufLen := CurBufSize;
|
||||||
|
|
||||||
While Not AbortTransfer Do Begin
|
While Not AbortTransfer Do Begin
|
||||||
If ZInitSender = ZFILE Then Begin
|
If ZInitSender = ZFILE Then Begin
|
||||||
|
|
Loading…
Reference in New Issue