|
@@ -8,9 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import javax.annotation.PostConstruct;
|
|
|
import java.util.Arrays;
|
|
|
-import java.util.HashMap;
|
|
|
import java.util.LinkedHashMap;
|
|
|
import java.util.Map;
|
|
|
|
|
@@ -42,78 +40,13 @@ public class ChargingMachineClient {
|
|
|
@Qualifier("modbusTcpMasterTemplateFifth")
|
|
|
private ModbusTcpMasterTemplate modbusTcpMasterTemplateFifth;
|
|
|
|
|
|
- private Map<String, ModbusTcpMasterTemplate> tcpMasterTemplateMap;
|
|
|
-
|
|
|
- @PostConstruct
|
|
|
- public void initMap() {
|
|
|
- tcpMasterTemplateMap = new HashMap<>();
|
|
|
- tcpMasterTemplateMap.put(MACHINE_NO.A.name(), modbusTcpMasterTemplateFourth);
|
|
|
- tcpMasterTemplateMap.put(MACHINE_NO.B.name(), modbusTcpMasterTemplateFifth);
|
|
|
- }
|
|
|
-
|
|
|
- public ModbusMasterUtil getModbusMasterUtil(MACHINE_NO machineNo) {
|
|
|
- return tcpMasterTemplateMap.get(machineNo.name()).getModbusMasterUtil();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 机器编号
|
|
|
- */
|
|
|
- public enum MACHINE_NO {
|
|
|
- A("1",1),
|
|
|
- B("2",2);
|
|
|
-
|
|
|
- private String value;
|
|
|
- private int no;
|
|
|
-
|
|
|
- MACHINE_NO(String value,Integer no) {
|
|
|
- this.value = value;
|
|
|
- this.no = no;
|
|
|
- }
|
|
|
-
|
|
|
- public String getValue() {
|
|
|
- return value;
|
|
|
- }
|
|
|
- public int getNo() {
|
|
|
- return no;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 根据值获得枚举类型 switch
|
|
|
- *
|
|
|
- * @param value
|
|
|
- * @return
|
|
|
- */
|
|
|
- public static MACHINE_NO getByValue(String value) {
|
|
|
- for (MACHINE_NO code : values()) {
|
|
|
- if (code.getValue().equals(value)) {
|
|
|
- return code;
|
|
|
- }
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
- /**
|
|
|
- * 根据值获得枚举类型 switch
|
|
|
- *
|
|
|
- * @param no
|
|
|
- * @return
|
|
|
- */
|
|
|
- public static MACHINE_NO getByNo(int no) {
|
|
|
- for (MACHINE_NO code : values()) {
|
|
|
- if (code.getNo() == no) {
|
|
|
- return code;
|
|
|
- }
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 充电机操作
|
|
|
*
|
|
|
* @param operation
|
|
|
* @return
|
|
|
*/
|
|
|
- public boolean operation(CHARGER_ADDRESS_MEANING operation, MACHINE_NO con) {
|
|
|
+ public boolean operation(CHARGER_ADDRESS_MEANING operation, boolean con) {
|
|
|
switch (operation) {
|
|
|
// 启动
|
|
|
case START:
|
|
@@ -135,7 +68,7 @@ public class ChargingMachineClient {
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
- public Map<CHARGER_STATUS, Boolean> getStatusMapping(MACHINE_NO con) {
|
|
|
+ public Map<CHARGER_STATUS, Boolean> getStatusMapping(boolean con) {
|
|
|
return ChargingMachineClient.CHARGER_STATUS.getMapping(getStatus(con));
|
|
|
}
|
|
|
|
|
@@ -144,7 +77,7 @@ public class ChargingMachineClient {
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
- public Map<String, Boolean> getStatusNameMapping(MACHINE_NO con) {
|
|
|
+ public Map<String, Boolean> getStatusNameMapping(boolean con) {
|
|
|
return ChargingMachineClient.CHARGER_STATUS.getNameMapping(getStatus(con));
|
|
|
}
|
|
|
|
|
@@ -155,8 +88,9 @@ public class ChargingMachineClient {
|
|
|
* 假设3个字节为:00000110 00000101 00000100
|
|
|
* 则最终返回的数组:[0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]
|
|
|
*/
|
|
|
- public boolean[] getStatus(MACHINE_NO con) {
|
|
|
- ModbusMasterUtil modbusMasterUtil = getModbusMasterUtil(con);
|
|
|
+ public boolean[] getStatus(boolean con) {
|
|
|
+ ModbusMasterUtil modbusMasterUtil = con ? modbusTcpMasterTemplateFourth.getModbusMasterUtil()
|
|
|
+ : modbusTcpMasterTemplateFifth.getModbusMasterUtil();
|
|
|
ReadResponse read = modbusMasterUtil.readCoils(1, CHARGER_STATUS.getOffset(), CHARGER_STATUS.getCommand());
|
|
|
if (read == null || read.getBooleanData() == null) {
|
|
|
log.error("获取充电机状态为空!");
|
|
@@ -174,8 +108,9 @@ public class ChargingMachineClient {
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
- private boolean start(MACHINE_NO con) {
|
|
|
- ModbusMasterUtil modbusMasterUtil = getModbusMasterUtil(con);
|
|
|
+ private boolean start(boolean con) {
|
|
|
+ ModbusMasterUtil modbusMasterUtil = con ? modbusTcpMasterTemplateFourth.getModbusMasterUtil()
|
|
|
+ : modbusTcpMasterTemplateFifth.getModbusMasterUtil();
|
|
|
return modbusMasterUtil.writeCoil(1, START.getOffset(), START.getCommand());
|
|
|
}
|
|
|
|
|
@@ -184,8 +119,9 @@ public class ChargingMachineClient {
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
- private boolean stop(MACHINE_NO con) {
|
|
|
- ModbusMasterUtil modbusMasterUtil = getModbusMasterUtil(con);
|
|
|
+ private boolean stop(boolean con) {
|
|
|
+ ModbusMasterUtil modbusMasterUtil = con ? modbusTcpMasterTemplateFourth.getModbusMasterUtil()
|
|
|
+ : modbusTcpMasterTemplateFifth.getModbusMasterUtil();
|
|
|
return modbusMasterUtil.writeCoil(1, STOP.getOffset(), STOP.getCommand());
|
|
|
}
|
|
|
|
|
@@ -194,8 +130,9 @@ public class ChargingMachineClient {
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
- private boolean discharge(MACHINE_NO con) {
|
|
|
- ModbusMasterUtil modbusMasterUtil = getModbusMasterUtil(con);
|
|
|
+ private boolean discharge(boolean con) {
|
|
|
+ ModbusMasterUtil modbusMasterUtil = con ? modbusTcpMasterTemplateFourth.getModbusMasterUtil()
|
|
|
+ : modbusTcpMasterTemplateFifth.getModbusMasterUtil();
|
|
|
return modbusMasterUtil.writeCoil(1, DISCHARGE.getOffset(), DISCHARGE.getCommand());
|
|
|
}
|
|
|
|