cn.foxtech.device.protocol.v1.iec104.slaver.IEC104SlaverGeneralCall Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fox-edge-server-protocol-iec104-slaver Show documentation
Show all versions of fox-edge-server-protocol-iec104-slaver Show documentation
fox-edge-server-protocol-iec104-slaver
package cn.foxtech.device.protocol.v1.iec104.slaver;
import cn.foxtech.device.protocol.v1.core.annotation.FoxEdgeDeviceType;
import cn.foxtech.device.protocol.v1.core.annotation.FoxEdgeOperate;
import cn.foxtech.device.protocol.v1.core.annotation.FoxEdgeOperateParam;
import cn.foxtech.device.protocol.v1.core.exception.ProtocolException;
import cn.foxtech.device.protocol.v1.utils.BcdUtils;
import cn.foxtech.device.protocol.v1.core.utils.JsonUtils;
import cn.foxtech.device.protocol.v1.iec104.core.builder.ApduVOBuilder;
import cn.foxtech.device.protocol.v1.iec104.core.entity.*;
import cn.foxtech.device.protocol.v1.iec104.core.enums.AsduTypeIdEnum;
import cn.foxtech.device.protocol.v1.iec104.core.enums.CotReasonEnum;
import cn.foxtech.device.protocol.v1.iec104.core.vo.ApduVO;
import cn.foxtech.device.protocol.v1.iec104.slaver.template.Iec104Template;
import cn.foxtech.device.protocol.v1.iec104.slaver.template.JReadDataTemplate;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 总召唤的编码解码器
*/
@FoxEdgeDeviceType(value = "IEC104 Device", manufacturer = "Fox Edge")
public class IEC104SlaverGeneralCall {
/**
* 总召唤的编码器
*
* @param param 参数
* @return 待发送的对象
*/
@FoxEdgeOperate(name = "总召唤", polling = true, type = FoxEdgeOperate.encoder, timeout = 10000)
@FoxEdgeOperateParam(names = {"设备地址"}, values = {"1"})
public static Object encodeSessionRequest(Map param) {
try {
// I帧控制头
IControlEntity controlEntity = new IControlEntity();
controlEntity.setSend((short) 0);
controlEntity.setAccept((short) 0);
ApduEntity apduEntity = new ApduEntity();
apduEntity.setControl(controlEntity);
AsduEntity asduEntity = new AsduEntity();
apduEntity.setAsdu(asduEntity);
// 总召唤的类型ID
asduEntity.setTypeId(AsduTypeIdEnum.generalCall.getValue());
// 非连续的数据:总召唤会要求带回各种数据,就不可能连续成一个数组
VsqEntity vsq = new VsqEntity();
vsq.setSq(false);
vsq.setNum(0);
asduEntity.setVsq(vsq);
// 激活
CotEntity cot = new CotEntity();
cot.setAddr(0);
cot.setTest(false);
cot.setPn(true);
cot.setReason(CotReasonEnum.active.getValue());
asduEntity.setCot(cot);
// 通用地址:1
asduEntity.setCommonAddress(1);
byte[] data = {0x00, 0x00, 0x00, 0x14};
asduEntity.setData(data);
// 实体转换为VO
ApduVO apduVO = ApduVOBuilder.buildVO(apduEntity);
// 一问多答:要额外指明等待指定的结束符activeEnded才算结束
apduVO.getWaitEndFlag().add(CotReasonEnum.activeEnded.getValue());
return apduVO;
} catch (Exception e) {
throw new ProtocolException("编码错误:" + e.getMessage());
}
}
/**
* 总召唤的解码器
*
* @param respond channel返回的响应对象
* @param param 设备的参数信息
* @return 解码后的设备数据
*/
@FoxEdgeOperate(name = "总召唤", polling = true, type = FoxEdgeOperate.decoder, timeout = 10000)
@FoxEdgeOperateParam(names = {"设备地址"}, values = {"1"})
public static Map decodeSessionRequest(Object respond, Map param) {
Map values = new HashMap<>();
// 从输入参数中,提取解码需要的模板参数
String templateName = (String) param.get("template_name");
String operateName = (String) param.get("operate_name");
Map operate = (Map) param.get("operate");
List
© 2015 - 2024 Weber Informatics LLC | Privacy Policy