From 4e4601d12f6a0d25647ea6419b6ad78f41a49f63 Mon Sep 17 00:00:00 2001 From: LongHairedHacker Date: Thu, 1 Dec 2016 00:16:42 +0100 Subject: [PATCH] Implemented timeouts for linux port --- software/linux/libsss7.c | 19 ++++++++++++++++++- software/linux/test.c | 2 +- software/sss7core/sss7.h | 2 +- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/software/linux/libsss7.c b/software/linux/libsss7.c index 27252e9..fa55f24 100644 --- a/software/linux/libsss7.c +++ b/software/linux/libsss7.c @@ -7,6 +7,7 @@ #include #include #include +#include #include "sss7.h" @@ -19,6 +20,13 @@ pthread_mutex_t state_mutex, rx_buffer_mutex; int serial_fd; +int get_milliseconds(void) { + struct timeval tv; + gettimeofday(&tv,NULL); + return tv.tv_sec * 1000 + tv.tv_usec / 1000; +} + + int uart_init(char *serialport) { serial_fd = open(serialport, O_RDWR | O_NOCTTY | O_NDELAY); if (serial_fd == -1) { @@ -46,7 +54,7 @@ int uart_init(char *serialport) { // No output processing options.c_oflag = 0; - options.c_cc[VTIME] = 20; + options.c_cc[VTIME] = 1; options.c_cc[VMIN] = 0; tcsetattr(serial_fd, TCSAFLUSH, &options); @@ -120,7 +128,9 @@ void uart_put_byte(uint8_t byte) { void *eventloop(void *arg) { int res = 0; + int timestamp = get_milliseconds(); while(1) { + printf("Loop\n"); if(uart_has_tx_byte) { write(serial_fd, &uart_tx_byte, 1); printf("Send %x\n", uart_tx_byte); @@ -143,6 +153,13 @@ void *eventloop(void *arg) { sss7_process_tx(); pthread_mutex_unlock(&state_mutex); } + + pthread_mutex_lock(&state_mutex); + int now = get_milliseconds(); + printf("Ticks: %d\n", now - timestamp); + sss7_process_ticks(now - timestamp); + timestamp = now; + pthread_mutex_unlock(&state_mutex); } return NULL; diff --git a/software/linux/test.c b/software/linux/test.c index a0c8185..1edc251 100644 --- a/software/linux/test.c +++ b/software/linux/test.c @@ -31,7 +31,7 @@ int main(int argc, char const *argv[]) { if(libsss7_send_failed()) { printf("Send failed\n"); } - sleep(2); + sleep(5); } diff --git a/software/sss7core/sss7.h b/software/sss7core/sss7.h index 3370bee..5e42b0a 100644 --- a/software/sss7core/sss7.h +++ b/software/sss7core/sss7.h @@ -27,7 +27,7 @@ enum sss7State { }; const static uint8_t SSS7_HEADER[] = {0xAA, 0xFE}; -const static uint16_t sss7_timeout = 50; +const static uint16_t sss7_timeout = 150; const static uint16_t sss7_timeout_increment = 1; #define SSS7_PAYLOAD_SIZE 16