增加测试

镇海石化
LAPTOP-S9HJSOEB\昊天 7 months ago
parent fd4ca98813
commit f4b8c369fd

@ -1,17 +1,26 @@
package com.zhehekeji.web.controller;
import com.zhehekeji.core.pojo.Result;
import com.zhehekeji.web.entity.RFID;
import com.zhehekeji.web.entity.Street;
import com.zhehekeji.web.service.RFID.RFIDMap;
import com.zhehekeji.web.service.RFID.RFIDSocket;
import com.zhehekeji.web.service.RFIDService;
import com.zhehekeji.web.service.StreetService;
import com.zhehekeji.web.service.TestService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.HashSet;
import java.util.Set;
@Api(value = "TestController",tags = "扫码测试")
@RequestMapping("/test")
@RestController
@Slf4j
public class TestController {
@Resource
@ -47,4 +56,67 @@ public class TestController {
return Result.success();
}
@Resource
StreetService streetService;
@Resource
RFIDService rfidService;
@ApiOperation("rfid")
@GetMapping("/rfid")
public Result<Set<String >> rfid(@PathVariable String streetId){
Street street = streetService.getStreetByPlcId(streetId);
RFIDSocket rfidSocket = new RFIDSocket(street.getPlcIp(), 4001);
rfidSocket.startCheck(1,true);
try {
Thread.sleep(1000*15);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
rfidSocket.stopCheck();
System.out.println(rfidSocket.getTags());
return Result.success(rfidSocket.getTags());
}
@ApiOperation("rfidNew")
@GetMapping("/rfidNew")
public Result<Set<String >> rfidNew(@PathVariable String streetId) {
Street street = streetService.getStreetByPlcId(streetId);
if (street != null) {
//rfid不分左右rfid使用同一ip和端口依靠传递字符调整方向
RFID rfid = rfidService.getRFIDByPlc(street.getId(), null);
if (rfid != null) {
RFIDStart(rfid.getIp(), rfid.getPort(), street.getId(), 1);
try {
Thread.sleep(1000*15);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
Set<String> tags = RFIDStop(street);
return Result.success(tags);
}
}
return Result.success(new HashSet<>());
}
public void RFIDStart(String ip, Integer port, Integer streetId, Integer direction) {
RFIDSocket rfidSocket = new RFIDSocket(ip, port);
log.info("rfid调用ip" + ip + ";port:" + port);
rfidSocket.startCheck(direction,false);
RFIDMap.put(streetId, rfidSocket);
}
public Set<String> RFIDStop(Street street) {
RFIDSocket rfidSocket = RFIDMap.get(street.getId());
Set<String> tags = null;
if (rfidSocket != null) {
tags = rfidSocket.getTags();
log.info("tags:{}", tags);
rfidSocket.stopCheck();
RFIDMap.remove(street.getId());
}
return tags;
}
}

Loading…
Cancel
Save