home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / COMMCDS.ZIP / TESTCDS.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1993-01-04  |  6.8 KB  |  217 lines

  1. {$M 4096,0,0}
  2. PROGRAM TestCDS;  {Version 0.90}
  3.  
  4. {$DEFINE COMMENTS}
  5.  
  6.    {This program generates a sample CDS activity log and calls on a program
  7. named "Operator" to calculate the cost of a call currently in progress.  It
  8. is designed as a limited tutorial for using the CommCDS unit in a program.
  9.  
  10.    This program, like the CommCDS unit, requires the TPRO5 toolkit from
  11. TurboPower Software in order to be compiled.}
  12.  
  13.  
  14. USES
  15.    TpCRT,
  16.    TpDate,
  17.    CommCDS;
  18.  
  19.  
  20. CONST
  21.    MaxByte    = 255;
  22.    NullString = '';
  23.  
  24.    OurName      = 'TESTCDS';         {the name of our test program}
  25.    AnalyzerName = 'OPERATOR';        {the name of a CDS phone bill analyzer}
  26.    ConnectARQ   = 'Modems established ARQ connection';
  27.  
  28.    Comment1 =
  29.       'This first comment shows what is possible in the Call Data Standard.  '
  30.     + 'Look above: you''ll see this comment has no "COM port" entry.  The '
  31.     + 'CommCDS unit knows no call is in progress, so it assumes this must be '
  32.     + 'a "generic", or global, comment.';
  33.  
  34.    Comment2 =
  35.       'If you look closely at the code, you will see it is formatted '
  36.     + 'differently compared to the final output in the CDS log file.  This '
  37.     + 'is because the CommCDS unit uses word-wrapping to keep the comments '
  38.     + 'within CDS log file syntax constraints.';
  39.  
  40.    Comment3 =
  41.       'This comment was added to the CDS log while a call was in progress.  '
  42.     + 'CommCDS added a "COM port" entry (above) which ties it to the call.';
  43.  
  44. VAR
  45.    TheComPort   : BYTE;
  46.    TheComSpeed  : LONGINT;
  47.    TheComBits   : BYTE;
  48.    TheComParity : CHAR;
  49.    TheComStopB  : BYTE;
  50.    NameOfBBS    : STRING;
  51.    PhoneNumber  : STRING;
  52.  
  53.    FileName        : STRING;
  54.    FileSize        : LONGINT;
  55.    Protocol        : CDSProtocolType;
  56.    TransferStarted : DateTimeRec;
  57.    TransferEnded   : DateTimeRec;
  58.    TotalXmitErrors : WORD;
  59.    Efficiency      : REAL;
  60.    AverageCPS      : WORD;
  61.  
  62. {============================================================================}
  63. PROCEDURE WasteTime;
  64.  
  65.    {This procedure provides us with a time lapse between CDS log entries.  It
  66. can be bypassed at any instant by pressing a key.}
  67.  
  68. VAR
  69.    GarbageChar : CHAR;
  70.    Index       : WORD;
  71.  
  72. BEGIN {WasteTime}
  73. IF (MaxByte = 0)
  74.  THEN EXIT; {no need to hang around here, eh?}
  75.  
  76. {Initialize.}
  77. WHILE KEYPRESSED
  78.  DO GarbageChar := READKEY;
  79.  
  80. {Waste some time to show a time lapse for the next log entry.}
  81. WRITELN(OUTPUT,'This countdown generates ''elapsed time''');
  82. WRITELN(OUTPUT,'between CDS log entries.  Press any key');
  83. WRITELN(OUTPUT,'if you want to stop the countdown.');
  84. FOR Index := MaxByte DOWNTO 1
  85.  DO BEGIN
  86.     WRITE(OUTPUT,^M'Countdown: ',Index,' seconds...    ');
  87.     IF KEYPRESSED
  88.      THEN {null}
  89.      ELSE DELAY(1000)
  90.     END;
  91.  
  92. WHILE KEYPRESSED
  93.  DO GarbageChar := READKEY;
  94.  
  95. WRITELN(OUTPUT);
  96. WRITELN(OUTPUT)
  97. END; {WasteTime}
  98. {============================================================================}
  99.  
  100. BEGIN {TestCDS}
  101. {Initialize program.}
  102. ProgramName := OurName;
  103. HostName    := NullString;
  104. InitCommCDS(NullString);
  105.  
  106. {$IFDEF COMMENTS}
  107.     {Let's log a CDS free-format comment to show that it can be done.}
  108.     LogFreeFormatComment(Comment1);
  109.     LogFreeFormatComment(Comment2);
  110.     LogFreeFormatComment(NullString);
  111.     IF (CDSIORESULT = 0)
  112.      THEN {everything went okay}
  113.      ELSE HALT(CDSIORESULT);
  114. {$ENDIF}
  115.  
  116. {We just connected to a call we placed.}
  117. TheComPort   := 1;          {we're using COM1}
  118. TheComSpeed  := 19200;      {we're running at 19.2k}
  119. TheComBits   := 8;          {our # of data bits}
  120. TheComParity := 'N';        {the parity (none)}
  121. TheComStopB  := 1;          {the stop bits (1)}
  122. NameOfBBS    := 'TheBBS';   {name of the BBS we dialed}
  123. PhoneNumber  := '555-1212'; {phone number for BBS}
  124.  
  125. {Tell CDS we just placed a call!}
  126. LogOutgoingCall(TheComPort,
  127.                 TheComSpeed,
  128.                 TheComBits,
  129.                 TheComParity,
  130.                 TheComStopB,
  131.                 NullString,    {we don't know who our user is}
  132.                 UnknownReason, {business or personal call status is unknown}
  133.                 NameOfBBS,
  134.                 PhoneNumber,
  135.                 FALSE,         {this is not a host callback}
  136.                 ConnectARQ);   {we know we connected with an ARQ}
  137. IF (CDSIORESULT = 0)
  138.  THEN {everything went okay}
  139.  ELSE HALT(CDSIORESULT);
  140.  
  141. {$IFDEF COMMENTS}
  142.     {This next CDS free-format comment will be "tied" to the call in progress.}
  143.     LogFreeFormatComment(Comment3);
  144.     LogFreeFormatComment(NullString);
  145.     IF (CDSIORESULT = 0)
  146.      THEN {everything went okay}
  147.      ELSE HALT(CDSIORESULT);
  148. {$ENDIF}
  149.  
  150. WasteTime;
  151.  
  152. {"Overhead" for logging into BBS is finished; we're in the Main conference.}
  153. LogForumSwitch('MAIN',NullString);
  154. IF (CDSIORESULT = 0)
  155.  THEN {everything went okay}
  156.  ELSE HALT(CDSIORESULT);
  157.  
  158. WasteTime;
  159.  
  160. {Pretend we moved to the download conference area.}
  161. LogForumSwitch('Download',NullString);
  162. IF (CDSIORESULT = 0)
  163.  THEN {everything went okay}
  164.  ELSE HALT(CDSIORESULT);
  165.  
  166. WasteTime;
  167.  
  168. {Now we're going to fake an uploaded file.}
  169. FileName          := 'SOMEFILE.ZIP';
  170. FileSize          := 18027;          {pretend this is the size of the file}
  171. Protocol          := YmodemG;        {pretend this is the transfer protocol}
  172. TransferStarted.D := Today;
  173. TransferStarted.T := CurrentTime;
  174.  
  175. WasteTime; {generate some elapsed time for the file transfer}
  176.  
  177. WITH TransferEnded
  178.  DO BEGIN
  179.     D := Today;
  180.     T := CurrentTime
  181.     END;
  182. TotalXmitErrors := 13;  {pretend we had lots of xmit errors}
  183. Efficiency      := 0.0; {pretend the file aborted, therefore no efficiency}
  184. AverageCPS      := 0;   {pretend the file aborted, therefore no avg CPS}
  185.  
  186. LogFileXfer(FileName,
  187.             TRUE,             {we're uploading this file}
  188.             FileSize,
  189.             UnknownReason,    {we don't know if this is business or personal}
  190.             Protocol,
  191.             FALSE,            {let a CDS phone bill analyzer decide if it
  192.                                 should suspend host BBS charges}
  193.             TransferStarted,
  194.             TransferEnded,
  195.             FALSE,            {pretend it wasn't aborted by sender}
  196.             FALSE,            {pretend it wasn't aborted by receiver}
  197.             TRUE,             {pretend it died when DTR went down}
  198.             TotalXmitErrors,
  199.             Efficiency,
  200.             AverageCPS,
  201.             NullString);
  202.  
  203.  
  204. {Okay, now the call has ended.}
  205. LogTerminatedCall(FALSE,       {no password on a regular outgoing call}
  206.                   FALSE,       {DTR is down, not up}
  207.                   TRUE,        {pretend we abruptly lost the carrier}
  208.                   0,           {we don't calculate average CPS for a call}
  209.                   NullString); {no comment for the CDS log}
  210. IF (CDSIORESULT = 0)
  211.  THEN {everything went okay}
  212.  ELSE HALT(CDSIORESULT);
  213.  
  214. WrapupCommCDS
  215. {And that's all he wrote!}
  216. END. {TestCDS}
  217.