60 lines
1.4 KiB
C
60 lines
1.4 KiB
C
|
#include "simulateFlux.h"
|
||
|
|
||
|
|
||
|
int writeOneRawData(){
|
||
|
|
||
|
char buff[26];
|
||
|
char buff2[18];
|
||
|
int32_t values[8];
|
||
|
uint32_t valbin[8];
|
||
|
quartet value;
|
||
|
|
||
|
FILE *f = fopen("rawData.csv" , "a");
|
||
|
|
||
|
if(fread(&buff, 26, 1, stdin)) {
|
||
|
fprintf(f , "%d,", millis());
|
||
|
if (strncmp(buff, "#################\n", (size_t)18) == 0) {
|
||
|
if (!(fread(&buff2, 18, 1, stdin))) {
|
||
|
fprintf(stderr, "Erreur lecture après ###...#");
|
||
|
return 2;
|
||
|
} else {
|
||
|
strncpy(buff, &buff[18], 8);
|
||
|
strncpy(&buff[8], buff2, 18);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
for (int i = 1; i < 9; i++){
|
||
|
value.octet1 = buff[3*i+1];
|
||
|
value.octet2 = buff[3*i+2];
|
||
|
value.octet3 = buff[3*i+3];
|
||
|
value.octet4 = 0;
|
||
|
|
||
|
valbin[i] = buff[3*i+1]*256*256*256 + buff[3*i+2]*256*256 + buff[3*i+3]*256;
|
||
|
memcpy(&values[i], &valbin[i], sizeof(uint32_t));
|
||
|
|
||
|
if(i<8){
|
||
|
fprintf(f, "%d,", values[i]/256);
|
||
|
}
|
||
|
else{
|
||
|
fprintf(f, "%d\n", values[i]/256);
|
||
|
}
|
||
|
}
|
||
|
fclose(f);
|
||
|
cpt++;
|
||
|
return 0;
|
||
|
}
|
||
|
else {
|
||
|
return 1;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void simulateFlux(){
|
||
|
while(writeOneRawData()==0){
|
||
|
sleep(0.004);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
int main(int argc , char argv[]){
|
||
|
simulateFlux();
|
||
|
printf("%d",cpt);
|
||
|
}
|