2023-06-01 17:22:38 +02:00
|
|
|
#include "./Include/b2hd.h"
|
2022-06-21 15:13:10 +02:00
|
|
|
#include <time.h>
|
|
|
|
|
2023-06-01 17:22:38 +02:00
|
|
|
int64_t millis()
|
|
|
|
{
|
|
|
|
// struct timespec now;
|
|
|
|
struct timespec *now = (struct timespec *)malloc(sizeof(struct timespec));
|
|
|
|
// timespec_get(&now, TIME_UTC);
|
|
|
|
timespec_get(now, TIME_UTC);
|
2022-06-21 15:13:10 +02:00
|
|
|
|
2023-06-01 17:22:38 +02:00
|
|
|
// #ifdef __USE_ISOC11 ????
|
|
|
|
int64_t tmp = (((int64_t)now->tv_sec) * 1000 + ((int64_t)now->tv_nsec) / ((int64_t)1000000));
|
|
|
|
free(now);
|
|
|
|
return tmp;
|
2022-06-21 15:13:10 +02:00
|
|
|
}
|
|
|
|
|
2022-06-09 17:34:24 +02:00
|
|
|
/**
|
|
|
|
* @brief allow to transform all binary hex data send by the Vegetal Signal captor in a .TXT file into decimal values in a .csv
|
2023-06-01 17:22:38 +02:00
|
|
|
*
|
2022-06-09 17:34:24 +02:00
|
|
|
*/
|
2022-05-31 17:42:26 +02:00
|
|
|
void b2hd()
|
2022-04-07 17:31:01 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int indice[6];
|
|
|
|
char buff[26];
|
|
|
|
char buff2[18];
|
|
|
|
int32_t values[8];
|
|
|
|
uint32_t valbin[8];
|
|
|
|
quartet value;
|
2023-06-01 17:22:38 +02:00
|
|
|
|
|
|
|
while (fread(&buff, 26, 1, stdin))
|
|
|
|
{
|
|
|
|
fprintf(stdout, "%ld,", 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)))
|
|
|
|
{
|
2022-04-07 17:31:01 +02:00
|
|
|
fprintf(stderr, "Erreur lesture après ###...#");
|
2023-06-01 17:22:38 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-04-07 17:31:01 +02:00
|
|
|
/*buff2[17] = '\0';*/
|
|
|
|
strncpy(buff, &buff[18], 8);
|
|
|
|
strncpy(&buff[8], buff2, 18);
|
|
|
|
}
|
|
|
|
}
|
2023-06-01 17:22:38 +02:00
|
|
|
value.octet1 = buff[3 * i + 1];
|
|
|
|
value.octet2 = buff[3 * i + 2];
|
|
|
|
value.octet3 = buff[3 * i + 3];
|
2022-04-07 17:31:01 +02:00
|
|
|
value.octet4 = 0;
|
|
|
|
/*memcpy(&values[i], &value, sizeof(quartet));*/
|
2023-06-01 17:22:38 +02:00
|
|
|
valbin[i] = buff[3 * i + 1] * 256 * 256 * 256 + buff[3 * i + 2] * 256 * 256 + buff[3 * i + 3] * 256;
|
2022-06-03 17:02:49 +02:00
|
|
|
memcpy(&values[i], &valbin[i], sizeof(uint32_t));
|
2023-06-01 17:22:38 +02:00
|
|
|
if (i < 8)
|
|
|
|
{
|
|
|
|
fprintf(stdout, "%d,", values[i] / 256);
|
2022-04-07 17:31:01 +02:00
|
|
|
}
|
2023-06-01 17:22:38 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf(stdout, "%d\n", values[i] / 256);
|
2022-04-07 17:31:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-06-14 10:46:12 +02:00
|
|
|
|
2023-06-01 17:22:38 +02:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2022-06-01 12:32:04 +02:00
|
|
|
b2hd();
|
|
|
|
}
|