.logicdata files are a bit broken #1482
This commit is contained in:
parent
d89f9b5165
commit
9fb76630c4
|
@ -27,7 +27,7 @@ public class LogicdataStreamFile extends StreamFile {
|
||||||
|
|
||||||
private static final int FLAG_NOTEMPTY = 2;
|
private static final int FLAG_NOTEMPTY = 2;
|
||||||
private static final int FLAG_EMPTY = 5;
|
private static final int FLAG_EMPTY = 5;
|
||||||
|
|
||||||
private static final int LOGIC4 = 0x40FD;
|
private static final int LOGIC4 = 0x40FD;
|
||||||
private static final int LOGIC8 = 0x673B;
|
private static final int LOGIC8 = 0x673B;
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ public class LogicdataStreamFile extends StreamFile {
|
||||||
|
|
||||||
// we need to split the combined events into separate channels
|
// we need to split the combined events into separate channels
|
||||||
for (int ch = 0; ch < numChannels; ch++) {
|
for (int ch = 0; ch < numChannels; ch++) {
|
||||||
List<Integer> chDeltas = new ArrayList<Integer>();
|
List<Integer> chDeltas = new ArrayList<>();
|
||||||
int chPrevState = -1;
|
int chPrevState = -1;
|
||||||
int prevTs = 0;
|
int prevTs = 0;
|
||||||
for (CompositeEvent event : events) {
|
for (CompositeEvent event : events) {
|
||||||
|
@ -100,14 +100,14 @@ public class LogicdataStreamFile extends StreamFile {
|
||||||
// encode state
|
// encode state
|
||||||
if (chState == 0)
|
if (chState == 0)
|
||||||
delta |= 0x8000;
|
delta |= 0x8000;
|
||||||
|
|
||||||
chDeltas.add(delta);
|
chDeltas.add(delta);
|
||||||
|
|
||||||
prevTs = ts;
|
prevTs = ts;
|
||||||
chPrevState = chState;
|
chPrevState = chState;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
writeChannelData(ch, chDeltas, chPrevState, prevTs);
|
writeChannelData(ch, chDeltas, chPrevState, prevTs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,7 +137,7 @@ public class LogicdataStreamFile extends StreamFile {
|
||||||
|
|
||||||
private void writeHeader() throws IOException {
|
private void writeHeader() throws IOException {
|
||||||
stream.write(magic);
|
stream.write(magic);
|
||||||
|
|
||||||
write(title.length());
|
write(title.length());
|
||||||
write(title);
|
write(title);
|
||||||
stream.flush();
|
stream.flush();
|
||||||
|
@ -161,7 +161,7 @@ public class LogicdataStreamFile extends StreamFile {
|
||||||
write(0);
|
write(0);
|
||||||
|
|
||||||
write(BLOCK);
|
write(BLOCK);
|
||||||
|
|
||||||
int4or5 = (numChannels == 4) ? 4 : 5;
|
int4or5 = (numChannels == 4) ? 4 : 5;
|
||||||
writeId(int4or5, int4or5);
|
writeId(int4or5, int4or5);
|
||||||
write(SUB);
|
write(SUB);
|
||||||
|
@ -245,7 +245,7 @@ public class LogicdataStreamFile extends StreamFile {
|
||||||
writeId(0, 0);
|
writeId(0, 0);
|
||||||
write(new int[]{ 0, 1, 1, 0, 1, 0x13 });
|
write(new int[]{ 0, 1, 1, 0, 1, 0x13 });
|
||||||
write(SUB);
|
write(SUB);
|
||||||
|
|
||||||
write(BLOCK);
|
write(BLOCK);
|
||||||
write(0);
|
write(0);
|
||||||
write(realDurationInSamples);
|
write(realDurationInSamples);
|
||||||
|
@ -265,16 +265,16 @@ public class LogicdataStreamFile extends StreamFile {
|
||||||
write(SUB);
|
write(SUB);
|
||||||
write(BLOCK);
|
write(BLOCK);
|
||||||
}
|
}
|
||||||
|
|
||||||
write(ch + 1);
|
write(ch + 1);
|
||||||
write(0);
|
write(0);
|
||||||
write(realDurationInSamples);
|
write(realDurationInSamples);
|
||||||
write(1);
|
write(1);
|
||||||
writeAs(lastRecord, 2);
|
writeAs(lastRecord, 2);
|
||||||
|
|
||||||
int numSamplesLeft = realDurationInSamples - lastRecord;
|
int numSamplesLeft = realDurationInSamples - lastRecord;
|
||||||
write(numSamplesLeft);
|
write(numSamplesLeft);
|
||||||
|
|
||||||
write(chLastState);
|
write(chLastState);
|
||||||
|
|
||||||
if (numEdges == 0) { // empty
|
if (numEdges == 0) { // empty
|
||||||
|
@ -282,7 +282,7 @@ public class LogicdataStreamFile extends StreamFile {
|
||||||
write(0, 30);
|
write(0, 30);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
write(FLAG_NOTEMPTY);
|
write(FLAG_NOTEMPTY);
|
||||||
|
|
||||||
if (ch == 0) {
|
if (ch == 0) {
|
||||||
|
@ -293,7 +293,7 @@ public class LogicdataStreamFile extends StreamFile {
|
||||||
} else {
|
} else {
|
||||||
write(0, 10);
|
write(0, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
write(numEdges);
|
write(numEdges);
|
||||||
write(0);
|
write(0);
|
||||||
write(numEdges);
|
write(numEdges);
|
||||||
|
@ -342,7 +342,8 @@ public class LogicdataStreamFile extends StreamFile {
|
||||||
write(numChannels);
|
write(numChannels);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void writeFooter() throws IOException {
|
@Override
|
||||||
|
protected void writeFooter() throws IOException {
|
||||||
write(BLOCK);
|
write(BLOCK);
|
||||||
for (int i = 0; i < numChannels; i++) {
|
for (int i = 0; i < numChannels; i++) {
|
||||||
writeId(i, 1);
|
writeId(i, 1);
|
||||||
|
@ -386,6 +387,7 @@ public class LogicdataStreamFile extends StreamFile {
|
||||||
writeTimingMarker();
|
writeTimingMarker();
|
||||||
|
|
||||||
stream.flush();
|
stream.flush();
|
||||||
|
System.out.println("writeFooter " + fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeTimingMarker() throws IOException {
|
private void writeTimingMarker() throws IOException {
|
||||||
|
@ -413,10 +415,10 @@ public class LogicdataStreamFile extends StreamFile {
|
||||||
write(value);
|
write(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void write(int [] values) throws IOException {
|
private void write(int[] values) throws IOException {
|
||||||
for (int i = 0; i < values.length; i++)
|
for (int value : values)
|
||||||
write(values[i]);
|
write(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeAs(long value, int numBytes) throws IOException {
|
private void writeAs(long value, int numBytes) throws IOException {
|
||||||
if (value == 0) {
|
if (value == 0) {
|
||||||
|
@ -445,14 +447,14 @@ public class LogicdataStreamFile extends StreamFile {
|
||||||
writeAs(value, 4);
|
writeAs(value, 4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void write(double value) throws IOException {
|
private void write(double value) throws IOException {
|
||||||
if (value == 0.0) {
|
if (value == 0.0) {
|
||||||
stream.write(0);
|
stream.write(0);
|
||||||
} else {
|
} else {
|
||||||
stream.write(8);
|
stream.write(8);
|
||||||
// doubles are saved little-endian, sorry Java :)
|
// doubles are saved little-endian, sorry Java :)
|
||||||
ByteBuffer bb = ByteBuffer.allocate(8);
|
ByteBuffer bb = ByteBuffer.allocate(8);
|
||||||
bb.order(ByteOrder.LITTLE_ENDIAN);
|
bb.order(ByteOrder.LITTLE_ENDIAN);
|
||||||
bb.putDouble(value);
|
bb.putDouble(value);
|
||||||
bb.rewind();
|
bb.rewind();
|
||||||
|
|
|
@ -21,9 +21,13 @@ public abstract class StreamFile {
|
||||||
public abstract void append(List<CompositeEvent> events);
|
public abstract void append(List<CompositeEvent> events);
|
||||||
|
|
||||||
public synchronized void close() {
|
public synchronized void close() {
|
||||||
|
try {
|
||||||
|
writeFooter();
|
||||||
|
} catch (IOException e) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (writer != null) {
|
if (writer != null) {
|
||||||
try {
|
try {
|
||||||
writeFooter(writer);
|
|
||||||
writer.close();
|
writer.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// ignoring this one
|
// ignoring this one
|
||||||
|
@ -44,6 +48,6 @@ public abstract class StreamFile {
|
||||||
writer = new OutputStreamWriter(stream);
|
writer = new OutputStreamWriter(stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void writeFooter(Writer writer) throws IOException {
|
protected void writeFooter() throws IOException {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ public class TSHighSpeedLog extends StreamFile {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void writeFooter(Writer writer) throws IOException {
|
protected void writeFooter() throws IOException {
|
||||||
writer.write("MARK 028\n");
|
writer.write("MARK 028\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue