Alejandro Acuña
2024-07-30 65a64a81d30f00f1fffd5da6866850e1308e1135
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
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();
    }    
    
    
     
}