Proyecto ABInBev para la tarjeta Guaria 1/2.

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers fingerprint_exe.cpp Source File

fingerprint_exe.cpp

Go to the documentation of this file.
00001 /**
00002  * @file fingerprint_exe.cpp
00003  * @author Felícito Manzano (felicito.manzano@detektor.com.sv)
00004  * @brief 
00005  * @version 0.1
00006  * @date 2020-10-03
00007  * 
00008  * @copyright Copyright (c) 2020
00009  * 
00010  */
00011 
00012 #include "mbed.h"
00013 #include "BufferedSerial.h"
00014 //#include "GT521FX.hpp"
00015 #include "New_GT521Fx.hpp "
00016 #include "jq8400_voice.hpp "
00017 #include "voice_cn_pa.hpp"
00018 #include "teltonika_fmu130.hpp "
00019 #include "jq8400_voice.hpp "
00020 #include "playlist.hpp"
00021 #include "safety_tip_exe.hpp "
00022 #include "USBSerial.h"
00023 
00024 
00025 // Objetos Entradas Digitales / Seriales
00026 /**
00027  * @brief 
00028  * 
00029  */
00030 extern BufferedSerial   avl_uart;
00031 extern BufferedSerial   voice_uart;
00032 extern DigitalOut       out1_fingerprint;
00033 extern DigitalOut       out3_gt521fx;
00034 extern DigitalOut       out4_gt521fx;
00035 extern BufferedSerial   fingerprint;
00036 extern USBSerial        myPC_debug;
00037 extern Ticker           tick_fingerprint;
00038 extern Ticker           tick_safety_tip;
00039 extern queue            colaPlaylist;
00040 
00041 
00042 // Variables Externas
00043 /**
00044  * @brief 
00045  * 
00046  */
00047 extern float    time_safety_tip;
00048 extern bool     flag_fingerprint_Sleep;
00049 extern bool     flag_driver_loggin;
00050 extern bool     functionality_safety_tip;
00051 extern bool     flag_fingerprint_query;
00052 extern bool     ble_connection_state;
00053 extern bool     fingerprint_override;
00054 extern bool     ignition;
00055 extern bool     finterprint_flag_working;
00056 extern bool     fingerprint_flag_poweroff;
00057 extern int      fingerprint_login;
00058 extern int      flag_fingerprint_turOn;
00059 extern int      fp_override_limit;
00060 extern int      fp_unauthorized_count;
00061 extern int      items_queue;
00062 
00063 
00064 // Variables locales
00065 /**
00066  * @brief 
00067  * 
00068  */
00069 int         fp_answer = 0;
00070 int         w;
00071 char        id_buffer[64];
00072 const char  TCA_ID_FP_LOGIN[]       = "TCA|004|DTK_FP;";
00073 const char  TCA_ID_UNIDENTIFIED[]   = "TCA|110|";
00074 const char  TCA_ID_LECTOR_HUE[]     = "TCA|111|";
00075 const char  TCA_FP_INIT[]           = "TCA|154|";
00076 const char  TCA_ID_OVERRIDE_ID[]    = "TCA|149|0";
00077 const char  FP_ENGINE_LOCK[]        = "setdigout 0?? ? ? ? ? ? ?";
00078 const char  FP_ENGINE_UNLOCK[]      = "setdigout 1?? ? ? ? ? ? ?";
00079 
00080 #define     DEBUG_F_CPP         1
00081 #define     FP_FP_READER_GT521     1
00082 /**
00083  * @brief 
00084  * 
00085  */
00086 void identify_fingerPrint() {
00087     flag_fingerprint_query = false;
00088     memset(id_buffer, '\0', sizeof(id_buffer));
00089 
00090     if (out3_gt521fx) {
00091         /* DESHABILITADA LA FUNCIÓN DE SLEEP EN EL LECTOR
00092             if (flag_fingerprint_Sleep) {
00093                 fingerprint.WakeUp();
00094                 flag_fingerprint_Sleep = false;
00095                 //myPC_debug.printf("FP - GT521Fx@WakeUp\r\n");
00096                 jq8400_addQueue(VOICE_functionality_fingerprint_reader);
00097             }
00098         */
00099         if (!(flag_driver_loggin) && ignition) {
00100             //Verificar con ignicion
00101             //fingerprint.CmosLed(1);
00102             #if FP_FP_READER_GT521 == 1
00103                 FP_LED_open();
00104             #else
00105             #endif
00106             wait_us(50000);
00107 
00108             #if FP_FP_READER_GT521 == 1
00109                 fp_answer = FP_IsPressFinger();
00110             #else
00111             #endif
00112 
00113             if (fp_answer == 0) {
00114                 #if FP_FP_READER_GT521 == 1
00115                     FP_CaptureFinger(1);
00116                 #else
00117                 #endif
00118 
00119                 #ifdef DEBUG_F_CPP
00120                     myPC_debug.printf("FP - Capturando...\r\n");
00121                 #endif
00122                 
00123                 #if FP_FP_READER_GT521 == 1
00124                     fingerprint_login = FP_Identify();
00125                     FP_LED_close();
00126                 #else
00127                 #endif
00128 
00129                 #ifdef DEBUG_F_CPP
00130                     myPC_debug.printf("FP - ID: %d\r\n", fingerprint_login);
00131                 #endif
00132                 
00133                 if (fingerprint_login >= 0) {
00134                     #ifdef DEBUG_F_CPP
00135                         myPC_debug.printf("FP - Autorizado...\r\n");
00136                     #endif
00137                     tick_fingerprint.detach();
00138                     jq8400_addQueue (VOICE_DRIVER_AUTHORIZED);
00139                     jq8400_addQueue (VOICE_WELLCOME);
00140 
00141                     // Limpiar cola
00142                     if (ble_connection_state) {
00143                         // No hacer nada
00144                     } else {
00145                         // jq8400_addQueue(VOICE_FP_AUTH_NO_BLUETOOTH); // Solicitar asistencia remota
00146                     }
00147                     
00148                     #ifdef DEBUG_F_CPP
00149                         myPC_debug.printf("%s\r\n", FP_ENGINE_UNLOCK);
00150                     #endif
00151                     tx_fmu130_command(FP_ENGINE_UNLOCK, &avl_uart);
00152                     out1_fingerprint = 1;
00153                     wait_us(1000000);
00154                     out1_fingerprint = 0;
00155                     fp_unauthorized_count = 0;
00156                     flag_fingerprint_turOn = false;
00157                     flag_driver_loggin = true;
00158                     #if FP_FP_READER_GT521 == 1
00159                         FP_LED_close();
00160                         FP_Close();
00161                     #else
00162                     #endif
00163                     wait_us(1000000);
00164                     fingerprint_flag_poweroff = true;
00165 
00166                     if (functionality_safety_tip) {
00167                         #ifdef DEBUG_F_CPP
00168                             myPC_debug.printf("FP - Ticker de Tip de Seguridad Iniciado\r\n");
00169                         #endif
00170                         tick_safety_tip.attach(&play_SafetyTip, time_safety_tip);
00171                     }
00172 
00173                     /* DESHABILITADA LA FUNCIÓN DE SLEEP EN EL LECTOR
00174                             fingerprint.Sleep();
00175                             flag_fingerprint_Sleep = true;
00176                         */
00177 
00178                     sprintf(id_buffer, "%s%04d", TCA_ID_FP_LOGIN, fingerprint_login);
00179                     tx_fmu130_message (id_buffer, &avl_uart);
00180                     #ifdef DEBUG_F_CPP
00181                         myPC_debug.printf("GPIO - GT521Fx@Sleep %d\r\n", flag_fingerprint_Sleep);
00182                         myPC_debug.printf("%s\r\n", id_buffer);
00183                     #endif
00184 
00185                     wait_us(100000);
00186                     sprintf(id_buffer, "%s3", TCA_ID_LECTOR_HUE);
00187                     tx_fmu130_message (id_buffer, &avl_uart);
00188                     #ifdef DEBUG_F_CPP
00189                         myPC_debug.printf("%s\r\n", id_buffer);
00190                     #endif
00191                 } else {
00192                     jq8400_addQueue (VOICE_DRIVER_UNAUTHORIZED);
00193                     sprintf(id_buffer, "%s%d", TCA_ID_UNIDENTIFIED, fingerprint_login);
00194                     #ifdef DEBUG_F_CPP
00195                         myPC_debug.printf("FP - No Autorizado...\r\n");
00196                         myPC_debug.printf("%s\r\n", id_buffer);
00197                     #endif
00198                     tx_fmu130_message (id_buffer, &avl_uart);
00199                     
00200                     #if FP_FP_READER_GT521 == 1
00201                         FP_LED_close();
00202                     #else
00203                     #endif
00204 
00205                     if (fingerprint_override) {
00206                         fp_unauthorized_count++;
00207                         #ifdef DEBUG_F_CPP
00208                             myPC_debug.printf("FP - %d de %d para Anular Identificacion de Huella\r\n", fp_unauthorized_count, fp_override_limit);
00209                         #endif
00210                         if (fp_unauthorized_count >= fp_override_limit)
00211                         {
00212                             #ifdef DEBUG_F_CPP
00213                                 myPC_debug.printf("FP - Anulando identificacion de Conductor...\r\n");
00214                             #endif
00215                             /////////////////////////////
00216                             // Limpiar cola de mensajes de voz
00217 
00218                             //
00219                             if (ble_connection_state) {
00220                                 jq8400_addQueue (VOICE_DRIVER_AUTHORIZED);
00221                             } else {
00222                                 // jq8400_addQueue(VOICE_FP_AUTH_NO_BLUETOOTH); // Solicitar asistencia remota
00223                             }
00224                             #ifdef DEBUG_F_CPP
00225                                 myPC_debug.printf("%s\r\n", FP_ENGINE_UNLOCK);
00226                             #endif
00227                             tx_fmu130_command(FP_ENGINE_UNLOCK, &avl_uart);
00228                             out1_fingerprint = 1;
00229                             wait_us(1000000);
00230                             out1_fingerprint = 0;
00231                             fp_unauthorized_count = 0;
00232                             flag_fingerprint_turOn = false;
00233                             flag_driver_loggin = true;
00234                             tick_fingerprint.detach();
00235                             #if FP_FP_READER_GT521 == 1
00236                                 FP_LED_close();
00237                             #else
00238                             #endif
00239                             wait_us(1000000);
00240                             fingerprint_flag_poweroff = true;
00241 
00242                             if (functionality_safety_tip) {
00243                                 #ifdef DEBUG_F_CPP
00244                                     myPC_debug.printf("FP - Ticker de Tip de Seguridad Iniciado\r\n");
00245                                 #endif
00246                                 tick_safety_tip.attach(&play_SafetyTip, time_safety_tip);
00247                             }
00248                             sprintf(id_buffer, "%s", TCA_ID_OVERRIDE_ID);
00249                             #ifdef DEBUG_F_CPP
00250                                 myPC_debug.printf("%s\r\n", id_buffer);
00251                             #endif
00252                             tx_fmu130_message (id_buffer, &avl_uart);
00253                         }
00254                     }
00255                 }
00256             } else {
00257                 #if FP_FP_READER_GT521 == 1
00258                     FP_LED_close();
00259                 #else
00260                 #endif
00261 
00262                 // Limpiar cola de mensajes de voz
00263                 #ifdef DEBUG_F_CPP
00264                     myPC_debug.printf("FP - No Presionado\r\n");
00265                 #endif
00266             }
00267         }
00268     }
00269 }
00270 
00271 /**
00272  * @brief 
00273  * 
00274  */
00275 void initFingerprintReader() {
00276     // Variable Interna
00277     int answer_GT521Fx = -1;
00278     wait_us(100000); // Tiempo de espera para inicializar el sensor
00279     #ifdef DEBUG_F_CPP
00280         myPC_debug.printf("\r\nInicializando GT521Fx");
00281     #endif
00282     
00283     #if FP_FP_READER_GT521 == 1
00284         answer_GT521Fx = FP_Open();
00285     #else
00286     #endif
00287     sprintf(id_buffer, "%s%d", TCA_FP_INIT, answer_GT521Fx);
00288     #ifdef DEBUG_F_CPP
00289         myPC_debug.printf("%s\r\n", id_buffer);
00290         myPC_debug.printf("\r\nGT521Fx Open: OK\r\n");
00291     #endif
00292     tx_fmu130_message (id_buffer, &avl_uart);
00293     #if FP_FP_READER_GT521 == 1
00294         FP_Close();
00295     #else
00296     #endif
00297 }