package com.dy.common.mw.protocol4Mqtt.pSdV1;
|
|
import com.dy.common.mw.protocol4Mqtt.MqttPubMsg;
|
import com.dy.common.mw.protocol4Mqtt.MqttSubMsg;
|
import com.dy.common.util.Callback;
|
import lombok.Data;
|
|
/**
|
* @Author: liurunyu
|
* @Date: 2025/6/4 16:58
|
* @Description 收到的订阅消息
|
*/
|
@Data
|
public class MqttSubMsgSdV1 extends MqttSubMsg {
|
public Integer address ;//寄存器地址
|
public String value ;//寄存器值
|
|
public MqttSubMsgSdV1(){}
|
|
public MqttSubMsgSdV1(String deviceId, String topic, String msg) {
|
this.deviceId = deviceId ;
|
this.topic = topic ;
|
this.msg = msg ;
|
}
|
public String toString(){
|
StringBuilder sb = new StringBuilder();
|
if(commandId != null){
|
sb.append("commandId:")
|
.append(commandId)
|
.append("\n") ;
|
}
|
sb.append("主题:")
|
.append(topic)
|
.append("\n") ;
|
sb.append("消息:")
|
.append(msg)
|
.append("\n") ;
|
|
return sb.toString() ;
|
}
|
|
public boolean subMsgMatchPubMsg(MqttPubMsg pubMsg){
|
if (pubMsg instanceof MqttPubMsgSdV1) {
|
MqttPubMsgSdV1 pubMsgSdV1 = (MqttPubMsgSdV1) pubMsg;
|
if(this.address.intValue() == pubMsgSdV1.getAddress().intValue()){
|
return true ;
|
}
|
}
|
return false ;
|
}
|
|
@Override
|
public boolean valid() {
|
if (topic == null || topic.isEmpty()) {
|
return false;
|
}
|
if (msg == null || msg.isEmpty()) {
|
return false;
|
}
|
return true;
|
}
|
|
@Override
|
public void action(Callback callback){
|
callback.call(this) ;
|
}
|
|
}
|