whyclj
2020-10-14 455401679935a41e16f8f71a8b62dd9af47b934a
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
package com.motor.data;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
import com.mchange.v1.util.Sublist;
import com.modbus.data.MyModbusMaster;
import com.modbus.data.MyModbusUtils;
import com.motor.alarm.Motor_Alarm;
import com.serotonin.modbus4j.BatchRead;
import com.serotonin.modbus4j.BatchResults;
import com.serotonin.modbus4j.code.DataType;
 
public class Motor_inf {
    
    public int motor_id;                            //µç»úid
    public String motor_name;                        //µç»úÃû³Æ
    public int motor_type;                            //µç»úÀàÐÍ
    public String motor_ip;                            //µç»úip
    public String note;                                //±¸ÓÃ
    
    public int conn_state;                            //ͨѶ״̬ 1:ͨѶÕý³£    0:ͨѶ¹ÊÕÏ
    
    public Load_motor_state load_state;                //¼ÓÔØµç»ú״̬
    public Subject_motor_state subject_state;        //ÊÜÊÔµç»ú״̬
    
    public List<Motor_Alarm> alarms;
    
    public Motor_inf(int motor_id) {
        this.motor_id = motor_id;
        alarms = new ArrayList<Motor_Alarm>();
        load_state = new Load_motor_state(motor_id);
        subject_state = new Subject_motor_state(motor_id);
    }
    
    public int getMotor_id() {
        return motor_id;
    }
    public String getMotor_name() {
        return motor_name;
    }
    public int getMotor_type() {
        return motor_type;
    }
    public String getMotor_ip() {
        return motor_ip;
    }
    public String getNote() {
        return note;
    }
    public void setMotor_id(int motor_id) {
        this.motor_id = motor_id;
    }
    public void setMotor_name(String motor_name) {
        this.motor_name = motor_name;
    }
    public void setMotor_type(int motor_type) {
        this.motor_type = motor_type;
    }
    public void setMotor_ip(String motor_ip) {
        this.motor_ip = motor_ip;
    }
    public void setNote(String note) {
        this.note = note;
    }
    
    /**
     *     »ñÈ¡µ±Ç°µç»ú¶ÔÏó
     * @return
     */
    public static Motor_inf getNowMotor(int motor_id,List<Motor_inf> motors) {
        Motor_inf motor = null;
        for(int i=0;i<motors.size();i++) {
            if(motor_id == motors.get(i).motor_id) {
                return motors.get(i);
            }
        }
        return motor;
    }
    
    @Override
    public String toString() {
        return "Motor_inf [motor_id=" + motor_id + ", motor_name=" + motor_name + ", motor_type=" + motor_type
                + ", motor_ip=" + motor_ip + ", note=" + note + "]";
    }
 
    /**
     * ´´½¨¶ÁÈ¡¼¯ºÏ
     * @param master
     * @return
     */
    public BatchRead<Integer> createBatchRead(MyModbusMaster master) {
        BatchRead<Integer> batch = new BatchRead<Integer>();
        for(int i=0;i<this.alarms.size();i++) {
            batch.addLocator(i,MyModbusUtils.createBaseLocator(12000+i*4, master));                                            
        }
        return batch;
    }
    
    /**
     * ½âÎö¶ÁÈ¡¼¯ºÏ
     * @param res
     */
    public void putBatchResult(BatchResults<Integer> res) {
        if(res != null) {
            for(int i=0;i<this.alarms.size();i++) {
                alarms.get(i).checkAlarm(MyModbusUtils.readBooleanToInt(res.getValue(i)));
            }
        }
    }
}