久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 1105|回復: 0
打印 上一主題 下一主題
收起左側(cè)

FPM32C指紋模塊源程序

[復制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:334697 發(fā)表于 2023-7-20 19:52 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
  1. #include <string.h>
  2. #include "fingerprint_action.h"
  3. #include "fingerprint_type.h"
  4. #include "fingerprint_protocol.h"

  5. static U8Bit s_recv_buffer[256];
  6. static U8Bit s_send_buffer[256];
  7. static U8Bit s_ftrDataBuffer[8196];        //待上傳下載的指紋數(shù)據(jù)buffer
  8. static U32Bit s_ftrDataLength = 0;          //待上傳下載的指紋數(shù)據(jù)buffer長度

  9. #define CHECK_BIT(value, x) ((value) & (1 << (x)))

  10. void Delay_ms(U32Bit delaytime)
  11. {
  12.      U32Bit i;
  13.      U32Bit j;

  14.      for (j = 0; j < delaytime; j++)
  15.      {
  16.          for (i = 0; i < 10000; i++)
  17.          {
  18.              //根據(jù)不同的開發(fā)環(huán)境實現(xiàn)延時
  19.          }
  20.      }
  21.      i=j;
  22. }


  23. void getID(void)
  24. {
  25.     U32Bit errorCode;
  26.         S32Bit ret;

  27.     FP_moduleID_t moduleID;

  28.     ret = FP_action_getID(&moduleID, &errorCode);
  29.     if(FP_OK == ret && 0 == errorCode)
  30.     {
  31.         //get ID ok
  32.     }
  33. }

  34. void enroll(void)
  35. {
  36.     U32Bit errorCode;
  37.         S32Bit ret;
  38.     U8Bit index = 1;
  39.     U8Bit isTouch;
  40.         U16Bit SaveID;

  41.     FP_enrollResult_t enrollResult;
  42.     enrollResult.fingerID = 0;
  43.     enrollResult.progress = 0;

  44.     //第一次直接enrollStart
  45.     goto EnrollStartLabel;

  46.     //
  47.     //每次enroll過后,確保手指要抬起來以后,再次按壓
  48. FingerLeaveLabel:               
  49.     FP_action_check_finger_is_touch(&isTouch, &errorCode);
  50.     if(0 != isTouch || COMP_CODE_OK != errorCode)
  51.     {
  52.         // 當isTouch不是0的時候,意味著手指在上,
  53.         //提示用戶手指離開sensor再次按壓
  54.         //printf("lift your finger please !");
  55.         //延時 200 ms
  56.                 Delay_ms(200);
  57.         goto FingerLeaveLabel;
  58.     }

  59.     //開始注冊
  60. EnrollStartLabel:
  61.     ret = FP_action_enroll_start(index, &errorCode);
  62.     if(COMP_CODE_OK != errorCode || FP_OK != ret)
  63.     {
  64.             Delay_ms(100);
  65.                 //可能上電初始化未完成或睡眠喚醒初始化中
  66.                 goto EnrollStartLabel;
  67.         }
  68.         else
  69.         {
  70.                 //可延時100ms后發(fā)送獲取注冊結(jié)果命令,采圖后需要大概這么長時間處理
  71.                 Delay_ms(100);
  72.         }

  73.     //獲取注冊結(jié)果
  74. EnrollResultLabel:
  75.     ret = FP_action_get_enroll_result(&enrollResult, &errorCode);
  76.     if(FP_DEVICE_TIMEOUT_ERROR == ret)
  77.         {
  78.                 //接受數(shù)據(jù)超時,根據(jù)接受數(shù)據(jù)所設(shè)超時時間適當延時。
  79.                 Delay_ms(100);
  80.                 goto EnrollResultLabel;
  81.         }

  82.     if(COMP_CODE_OK == errorCode)
  83.     {
  84.         //如果errorCode 是COMP_CODE_OK,說明本次enroll執(zhí)行完成,
  85.         //此時可以查看enrollResult.progress是否增加,如果增加,說明本次enroll成功

  86.         //如果progress >= 100 ,說明整個注冊流程成功結(jié)束,開始根據(jù)enrollResult.fingerID保存指紋
  87.         if(enrollResult.progress >= 0x64)
  88.         {
  89.             goto SaveStartLabel;
  90.         }
  91.         else
  92.         {
  93.             //如果progress < 100, 手指離開sensor,再次按壓,繼續(xù)注冊
  94.             index++;
  95.             //延時 100 ms
  96.             Delay_ms(100);
  97.             goto FingerLeaveLabel;
  98.         }
  99.     }
  100.     else if(COMP_CODE_CMD_NOT_FINISHED == errorCode)
  101.     {
  102.         //errorCode == COMP_CODE_CMD_NOT_FINISHED意味著sensor還沒有處理完指紋數(shù)據(jù)或沒有按壓手指,
  103.         //適當延時,再次獲取結(jié)果
  104.         //延時 100 ms
  105.         Delay_ms(100);
  106.         goto EnrollResultLabel;
  107.     }
  108.     else if(COMP_CODE_SAME_ID == errorCode)
  109.     {
  110.         //errorCode == COMP_CODE_SAME_ID意味著與已注冊指紋重復,需換手指注冊
  111.         //適當延時,再次獲取結(jié)果
  112.         //延時 100 ms
  113.         Delay_ms(100);
  114.         goto EnrollResultLabel;
  115.     }
  116.         else if(COMP_CODE_NO_FINGER_DETECT == errorCode)
  117.         {
  118.                 //errorCode == COMP_CODE_NO_FINGER_DETECT意味著超時還沒按壓手指
  119.         //重新注冊
  120.         }
  121.         else if(COMP_CODE_OTHER_ERROR == errorCode)
  122.         {
  123.          goto EnrollStartLabel;
  124.         }
  125.         else if(COMP_CODE_NO_REQ_CMD == errorCode)
  126.         {
  127.                 goto EnrollStartLabel;
  128.         }
  129.         else
  130.     {
  131.         //圖像質(zhì)量不好,手指可能按壓過重、過輕、或者太過潮濕等,繼續(xù)enrollStart即可,也可根據(jù)Elock用戶手冊細化處理
  132.         //延時 200 ms
  133.             Delay_ms(200);
  134.         goto EnrollStartLabel;
  135.     }

  136.     //保存指紋開始
  137.     //enrollResult.fingerID會根據(jù)模組回復的推薦id去保存,編號從00開始
  138. SaveStartLabel:
  139.     ret = FP_action_save_start(enrollResult.fingerID, &errorCode);
  140.     if(COMP_CODE_OK != errorCode || FP_OK != ret)
  141.     {
  142.             Delay_ms(100);
  143.                 goto SaveStartLabel;
  144.         }

  145.         Delay_ms(200);
  146.     //獲取保存指紋結(jié)果
  147. SaveResultLabel://【保存指紋開始命令】發(fā)送后,模組需操作flash,這期間大概200ms發(fā)送【獲取保存指紋結(jié)果】沒有數(shù)據(jù)回復,可超時重發(fā)
  148.     ret = FP_action_get_save_result(&errorCode, &SaveID);
  149.         if(FP_DEVICE_TIMEOUT_ERROR == ret)
  150.         {
  151.                 //接受數(shù)據(jù)超時,根據(jù)接受數(shù)據(jù)所設(shè)超時時間適當延時。
  152.                 Delay_ms(100);
  153.                 goto SaveResultLabel;
  154.         }
  155.         
  156.     if(COMP_CODE_OK == errorCode)
  157.     {
  158.             //查看保存成功的SaveID
  159.         //保存完成
  160.     }
  161.     else if(COMP_CODE_CMD_NOT_FINISHED == errorCode)
  162.     {
  163.         //還未保存完成,延時適當時間,再次獲取結(jié)果
  164.         //延時 100 ms
  165.         Delay_ms(100);
  166.         goto SaveResultLabel;
  167.     }
  168.     else if(COMP_CODE_STORAGE_IS_FULL == errorCode)
  169.     {
  170.         //flash存儲已滿,不能保存指紋
  171.     }
  172.     else
  173.     {
  174.         //其他錯誤,比如硬件錯誤等。
  175.     }

  176.     return;
  177. }

  178. void match(void)
  179. {
  180.     U32Bit errorCode;
  181.     S32Bit ret;
  182.     U8Bit isTouch;
  183.     FP_matchResult_t matchResult;

  184. /***********************
  185. 為了提速,也可以不先檢查手指在位,
  186. 不同的模組回復時間不同(FPM08X系列模組大約耗時30ms左右)
  187. ************************/
  188. checkFingeronLabel:
  189.     FP_action_check_finger_is_touch(&isTouch, &errorCode);
  190.     if((0 != isTouch) && (COMP_CODE_OK == errorCode))
  191.     {
  192.         //當isTouch是1的時候,意味著手指在上,
  193.         //播放語音“滴”
  194.     }
  195.     else
  196.     {
  197.         //延時 50 ms
  198.         Delay_ms(50);
  199.         goto checkFingeronLabel;
  200.     }
  201. /**********************/   
  202. matchStartLabel:
  203.     //開始match
  204.     ret = FP_action_match_start(&errorCode);
  205.         if(COMP_CODE_OK != errorCode || FP_OK != ret)
  206.         {
  207.                 //延時 50 ms
  208.                 //可能上電初始化未完成或睡眠喚醒初始化中
  209.         Delay_ms(50);
  210.                 goto matchStartLabel;
  211.         }

  212.         //匹配處理固定大于300ms;
  213.     Delay_ms(300);
  214.     //獲取注冊結(jié)果
  215. matchResultLabel:
  216.     ret = FP_action_get_match_result(&matchResult,&errorCode);
  217.     if(FP_DEVICE_TIMEOUT_ERROR == ret)
  218.         {
  219.                 //接受數(shù)據(jù)超時,根據(jù)接受數(shù)據(jù)所設(shè)超時時間適當延時。
  220.                 Delay_ms(100);
  221.                 goto matchResultLabel;
  222.         }

  223.     if(COMP_CODE_OK == errorCode)
  224.     {
  225.         //match動作完成

  226.         /*  typedef struct {
  227.          *      U16Bit isPass;
  228.          *      U16Bit matchScore;
  229.          *      U16Bit matchID;
  230.          * } FP_matchResult_t, *FP_matchResult_p;
  231.          */

  232.         // isPass是1的話,代表已經(jīng)匹配到了指紋,這時,matchID是匹配到的指紋ID
  233.         // matchScore是具體匹配的分數(shù)

  234.         if(1 == matchResult.isPass)
  235.         {
  236.             //匹配到指紋
  237.         }
  238.         else
  239.         {
  240.             //未匹配到指紋
  241.         }

  242.     }
  243.     else if(COMP_CODE_CMD_NOT_FINISHED == errorCode)
  244.     {
  245.         //還未匹配完成,延時適當時間,再次獲取結(jié)果,處理指紋需要一些時間
  246.         //延時 30 ms
  247.             Delay_ms(30);
  248.         goto matchResultLabel;
  249.     }
  250.         else if(COMP_CODE_NO_FINGER_DETECT == errorCode)
  251.         {
  252.                 //errorCode == COMP_CODE_NO_FINGER_DETECT意味著超時還沒按壓手指
  253.         //重新匹配
  254.         }
  255.     else if(COMP_CODE_NO_REQ_CMD == errorCode)
  256.     {
  257.         goto matchStartLabel;
  258.         }
  259.     else if(COMP_CODE_HARDWARE_ERROR == errorCode)
  260.     {
  261.         //延時 200 ms
  262.         Delay_ms(200);
  263.         goto matchStartLabel;
  264.     }
  265.         else
  266.     {
  267.         return;
  268.     }

  269. }


  270. /***匹配成功后執(zhí)行更新指紋特征(模組自學習),有利于優(yōu)化體驗*
  271.     該命令可在匹配成功以后直接發(fā)送,模組自身會判斷是否要自學習,
  272.     如果不需要會返回錯誤碼
  273. **/
  274. void updateFeature(void)
  275. {
  276.     U32Bit errorCode;
  277.     S32Bit ret;

  278.     S32Bit updateID = 0;//傳入的ID必須與匹配成功后的ID一致

  279. updatestartLabel:
  280.     ret = FP_action_update_start(updateID, &errorCode);
  281.     if(COMP_CODE_OK == errorCode)
  282.     {        
  283.         //需要更新,延時100毫秒
  284.         Delay_ms(100);
  285.     }
  286.     else
  287.     {
  288.        //不需要更新,直接結(jié)束
  289.         return;
  290.     }

  291. updateResultLabel:
  292.     ret = FP_action_get_update_result(&errorCode);
  293.     if(ret == FP_DEVICE_TIMEOUT_ERROR)
  294.     {
  295.         Delay_ms(100);
  296.         goto updateResultLabel;
  297.     }

  298.     if(COMP_CODE_OK == errorCode)
  299.     {
  300.             //更新成功;
  301.     }
  302.     else if(COMP_CODE_CMD_NOT_FINISHED == errorCode)
  303.     {
  304.         //適當延時100ms,再次獲取
  305.         Delay_ms(100);
  306.         goto updateResultLabel;
  307.     }
  308.     else
  309.     {
  310.         //更新失敗,重新更新,或者退出
  311.         goto updatestartLabel;
  312.     }
  313.                
  314.     return;
  315. }


  316. void deleteFp(void)
  317. {
  318.     U32Bit errorCode;
  319.     S32Bit ret;
  320.     S16Bit delete_id = -1;

  321.     //開始刪除,delete_id > 0 的時候,刪除指定id的指紋。
  322.     //delete_id == -1的時候,刪除所有指紋,
  323. deleteStartLabel:
  324.     ret = FP_action_delete_start(delete_id, &errorCode);
  325.         if(COMP_CODE_OK != errorCode || FP_OK != ret)
  326.         {
  327.                 //延時 100 ms
  328.                 //可能上電初始化未完成或睡眠喚醒初始化中
  329.                 Delay_ms(100);
  330.                 goto deleteStartLabel;
  331.         }

  332.     //獲取刪除結(jié)果
  333. deleteResultLabel:
  334.         Delay_ms(100);      //延時 100 ms
  335.     ret = FP_action_get_delete_result(&errorCode);
  336.     if(ret == FP_DEVICE_TIMEOUT_ERROR)
  337.     {
  338.         goto deleteResultLabel;
  339.     }
  340.         
  341.     if(COMP_CODE_OK == errorCode)
  342.     {
  343.         //刪除成功
  344.     }
  345.     else if(COMP_CODE_CMD_NOT_FINISHED == errorCode)
  346.     {
  347.         //還未刪除完成,再次獲取結(jié)果
  348.         goto deleteResultLabel;
  349.     }
  350.     else
  351.     {
  352.         //其他錯誤,比如指紋ID不存在等、flash硬件錯誤等。
  353.     }

  354.     return;
  355. }

  356. void Sleep(void)
  357. {
  358.          U32Bit errorCode;
  359.      S32Bit ret;

  360. SleepStartLabel:
  361.     ret = FP_action_sleep(sleep_type_normal, &errorCode);
  362.     if(FP_OK == ret && 0 == errorCode)
  363.     {
  364.         //休眠成功,模組進入休眠
  365.     }
  366.     else
  367.     {
  368.         //延時 200 ms, 繼續(xù)發(fā)送休眠命令,直到回復休眠成功為止
  369.                 Delay_ms(200);
  370.         goto SleepStartLabel;
  371.     }
  372. }


  373. void autoEnroll(void)
  374. {
  375.     U32Bit errorCode;
  376.         S32Bit ret;
  377.     FP_auto_enroll_t enrollPara;
  378.         FP_enrollResult_t EnrollResult;
  379.     U32Bit timeout = 10000; //建議超時時間設(shè)為10s

  380.         enrollPara.fingerID_high = 0xFF;  //可修改ID,若 ID 為 0xFFFF 則由系統(tǒng)自動分配指紋 ID 。
  381.         enrollPara.fingerID_low = 0xFF;  //可修改ID,若 ID 為 0xFFFF 則由系統(tǒng)自動分配指紋 ID 。
  382.         
  383.         enrollPara.enroll_mode = 0x01; //設(shè)置為 1則表示按壓后需要等待手指抬起再次才可以進行下次注冊,設(shè)置為0則不需要。
  384.         enrollPara.times = 3;                  //可修改注冊次數(shù),范圍:1~6次

  385. SendEnrollStartLabel:
  386.         ret = FP_action_auto_enroll_send(enrollPara);
  387.     if(FP_OK != ret)
  388.     {
  389.         goto SendEnrollStartLabel;
  390.     }

  391. GetEnrollResultLabel:
  392.     ret = FP_action_auto_enroll_recv( &EnrollResult , &errorCode, timeout);  //處理返回碼
  393.     if(0 != ret)
  394.     {
  395.         //可能在等待手指按壓,或者正在處理注冊,再重新查詢是否接收到
  396.         goto GetEnrollResultLabel;
  397.     }

  398.     if(errorCode == COMP_CODE_CMD_DATA_LEN_ERROR || errorCode == COMP_CODE_CMD_DATA_ERROR)
  399.     {
  400.         //檢查命令是否發(fā)錯,重新開始注冊
  401.         goto SendEnrollStartLabel;
  402.     }

  403.     if(errorCode == COMP_CODE_STORAGE_IS_FULL)
  404.     {
  405.         //指紋容量已滿,退出
  406.         return;
  407.     }

  408.     if((100 == EnrollResult.progress) && (EnrollResult.state == 0xff))
  409.     {
  410.         if(COMP_CODE_OK == errorCode)
  411.         {
  412.             // 進度100,state=0XFF時才認為注冊成功
  413.             // 注冊成功
  414.         }
  415.         else
  416.         {
  417.             //存儲出了問題,重新開始注冊
  418.             goto SendEnrollStartLabel;
  419.         }
  420.     }
  421.     else
  422.     {
  423.         if(errorCode == COMP_CODE_OK)
  424.         {
  425.             //單次注冊成功,繼續(xù)按壓
  426.         }
  427.         else if(errorCode == COMP_CODE_SAME_ID)
  428.         {
  429.             //重復指紋,可提示用戶換手指按壓
  430.         }
  431.         else if(errorCode == COMP_CODE_UNQUALIFIED_IMAGE_ERROR)
  432.         {
  433.             //采圖質(zhì)量不好,繼續(xù)按壓直到成功
  434.         }
  435.         else if(errorCode == COMP_CODE_NO_FINGER_DETECT)
  436.         {
  437.             //8S超時還沒按壓手指,繼續(xù)按壓直到注冊成功;
  438.         }
  439.         else
  440.         {
  441.             //其他問題,繼續(xù)按壓
  442.         }

  443.         //繼續(xù)獲取下一次結(jié)果
  444.         goto GetEnrollResultLabel;
  445.     }

  446.     return;
  447. }


  448. void matchSyn(void)
  449. {
  450.     U32Bit errorCode;
  451.         S32Bit ret;
  452.     U32Bit timeout = 10000; //建議超時時間設(shè)為10s
  453.     FP_matchResult_t matchResult;

  454. matchSynSendLabel:
  455.     ret = FP_action_match_syn_send();
  456.     if(FP_OK != ret)
  457.     {
  458.         goto matchSynSendLabel;
  459.     }

  460. getMatchSynResultLabel:
  461.     ret = FP_action_match_syn_recv(&matchResult, &errorCode, timeout);
  462.     if(FP_DEVICE_TIMEOUT_ERROR == ret)
  463.     {
  464.         //可能在等待手指按壓,或者正在處理匹配,再重新查詢是否接收到
  465.         goto getMatchSynResultLabel;
  466.     }

  467.     if((FP_OK == ret) && (COMP_CODE_OK == errorCode))
  468.     {
  469.         if(1 == matchResult.isPass)
  470.         {
  471.             //匹配成功
  472.             //同步匹配會自帶自學習功能,所以耗時會相對于分步匹配長一點
  473.         }
  474.         else
  475.         {
  476.             //匹配失敗
  477.         }
  478.     }
  479.     else if(COMP_CODE_NO_FINGER_DETECT == errorCode)
  480.     {
  481.         //沒有手指按壓
  482.     }
  483.     else if(COMP_CODE_UNQUALIFIED_IMAGE_ERROR == errorCode)
  484.     {
  485.         //采圖質(zhì)量不佳
  486.         goto matchSynSendLabel;
  487.     }
  488.     else
  489.     {
  490.         //其他錯誤
  491.     }
  492. }


  493. void deleteSyn(void)
  494. {
  495.     U32Bit errorCode;
  496.     S32Bit ret;
  497.     U32Bit timeout = 1000;         //建議超時時間設(shè)為1s
  498.     S16Bit delete_id = -1;

  499.     //delete_id > 0 的時候,刪除指定id的指紋。
  500.     //delete_id == -1的時候,刪除所有指紋,

  501. SendDeleteStartLabel:
  502.     ret = FP_action_delete_syn_send(delete_id);
  503.     if(FP_OK != ret)
  504.     {
  505.         goto SendDeleteStartLabel;
  506.     }

  507. GetDeleteResultLabel:
  508.     ret = FP_action_delete_syn_recv(&errorCode, timeout);
  509.     if(ret == FP_DEVICE_TIMEOUT_ERROR)
  510.     {
  511.         goto GetDeleteResultLabel;
  512.     }

  513.     if((FP_OK == ret) && (COMP_CODE_OK == errorCode))
  514.     {
  515.         //刪除成功
  516.     }
  517.     else
  518.     {
  519.         //其他錯誤,比如指紋ID不存在等、flash硬件錯誤等。
  520.     }

  521.     return;
  522. }


  523. /**********************************************************************************************
  524. 上傳指紋特征:適用于FPM08X系列軟件版本大于118的模組(如版本號為:FPM083-00-118);

  525. 一般的,分為三種應(yīng)用場景:
  526.     1、上傳模組內(nèi)正在注冊的id:替代保存指紋命令(0x13)+ 查詢保存結(jié)果命令(0x14),
  527.         直接將指紋數(shù)據(jù)上傳至上位機;

  528.     2、上傳模組內(nèi)存儲的指定一個id:上傳之前,需確認id是否存在,如果存在則繼續(xù)上傳;

  529.     3、上傳模組內(nèi)存儲的所有id;上傳之前,需獲取指紋模板分布,然后根據(jù)分布指定id號,一個一個上傳;

  530. *********************************************************************************************/

  531. void uploadFTR(void)
  532. {
  533.     FP_ftrData_t uploadftrData;
  534.     FP_ftrDistribution_t distribution;
  535.     U32Bit errorCode;
  536.     S32Bit ret;
  537.     U16Bit ftrLength;
  538.     S32Bit i = 0;
  539.     U16Bit frameCount;
  540.     U8Bit ftrReceiveBuffer[128];        //每幀命令回復的buffer
  541.     U8Bit err_num = 0;

  542. /*
  543.     typedef struct {
  544.         U16Bit id;          //待上傳的指紋id
  545.         U16Bit length;      //待上傳的指紋數(shù)據(jù)長度
  546.         U8Bit  *data;      
  547.     }FP_ftrData_t, *FP_ftrData_p;
  548. */

  549.     uploadftrData.data = s_ftrDataBuffer;
  550.     uploadftrData.id = 0x00;

  551. /******上傳模組內(nèi)正在注冊的id*************
  552.     //注冊進度100%
  553.     //保存指紋開始
  554.     uploadftrData.id = 0xFFFF;      //當id為0XFFFF時,可直接上傳
  555.     goto UploadFtrGetInfoLabel;
  556. *****************************************/

  557. UploadFtrCheckFtrLabel:
  558.     ret = FP_action_get_ftr_distribution(&distribution, &errorCode);
  559.     if(FP_OK != ret || errorCode != FP_OK)
  560.     {
  561.         //錯誤,重新發(fā)送  
  562.         Delay_ms(100);
  563.         goto UploadFtrCheckFtrLabel;
  564.     }

  565. /*****************上傳模組內(nèi)存儲的指定一個id**********/
  566. //  Printf("distribution[] = 0x%x\r\n", distribution.distributon[check_id >> 3]);

  567.     if(0 == CHECK_BIT(distribution.distributon[uploadftrData.id >> 3], (uploadftrData.id & 0x7)))      
  568.     {
  569.         //id不存在,重新輸出正確id號
  570.         Delay_ms(100);
  571.         goto UploadFtrCheckFtrLabel;
  572.     }
  573. /****************************************************/

  574. /*********上傳模組內(nèi)存儲的所有id********************
  575.     S16Bit upload_id[100] = 0;  //待上傳的id,用于上傳所有指紋
  576.     U8Bit currentByte = 0;
  577.     S16Bit *p = &upload_id[0];

  578.     for(int i = 0; i <= (distribution.ftrMaxCount >> 3); i++)
  579.     {
  580.         currentByte = distribution.distributon[i];
  581.         for(int j = 0; j < 8; j++)
  582.         {
  583.             if(CHECK_BIT(currentByte,j))
  584.             {
  585.                 *p = i*8 + j;     
  586.                 p++;
  587.             }
  588.         }
  589.     }
  590. **************************************************/
  591. UploadFtrGetInfoLabel:
  592.     ret= FP_action_get_ftr_info(&uploadftrData, &errorCode);
  593.     if( FP_OK != ret)
  594.     {
  595.         Delay_ms(100);
  596.         goto UploadFtrGetInfoLabel;
  597.     }

  598.     ftrLength = uploadftrData.length;
  599.     frameCount = ((ftrLength - 1) >> 7) + 1;   

  600. UploadFtrGetDataLabel:
  601.     for(; i < frameCount; i++)
  602.     {
  603.         ret = FP_action_get_ftr_data(i, ftrReceiveBuffer, &errorCode);
  604.         if(ret != FP_OK || errorCode != FP_OK)
  605.         {
  606.             err_num++;
  607.             if(err_num < 3)
  608.             {
  609.                 //數(shù)據(jù)接收有誤重新發(fā)送該幀
  610.                 goto UploadFtrGetDataLabel;
  611.             }
  612.             else
  613.             {
  614.                 //如果超過3次,報錯退出
  615.                 return;
  616.             }
  617.         }
  618.         else
  619.         {
  620.             err_num = 0;
  621.             memcpy(uploadftrData.data + 128*i, ftrReceiveBuffer, 128);    //模組每幀回復的數(shù)據(jù)長度其實是固定的128字節(jié)
  622.         }
  623.     }

  624.     s_ftrDataLength = ftrLength;

  625.     /*
  626.         FTR存儲在上位機數(shù)據(jù)庫前
  627.         需對ftrData的長度ftrLength進行記錄,作為該指紋下載時的長度;
  628.         可把ftrData打包一下(加一個CRC或奇偶校驗)
  629.     */
  630. }


  631. /*********************************************************************************************
  632. 下載指紋特征:適用于FPM08X系列軟件版本大于118的模組(如版本號為:FPM083-00-118);
  633. 將指紋數(shù)據(jù)分發(fā)到模組中
  634. */
  635. void downloadFTR(void)
  636. {
  637.     FP_ftrData_t downloadftrData;
  638.     U8Bit ftrSentBuffer[128];          //每幀命令發(fā)送的buffer
  639.     U16Bit i = 0;
  640.     U16Bit remainLength;
  641.     U16Bit currentLength;
  642.     U16Bit frameCount;
  643.     U32Bit errorCode;
  644.     U32Bit ret;
  645.     U32Bit timeout = DEFAULT_TIME_OUT;
  646.     U8Bit err_num = 0;

  647. /*
  648.     typedef struct {
  649.         U16Bit id;          //待下載的指紋id
  650.         U16Bit length;      //待下載的指紋數(shù)據(jù)長度
  651.         U8Bit  *data;      
  652.     }FP_ftrData_t, *FP_ftrData_p;
  653. */
  654.     downloadftrData.data = s_ftrDataBuffer;
  655.     downloadftrData.length = s_ftrDataLength;
  656.     downloadftrData.id = 0;

  657. DownloadFtrSentInfoLabel:
  658.     ret = FP_action_write_ftr_info(&downloadftrData, &errorCode);
  659.     if(FP_OK != ret || errorCode != FP_OK)
  660.     {
  661.         Delay_ms(100);
  662.         goto DownloadFtrSentInfoLabel;
  663.     }

  664.     remainLength = downloadftrData.length;
  665.     currentLength = 128;
  666.     frameCount = ((downloadftrData.length - 1) >> 7) + 1;

  667. DownloadFtrSentDataLabel:
  668.     for(; i < frameCount; i++)
  669.     {
  670.         memcpy(ftrSentBuffer, downloadftrData.data + 128*i, currentLength);

  671.         //如果發(fā)最后一幀,由于模組需要存儲指紋,命令超時時間需久一點, 1S比較合適
  672.         if (i == frameCount - 1)
  673.         {
  674.             timeout = 1000;
  675.         }
  676.         ret = FP_action_write_ftr_data(i, ftrSentBuffer, currentLength, &errorCode, timeout);
  677.         if(FP_OK != ret || errorCode != FP_OK)
  678.         {
  679.             err_num++;
  680.             if(err_num < 3)
  681.             {
  682.                 //數(shù)據(jù)發(fā)送有誤,重新發(fā)送該幀
  683.                 Delay_ms(100);
  684.                 goto DownloadFtrSentDataLabel;

  685.             }
  686.             else
  687.             {
  688.                 //如果超過3次,報錯退出
  689.                 return;
  690.             }
  691.         }
  692.         else
  693.         {
  694.             err_num = 0;
  695.             remainLength -= currentLength;
  696.             if(remainLength < 128)
  697.             {
  698.                 currentLength = remainLength;
  699.             }
  700.         }
  701.     }
  702. }

  703. /*********************************************************************************************
  704. 設(shè)置 LED 控制信息:適用于帶LED燈的模組;
  705. */
  706. void setLed(void)
  707. {
  708.     U32Bit errorCode;
  709.     S32Bit ret;
  710.         FP_LED_CTRL_INFO stLEDCtrlInfo;

  711. setLedStartLabel:
  712. /**燈的模式與顏色按需求設(shè)置,以下為參考范例1:閃爍綠燈5次,亮的時間為200ms,滅的時間為200ms*/
  713.     stLEDCtrlInfo.ucLEDCtrlMode = EM_LED_CTRL_BLINK;
  714.     stLEDCtrlInfo.ucLEDColor = EM_LED_GREEN;
  715.     stLEDCtrlInfo.usLEDpara1 = 0x14;    //點亮時長
  716.     stLEDCtrlInfo.usLEDpara2 = 0x14;    //熄滅時長
  717.     stLEDCtrlInfo.usLEDpara3 = 0x5;     //閃爍次數(shù)
  718. /***/
  719. /**燈的模式與顏色按需求設(shè)置,以下為參考范例2:藍燈呼吸,最大占空比100,最小占空比0,占空比每秒變化50%)*
  720.     stLEDCtrlInfo.ucLEDCtrlMode = EM_LED_CTRL_PWM;
  721.     stLEDCtrlInfo.ucLEDColor = EM_LED_BLUE;
  722.     stLEDCtrlInfo.usLEDpara1 = 0x64;    //最大占空比
  723.     stLEDCtrlInfo.usLEDpara2 = 0x00;    //熄滅時長
  724.     stLEDCtrlInfo.usLEDpara3 = 0x32;     //閃爍次數(shù)
  725. ***/
  726.     ret = FP_action_set_led(&stLEDCtrlInfo, &errorCode);
  727.     if(FP_OK == ret && 0 == errorCode)
  728.     {
  729.         //點燈成功
  730.     }
  731.     else
  732.     {
  733.         //延時 50 ms, 繼續(xù)發(fā)送點燈命令,或者直接退出
  734.         Delay_ms(50);
  735.         goto setLedStartLabel;
  736.     }
  737. }


  738. /*********************************************************************************************
  739. 設(shè)置系統(tǒng)策略:用于設(shè)置模組默認的功能;如關(guān)閉重復指紋檢查功能
  740. */
  741. void setSysPolicy(void)
  742. {
  743.     U32Bit errorCode;
  744.     S32Bit ret;
  745.     U32Bit SysPolicy_value;
  746.     U32Bit SysPolicy_bit_selflearn = 0x00000002;    //重復指紋檢查功能的位
  747.     U32Bit timeout = 1000; //建議超時時間設(shè)為1s

  748. /**設(shè)置系統(tǒng)策略之前,先獲取系統(tǒng)策略*/
  749. getSysPolicyLabel:

  750.     ret = FP_action_get_SysPolicy(&SysPolicy_value, &errorCode);
  751.     if(FP_OK == ret && 0 == errorCode)
  752.     {
  753.         //獲取策略成功
  754.     }
  755.     else
  756.     {
  757.         //延時 50 ms, 繼續(xù)發(fā)送點燈命令,或者直接退出
  758.         Delay_ms(50);
  759.         goto getSysPolicyLabel;
  760.     }

  761. setSysPolicyLabel:
  762.     SysPolicy_value &= ~SysPolicy_bit_selflearn;

  763.     ret = FP_action_set_SysPolicy(&SysPolicy_value, &errorCode, timeout);  //處理返回碼
  764.     if(FP_OK == ret && 0 == errorCode)
  765.     {
  766.         //獲取策略成功后,模組會自行復位
  767.         Delay_ms(200);
  768.         return;
  769.     }
  770.     else
  771.     {
  772.         //延時 50 ms, 繼續(xù)發(fā)送
  773.         Delay_ms(50);
  774.         goto setSysPolicyLabel;
  775.     }
  776. }


  777. void demo_main(U8Bit command)
  778. {
  779.     //設(shè)置指紋收發(fā)的buffer
  780.     FP_action_set_send_buffer(s_send_buffer);
  781.     FP_action_set_recv_buffer(s_recv_buffer);

  782.     switch(command)
  783.     {
  784.         case 0:
  785.             getID();
  786.             break;
  787.         case 1:
  788.             enroll();
  789.             break;
  790.         case 2:
  791.             match();
  792.             break;
  793.         case 3:
  794.             deleteFp();
  795.             break;
  796.             case 4:
  797.             Sleep();
  798.             break;
  799.             case 5:
  800.             updateFeature();
  801.                     break;
  802.         case 6:
  803.             autoEnroll();
  804.             break;
  805.         case 7:
  806.             matchSyn();
  807.             break;
  808.         case 8:
  809.             deleteSyn();
  810.             break;
  811.         case 9:
  812.             uploadFTR();
  813.             break;
  814.         case 10:
  815.             downloadFTR();
  816.             break;
  817.         case 11:
  818.             setLed();
  819.             break;
  820.         case 12:
  821.             setSysPolicy();
  822.             break;

  823.         default:
  824.             break;
  825.     }

  826. }
復制代碼


分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 午夜欧美 | 久久不射电影网 | 97精品超碰一区二区三区 | 亚洲在线一区二区 | 久草在线免费资源 | 久久国产欧美日韩精品 | 国产欧美一区二区三区免费 | 欧美国产日韩一区 | 粉嫩在线 | 成人在线播放 | 国产精品一区视频 | 久久久一区二区 | 亚洲视频一区二区三区 | 一区二区三区视频在线观看 | 男人视频网站 | 在线午夜 | 日韩国产专区 | 欧美 日韩 国产 成人 在线 91 | 国产日产精品一区二区三区四区 | 麻豆久久久久久久 | 久久精品成人 | 亚洲成人精品一区 | 国内精品久久精品 | 中文在线一区二区 | 久久av一区 | 久久精品小短片 | 国产精品成人一区 | 四虎免费视频 | 欧美日韩国产一区二区三区不卡 | 欧美xxxx在线| 夜夜爽99久久国产综合精品女不卡 | 美女久久久久 | 欧美.com| 欧美激情久久久 | 中文字幕国产 | 性色视频| 一区二区免费在线观看 | 精品欧美一区二区三区免费观看 | 国产一区二 | 国产精品视频网 | 久久久91|