public static PostMessage DealACKNACK(byte[] inBuffer) { PostMessage postMsg = new PostMessage(); try { if (inBuffer != null && inBuffer.Length > 2) { int start = 0; for (int i = start; i < 3; i++) { if (inBuffer[i] == PostDefine.START[0]) { start++; } else { break; } } int end = 0; for (int i = inBuffer.Length - 1; i >= inBuffer.Length - 3; i--) { if (inBuffer[i] == PostDefine.END[0]) { end++; } else { break; } } int index = start; if (inBuffer[index] == PostDefine.ACK) { postMsg.setReturnType(ReturnType.ACK); postMsg.setErrorInfo(CheckCode(inBuffer.ToString() .Substring(index + 1, index + 3))); } else if (inBuffer[index] == PostDefine.NAK) { postMsg.setReturnType(ReturnType.NAK); postMsg.setErrorInfo(CheckCode(inBuffer.ToString() .Substring(index + 1, index + 3))); } else { index += 11; if (inBuffer.Length > index) { if (inBuffer[index] == PostDefine.SUCCEED) // 0x60 { postMsg.setReturnType(ReturnType.PATH); int len = inBuffer.Length - (11 + 2 + start + end); // ���������� byte[] header = new byte[] { inBuffer[start + 1], inBuffer[start + 2] }; int msgLen = Integer.ParseInt(Function .hexString(header), 16); if (msgLen == len + 8) { byte[] bytesContent = new byte[len]; int j = 0; end = start + 11 + len; for (int i = start + 11; i < end; i++) { bytesContent[j] = inBuffer[i]; j++; } postMsg.setContent(bytesContent); } else { postMsg.setReturnType(ReturnType.Integrity); } } } else { postMsg.setReturnType(ReturnType.NONE); } } } } catch (System.Exception ex) { // ex.printStackTrace(); // System.out.println("���������������� " + "\r\n"); } return postMsg; }
public static PostMessage DealACKNACK(byte[] inBuffer) { PostMessage postMsg = new PostMessage(); try { if (inBuffer != null && inBuffer.Length > 2) { int start = 0; for (int i = start; i < 3; i++) { if (inBuffer[i] == PostDefine.START[0]) { start++; } else { break; } } int end = 0; for (int i = inBuffer.Length - 1; i >= inBuffer.Length - 3; i--) { if (inBuffer[i] == PostDefine.END[0]) { end++; } else { break; } } int index = start; if (inBuffer[index] == PostDefine.ACK) { postMsg.setReturnType(ReturnType.ACK); postMsg.setErrorInfo(CheckCode(inBuffer.ToString() .Substring(index + 1, index + 3))); } else if (inBuffer[index] == PostDefine.NAK) { postMsg.setReturnType(ReturnType.NAK); postMsg.setErrorInfo(CheckCode(inBuffer.ToString() .Substring(index + 1, index + 3))); } else { index += 11; if (inBuffer.Length > index) { if (inBuffer[index] == PostDefine.SUCCEED) // 0x60 { postMsg.setReturnType(ReturnType.PATH); int len = inBuffer.Length - (11 + 2 + start + end); // ���������� byte[] header = new byte[] { inBuffer[start + 1], inBuffer[start + 2] }; int msgLen = Integer.ParseInt(Function .hexString(header), 16); if (msgLen == len + 8) { byte[] bytesContent = new byte[len]; int j = 0; end = start + 11 + len; for (int i = start + 11; i < end; i++) { bytesContent[j] = inBuffer[i]; j++; } postMsg.setContent(bytesContent); } else { postMsg.setReturnType(ReturnType.Integrity); } } } else { postMsg.setReturnType(ReturnType.NONE); } } } } catch (System.Exception ex) { // ex.printStackTrace(); // System.out.println("���������������� " + "\r\n"); } return(postMsg); }