Alejandro Acuña
2024-10-25 bf65497ed7abf9c669eb3cc0ba219dfa4494b759
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
package art.servers.colorsserver.m.protocol;
 
import art.library.utils.common.*;
import static art.servers.colorsserver.m.protocol.M_ProtocolWriter.DET;
 
public class M_Message
{
    private int[] data;
    private int pointer = 0;
    public boolean isAck = false;
    public boolean isNack = false;
    public boolean isTrcam = false;
    public int directive = 0;
    public int controller = 0;
    public int table = 0;
 
 
    public void fillInformation ()
    {
        if (data[0] == M_ProtocolAnalyser.STX)
        {
            controller = data[1] & 0x7F;
            directive = data[2] & 0x7F;
            if (directive == M_ProtocolWriter.M_READ_TABLE_FULL)
            {
                table = data[3] & 0x7F;
            }
        }
    }
 
 
    public void setData(byte[] input)
    {
        data = new int[input.length];
        for (int i=0; i<data.length; i++)
        {
            data[i] = (int)input[i];
        }
    }
 
 
    public void setData(int[] input)
    {
        data = new int[input.length];
        for (int i=0; i<data.length; i++)
        {
            data[i] = input[i];
        }
    }
 
 
    public void reset ()
    {
        pointer = 0;
    }
 
 
    public int length ()
    {
        return(data.length);
    }
 
 
    public int readByte () throws Exception
    {
       return (data[pointer++]);
    }
 
 
    public int readShort () throws Exception
    {
       return (readByte() + (readByte() << 8));
    }
 
 
 
    public int readShortHigh () throws Exception
    {
       return ((readByte() << 8) + readByte());
    }
 
 
 
    public int readInt () throws Exception
    {
       return (readByte() + (readByte() << 8) + (readByte() << 16) + (readByte() << 24));
    }
 
 
    public int readIntHigh () throws Exception
    {
       return ((readByte() << 24) + (readByte() << 16) + (readByte() << 8) + readByte());
    }
 
 
    public int[] readFully () throws Exception
    {
        int[] resultado = new int[data.length - pointer];
        System.arraycopy(data, pointer, resultado, 0, resultado.length);
        return resultado;
    }
 
 
 
    public int[] readIntArray (int count) throws Exception
    {
        int[] resultado = new int[count];
        System.arraycopy(data, pointer, resultado, 0, resultado.length);
        pointer = pointer + count;
        return resultado;
    }
 
 
 
    public boolean eof()
    {
        return (pointer >= data.length-1);
    }
 
 
    public byte[] toByteArray()
    {
        return(ArrayUtils.toByteArray(data));
    }
 
 
    public boolean isCountingDetectorQuery()
    {
        return(data[0] == DET);
    }
 
 
    public String toString()
    {
        String result = "";
 
        try
        {
            for (int i=0; i<data.length; i++)
            {
                String svalue = String.format("%02X", data[i] & 0xFF);
                result += svalue + " ";
            }
        }
        catch (Exception e)
        {
            
        }
 
        return(result);
    }
 
}