48 lines
1.3 KiB
C
48 lines
1.3 KiB
C
#include "b2hd.h"
|
|
/**
|
|
* @brief allow to transform all binary hex data send by the Vegetal Signal captor in a .TXT file into decimal values in a .csv
|
|
*
|
|
*/
|
|
void b2hd()
|
|
{
|
|
int i;
|
|
int indice[6];
|
|
char buff[26];
|
|
char buff2[18];
|
|
int32_t values[8];
|
|
uint32_t valbin[8];
|
|
quartet value;
|
|
|
|
while (fread(&buff, 26, 1, stdin)) {
|
|
fprintf(stdout , "%d,", millis());
|
|
for (int i = 1; i < 9; i++){
|
|
/*buff[25] = '\0';*/
|
|
if (strncmp(buff, "#################\n", (size_t)18) == 0) {
|
|
if (!(fread(&buff2, 18, 1, stdin))) {
|
|
fprintf(stderr, "Erreur lesture après ###...#");
|
|
break;
|
|
} else {
|
|
/*buff2[17] = '\0';*/
|
|
strncpy(buff, &buff[18], 8);
|
|
strncpy(&buff[8], buff2, 18);
|
|
}
|
|
}
|
|
value.octet1 = buff[3*i+1];
|
|
value.octet2 = buff[3*i+2];
|
|
value.octet3 = buff[3*i+3];
|
|
value.octet4 = 0;
|
|
/*memcpy(&values[i], &value, sizeof(quartet));*/
|
|
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(stdout, "%d,", values[i]/256);
|
|
}
|
|
else{
|
|
fprintf(stdout, "%d\n", values[i]/256);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
int main(int argc , char** argv){
|
|
b2hd();
|
|
} |