|  |  |  | 
|---|
|  |  |  | import com.alibaba.fastjson2.JSON; | 
|---|
|  |  |  | import com.alibaba.fastjson2.JSONObject; | 
|---|
|  |  |  | import com.dy.common.mw.protocol.Command; | 
|---|
|  |  |  | import com.dy.common.mw.protocol4Mqtt.MqttCallback; | 
|---|
|  |  |  | import com.dy.common.mw.protocol4Mqtt.MqttTopic; | 
|---|
|  |  |  | import com.dy.common.mw.protocol4Mqtt.Vo4Up; | 
|---|
|  |  |  | import com.dy.common.mw.protocol4Mqtt.*; | 
|---|
|  |  |  | import com.dy.common.mw.protocol4Mqtt.pSdV1.comParam.ComCtrlVo; | 
|---|
|  |  |  | import com.dy.common.mw.protocol4Mqtt.pSdV1.comParam.ComSetParamVo; | 
|---|
|  |  |  | import com.dy.common.mw.protocol4Mqtt.pSdV1.downVos.FaultClearVo; | 
|---|
|  |  |  | 
|---|
|  |  |  | * @Description | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public class ProtocolParserSdV1 { | 
|---|
|  |  |  | public MqttSubMsgSdV1 parseSubMsg(MqttTopic subTopic, MqttMessage mqttMsg, MqttCallback callback) throws Exception { | 
|---|
|  |  |  | public MqttSubMsg parseSubMsg(MqttTopic subTopic, MqttMessage mqttMsg, MqttCallback callback) throws Exception { | 
|---|
|  |  |  | String strTxt = new String(mqttMsg.getPayload(), "UTF-8"); | 
|---|
|  |  |  | if(!JSON.isValid(strTxt)){ | 
|---|
|  |  |  | throw new Exception("接收到MQTT消息,协议" + subTopic.protocol + ",设备ID" + subTopic.devId + ",主题" + subTopic.longName() + "消息格式非json数据(" + strTxt + ")") ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | MqttSubMsgSdV1 msg = new MqttSubMsgSdV1(subTopic, strTxt); | 
|---|
|  |  |  | MqttSubMsg msg = new MqttSubMsg(subTopic, strTxt); | 
|---|
|  |  |  | Vo4Up vo ; | 
|---|
|  |  |  | DevRunInfo stInfo = null ; | 
|---|
|  |  |  | switch (subTopic.type) { | 
|---|
|  |  |  | 
|---|
|  |  |  | return msg; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public MqttPubMsgSdV1 createPubMsg(String orgTag, Command com) throws Exception { | 
|---|
|  |  |  | MqttPubMsgSdV1 msg ; | 
|---|
|  |  |  | public MqttPubMsg createPubMsg(String orgTag, Command com) throws Exception { | 
|---|
|  |  |  | MqttPubMsg msg ; | 
|---|
|  |  |  | switch (com.code) { | 
|---|
|  |  |  | case CodeSdV1.cd_Fault -> { | 
|---|
|  |  |  | //故障解除命令 | 
|---|
|  |  |  | 
|---|
|  |  |  | throw new Exception("接收到MQTT命令,协议" + com.protocol + "版本" + com.protocolVersion + "功能码" + com.code + "命令结果回收URL为空") ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | private MqttPubMsgSdV1 createPubMsgOfFault(String orgTag, Command com) throws Exception { | 
|---|
|  |  |  | private MqttPubMsg createPubMsgOfFault(String orgTag, Command com) throws Exception { | 
|---|
|  |  |  | JSONObject obj = (JSONObject) com.param; | 
|---|
|  |  |  | String json = obj.toJSONString(); | 
|---|
|  |  |  | ComCtrlVo cvo = JSON.parseObject(json, ComCtrlVo.class); | 
|---|
|  |  |  | if(cvo == null){ | 
|---|
|  |  |  | throw new Exception("json转ComCtrlVo为null") ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | MqttPubMsgSdV1 msg = new MqttPubMsgSdV1() ; | 
|---|
|  |  |  | MqttPubMsg msg = new MqttPubMsg() ; | 
|---|
|  |  |  | this.setPubMsgBase(com, msg); | 
|---|
|  |  |  | msg.isCacheForOffLine = false ; | 
|---|
|  |  |  | msg.hasResponse = true ; | 
|---|
|  |  |  | 
|---|
|  |  |  | msg.msg = JSON.toJSONString(new FaultClearVo(cvo.startTrueStopFalse ?(byte)1:0)) ; | 
|---|
|  |  |  | return msg ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | private MqttPubMsgSdV1 createPubMsgOfStir(String orgTag, Command com) throws Exception { | 
|---|
|  |  |  | private MqttPubMsg createPubMsgOfStir(String orgTag, Command com) throws Exception { | 
|---|
|  |  |  | JSONObject obj = (JSONObject) com.param; | 
|---|
|  |  |  | String json = obj.toJSONString(); | 
|---|
|  |  |  | ComCtrlVo cvo = JSON.parseObject(json, ComCtrlVo.class); | 
|---|
|  |  |  | if(cvo == null){ | 
|---|
|  |  |  | throw new Exception("json转ComCtrlVo为null") ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | MqttPubMsgSdV1 msg = new MqttPubMsgSdV1() ; | 
|---|
|  |  |  | MqttPubMsg msg = new MqttPubMsg() ; | 
|---|
|  |  |  | this.setPubMsgBase(com, msg); | 
|---|
|  |  |  | msg.isCacheForOffLine = false ; | 
|---|
|  |  |  | msg.hasResponse = true ; | 
|---|
|  |  |  | 
|---|
|  |  |  | msg.msg = JSON.toJSONString(new StirStartVo(cvo.startTrueStopFalse ?(byte)1:0)) ; | 
|---|
|  |  |  | return msg ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | private MqttPubMsgSdV1 createPubMsgOfInject(String orgTag, Command com) throws Exception { | 
|---|
|  |  |  | private MqttPubMsg createPubMsgOfInject(String orgTag, Command com) throws Exception { | 
|---|
|  |  |  | JSONObject obj = (JSONObject) com.param; | 
|---|
|  |  |  | String json = obj.toJSONString(); | 
|---|
|  |  |  | ComCtrlVo cvo = JSON.parseObject(json, ComCtrlVo.class); | 
|---|
|  |  |  | if(cvo == null){ | 
|---|
|  |  |  | throw new Exception("json转ComCtrlVo为null") ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | MqttPubMsgSdV1 msg = new MqttPubMsgSdV1() ; | 
|---|
|  |  |  | MqttPubMsg msg = new MqttPubMsg() ; | 
|---|
|  |  |  | this.setPubMsgBase(com, msg); | 
|---|
|  |  |  | msg.isCacheForOffLine = false ; | 
|---|
|  |  |  | msg.hasResponse = true ; | 
|---|
|  |  |  | 
|---|
|  |  |  | msg.msg = JSON.toJSONString(new InjectStartVo(cvo.startTrueStopFalse ?(byte)1:0)) ; | 
|---|
|  |  |  | return msg ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | private MqttPubMsgSdV1 createPubMsgOfIrr(String orgTag, Command com) throws Exception { | 
|---|
|  |  |  | private MqttPubMsg createPubMsgOfIrr(String orgTag, Command com) throws Exception { | 
|---|
|  |  |  | JSONObject obj = (JSONObject) com.param; | 
|---|
|  |  |  | String json = obj.toJSONString(); | 
|---|
|  |  |  | ComCtrlVo cvo = JSON.parseObject(json, ComCtrlVo.class); | 
|---|
|  |  |  | if(cvo == null){ | 
|---|
|  |  |  | throw new Exception("json转ComCtrlVo为null") ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | MqttPubMsgSdV1 msg = new MqttPubMsgSdV1() ; | 
|---|
|  |  |  | MqttPubMsg msg = new MqttPubMsg() ; | 
|---|
|  |  |  | this.setPubMsgBase(com, msg); | 
|---|
|  |  |  | msg.isCacheForOffLine = false ; | 
|---|
|  |  |  | msg.hasResponse = true ; | 
|---|
|  |  |  | 
|---|
|  |  |  | return msg ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private MqttPubMsgSdV1 createPubMsgOfParam(String orgTag, Command com) throws Exception { | 
|---|
|  |  |  | private MqttPubMsg createPubMsgOfParam(String orgTag, Command com) throws Exception { | 
|---|
|  |  |  | JSONObject obj = (JSONObject) com.param; | 
|---|
|  |  |  | String json = obj.toJSONString(); | 
|---|
|  |  |  | ComSetParamVo cvo = JSON.parseObject(json, ComSetParamVo.class); | 
|---|
|  |  |  | if(cvo == null){ | 
|---|
|  |  |  | throw new Exception("json转ComSetParamVo为null") ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | MqttPubMsgSdV1 msg = new MqttPubMsgSdV1() ; | 
|---|
|  |  |  | MqttPubMsg msg = new MqttPubMsg() ; | 
|---|
|  |  |  | this.setPubMsgBase(com, msg); | 
|---|
|  |  |  | msg.isCacheForOffLine = false ; | 
|---|
|  |  |  | msg.hasResponse = false ; | 
|---|
|  |  |  | msg.hasResponse = true ; | 
|---|
|  |  |  | msg.cd = CodeSdV1.cd_Param ; | 
|---|
|  |  |  | msg.topic = new MqttTopic(orgTag, com.protocol + com.protocolVersion, com.rtuAddr, ProtocolConstantSdV1.PubTopicParam, cvo.no) ; | 
|---|
|  |  |  | msg.msg = JSON.toJSONString(new ParamSetVo(cvo.stirDuration, cvo.injectDuration)) ; | 
|---|
|  |  |  | return msg ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private void setPubMsgBase(Command com, MqttPubMsgSdV1 msg){ | 
|---|
|  |  |  | private void setPubMsgBase(Command com, MqttPubMsg msg){ | 
|---|
|  |  |  | msg.commandId = com.id ; | 
|---|
|  |  |  | msg.deviceId = com.rtuAddr ; | 
|---|
|  |  |  | msg.mqttResultSendWebUrl = com.rtuResultSendWebUrl ; | 
|---|