⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 admdm.pas

📁 测试用例
💻 PAS
📖 第 1 页 / 共 5 页
字号:
    SendCommand(LmModem.Reset);
  end;
  ConfigInit := LmModem.Settings.Prefix + ' ';
  with FModemConfig do begin
    { port settings }
    FComPort.DataBits := DataBits;
    FComPort.Parity := Parity;
    FComPort.StopBits := StopBits;
    { speaker options }
    case SpeakerVolume of
      svLow  : ConfigInit := ConfigInit + LmModem.Settings.SpeakerVolume_Low + ' ';
      svMed  : ConfigInit := ConfigInit + LmModem.Settings.SpeakerVolume_Med + ' ';
      svHigh : ConfigInit := ConfigInit + LmModem.Settings.SpeakerVolume_High + ' ';
    end;
    case SpeakerMode of
      smOff   : ConfigInit := ConfigInit + LmModem.Settings.SpeakerMode_Off + ' ';
      smOn    : ConfigInit := ConfigInit + LmModem.Settings.SpeakerMode_On + ' ';
      smDial  : ConfigInit := ConfigInit + LmModem.Settings.SpeakerMode_Dial + ' ';
    end;
    { connection control }
    case FlowControl of
      fcOff  : ConfigInit := ConfigInit + LmModem.Settings.FlowControl_Off + ' ';
      fcHard : ConfigInit := ConfigInit + LmModem.Settings.FlowControl_Hard + ' ';
      fcSoft : ConfigInit := ConfigInit + LmModem.Settings.FlowControl_Soft + ' ';
    end;
    if ecOff in ErrorControl then
      ConfigInit := ConfigInit + LmModem.Settings.ErrorControl_Off + ' '
    else begin
      ConfigInit := ConfigInit + LmModem.Settings.ErrorControl_On + ' ';
      if ecForced in ErrorControl then
       ConfigInit := ConfigInit + LmModem.Settings.ErrorControl_Forced + ' ';
      if ecCellular in ErrorControl then
        ConfigInit := ConfigInit + LmModem.Settings.ErrorControl_Cellular + ' ';
    end;
    if Compression then
      ConfigInit := ConfigInit + LmModem.Settings.Compression_On + ' '
    else
      ConfigInit := ConfigInit + LmModem.Settings.Compression_Off + ' ';
    case Modulation of
      smBell      : ConfigInit := ConfigInit + LmModem.Settings.Modulation_Bell + ' ';
      smCCITT     : ConfigInit := ConfigInit + LmModem.Settings.Modulation_CCITT + ' ';
      smCCITT_V23 : ConfigInit := ConfigInit + LmModem.Settings.Modulation_CCITT_V23 + ' ';
    end;
    if BlindDial then
      ConfigInit := ConfigInit + LmModem.Settings.Blind_On
    else
      ConfigInit := ConfigInit + LmModem.Settings.Blind_Off;
    ConfigInit := ConfigInit +
      PoundReplace(LmModem.Settings.CallSetupFailTimer, CallSetupFailTimeout) + ' ';
    ConfigInit := ConfigInit +
      PoundReplace(LmModem.Settings.InactivityTimeout, InactivityTimeout) + ' ';
    ConfigInit := ConfigInit + LmModem.Settings.Terminator;

    {$IFDEF AdModemDebug}
    FComPort.AddStringToLog('Init 1');
    {$ENDIF}
    SendCommand(ConvertXML(ConfigInit));

    if ExtraSettings <> '' then begin
      {$IFDEF AdModemDebug}
      FComPort.AddStringToLog('Init 2');
      {$ENDIF}
      SendCommand(ConvertXML(ExtraSettings + #13));
    end;
  end;
  Initialized := True;
end;

function TAdCustomModem.ModemLogToString(
  LogCode: TApdModemLogCode): string;
  { convert a LogCode into a string }
begin
  case LogCode of
    mlNone         : Result := 'None, nothing to log';
    mlDial         : Result := 'Dialing';
    mlAutoAnswer   : Result := 'Initiated AutoAnswer';
    mlAnswer       : Result := 'Answering an incoming call';
    mlConnect      : Result := 'Connected';
    mlCancel       : Result := 'Call cancelled';
    mlBusy         : Result := 'Called number was busy';
    mlConnectFail  : Result := 'Connection attempt failed';
    else             Result := 'Undefined modem log code';
  end;
end;

function TAdCustomModem.ModemStatusMsg(Status: TApdModemState): string;
  { convert a status code into a string }
var
  Plural : char;
begin
  case Status of
    msUnknown :
      Result := 'Hasn''t been initialized';
    msIdle :
      Result := 'Idle and ready';
    msInitializing :
      Result := 'Starting initialization process';
    msAutoAnswerBackground :
      Result := 'AutoAnswer no rings received';
    msAutoAnswerWait :
      begin
        if (FAnswerOnRing - FRingCount) > 1 then
          Plural := 's'
        else
          Plural := ' ';
        Result := Format('AutoAnswer waiting for %d more ring%s',
          [FAnswerOnRing - FRingCount, Plural]);
      end;
    msAnswerWait :
      Result := 'Answering call waiting for connect';
    msDial :
      Result := Format('Dialing %s', [FPhoneNumber]);
    msConnectWait :
      Result := 'Waiting for remote to answer';
    msConnected :
      Result := 'Connected';
    msHangup :
      Result := 'Starting hangup process';
    msCancel :
      Result := 'Starting cancel process';
    else
      Result := 'Undefined modem state';
  end;
end;

procedure TAdCustomModem.Notification(AComponent: TComponent;
  Operation: TOperation);
begin
  inherited Notification(AComponent, Operation);

  if not (csDesigning in ComponentState) then
    exit;
  if (Operation = opRemove) then begin
    { see if our com port is going away }
    if (AComponent = FComPort) then
      ComPort := nil;
    { see if our status dialog is going away }
    if (AComponent = FStatusDisplay) then
      StatusDisplay := nil;
  end else if (Operation = opInsert) then begin
    {Check for a com port being installed}
    if not Assigned(FComPort) and (AComponent is TApdCustomComPort) then
      ComPort := TApdCustomComPort(AComponent);
    if not Assigned(FStatusDisplay) and (AComponent is TAdAbstractModemStatus) then
      StatusDisplay := TAdAbstractModemStatus(AComponent);
  end;
end;

procedure TAdCustomModem.PrepForConnect(EnableTriggers: Boolean);
begin
  if EnableTriggers then begin
    { somebody set us up the trigger }
    if DCDTrigger > 0 then
      FComPort.RemoveTrigger(DCDTrigger);
    DCDTrigger := FComPort.AddStatusTrigger(stModem);
    FComPort.SetStatusTrigger(DCDTrigger, msDCDDelta, True);
    if StatusTimerTrigger > 0 then
      FComPort.RemoveTrigger(StatusTimerTrigger);
    StatusTimerTrigger := FComPort.AddTimerTrigger;
    FComPort.SetTimerTrigger(StatusTimerTrigger, 1000, True);
  end else begin
    if DCDTrigger > 0 then begin
      FComPort.RemoveTrigger(DCDTrigger);
      DCDTrigger := 0;
    end;
    if StatusTimerTrigger > 0 then begin
      FComPort.RemoveTrigger(StatusTimerTrigger);
      StatusTimerTrigger := 0;
    end;
  end;
  FNegotiationResponses.Clear;
end;

procedure TAdCustomModem.ResponseStringPacket(Sender: TObject;
  Data: String);
var
  Res : Integer;
begin
  { we've detected a string ending with #13#10, see if it is }
  { something we are looking for }
  { assume it's not }
  OKResponse := False;
  ErrorResponse := False;
  ConnectResponse := False;
  WaitingForResponse := True;

  { if we're waiting for the connection, add the response to the list }
  if FModemState in [msConnectWait, msAnswerWait] then begin
    if Data <> #13#10 then begin
      {$IFDEF AdModemDebug}
      FComPort.AddStringToLog('Informative response');
      {$ENDIF}
      FNegotiationResponses.Add(Data);
    end;
  end;

  Res := CheckErrors(Data);
  if Res <> ecOK then begin
    ErrorResponse := True;
    WaitingForResponse := False;
    if (FModemState = msHangup) and (Res = ecModemNoCarrier) then
      { we've disconnected }
    else begin
      DoFail(Res);
      Exit;
    end;
  end;

  { check for caller ID tags }
  if FModemState in [msAutoAnswerBackground, msAutoAnswerWait, msAnswerWait] then begin
    CheckCallerID(Data);
    ResponsePacket.Enabled := True;
  end;

  { interpret the response based on what state we're in }
   case FModemState of
    msUnknown,
    msIdle,
    msConnected : { anything here means that the packet wasn't disabled }
      begin
        ResponsePacket.Enabled := False;
        WaitingForResponse := False;
      end;
    msInitializing : { anything here should be a OK or ERROR response }
      begin
        if CheckResponses(Data, ApxDefOKResponse, LmModem.Responses.OK) then begin
          { it's an OK }
          {$IFDEF AdModemDebug}
          FComPort.AddStringToLog('OKResponse');
          {$ENDIF}
          OKResponse := True;
          WaitingForResponse := False;
        end else
          if Pos(LastCommand, Data) > 0 then begin
            {$IFDEF AdModemDebug}
            FComPort.AddStringToLog('EchoResponse');
            {$ENDIF}
            ResponsePacket.Enabled := True;
          end else begin
            {$IFDEF AdModemDebug}
            FComPort.AddStringToLog('Unknown response');
            {$ENDIF}
            DoFail(ecModemRejectedCommand);
            WaitingForResponse := False;
          end;
      end;
    msAutoAnswerBackground :
      begin
        if CheckResponses(Data, ApxDefRingResponse, LmModem.Responses.Ring) then begin
          { it's the first RING }
          if not FCallerIDProvided and CallerIDInfo.HasData then begin
            DoCallerID;
          end;
          FRingCount := 1;
          {$IFDEF AdModemDebug}
          FComPort.AddStringToLog('Ring' + IntToStr(FRingCount));
          {$ENDIF}
          DoStatus(msAutoAnswerWait);
          ResponsePacket.TimeOut := FRingWaitTimeout;
          ResponsePacket.EnableTimeOut := FRingWaitTimeout;              {!!.04}
          ResponsePacket.Enabled := True;
        end;
      end;
    msAutoAnswerWait : { looking for more RINGs }
      begin
        if CheckResponses(Data, ApxDefRingResponse, LmModem.Responses.Ring) then begin
          { it's another RING }
          inc(FRingCount);
          if not FCallerIDProvided and CallerIDInfo.HasData then begin
            DoCallerID;
          end;
          { see if we need to answer it now }
          if FRingCount >= FAnswerOnRing then begin
            DoStatus(msAnswerWait);
            WaitingForResponse := False;
            { send the ATA }
            {$IFDEF AdModemDebug}
            FComPort.AddStringToLog('AutoAnswer post');
            {$ENDIF}
            Postmessage(Handle, apw_AutoAnswer, 0, 0);
          end else begin
            { not enough rings }
            {$IFDEF AdModemDebug}
            FComPort.AddStringToLog('Ring' + IntToStr(FRingCount));
            {$ENDIF}
            DoStatus(msAutoAnswerWait);
            ResponsePacket.TimeOut := FRingWaitTimeout;
            ResponsePacket.EnableTimeOut := FRingWaitTimeout;            {!!.04}
            ResponsePacket.Enabled := True;
          end;
        end;
      end;

    msAnswerWait,
    msDial,
    msConnectWait : { waiting for connect or error }
      begin
        if CheckResponses(Data, ApxDefConnectResponse, LmModem.Responses.Connect) then begin
          { it's a CONNECT }
          ConnectResponse := True;
          OKResponse := True;
          WaitingForResponse := False;
          {$IFDEF AdModemDebug}
          FComPort.AddStringToLog('Connect response');
          {$ENDIF}
          if not FConnected then begin
            DoStatus(msConnected);
            DoConnect;
          end;
        end else
          ResponsePacket.Enabled := True;
      end;
    msHangup,
    msCancel : { starting hangup }
      begin
        WaitingForResponse := False;
      end;
  end;
end;

procedure TAdCustomModem.ResponseTimeout(Sender: TObject);
begin
  { data packet timed out }
  TimedOut := True;
  if FModemState = msAutoAnswerWait then begin
    FRingCount := 0;
    DoStatus(msAutoAnswerBackground);
    ResponsePacket.Timeout := 0;
    ResponsePacket.Enabled := True;
  end;
end;

function TAdCustomModem.SelectDevice: Boolean;
  { display the modem selection dialog }
begin
  try
    Result := False;                                                     {!!.06}
    if not DirectoryExists(FModemCapFolder) then                         {!!.06}
      raise EInOutError.CreateFmt(                                       {!!.06}
        'Modemcap folder not found'#13#10'(%s)', [FModemCapFolder]);     {!!.06}
        
    {$IFDEF AdModemDebug}
    if Assigned(FComPort) then
      FComPort.AddStringToLog('Selecting');
    {$ENDIF}
    LibModem.LibModemPath := FModemCapFolder;
    Result := LibModem.SelectModem(
      FSelectedDevice.FModemFile,
      FSelectedDevice.FManufacturer,
      FSelectedDevice.FName, LmModem);
    FDeviceSelected := Result;                                    {!!.04}{!!.05}
    {$IFDEF AdModemDebug}
    if Result and Assigned(FComPort) then begin
       FComPort.AddStringToLog('Selected from ' + FSelectedDevice.FModemFile);
       FComPort.AddStringToLog('Selected manufacturer: ' + FSelectedDevice.FManufacturer);
       FComPort.AddStringToLog('Selected device: ' + FSelectedDevice.FName);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -