LibDriver AS608  1.0.0
AS608 full-featured driver
driver_as608_fingerprint_test.c
Go to the documentation of this file.
1 
38 #include <stdlib.h>
39 
40 static as608_handle_t gs_handle;
41 static uint8_t gs_buffer[48 * 1024];
51 uint8_t as608_fingerprint_test(uint32_t addr)
52 {
53  uint8_t res;
54  uint8_t j;
55  uint8_t table[32];
56  uint16_t number;
57  uint16_t score;
58  uint16_t page_number;
59  uint16_t found_page;
60  uint16_t output_len;
61  uint16_t i;
62  uint32_t timeout;
63  as608_info_t info;
64  as608_status_t status;
65 
66  /* link interface function */
75 
76  /* get as608 information */
77  res = as608_info(&info);
78  if (res != 0)
79  {
80  as608_interface_debug_print("as608: get info failed.\n");
81 
82  return 1;
83  }
84  else
85  {
86  /* print chip information */
87  as608_interface_debug_print("as608: chip is %s.\n", info.chip_name);
88  as608_interface_debug_print("as608: manufacturer is %s.\n", info.manufacturer_name);
89  as608_interface_debug_print("as608: interface is %s.\n", info.interface);
90  as608_interface_debug_print("as608: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
91  as608_interface_debug_print("as608: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
92  as608_interface_debug_print("as608: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
93  as608_interface_debug_print("as608: max current is %0.2fmA.\n", info.max_current_ma);
94  as608_interface_debug_print("as608: max temperature is %0.1fC.\n", info.temperature_max);
95  as608_interface_debug_print("as608: min temperature is %0.1fC.\n", info.temperature_min);
96  }
97 
98  /* start fingerprint test */
99  as608_interface_debug_print("as608: start fingerprint test.\n");
100 
101  /* as608 init */
102  res = as608_init(&gs_handle, addr);
103  if (res != 0)
104  {
105  as608_interface_debug_print("as608: init failed.\n");
106 
107  return 1;
108  }
109 
110  /* output */
111  as608_interface_debug_print("as608: please put your finger on the sensor.\n");
112 
113  /* max 10s */
114  timeout = 10;
115 
116  /* wait your finger */
117  while (timeout != 0)
118  {
119  /* get image */
120  res = as608_get_image(&gs_handle, addr, &status);
121  if (res != 0)
122  {
123  as608_interface_debug_print("as608: get image failed.\n");
124  (void)as608_deinit(&gs_handle);
125 
126  return 1;
127  }
128  if (status == AS608_STATUS_OK)
129  {
130  /* generate feature */
131  res = as608_generate_feature(&gs_handle, addr, AS608_BUFFER_NUMBER_1, &status);
132  if (res != 0)
133  {
134  as608_interface_debug_print("as608: generate feature failed.\n");
135  (void)as608_deinit(&gs_handle);
136 
137  return 1;
138  }
139  if (status == AS608_STATUS_OK)
140  {
141  /* output */
142  as608_interface_debug_print("as608: generate feature success.\n");
143 
144  /* output */
145  as608_interface_debug_print("as608: please put your finger on the sensor again.\n");
146 
147  /* delay 2000ms */
149 
150  /* max 10s */
151  timeout = 10;
152 
153  /* wait your finger */
154  while (timeout != 0)
155  {
156  /* get image */
157  res = as608_get_image(&gs_handle, addr, &status);
158  if (res != 0)
159  {
160  as608_interface_debug_print("as608: get image failed.\n");
161  (void)as608_deinit(&gs_handle);
162 
163  return 1;
164  }
165  if (status == AS608_STATUS_OK)
166  {
167  /* generate feature */
168  res = as608_generate_feature(&gs_handle, addr, AS608_BUFFER_NUMBER_2, &status);
169  if (res != 0)
170  {
171  as608_interface_debug_print("as608: generate feature failed.\n");
172  (void)as608_deinit(&gs_handle);
173 
174  return 1;
175  }
176  if (status == AS608_STATUS_OK)
177  {
178  /* output */
179  as608_interface_debug_print("as608: generate feature success.\n");
180 
181  goto next;
182  }
183  else
184  {
185  (void)as608_print_status(&gs_handle, status);
186  }
187  }
188 
189  /* delay 1000ms */
191 
192  /* timeout-- */
193  timeout--;
194  }
195 
196  /* check timeout */
197  if (timeout == 0)
198  {
199  as608_interface_debug_print("as608: timeout.\n");
200  (void)as608_deinit(&gs_handle);
201 
202  return 1;
203  }
204  }
205  else
206  {
207  (void)as608_print_status(&gs_handle, status);
208  }
209  }
210 
211  /* delay 1000ms */
213 
214  /* timeout-- */
215  timeout--;
216  }
217 
218  /* check timeout */
219  if (timeout == 0)
220  {
221  as608_interface_debug_print("as608: timeout.\n");
222  (void)as608_deinit(&gs_handle);
223 
224  return 1;
225  }
226 
227  next:
228 
229  /* match feature */
230  res = as608_match_feature(&gs_handle, addr, &score, &status);
231  if (res != 0)
232  {
233  as608_interface_debug_print("as608: match feature failed.\n");
234  (void)as608_deinit(&gs_handle);
235 
236  return 1;
237  }
238  if (status != AS608_STATUS_OK)
239  {
240  (void)as608_print_status(&gs_handle, status);
241  (void)as608_deinit(&gs_handle);
242 
243  return 1;
244  }
245  else
246  {
247  as608_interface_debug_print("as608: match feature and score is %d.\n", score);
248  }
249 
250  /* combine feature */
251  res = as608_combine_feature(&gs_handle, addr, &status);
252  if (res != 0)
253  {
254  as608_interface_debug_print("as608: combine feature failed.\n");
255  (void)as608_deinit(&gs_handle);
256 
257  return 1;
258  }
259  if (status != AS608_STATUS_OK)
260  {
261  (void)as608_print_status(&gs_handle, status);
262  (void)as608_deinit(&gs_handle);
263 
264  return 1;
265  }
266  else
267  {
268  as608_interface_debug_print("as608: combine feature.\n");
269  }
270 
271  /* store feature */
272  page_number = rand() % 300;
273  res = as608_store_feature(&gs_handle, addr, AS608_BUFFER_NUMBER_2, page_number, &status);
274  if (res != 0)
275  {
276  as608_interface_debug_print("as608: store feature failed.\n");
277  (void)as608_deinit(&gs_handle);
278 
279  return 1;
280  }
281  if (status != AS608_STATUS_OK)
282  {
283  (void)as608_print_status(&gs_handle, status);
284  (void)as608_deinit(&gs_handle);
285 
286  return 1;
287  }
288  else
289  {
290  as608_interface_debug_print("as608: store feature to page %d.\n", page_number);
291  }
292 
293  /* output */
294  as608_interface_debug_print("as608: please put your finger on the sensor.\n");
295 
296  /* delay 2000ms */
298 
299  /* max 10s */
300  timeout = 10;
301 
302  /* wait your finger */
303  while (timeout != 0)
304  {
305  /* get image */
306  res = as608_get_image(&gs_handle, addr, &status);
307  if (res != 0)
308  {
309  as608_interface_debug_print("as608: get image failed.\n");
310  (void)as608_deinit(&gs_handle);
311 
312  return 1;
313  }
314  if (status == AS608_STATUS_OK)
315  {
316  /* generate feature */
317  res = as608_generate_feature(&gs_handle, addr, AS608_BUFFER_NUMBER_1, &status);
318  if (res != 0)
319  {
320  as608_interface_debug_print("as608: generate feature failed.\n");
321  (void)as608_deinit(&gs_handle);
322 
323  return 1;
324  }
325  if (status == AS608_STATUS_OK)
326  {
327  /* high speed search */
328  res = as608_high_speed_search(&gs_handle, addr, AS608_BUFFER_NUMBER_1,
329  0, 300, &found_page,
330  &score, &status);
331  if (res != 0)
332  {
333  as608_interface_debug_print("as608: search feature failed.\n");
334  (void)as608_deinit(&gs_handle);
335 
336  return 1;
337  }
338  if (status == AS608_STATUS_OK)
339  {
340  as608_interface_debug_print("as608: high speed found in the page %d and score is %d.\n", found_page, score);
341 
342  break;
343  }
344  else
345  {
346  (void)as608_print_status(&gs_handle, status);
347  (void)as608_deinit(&gs_handle);
348 
349  return 1;
350  }
351  }
352  else
353  {
354  (void)as608_print_status(&gs_handle, status);
355  (void)as608_deinit(&gs_handle);
356 
357  return 1;
358  }
359  }
360 
361  /* delay 1000ms */
363 
364  /* timeout-- */
365  timeout--;
366  }
367 
368  /* check timeout */
369  if (timeout == 0)
370  {
371  as608_interface_debug_print("as608: timeout.\n");
372  (void)as608_deinit(&gs_handle);
373 
374  return 1;
375  }
376 
377  /* output */
378  as608_interface_debug_print("as608: please put your finger on the sensor.\n");
379 
380  /* delay 2000ms */
382 
383  /* max 10s */
384  timeout = 10;
385 
386  /* wait your finger */
387  while (timeout != 0)
388  {
389  /* get image */
390  res = as608_get_image(&gs_handle, addr, &status);
391  if (res != 0)
392  {
393  as608_interface_debug_print("as608: get image failed.\n");
394  (void)as608_deinit(&gs_handle);
395 
396  return 1;
397  }
398  if (status == AS608_STATUS_OK)
399  {
400  /* generate feature */
401  res = as608_generate_feature(&gs_handle, addr, AS608_BUFFER_NUMBER_1, &status);
402  if (res != 0)
403  {
404  as608_interface_debug_print("as608: generate feature failed.\n");
405  (void)as608_deinit(&gs_handle);
406 
407  return 1;
408  }
409  if (status == AS608_STATUS_OK)
410  {
411  /* search */
412  res = as608_search_feature(&gs_handle, addr, AS608_BUFFER_NUMBER_1,
413  0, 300, &found_page,
414  &score, &status);
415  if (res != 0)
416  {
417  as608_interface_debug_print("as608: search feature failed.\n");
418  (void)as608_deinit(&gs_handle);
419 
420  return 1;
421  }
422  if (status == AS608_STATUS_OK)
423  {
424  as608_interface_debug_print("as608: found in the page %d and score is %d.\n", found_page, score);
425 
426  break;
427  }
428  else
429  {
430  (void)as608_print_status(&gs_handle, status);
431  (void)as608_deinit(&gs_handle);
432 
433  return 1;
434  }
435  }
436  else
437  {
438  (void)as608_print_status(&gs_handle, status);
439  (void)as608_deinit(&gs_handle);
440 
441  return 1;
442  }
443  }
444 
445  /* delay 1000ms */
447 
448  /* timeout-- */
449  timeout--;
450  }
451 
452  /* check timeout */
453  if (timeout == 0)
454  {
455  as608_interface_debug_print("as608: timeout.\n");
456  (void)as608_deinit(&gs_handle);
457 
458  return 1;
459  }
460 
461  /* get valid template number */
462  res = as608_get_valid_template_number(&gs_handle, addr, &number, &status);
463  if (res != 0)
464  {
465  as608_interface_debug_print("as608: get valid template number failed.\n");
466  (void)as608_deinit(&gs_handle);
467 
468  return 1;
469  }
470  if (status != AS608_STATUS_OK)
471  {
472  (void)as608_print_status(&gs_handle, status);
473  (void)as608_deinit(&gs_handle);
474 
475  return 1;
476  }
477  else
478  {
479  as608_interface_debug_print("as608: valid template number is %d.\n", number);
480  }
481 
482  for (j = 0; j < 4; j++)
483  {
484  res = as608_get_index_table(&gs_handle, addr, j, table, &status);
485  if (res != 0)
486  {
487  as608_interface_debug_print("as608: get index table failed.\n");
488  (void)as608_deinit(&gs_handle);
489 
490  return 1;
491  }
492 
493  as608_interface_debug_print("index table %d: \n", j);
494 
495  /* output */
496  for (i = 0; i < 32; i++)
497  {
498  as608_interface_debug_print("0x%02X ", table[i]);
499  }
501  }
502 
503  /* load feature */
504  res = as608_load_feature(&gs_handle, addr, AS608_BUFFER_NUMBER_2, page_number, &status);
505  if (res != 0)
506  {
507  as608_interface_debug_print("as608: load feature failed.\n");
508  (void)as608_deinit(&gs_handle);
509 
510  return 1;
511  }
512  if (status != AS608_STATUS_OK)
513  {
514  (void)as608_print_status(&gs_handle, status);
515  (void)as608_deinit(&gs_handle);
516 
517  return 1;
518  }
519  else
520  {
521  as608_interface_debug_print("as608: load feature from page number %d.\n", page_number);
522  }
523 
524  /* upload feature */
525  output_len = 65535;
526  res = as608_upload_feature(&gs_handle, addr, AS608_BUFFER_NUMBER_2, gs_buffer, &output_len, &status);
527  if (res != 0)
528  {
529  as608_interface_debug_print("as608: upload feature failed.\n");
530  (void)as608_deinit(&gs_handle);
531 
532  return 1;
533  }
534  if (status != AS608_STATUS_OK)
535  {
536  (void)as608_print_status(&gs_handle, status);
537  (void)as608_deinit(&gs_handle);
538 
539  return 1;
540  }
541  else
542  {
543  as608_interface_debug_print("as608: upload feature is %dbytes.\n", output_len);
544  /* output */
545  for (i = 0; i < output_len; i++)
546  {
547  as608_interface_debug_print("0x%02X ", gs_buffer[i]);
548  }
550  }
551 
552  /* download feature */
553  res = as608_download_feature(&gs_handle, addr, AS608_BUFFER_NUMBER_1, gs_buffer, output_len, &status);
554  if (res != 0)
555  {
556  as608_interface_debug_print("as608: download feature failed.\n");
557  (void)as608_deinit(&gs_handle);
558 
559  return 1;
560  }
561  if (status != AS608_STATUS_OK)
562  {
563  (void)as608_print_status(&gs_handle, status);
564  (void)as608_deinit(&gs_handle);
565 
566  return 1;
567  }
568  else
569  {
570  as608_interface_debug_print("as608: download feature ok.\n");
571  }
572 
573  /* upload image */
574  output_len = 65535;
575  res = as608_upload_image(&gs_handle, addr, gs_buffer, &output_len, &status);
576  if (res != 0)
577  {
578  as608_interface_debug_print("as608: upload image failed.\n");
579  (void)as608_deinit(&gs_handle);
580 
581  return 1;
582  }
583  if (status != AS608_STATUS_OK)
584  {
585  (void)as608_print_status(&gs_handle, status);
586  (void)as608_deinit(&gs_handle);
587 
588  return 1;
589  }
590  else
591  {
592  as608_interface_debug_print("as608: upload image is %dbytes.\n", output_len);
593  }
594 
595  /* download image */
596  res = as608_download_image(&gs_handle, addr, gs_buffer, output_len, &status);
597  if (res != 0)
598  {
599  as608_interface_debug_print("as608: download image failed.\n");
600  (void)as608_deinit(&gs_handle);
601 
602  return 1;
603  }
604  if (status != AS608_STATUS_OK)
605  {
606  (void)as608_print_status(&gs_handle, status);
607  (void)as608_deinit(&gs_handle);
608 
609  return 1;
610  }
611  else
612  {
613  as608_interface_debug_print("as608: download image ok.\n");
614  }
615 
616  /* output */
617  as608_interface_debug_print("as608: please put your another finger on the sensor.\n");
618 
619  /* delay 2000ms */
621 
622  /* max 10s */
623  timeout = 10;
624 
625  /* wait your finger */
626  while (timeout != 0)
627  {
628  /* enroll */
629  res = as608_enroll(&gs_handle, addr, &number, &status);
630  if (res != 0)
631  {
632  as608_interface_debug_print("as608: enroll failed.\n");
633  (void)as608_deinit(&gs_handle);
634 
635  return 1;
636  }
637  if (status == AS608_STATUS_OK)
638  {
639  as608_interface_debug_print("as608: enroll ok with page number %d.\n", number);
640 
641  break;
642  }
643 
644  /* delay 1000ms */
646 
647  /* timeout-- */
648  timeout--;
649  }
650 
651  /* check timeout */
652  if (timeout == 0)
653  {
654  as608_interface_debug_print("as608: timeout.\n");
655  (void)as608_deinit(&gs_handle);
656 
657  return 1;
658  }
659 
660  /* output */
661  as608_interface_debug_print("as608: please put your another finger on the sensor.\n");
662 
663  /* delay 2000ms */
665 
666  /* max 10s */
667  timeout = 10;
668 
669  /* wait your finger */
670  while (timeout != 0)
671  {
672  /* enroll */
673  res = as608_identify(&gs_handle, addr, &number, &score, &status);
674  if (res != 0)
675  {
676  as608_interface_debug_print("as608: enroll failed.\n");
677  (void)as608_deinit(&gs_handle);
678 
679  return 1;
680  }
681  if (status == AS608_STATUS_OK)
682  {
683  as608_interface_debug_print("as608: identify ok with page number %d and score %d.\n", number, score);
684 
685  break;
686  }
687 
688  /* delay 1000ms */
690 
691  /* timeout-- */
692  timeout--;
693  }
694 
695  /* check timeout */
696  if (timeout == 0)
697  {
698  as608_interface_debug_print("as608: timeout.\n");
699  (void)as608_deinit(&gs_handle);
700 
701  return 1;
702  }
703 
704  /* delete feature */
705  res = as608_delete_feature(&gs_handle, addr, page_number, 1, &status);
706  if (res != 0)
707  {
708  as608_interface_debug_print("as608: delete feature failed.\n");
709  (void)as608_deinit(&gs_handle);
710 
711  return 1;
712  }
713  if (status != AS608_STATUS_OK)
714  {
715  (void)as608_print_status(&gs_handle, status);
716  (void)as608_deinit(&gs_handle);
717 
718  return 1;
719  }
720  else
721  {
722  as608_interface_debug_print("as608: delete feature in page %d.\n", page_number);
723  }
724 
725  /* empty all feature */
726  res = as608_empty_all_feature(&gs_handle, addr, &status);
727  if (res != 0)
728  {
729  as608_interface_debug_print("as608: empty all feature failed.\n");
730  (void)as608_deinit(&gs_handle);
731 
732  return 1;
733  }
734  if (status != AS608_STATUS_OK)
735  {
736  (void)as608_print_status(&gs_handle, status);
737  (void)as608_deinit(&gs_handle);
738 
739  return 1;
740  }
741  else
742  {
743  as608_interface_debug_print("as608: empty all feature.\n");
744  }
745 
746  /* finish fingerprint test */
747  as608_interface_debug_print("as608: finish fingerprint test.\n");
748  (void)as608_deinit(&gs_handle);
749 
750  return 0;
751 }
driver as608 fingerprint test header file
uint8_t as608_download_image(as608_handle_t *handle, uint32_t addr, uint8_t *input_buffer, uint16_t input_len, as608_status_t *status)
download image
uint8_t as608_init(as608_handle_t *handle, uint32_t addr)
initialize the chip
Definition: driver_as608.c:465
uint8_t as608_load_feature(as608_handle_t *handle, uint32_t addr, as608_buffer_number_t num, uint16_t page_number, as608_status_t *status)
load feature
uint8_t as608_generate_feature(as608_handle_t *handle, uint32_t addr, as608_buffer_number_t num, as608_status_t *status)
generate feature
Definition: driver_as608.c:702
uint8_t as608_get_index_table(as608_handle_t *handle, uint32_t addr, uint8_t num, uint8_t table[32], as608_status_t *status)
get index table
uint8_t as608_store_feature(as608_handle_t *handle, uint32_t addr, as608_buffer_number_t num, uint16_t page_number, as608_status_t *status)
store feature
Definition: driver_as608.c:973
as608_status_t
as608 status enumeration definition
Definition: driver_as608.h:153
uint8_t as608_info(as608_info_t *info)
get chip's information
uint8_t as608_upload_image(as608_handle_t *handle, uint32_t addr, uint8_t *output_buffer, uint16_t *output_len, as608_status_t *status)
upload image
uint8_t as608_get_valid_template_number(as608_handle_t *handle, uint32_t addr, uint16_t *num, as608_status_t *status)
get valid template number
uint8_t as608_search_feature(as608_handle_t *handle, uint32_t addr, as608_buffer_number_t num, uint16_t start_page, uint16_t page_number, uint16_t *found_page, uint16_t *score, as608_status_t *status)
search feature
Definition: driver_as608.c:836
uint8_t as608_get_image(as608_handle_t *handle, uint32_t addr, as608_status_t *status)
get image
Definition: driver_as608.c:638
uint8_t as608_download_feature(as608_handle_t *handle, uint32_t addr, as608_buffer_number_t num, uint8_t *input_buffer, uint16_t input_len, as608_status_t *status)
download feature
uint8_t as608_combine_feature(as608_handle_t *handle, uint32_t addr, as608_status_t *status)
combine feature
Definition: driver_as608.c:908
uint8_t as608_print_status(as608_handle_t *handle, as608_status_t status)
print status
uint8_t as608_match_feature(as608_handle_t *handle, uint32_t addr, uint16_t *score, as608_status_t *status)
match feature
Definition: driver_as608.c:767
uint8_t as608_delete_feature(as608_handle_t *handle, uint32_t addr, uint16_t page_number, uint16_t number, as608_status_t *status)
delete feature
uint8_t as608_upload_feature(as608_handle_t *handle, uint32_t addr, as608_buffer_number_t num, uint8_t *output_buffer, uint16_t *output_len, as608_status_t *status)
upload feature
uint8_t as608_deinit(as608_handle_t *handle)
close the chip
Definition: driver_as608.c:575
uint8_t as608_identify(as608_handle_t *handle, uint32_t addr, uint16_t *page_number, uint16_t *score, as608_status_t *status)
identify
uint8_t as608_empty_all_feature(as608_handle_t *handle, uint32_t addr, as608_status_t *status)
empty all feature
uint8_t as608_enroll(as608_handle_t *handle, uint32_t addr, uint16_t *page_number, as608_status_t *status)
enroll
uint8_t as608_high_speed_search(as608_handle_t *handle, uint32_t addr, as608_buffer_number_t buffer_number, uint16_t start_page, uint16_t page_number, uint16_t *found_page, uint16_t *score, as608_status_t *status)
high speed search
@ AS608_STATUS_OK
Definition: driver_as608.h:154
@ AS608_BUFFER_NUMBER_2
Definition: driver_as608.h:97
@ AS608_BUFFER_NUMBER_1
Definition: driver_as608.h:96
uint8_t as608_interface_uart_init(void)
interface uart init
uint8_t as608_interface_uart_flush(void)
interface uart flush
uint8_t as608_interface_uart_deinit(void)
interface uart deinit
uint16_t as608_interface_uart_read(uint8_t *buf, uint16_t len)
interface uart read
void as608_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t as608_interface_uart_write(uint8_t *buf, uint16_t len)
interface uart write
void as608_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t as608_fingerprint_test(uint32_t addr)
fingerprint test
as608 handle structure definition
Definition: driver_as608.h:213
as608 information structure definition
Definition: driver_as608.h:231
float temperature_max
Definition: driver_as608.h:239
float supply_voltage_max_v
Definition: driver_as608.h:236
uint32_t driver_version
Definition: driver_as608.h:240
float temperature_min
Definition: driver_as608.h:238
float max_current_ma
Definition: driver_as608.h:237
char manufacturer_name[32]
Definition: driver_as608.h:233
float supply_voltage_min_v
Definition: driver_as608.h:235
char interface[8]
Definition: driver_as608.h:234
char chip_name[32]
Definition: driver_as608.h:232