@Test public void testIncomingLong() { int[] buffer = new int[] { 0x21, 0x31, 0x21, 0x57, 0x54, 0xC7, 0x17, 0xB5, 0xFD, 0xD1, 0x48, 0x08, 0x35, 0x6C, 0x66, 0xD2, 0x40, 0x76, 0x1F, 0xAB, 0xCB, 0x6C, 0x1D, 0x15, 0xF7, 0xD1, 0xFA, 0xB8, 0xC6, 0xCC, 0xB3, 0xFB, 0xF1, 0xD1, 0xB5, 0x0F, 0xDE, 0xAB, 0x1C, 0xC6, 0x2A, 0xB5, 0x3B, 0x8C, 0x72, 0x86, 0x4A, 0x92, 0x71, 0x58, 0x3D, 0x5D, 0x78, 0x8A, 0x50, 0x8A, 0x5F, 0x32, 0x06, 0xA7, 0xF7, 0x68, 0x38, 0x47, 0xA4, 0x63, 0xCD, 0x7D, 0x3A, 0x35, 0x9A, 0x75, 0x45, 0xB8, 0xEE, 0x9E, 0x4F, 0x88, 0xC5, 0x7C, 0xD1, 0xD7, 0x6C, 0x96, 0x0D, 0x96, 0xE9, 0x09, 0x4F, 0xCB, 0x51, 0x69, 0x07, 0x3D, 0xE3, 0xE7, 0x85, 0x33, 0xC8, 0xE4, 0x72, 0xAE, 0x1E, 0xF1, 0x53, 0x28, 0x15, 0x66, 0x3D, 0x16, 0x3C, 0x17, 0x73, 0x09, 0xF6, 0x53, 0x1E, 0xB6, 0x80, 0x15, 0x63, 0xF1, 0x34, 0xED, 0xE0, 0x3C, 0xC8, 0x87, 0xCF, 0xAC, 0x35, 0x90, 0x03, 0x97, 0x76, 0xDA, 0x26, 0x3E, 0x71, 0x4D, 0xD6, 0xE0, 0x6C, 0x50, 0xC2, 0x40, 0x1E, 0x6A, 0xBE, 0x4A, 0x75, 0x8F, 0x78, 0x60, 0x1E, 0x69 }; AshFrame frame = AshFrame.createFromInput(buffer); assertEquals(1, frame.ackNum); assertEquals(2, frame.frmNum); assertEquals(152, frame.dataBuffer.length); }
public static AshFrame createFromInput(int[] buffer) { if (buffer.length < 3) { return null; } int[] unstuffedData = new int[buffer.length]; int outLength = 0; boolean escape = false; for (int data : buffer) { if (escape) { escape = false; if ((data & 0x20) == 0) { data = (byte) (data + 0x20); } else { data = (byte) (data & 0xDF); } } else if (data == 0x7D) { escape = true; continue; } unstuffedData[outLength++] = data; } if (checkCRC(unstuffedData, outLength) != 0) { return null; } FrameType frameType = getFrameType(unstuffedData); if (frameType == null) { logger.debug("Invalid ASH frame type {}", String.format("%02X", unstuffedData[0])); return null; } int[] frameBuffer = Arrays.copyOfRange(unstuffedData, 0, outLength); switch (frameType) { case ACK: return new AshFrameAck(frameBuffer); case DATA: dataRandomise(frameBuffer, 1, frameBuffer.length); return new AshFrameData(frameBuffer); case ERROR: return new AshFrameError(frameBuffer); case NAK: return new AshFrameNak(unstuffedData); case RST: return new AshFrameRst(); case RSTACK: return new AshFrameRstAck(frameBuffer); default: break; } return null; }
AshFrame { public static AshFrame createFromInput(int[] buffer) { if (buffer.length < 3) { return null; } int[] unstuffedData = new int[buffer.length]; int outLength = 0; boolean escape = false; for (int data : buffer) { if (escape) { escape = false; if ((data & 0x20) == 0) { data = (byte) (data + 0x20); } else { data = (byte) (data & 0xDF); } } else if (data == 0x7D) { escape = true; continue; } unstuffedData[outLength++] = data; } if (checkCRC(unstuffedData, outLength) != 0) { return null; } FrameType frameType = getFrameType(unstuffedData); if (frameType == null) { logger.debug("Invalid ASH frame type {}", String.format("%02X", unstuffedData[0])); return null; } int[] frameBuffer = Arrays.copyOfRange(unstuffedData, 0, outLength); switch (frameType) { case ACK: return new AshFrameAck(frameBuffer); case DATA: dataRandomise(frameBuffer, 1, frameBuffer.length); return new AshFrameData(frameBuffer); case ERROR: return new AshFrameError(frameBuffer); case NAK: return new AshFrameNak(unstuffedData); case RST: return new AshFrameRst(); case RSTACK: return new AshFrameRstAck(frameBuffer); default: break; } return null; } }
AshFrame { public static AshFrame createFromInput(int[] buffer) { if (buffer.length < 3) { return null; } int[] unstuffedData = new int[buffer.length]; int outLength = 0; boolean escape = false; for (int data : buffer) { if (escape) { escape = false; if ((data & 0x20) == 0) { data = (byte) (data + 0x20); } else { data = (byte) (data & 0xDF); } } else if (data == 0x7D) { escape = true; continue; } unstuffedData[outLength++] = data; } if (checkCRC(unstuffedData, outLength) != 0) { return null; } FrameType frameType = getFrameType(unstuffedData); if (frameType == null) { logger.debug("Invalid ASH frame type {}", String.format("%02X", unstuffedData[0])); return null; } int[] frameBuffer = Arrays.copyOfRange(unstuffedData, 0, outLength); switch (frameType) { case ACK: return new AshFrameAck(frameBuffer); case DATA: dataRandomise(frameBuffer, 1, frameBuffer.length); return new AshFrameData(frameBuffer); case ERROR: return new AshFrameError(frameBuffer); case NAK: return new AshFrameNak(unstuffedData); case RST: return new AshFrameRst(); case RSTACK: return new AshFrameRstAck(frameBuffer); default: break; } return null; } protected  AshFrame(); }
AshFrame { public static AshFrame createFromInput(int[] buffer) { if (buffer.length < 3) { return null; } int[] unstuffedData = new int[buffer.length]; int outLength = 0; boolean escape = false; for (int data : buffer) { if (escape) { escape = false; if ((data & 0x20) == 0) { data = (byte) (data + 0x20); } else { data = (byte) (data & 0xDF); } } else if (data == 0x7D) { escape = true; continue; } unstuffedData[outLength++] = data; } if (checkCRC(unstuffedData, outLength) != 0) { return null; } FrameType frameType = getFrameType(unstuffedData); if (frameType == null) { logger.debug("Invalid ASH frame type {}", String.format("%02X", unstuffedData[0])); return null; } int[] frameBuffer = Arrays.copyOfRange(unstuffedData, 0, outLength); switch (frameType) { case ACK: return new AshFrameAck(frameBuffer); case DATA: dataRandomise(frameBuffer, 1, frameBuffer.length); return new AshFrameData(frameBuffer); case ERROR: return new AshFrameError(frameBuffer); case NAK: return new AshFrameNak(unstuffedData); case RST: return new AshFrameRst(); case RSTACK: return new AshFrameRstAck(frameBuffer); default: break; } return null; } protected  AshFrame(); int[] getOutputBuffer(); static AshFrame createFromInput(int[] buffer); int getFrmNum(); void setFrmNum(int frmNum); int getAckNum(); void setAckNum(int ackNum); FrameType getFrameType(); }
AshFrame { public static AshFrame createFromInput(int[] buffer) { if (buffer.length < 3) { return null; } int[] unstuffedData = new int[buffer.length]; int outLength = 0; boolean escape = false; for (int data : buffer) { if (escape) { escape = false; if ((data & 0x20) == 0) { data = (byte) (data + 0x20); } else { data = (byte) (data & 0xDF); } } else if (data == 0x7D) { escape = true; continue; } unstuffedData[outLength++] = data; } if (checkCRC(unstuffedData, outLength) != 0) { return null; } FrameType frameType = getFrameType(unstuffedData); if (frameType == null) { logger.debug("Invalid ASH frame type {}", String.format("%02X", unstuffedData[0])); return null; } int[] frameBuffer = Arrays.copyOfRange(unstuffedData, 0, outLength); switch (frameType) { case ACK: return new AshFrameAck(frameBuffer); case DATA: dataRandomise(frameBuffer, 1, frameBuffer.length); return new AshFrameData(frameBuffer); case ERROR: return new AshFrameError(frameBuffer); case NAK: return new AshFrameNak(unstuffedData); case RST: return new AshFrameRst(); case RSTACK: return new AshFrameRstAck(frameBuffer); default: break; } return null; } protected  AshFrame(); int[] getOutputBuffer(); static AshFrame createFromInput(int[] buffer); int getFrmNum(); void setFrmNum(int frmNum); int getAckNum(); void setAckNum(int ackNum); FrameType getFrameType();  }