I would like to convert on my PC
because of the speed of conversion. But I have some difficulties to read the data
#include <iostream>
#include <time.h>
#include <sys/time.h>
#include <stdio.h>
using namespace std;
#define millis() tp.tv_sec * 1000 + tp.tv_usec / 1000;
const uint8_t ADC_DIM = 10;
struct data_t
{
unsigned long time;
int16_t adc[10];
};
const uint8_t BUFFER_BLOCK_COUNT = 12;
const uint16_t DATA_DIM = (512 - 4) / sizeof(data_t);
const uint16_t FILL_DIM = 512 - 4 - DATA_DIM * sizeof(data_t);
const uint8_t QUEUE_DIM = BUFFER_BLOCK_COUNT + 2;
struct block_t
{
uint16_t count;
uint16_t overrun;
data_t data[DATA_DIM];
uint8_t fill[FILL_DIM];
};
block_t* emptyQueue[QUEUE_DIM];
uint8_t emptyHead;
uint8_t emptyTail;
block_t* fullQueue[QUEUE_DIM];
uint8_t fullHead;
uint8_t fullTail;
inline uint8_t queueNext(uint8_t ht)
{
return ht < (QUEUE_DIM - 1) ? ht + 1 : 0;
}
int main()
{
struct timeval tp;
gettimeofday(&tp, NULL);
uint8_t lastPct = 0;
block_t block;
uint32_t t0 = millis();
uint32_t syncCluster = 0;
FILE* biFile = NULL;
biFile = fopen("data01.bin", "r");
if (biFile != NULL)
{
}
else
{
printf("Impossible d'ouvrir le fichier data03.bin");
}
FILE* csvFile = NULL;
char csvName[13];
csvFile = fopen("data0X.csv", "w");
if (csvFile != NULL)
{
}
else
{
printf("Impossible d'ouvrir le fichier data03.bin");
}
unsigned long time[512];
int i = 0;
unsigned int k = 0;
do
{
cout<<"SEEK_CUR before readings "<<SEEK_CUR<<endl;
int resread = fread(&block,1,512,biFile);
fseek(biFile,512*k,SEEK_SET);
cout<<"SEEK_CUR after readings "<<SEEK_CUR<<endl;
cout<<"resread is "<<resread<<endl;
cout<<"arbitrary readings:"<<endl;
cout<<"Count"<<block.count<<endl;
cout<<"time "<<":"<<block.data->time<<endl;
time[k] = block.data->time;
for(int z = 0; z<21; z++)
{
cout<<block.data[z].time<<", ";
fprintf (csvFile, "%lu, ",block.data[z].time);
for(int j = 0; j<ADC_DIM; j++)
{
cout<<block.data[z].adc[j]<<", ";
fprintf (csvFile, "%d, ",block.data[z].adc[j]);
}
cout<<"0"<<endl;
fprintf (csvFile, "%d\n",0);
}
cout<<"fill"<<block.fill<<endl;
cout<<"overrun"<<block.overrun<<endl;
k++;
}
while(k<3);
cout<<"\n\nk="<<k<<endl;
fclose(csvFile);
fclose(biFile);
return 0;
}
This code does the job, but unfortunately, file position indicator stays at the begins of the file, and next block is the first block.
Please, any help to write good bin2csv convertor on the PC side.
SEEK_CUR before readings 1
SEEK_CUR after readings 1
resread is 512
arbitrary readings:
Count21
time :25261656
25261656, 0, 101, 202, 303, 404, 505, 606, 707, 808, 909, 0
25263656, 0, 101, 202, 303, 404, 505, 606, 707, 808, 909, 0
25265660, 0, 101, 202, 303, 404, 505, 606, 707, 808, 909, 0
25267660, 0, 101, 202, 303, 404, 505, 606, 707, 808, 909, 0
25269656, 0, 101, 202, 303, 404, 505, 606, 707, 808, 909, 0
25271660, 0, 101, 202, 303, 404, 505, 606, 707, 808, 909, 0
25273656, 0, 101, 202, 303, 404, 505, 606, 707, 808, 909, 0
25275660, 0, 101, 202, 303, 404, 505, 606, 707, 808, 909, 0
25277660, 0, 101, 202, 303, 404, 505, 606, 707, 808, 909, 0
25279656, 0, 101, 202, 303, 404, 505, 606, 707, 808, 909, 0
25281656, 0, 101, 202, 303, 404, 505, 606, 707, 808, 909, 0
25283660, 0, 101, 202, 303, 404, 505, 606, 707, 808, 909, 0
25285660, 0, 101, 202, 303, 404, 505, 606, 707, 808, 909, 0
25287656, 0, 101, 202, 303, 404, 505, 606, 707, 808, 909, 0
25289660, 0, 101, 202, 303, 404, 505, 606, 707, 808, 909, 0
25291660, 0, 101, 202, 303, 404, 505, 606, 707, 808, 909, 0
25293656, 0, 101, 202, 303, 404, 505, 606, 707, 808, 909, 0
25295660, 0, 101, 202, 303, 404, 505, 606, 707, 808, 909, 0
25297660, 0, 101, 202, 303, 404, 505, 606, 707, 808, 909, 0
25299660, 0, 101, 202, 303, 404, 505, 606, 707, 808, 909, 0
25301656, 0, 101, 202, 303, 404, 505, 606, 707, 808, 909, 0
fill
overrun0