asd
Alejandro Acuña
2024-09-16 816cb391a192e357426312ab8e591fd49d1d242e
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
package art.servers.gost.access.types.neural;
 
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import java.lang.reflect.Field;
 
 
@JsonPropertyOrder
({ 
    "Alarm checksum",
    "Alarm online",
    "Alarm VID",
    "Alarm NTP",
    "Alarm GPS"
})
 
 
 
 
public class NeuralStatusAlarms
{
    @JsonProperty("Alarm checksum")
    public long alarm_checksum = 0;
 
    @JsonProperty("Alarm online")
    public long alarm_online = 0;
 
    @JsonProperty("Alarm VID")
    public long alarm_vid = 0;
 
    @JsonProperty("Alarm NTP")
    public long alarm_ntp = 0;
 
    @JsonProperty("Alarm GPS")
    public long alarm_gps = 0;
    
    
 
    @JsonIgnore
    public boolean setAlarm(String fieldName, boolean value)
    {
        try
        {
            Object object = NeuralStatusAlarms.this;
            Field field = getField(fieldName, this.getClass());
            field.setAccessible(true);
            long alarmTimestamp = field.getLong(object);
            if ((value == true) && (alarmTimestamp > 0)) return false;
            if ((value == false) && (alarmTimestamp == 0)) return false;
            
            if (value == true)
            {
                field.set(object, System.currentTimeMillis());
            }
            else
            {
                field.set(object, 0);
            }
        }
        catch (Exception e)
        {
        }
 
        return true;
    }
    
    
    @JsonIgnore
    public Field getField(String fieldName, Class<?> clazz) 
    {
        while (clazz != null && clazz != Object.class) 
        {
            for (Field field : clazz.getDeclaredFields()) 
            {
                if (field.getName().equals(fieldName))
                {
                    return field;
                }
            }
            
            clazz = clazz.getSuperclass();
        }
 
        return null;
    }    
 
}