| | |
| | | import com.dy.common.mw.protocol.Command; |
| | | import com.dy.common.mw.protocol4Mqtt.pSdV1.ProtocolConstantSdV1; |
| | | import com.dy.common.mw.protocol4Mqtt.pSdV1.ProtocolParserSdV1; |
| | | import com.dy.common.util.NumUtil; |
| | | import org.eclipse.paho.client.mqttv3.MqttMessage; |
| | | |
| | | /** |
| | |
| | | public static MqttTopic parseSubTopic(String topic) throws Exception { |
| | | if(topic != null && topic.trim().length() != 0){ |
| | | String[] topicGrp = topic.split("/") ; |
| | | if(topicGrp.length != 4){ |
| | | if(topicGrp.length != 5){ |
| | | throw new Exception("接收的mqtt消息主题不可识别") ; |
| | | }else{ |
| | | if(NumUtil.isPlusIntNumber(topicGrp[4])){ |
| | | throw new Exception("接收的mqtt消息主题不可识别") ; |
| | | } |
| | | if(Integer.parseInt(topicGrp[4]) <= 0){ |
| | | throw new Exception("接收的mqtt消息主题不可识别") ; |
| | | } |
| | | MqttTopic vo = new MqttTopic() ; |
| | | vo.orgTag = topicGrp[0] ; |
| | | vo.protocol = topicGrp[1] ; |
| | | vo.devId = topicGrp[2] ; |
| | | vo.name = topicGrp[3] ; |
| | | vo.type = topicGrp[3] ; |
| | | vo.no = Integer.parseInt(topicGrp[4]) ; |
| | | return vo ; |
| | | } |
| | | }else{ |
| | |
| | | } |
| | | |
| | | public static String createPubTopic(MqttTopic tp) throws Exception { |
| | | return tp.orgTag + "/" + tp.protocol + "/" + tp.devId + "/" + tp.name; |
| | | return tp.orgTag + "/" + tp.protocol + "/" + tp.devId + "/" + tp.type + "/" + tp.no; |
| | | } |
| | | |
| | | public static MqttSubMsg parseSubMsg(MqttTopic subTopic, MqttMessage mqttMsg, MqttCallback callback) throws Exception { |