datalogger demo example
Answer
2/7/18 7:56 AM
In the datalogger example, can I break the number of data units?

So if you read the csv file in Excel, the 2003 version can read up to 65,536 lines.
Or later, you can read up to 1,048,576 lines. When you saved the acceleration data in 2ms increments, you saved 64,277,156 in 17 hours.

I want to create a new file every 65536 rows or units so that Excel can read the csv file.

What part is it possible to transform?
0 (0 Votes)
RE: datalogger demo example
Answer
2/7/18 1:47 PM as a reply to jang.
Hello jang,

currently, the only trigger for creating a new file is pressing the first button. This will execute the following code:
 
if (BSP_XDK_BUTTON_RELEASED == data) {
BackBuffer->length = 0;
BackBuffer->data[0] = 0;
ActiveBuffer->length = 0;
ActiveBuffer->data[0] = 0;
newFile = 1;
addnewfile = 1;
closefile = 1;
buttoncount++;
sprintf(filename, config.filename, buttoncount);
}
In this code, the variables that tell the application to create a new file are closefile and newFile .
The first, closefile will tell the function SDC_writeBackBuffer() to create a new file, the next time it attempts to write to the SD card.

The second variable newfile tells the function UpdateSensorValues() to prepare a new header-line for the buffer (the header-line being the column names).

In the code-snippet, the last two lines tell the application the next filename. As such, when you automatically create a new file, you should also consider adding those two lines.

In general, how I would recommend to transform the code is to count how many lines have been written. Use a global variable, such as lineCount for that.

This variable should be incremented every time writeSensorDataCsv() and writeSensorDataCsvHeader() are called. On the other hand, this variable should be reset every time f_close(&fileObject); is called within SDC_writeBackBuffer() .

What you would want to do now is to see how many lines you have buffered so far, using lineCount . Once it exceeds a certain threshold, such as 64000, you set closefile = 1; and wait for the next write via f_printf() , which is also called within SDC_writeBackBuffer() . You can do a check for the current lineCount value at the end of the functions where you increment the value.

If the f_printf() is successful, you call the following code:

 
BackBuffer->length = 0;
BackBuffer->data[0] = 0;
ActiveBuffer->length = 0;
ActiveBuffer->data[0] = 0;
newFile = 1;
addnewfile = 1;
buttoncount++;
sprintf(filename, config.filename, buttoncount);
Given the right order of execution, this should work and split the files up successfully into files that contain at most 65536 rows.

Keep in mind that I do not guarantee that this will work, since I can not predict how you would implement it exactly, and I did not test this myself. The implementation is completely up to you.

As an alternative, there is always the possibility auf using a python script to split the files up on the computer. Presumably, this would also be easier.

Please tell me if this was helpful, and do not hesitate to ask further questions.

Kind regards,
Alex
0 (0 Votes)