add tcp
parent
8713a1ddcb
commit
73f8dee58b
@ -0,0 +1,40 @@
|
||||
package com.zhehekeji.web.controller;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.zhehekeji.core.pojo.Result;
|
||||
import com.zhehekeji.core.util.Assert;
|
||||
import com.zhehekeji.web.entity.Street;
|
||||
import com.zhehekeji.web.mapper.StreetMapper;
|
||||
import com.zhehekeji.web.pojo.street.StreetSearch;
|
||||
import com.zhehekeji.web.pojo.street.StreetVO;
|
||||
import com.zhehekeji.web.service.ClientMap;
|
||||
import com.zhehekeji.web.service.StreetService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@Api(value = "PLCController",tags = "PLC管理")
|
||||
@RestController(value = "PLCController")
|
||||
@RequestMapping("/plc")
|
||||
public class PLCController {
|
||||
|
||||
@Resource
|
||||
private StreetService streetService;
|
||||
@Resource
|
||||
private StreetMapper streetMapper;
|
||||
|
||||
|
||||
@GetMapping("/heart")
|
||||
@ApiOperation(value = "心跳")
|
||||
public Result heart(@RequestParam Integer id) throws InterruptedException {
|
||||
Street street = streetMapper.selectById(id);
|
||||
Assert.isTrue(street!= null && street.getPlcIp() != null && street.getPlcPort() != null,"未配置IP");
|
||||
ClientMap.createClient(street);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
package com.zhehekeji.web.service;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.MessageToByteEncoder;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
public class MyProtocolEncoder extends MessageToByteEncoder<SendHeart> {
|
||||
|
||||
@Override
|
||||
protected void encode(ChannelHandlerContext ctx, SendHeart msg, ByteBuf out) throws Exception {
|
||||
if(msg == null){
|
||||
throw new Exception("msg is null");
|
||||
}
|
||||
out.writeChar(msg.getL());
|
||||
out.writeChar(msg.getP());
|
||||
out.writeShort(msg.getLength());
|
||||
out.writeCharSequence(msg.getPlcId(), Charset.defaultCharset());
|
||||
out.writeCharSequence(msg.getType(), Charset.defaultCharset());
|
||||
out.writeCharSequence(msg.getId(),Charset.defaultCharset());
|
||||
out.writeChar(msg.getMaohao());
|
||||
out.writeChar(msg.getH());
|
||||
out.writeBytes(msg.getEmp());
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
package com.zhehekeji.web.service;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class SendHeart {
|
||||
|
||||
private char l = 'L';
|
||||
|
||||
private char p = 'P';
|
||||
|
||||
private short length = 43;
|
||||
|
||||
private String plcId = "ABC000";
|
||||
|
||||
private String type = "0A";
|
||||
|
||||
private String id = "0101010101";
|
||||
|
||||
private char maohao = ':';
|
||||
|
||||
private char h = 'H';
|
||||
|
||||
private byte[]emp = new byte[]{10};
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue