Go Down

Topic: Write template on Fingerprint sensor R305/R307 (Read 3646 times) previous topic - next topic

dhananjayaggarwal

Post the full true output of the example - not just an extract of what you think is meaningful

Are you running this on a UNO or MEGA ?

The  stray FFFFFFFFFFF you see are just there because buffer is initialized with plenty of FF in the library

They seem to use data packets of 256 bytes but seems what you get back is actually the 128 bytes version

having multiple data packet is not impossible as you might not be able to fit all the data in one frame, so you should expect when you send a command to get many answer and at some point the last frame will include a End of Data packet command so that you know it's the last one

there is  plenty of garbage so would need to see exactly the output on the Serial console...

The 3 frames you see are



FFFFFFFFFFFFFFFFFF0165159200FFFEFFFEFFFEFFFEF80EC00680008000800080000000000000000000000000008000000000000000000000000000000020AB78324242982B0D


EF01
FFFFFFFF
02 Data packet
0082 length of package = command packets + data packets + CKSUM --> 128 bytes + 2 for checksum
5E1F56592A3ED8D9674201F90000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
056C CKSUM (this one is OK)

EF01
FFFFFFFF
02 Data packet
0082 length of package = command packets + data packets + CKSUM --> 128 bytes + 2 for checksum
03015E169700FFFEFFFEFFFEFF1EC006C002C0008000000000000000000000000000000000000000000000000000FFFFFFFFFFFFFFFFFFFFFF98415E1BA41ADE49A4431E6BA481FE2E26047E60AB033E0AAD845E59B2DC5E45B39ADE0AB604BE09BADC5E1F3D9ABE553F04FE48C29ADE3898031F26AD843F53AF44FF71B81F9F
2AF9 CKSUM (this one seems wrong)

EF01
FFFFFFFF
08 End of Data packet
0082 length of package = command packets + data packets + CKSUM --> 128 bytes + 2 for checksum
39C306376297D71C659B2C7C2E39441600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0618 CKSUM (this one is OK)


FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF







This is my first comment so please forgive if I do some mistake.
I'm using Adafruit Fingerprint sensor library with Arduino Uno and I'm getting the same output of show_fingerprint_templates example code i.e. the 3 frames you've pointed to.

Now I want to know that

Firstly : how did you came to conclusion about which one is ( OK) and which one is (WRONG). Like in the manual/datasheet it is stated that CKSUM  is equal to 'the arithmetic sum of package identifier, package length and
all package contents. Overflowing bits are omitted. high byte is
transferred first'.

Secondly : What will be the final correct template if we consider the above example?

Please help me I'm struggling with this problem of identifying the correct template (from past few weeks) so that I can store it and later upload back the correct template to the sensor.

Thank You

J-M-L

#31
Mar 13, 2019, 10:16 am Last Edit: Mar 13, 2019, 12:45 pm by J-M-L
this was what the OP posted

Code: [Select]
FFFFFFFFFFFFFFFFFF0165159200FFFEFFFEFFFEFFFEF80EC00680008000800080000000000000000000000000
008000000000000000000000000000000020AB78324242982B0DEF01FFFFFFFF0200825E1F56592A3ED8D9674201F900000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000056CEF01FFFFFFFF0200820
3015E169700FFFEFFFEFFFEFF1EC006C002C0008000000000000000000000000000000000000000000000000
000FFFFFFFFFFFFFFFFFFFFFF98415E1BA41ADE49A4431E6BA481FE2E26047E60AB033E0AAD845E59B2DC5E4
5B39ADE0AB604BE09BADC5E1F3D9ABE553F04FE48C29ADE3898031F26AD843F53AF44FF71B81F9F2AF9EF0
1FFFFFFFF08008239C306376297D71C659B2C7C2E3944160000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000618FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF


as the output of his request.  in that blurb or data we can recognize 3 frames starting with EF01

I color coded the format of a frame as:
data to be ignored
EF01
ADDER --> Default value is 0xFFFFFFFF
package identifier --> describe what type of information is in the package
length  --> length of package
The actual data
check sum


FFFFFFFFFFFFFFFFFF0165159200FFFEFFFEFFFEFFFEF80EC006800080008000800000000000000
00000000000008000000000000000000000000000000020AB78324242982B0D

EF01FFFFFFFF020082
5E1F56592A3ED8D9674201F9000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000

056C
EF01FFFFFFFF020082
03015E169700FFFEFFFEFFFEFF1EC006C002C000800000000000000000000000000000000000000
0000000000000FFFFFFFFFFFFFFFFFFFFFF98415E1BA41ADE49A4431E6BA481FE2E26047E60AB033E0AAD845
E59B2DC5E45B39ADE0AB604BE09BADC5E1F3D9ABE553F04FE48C29ADE3898031F26AD843F53AF44FF71B81F9F

2AF9
EF01FFFFFFFF080082
39C306376297D71C659B2C7C2E394416000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000

0618
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF



so we see we have 3 frames, the first two are of type 02, meaning 'Data packet' and the last one is of type 08 which means 'End of Data packet'. (01 would be a "Command packet", 07 would be an "Acknowledge packet")

we then see that the length of package is 0x0082(hex) which is 130 in decimal
The length of the packet is composed of the length of the data + the 2 bytes for the checksum --> 128 bytes + 2 for checksum = 130 --> so we have 128 bytes of data, which will be represented as 256 ASCII symbols for the data and 2 bytes for the checksum represented by 4 ASCII symbols (theoretical Max length is 256 bytes so the library creates large buffers just in case but here we get the 128 byte frames).

we then have the data followed by the checksum on 16 bits

To calculate the checksum the documentation states it's the arithmetic sum of package identifier, package length and all package content with Overflowing bits being omitted

package ID = 1 byte
package length = 2 bytes
package content = we have seen above it's 128 bytes

so to run the checksum we need 128+2+1 = 131 bytes, or 262 characters starting at the package ID

So you need to take the package ID, length and content and sum all the numeric value represented by each byte, so you need to read 2 ASCII symbols, high side first, build a byte value and add to the sum in a 16 bit unsigned variable ignoring overflow.

In the first example above this would be the stream of data
Code: [Select]
0200825E1F56592A3ED8D9674201F90000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

if you dump that into this test code
Code: [Select]
void getHexBufferCKSum()
{
  uint16_t cksum = 0;
  uint16_t lsb = 0, hsb = 0;
  boolean waitingForHigh = true;
  Serial.println(F("Enter HexBuffer (0..9 or A..F all caps):"));
  unsigned int nbBytes = 0;
  unsigned int nbCars = 0;
  while (1) {
    if (Serial.available()) {
      int r = Serial.read();
      if ((r != -1) && (r != '\n')) { // ignore and terminates on '\n'
        if ((r != '\r') && (((r >= '0') && (r <= '9')) || ((r >= 'A') && (r <= 'F')))) { // ignore '\r', handle only 0 to 9 and A to F
          uint8_t v;
          if ((r >= '0') && (r <= '9')) v = r - '0';
          else v = r - 'A' + 10;
          if (waitingForHigh) {
            hsb =  v;
          } else {
            lsb = v;
            cksum += 16 * hsb + lsb;
            nbBytes++; // got a full byte
          }
          waitingForHigh = !waitingForHigh;
          nbCars++;
        }
      } else break;
    }
  }

  Serial.print(F("received "));  Serial.print(nbCars);
  Serial.print(F(" characters ("));  Serial.print(nbBytes);
  Serial.print(F(" bytes), cksum is ")); Serial.println(cksum, HEX);
  if (nbCars != 2 * nbBytes)   Serial.println(F("*** received weird number of characters, check input ***"));
  Serial.println(F("-------------------"));

}

void setup() {
  Serial.begin(115200);
}

void loop() {
  getHexBufferCKSum();
}

you will see in your Serial console (set at 115200 bauds / sending NL to terminate)

Enter HexBuffer (0..9 or A..F all caps):
received 262 characters (131 bytes), cksum is 56C


So you can see that there is ineed 262 characters received and 56C(hex) is indeed the check sum 056C we had received for the first package

if you run the data for the third package you will see in your Serial console

Enter HexBuffer (0..9 or A..F all caps):
received 262 characters (131 bytes), cksum is 618


So you can see that there is ineed 262 characters received and 618(hex) is indeed the check sum 0618 we had received for the third package

but if you run that for the second package, you will see in your Serial console

Enter HexBuffer (0..9 or A..F all caps):
received 262 characters (131 bytes), cksum is 359D


So you can see that there is ineed 262 characters received BUT 359D(hex) is NOT the check sum 2AF9 we had received for the third package.. So something weird  there...
Hello - Please do not PM me for help,  others will benefit as well if you post your question publicly on the forums.
Bonjour Pas de messages privés SVP, postez dans le forum directement pour que ça profite à tous

dhananjayaggarwal

Thank You so much. You've helped me a lot
in understanding the dynamics and now I can work  with peace as now I know that I'm headed in the right direction.

Thank You

dhananjayaggarwal

One final thing I want to ask that if I'm writing template back to the sensor, I will be following the steps below. Can you point out if any mistake you think these points have:-
  • Since total size of template is 512 bytes, create two data frames containing 128 bytes of data each.
  • Send DownChar command first to the sensor and receive ready to send from sensor.
  • Start sending first data frame with 128 higher bytes and send data in Big Endian form i.e. higher byte first.
  • Now send the second data frame with package identifier as 'End of Data' in similar fashion
  • The above steps successfully downloads the template to the desired buffer which was mentioned while sending DownChar command in step 2.
  • Now store buffer to desired pageID.


These are the steps I will be following.

J-M-L

Since total size of template is 512 bytes, create two data frames containing 128 bytes of data each.
hum... 2 x 128 is not 512....

you can see above that extracting one profile actually required 3 frames

so you probably need to build the right number of frames based on what was actually received from the command to upload to the computer, and play that back the other way.

I'm on the go and don't have the device available so can't test anything - but that's how I would explore that
Hello - Please do not PM me for help,  others will benefit as well if you post your question publicly on the forums.
Bonjour Pas de messages privés SVP, postez dans le forum directement pour que ça profite à tous

dhananjayaggarwal

you can see above that extracting one profile actually required 3 frames

This point is where all I got confused. The Adafruit library of show_fingerprint_templates extracts the total of final 512 bytes out of which one frame is received as faulty always.

Also these 512 bytes of data contains other parts of frame like header, package identifier, package length, content, cksm.

Whereas the specification of sensor states that size of each template is 512 bytes. So should I keep the lower bytes as 0x00 to complete the 512 bytes of template size? Or I should just upload the 256 bytes which are OK out of three frames received.

I am really feeling stupid to ask these questions and really sorry for it. But I've went through manual multiple times and unable to find details about this.
Thank you for giving time.

J-M-L

I haven't done it as I did not have the need, just looking at the spec like you.

@nimit393 seems to say it has done it, but seems missing in action and refused to post his code... so up to you to reinvent the wheel

would need to explore
Hello - Please do not PM me for help,  others will benefit as well if you post your question publicly on the forums.
Bonjour Pas de messages privés SVP, postez dans le forum directement pour que ça profite à tous

dhananjayaggarwal

Still you've helped me a lot. I would definitely share if I got a success in it.
Thank you  :)

J-M-L

#38
Mar 13, 2019, 12:43 pm Last Edit: Mar 13, 2019, 12:43 pm by J-M-L
I would definitely share if I got a success in it.
would be good for the community! thx +1 karma as encouragement
Hello - Please do not PM me for help,  others will benefit as well if you post your question publicly on the forums.
Bonjour Pas de messages privés SVP, postez dans le forum directement pour que ça profite à tous

GVS

Hello.
Need help with this issue.
Is the topic still active?

J-M-L

Seems @dhananjayaggarwal did not succeed or decided not to share...
Hello - Please do not PM me for help,  others will benefit as well if you post your question publicly on the forums.
Bonjour Pas de messages privés SVP, postez dans le forum directement pour que ça profite à tous

GVS

This is upsetting.
Maybe you can help find the right direction.
Sorry for my English, I'm from Ukraine ...
My experience in programming arduino is not great, so many problems and questions arise. The challenge now is to clone the fingerprint database from one scanner to another. Having studied this topic, I managed to get a response from the scanner with the data packet, but they do not look like they showed here. The method of receipt as in message #24.
I use Arduino Nano + R307 fingerprint scanner. To send messages, your sketch from message # 12 and CoolTerm. The result is in the attached file. I can't understand how to extract the data necessary for cloning from it (((

J-M-L

I never did use have access to the same doc as you, as highlighted above... sorry can't help
Hello - Please do not PM me for help,  others will benefit as well if you post your question publicly on the forums.
Bonjour Pas de messages privés SVP, postez dans le forum directement pour que ça profite à tous

GVS

I'm at a standstill, maybe someone will point the right direction.
I do a fingerprint scan, convert it to a template with the RegModel command. The documentation says - "generate a template which is stroed back in both CharBuffer1 and CharBuffer2". As I understand it, the contents of the buffers should be the same. Having executed the comparison command - Match, I get confirmation of this. But if I try to output the contents of the buffers to the console with the command - UpChar, I see completely different data. Moreover, if I ask several times in a row to display the contents of the buffer neither doing anything else with the scanner, I get different values ...
In the attached file, data output from buffer No. 1 and several conclusions in a row from buffer No. 2.

Go Up