📄 awtpcl.pas
字号:
(***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is TurboPower Async Professional
*
* The Initial Developer of the Original Code is
* TurboPower Software
*
* Portions created by the Initial Developer are Copyright (C) 1991-2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* ***** END LICENSE BLOCK ***** *)
{*********************************************************}
{* AWTPCL.PAS 4.06 *}
{*********************************************************}
{* Protocol type definitions *}
{*********************************************************}
{Global defines potentially affecting this unit}
{$I AWDEFINE.INC}
unit AwTPcl;
{Type definitions for protocol units}
interface
uses
WinTypes,
WinProcs,
SysUtils,
OoMisc,
AdPort,
AwUser;
const
{Compile-time options}
FileBufferSize = 8192; {Size of buffer for receive/xmitting files}
awpDefHandshakeWait = 182; {Wait time for resp during handshake (10 sec)}
awpDefHandshakeRetry = 10; {Number of times to retry handshake}
awpDefTransTimeout = 1092; {Ticks to wait for receiver flow control release}
apMaxBlockSize = 1024; {Maximum block size for most protocols}
BlockFillChar : char = ^Z; {Fill character for partial protocol blocks}
TelixDelay = 9; {Delay handshake for 9 Ticks (for Telix)}
const
MaxWindowSlots = 27; {Avoids MS-Kermit bug}
BPTimeoutMax = 546; {Max Ticks allowed timeout per-char, 30 seconds}
BPErrorMax = 10; {Max sequential errors}
BPBufferMax = 2048; {Largest data block available}
BPSendAheadMax = 2; {Max number of packets we can send ahead (normal)}
BPDefFinishWait = 273; {Wait time for error ack, 15 seconds}
ESCIResponse : String[31] = '#IB1,SSxx,GF,PB,DT';
type
{Possible results for start block characters}
TProcessBlockStart = (pbsNone, pbs128, pbs1024, pbsCancel, pbsEOT);
{Holds info about Kermit data in Window slots}
TSlotInfo = record
Len : Integer;
Seq : Integer;
InUse : Bool;
Acked : Bool;
Retries : Cardinal;
end;
{Sliding window table, info}
TInfoTable = array[1..MaxWindowSlots] of TSlotInfo;
{Sliding window table, data}
PDataTable = ^TDataTable;
TDataTable = array[0..(MaxWindowSlots*1024)-1] of Char;
type
{Xmodem protocol states}
TXmodemState = (
{Transmit states}
txInitial, {Open file, log it, etc.}
txHandshake, {Waiting for handshake}
txGetBlock, {Get the next block to transmit}
txWaitFreeSpace, {Wait until outbuffer has enough freespace}
txSendBlock, {Send next protocol block}
txDraining, {Waiting for protocol block to drain}
txReplyPending, {Waiting for reply to last block}
txEndDrain, {Wait for output buffer to drain before EOT}
txFirstEndOfTransmit, {Send first EOT}
txRestEndOfTransmit, {Send subseqent EOTs}
txEotReply, {Waiting for EOT reply}
txFinished, {Close file, log it, etc.}
txDone, {Signal end of protocol}
{Receive states}
rxInitial, {Initialize vars, get buffers, etc.}
rxWaitForHSReply, {Waiting for 1st reply to handshake}
rxWaitForBlockStart, {Wait for block start}
rxCollectBlock, {Collect data}
rxProcessBlock, {Process block}
rxFinishedSkip, {Close file, log as skip}
rxFinished, {Close file, log as good/bad}
rxDone); {Signal end of protocol}
{Ymodem protocol transmit states}
TYmodemState = (
{Transmit states}
tyInitial, {Get next file}
tyHandshake, {Waiting for handshake}
tyGetFileName, {Get the next file to transmit}
tySendFileName, {Format and send file name block}
tyDraining, {Waiting for protocol block to drain}
tyReplyPending, {Waiting for reply to name block}
tyPrepXmodem, {Prepare to enter Xmodem state table}
tySendXmodem, {Calling Xmodem state table}
tyFinished, {Send EOT block}
tyFinishDrain, {Wait for EOT to block to drain}
tyDone, {Signal end of protocol}
{Receive states}
ryInitial, {Initialize vars, get buffers, etc.}
ryDelay, {Delay the handshake for Telix}
ryWaitForHSReply, {Waiting for 1st reply to handshake}
ryWaitForBlockStart, {Wait for block start}
ryCollectBlock, {Collect received chars into DataBlock}
ryProcessBlock, {Process complete DataBlock}
ryOpenFile, {Extract file info}
ryPrepXmodem, {Prepare to enter Xmodem state}
ryReceiveXmodem, {Calling Xmodem state table}
ryFinished, {Clean up}
ryDone); {Signal end of protocol}
{Main Zmodem state table}
TZmodemState = (
{Transmit states}
tzInitial, {Allocates buffers, sends zrqinit}
tzHandshake, {Wait for hdr (zrinit), rsend zrqinit on timout}
tzGetFile, {Call NextFile, build ZFile packet}
tzSendFile, {Send ZFile packet}
tzCheckFile, {Wait for hdr (zrpos), set next state to tzData}
tzStartData, {Send ZData and next data subpacket}
tzEscapeData, {Check for header, escape next block}
tzSendData, {Wait for free space in buffer, send escaped block}
tzWaitAck, {Wait for Ack on ZCRCW packets}
tzSendEof, {Send eof}
tzDrainEof, {Wait for output buffer to drain}
tzCheckEof, {Wait for hdr (zrinit)}
tzSendFinish, {Send zfin}
tzCheckFinish, {Wait for hdr (zfin)}
tzError, {Cleanup after errors}
tzCleanup, {Release buffers and other cleanup}
tzDone, {Signal end of protocol}
{Receive states}
rzRqstFile, {Send zrinit}
rzDelay, {Delay handshake for Telix}
rzWaitFile, {Waits for hdr (zrqinit, zrfile, zsinit, etc)}
rzCollectFile, {Collect file info into work block}
rzSendInit, {Extract send init info}
rzSendBlockPrep, {Discard last two chars of previous hex packet}
rzSendBlock, {Collect sendinit block}
rzSync, {Send ZrPos with current file position}
rzStartFile, {Extract file info, prepare writing, etc., put zrpos}
rzStartData, {Wait for hdr (zrdata)}
rzCollectData, {Collect data subpacket}
rzGotData, {Got dsp, put it}
rzWaitEof, {Wait for hdr (zreof)}
rzEndOfFile, {Close file, log it, etc}
rzSendFinish, {Send ZFin, goto rzWaitOO}
rzCollectFinish, {Check for OO, goto rzFinish}
rzError, {Handle errors while file was open}
rzWaitCancel, {Wait for the cancel to leave the outbuffer}
rzCleanup, {Clean up buffers, etc.}
rzDone); {Signal end of protocol}
{General header collection states}
THeaderState = (
hsNone, {Not currently checking for a header}
hsGotZPad, {Got initial or second asterisk}
hsGotZDle, {Got ZDle}
hsGotZBin, {Got start of binary header}
hsGotZBin32, {Got start of binary 32 header}
hsGotZHex, {Got start of hex header}
hsGotHeader); {Got complete header}
{Hex header collection states}
HexHeaderStates = (
hhFrame, {Processing frame type char}
hhPos1, {Processing 1st position info byte}
hhPos2, {Processing 2nd position info byte}
hhPos3, {Processing 3rd position info byte}
hhPos4, {Processing 4th position info byte}
hhCrc1, {Processing 1st CRC byte}
hhCrc2); {Processing 2nd CRC byte}
{Binary header collection states}
BinaryHeaderStates = (
bhFrame, {Processing frame type char}
bhPos1, {Processing 1st position info byte}
bhPos2, {Processing 2nd position info byte}
bhPos3, {Processing 3rd position info byte}
bhPos4, {Processing 1th position info byte}
bhCrc1, {Processing 1st CRC byte}
bhCrc2, {Processing 2nd CRC byte}
bhCrc3, {Processing 3rd CRC byte}
bhCrc4); {Processing 4th CRC byte}
{Only two states possible when receiving blocks}
ReceiveBlockStates = (
rbData, {Receiving data bytes}
rbCrc); {Receiving block check bytes}
{Kermit state machine states}
TKermitState = (
{Transmit states}
tkInit, {Send SendInit packet}
tkInitReply, {Wait for header reply to SendInit}
tkCollectInit, {Collect data packet for SendInit reply}
tkOpenFile, {Open next file to transmit}
tkSendFile, {Send File packet}
tkFileReply, {Wait for header reply to File}
tkCollectFile, {Collect data packet for File reply}
tkCheckTable, {Check table for space, escape next block if room}
tkSendData, {Send next Data packet}
tkBlockReply, {Wait for header reply to Data}
tkCollectBlock, {Collect data packet for Data reply}
tkSendEof, {Send Eof packet}
tkEofReply, {Wait for header reply to Eof}
tkCollectEof, {Collect data packet for Eof reply}
tkSendBreak, {Send Break packet}
tkBreakReply, {Wait for header reply to Break}
tkCollectBreak, {Collect data packet for Break reply}
tkComplete, {Send Complete packet}
tkWaitCancel, {Wait for cancel to go out}
tkError, {Done, log and clean up}
tkDone, {Signals end of protocol}
{Receive states}
rkInit, {Set initial timer}
rkGetInit, {Wait for SendInit header}
rkCollectInit, {Collect SendInit data field}
rkGetFile, {Wait for File header}
rkCollectFile, {Collect File data field}
rkGetData, {Wait for Data header}
rkCollectData, {Collect Data data field}
rkComplete, {Normal completion}
rkWaitCancel, {Wait for cancel to go out}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -