@Test public void testFrame01() throws TcTmException { byte[] data = intToByteArray(AOS_FRAME_01); AosManagedParameters tmp = getParams(); AosFrameDecoder tfd = new AosFrameDecoder(tmp); AosTransferFrame tf = tfd.decode(data, 0, data.length); assertEquals(0xAB, tf.getSpacecraftId()); assertEquals(1, tf.getVirtualChannelId()); assertEquals(343, tf.getVcFrameSeq()); assertEquals(8, tf.getFirstHeaderPointer()); assertFalse(tf.hasOcf()); List<byte[]> pktList = new ArrayList<>(); PacketDecoder pd = new PacketDecoder(500, (byte[] p) -> pktList.add(p)); pd.process(tf.getData(), tf.getFirstHeaderPointer(), tf.getDataEnd() - tf.getFirstHeaderPointer()); assertTrue(pd.hasIncompletePacket()); assertTrue(pktList.isEmpty()); }
@Override public AosTransferFrame decode(byte[] data, int offset, int length) throws TcTmException { log.trace("decoding frame buf length: {}, dataOffset: {} , dataLength: {}", data.length, offset, length); int version = data[offset] >>6; if(version != 1) { throw new TcTmException("Bad frame version number " + version + "; expected 1 (AOS)"); } if (length != aosParams.frameLength) { throw new TcTmException("Bad frame length " + length + "; expected " + aosParams.frameLength); } int dataEnd = offset + length; if (crc != null) { dataEnd -= 2; int c1 = crc.compute(data, offset, dataEnd - offset); int c2 = ByteArrayUtils.decodeShort(data, dataEnd); if (c1 != c2) { throw new CorruptedFrameException("Bad CRC computed: " + c1 + " in the frame: " + c2); } } int gvcid; int dataOffset = offset + 6; if (aosParams.frameHeaderErrorControlPresent) { try { DecoderResult dr = AosFrameHeaderErrorCorr.decode(ByteArrayUtils.decodeShort(data, offset), data[offset + 5], ByteArrayUtils.decodeShort(data, offset + 6)); gvcid = dr.gvcid; } catch (ReedSolomonException e) { throw new CorruptedFrameException("Failed to Reed-Solomon verify/correct the AOS frame header fields"); } dataOffset += 2; } else { gvcid = ByteArrayUtils.decodeShort(data, offset); } int vn = gvcid >> 14; if (vn != 1) { throw new TcTmException("Invalid AOS frame version number " + vn + "; expected " + 1); } int spacecraftId = (gvcid >> 6)&0xFF; int virtualChannelId = gvcid & 0x3F; AosTransferFrame atf = new AosTransferFrame(data, spacecraftId, virtualChannelId); AosVcManagedParameters vmp = aosParams.vcParams.get(virtualChannelId); if (vmp == null) { if (virtualChannelId == 63) { atf.setServiceType(ServiceType.IDLE); return atf; } throw new TcTmException("Received data for unknown VirtualChannel " + virtualChannelId); } dataOffset += aosParams.insertZoneLength; atf.setVcFrameSeq(ByteArrayUtils.decode3Bytes(data, offset + 2)); if (vmp.ocfPresent) { dataEnd -= 4; atf.setOcf(ByteArrayUtils.decodeInt(data, dataEnd)); } if (vmp.service == ServiceType.PACKET) { int fhp = ByteArrayUtils.decodeShort(data, dataOffset) & 0x7FF; dataOffset += 2; if (fhp == 0x7FF) { fhp = -1; } else { fhp += dataOffset; if (fhp > dataEnd) { throw new TcTmException("First header pointer in the M_PDU part of AOS frame is outside the data " + (fhp - dataOffset) + ">" + (dataEnd - dataOffset)); } } atf.setFirstHeaderPointer(fhp); } atf.setDataStart(dataOffset); atf.setDataEnd(dataEnd); return atf; }
AosFrameDecoder implements TransferFrameDecoder { @Override public AosTransferFrame decode(byte[] data, int offset, int length) throws TcTmException { log.trace("decoding frame buf length: {}, dataOffset: {} , dataLength: {}", data.length, offset, length); int version = data[offset] >>6; if(version != 1) { throw new TcTmException("Bad frame version number " + version + "; expected 1 (AOS)"); } if (length != aosParams.frameLength) { throw new TcTmException("Bad frame length " + length + "; expected " + aosParams.frameLength); } int dataEnd = offset + length; if (crc != null) { dataEnd -= 2; int c1 = crc.compute(data, offset, dataEnd - offset); int c2 = ByteArrayUtils.decodeShort(data, dataEnd); if (c1 != c2) { throw new CorruptedFrameException("Bad CRC computed: " + c1 + " in the frame: " + c2); } } int gvcid; int dataOffset = offset + 6; if (aosParams.frameHeaderErrorControlPresent) { try { DecoderResult dr = AosFrameHeaderErrorCorr.decode(ByteArrayUtils.decodeShort(data, offset), data[offset + 5], ByteArrayUtils.decodeShort(data, offset + 6)); gvcid = dr.gvcid; } catch (ReedSolomonException e) { throw new CorruptedFrameException("Failed to Reed-Solomon verify/correct the AOS frame header fields"); } dataOffset += 2; } else { gvcid = ByteArrayUtils.decodeShort(data, offset); } int vn = gvcid >> 14; if (vn != 1) { throw new TcTmException("Invalid AOS frame version number " + vn + "; expected " + 1); } int spacecraftId = (gvcid >> 6)&0xFF; int virtualChannelId = gvcid & 0x3F; AosTransferFrame atf = new AosTransferFrame(data, spacecraftId, virtualChannelId); AosVcManagedParameters vmp = aosParams.vcParams.get(virtualChannelId); if (vmp == null) { if (virtualChannelId == 63) { atf.setServiceType(ServiceType.IDLE); return atf; } throw new TcTmException("Received data for unknown VirtualChannel " + virtualChannelId); } dataOffset += aosParams.insertZoneLength; atf.setVcFrameSeq(ByteArrayUtils.decode3Bytes(data, offset + 2)); if (vmp.ocfPresent) { dataEnd -= 4; atf.setOcf(ByteArrayUtils.decodeInt(data, dataEnd)); } if (vmp.service == ServiceType.PACKET) { int fhp = ByteArrayUtils.decodeShort(data, dataOffset) & 0x7FF; dataOffset += 2; if (fhp == 0x7FF) { fhp = -1; } else { fhp += dataOffset; if (fhp > dataEnd) { throw new TcTmException("First header pointer in the M_PDU part of AOS frame is outside the data " + (fhp - dataOffset) + ">" + (dataEnd - dataOffset)); } } atf.setFirstHeaderPointer(fhp); } atf.setDataStart(dataOffset); atf.setDataEnd(dataEnd); return atf; } }
AosFrameDecoder implements TransferFrameDecoder { @Override public AosTransferFrame decode(byte[] data, int offset, int length) throws TcTmException { log.trace("decoding frame buf length: {}, dataOffset: {} , dataLength: {}", data.length, offset, length); int version = data[offset] >>6; if(version != 1) { throw new TcTmException("Bad frame version number " + version + "; expected 1 (AOS)"); } if (length != aosParams.frameLength) { throw new TcTmException("Bad frame length " + length + "; expected " + aosParams.frameLength); } int dataEnd = offset + length; if (crc != null) { dataEnd -= 2; int c1 = crc.compute(data, offset, dataEnd - offset); int c2 = ByteArrayUtils.decodeShort(data, dataEnd); if (c1 != c2) { throw new CorruptedFrameException("Bad CRC computed: " + c1 + " in the frame: " + c2); } } int gvcid; int dataOffset = offset + 6; if (aosParams.frameHeaderErrorControlPresent) { try { DecoderResult dr = AosFrameHeaderErrorCorr.decode(ByteArrayUtils.decodeShort(data, offset), data[offset + 5], ByteArrayUtils.decodeShort(data, offset + 6)); gvcid = dr.gvcid; } catch (ReedSolomonException e) { throw new CorruptedFrameException("Failed to Reed-Solomon verify/correct the AOS frame header fields"); } dataOffset += 2; } else { gvcid = ByteArrayUtils.decodeShort(data, offset); } int vn = gvcid >> 14; if (vn != 1) { throw new TcTmException("Invalid AOS frame version number " + vn + "; expected " + 1); } int spacecraftId = (gvcid >> 6)&0xFF; int virtualChannelId = gvcid & 0x3F; AosTransferFrame atf = new AosTransferFrame(data, spacecraftId, virtualChannelId); AosVcManagedParameters vmp = aosParams.vcParams.get(virtualChannelId); if (vmp == null) { if (virtualChannelId == 63) { atf.setServiceType(ServiceType.IDLE); return atf; } throw new TcTmException("Received data for unknown VirtualChannel " + virtualChannelId); } dataOffset += aosParams.insertZoneLength; atf.setVcFrameSeq(ByteArrayUtils.decode3Bytes(data, offset + 2)); if (vmp.ocfPresent) { dataEnd -= 4; atf.setOcf(ByteArrayUtils.decodeInt(data, dataEnd)); } if (vmp.service == ServiceType.PACKET) { int fhp = ByteArrayUtils.decodeShort(data, dataOffset) & 0x7FF; dataOffset += 2; if (fhp == 0x7FF) { fhp = -1; } else { fhp += dataOffset; if (fhp > dataEnd) { throw new TcTmException("First header pointer in the M_PDU part of AOS frame is outside the data " + (fhp - dataOffset) + ">" + (dataEnd - dataOffset)); } } atf.setFirstHeaderPointer(fhp); } atf.setDataStart(dataOffset); atf.setDataEnd(dataEnd); return atf; } AosFrameDecoder(AosManagedParameters aosParams); }
AosFrameDecoder implements TransferFrameDecoder { @Override public AosTransferFrame decode(byte[] data, int offset, int length) throws TcTmException { log.trace("decoding frame buf length: {}, dataOffset: {} , dataLength: {}", data.length, offset, length); int version = data[offset] >>6; if(version != 1) { throw new TcTmException("Bad frame version number " + version + "; expected 1 (AOS)"); } if (length != aosParams.frameLength) { throw new TcTmException("Bad frame length " + length + "; expected " + aosParams.frameLength); } int dataEnd = offset + length; if (crc != null) { dataEnd -= 2; int c1 = crc.compute(data, offset, dataEnd - offset); int c2 = ByteArrayUtils.decodeShort(data, dataEnd); if (c1 != c2) { throw new CorruptedFrameException("Bad CRC computed: " + c1 + " in the frame: " + c2); } } int gvcid; int dataOffset = offset + 6; if (aosParams.frameHeaderErrorControlPresent) { try { DecoderResult dr = AosFrameHeaderErrorCorr.decode(ByteArrayUtils.decodeShort(data, offset), data[offset + 5], ByteArrayUtils.decodeShort(data, offset + 6)); gvcid = dr.gvcid; } catch (ReedSolomonException e) { throw new CorruptedFrameException("Failed to Reed-Solomon verify/correct the AOS frame header fields"); } dataOffset += 2; } else { gvcid = ByteArrayUtils.decodeShort(data, offset); } int vn = gvcid >> 14; if (vn != 1) { throw new TcTmException("Invalid AOS frame version number " + vn + "; expected " + 1); } int spacecraftId = (gvcid >> 6)&0xFF; int virtualChannelId = gvcid & 0x3F; AosTransferFrame atf = new AosTransferFrame(data, spacecraftId, virtualChannelId); AosVcManagedParameters vmp = aosParams.vcParams.get(virtualChannelId); if (vmp == null) { if (virtualChannelId == 63) { atf.setServiceType(ServiceType.IDLE); return atf; } throw new TcTmException("Received data for unknown VirtualChannel " + virtualChannelId); } dataOffset += aosParams.insertZoneLength; atf.setVcFrameSeq(ByteArrayUtils.decode3Bytes(data, offset + 2)); if (vmp.ocfPresent) { dataEnd -= 4; atf.setOcf(ByteArrayUtils.decodeInt(data, dataEnd)); } if (vmp.service == ServiceType.PACKET) { int fhp = ByteArrayUtils.decodeShort(data, dataOffset) & 0x7FF; dataOffset += 2; if (fhp == 0x7FF) { fhp = -1; } else { fhp += dataOffset; if (fhp > dataEnd) { throw new TcTmException("First header pointer in the M_PDU part of AOS frame is outside the data " + (fhp - dataOffset) + ">" + (dataEnd - dataOffset)); } } atf.setFirstHeaderPointer(fhp); } atf.setDataStart(dataOffset); atf.setDataEnd(dataEnd); return atf; } AosFrameDecoder(AosManagedParameters aosParams); @Override AosTransferFrame decode(byte[] data, int offset, int length); }
AosFrameDecoder implements TransferFrameDecoder { @Override public AosTransferFrame decode(byte[] data, int offset, int length) throws TcTmException { log.trace("decoding frame buf length: {}, dataOffset: {} , dataLength: {}", data.length, offset, length); int version = data[offset] >>6; if(version != 1) { throw new TcTmException("Bad frame version number " + version + "; expected 1 (AOS)"); } if (length != aosParams.frameLength) { throw new TcTmException("Bad frame length " + length + "; expected " + aosParams.frameLength); } int dataEnd = offset + length; if (crc != null) { dataEnd -= 2; int c1 = crc.compute(data, offset, dataEnd - offset); int c2 = ByteArrayUtils.decodeShort(data, dataEnd); if (c1 != c2) { throw new CorruptedFrameException("Bad CRC computed: " + c1 + " in the frame: " + c2); } } int gvcid; int dataOffset = offset + 6; if (aosParams.frameHeaderErrorControlPresent) { try { DecoderResult dr = AosFrameHeaderErrorCorr.decode(ByteArrayUtils.decodeShort(data, offset), data[offset + 5], ByteArrayUtils.decodeShort(data, offset + 6)); gvcid = dr.gvcid; } catch (ReedSolomonException e) { throw new CorruptedFrameException("Failed to Reed-Solomon verify/correct the AOS frame header fields"); } dataOffset += 2; } else { gvcid = ByteArrayUtils.decodeShort(data, offset); } int vn = gvcid >> 14; if (vn != 1) { throw new TcTmException("Invalid AOS frame version number " + vn + "; expected " + 1); } int spacecraftId = (gvcid >> 6)&0xFF; int virtualChannelId = gvcid & 0x3F; AosTransferFrame atf = new AosTransferFrame(data, spacecraftId, virtualChannelId); AosVcManagedParameters vmp = aosParams.vcParams.get(virtualChannelId); if (vmp == null) { if (virtualChannelId == 63) { atf.setServiceType(ServiceType.IDLE); return atf; } throw new TcTmException("Received data for unknown VirtualChannel " + virtualChannelId); } dataOffset += aosParams.insertZoneLength; atf.setVcFrameSeq(ByteArrayUtils.decode3Bytes(data, offset + 2)); if (vmp.ocfPresent) { dataEnd -= 4; atf.setOcf(ByteArrayUtils.decodeInt(data, dataEnd)); } if (vmp.service == ServiceType.PACKET) { int fhp = ByteArrayUtils.decodeShort(data, dataOffset) & 0x7FF; dataOffset += 2; if (fhp == 0x7FF) { fhp = -1; } else { fhp += dataOffset; if (fhp > dataEnd) { throw new TcTmException("First header pointer in the M_PDU part of AOS frame is outside the data " + (fhp - dataOffset) + ">" + (dataEnd - dataOffset)); } } atf.setFirstHeaderPointer(fhp); } atf.setDataStart(dataOffset); atf.setDataEnd(dataEnd); return atf; } AosFrameDecoder(AosManagedParameters aosParams); @Override AosTransferFrame decode(byte[] data, int offset, int length);  }