bulentv / js_zklib

Attendance Machine Library for NodeJS with a connection to the network using the UDP protocol and port 4370
GNU General Public License v2.0
56 stars 46 forks source link

GetAttendance function with different results #8

Closed mribichich closed 6 years ago

mribichich commented 6 years ago

Hi there. I've been trying to use your library, but it seems that I may have a different version of zkaccess, because the GetAttendace message is not being parse correctly

In line 19 you have:

    var att = {
      uid: parseInt(attdata.slice(0,4).toString("ascii").split('\0').shift()) || 0,
      id: parseInt(attdata.slice(4,8).toString("ascii").split('\0').shift()) || 0,
      state: attdata[28],
      timestamp: self.decode_time(attdata.readUInt32LE(29))
    };
    return att;

But the uid and id are empty or wrong.

This is the buffer that comes:

I had to change it to this in order to work:

    var att = {
      id: (attdata[3] << 8) + attdata[2],
      userId: parseInt(attdata.slice(4, 6).toString("ascii")),
      state: attdata[28],
      timestamp: self.decode_time(attdata.readUInt32LE(29)),
    };

I would love to PR back to the lib, but is it working for you? How could we make it compatible with your version of the protocol and mine.

The version command returns 10

thanks!

mribichich commented 6 years ago

device firmware v6.60 Aug 10 2015

mribichich commented 6 years ago

@bulentv what do you think about this? I was thinking that maybe we could solve it with two options:

The drawback from this one is that the decode func I have to use will not be in the lib, so others cannot use it

ZKLib.prototype.getattendance = function(decodingFunc, cb) {

what do you think?

thanks

bulentv commented 6 years ago

@mribichich

I definetely prefer the second option. If you can implement your decoder in some file, named like att_parser_v6.60.js so we can import and refer it in the config. I will in the meantime move the existing parser to a separate file called att_parser_legacy.js.

One issue is unfortunately I no longer have access to any device to test the code. Hope we will have some feedback.

Please continue using ES2015 styling, I'm converting the other files as well.

Thanks

mribichich commented 6 years ago

Ok great, I like it better too.

I of course have access to the one I'm using but only that one.

I'll let you know when its ready.

thanks

mribichich commented 6 years ago

@bulentv were you able to separate the decoder like you said to a att_parser_legacy.js ?

How do you want to handle the require of the possible decoders?

As an option? maybe something like:

options: {
  attendanceDecoder or attendanceParser: 'legacy' or '6.60'
}

is that ok?

mribichich commented 6 years ago

I can extract both if you want

bulentv commented 6 years ago

Yes, it would be great. I haven't had time to do it, completed the es2015 transition though.