uhppoted/uhppoted-nodejs

getCardByIndex issue

Closed this issue · 5 comments

i use getCards method to get total cards number and after that i iterate using getCardByIndex method from 0 until total cards to get every card added on the device.

the problem is that many many cards show 4294967295 as card number and that number never was added to my device.

I noticed 4294967295 is equal to 2^32 so maybe are deleted cards or something more

when i use uhppote-cli / get-cards give me the right total of cards and no one its equal to 4294967295

So, there is a better method to get all existing card in my device and total number too?

Sample of getCardByIndex with issue:

card: {
number: 4294967295,
valid: { from: '', to: '' },
doors: { '1': false, '2': false, '3': false, '4': false },
PIN: 0
}

Regards

Hi,

4294967295 corresponds to 0xffffffff which is a marker for a deleted card. The CLI algorithm basically retrieves the card at index 1 and then steps through until it has retrieved the number of cards returned by get-cards, discarding any cards with 0 (not found) or 0xffffffff (deleted). I think the maximum number of cards is around 20000 so you probably want to put a check for that in the loop so that it doesn't loop forever if something has gone wrong.

So yeah, you're pretty much on the right track - thought I had documented it but I see it's only in the get-card-by-index example:

const uhppoted = require('uhppoted')
const ctx = require('./common.js')

const deviceID = 405419896
const index = 3

uhppoted.getCardByIndex(ctx, deviceID, index)
  .then(response => {
    switch (response.card.number) {
      case 0:
        console.log(`get-card-by-index: card @${index} not found`)
        break

      case 0xffffffff:
        console.log(`get-card-by-index: card @${index} deleted`)
        break

      default:
        console.log('\nget-card-by-index:\n', response)
    }
  })
  .catch(err => {
    console.log(`\n   *** ERROR ${err.message}\n`)
  })

I'll make a note to update the doc.

Huh! That turns out to be harder than it should be! I've added get-all-cards to the examples but Promises make it awkward enough that I'm considering adding it to the API.

Unless you have a cleaner way to do it?

its ok, the only issue its that cannot be paginated correctly and there is no way to get the real total of cards without iterate each index but i understand that is a hardware limitation :)

FWIW, I've never seen an incorrect card count from get-cards but there's nothing to say it couldn't happen. I guess we live with it like it is then :-).

I'll leave the get-all-cards as an example for now - if anybody else pops to ask it's easy to point at and I can then think about lifting it into the API.

Hi,

Going to close this out - the jsdoc updates and new examples will be in the next release. Feel free to reopen it if you need to though :-).