first bugfixes

This commit is contained in:
rusefi 2020-07-19 20:47:58 -04:00
parent 8365e5719e
commit 35e69c1c99
1 changed files with 35 additions and 19 deletions

View File

@ -58,19 +58,11 @@ static void writeAs(int64_t value, int numBytes) {
} else {
writeByte(numBytes);
for (int i = 0; i < numBytes; i++) {
writeByte((uint8_t)((value >> (i * 8)) & 0xff));
writeByte((uint8_t) ((value >> (i * 8)) & 0xff));
}
}
}
static void writeString(const char *value) {
int len = strlen(value);
writeByte(len);
for (int i = 0; i < len; i++) {
writeByte(value[i]);
}
}
// This is the main secret of this format! :)
static void write(int64_t value) {
if (value < 0 || value > 0xFFFFFFFFL) {
@ -88,6 +80,14 @@ static void write(int64_t value) {
}
}
static void writeString(const char *value) {
int len = strlen(value);
write(len);
for (int i = 0; i < len; i++) {
writeByte(value[i]);
}
}
// todo: some C++ magic would allow us to drop 'count' parameter
// todo: Look at efi::size in util
static void write(int values[], int count) {
@ -138,16 +138,31 @@ static void writeHeader() {
}
static void writeDouble(double value) {
static_assert(sizeof(double) == 8);
if (value == 0.0) {
writeByte(0);
} else {
writeByte(8);
char *ptr = (char*) (void*) &value;
for (int i = 0; i < 8; i++) {
writeByte(ptr[i]);
}
}
}
static void writeChannelHeader(int ch) {
write(0xff);
write(ch);
writeString(channelNames[ch]);
write(0, 2);
write(1.0);
writeDouble(1.0);
write(0);
write(0.0);
writeDouble(0.0);
write(1); // or 2
write(0.0); // or 1.0
writeDouble(0.0); // or 1.0
// this part sounds like the 'next' pointer?
if (ch == numChannels - 1) {
@ -167,11 +182,11 @@ static void writeEdges(int64_t *chDeltas, bool useLongDeltas, int numEdges) {
// set 16-bit 'sign' flag
if (!useLongDeltas && (d & SIGN_FLAG) == SIGN_FLAG)
d = (d & 0x7fff) | (SIGN_FLAG >> 16);
writeByte((uint8_t)(d & 0xff));
writeByte((uint8_t)((d >> 8) & 0xff));
writeByte((uint8_t) (d & 0xff));
writeByte((uint8_t) ((d >> 8) & 0xff));
if (useLongDeltas) {
writeByte((uint8_t)((d >> 16) & 0xff));
writeByte((uint8_t)((d >> 24) & 0xff));
writeByte((uint8_t) ((d >> 16) & 0xff));
writeByte((uint8_t) ((d >> 24) & 0xff));
}
}
writeByte(0x00);
@ -197,6 +212,7 @@ static void writeChannelData(int ch, int64_t *chDeltas, int chLastState,
write(ch + 1);
write(0);
write(realDurationInSamples);
printf("realDurationInSamples=%d\n", realDurationInSamples);
write(1);
write(lastRecord);
@ -417,9 +433,9 @@ static void writeEvents(CompositeEvent *events, int count) {
prevTs = ts;
chPrevState = chState;
}
writeChannelData(ch, chDeltas, chPrevState, prevTs, useLongDeltas,
deltaCount);
}
writeChannelData(ch, chDeltas, chPrevState, prevTs, useLongDeltas,
deltaCount);
}
free(chDeltas);
@ -458,7 +474,7 @@ static void writeFooter() {
write(BLOCK);
write(0);
write(1.0);
writeDouble(1.0);
write(SUB);
write(0, 6);
write(1);