Administrator
2021-04-29 e2b58dc05d331566ef83ba20ab60a419c0e73805
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
package com.dev.fbs9600;
 
import com.battdata_rt.BattData_RT;
import com.dev.modbus4j.MyModbusMaster;
import com.dev.modbus4j.MyModbusUtils;
import com.serotonin.modbus4j.BatchRead;
import com.serotonin.modbus4j.BatchResults;
import com.serotonin.modbus4j.code.DataType;
 
public class FBS9600_State {
    static final int UsrCmdNull = 0;
    static final int UsrCmdTestRes = 81;
    static final int UsrCmdTestResSuc = 82;
    static final int WorkStateNull = 0;
    static final int WorkStateRes = 1;
    public String ip_addr;
    public int dev_id;
    public int check_dev_id;                //校验设备id
    private int op_cmd;
    private boolean op_cmd_ack_fromdev = false;
    int work_state;
    int com_count;
    int com_err_count;
    long alm_rec_id = 0L;
 
    public FBS9600_State(String ipaddr, int id) {
        this.ip_addr = ipaddr;
        this.dev_id = id;
    }
 
    public void setWorkState() {
        this.work_state = 1;
    }
 
    public void clearWorkState() {
        this.work_state = 0;
    }
 
    public int getWorkState() {
        return this.work_state;
    }
 
    public void setFBS9600CmdAckFromDev(boolean stat) {
        this.op_cmd_ack_fromdev = stat;
    }
 
    public boolean getFBS9600CmdAckFromDev() {
        return this.op_cmd_ack_fromdev;
    }
 
    public void setFBS9600Cmd(int cmd) {
        this.op_cmd = cmd;
    }
 
    public int getFBS9600Cmd() {
        return this.op_cmd;
    }
 
    public void setComCountInc() {
        this.com_err_count = 0;
        this.com_count += 1;
        if (this.com_count >= 90000000)
            this.com_count = 1;
    }
 
    public void setComErrCountInc() {
        this.com_err_count += 1;
        if (this.com_err_count >= 90000000)
            this.com_err_count = 20;
    }
 
    /**
     * 构造State读取集合
     * @param master
     * @return
     */
    public BatchRead<Integer> createBatchRead(MyModbusMaster master) {
        BatchRead<Integer> batch = new BatchRead<Integer>();
        batch.addLocator(0,MyModbusUtils.createBaseLocator(0xF001,DataType.TWO_BYTE_INT_UNSIGNED, master));                                    //机箱跳闸输出    
        batch.addLocator(1,MyModbusUtils.createBaseLocator(0xF002, DataType.TWO_BYTE_INT_UNSIGNED, master));                                    //故障复位信号    
        
        return batch;
    }
    
    /**
     * 解析State读取集合
     * @param res
     */
    public boolean putBatchResult(BatchResults<Integer> res) {
        if(res != null) {
            int dev_head = res.getIntValue(0);
            int dev_food = res.getIntValue(1);
            
            this.check_dev_id = dev_head*100000+dev_food;
            //System.out.println(this.check_dev_id+"===="+dev_head+"==="+dev_food);
            return true;
        }
        return false;
    }
 
    /**
     *     读取电池组组端数据信息
     * @param master
     * @return
     */
    public BatchRead<Integer> createGruopBatchRead(MyModbusMaster master,int index) {
        int offset = index*0x1000;
        BatchRead<Integer> batch = new BatchRead<Integer>();
        batch.addLocator(0,MyModbusUtils.createBaseLocator(0x0003+offset,DataType.TWO_BYTE_INT_UNSIGNED, master));        //模块状态:0-正常采集 1-内阻测试 2-单体编号                            
        batch.addLocator(1,MyModbusUtils.createBaseLocator(0x0004+offset, DataType.TWO_BYTE_INT_UNSIGNED, master));        //组端电压                        
        batch.addLocator(2,MyModbusUtils.createBaseLocator(0x0006+offset, DataType.TWO_BYTE_INT_UNSIGNED, master));        //组端电流                        
        batch.addLocator(3,MyModbusUtils.createBaseLocator(0x0007+offset, DataType.TWO_BYTE_INT_UNSIGNED, master));        //蓄电池状态                            
        batch.addLocator(4,MyModbusUtils.createBaseLocator(0x000A+offset, DataType.TWO_BYTE_INT_UNSIGNED, master));        //纹波电流均值                            
        batch.addLocator(5,MyModbusUtils.createBaseLocator(0x000B+offset, DataType.TWO_BYTE_INT_UNSIGNED, master));        //纹波电流峰值                                
        return batch;
    }
 
    
    
    public boolean putGroupBatchResult(BatchResults<Integer> res,int index,BattData_RT battData_RT) {
        if(res != null) {
            battData_RT.mTestData.updateGroupVolFrom_FBSDev(((float)res.getIntValue(0))/10);
            float battcurr = ((float)res.getIntValue(1))/10;
            int battstate = res.getIntValue(2);            
            if (1 == battstate) {
                battcurr *= -1.0F;
            }
            battData_RT.mTestData.updateCurrFrom_FBSDev(battcurr);        
            return true;
        }
        return false;
    }
 
    public BatchRead<Integer> createMonVolBatchRead(MyModbusMaster master, int index,int monCount) {
        int offset = index*0x1000;
        BatchRead<Integer> batch = new BatchRead<Integer>();
        for(int i=0;i<monCount;i++) {            
            batch.addLocator(i,MyModbusUtils.createBaseLocator(0x001C+offset+i,DataType.TWO_BYTE_INT_UNSIGNED, master));        //单体电压                        
        }
        return batch;
    }
 
    public boolean putMonVolBatchResult(BatchResults<Integer> res, int index, BattData_RT battData_RT) {
        if(res != null) {
            for(int i=0;i<battData_RT.MonCount;i++) {
                battData_RT.al_MonVol.get(i).monVol = ((float)res.getIntValue(i))/1000;
            }        
            return true;
        }
        return false;
    }
}