Part Number:MSP432P401R
Hi Team,
I am working on an application where I have to write the data captured from a pulser to SD card.
The data format includes header (26 bytes) followed by data itself.
I am using the FatFs library to write it.
The data that I am getting is uint8_t type.
The format of the header is as below:
Version: | 4 digits | 4 Bytes |
Payload Size: | 0-65535 | 2 Bytes |
HW Version: | 4 digits | 4 Bytes |
Time Code: | 4 digits | 4 Bytes |
Vector ID: | 0-65535 | 2 Bytes |
Up Vector Length: | 0-65535 | 2 Bytes |
Up Sample Freq: | 0-16777215 | 3 Bytes |
Dn Vector Length: | 0-65535 | 2 Bytes |
Dn Sample Freq: | 0-16777215 | 3 Bytes |
Up Vector Data | 4096 bytes | Up Vector Length Bytes |
Dn Vector Data | 6656 | Down Vector Length Bytes |
The overall file size needs to be around 10 KB based on above table.
However, the size spikes up to around 14 - 15 KB.
Providing example as below:
Version: | 1,9,1,0 | 4 Bytes |
Payload Size: | 10754 | 2 Bytes |
HW Version: | 2,2,0,0 | 4 Bytes |
Time Code: | 0x5C40E21C | 4 Bytes |
Vector ID: | 1 | 2 Bytes |
Up Vector Length: | 4097 | 2 Bytes |
Up Sample Freq: | 8333333 | 3 Bytes |
Dn Vector Length: | 6657 | 2 Bytes |
Dn Sample Freq: | 8333333 | 3 Bytes |
Up Vector Data | Data | Up Vector Length Bytes |
Dn Vector Data | Data | Down Vector Length Bytes |
Below is the line of code that I have written for that:
Option 1:
f_lseek(&fFile, totalshotBytesWritten);
logshotbytesWritten = f_printf(&fFile, "%d%d%d%d",1,9,1,0);
totalshotBytesWritten += logshotbytesWritten;
f_lseek(&fFile, totalshotBytesWritten);
logshotbytesWritten = f_printf(&fFile, "%d", ((uint16_t)(upvector_length + downvector_length)));
totalshotBytesWritten += logshotbytesWritten;
f_lseek(&fFile, totalshotBytesWritten);
logshotbytesWritten = f_printf(&fFile, "%d%d%d%d", 2,2,0,0);
totalshotBytesWritten += logshotbytesWritten;
f_lseek(&fFile, totalshotBytesWritten);
logshotbytesWritten = f_printf(&fFile, "%d", (uint16_t)v->vectorID);
totalshotBytesWritten += logshotbytesWritten;
f_lseek(&fFile, totalshotBytesWritten);
logshotbytesWritten = f_printf(&fFile, "%d", (uint16_t)upvector_length);
totalshotBytesWritten += logshotbytesWritten;
f_lseek(&fFile, totalshotBytesWritten);
logshotbytesWritten = f_printf(&fFile, "%d", v->frequency);
totalshotBytesWritten += logshotbytesWritten;
f_lseek(&fFile, totalshotBytesWritten);
logshotbytesWritten = f_printf(&fFile, "%d", (uint16_t)downvector_length);
totalshotBytesWritten += logshotbytesWritten;
f_lseek(&fFile, totalshotBytesWritten);
logshotbytesWritten = f_printf(&fFile, "%d", v->frequency);
totalshotBytesWritten += logshotbytesWritten;
// for each slice in the slice vector
for (j = 0; j < v->sv.length; j++) {
scaleFactor = (127 - v->sv.slice[j].attenuation) * dBGainScale;
scaleFactor = powf(10.0, scaleFactor/20.0);
// from the slice start to the slice stop vector indexes
for (ipMSV = v->sv.slice[j].attenuationStartIndex;
ipMSV <= v->sv.slice[j].attenuationStopIndex;
ipMSV++) {
// scale the output data
output = ((float)v->data[ipMSV] - 127.0) * scaleFactor;
// update the checksum
checksum += (uint16_t)output;
// convert the int16 value to hex chars
f_lseek(&fFile, totalshotBytesWritten);
logshotbytesWritten = f_printf(&fFile, "%d", (uint8_t)output);
totalshotBytesWritten += logshotbytesWritten;
// reached max values per line, or this is the end of the vector
if (((ipMSV+1) % config.pixelsPerLine == 0)
|| (ipMSV == v->length-1)) {
// appened a terminator and newline to the print buffer
// strcat(consolePrintBuffer, ";\n");
// reset the print buffer
consolePrintBuffer[0] = '\0';
}
}
Option 2:
consolePrintBuffer[index++] = (uint8_t)1;
consolePrintBuffer[index++] = (uint8_t)9;
consolePrintBuffer[index++] = (uint8_t)1;
consolePrintBuffer[index++] = (uint8_t)0;
consolePrintBuffer[index++] = (uint8_t)((upvector_length + downvector_length) >> 8);
consolePrintBuffer[index++] = (uint8_t)(upvector_length + downvector_length);
consolePrintBuffer[index++] = (uint8_t)2;
consolePrintBuffer[index++] = (uint8_t)2;
consolePrintBuffer[index++] = (uint8_t)0;
consolePrintBuffer[index++] = (uint8_t)0;
consolePrintBuffer[index++] = (uint8_t)((0x5C40E21C) >> 24);
consolePrintBuffer[index++] = (uint8_t)((0x5C40E21C) >> 16);
consolePrintBuffer[index++] = (uint8_t)((0x5C40E21C) >> 8);
consolePrintBuffer[index++] = (uint8_t)(0x5C40E21C);
consolePrintBuffer[index++] = (uint8_t)((v->vectorID) >> 8);
consolePrintBuffer[index++] = (uint8_t)(v->vectorID);
consolePrintBuffer[index++] = (uint8_t)(upvector_length >> 8);
consolePrintBuffer[index++] = (uint8_t)(upvector_length);
consolePrintBuffer[index++] = (uint8_t)((v->frequency) >> 16);
consolePrintBuffer[index++] = (uint8_t)((v->frequency) >> 8);
consolePrintBuffer[index++] = (uint8_t)(v->frequency);
consolePrintBuffer[index++] = (uint8_t)(downvector_length >> 8);
consolePrintBuffer[index++] = (uint8_t)(downvector_length);
consolePrintBuffer[index++] = (uint8_t)((v->frequency) >> 16);
consolePrintBuffer[index++] = (uint8_t)((v->frequency) >> 8);
consolePrintBuffer[index++] = (uint8_t)(v->frequency);
f_lseek(&fFile, totalshotBytesWritten);
logshotbytesWritten = f_printf(&fFile, "%x", consolePrintBuffer);
totalshotBytesWritten += logshotbytesWritten;
// for each slice in the slice vector
for (j = 0; j < v->sv.length; j++) {
scaleFactor = (127 - v->sv.slice[j].attenuation) * dBGainScale;
scaleFactor = powf(10.0, scaleFactor/20.0);
// from the slice start to the slice stop vector indexes
for (ipMSV = v->sv.slice[j].attenuationStartIndex;
ipMSV <= v->sv.slice[j].attenuationStopIndex;
ipMSV++) {
// scale the output data
output = ((float)v->data[ipMSV] - 127.0) * scaleFactor;
// update the checksum
checksum += (uint16_t)output;
// convert the int16 value to hex chars
f_lseek(&fFile, totalshotBytesWritten);
logshotbytesWritten = f_printf(&fFile, "%x", (uint8_t)output);
totalshotBytesWritten += logshotbytesWritten;
// reached max values per line, or this is the end of the vector
if (((ipMSV+1) % config.pixelsPerLine == 0)
|| (ipMSV == v->length-1)) {
// appened a terminator and newline to the print buffer
// strcat(consolePrintBuffer, ";\n");
// reset the print buffer
consolePrintBuffer[0] = '\0';
}
}
In option 1 the header size instead of 26 bytes becomes 39 bytes and rest of the data size also gets increased rather than 10754 become around 14KB
In option 2 I get the ascii equivalent printed in the file rather than the actual number.
I am really confused as to whether is it actually possible to write decimal number in the file or not or it just gets written as ascii value.
Hope to receive some help.