@Test public void testRawCcsdsReader() throws InterruptedException, IOException { TmFileReader tfr=new TmFileReader("src/test/resources/TmFileReaderTest-rawccsds", new IssPacketPreprocessor(null)); TmPacket pwrt=tfr.readPacket(TimeEncoding.getWallclockTime()); assertNotNull(pwrt); ByteBuffer bb = ByteBuffer.wrap(pwrt.getPacket()); assertEquals(148, bb.capacity()); assertEquals(0x1be5d9a0, bb.getInt(0)); pwrt=tfr.readPacket(TimeEncoding.getWallclockTime()); assertNotNull(pwrt); bb = ByteBuffer.wrap(pwrt.getPacket()); assertEquals(528, bb.capacity()); assertEquals(0x1bdff44c, bb.getInt(0)); assertEquals(0x1, bb.getInt(520)); pwrt=tfr.readPacket(TimeEncoding.getWallclockTime()); assertNull(pwrt); }
public TmPacket readPacket(long rectime) throws IOException { int res; byte[] buffer; byte[] fourb = new byte[4]; res = inputStream.read(fourb); if (res == -1) { inputStream.close(); return null; } else if (res != 4) { System.err.println("fourb: " + StringConverter.arrayToHexString(fourb)); inputStream.close(); throw new IOException("Could only read " + res + " out of 4 bytes. Corrupted file?"); } byte[] ccsdshdr = new byte[16]; int ccsdshdroffset = 0; boolean isPacts = false; if ((fourb[2] == 0) && (fourb[3] == 0)) { byte[] b = new byte[6]; res = inputStream.read(b); if (res != 6) { inputStream.close(); throw new IOException("Could only read " + res + " out of 6 bytes. Corrupted file?"); } else { ByteBuffer bb = ByteBuffer.wrap(b); long unixTimesec = (0xFFFFFFFFL & (long) bb.getInt(1)) + 315964800L; int unixTimeMicrosec = (bb.get() & 0xFF) * (1000000 / 256); rectime = TimeEncoding.fromUnixTime(unixTimesec, unixTimeMicrosec); } } else if ((fourb[0] & 0xe8) == 0x08) { System.arraycopy(fourb, 0, ccsdshdr, 0, 4); ccsdshdroffset = 4; } else { isPacts = true; int i, j; StringBuilder hdr = new StringBuilder(); j = 0; for (i = 0; i < 4; i++) { hdr.append((char) fourb[i]); if (fourb[i] == 32) { ++j; } } while ((j < 2) && (i < 20)) { int c = inputStream.read(); if (c == -1) { inputStream.close(); throw new IOException("short PaCTS ASCII header: '" + hdr.toString() + "'"); } hdr.append((char) c); if (c == 32) { ++j; } i++; } if (i == 20) { inputStream.close(); throw new IOException( "ASCII header too long, probably not a PaCTS archive file: '" + hdr.toString() + "'"); } } res = inputStream.read(ccsdshdr, ccsdshdroffset, 16 - ccsdshdroffset); if (res != 16 - ccsdshdroffset) { inputStream.close(); throw new IOException("CCSDS packet header short read " + res + "/16-ccsdshdroffset"); } int len = ((ccsdshdr[4] & 0xff) << 8) + (ccsdshdr[5] & 0xff) + 7; if ((len < 16) || len > CcsdsPacket.MAX_CCSDS_SIZE) { inputStream.close(); throw new IOException("invalid ccsds packet of length " + len + ". Corrupted file?"); } buffer = Arrays.copyOf(ccsdshdr, len); res = inputStream.read(buffer, 16, len - 16); if (res != len - 16) { inputStream.close(); throw new IOException("CCSDS packet body short read " + res + "/" + (len - 16)); } if (isPacts) { if (inputStream.skip(1) != 1) { inputStream.close(); throw new IOException("no new line at the end of the PaCTS packet"); } } return packetPreprocessor.process(new TmPacket(TimeEncoding.getWallclockTime(), buffer)); }
TmFileReader { public TmPacket readPacket(long rectime) throws IOException { int res; byte[] buffer; byte[] fourb = new byte[4]; res = inputStream.read(fourb); if (res == -1) { inputStream.close(); return null; } else if (res != 4) { System.err.println("fourb: " + StringConverter.arrayToHexString(fourb)); inputStream.close(); throw new IOException("Could only read " + res + " out of 4 bytes. Corrupted file?"); } byte[] ccsdshdr = new byte[16]; int ccsdshdroffset = 0; boolean isPacts = false; if ((fourb[2] == 0) && (fourb[3] == 0)) { byte[] b = new byte[6]; res = inputStream.read(b); if (res != 6) { inputStream.close(); throw new IOException("Could only read " + res + " out of 6 bytes. Corrupted file?"); } else { ByteBuffer bb = ByteBuffer.wrap(b); long unixTimesec = (0xFFFFFFFFL & (long) bb.getInt(1)) + 315964800L; int unixTimeMicrosec = (bb.get() & 0xFF) * (1000000 / 256); rectime = TimeEncoding.fromUnixTime(unixTimesec, unixTimeMicrosec); } } else if ((fourb[0] & 0xe8) == 0x08) { System.arraycopy(fourb, 0, ccsdshdr, 0, 4); ccsdshdroffset = 4; } else { isPacts = true; int i, j; StringBuilder hdr = new StringBuilder(); j = 0; for (i = 0; i < 4; i++) { hdr.append((char) fourb[i]); if (fourb[i] == 32) { ++j; } } while ((j < 2) && (i < 20)) { int c = inputStream.read(); if (c == -1) { inputStream.close(); throw new IOException("short PaCTS ASCII header: '" + hdr.toString() + "'"); } hdr.append((char) c); if (c == 32) { ++j; } i++; } if (i == 20) { inputStream.close(); throw new IOException( "ASCII header too long, probably not a PaCTS archive file: '" + hdr.toString() + "'"); } } res = inputStream.read(ccsdshdr, ccsdshdroffset, 16 - ccsdshdroffset); if (res != 16 - ccsdshdroffset) { inputStream.close(); throw new IOException("CCSDS packet header short read " + res + "/16-ccsdshdroffset"); } int len = ((ccsdshdr[4] & 0xff) << 8) + (ccsdshdr[5] & 0xff) + 7; if ((len < 16) || len > CcsdsPacket.MAX_CCSDS_SIZE) { inputStream.close(); throw new IOException("invalid ccsds packet of length " + len + ". Corrupted file?"); } buffer = Arrays.copyOf(ccsdshdr, len); res = inputStream.read(buffer, 16, len - 16); if (res != len - 16) { inputStream.close(); throw new IOException("CCSDS packet body short read " + res + "/" + (len - 16)); } if (isPacts) { if (inputStream.skip(1) != 1) { inputStream.close(); throw new IOException("no new line at the end of the PaCTS packet"); } } return packetPreprocessor.process(new TmPacket(TimeEncoding.getWallclockTime(), buffer)); } }
TmFileReader { public TmPacket readPacket(long rectime) throws IOException { int res; byte[] buffer; byte[] fourb = new byte[4]; res = inputStream.read(fourb); if (res == -1) { inputStream.close(); return null; } else if (res != 4) { System.err.println("fourb: " + StringConverter.arrayToHexString(fourb)); inputStream.close(); throw new IOException("Could only read " + res + " out of 4 bytes. Corrupted file?"); } byte[] ccsdshdr = new byte[16]; int ccsdshdroffset = 0; boolean isPacts = false; if ((fourb[2] == 0) && (fourb[3] == 0)) { byte[] b = new byte[6]; res = inputStream.read(b); if (res != 6) { inputStream.close(); throw new IOException("Could only read " + res + " out of 6 bytes. Corrupted file?"); } else { ByteBuffer bb = ByteBuffer.wrap(b); long unixTimesec = (0xFFFFFFFFL & (long) bb.getInt(1)) + 315964800L; int unixTimeMicrosec = (bb.get() & 0xFF) * (1000000 / 256); rectime = TimeEncoding.fromUnixTime(unixTimesec, unixTimeMicrosec); } } else if ((fourb[0] & 0xe8) == 0x08) { System.arraycopy(fourb, 0, ccsdshdr, 0, 4); ccsdshdroffset = 4; } else { isPacts = true; int i, j; StringBuilder hdr = new StringBuilder(); j = 0; for (i = 0; i < 4; i++) { hdr.append((char) fourb[i]); if (fourb[i] == 32) { ++j; } } while ((j < 2) && (i < 20)) { int c = inputStream.read(); if (c == -1) { inputStream.close(); throw new IOException("short PaCTS ASCII header: '" + hdr.toString() + "'"); } hdr.append((char) c); if (c == 32) { ++j; } i++; } if (i == 20) { inputStream.close(); throw new IOException( "ASCII header too long, probably not a PaCTS archive file: '" + hdr.toString() + "'"); } } res = inputStream.read(ccsdshdr, ccsdshdroffset, 16 - ccsdshdroffset); if (res != 16 - ccsdshdroffset) { inputStream.close(); throw new IOException("CCSDS packet header short read " + res + "/16-ccsdshdroffset"); } int len = ((ccsdshdr[4] & 0xff) << 8) + (ccsdshdr[5] & 0xff) + 7; if ((len < 16) || len > CcsdsPacket.MAX_CCSDS_SIZE) { inputStream.close(); throw new IOException("invalid ccsds packet of length " + len + ". Corrupted file?"); } buffer = Arrays.copyOf(ccsdshdr, len); res = inputStream.read(buffer, 16, len - 16); if (res != len - 16) { inputStream.close(); throw new IOException("CCSDS packet body short read " + res + "/" + (len - 16)); } if (isPacts) { if (inputStream.skip(1) != 1) { inputStream.close(); throw new IOException("no new line at the end of the PaCTS packet"); } } return packetPreprocessor.process(new TmPacket(TimeEncoding.getWallclockTime(), buffer)); } TmFileReader(String fileName, PacketPreprocessor packetPreprocessor); }
TmFileReader { public TmPacket readPacket(long rectime) throws IOException { int res; byte[] buffer; byte[] fourb = new byte[4]; res = inputStream.read(fourb); if (res == -1) { inputStream.close(); return null; } else if (res != 4) { System.err.println("fourb: " + StringConverter.arrayToHexString(fourb)); inputStream.close(); throw new IOException("Could only read " + res + " out of 4 bytes. Corrupted file?"); } byte[] ccsdshdr = new byte[16]; int ccsdshdroffset = 0; boolean isPacts = false; if ((fourb[2] == 0) && (fourb[3] == 0)) { byte[] b = new byte[6]; res = inputStream.read(b); if (res != 6) { inputStream.close(); throw new IOException("Could only read " + res + " out of 6 bytes. Corrupted file?"); } else { ByteBuffer bb = ByteBuffer.wrap(b); long unixTimesec = (0xFFFFFFFFL & (long) bb.getInt(1)) + 315964800L; int unixTimeMicrosec = (bb.get() & 0xFF) * (1000000 / 256); rectime = TimeEncoding.fromUnixTime(unixTimesec, unixTimeMicrosec); } } else if ((fourb[0] & 0xe8) == 0x08) { System.arraycopy(fourb, 0, ccsdshdr, 0, 4); ccsdshdroffset = 4; } else { isPacts = true; int i, j; StringBuilder hdr = new StringBuilder(); j = 0; for (i = 0; i < 4; i++) { hdr.append((char) fourb[i]); if (fourb[i] == 32) { ++j; } } while ((j < 2) && (i < 20)) { int c = inputStream.read(); if (c == -1) { inputStream.close(); throw new IOException("short PaCTS ASCII header: '" + hdr.toString() + "'"); } hdr.append((char) c); if (c == 32) { ++j; } i++; } if (i == 20) { inputStream.close(); throw new IOException( "ASCII header too long, probably not a PaCTS archive file: '" + hdr.toString() + "'"); } } res = inputStream.read(ccsdshdr, ccsdshdroffset, 16 - ccsdshdroffset); if (res != 16 - ccsdshdroffset) { inputStream.close(); throw new IOException("CCSDS packet header short read " + res + "/16-ccsdshdroffset"); } int len = ((ccsdshdr[4] & 0xff) << 8) + (ccsdshdr[5] & 0xff) + 7; if ((len < 16) || len > CcsdsPacket.MAX_CCSDS_SIZE) { inputStream.close(); throw new IOException("invalid ccsds packet of length " + len + ". Corrupted file?"); } buffer = Arrays.copyOf(ccsdshdr, len); res = inputStream.read(buffer, 16, len - 16); if (res != len - 16) { inputStream.close(); throw new IOException("CCSDS packet body short read " + res + "/" + (len - 16)); } if (isPacts) { if (inputStream.skip(1) != 1) { inputStream.close(); throw new IOException("no new line at the end of the PaCTS packet"); } } return packetPreprocessor.process(new TmPacket(TimeEncoding.getWallclockTime(), buffer)); } TmFileReader(String fileName, PacketPreprocessor packetPreprocessor); TmPacket readPacket(long rectime); void close(); }
TmFileReader { public TmPacket readPacket(long rectime) throws IOException { int res; byte[] buffer; byte[] fourb = new byte[4]; res = inputStream.read(fourb); if (res == -1) { inputStream.close(); return null; } else if (res != 4) { System.err.println("fourb: " + StringConverter.arrayToHexString(fourb)); inputStream.close(); throw new IOException("Could only read " + res + " out of 4 bytes. Corrupted file?"); } byte[] ccsdshdr = new byte[16]; int ccsdshdroffset = 0; boolean isPacts = false; if ((fourb[2] == 0) && (fourb[3] == 0)) { byte[] b = new byte[6]; res = inputStream.read(b); if (res != 6) { inputStream.close(); throw new IOException("Could only read " + res + " out of 6 bytes. Corrupted file?"); } else { ByteBuffer bb = ByteBuffer.wrap(b); long unixTimesec = (0xFFFFFFFFL & (long) bb.getInt(1)) + 315964800L; int unixTimeMicrosec = (bb.get() & 0xFF) * (1000000 / 256); rectime = TimeEncoding.fromUnixTime(unixTimesec, unixTimeMicrosec); } } else if ((fourb[0] & 0xe8) == 0x08) { System.arraycopy(fourb, 0, ccsdshdr, 0, 4); ccsdshdroffset = 4; } else { isPacts = true; int i, j; StringBuilder hdr = new StringBuilder(); j = 0; for (i = 0; i < 4; i++) { hdr.append((char) fourb[i]); if (fourb[i] == 32) { ++j; } } while ((j < 2) && (i < 20)) { int c = inputStream.read(); if (c == -1) { inputStream.close(); throw new IOException("short PaCTS ASCII header: '" + hdr.toString() + "'"); } hdr.append((char) c); if (c == 32) { ++j; } i++; } if (i == 20) { inputStream.close(); throw new IOException( "ASCII header too long, probably not a PaCTS archive file: '" + hdr.toString() + "'"); } } res = inputStream.read(ccsdshdr, ccsdshdroffset, 16 - ccsdshdroffset); if (res != 16 - ccsdshdroffset) { inputStream.close(); throw new IOException("CCSDS packet header short read " + res + "/16-ccsdshdroffset"); } int len = ((ccsdshdr[4] & 0xff) << 8) + (ccsdshdr[5] & 0xff) + 7; if ((len < 16) || len > CcsdsPacket.MAX_CCSDS_SIZE) { inputStream.close(); throw new IOException("invalid ccsds packet of length " + len + ". Corrupted file?"); } buffer = Arrays.copyOf(ccsdshdr, len); res = inputStream.read(buffer, 16, len - 16); if (res != len - 16) { inputStream.close(); throw new IOException("CCSDS packet body short read " + res + "/" + (len - 16)); } if (isPacts) { if (inputStream.skip(1) != 1) { inputStream.close(); throw new IOException("no new line at the end of the PaCTS packet"); } } return packetPreprocessor.process(new TmPacket(TimeEncoding.getWallclockTime(), buffer)); } TmFileReader(String fileName, PacketPreprocessor packetPreprocessor); TmPacket readPacket(long rectime); void close();  }