Skip to content

Getting incorrect packet data when uploading image #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
xavirp opened this issue Feb 25, 2021 · 7 comments
Closed

Getting incorrect packet data when uploading image #29

xavirp opened this issue Feb 25, 2021 · 7 comments

Comments

@xavirp
Copy link

xavirp commented Feb 25, 2021

Hi,
I've tested the PR and I'm receiving this error when downloading template. The last debug lines are:
Downloading template...
*** DEBUG ==> _send_packet length: 13
*** DEBUG ==> _send_packet data: ['ef', '01', 'ff', 'ff', 'ff', 'ff', '01', '00', '04', '08', '01', '00', '0e']
*** DEBUG ==> _get_packet received data: ['ef', '01', 'ff', 'ff', 'ff', 'ff', '07', '00', '03', '00', '00', '0a']
*** DEBUG ==> _get_packet reply: ['00']
*** DEBUG ==> _get_data received data: ['ef', '01', 'ff', 'ff', 'ff', 'ff', '02', '00', '82']
*** DEBUG ==> _get_data received start pos: 0xef01
*** DEBUG ==> _get_data received address: [255, 255, 255, 255]
*** DEBUG ==> _get_data received packet_type: 0x2
*** DEBUG ==> _get_data received length: 0x82
*** DEBUG ==> _get_data received checksum: (20956,)
*** DEBUG ==> _get_data received data: ['36', 'ab', '14', '65', '0f', 'a7', '05', '1f', '2e']
*** DEBUG ==> _get_data received start pos: 0x36ab
Traceback (most recent call last):
File "adafruit_template_file_compare.py", line 196, in
enroll_save_to_file()
File "adafruit_template_file_compare.py", line 147, in enroll_save_to_file
data = finger.get_fpdata("char", 1)
File "/home/pi/huellas/adafruit.py", line 222, in get_fpdata
res = self._get_data(9)
File "/home/pi/huellas/adafruit.py", line 405, in _get_data
reply += self._get_data(9)
File "/home/pi/huellas/adafruit.py", line 382, in _get_data
raise RuntimeError("Incorrect packet data")
RuntimeError: Incorrect packet data

The data received length is 130 (I showed it in hex). For some reason there's no next complete parcel, don't know why. Any clue?
Thx

@xavirp
Copy link
Author

xavirp commented Feb 25, 2021

Sorry, my (your) _get_data function is:

def _get_data(self, expected):
        """Gets packet from serial and checks structure for _DATAPACKET
        and _ENDDATAPACKET.  Alternate method for getting data such
        as fingerprint image, etc.  Returns the data payload."""
        res = self._uart.read(expected)
        self._print_debug("_get_data received data:", res, data_type="hex")
        if (not res) or (len(res) != expected):
            raise RuntimeError("Failed to read data from sensor")

        # first two bytes are start code
        start = struct.unpack(">H", res[0:2])[0]
        self._print_debug("_get_data received start pos:", str(hex(start)))
        if start != _STARTCODE:
            raise RuntimeError("Incorrect packet data")
        # next 4 bytes are address
        addr = list(i for i in res[2:6])
        self._print_debug("_get_data received address:", addr)
        if addr != self.address:
            raise RuntimeError("Incorrect address")

        packet_type, length = struct.unpack(">BH", res[6:9])
        self._print_debug("_get_data received packet_type:", str(hex(packet_type)))
        self._print_debug("_get_data received length:", str(hex(length)))

        # todo: check checksum

        if packet_type != _DATAPACKET:
            if packet_type != _ENDDATAPACKET:
                raise RuntimeError("Incorrect packet data")

        if packet_type == _DATAPACKET:
            res = self._uart.read(length - 2)
            # todo: we should really inspect the headers and checksum
            **reply = list(i for i in res[0:length])**
            received_checksum = struct.unpack(">H", self._uart.read(2))
            self._print_debug("_get_data received checksum:", received_checksum)
            reply += self._get_data(9)

        elif packet_type == _ENDDATAPACKET:
            res = self._uart.read(length - 2)
            # todo: we should really inspect the headers and checksum
            reply = list(i for i in res[0:length])
            received_checksum = struct.unpack(">H", self._uart.read(2))
            self._print_debug("_get_data received checksum:", received_checksum)

        self._print_debug("_get_data reply length:", len(reply))
        self._print_debug("_get_data reply:", reply, data_type="hex")
        return reply

Please, look at the line between ** XXXXX **
Your putting the content bytes into a list, but shouldn't it be res[0:length-2] ?

@admiralmaggie
Copy link

admiralmaggie commented Feb 27, 2021

Hello @xavirp,
Which sensor are you testing with?

Cheers,
AR

@xavirp
Copy link
Author

xavirp commented Feb 28, 2021

Hi Ar,
It's a R503

@admiralmaggie
Copy link

@xavirp I'm unable to replicate this on my end. One option is to download Eltima's serial port monitor and view the raw packets between your PC and the sensor. It might provide some clue as to why you are not getting complete packets.

@jaiguptanick
Copy link

Is this issue resolved?
I am also getting similar error, I have same sensor using with ItsyBitsy M0 express

@tekktrik
Copy link
Member

@ajiekurniawansaputra did #47 resolve this for you? I'm wondering if this can be closed now.

@ajiekurniawansaputra
Copy link
Contributor

yess

@tekktrik tekktrik closed this as completed Jun 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants