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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
package art.servers.pvvserver.protocols.dgt.clv;
 
import art.library.model.devices.vms.general.VmsGeneral;
import art.library.model.devices.vms.pvv.Pvv;
import art.library.model.devices.vms.pvv.PvvCommands;
import art.library.model.devices.vms.pvv.information.PvvInformationConfigurationAddressSpeed;
import art.library.utils.common.ArrayUtils;
import java.util.ArrayList;
import java.util.List;
 
public class ClvDgtProtocolConstructor
{
 
    public ClvDgtProtocolConstructor()
    {
    }
 
    /**
     * ORDCC
     *
     * @param device
     * @return
     * @throws Exception
     */
    public static byte[] ORDCC(VmsGeneral device) throws Exception
    {
        return new byte[0];
    }
 
    /**
     * ASF status query
     *
     * @param address
     * @return
     * @throws java.lang.Exception
     */
    public static byte[] readAlarms(int address) throws Exception
    {
        ClvDgtPDU requestAlarms = new ClvDgtPDU();
        requestAlarms.stx = ClvDgtConstants.CLV_STX;
        requestAlarms.etx = ClvDgtConstants.CLV_ETX;
        requestAlarms.address = address;
        requestAlarms.function = ClvDgtConstants.STR_PCLV_ALR;
        requestAlarms.information = new int[0];
        byte[] send = requestAlarms.createMessage();
        return (send);
    }
 
    /**
     * ASF configuration query
     *
     * @param address
     * @return
     * @throws java.lang.Exception
     */
    public static byte[] readConfiguration(int address) throws Exception
    {
        ClvDgtPDU requestConfiguration = new ClvDgtPDU();
        requestConfiguration.stx = ClvDgtConstants.CLV_STX;
        requestConfiguration.etx = ClvDgtConstants.CLV_ETX;
        requestConfiguration.address = address;
        requestConfiguration.function = ClvDgtConstants.STR_PCLV_PP;
        requestConfiguration.information = new int[0];
        byte[] send = requestConfiguration.createMessage();
        return (send);
    }
 
    /**
     * ASF message query
     *
     * @param address
     * @return
     * @throws java.lang.Exception
     */
    public static byte[] readMessage(int address) throws Exception
    {
        ClvDgtPDU requestConfiguration = new ClvDgtPDU();
        requestConfiguration.stx = ClvDgtConstants.CLV_STX;
        requestConfiguration.etx = ClvDgtConstants.CLV_ETX;
        requestConfiguration.address = address;
        requestConfiguration.function = ClvDgtConstants.STR_PCLV_EP;
        requestConfiguration.information = new int[0];
        byte[] send = requestConfiguration.createMessage();
        return (send);
    }
 
    /**
     * ASF reset order
     *
     * @param address
     * @return
     * @throws java.lang.Exception
     */
    public static byte[] reset(int address) throws Exception
    {
        ClvDgtPDU orderReset = new ClvDgtPDU();
        orderReset.stx = ClvDgtConstants.CLV_STX;
        orderReset.etx = ClvDgtConstants.CLV_ETX;
        orderReset.address = address;
        //ASF reset, STR_OCLV_RES = 0x15
        orderReset.function = ClvDgtConstants.STR_OCLV_RES;
        //Without associated information, empty array
        orderReset.information = new int[0];
        byte[] send = orderReset.createMessage();
        return (send);
    }
 
    /**
     * ASF mep order
     *
     * @param address
     * @param command
     * @param deviceclone
     * @return
     * @throws java.lang.Exception
     */
    public static byte[] mep(int address, PvvCommands command, Pvv deviceclone) throws Exception
    {
        ClvDgtPDU orderReset = new ClvDgtPDU();
        orderReset.stx = ClvDgtConstants.CLV_STX;
        orderReset.etx = ClvDgtConstants.CLV_ETX;
        orderReset.address = address;
        //ASF MEP, STR_OCLV_RES = 0x1A
        orderReset.function = ClvDgtConstants.STR_OCLV_MEP;
        orderReset.information = ArrayUtils.toIntArray(getBodyContentMessage(command.message.speed, deviceclone));
        byte[] send = orderReset.createMessage();
        return (send);
    }
 
    /**
     * Get body content message of MEP
     *
     * @param commandSpeed
     * @param deviceclone
     * @return
     */
    public static byte[] getBodyContentMessage(int commandSpeed, Pvv deviceclone)
    {
        byte[] result;
        //Off
        if (commandSpeed <= 0)
        {
            //AsfDgtConstants.ASF_OFF = '0' = 0x30
            result = new byte[]
            {
                ClvDgtConstants.CLV_OFF
            };
            //Fix state    
        } else
        {
            List<Byte> informationList = new ArrayList<>();
            informationList.add((byte) ClvDgtConstants.CLV_FIX);
            informationList.add((byte) ClvDgtConstants.CLV_TOPOLOGY_1);
            informationList.add((byte) '1');
 
            List<Byte> lgraphicA = new ArrayList<>();
            PvvInformationConfigurationAddressSpeed addressSpeed = deviceclone.getDeviceInformation().configuration.getBySpeed(commandSpeed);
            lgraphicA.add((byte) '1');
            lgraphicA.add((byte) '1');
            lgraphicA.add((byte) addressSpeed.address);
            lgraphicA.add((byte) 'N');
 
            informationList.addAll(lgraphicA);
 
            result = new byte[informationList.size()];
            int index = 0;
            for (byte elem : informationList)
            {
                result[index++] = elem;
            }
        }
        return result;
    }
 
 
    /**
     * ASF mpp order
     *
     * @param address
     * @param command
     * @param deviceclone
     * @return
     * @throws java.lang.Exception
     */
/*
    public static byte[] mpp(int address, PvvCommands command, Pvv deviceclone) throws Exception
    {
        int brightness = -1;  // Auto
        if (deviceclone.getDeviceStatus().brightnessLevel != AsfStatus.BRIGHTNESS_MODE_AUTO)
        {
            brightness = deviceclone.getDeviceStatus().brightnessLevel;
        }
        if (command.brightness != -2)
        {
            brightness = command.brightness;
        }
        int blinkOn = (int) Math.round(deviceclone.getDeviceStatus().blinkOn * 1000);
        if (command.blinkOn > -1)
        {
            blinkOn = (int) Math.round(command.blinkOn * 1000);
        }
        int blinkOff = (int) Math.round(deviceclone.getDeviceStatus().blinkOff * 1000);
        if (command.blinkOff > -1)
        {
            blinkOff = (int) Math.round(command.blinkOff * 1000);
        }
 
        if (blinkOn == 0)
        {
            blinkOn = 500;
        }
        if (blinkOff == 0)
        {
            blinkOff = 500;
        }
 
        int messagetime = 2;
        if (brightness == -1)
        {
            brightness = 'A';
        } else
        {
            brightness = ClvDgtProtocolConstructor.getBrightnessDGTLevel(brightness, deviceclone.getDeviceInformation().maximumBrightnessLevel);
        }
 
        ClvDgtPDU request = new ClvDgtPDU();
        request.stx = ClvDgtConstants.CLV_STX;
        request.etx = ClvDgtConstants.CLV_ETX;
        request.address = address;
        //ASF MPP, send panel configuration, STR_OCLV_MPP = 0x11
        request.function = ClvDgtConstants.STR_OCLV_MPP;
 
        request.information = new int[]
        {
            //Byte 1
            command.timeout == -1 ? deviceclone.getDeviceConfiguration().timeout : command.timeout,
            //Byte 2
            brightness,
            //Byte 3
            address,
            //Byte 4
            messagetime,
            //Byte 5
            blinkOn,
            //Byte 6
            blinkOff,
            //Bytes from 7 to 16: reserved
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0
        };
 
        byte[] send = request.createMessage();
        return (send);
    }
*/
 
    /**
     * BrightnessDGTLevel
     *
     * @param input
     * @param maximum
     * @return
     */
    public static int getBrightnessDGTLevel(int input, int maximum)
    {
        // Input is a 0-100 value
        return ((int) Math.round(((float) input * (float) maximum) / 100f));
    }
 
    /**
     * BrightnessClientLevel
     *
     * @param input
     * @param maximum
     * @param maximumVms
     * @return
     */
    public static int getBrightnessClientLevel(int input, int maximum, int maximumVms)
    {
        // Input is a 0-7 value
        int result = (int) Math.round(((float) input * (float) maximum) / (float) maximumVms);
        if (result > 100)
        {
            result = 100;
        }
        return (result);
    }
}