liurunyu
2 天以前 f8b2e59a82702a790c383a8ecd90c708c76e2488
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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) ;
    }
 
}