time resolution in microseconds

pull/53/head
Xael South 2024-05-14 12:36:09 +02:00
rodzic c9f4c58573
commit b6a7705d67
5 zmienionych plików z 58 dodań i 25 usunięć

Wyświetl plik

@ -32,15 +32,8 @@
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <fixedptc/fixedptc.h>
#include "build/version.h"
#include "fir.h"
#include "iir.h"
#include "ppf.h"
#include "moving_average_filter.h"
#include "atan2.h"
#include "t1_c1_packet_decoder.h"
#include "s1_packet_decoder.h"
#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
#define WINDOWS_BUILD 1
@ -48,6 +41,16 @@
#define WINDOWS_BUILD 0
#endif
#include "build/version.h"
#include "fir.h"
#include "iir.h"
#include "ppf.h"
#include "moving_average_filter.h"
#include "atan2.h"
#include "rtl_wmbus_util.h"
#include "t1_c1_packet_decoder.h"
#include "s1_packet_decoder.h"
#if WINDOWS_BUILD == 1
#define CHECK_FLOW 0
@ -867,6 +870,7 @@ static void print_usage(const char *program_name)
{
fprintf(stdout, "rtl_wmbus: " VERSION "\n\n");
fprintf(stdout, "Usage %s:\n", program_name);
fprintf(stdout, "\t-o remove DC offset\n");
fprintf(stdout, "\t-a accelerate (use an inaccurate atan version)\n");
fprintf(stdout, "\t-r 0 to disable run length algorithm\n");
fprintf(stdout, "\t-t 0 to disable time2 algorithm\n");

Wyświetl plik

@ -323,6 +323,9 @@
<F N="include/mode_s_util.h"/>
<F N="include/mode_t_util.h"/>
</Folder>
<Folder Name="samples">
<F N="samples/readme.txt"/>
</Folder>
<F N="androidbuild.bat"/>
<F N="atan2.h"/>
<F N="build-deb.sh"/>
@ -335,6 +338,7 @@
<F N="README.md"/>
<F N="rtl_wmbus.c"/>
<F N="rtl_wmbus.py"/>
<F N="rtl_wmbus_util.h"/>
<F N="s1_packet_decoder.h"/>
<F N="t1_c1_packet_decoder.h"/>
</Files>

39
rtl_wmbus_util.h 100644
Wyświetl plik

@ -0,0 +1,39 @@
#include <stddef.h>
#include <time.h>
#if WINDOWS_BUILD
#else
#include <sys/time.h>
#endif
inline int make_time_string(char* timestamp, size_t timestamp_size)
{
memset(timestamp, 0, timestamp_size);
#if WINDOWS_BUILD
time_t now;
if (time(&now) == NULL)
return -1;
struct tm* timeinfo = gmtime(&now);
if (timeinfo == NULL)
return -1;
strftime(timestamp, timestamp_size, "%Y-%m-%d %H:%M:%S.000000", timeinfo);
#else
struct timeval tv;
if (gettimeofday(&tv, NULL) != 0)
return -1;
struct tm timeinfo;
if (localtime_r(&tv.tv_sec, &timeinfo) == NULL)
return -1;
char fmt[timestamp_size];
strftime(fmt, sizeof(fmt), "%Y-%m-%d %H:%M:%S.%%06u", &timeinfo);
snprintf(timestamp, timestamp_size, fmt, tv.tv_usec);
#endif
return 0;
}

Wyświetl plik

@ -31,7 +31,6 @@
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
static const uint8_t MANCHESTER_IEEE_802_3[4] = {
0xFF, 0x01, 0x00, 0xFF // According to wireless MBus spec.: "01b” representing a “one”; "10b" representing a "zero".
@ -227,11 +226,7 @@ static void s1_rx_last_data_bit(unsigned bit, struct s1_packet_decoder_work *dec
}
else
{
time_t now;
time(&now);
struct tm *timeinfo = gmtime(&now);
strftime(decoder->timestamp, sizeof(decoder->timestamp), "%Y-%m-%d %H:%M:%S.000", timeinfo);
make_time_string(decoder->timestamp, sizeof(decoder->timestamp));
}
}

Wyświetl plik

@ -31,7 +31,6 @@
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#if !defined(PACKET_CAPTURE_THRESHOLD)
#define PACKET_CAPTURE_THRESHOLD 5u
@ -388,11 +387,7 @@ static void t1_rx_low_nibble_last_data_bit(unsigned bit, struct t1_c1_packet_dec
}
else
{
time_t now;
time(&now);
struct tm *timeinfo = gmtime(&now);
strftime(decoder->timestamp, sizeof(decoder->timestamp), "%Y-%m-%d %H:%M:%S.000", timeinfo);
make_time_string(decoder->timestamp, sizeof(decoder->timestamp));
}
}
@ -460,11 +455,7 @@ static void c1_rx_last_data_bit(unsigned bit, struct t1_c1_packet_decoder_work *
}
else
{
time_t now;
time(&now);
struct tm *timeinfo = gmtime(&now);
strftime(decoder->timestamp, sizeof(decoder->timestamp), "%Y-%m-%d %H:%M:%S.000", timeinfo);
make_time_string(decoder->timestamp, sizeof(decoder->timestamp));
}
}