public static void ProtocolPackageResolver_Unload(byte[] b, int c, TcpSocketClient client) { TcpClientBindingExternalClass TcpExtendTemp = client.External.External as TcpClientBindingExternalClass; if (b[2] == 0x01 && b[3] == 0x00 && b[4] == 0x02) { TcpExtendTemp.TVersion = "010002"; GoYOUnpack(b, c, client, "7A7A010002", "7B7B", OnResolveRecvMessagede_7A02); } }
private static void GoYOTower0x7E(byte[] b, int c, TcpSocketClient client) { TcpClientBindingExternalClass TcpExtendTemp = client.External.External as TcpClientBindingExternalClass; switch (b[2]) { case 0x0E: TcpExtendTemp.TVersion = "7E7E0E"; GoYOUnpack(b, c, client, "7E7E0E", "7D7D", OnResolveRecvMessagede_7E0E); break; default: break; } }
/// <summary> /// 扬尘噪音入口 /// </summary> /// <param name="b"></param> /// <param name="c"></param> /// <param name="client"></param> public static void ProtocolPackageResolver_RaiseDustNoise(byte[] b, int c, TcpSocketClient client) { //符合字节流协议处理 TcpClientBindingExternalClass TcpExtendTemp = client.External.External as TcpClientBindingExternalClass; // ** ** ** ** 5E ** ** ** 02 if (c > 8 && b[3] == 0x5E && b[7] == 0x02)//创塔设备 { TcpExtendTemp.TVersion = "ct"; ProtocolAnalysis_CT.OnResolveRecvMessage(b, c, client); } else if (b[0] == 0x7A && b[1] == 0x7A) { TcpExtendTemp.TVersion = "goyo"; if (b[2] == 0x01 && b[3] == 0x00 && b[4] == 0x04) { GoYOUnpack(b, c, client, "7A7A010004", "7B7B", ProtocolAnalysis_V1.OnResolveRecvMessage); } } }
public static void OnResolveRecvMessage(byte[] b, int c, TcpSocketClient client) { try { string datastring = Encoding.UTF8.GetString(b, 0, c); Send_frame sf = JsonConvert.DeserializeObject <Send_frame>(datastring); if (sf == null) { //数据错误 string sendmessage = JsonConvert.SerializeObject(Iot_reply_frame.Get_reply_frame(Result_code.data_error, Result_code.data_error_des)); client.SendMessage(sendmessage); //杀死该socket Thread.Sleep(1000); client.DisSocket(); } //长链接 else if (sf.short_link == null) { if (sf.frame_type == Frame_type.注册帧) { string frame_token = Register_operation.Judge_vendor_code(sf.data); if (string.IsNullOrEmpty(frame_token)) { //数据错误 string sendmessage = JsonConvert.SerializeObject(Iot_reply_frame.Get_reply_frame(Result_code.vendor_code_error, Result_code.vendor_code_error_des)); client.SendMessage(sendmessage); //杀死该socket Thread.Sleep(1000); client.DisSocket(); } else { TcpClientBindingExternalClass TcpExtendTemp = client.External.External as TcpClientBindingExternalClass; TcpExtendTemp.uuid = frame_token; //frame_token //发送正确的应答 string sendmessage = JsonConvert.SerializeObject(Iot_reply_frame.Get_reply_frame(new Register_reply_frame() { frame_token = frame_token })); client.SendMessage(sendmessage); } } else if (sf.frame_type == Frame_type.心跳帧) { TcpClientBindingExternalClass TcpExtendTemp = client.External.External as TcpClientBindingExternalClass; //TcpExtendTemp.uuid = "";//frame_token if (TcpExtendTemp.uuid == null || TcpExtendTemp.uuid == "" || TcpExtendTemp.uuid != sf.frame_token) { //帧token错误 string sendmessage = JsonConvert.SerializeObject(Iot_reply_frame.Get_reply_frame(Result_code.frame_token_error, Result_code.frame_token_error_des)); client.SendMessage(sendmessage); //杀死该socket Thread.Sleep(1000); client.DisSocket(); } else { //正确应答 string sendmessage = JsonConvert.SerializeObject(Iot_reply_frame.Get_reply_frame(Result_code.success, Result_code.success_des)); client.SendMessage(sendmessage); } } else if (sf.frame_type == Frame_type.数据帧) { TcpClientBindingExternalClass TcpExtendTemp = client.External.External as TcpClientBindingExternalClass; //TcpExtendTemp.uuid = "";//frame_token if (TcpExtendTemp.uuid == null || TcpExtendTemp.uuid == "" || TcpExtendTemp.uuid != sf.frame_token) { //帧token错误 string sendmessage = JsonConvert.SerializeObject(Iot_reply_frame.Get_reply_frame(Result_code.frame_token_error, Result_code.frame_token_error_des)); client.SendMessage(sendmessage); //杀死该socket Thread.Sleep(1000); client.DisSocket(); } else { //正确应答 string sendmessage = JsonConvert.SerializeObject(Iot_reply_frame.Get_reply_frame(Result_code.success, Result_code.success_des)); client.SendMessage(sendmessage); //todo解析 Data_frame_operation.Data_operation(sf.equipment_type, sf.data); } } else { //数据错误 string sendmessage = JsonConvert.SerializeObject(Iot_reply_frame.Get_reply_frame(Result_code.data_error, Result_code.data_error_des)); client.SendMessage(sendmessage); //杀死该socket Thread.Sleep(1000); client.DisSocket(); } } //短链接 else if (sf.short_link == "true") { if (sf.frame_type == Frame_type.数据帧) { bool frame_token = Register_operation.Judge_vendor_code(sf.frame_token); if (!frame_token)//厂商验证码不正确 { //数据错误 string sendmessage = JsonConvert.SerializeObject(Iot_reply_frame.Get_reply_frame(Result_code.vendor_code_error, Result_code.vendor_code_error_des)); client.SendMessage(sendmessage); //杀死该socket Thread.Sleep(1000); client.DisSocket(); } else//厂商验证码正确 { //正确应答 string sendmessage = JsonConvert.SerializeObject(Iot_reply_frame.Get_reply_frame(Result_code.success, Result_code.success_des)); client.SendMessage(sendmessage); //todo解析 Data_frame_operation.Data_operation(sf.equipment_type, sf.data); //短链接差不多就杀死这个链接 Thread.Sleep(3000); client.DisSocket(); } } else { //数据错误 string sendmessage = JsonConvert.SerializeObject(Iot_reply_frame.Get_reply_frame(Result_code.data_error, Result_code.data_error_des)); client.SendMessage(sendmessage); //杀死该socket Thread.Sleep(1000); client.DisSocket(); } } else { //数据错误 string sendmessage = JsonConvert.SerializeObject(Iot_reply_frame.Get_reply_frame(Result_code.data_error, Result_code.data_error_des)); client.SendMessage(sendmessage); //杀死该socket Thread.Sleep(1000); client.DisSocket(); } } catch (Exception ex) { if (client != null) { string sendmessage = JsonConvert.SerializeObject(Iot_reply_frame.Get_reply_frame(Result_code.unknown_error, Result_code.unknown_error_des)); client.SendMessage(sendmessage); //杀死该socket Thread.Sleep(1000); client.DisSocket(); } } }