Transferência e Supervisão
|
Início Anterior Próximo |
|
procedure TForm1.voice1PlayStop(Sender: TObject; Port,
|
StopStatus: Smallint);
|
begin
|
|
case StopStatus of
|
ssNormal: //MENSAGEM FOI ATE O FIM
|
begin
|
case Estado[Port] of
|
(........)
|
TRANSFERENCIA:
|
begin
|
if (lstRamal.Count > 0) then //ainda tem ramais
|
begin
|
if nEstadoRamal[Port] <> LIVRE then
|
begin
|
//verifica se
|
nEstadoRamal[Port] := LIVRE;
|
voice1.PlayFile(Port,'sisaguar.sig','');
|
end
|
else
|
Begin
|
//prepara discagem
|
InsereDado(Port,'Executando Flash...');
|
nEstadoFlash[Port] := DISCA;
|
voice1.Flash(Port,700,1500);
|
end;
|
end
|
else
|
begin
|
//Acabaram os ramais da lista
|
//Fala "tente mais tarde"
|
Estado[Port] := TENTEMAISTARDE;
|
voice1.PlayFile(Port,'MAISTARD.SIG','');
|
end;
|
end;
|
TENTEMAISTARDE:
|
begin
|
Sleep(100);
|
voice1.HangUp(Port);
|
Estado[Port] := NADA;
|
InsereDado(Port,'Não ouve atendimento. Desligado!');
|
InsereDado(Port,'Esperando nova ligação...');
|
end;
|
end;
|
ssDigitReceived:
|
begin
|
(........)
|
end; //submenu
|
end;
|
(........)
|
|
|
Mais uma vez reforçamos esta característica assíncrona que a VoicerLib tem. Repare que dentro do evento OnPlayStop é executado o PlayFile. O fluxo continua e sai do OnPlayStop. Quando a mensagem termina o evento é chamado novamente. Não se trata de recursividade.
|
|
O primeiro bloco da rotina anterior inicia a transferência através do comando Flash. Antes é necessário atribuir a variável nEstadoFlash com o valor DISCA para que possa ser diferenciado a situação de flash para discar e flash para retomar a ligação (em caso de ocupado ou não atender). Como o flash é um comando lento, sua conclusão dar-se-á no evento OnAfterFlash:
|
|
procedure TForm1.voice1AfterFlash(Sender: TObject; Port:
|
Smallint);
|
begin
|
case nEstadoFlash[Port] of
|
DISCA:
|
begin
|
InsereDado(Port,'Discando para o Ramal ' +
|
lstRamal.Strings[0]);
|
voice1.Dial(Port, lstRamal.Strings[0],1000);
|
nChamando[Port] := 1;
|
end;
|
(......)
|
|
|
procedure TForm1.voice1AfterDial(Sender: TObject; Port:
|
Smallint);
|
begin
|
case Estado[Port] of
|
TRANSFERENCIA:
|
begin
|
InsereDado(Port,'Iniciando Supervisão...');
|
voice1.EnableCallProgress(Port);
|
voice1.EnableAnswerDetection(Port);
|
//12 segundos ate o primeiro toque
|
nContaTimeOutAtende[Port] := 12;
|
end;
|
end;
|
end;
|
|
A supervisão é iniciada com o EnableCallProgress que monitora os tons de "chamando" e ocupado e o EnableAnswerDetection que monitora o atendimento.
|
|
Com a placa VoicerPhone utilizando um headset é necessário desligar o microfone antes de habilitar as supervisões de linha
|
|
Neste momento o sistema deverá estar preparado para 3 situações: atendimento, ocupado e não atende.
|
|
O atendimento poderá ser tratado de duas maneiras: a primeira é através da detecção propriamente dita que gera o evento OnAnswerDetected:
|
|
procedure TForm1.voice1AnswerDetected(Sender: TObject; Port:
|
Smallint);
|
begin
|
case Estado[Port] of
|
TRANSFERENCIA:
|
begin
|
voice1.DisableAnswerDetection(Port);
|
voice1.DisableCallProgress(Port);
|
InsereDado(Port,'Ligação Entregue. Esperando nova...');
|
voice1.HangUp(Port);
|
Estado[Port] := NADA;
|
end;
|
end;
|
end;
|
|
procedure TForm1.tmrGeralTimer(Sender: TObject);
|
var
|
Port: integer;
|
begin
|
for Port := 1 to 20 do
|
begin
|
case Estado[Port] of
|
TRANSFERENCIA:
|
begin
|
Dec(nContaTimeOutAtende[Port]);
|
if nContaTimeOutAtende[Port] = 0 then
|
begin
|
//timeout, significa que atendeu
|
InsereDado(Port,'Timeout de atendimento');
|
//chama a rotina que trata o atendimento
|
voice1AnswerDetected(Sender,Port);
|
end;
|
end;
|
end;
|
end;
|
end;
|
|
procedure TForm1.voice1Calling(Sender: TObject; Port:
|
Smallint);
|
begin
|
case Estado[Port] of
|
TRANSFERENCIA:
|
begin
|
InsereDado(Port,IntToStr(nChamando[Port])+
|
'o. Toque...');
|
//8 segundos ate os proximos toques
|
nContaTimeOutAtende[Port] := 8;
|
if nChamando[Port] > NUMTOQUESRETOMADA then
|
begin
|
//deu ocupado
|
voice1.DisableAnswerDetection(Port);
|
Sleep(10);
|
voice1.DisableCallProgress(Port);
|
InsereDado(Port,'Ramal não atende...');
|
nEstadoRamal[Port] := NAOATENDE;
|
nEstadoFlash[Port] := RETOMA;
|
voice1.Flash(Port,700,1500);
|
end
|
else
|
Inc(nChamando[Port]);
|
end;
|
end;
|
end;
|
|
procedure TForm1.voice1BusyDetected(Sender: TObject; Port:
|
Smallint);
|
begin
|
case Estado[Port] of
|
TRANSFERENCIA:
|
begin
|
//deu ocupado na transferencia
|
voice1.DisableAnswerDetection(Port);
|
Sleep(10);
|
voice1.DisableCallProgress(Port);
|
InsereDado(Port,'Ocupado na Supervisão...');
|
nEstadoRamal[Port] := OCUPADO;
|
nEstadoFlash[Port] := RETOMA;
|
voice1.Flash(Port,700,1500);
|
end;
|
else
|
begin //qualquer outro caso desliga
|
Sleep(100);
|
voice1.HangUp(Port);
|
Estado[Port] := NADA;
|
InsereDado(Port,'Cliente Desligou.');
|
InsereDado(Port,'Esperando nova ligação...');
|
end;
|
end;
|
end;
|
|
procedure TForm1.voice1AfterFlash(Sender: TObject; Port:
|
Smallint);
|
begin
|
case nEstadoFlash[Port] of
|
(......)
|
RETOMA:
|
begin
|
InsereDado(Port,'Retomando Ligação...');
|
try
|
lstRamal.Delete(0);
|
except
|
end;
|
//fala ramal ocupado ou ramal nao atende
|
if nEstadoRamal[Port] = OCUPADO then
|
begin
|
voice1.PLayFile(Port,'SISROCUP.SIG','')
|
end
|
else
|
begin
|
voice1.PLayFile(Port,'SISRNAOA.SIG','');
|
end;
|
end;
|
(......)
|