brianrho / FPM

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

read serial number from newer models such as R503 #36

Closed oskarn97 closed 10 months ago

brianrho commented 4 years ago

Thanks. Some changes you should make first:

- /* 58 is max packet length for ACKed commands (read prod info) */
- #define FPM_BUFFER_SZ              (58)

+ /* 46 is the max packet length for ACKed commands, +1 for confirmation code */
+ #define FPM_BUFFER_SZ             (46 + 1)

...because 46 is the maximum packet length for the ReadProdInfo command and the buffer is only ever supposed to hold the packet's payload + 1 byte for the confirmation code, not the entire packet including the header.

For the function itself:

int16_t FPM::getSerialNumber(uint8_t * serialNumber)

...right now, it accepts a pointer and just copies the serial number into that. It relies on the user knowing just how many bytes to allocate for the serial number, which we can avoid here. Considering the product info is made up of proper ASCII strings or integers, I think using a struct to hold the data would allow users easily access all its individual members, not only the serial number, without having to know about the internal workings or packet format, like prod_info.serialNumber or prod_info.templateSize. Something like this:

typedef struct {
char moduleModel[16+1];
char batchNumber[4+1];
char serialNumber[8+1];
struct {
   uint8_t major;
   uint8_t minor;
} hwVersion;
char sensorModel[8+1];
uint16_t imageWidth;
uint16_t imageHeight;
uint16_t templateSize;
uint16_t databaseSize;
} FPM_ProductInfo;

This way, one could call FPM::getProductInfo(FPM_ProductInfo * prod_info); and access the members easily, especially the strings as already null-terminated. You'd need to copy each part of the ProdInfo packet carefully into the right member of the struct, making sure to swap bytes where necessary since the numbers are in big-endian format.

brianrho commented 10 months ago

After the recent refactoring, this function is now available as FPM::readProductInfo(). Closing this.