灯光控制

nanjing-yancao-wuliuzhongxin
yiming 3 years ago
parent b1f871a74b
commit 12272a6ea8

@ -10,6 +10,8 @@ import com.zhehekeji.web.pojo.street.StreetSearch;
import com.zhehekeji.web.pojo.street.StreetVO;
import com.zhehekeji.web.service.LightSourceService;
import com.zhehekeji.web.service.StreetService;
import com.zhehekeji.web.service.client.ClientChanel;
import com.zhehekeji.web.service.client.LCTransmission;
import com.zhehekeji.web.service.damLightSource.JYDAMEquip;
import com.zhehekeji.web.service.damLightSource.JYDamHelper;
import com.zhehekeji.web.service.hikLightSource.HikControlSocket;
@ -81,87 +83,38 @@ public class StreetController {
@GetMapping("/lightSource/open")
@ApiOperation(value = "开启光源")
public Result openLightSource(){
List<LightSource> lightSources = lightSourceService.getLightSource();
lightSources.forEach(lightSource -> {
JSONObject obj = JSONObject.parseObject(configProperties.getLightSource().getInfo());
if(configProperties.getLightSource().getType() == 1){
JYDAMEquip equip = JYDamHelper.Connect(lightSource.getIp(),lightSource.getPort());
JYDamHelper.openDO(equip,configProperties.getLightSource().getIndex());
Integer status = JYDamHelper.ReadStatus(equip,configProperties.getLightSource().getNum(),configProperties.getLightSource().getIndex());
log.info("ip:{},status:{}",lightSource.getIp(),status);
equip.DisConnect();
}else if(configProperties.getLightSource().getType() == 2){
HikControlSocket.openLight(lightSource.getIp(),lightSource.getPort(),configProperties.getLightSource().getIndex(),1);
}
ClientChanel.keys().forEach(k->{
LCTransmission lcTransmission = new LCTransmission(k,1);
ClientChanel.write(lcTransmission.toString(),k);
});
return Result.success();
}
@GetMapping("/lightSource/close")
@ApiOperation(value = "关闭光源")
public Result closeLightSource(){
List<LightSource> lightSources = lightSourceService.getLightSource();
lightSources.forEach(lightSource -> {
JSONObject obj = JSONObject.parseObject(configProperties.getLightSource().getInfo());
if(configProperties.getLightSource().getType() == 1){
JYDAMEquip equip = JYDamHelper.Connect(lightSource.getIp(),lightSource.getPort());
JYDamHelper.closeDO(equip,obj.getInteger("index"));
Integer status = JYDamHelper.ReadStatus(equip,obj.getInteger("num"),obj.getInteger("index"));
log.info("ip:{},status:{}",lightSource.getIp(),status);
}else if(configProperties.getLightSource().getType() == 2){
HikControlSocket.openLight(lightSource.getIp(),lightSource.getPort(),configProperties.getLightSource().getIndex(),0);
}
ClientChanel.keys().forEach(k->{
LCTransmission lcTransmission = new LCTransmission(k,0);
ClientChanel.write(lcTransmission.toString(),k);
});
return Result.success();
}
@GetMapping("/lightSource/open/{streetId}")
@ApiOperation(value = "开启单个巷道光源")
public Result openStreetLightSource(@PathVariable Integer streetId){
List<LightSource> lightSources = lightSourceService.getLightSourceByStreetId(streetId);
lightSources.forEach(lightSource -> {
if(configProperties.getLightSource().getType() == 1){
JYDAMEquip equip = JYDamHelper.Connect(lightSource.getIp(),lightSource.getPort());
JYDamHelper.openDO(equip,configProperties.getLightSource().getIndex());
Integer status = JYDamHelper.ReadStatus(equip,configProperties.getLightSource().getNum(),configProperties.getLightSource().getIndex());
log.info("ip:{},status:{}",lightSource.getIp(),status);
equip.DisConnect();
}else if(configProperties.getLightSource().getType() == 2){
HikControlSocket.openLight(lightSource.getIp(),lightSource.getPort(),configProperties.getLightSource().getIndex(),1);
}
});
Street street = streetService.streetById(streetId);
LCTransmission lcTransmission = new LCTransmission(street.getPlcId(),1);
ClientChanel.write(lcTransmission.toString(),street.getPlcId());
return Result.success();
}
@GetMapping("/lightSource/close/{streetId}")
@ApiOperation(value = "关闭单个巷道光源")
public Result closeStreetLightSource(@PathVariable Integer streetId){
List<LightSource> lightSources = lightSourceService.getLightSourceByStreetId(streetId);
lightSources.forEach(lightSource -> {
if(configProperties.getLightSource().getType() == 1){
JYDAMEquip equip = JYDamHelper.Connect(lightSource.getIp(),lightSource.getPort());
JYDamHelper.closeDO(equip,configProperties.getLightSource().getIndex());
Integer status = JYDamHelper.ReadStatus(equip,configProperties.getLightSource().getNum(),configProperties.getLightSource().getIndex());
log.info("ip:{},status:{}",lightSource.getIp(),status);
equip.DisConnect();
}else if(configProperties.getLightSource().getType() == 2){
HikControlSocket.openLight(lightSource.getIp(),lightSource.getPort(),configProperties.getLightSource().getIndex(),0);
}
});
Street street = streetService.streetById(streetId);
LCTransmission lcTransmission = new LCTransmission(street.getPlcId(),0);
ClientChanel.write(lcTransmission.toString(),street.getPlcId());
return Result.success();
}

@ -9,6 +9,7 @@ import org.slf4j.LoggerFactory;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
/**
* chanel
@ -23,6 +24,7 @@ public class ClientChanel {
*/
private static Map<String, Channel> channelMap = new HashMap<>();
/**
* key :IP
* value:
@ -61,6 +63,11 @@ public class ClientChanel {
public static void disConnect(String key){
channelMap.remove(key);
}
public static Set<String> keys(){
return channelMap.keySet();
}
public static Channel get(String key){

@ -0,0 +1,34 @@
package com.zhehekeji.web.service.client;
import lombok.Data;
@Data
/**
*
*/
public class LCTransmission {
private static String HEADER = "LC";
private String SRMNumber;
/**
* 1: 0
*/
private Integer status;
public String toString(){
return HEADER + "," + SRMNumber+","+status;
}
public static String getHEADER(){
return HEADER;
}
public LCTransmission(String SRMNumber,Integer status){
this.SRMNumber = SRMNumber;
this.status = status;
}
}
Loading…
Cancel
Save