diff options
Diffstat (limited to 'reader.c')
-rw-r--r-- | reader.c | 31 |
1 files changed, 20 insertions, 11 deletions
@@ -13,9 +13,10 @@ #define DEFAULT_POLL_TIMEOUT 1000 #define MAX_TAGS 5 -#define FLAG_CORE_NOTIFIED 1 -#define FLAG_ACTIVE 2 +#define FLAG_PRESENT 1 +#define FLAG_FULLY_READ 2 #define FLAG_UNPROGRAMMED 4 +#define FLAG_ACTIVE 8 static void* reader_module = NULL; static reader_plugin_handle reader_backend_handle = NULL; @@ -90,23 +91,25 @@ int reader_init(){ static void reader_expire(){ size_t n = 0; for(n = 0; n < MAX_TAGS; n++){ - tags[n].flags &= ~(FLAG_ACTIVE); + tags[n].flags &= ~(FLAG_PRESENT); } } static int reader_process(){ size_t n = 0; for(n = 0; n < MAX_TAGS; n++){ - if(tags[n].flags & FLAG_ACTIVE){ - if(!(tags[n].flags & FLAG_CORE_NOTIFIED)){ + if(tags[n].flags & FLAG_PRESENT){ + //TODO verify tag is fully read before pushing + + if(!(tags[n].flags & FLAG_ACTIVE)){ //new tag //TODO printf("Tag index %lu detected\n", n); - tags[n].flags |= FLAG_CORE_NOTIFIED; + tags[n].flags |= FLAG_ACTIVE; } } else{ - if(tags[n].flags & FLAG_CORE_NOTIFIED){ + if(tags[n].flags & FLAG_ACTIVE){ //tag was removed //TODO printf("Tag index %lu removed\n", n); @@ -124,20 +127,26 @@ int reader_tag_present(nfc_tag_info_t tag){ //check if tag already known for(n = 0; n < MAX_TAGS; n++){ - if((tags[n].flags & (FLAG_ACTIVE | FLAG_CORE_NOTIFIED)) + if((tags[n].flags & (FLAG_PRESENT | FLAG_ACTIVE)) && tags[n].info.uid_length == tag.uid_length && !memcmp(tags[n].info.uid, tag.uid, tag.uid_length)){ //mark still active - tags[n].flags |= FLAG_ACTIVE; - return 0; + tags[n].flags |= FLAG_PRESENT; + + //TODO if full data submitted, copy in + + //if data has not yet been fully read, request a full read + return (tags[n].flags & (FLAG_FULLY_READ | FLAG_UNPROGRAMMED)) ? 0 : TAG_READ_REQUESTED; } } //if not, add it for(n = 0; n < MAX_TAGS; n++){ if(!tags[n].flags){ - tags[n].flags |= FLAG_ACTIVE; + tags[n].flags |= FLAG_PRESENT; memcpy(&(tags[n].info), &tag, sizeof(tag)); + + //TODO set FULLY_READ flag if necessary return 0; } } |