📄 awtpcl.pas
字号:
rkError, {Error completion}
rkDone); {Signals end of protocolcompletion}
{Header state machine states}
TKermitHeaderState = (
hskNone, {No header collection in process}
hskGotMark, {Got mark}
hskGotLen, {Got length byte}
hskGotSeq, {Got sequence number}
hskGotType, {Got packet type}
hskGotLong1, {Got first byte of long length}
hskGotLong2, {Got second byte of long length}
hskDone); {Got everything}
TKermitDataState = (
dskData, {Collecting data bytes}
dskCheck1, {Collecting check bytes}
dskCheck2, {Collecting check bytes}
dskCheck3); {Collecting check bytes}
type
{B+ buffer}
PBPDataBlock = ^TBPDataBlock;
TBPDataBlock = array[1..BPBufferMax] of Char;
{B+ window buffer}
TSABuffer = record
Seq : Cardinal; {Sequence number}
Num : Cardinal; {Packet's data size}
PType : Char; {Packet type}
Buf : PBPDataBlock; {Packet's data}
end;
TSPackets = array[1..BPSendAheadMax] of TSABuffer;
{For quoting params sets and all data}
TQuoteArray = array[0..7] of Byte;
TQuoteTable = array[0..255] of Char;
type
{Main BPlus state table}
TBPlusState = (
{Receive states}
rbInitial, {Start waiting for first N packet}
rbGetDLE, {Get header start, <DLE>}
rbGetB, {Get B of header start}
rbCollectPacket, {Collect packet, checksum and verify}
rbProcessPacket, {Check packet type and dispatch}
rbFinished, {Normal end of protocol}
rbSendEnq, {Send <ENQ><ENQ> after a timeout}
rbError, {Error end of protocol}
rbWaitErrorAck, {Wait for Ack for failure packet}
rbCleanup, {Cleanup and end protocol}
rbDone, {Signal end}
{Transmit states}
tbInitial, {Startup stuff}
tbGetBlock, {Read next block to xmit}
tbWaitFreeSpace, {Wait for free space to send block}
tbSendData, {Transmit the next block}
tbCheckAck, {Wait for acknowledgements (handle re-xmits)}
tbEndOfFile, {Send TC packet}
tbEofAck, {Wait for TC ack}
tbError, {Failed}
tbWaitErrorAck, {Wait for Ack for failure packet}
tbCleanup, {Cleanup and end protocol}
tbDone); {Signal end}
{Packet collection states}
TPacketState = (
psGetDLE, {Waiting for DLE}
psGetB, {Waiting for B}
psGetSeq, {Waiting for sequence number}
psGetType, {Get type byte}
psGetData, {Collecting data}
psGetCheck1, {Waiting for first check byte}
psGetCheck2, {Waiting for second check byte, if any}
psCheckCheck, {Checking block check}
psSendAck, {OK, sending ACK (finished)}
psError, {Error collecting packet}
psSuccess); {Packet collected OK}
{Terminal packet state, when processing packets in terminal mode}
TTermPacketState = (
tpsWaitB, {Waiting for B}
tpsWaitSeq, {Waiting for sequence}
tpsWaitType, {Waiting for packet type, process when found}
tpsCollectPlus, {Collecting + packet}
tpsCollectAckPlus, {Collecting ack from + response}
tpsCollectT, {Collecting T packet}
tpsCollectAckT, {Collecting ack from optional T response}
tpsError); {Error collecting packet}
{Ack collection state}
TAckCollectionState = (
acGetDLE, {Wait for DLE}
acGetNum, {Wait for packet number}
acHaveAck, {Got ack, check sequence}
acGetPacket, {Got packet, start collecting}
acCollectPacket, {Collect packet}
acSkipPacket1, {Discard packet data}
acSkipPacket2, {Discard 1st checksum byte}
acSkipPacket3, {Discard quoted part of 1st checksum byte}
acSkipPacket4, {Discard 2nd checksum byte}
acSkipPacket5, {Discard quoted part of 2nd checksum byte}
acTimeout, {Timeout collecting data}
acError, {Error processing ack/packet}
acSendNak, {Sending nak}
acSendEnq, {Sending enq and resyncing}
acResync1, {Collect 1st DLE of resync}
acResync2, {Collect seq of first resync}
acResync3, {Collect 2nd DLE of resync}
acResync4, {Collect seq of second resync}
acSendData, {Sending data}
acFailed); {Failed miserably}
{Protocol direction options}
TDirection = (dUpload, dDownload);
{Transfer parameters}
ParamsRecord = record
WinSend : Byte; {Send window size}
WinRecv : Byte; {Receive window size}
BlkSize : Byte; {Block size (* 128)}
ChkType : Byte; {Check type, chksum or CRC}
QuoteSet : TQuoteArray; {Chars to quote}
DROpt : Byte; {DL Recovery option}
UROpt : Byte; {UL Recovery option}
FIOpt : Byte; {File Info option}
end;
{Ascii state table}
TAsciiState = (
taInitial, {Prepare to transmit file}
taGetBlock, {Get next block to transmit}
taWaitFreeSpace, {Wait for free space in output buffer}
taSendBlock, {Start transmitting current block}
taSendDelay, {Wait for delay for next outgoing character/line}
taFinishDrain, {Wait for last data to go out}
taFinished, {Normal or error completion, cleanup}
taDone, {Done with transmit}
raInitial, {Prepare to receive file}
raCollectBlock, {Collect block}
raProcessBlock, {Check for ^Z, write block to disk}
raFinished, {Normal or error completion, cleanup}
raDone); {Done with receive}
type
{For storing received and transmitted blocks}
PDataBlock = ^TDataBlock;
TDataBlock = array[1..apMaxBlockSize] of Char;
{Describes working buffer for expanding a standard buffer with escapes}
PWorkBlock = ^TWorkBlock;
TWorkBlock = array[1..2*apMaxBlockSize] of Char;
{Describes 4K internal input buffer for Kermit}
PInBuffer = ^TInBuffer;
TInBuffer = array[1..4096] of Char;
{Describes data area of headers}
TPosFlags = array[0..3] of Byte;
{For buffering received and transmitted files}
PFileBuffer = ^TFileBuffer;
TFileBuffer = array[0..FileBufferSize-1] of Byte;
PProtocolData = ^TProtocolData;
{Prepare procedure}
TPrepareProc = procedure(P : PProtocolData);
{Protocol notification function}
TProtocolFunc = procedure(
Msg, wParam : Cardinal;
lParam : LongInt);
{Hook types}
PrepFinishProc = procedure(P : PProtocolData);
{-Prepare/cleanup file reading/writing}
ReadProtProc = function (P : PProtocolData;
var Block : TDataBlock;
var BlockSize : Cardinal) : Bool;
{-Get next block of data to transmit}
WriteProtProc = function (P : PProtocolData;
var Block : TDataBlock;
BlockSize : Cardinal) : Bool;
{-Write block of data just received}
CancelFunc = procedure(P : PProtocolData);
{-Send Cancel sequence}
ShowStatusProc = procedure(P : PProtocolData; Options : Cardinal);
{-Send message to status window}
NextFileFunc = function(P : PProtocolData; FName : PChar) : Bool;
{-Request next file to transmit}
LogFileProc = procedure(P : PProtocolData; LogFileStatus : Cardinal);
{-Log transmitted/received file}
AcceptFileFunc = function(P : PProtocolData; FName : PChar) : Bool;
{-Accept this incoming file?}
TKermitOptions = record
MaxPacketLen : Byte;
MaxTimeout : Byte;
PadCount : Byte;
PadChar : Char;
Terminator : Char;
CtlPrefix : Char;
HibitPrefix : Char;
Check : Char;
RepeatPrefix : Char;
CapabilitiesMask : Byte;
WindowSize : Byte;
MaxLongPacketLen : Cardinal;
SendInitSize : Cardinal;
end;
{The complete protocol record}
TProtocolData = record
{Trigger handles}
aStatusTrigger : Integer; {Status timer trigger handle}
aTimeoutTrigger : Integer; {Timeout timer trigger handle}
aOutBuffFreeTrigger : Integer; {Outbuffree status trigger handle}
aOutBuffUsedTrigger : Integer; {Outbuffused status trigger handle}
aNoCarrierTrigger : Integer; {No carrier status trigger handle}
{General...}
aHWindow : HWnd; {Registered window}
aHC : TApdCustomComPort; {Handle of port component}
aBatchProtocol : Bool; {True if protocol supports batch}
aFilesSent : Bool; {True if we actually sent a file}
aAbortFlag : Bool; {True to signal abort}
aTimerStarted : Bool; {True once timer has been started}
aCurProtocol : Integer; {Protocol type}
aCheckType : Cardinal; {Code for block check type}
aHandshakeRetry : Cardinal; {Attempts to retry handshaking}
aHandshakeWait : Cardinal; {Wait seconds during handshaking}
aHandshakeAttempt : Cardinal; {Current handshake attempt}
aBlockLen : Cardinal; {Block length}
aBlockNum : Cardinal; {Current block number}
aFlags : Cardinal; {AbstractProtocol options}
aTransTimeout : Cardinal; {Ticks to wait for trans freespace}
aFinishWait : Cardinal; {Wait time for ZFin/EOT response}
aRcvTimeout : Cardinal; {Seconds to wait for received char}
aProtocolStatus : Cardinal; {Holds last status}
aLastBlockSize : Cardinal; {Last blocksize}
aProtocolError : Integer; {Holds last error}
aSrcFileLen : LongInt; {Size of file (in bytes)}
aSrcFileDate : LongInt; {Timestamp of source file}
aBlockCheck : DWORD; {Block check value}
aInitFilePos : LongInt; {Initial file pos during resumes}
aReplyTimer : EventTimer; {Track timeouts waiting replies}
aDataBlock : PDataBlock; {Working data block}
aCurProtFunc : TProtocolFunc; {Protocol function}
{$IFDEF Win32}
aProtSection : TRTLCriticalSection; {When state machine is busy}
{$ENDIF}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -