package test.protocol.musatel;
|
|
|
public class MusatelOutputStream extends MusatelProtocol
|
{
|
private ControllerMusatel musatel = null;
|
|
public MusatelOutputStream (ControllerMusatel musatel)
|
{
|
this.musatel = musatel;
|
}
|
|
|
|
public void openAudio (String computerAddress, int audioPort) throws Exception
|
{
|
byte[] address = musatel.getIpArray(computerAddress);
|
|
function(MusatelProtocol.ORD_FON_ON, new byte[]
|
{
|
address[0],
|
address[1],
|
address[2],
|
address[3],
|
(byte)(audioPort & 0xFF),
|
(byte)((audioPort >> 8) & 0xFF)
|
});
|
}
|
|
|
|
|
|
public void closeAudio () throws Exception
|
{
|
function(MusatelProtocol.ORD_FON_OFF);
|
}
|
|
|
|
/**
|
* El poste emite el tono solicitado por su altavoz. La señal de audio del tono es recibida por el operador
|
*/
|
public void ringTone (boolean state) throws Exception
|
{
|
if (state == true)
|
{
|
function(MusatelProtocol.ORD_TON_ON);
|
}
|
else
|
{
|
function(MusatelProtocol.ORD_TON_OFF);
|
}
|
}
|
|
|
|
public void maintenanceTest () throws Exception
|
{
|
function(MusatelProtocol.ORD_TST_MAN);
|
}
|
|
|
|
|
|
public void audioTest () throws Exception
|
{
|
function(MusatelProtocol.ORD_TST_FON);
|
}
|
|
|
|
|
public void message (boolean state) throws Exception
|
{
|
if (state == true)
|
{
|
function(MusatelProtocol.ORD_VOZ_ON);
|
}
|
else
|
{
|
function(MusatelProtocol.ORD_VOZ_OFF);
|
}
|
}
|
|
|
|
public void volume (int level) throws Exception
|
{
|
if (level < 0) level = 0;
|
if (level > 7) level = 7;
|
|
function(MusatelProtocol.ORD_ADJ_VOL, new byte[]{(byte)level});
|
}
|
|
|
|
public void reset () throws Exception
|
{
|
function(MusatelProtocol.ORD_FON_OFF);
|
}
|
|
|
|
|
public void callWait() throws Exception
|
{
|
function(MusatelProtocol.ACK_DEM_USE, new byte[]{MusatelProtocol.P_MAS, MusatelProtocol.L_ESP});
|
}
|
|
|
|
public void callAnswer(String computerAddress, int audioPort) throws Exception
|
{
|
byte[] address = musatel.getIpArray(computerAddress);
|
|
function(MusatelProtocol.ACK_DEM_USE, new byte[]
|
{
|
MusatelProtocol.L_FON,
|
address[0],
|
address[1],
|
address[2],
|
address[3],
|
(byte)(audioPort & 0xFF),
|
(byte)((audioPort >> 8) & 0xFF)
|
});
|
|
}
|
|
|
|
|
|
|
|
|
public void function (byte code) throws Exception
|
{
|
function(code, new byte[0]);
|
}
|
|
|
|
|
public void function (byte code, byte[] params) throws Exception
|
{
|
musatel.connect();
|
|
byte[] send = new byte[5 + params.length];
|
send[0] = 0x00;
|
send[1] = code;
|
send[2] = MusatelProtocol.P_MAS;
|
|
for (int i=0; i<params.length; i++)
|
{
|
send[3 + i] = params[i];
|
}
|
|
send[3 + params.length] = (byte)0xFF;
|
send[4 + params.length] = (byte)0xFF;
|
|
|
System.out.print(">");
|
|
for (int i=0; i<send.length; i++)
|
{
|
System.out.print(" " + String.format("%02X", send[i]));
|
}
|
|
System.out.println();
|
|
musatel.socket.setSoTimeout(musatel.timeout);
|
musatel.os.write(send);
|
musatel.os.flush();
|
musatel.input.response();
|
}
|
|
|
|
}
|