LibDriver AS608  1.0.0
AS608 full-featured driver
driver_as608_basic.c
Go to the documentation of this file.
1 
37 #include "driver_as608_basic.h"
38 
39 static as608_handle_t gs_handle;
40 static uint32_t gs_addr = 0;
50 uint8_t as608_basic_init(uint32_t addr)
51 {
52  uint8_t res;
53 
54  /* link interface function */
63 
64  /* as608 init */
65  res = as608_init(&gs_handle, addr);
66  if (res != 0)
67  {
68  as608_interface_debug_print("as608: init failed.\n");
69 
70  return 1;
71  }
72 #if (AS608_BASIC_SEND_CONFIG == 1)
73  /* set default port */
74  res = as608_set_port(&gs_handle, addr, AS608_BASIC_DEFAULT_PORT, &status);
75  if (res != 0)
76  {
77  as608_interface_debug_print("as608: set port failed.\n");
78  (void)as608_deinit(&gs_handle);
79 
80  return 1;
81  }
82  if (status != AS608_STATUS_OK)
83  {
84  as608_interface_debug_print("as608: status not ok.\n");
85  (void)as608_deinit(&gs_handle);
86 
87  return 1;
88  }
89 
90  /* set default baud rate */
91  res = as608_set_baud_rate(&gs_handle, addr, AS608_BASIC_DEFAULT_BAUD_RATE, &status);
92  if (res != 0)
93  {
94  as608_interface_debug_print("as608: set baud rate failed.\n");
95  (void)as608_deinit(&gs_handle);
96 
97  return 1;
98  }
99  if (status != AS608_STATUS_OK)
100  {
101  as608_interface_debug_print("as608: status not ok.\n");
102  (void)as608_deinit(&gs_handle);
103 
104  return 1;
105  }
106 
107  /* set default level */
108  res = as608_set_level(&gs_handle, addr, AS608_BASIC_DEFAULT_LEVEL, &status);
109  if (res != 0)
110  {
111  as608_interface_debug_print("as608: set level failed.\n");
112  (void)as608_deinit(&gs_handle);
113 
114  return 1;
115  }
116  if (status != AS608_STATUS_OK)
117  {
118  as608_interface_debug_print("as608: status not ok.\n");
119  (void)as608_deinit(&gs_handle);
120 
121  return 1;
122  }
123 
124  /* set default packet size */
125  res = as608_set_packet_size(&gs_handle, addr, AS608_BASIC_DEFAULT_PACKET_SIZE, &status);
126  if (res != 0)
127  {
128  as608_interface_debug_print("as608: set packet size failed.\n");
129  (void)as608_deinit(&gs_handle);
130 
131  return 1;
132  }
133  if (status != AS608_STATUS_OK)
134  {
135  as608_interface_debug_print("as608: status not ok.\n");
136  (void)as608_deinit(&gs_handle);
137 
138  return 1;
139  }
140 
141  /* set default password */
142  res = as608_set_password(&gs_handle, addr, AS608_BASIC_DEFAULT_PASSWORD, &status);
143  if (res != 0)
144  {
145  as608_interface_debug_print("as608: set password failed.\n");
146  (void)as608_deinit(&gs_handle);
147 
148  return 1;
149  }
150  if (status != AS608_STATUS_OK)
151  {
152  as608_interface_debug_print("as608: status not ok.\n");
153  (void)as608_deinit(&gs_handle);
154 
155  return 1;
156  }
157 
158  /* verify default password */
159  res = as608_verify_password(&gs_handle, addr, AS608_BASIC_DEFAULT_PASSWORD, &status);
160  if (res != 0)
161  {
162  as608_interface_debug_print("as608: verify password failed.\n");
163  (void)as608_deinit(&gs_handle);
164 
165  return 1;
166  }
167  if (status != AS608_STATUS_OK)
168  {
169  as608_interface_debug_print("as608: status not ok.\n");
170  (void)as608_deinit(&gs_handle);
171 
172  return 1;
173  }
174 
175  /* set default chip address */
176  res = as608_set_chip_address(&gs_handle, addr, AS608_BASIC_DEFAULT_ADDRESS, &status);
177  if (res != 0)
178  {
179  as608_interface_debug_print("as608: set chip address failed.\n");
180  (void)as608_deinit(&gs_handle);
181 
182  return 1;
183  }
184  if (status != AS608_STATUS_OK)
185  {
186  as608_interface_debug_print("as608: status not ok.\n");
187  (void)as608_deinit(&gs_handle);
188 
189  return 1;
190  }
191 #endif
192  /* set address */
193  gs_addr = addr;
194 
195  return 0;
196 }
197 
214 uint8_t as608_basic_input_fingerprint(void (*callback)(int8_t status, const char *const fmt, ...),
215  uint16_t *score,
216  uint16_t *page_number,
217  as608_status_t *status)
218 {
219  uint8_t res;
220  uint32_t timeout;
221 
222  /* max default time */
223  timeout = AS608_BASIC_DEFAULT_TIMEOUT;
224 
225  /* wait your finger */
226  while (timeout != 0)
227  {
228  /* run the callback */
229  if (callback != NULL)
230  {
231  /* output */
232  callback(0, "please put your finger on the sensor.\n");
233  }
234 
235  /* get image */
236  res = as608_get_image(&gs_handle, gs_addr, status);
237  if (res != 0)
238  {
239  return 1;
240  }
241  if (*status == AS608_STATUS_OK)
242  {
243  /* generate feature */
244  res = as608_generate_feature(&gs_handle, gs_addr, AS608_BUFFER_NUMBER_1, status);
245  if (res != 0)
246  {
247  return 1;
248  }
249  if (*status == AS608_STATUS_OK)
250  {
251  /* run the callback */
252  if (callback != NULL)
253  {
254  /* output */
255  callback(1, "please put your finger on the sensor again.\n");
256  }
257 
258  /* max default time */
259  timeout = AS608_BASIC_DEFAULT_TIMEOUT;
260 
261  /* wait your finger */
262  while (timeout != 0)
263  {
264  /* get image */
265  res = as608_get_image(&gs_handle, gs_addr, status);
266  if (res != 0)
267  {
268  return 1;
269  }
270  if (*status == AS608_STATUS_OK)
271  {
272  /* generate feature */
273  res = as608_generate_feature(&gs_handle, gs_addr, AS608_BUFFER_NUMBER_2, status);
274  if (res != 0)
275  {
276  return 1;
277  }
278  if (*status == AS608_STATUS_OK)
279  {
280  /* run the callback */
281  if (callback != NULL)
282  {
283  /* output */
284  callback(2, "generate feature success.\n");
285  }
286 
287  goto next;
288  }
289  else
290  {
291  /* run the callback */
292  if (callback != NULL)
293  {
294  /* output */
295  callback(-1, "error.\n");
296  }
297  }
298  }
299 
300  /* delay 1000ms */
302 
303  /* timeout-- */
304  timeout--;
305  }
306 
307  /* check timeout */
308  if (timeout == 0)
309  {
310  return 2;
311  }
312  }
313  else
314  {
315  /* run the callback */
316  if (callback != NULL)
317  {
318  /* output */
319  callback(-1, "error.\n");
320  }
321  }
322  }
323 
324  /* delay 1000ms */
326 
327  /* timeout-- */
328  timeout--;
329  }
330 
331  /* check timeout */
332  if (timeout == 0)
333  {
334  return 2;
335  }
336 
337  next:
338  /* match feature */
339  res = as608_match_feature(&gs_handle, gs_addr, score, status);
340  if (res != 0)
341  {
342  return 1;
343  }
344  if (*status != AS608_STATUS_OK)
345  {
346  /* run the callback */
347  if (callback != NULL)
348  {
349  /* output */
350  callback(-1, "error.\n");
351  }
352 
353  return 1;
354  }
355 
356  /* combine feature */
357  res = as608_combine_feature(&gs_handle, gs_addr, status);
358  if (res != 0)
359  {
360  return 1;
361  }
362  if (*status != AS608_STATUS_OK)
363  {
364  /* run the callback */
365  if (callback != NULL)
366  {
367  /* output */
368  callback(-1, "error.\n");
369  }
370 
371  return 1;
372  }
373 
374  /* get valid template number */
375  res = as608_get_valid_template_number(&gs_handle, gs_addr, page_number, status);
376  if (res != 0)
377  {
378  return 1;
379  }
380  if (*status != AS608_STATUS_OK)
381  {
382  /* run the callback */
383  if (callback != NULL)
384  {
385  /* output */
386  callback(-1, "error.\n");
387  }
388 
389  return 1;
390  }
391 
392  /* store feature */
393  res = as608_store_feature(&gs_handle, gs_addr, AS608_BUFFER_NUMBER_2, *page_number, status);
394  if (res != 0)
395  {
396  return 1;
397  }
398  if (*status != AS608_STATUS_OK)
399  {
400  /* run the callback */
401  if (callback != NULL)
402  {
403  /* output */
404  callback(-1, "error.\n");
405  }
406 
407  return 1;
408  }
409 
410  return 0;
411 }
412 
423 uint8_t as608_basic_verify(uint16_t *found_page, uint16_t *score, as608_status_t *status)
424 {
425  uint8_t res;
426 
427  /* get image */
428  res = as608_get_image(&gs_handle, gs_addr, status);
429  if (res != 0)
430  {
431  return 1;
432  }
433  if (*status != AS608_STATUS_OK)
434  {
435  return 1;
436  }
437 
438  /* generate feature */
439  res = as608_generate_feature(&gs_handle, gs_addr, AS608_BASIC_DEFAULT_FEATURE, status);
440  if (res != 0)
441  {
442  return 1;
443  }
444  if (*status != AS608_STATUS_OK)
445  {
446  return 1;
447  }
448 
449  /* search feature */
450  res = as608_search_feature(&gs_handle, gs_addr,
452  0, 300, found_page,
453  score, status);
454  if (res != 0)
455  {
456  return 1;
457  }
458 
459  return 0;
460 }
461 
472 uint8_t as608_basic_high_speed_verify(uint16_t *found_page, uint16_t *score, as608_status_t *status)
473 {
474  uint8_t res;
475 
476  /* get image */
477  res = as608_get_image(&gs_handle, gs_addr, status);
478  if (res != 0)
479  {
480  return 1;
481  }
482  if (*status != AS608_STATUS_OK)
483  {
484  return 1;
485  }
486 
487  /* generate feature */
488  res = as608_generate_feature(&gs_handle, gs_addr, AS608_BASIC_DEFAULT_FEATURE, status);
489  if (res != 0)
490  {
491  return 1;
492  }
493  if (*status != AS608_STATUS_OK)
494  {
495  return 1;
496  }
497 
498  /* high speed search feature */
499  res = as608_high_speed_search(&gs_handle, gs_addr,
501  0, 300, found_page,
502  score, status);
503  if (res != 0)
504  {
505  return 1;
506  }
507 
508  return 0;
509 }
510 
520 {
521  uint8_t res;
522 
523  /* print status */
524  res = as608_print_status(&gs_handle, status);
525  if (res != 0)
526  {
527  return 1;
528  }
529 
530  return 0;
531 }
532 
542 uint8_t as608_basic_delete_fingerprint(uint16_t page_number, as608_status_t *status)
543 {
544  uint8_t res;
545 
546  /* delete feature */
547  res = as608_delete_feature(&gs_handle, gs_addr, page_number, 1, status);
548  if (res != 0)
549  {
550  return 1;
551  }
552 
553  return 0;
554 }
555 
565 {
566  uint8_t res;
567 
568  /* empty all feature */
569  res = as608_empty_all_feature(&gs_handle, gs_addr, status);
570  if (res != 0)
571  {
572  return 1;
573  }
574 
575  return 0;
576 }
577 
585 uint8_t as608_basic_deinit(void)
586 {
587  /* deinit as608 */
588  if (as608_deinit(&gs_handle) != 0)
589  {
590  return 1;
591  }
592 
593  return 0;
594 }
driver as608 basic header file
uint8_t as608_set_port(as608_handle_t *handle, uint32_t addr, as608_bool_t enable, as608_status_t *status)
enable or disable port
uint8_t as608_set_packet_size(as608_handle_t *handle, uint32_t addr, as608_packet_size_t size, as608_status_t *status)
set packet size
uint8_t as608_init(as608_handle_t *handle, uint32_t addr)
initialize the chip
Definition: driver_as608.c:465
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_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_set_password(as608_handle_t *handle, uint32_t addr, uint32_t password, as608_status_t *status)
set password
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_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_set_level(as608_handle_t *handle, uint32_t addr, as608_level_t level, as608_status_t *status)
set level
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_set_baud_rate(as608_handle_t *handle, uint32_t addr, uint8_t n_9600, as608_status_t *status)
set baud rate
uint8_t as608_deinit(as608_handle_t *handle)
close the chip
Definition: driver_as608.c:575
uint8_t as608_set_chip_address(as608_handle_t *handle, uint32_t addr, uint32_t new_addr, as608_status_t *status)
set the chip address
uint8_t as608_empty_all_feature(as608_handle_t *handle, uint32_t addr, as608_status_t *status)
empty all feature
uint8_t as608_verify_password(as608_handle_t *handle, uint32_t addr, uint32_t password, as608_status_t *status)
verify password
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
#define AS608_BASIC_DEFAULT_PACKET_SIZE
#define AS608_BASIC_DEFAULT_LEVEL
#define AS608_BASIC_DEFAULT_ADDRESS
uint8_t as608_basic_empty_fingerprint(as608_status_t *status)
basic example empty fingerprint
uint8_t as608_basic_init(uint32_t addr)
basic example init
uint8_t as608_basic_delete_fingerprint(uint16_t page_number, as608_status_t *status)
basic example delete fingerprint
#define AS608_BASIC_DEFAULT_FEATURE
uint8_t as608_basic_print_status(as608_status_t status)
basic example print status
uint8_t as608_basic_input_fingerprint(void(*callback)(int8_t status, const char *const fmt,...), uint16_t *score, uint16_t *page_number, as608_status_t *status)
basic example input fingerprint
uint8_t as608_basic_deinit(void)
basic example deinit
uint8_t as608_basic_verify(uint16_t *found_page, uint16_t *score, as608_status_t *status)
basic example verify
#define AS608_BASIC_DEFAULT_PASSWORD
#define AS608_BASIC_DEFAULT_BAUD_RATE
uint8_t as608_basic_high_speed_verify(uint16_t *found_page, uint16_t *score, as608_status_t *status)
basic example high speed verify
#define AS608_BASIC_DEFAULT_TIMEOUT
#define AS608_BASIC_DEFAULT_PORT
as608 basic example default definition
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
as608 handle structure definition
Definition: driver_as608.h:213