brianrho / FPM

Arduino library for the R30x/ZFMxx/FPMxx optical fingerprint sensors
105 stars 41 forks source link

templates example fails #34

Closed cheofusi closed 4 years ago

cheofusi commented 4 years ago

I'm unable to use the read_template function in the templates example with the FPM10A sensor. Fails with a "packet too long: 130" error.

brianrho commented 4 years ago

Hi Brandon, good work narrowing it down:

https://github.com/brianrho/FPM/blob/7b2c0cf8fa15d52d431888bec2a0aeecee74ec7b/src/FPM.cpp#L721

From what you explained earlier, this condition is what is failing and yet your packet length (130 bytes) looks just fine to me (usually 128 + 2 bytes for checksum, as I recall). So, I think the problem here is, you supplied an insufficient buffer to readRaw(). If you're using the default templates example, the default buffer size there is 768. If you check the comment above the relevant #define, you'll see where I mentioned that some sensors have larger-than-normal template sizes, up to 1024 bytes. It's possible your sensor is one of those, so try setting BUFF_SZ to 1024 and see if it helps.

cheofusi commented 4 years ago

Thanks for responding. My sensor, the FPM10A, uses a 512 template. However setting the BUFF_SZ to 512 doesn't fix the issue. I succeeded in reading the template using the example from the official Adafruit library which shows that the sensor uses 267 byte packets for data transfer, and not the usual 128 + 2 for COMMAND & ACK packets. So all I do is read two packets and extract half the template from each packet.

However with a params check the sensor returns 130 for packet_length which your library tries to use as the chunk length for data transfer, and which doesn't work

brianrho commented 4 years ago

Wait, that doesn't make sense. I thought you said the error was "packet too long: 130". Are you saying it reports 130 as the length within the packet itself (not the initial system parameters) but then follows up with 267 bytes instead?

brianrho commented 4 years ago

Because the only time I use sys_params.packet_len is when writing/uploading templates back to the sensor.

cheofusi commented 4 years ago

Wait, that doesn't make sense. I thought you said the error was "packet too long: 130". Are you saying it reports 130 as the length within the packet itself (not the initial system parameters) but then follows up with 267 bytes instead?

Exactly. I can't figure out whether it's the ACK packet following the download command or its the first packet containing the template itself. Same issue with uploading templates to the sensor. Have you tested the WriteRaw and ReadRaw functions with the fpm10a??

brianrho commented 4 years ago

Definitely. An FPM10A was actually the first fingerprint sensor I ever used years back. You likely just have different/updated firmware.

Leave template uploads for now. Let's focus on just downloads.

I still think you just have a buffer that's too small. So try the 1024-sized buffer, as I said before, and let me know what you find.

cheofusi commented 4 years ago

I tried all the 1024. The sketch is the templates example. By the way not every packet is 267 bytes in length. Only the data packets carrying the template. I also solved the problem for uploads. All I did was change the chunk_sz in the readRaw function to 256 and the loop counter, i, in the writePacket function to an unint16_t.

brianrho commented 4 years ago

Okay, if your issue is solved, I'll be closing this.