cn.foxtech.device.protocol.v1.modbus.template.JReadStatusTemplate Maven / Gradle / Ivy
package cn.foxtech.device.protocol.v1.modbus.template;
import cn.foxtech.device.protocol.v1.core.context.ApplicationContext;
import cn.foxtech.device.protocol.v1.core.exception.ProtocolException;
import cn.foxtech.device.protocol.v1.core.template.ITemplate;
import cn.foxtech.device.protocol.v1.modbus.core.ModBusWriteStatusRequest;
import lombok.Data;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* CoilStatus数据实体的数据模板
*/
@Data
public class JReadStatusTemplate implements ITemplate {
public static final String READ_COIL_STATUS = "Read Coil Status";
public static final String READ_DISCRETE_INPUT_STATUS = "Read Discrete Input Status";
public static final String WRITE_SINGLE_STATUS = "Write Single Status";
private JDecoderParam decoderParam = new JDecoderParam();
/**
* 缺省的状态格式
*
* @return 系统模板名称
*/
public String getSysTemplateName() {
return "status default";
}
public void loadJsnModel(String modelName) {
// 从进程的上下文中,获得设备模型信息
Map deviceTemplateEntity = ApplicationContext.getDeviceModels(modelName);
// 检测:上下文侧的时间戳和当前模型的时间戳是否一致
Object updateTime = deviceTemplateEntity.getOrDefault("updateTime", 0L);
if (this.decoderParam.updateTime.equals(updateTime)) {
return;
}
// 取出JSON模型的数据列表
Map modelParam = (Map) deviceTemplateEntity.getOrDefault("modelParam", new HashMap<>());
List