| | |
| | | package com.zy.acs.manager.core.service; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.github.xingshuangs.iot.protocol.modbus.service.ModbusRtuOverTcp; |
| | | import com.github.xingshuangs.iot.protocol.modbus.service.ModbusTcp; |
| | | import com.github.xingshuangs.iot.utils.HexUtil; |
| | | import com.zy.acs.framework.common.Cools; |
| | |
| | | @Autowired |
| | | private FuncStaService funcStaService; |
| | | |
| | | private final Map<String, ModbusTcp> CHARGE_CACHE = new ConcurrentHashMap<>(); |
| | | private final Map<String, ModbusRtuOverTcp> CHARGE_CACHE = new ConcurrentHashMap<>(); |
| | | |
| | | |
| | | @PostConstruct |
| | |
| | | |
| | | |
| | | public void add(FuncSta funcSta) { |
| | | ModbusTcp modbusTcp = new ModbusTcp(funcSta.getIp(), funcSta.getPort()); |
| | | ModbusRtuOverTcp modbusTcp = new ModbusRtuOverTcp(funcSta.getIp(), funcSta.getPort()); |
| | | modbusTcp.setComCallback((tag, bytes) -> log.info("%s[%d] %s%n", tag, bytes.length, HexUtil.toHexString(bytes))); |
| | | CHARGE_CACHE.put(funcSta.getUuid(), modbusTcp); |
| | | } |
| | |
| | | CHARGE_CACHE.remove(chargePointId); |
| | | } |
| | | |
| | | public ModbusTcp get(String chargePointId) { |
| | | ModbusTcp modbusTcp = CHARGE_CACHE.get(chargePointId); |
| | | public ModbusRtuOverTcp get(String chargePointId) { |
| | | ModbusRtuOverTcp modbusTcp = CHARGE_CACHE.get(chargePointId); |
| | | if (modbusTcp != null) { |
| | | return modbusTcp; |
| | | } |
| | | FuncSta funcSta = funcStaService.getOne(new LambdaQueryWrapper<FuncSta>().eq(FuncSta::getUuid, chargePointId)); |
| | | modbusTcp = new ModbusTcp(funcSta.getIp(), funcSta.getPort()); |
| | | modbusTcp = new ModbusRtuOverTcp(funcSta.getIp(), funcSta.getPort()); |
| | | modbusTcp.setComCallback((tag, bytes) -> log.info("%s[%d] %s%n", tag, bytes.length, HexUtil.toHexString(bytes))); |
| | | CHARGE_CACHE.put(chargePointId, modbusTcp); |
| | | return modbusTcp; |
| | | } |
| | | |