RfidConfig.java
2.57 KB
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
package com.yoho.rfid.service;
import com.yoho.rfid.model.RfidClient;
import com.yoho.rfid.util.SocketConstant;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
/**
* 配置RFID读写器
*/
@Component
public class RfidConfig {
private static final Logger logger = LoggerFactory.getLogger(RfidConfig.class);
@Value("${rfid.client.address:null}")
private String clientAddress[];
@Autowired
private RfidInit rfidInit;
@Autowired
private RfidMonitor rfidMonitor;
@Autowired
private RfidConnMonitor rfidConnMonitor;
@PostConstruct
private void initClient() {
if (ArrayUtils.isNotEmpty(clientAddress)) {
for(int i=0; i<clientAddress.length; i++){
RfidClient rfidClient = new RfidClient();
try{
String clientInfo[] = clientAddress[i].split(":");
// mac
rfidClient.setMacId(clientInfo[0]);
// ip
rfidClient.setIp(clientInfo[1]);
// port
rfidClient.setPort(clientInfo[2]);
// power
String power = clientInfo[3];
buildPowerInfo(rfidClient, power);
// speedmode
rfidClient.setSpeedMode(Integer.valueOf(clientInfo[4]));
SocketConstant.rfidClientAllMap.put(rfidClient.getIp(), rfidClient);
}catch(Exception e){
logger.warn("client info configured error, e is:{}", e);
return;
}
// 连接client,开始监听上报数据
rfidInit.openRFID(rfidClient);
}
rfidMonitor.startMonitor();
rfidConnMonitor.startMonitor();
}else {
logger.info("client is not configured");
}
}
public void buildPowerInfo(RfidClient rfidClient, String power) {
if(StringUtils.isEmpty(power)){
return;
}
String info[] = power.split("-");//是否启用-功率
String flag[] = info[0].split("\\|");//是否启用
String capacity[] = info[1].split("\\|");//功率
//设置四个天线的开启状态
rfidClient.setPower0("1".equals(flag[0]) ? true : false);
rfidClient.setPower1("1".equals(flag[1]) ? true : false);
rfidClient.setPower2("1".equals(flag[2]) ? true : false);
rfidClient.setPower3("1".equals(flag[3]) ? true : false);
//设置四个天线的功率
rfidClient.setCapacity0(Integer.valueOf(capacity[0]));
rfidClient.setCapacity1(Integer.valueOf(capacity[1]));
rfidClient.setCapacity2(Integer.valueOf(capacity[2]));
rfidClient.setCapacity3(Integer.valueOf(capacity[3]));
}
}