From 737914b33d3fe35290bb6afaa9eda398dbd31cea Mon Sep 17 00:00:00 2001 From: cbdev Date: Mon, 19 Jun 2023 23:22:25 +0200 Subject: Move polling functionality to reader module --- reader_yhy.c | 49 ++++++++----------------------------------------- 1 file changed, 8 insertions(+), 41 deletions(-) (limited to 'reader_yhy.c') diff --git a/reader_yhy.c b/reader_yhy.c index 58bd345..7ece702 100644 --- a/reader_yhy.c +++ b/reader_yhy.c @@ -8,21 +8,9 @@ #include "libyhy.h" static int reader_fd = -1; -static int timer_fd = -1; int init(){ char reader_version[100]; - size_t poll_timeout = 1000; - struct itimerspec timer_cfg = { - 0 - }; - - if(config_get("nfc", "interval")){ - poll_timeout = strtoul(config_get("nfc", "interval"), NULL, 10); - } - - timer_cfg.it_value.tv_sec = timer_cfg.it_interval.tv_sec = poll_timeout / 1000; - timer_cfg.it_value.tv_nsec = timer_cfg.it_interval.tv_nsec = (poll_timeout % 1000) * 1e6; char* port = config_get("nfc", "device"); if(!port){ @@ -31,7 +19,7 @@ int init(){ } //TODO set cloexec, nonblock - printf("Opening %s with polltime %lu\n", port, poll_timeout); + printf("Opening YHY reader on %s\n", port); reader_fd = yhy_open(port); if(reader_fd < 0){ printf("Failed to open reader connection at %s\n", port); @@ -42,45 +30,24 @@ int init(){ printf("Connected YHY reader reports firmware: %s\n", reader_version); } - //create timerfd - timer_fd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC); - if(timer_fd < 0){ - printf("Failed to create timer fd\n"); - return 1; - } - - if(timerfd_settime(timer_fd, 0, &timer_cfg, NULL)){ - printf("Failed to set timer\n"); - return 1; - } - core_manage_fd(reader_fd, 1, system_reader); - core_manage_fd(timer_fd, 1, system_reader); - return 0; } int handle(int fd){ - uint8_t buffer[1024]; - - if(fd == timer_fd){ - //acknowledge the timer - read(fd, buffer, sizeof(buffer)); - - //see if there is a tag - //TODO - return 0; + if(fd == reader_fd){ + printf("Unhandled data on YHY fd\n"); } + return 0; +} - printf("Unknown FD in reader_yhy handler\n"); - return 1; +int scan(){ + printf("Scanning field\n"); + return 0; } static void __attribute__((destructor)) cleanup(){ core_manage_fd(reader_fd, 0, system_reader); close(reader_fd); reader_fd = -1; - core_manage_fd(timer_fd, 0, system_reader); - close(timer_fd); - timer_fd = -1; } -- cgit v1.2.3