Proyecto ABInBev para la tarjeta Guaria 1/2.

Committer:
fmanzano_dtk
Date:
Fri Jul 01 13:05:44 2022 -0600
Revision:
2:1ef167d1b7b8
Parent:
0:2d7ac38345d8
Child:
3:6e55713bc91d
Se actualiza el archivo main

Who changed what in which revision?

UserRevisionLine numberNew contents of line
fmanzano_dtk 2:1ef167d1b7b8 1 /**
fmanzano_dtk 2:1ef167d1b7b8 2 * @file main.cpp
fmanzano_dtk 2:1ef167d1b7b8 3 * @author Felícito Manzano (felicito.manzano@detektor.com.sv)
fmanzano_dtk 2:1ef167d1b7b8 4 * @brief
fmanzano_dtk 2:1ef167d1b7b8 5 * Proyecto para ABInBev Cervecería Nacional de Panamá, incluye el soporte
fmanzano_dtk 2:1ef167d1b7b8 6 * para para 5 entradas digitales, conexión vía Bluetooth SPP con equipo
fmanzano_dtk 2:1ef167d1b7b8 7 * Teltonika FMU130 para el envío y recepción de mensajes al servidor
fmanzano_dtk 2:1ef167d1b7b8 8 * del ecosistema Detektor, también incluye un puerto serial TTL para
fmanzano_dtk 2:1ef167d1b7b8 9 * controlar el módulo de voz JQ8400, puerto serial para el lector de
fmanzano_dtk 2:1ef167d1b7b8 10 * huellas GT521Fx y puerto serial RS232 con el sensor de lluvia RG9.
fmanzano_dtk 2:1ef167d1b7b8 11 * @version 0.1
fmanzano_dtk 2:1ef167d1b7b8 12 * @date 2020-09-26
fmanzano_dtk 2:1ef167d1b7b8 13 *
fmanzano_dtk 2:1ef167d1b7b8 14 * @copyright Copyright (c) 2020
fmanzano_dtk 2:1ef167d1b7b8 15 *
fmanzano_dtk 0:2d7ac38345d8 16 */
fmanzano_dtk 0:2d7ac38345d8 17
fmanzano_dtk 0:2d7ac38345d8 18 #include "mbed.h"
fmanzano_dtk 0:2d7ac38345d8 19 #include "platform/mbed_thread.h"
fmanzano_dtk 2:1ef167d1b7b8 20 #include "stm32f4xx_hal_iwdg.h"
fmanzano_dtk 2:1ef167d1b7b8 21 //#include "stm32f0xx_hal_iwdg.h"
fmanzano_dtk 2:1ef167d1b7b8 22 #include "BufferedSerial.h"
fmanzano_dtk 2:1ef167d1b7b8 23 #include "ics5_pinout.hpp"
fmanzano_dtk 2:1ef167d1b7b8 24 #include "jq8400_voice.hpp"
fmanzano_dtk 2:1ef167d1b7b8 25 #include "voice_cn_pa.hpp"
fmanzano_dtk 2:1ef167d1b7b8 26 #include "New_GT521Fx.hpp"
fmanzano_dtk 2:1ef167d1b7b8 27 #include "gpio_exe.hpp"
fmanzano_dtk 2:1ef167d1b7b8 28 #include "fmu130_exe.hpp"
fmanzano_dtk 2:1ef167d1b7b8 29 #include "fingerprint_exe.hpp"
fmanzano_dtk 2:1ef167d1b7b8 30 #include "playlist_exe.hpp"
fmanzano_dtk 2:1ef167d1b7b8 31 #include "playlist.hpp"
fmanzano_dtk 2:1ef167d1b7b8 32 #include "teltonika_fmu130.hpp"
fmanzano_dtk 2:1ef167d1b7b8 33 #include "fireup_exe.hpp"
fmanzano_dtk 2:1ef167d1b7b8 34 #include "safety_tip_exe.hpp"
fmanzano_dtk 2:1ef167d1b7b8 35 #include "eeprom.h"
fmanzano_dtk 2:1ef167d1b7b8 36 #include "flash_exe.cpp"
fmanzano_dtk 2:1ef167d1b7b8 37 #include "USBSerial.h"
fmanzano_dtk 2:1ef167d1b7b8 38 #include <ctype.h>
fmanzano_dtk 2:1ef167d1b7b8 39
fmanzano_dtk 2:1ef167d1b7b8 40 /**
fmanzano_dtk 2:1ef167d1b7b8 41 * INTERFACES:
fmanzano_dtk 2:1ef167d1b7b8 42 * Se utiliza la librería ICS5_Pinout para hacer el cambio de pines
fmanzano_dtk 2:1ef167d1b7b8 43 * en base a la tarjeta para la que se compilará. Se tiene soporte para
fmanzano_dtk 2:1ef167d1b7b8 44 * las tarjetas NUCLEO F303K8, NUCLEO F091RC, ICS3 e ICS5.
fmanzano_dtk 2:1ef167d1b7b8 45 */
fmanzano_dtk 2:1ef167d1b7b8 46 #define DEBUG 1
fmanzano_dtk 2:1ef167d1b7b8 47
fmanzano_dtk 2:1ef167d1b7b8 48 #if (ICS_BOARD_ID == 11)
fmanzano_dtk 2:1ef167d1b7b8 49 // Serial
fmanzano_dtk 2:1ef167d1b7b8 50 BufferedSerial avl_uart(BLE_TX, BLE_RX, 1024, 2); //! UART TTL para enlace con el equipo Teltonika FMU130.
fmanzano_dtk 2:1ef167d1b7b8 51 BufferedSerial voice_uart(TTL_VOICE_TX, TTL_VOICE_RX); //! UART TTL para comunicación con el módulo de voz JQ8400.
fmanzano_dtk 2:1ef167d1b7b8 52 BufferedSerial fingerprint(TTL_TX, TTL_RX);
fmanzano_dtk 2:1ef167d1b7b8 53 #ifdef DEBUG
fmanzano_dtk 2:1ef167d1b7b8 54 USBSerial myPC_debug;
fmanzano_dtk 2:1ef167d1b7b8 55 #endif
fmanzano_dtk 2:1ef167d1b7b8 56
fmanzano_dtk 2:1ef167d1b7b8 57 // PCB Support
fmanzano_dtk 2:1ef167d1b7b8 58 InterruptIn mybutton(USER_BUTTON);
fmanzano_dtk 2:1ef167d1b7b8 59 DigitalIn bluetooth_state(BT_STATE);
fmanzano_dtk 2:1ef167d1b7b8 60 DigitalOut myled(USER_LED1);
fmanzano_dtk 2:1ef167d1b7b8 61 DigitalOut flashLED(USER_LED2);
fmanzano_dtk 2:1ef167d1b7b8 62 DigitalOut out2_ble_reset(BT_RESET);
fmanzano_dtk 2:1ef167d1b7b8 63
fmanzano_dtk 2:1ef167d1b7b8 64 // Outputs
fmanzano_dtk 2:1ef167d1b7b8 65 DigitalOut out1_fingerprint(OUTPUT1_NEGATIVE);
fmanzano_dtk 2:1ef167d1b7b8 66 DigitalOut out3_gt521fx(OUTPUT2_NEGATIVE);
fmanzano_dtk 2:1ef167d1b7b8 67 DigitalOut out4_gt521fx(OUTPUT3_NEGATIVE);
fmanzano_dtk 2:1ef167d1b7b8 68
fmanzano_dtk 2:1ef167d1b7b8 69 // Inputs
fmanzano_dtk 2:1ef167d1b7b8 70 DigitalIn in1_ignition(INPUT1_POSITIVE);
fmanzano_dtk 2:1ef167d1b7b8 71 DigitalIn in2_pilot(INPUT2_NEGATIVE);
fmanzano_dtk 2:1ef167d1b7b8 72 DigitalIn in3_copilot(INPUT3_NEGATIVE);
fmanzano_dtk 2:1ef167d1b7b8 73 DigitalIn in4_crew(INPUT4_NEGATIVE);
fmanzano_dtk 2:1ef167d1b7b8 74 DigitalIn in5_rain_sensor(INPUT5_NEGATIVE);
fmanzano_dtk 2:1ef167d1b7b8 75 #endif
fmanzano_dtk 2:1ef167d1b7b8 76
fmanzano_dtk 2:1ef167d1b7b8 77 // EEPROM
fmanzano_dtk 2:1ef167d1b7b8 78 EEPROM ep(I2C_SDA_EE, I2C_SCL_EE, 0x0, EEPROM::T24C32);
fmanzano_dtk 2:1ef167d1b7b8 79 int32_t eeprom_size,max_size;
fmanzano_dtk 2:1ef167d1b7b8 80 #define EEPROM_ADDR 0x0
fmanzano_dtk 2:1ef167d1b7b8 81 #define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
fmanzano_dtk 2:1ef167d1b7b8 82 #define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
fmanzano_dtk 2:1ef167d1b7b8 83 typedef struct _MyData {
fmanzano_dtk 2:1ef167d1b7b8 84 int16_t sdata;
fmanzano_dtk 2:1ef167d1b7b8 85 int32_t idata;
fmanzano_dtk 2:1ef167d1b7b8 86 float fdata;
fmanzano_dtk 2:1ef167d1b7b8 87 } MyData;
fmanzano_dtk 2:1ef167d1b7b8 88 static void myerror(std::string msg) {
fmanzano_dtk 2:1ef167d1b7b8 89 printf("Error %s\n",msg.c_str());
fmanzano_dtk 2:1ef167d1b7b8 90 exit(1);
fmanzano_dtk 2:1ef167d1b7b8 91 }
fmanzano_dtk 2:1ef167d1b7b8 92
fmanzano_dtk 2:1ef167d1b7b8 93
fmanzano_dtk 2:1ef167d1b7b8 94 // VOICE
fmanzano_dtk 2:1ef167d1b7b8 95 queue colaPlaylist(10);
fmanzano_dtk 2:1ef167d1b7b8 96
fmanzano_dtk 2:1ef167d1b7b8 97 // HAL BASED
fmanzano_dtk 2:1ef167d1b7b8 98 static IWDG_HandleTypeDef my_iwdg;
fmanzano_dtk 0:2d7ac38345d8 99
fmanzano_dtk 0:2d7ac38345d8 100
fmanzano_dtk 2:1ef167d1b7b8 101 // FUNCIONALIDADES
fmanzano_dtk 2:1ef167d1b7b8 102 // Nuevas banderas para habilitar/deshabilitar funciones.
fmanzano_dtk 2:1ef167d1b7b8 103 bool functionality_idle_shutdown;
fmanzano_dtk 2:1ef167d1b7b8 104 bool functionality_idle_reminder;
fmanzano_dtk 2:1ef167d1b7b8 105 bool functionality_seatbelt_reading;
fmanzano_dtk 2:1ef167d1b7b8 106 bool functionality_force_driver_buclke;
fmanzano_dtk 2:1ef167d1b7b8 107 bool functionality_rain_sensor;
fmanzano_dtk 2:1ef167d1b7b8 108 bool functionality_rainSensor_silentMode;
fmanzano_dtk 2:1ef167d1b7b8 109 bool functionality_fingerprint_reader;
fmanzano_dtk 2:1ef167d1b7b8 110 bool functionality_safety_tip;
fmanzano_dtk 2:1ef167d1b7b8 111 bool functionality_geo_warning;
fmanzano_dtk 2:1ef167d1b7b8 112 bool functionality_ble_autoreset;
fmanzano_dtk 2:1ef167d1b7b8 113 bool fingerprint_remotly_disable;
fmanzano_dtk 2:1ef167d1b7b8 114 bool fingerprint_override;
fmanzano_dtk 2:1ef167d1b7b8 115 bool finterprint_flag_working = false;
fmanzano_dtk 2:1ef167d1b7b8 116 bool fingerprint_flag_poweroff = false;
fmanzano_dtk 2:1ef167d1b7b8 117
fmanzano_dtk 2:1ef167d1b7b8 118 /**
fmanzano_dtk 2:1ef167d1b7b8 119 * BANDERAS:
fmanzano_dtk 2:1ef167d1b7b8 120 * Se utiliza un esquema de banderas para indicar el cambio de un estado
fmanzano_dtk 2:1ef167d1b7b8 121 * y que se debe realizar un procesamiento especial (transmitir un
fmanzano_dtk 2:1ef167d1b7b8 122 * evento, activar un accesorio, etc.)
fmanzano_dtk 2:1ef167d1b7b8 123 */
fmanzano_dtk 2:1ef167d1b7b8 124
fmanzano_dtk 2:1ef167d1b7b8 125 float time_safety_tip; // 15 minutos = 900
fmanzano_dtk 2:1ef167d1b7b8 126 float time_sample_rain; // muestras a 9 equivalen a 90 segundos o minuto y medio.
fmanzano_dtk 2:1ef167d1b7b8 127 float time_ble_autoreset;
fmanzano_dtk 2:1ef167d1b7b8 128 bool flag_rain_no_answer = false;
fmanzano_dtk 2:1ef167d1b7b8 129 bool flag_idle_force_shutdown = false;
fmanzano_dtk 2:1ef167d1b7b8 130 bool flag_idle_reminder = false;
fmanzano_dtk 2:1ef167d1b7b8 131 bool flag_fingerprint_Sleep = false;
fmanzano_dtk 2:1ef167d1b7b8 132 bool flag_driver_loggin = false;
fmanzano_dtk 2:1ef167d1b7b8 133 bool flag_playingSound = false;
fmanzano_dtk 2:1ef167d1b7b8 134 bool flag_safety_tip = false;
fmanzano_dtk 2:1ef167d1b7b8 135 bool rain_sensor_type = false; // True = RS232, False = DIN
fmanzano_dtk 2:1ef167d1b7b8 136 bool flag_query_rain_sensor;
fmanzano_dtk 2:1ef167d1b7b8 137 bool flag_notify_rain_sensor;
fmanzano_dtk 2:1ef167d1b7b8 138 bool flag_read_inputs;
fmanzano_dtk 2:1ef167d1b7b8 139 bool flag_fingerprint_turOn;
fmanzano_dtk 2:1ef167d1b7b8 140 bool flag_fri_ics;
fmanzano_dtk 2:1ef167d1b7b8 141 int flag_fingerprint_query;
fmanzano_dtk 2:1ef167d1b7b8 142 int flag_ignition;
fmanzano_dtk 2:1ef167d1b7b8 143 int flag_pilot_seatbelt;
fmanzano_dtk 2:1ef167d1b7b8 144 int flag_copilot_seatbelt;
fmanzano_dtk 2:1ef167d1b7b8 145 int flag_crew_pilot_seatbelt;
fmanzano_dtk 2:1ef167d1b7b8 146 int flag_ble_connection_state;
fmanzano_dtk 2:1ef167d1b7b8 147 int flag_rainsensorDigInput;
fmanzano_dtk 2:1ef167d1b7b8 148
fmanzano_dtk 2:1ef167d1b7b8 149 /**
fmanzano_dtk 2:1ef167d1b7b8 150 * ENTRADAS:
fmanzano_dtk 2:1ef167d1b7b8 151 * Para la lectura de entradas digitales se utiliza un estructura de 4
fmanzano_dtk 2:1ef167d1b7b8 152 * variables que incluyen el estado actual de la entrada, el estado previo
fmanzano_dtk 2:1ef167d1b7b8 153 * de la entrada, un arreglo de cuatro posiciones para tomar muestras y
fmanzano_dtk 2:1ef167d1b7b8 154 * realizar la función de debug y un contador para indicar la posición en
fmanzano_dtk 2:1ef167d1b7b8 155 * el arreglo para capturar la muestra de la entrada.
fmanzano_dtk 2:1ef167d1b7b8 156 */
fmanzano_dtk 2:1ef167d1b7b8 157 bool ignition;
fmanzano_dtk 2:1ef167d1b7b8 158 bool estado_actual_ignicion;
fmanzano_dtk 2:1ef167d1b7b8 159 bool ignition_prev;
fmanzano_dtk 2:1ef167d1b7b8 160 bool ignition_samples[4];
fmanzano_dtk 2:1ef167d1b7b8 161 int ignition_counter;
fmanzano_dtk 2:1ef167d1b7b8 162
fmanzano_dtk 2:1ef167d1b7b8 163 bool pilot_seatbelt;
fmanzano_dtk 2:1ef167d1b7b8 164 bool pilot_seatbelt_prev;
fmanzano_dtk 2:1ef167d1b7b8 165 bool pilot_seatbelt_samples[4];
fmanzano_dtk 2:1ef167d1b7b8 166 int pilot_seatbelt_c;
fmanzano_dtk 2:1ef167d1b7b8 167
fmanzano_dtk 2:1ef167d1b7b8 168 bool copilot_seatbelt;
fmanzano_dtk 2:1ef167d1b7b8 169 bool copilot_seatbelt_prev;
fmanzano_dtk 2:1ef167d1b7b8 170 bool copilot_seatbelt_samples[4];
fmanzano_dtk 2:1ef167d1b7b8 171 int copilot_seatbelt_c;
fmanzano_dtk 2:1ef167d1b7b8 172
fmanzano_dtk 2:1ef167d1b7b8 173 bool crew_seatbelt;
fmanzano_dtk 2:1ef167d1b7b8 174 bool crew_seatbelt_prev;
fmanzano_dtk 2:1ef167d1b7b8 175 bool crew_seatbelt_samples[4];
fmanzano_dtk 2:1ef167d1b7b8 176 int crew_seatbelt_c;
fmanzano_dtk 2:1ef167d1b7b8 177
fmanzano_dtk 2:1ef167d1b7b8 178 bool ble_connection_state;
fmanzano_dtk 2:1ef167d1b7b8 179 bool ble_connection_state_prev;
fmanzano_dtk 2:1ef167d1b7b8 180 bool ble_connection_state_samples[4];
fmanzano_dtk 2:1ef167d1b7b8 181 int ble_connection_state_samples_c;
fmanzano_dtk 2:1ef167d1b7b8 182
fmanzano_dtk 2:1ef167d1b7b8 183 bool rg9_raining;
fmanzano_dtk 2:1ef167d1b7b8 184 bool rg9_raining_prev;
fmanzano_dtk 2:1ef167d1b7b8 185 bool rg9_raining_samples[10];
fmanzano_dtk 2:1ef167d1b7b8 186 int rg9_raining_samples_c;
fmanzano_dtk 2:1ef167d1b7b8 187
fmanzano_dtk 2:1ef167d1b7b8 188
fmanzano_dtk 2:1ef167d1b7b8 189 /**
fmanzano_dtk 2:1ef167d1b7b8 190 * FMU130:
fmanzano_dtk 2:1ef167d1b7b8 191 * Se definen las variables para recepción de datos del equipo FMU130 vía
fmanzano_dtk 2:1ef167d1b7b8 192 * enlace Bluetooth SPP
fmanzano_dtk 2:1ef167d1b7b8 193 */
fmanzano_dtk 2:1ef167d1b7b8 194 char fmu130_payload[1024];
fmanzano_dtk 2:1ef167d1b7b8 195 int fmu130_payload_type;
fmanzano_dtk 2:1ef167d1b7b8 196 int incoming_bytes;
fmanzano_dtk 2:1ef167d1b7b8 197 int temp_JQ8400_Volume;
fmanzano_dtk 2:1ef167d1b7b8 198
fmanzano_dtk 2:1ef167d1b7b8 199
fmanzano_dtk 2:1ef167d1b7b8 200 /**
fmanzano_dtk 2:1ef167d1b7b8 201 * HUELLAS:
fmanzano_dtk 2:1ef167d1b7b8 202 * Se definen las variables para el procesamiento del módulo lector de
fmanzano_dtk 2:1ef167d1b7b8 203 * huellas conectado a un UART-TTL
fmanzano_dtk 2:1ef167d1b7b8 204 */
fmanzano_dtk 2:1ef167d1b7b8 205 int bluetooth_cmd_id;
fmanzano_dtk 2:1ef167d1b7b8 206 int fingerprint_id;
fmanzano_dtk 2:1ef167d1b7b8 207 int fingerprint_login;
fmanzano_dtk 2:1ef167d1b7b8 208 char fingerprint_hex[997];
fmanzano_dtk 2:1ef167d1b7b8 209 char fingerprint_asc[499];
fmanzano_dtk 2:1ef167d1b7b8 210 char fingerprint_cmd[4];
fmanzano_dtk 0:2d7ac38345d8 211
fmanzano_dtk 0:2d7ac38345d8 212
fmanzano_dtk 2:1ef167d1b7b8 213 /**
fmanzano_dtk 2:1ef167d1b7b8 214 * EVENTOS_TELTONIKA:
fmanzano_dtk 2:1ef167d1b7b8 215 * Se definen las variables para el procesamiento de Tramas del equipo
fmanzano_dtk 2:1ef167d1b7b8 216 * Teltonika FMU130 con eventos como los hábitos de manejo.
fmanzano_dtk 2:1ef167d1b7b8 217 */
fmanzano_dtk 2:1ef167d1b7b8 218 char avl_fmu130_header[2];
fmanzano_dtk 2:1ef167d1b7b8 219 char avl_fmu130_imei[16];
fmanzano_dtk 2:1ef167d1b7b8 220 int avl_fmu130_id;
fmanzano_dtk 2:1ef167d1b7b8 221 int avl_fmu130_status;
fmanzano_dtk 2:1ef167d1b7b8 222
fmanzano_dtk 2:1ef167d1b7b8 223 /**
fmanzano_dtk 2:1ef167d1b7b8 224 * SENSOR DE LLUVIA RG9:
fmanzano_dtk 2:1ef167d1b7b8 225 * Se definen las variables para el procesamiento de tramas del sensor
fmanzano_dtk 2:1ef167d1b7b8 226 * de lluvia HYDREON RG9.
fmanzano_dtk 2:1ef167d1b7b8 227
fmanzano_dtk 2:1ef167d1b7b8 228 bool rg9_raining;
fmanzano_dtk 2:1ef167d1b7b8 229 char rg9_payload[64];
fmanzano_dtk 2:1ef167d1b7b8 230 int rg9_weather_id;
fmanzano_dtk 2:1ef167d1b7b8 231 int rg9_weather_id_prev;
fmanzano_dtk 2:1ef167d1b7b8 232 int rg9_count_noAnser = 0;
fmanzano_dtk 2:1ef167d1b7b8 233 */
fmanzano_dtk 2:1ef167d1b7b8 234
fmanzano_dtk 2:1ef167d1b7b8 235 // Inicialización de variables de Velocidad
fmanzano_dtk 2:1ef167d1b7b8 236 int wet_Speed_Warning;
fmanzano_dtk 2:1ef167d1b7b8 237 int wet_Speed_Limit;
fmanzano_dtk 2:1ef167d1b7b8 238 int dry_Speed_Warning;
fmanzano_dtk 2:1ef167d1b7b8 239 int dry_Speed_Limit;
fmanzano_dtk 2:1ef167d1b7b8 240 char wet_Speed_CMD[30];
fmanzano_dtk 2:1ef167d1b7b8 241 char dry_Speed_CMD[30];
fmanzano_dtk 2:1ef167d1b7b8 242
fmanzano_dtk 2:1ef167d1b7b8 243
fmanzano_dtk 2:1ef167d1b7b8 244 // Fingerprint Override
fmanzano_dtk 2:1ef167d1b7b8 245 int fp_override_limit; // Limite de lecturas fallidas antes de autorizar
fmanzano_dtk 2:1ef167d1b7b8 246 int fp_unauthorized_count = 0;
fmanzano_dtk 2:1ef167d1b7b8 247 int items_queue = 0;
fmanzano_dtk 2:1ef167d1b7b8 248
fmanzano_dtk 2:1ef167d1b7b8 249 // Inicialización de Entradas Digitales para Cinturón de Seguridad
fmanzano_dtk 2:1ef167d1b7b8 250 // Detalle de entradas por cada cinturon
fmanzano_dtk 2:1ef167d1b7b8 251 bool pilot_buckle_type;
fmanzano_dtk 2:1ef167d1b7b8 252 int pilot_buckleUp;
fmanzano_dtk 2:1ef167d1b7b8 253 int pilot_unfasten;
fmanzano_dtk 2:1ef167d1b7b8 254 bool copilot_buckle_type;
fmanzano_dtk 2:1ef167d1b7b8 255 int copilot_buckleUp;
fmanzano_dtk 2:1ef167d1b7b8 256 int copilot_unfasten;
fmanzano_dtk 2:1ef167d1b7b8 257 bool crew_buckle_type;
fmanzano_dtk 2:1ef167d1b7b8 258 int crew_buckleUp;
fmanzano_dtk 2:1ef167d1b7b8 259 int crew_unfasten;
fmanzano_dtk 2:1ef167d1b7b8 260
fmanzano_dtk 2:1ef167d1b7b8 261 /**
fmanzano_dtk 2:1ef167d1b7b8 262 * TICKER DE mbed:
fmanzano_dtk 2:1ef167d1b7b8 263 * Definición de eventos gestionados por eventos temporizados.
fmanzano_dtk 2:1ef167d1b7b8 264 */
fmanzano_dtk 2:1ef167d1b7b8 265 Ticker tick_blink;
fmanzano_dtk 2:1ef167d1b7b8 266 Ticker tick_rain_sensor; // para comunicación vía UART
fmanzano_dtk 2:1ef167d1b7b8 267 Ticker tick_readInputs;
fmanzano_dtk 2:1ef167d1b7b8 268 Ticker tick_fingerprint;
fmanzano_dtk 2:1ef167d1b7b8 269 Ticker tick_idle_shutdown;
fmanzano_dtk 2:1ef167d1b7b8 270 Ticker tick_idle_reminder;
fmanzano_dtk 2:1ef167d1b7b8 271 Ticker tick_safety_tip;
fmanzano_dtk 2:1ef167d1b7b8 272 Ticker tick_playingAudio;
fmanzano_dtk 2:1ef167d1b7b8 273 Ticker tick_fri_ics;
fmanzano_dtk 2:1ef167d1b7b8 274 Ticker tick_autoreset_ble;
fmanzano_dtk 2:1ef167d1b7b8 275
fmanzano_dtk 2:1ef167d1b7b8 276 /**
fmanzano_dtk 2:1ef167d1b7b8 277 * @brief Función para hacer titilar el LED de usuario.
fmanzano_dtk 2:1ef167d1b7b8 278 *
fmanzano_dtk 2:1ef167d1b7b8 279 */
fmanzano_dtk 2:1ef167d1b7b8 280 void blink_led() {
fmanzano_dtk 2:1ef167d1b7b8 281 myled = !myled;
fmanzano_dtk 2:1ef167d1b7b8 282 }
fmanzano_dtk 2:1ef167d1b7b8 283
fmanzano_dtk 2:1ef167d1b7b8 284 /**
fmanzano_dtk 2:1ef167d1b7b8 285 * @brief Activación de la bandera para leer entradas digitales.
fmanzano_dtk 2:1ef167d1b7b8 286 *
fmanzano_dtk 2:1ef167d1b7b8 287 */
fmanzano_dtk 2:1ef167d1b7b8 288 void readInputs() {
fmanzano_dtk 2:1ef167d1b7b8 289 flag_read_inputs = true;
fmanzano_dtk 2:1ef167d1b7b8 290 }
fmanzano_dtk 2:1ef167d1b7b8 291
fmanzano_dtk 2:1ef167d1b7b8 292 // Función al presionar boton
fmanzano_dtk 2:1ef167d1b7b8 293 void pressed() {
fmanzano_dtk 2:1ef167d1b7b8 294 eeprom_Default();
fmanzano_dtk 2:1ef167d1b7b8 295 wait_ms(100);
fmanzano_dtk 2:1ef167d1b7b8 296 NVIC_SystemReset();
fmanzano_dtk 2:1ef167d1b7b8 297 }
fmanzano_dtk 0:2d7ac38345d8 298
fmanzano_dtk 2:1ef167d1b7b8 299 int main() {
fmanzano_dtk 2:1ef167d1b7b8 300
fmanzano_dtk 2:1ef167d1b7b8 301 /**
fmanzano_dtk 2:1ef167d1b7b8 302 * @brief INICIAR INTERFACES
fmanzano_dtk 2:1ef167d1b7b8 303 * Se define el baudrate para las interfaces USART, y el modo para
fmanzano_dtk 2:1ef167d1b7b8 304 * las entradas digitales. También se envía a tierra el pin para la
fmanzano_dtk 2:1ef167d1b7b8 305 * interface Bluetooth.
fmanzano_dtk 2:1ef167d1b7b8 306 */
fmanzano_dtk 2:1ef167d1b7b8 307 avl_uart.baud(115200);
fmanzano_dtk 2:1ef167d1b7b8 308 fingerprint.baud(9600);
fmanzano_dtk 2:1ef167d1b7b8 309 voice_uart.baud(9600);
fmanzano_dtk 2:1ef167d1b7b8 310 in1_ignition.mode(PullDown);
fmanzano_dtk 2:1ef167d1b7b8 311 in2_pilot.mode(PullDown);
fmanzano_dtk 2:1ef167d1b7b8 312 in3_copilot.mode(PullDown);
fmanzano_dtk 2:1ef167d1b7b8 313 in4_crew.mode(PullDown);
fmanzano_dtk 2:1ef167d1b7b8 314 in5_rain_sensor.mode(PullDown);
fmanzano_dtk 2:1ef167d1b7b8 315 wait_us(1000000);
fmanzano_dtk 2:1ef167d1b7b8 316 out1_fingerprint = 0;
fmanzano_dtk 2:1ef167d1b7b8 317 out2_ble_reset = 0;
fmanzano_dtk 2:1ef167d1b7b8 318 out3_gt521fx = 0;
fmanzano_dtk 2:1ef167d1b7b8 319 out4_gt521fx = 0;
fmanzano_dtk 2:1ef167d1b7b8 320 mybutton.fall(&pressed);
fmanzano_dtk 2:1ef167d1b7b8 321
fmanzano_dtk 2:1ef167d1b7b8 322 //Flash
fmanzano_dtk 2:1ef167d1b7b8 323 boot_message();
fmanzano_dtk 2:1ef167d1b7b8 324 //flash_Booting();
fmanzano_dtk 2:1ef167d1b7b8 325
fmanzano_dtk 2:1ef167d1b7b8 326
fmanzano_dtk 2:1ef167d1b7b8 327 // Configuración Inicial de Nivel de volumen.
fmanzano_dtk 2:1ef167d1b7b8 328 jq8400_iniVol(temp_JQ8400_Volume, &voice_uart);
fmanzano_dtk 2:1ef167d1b7b8 329
fmanzano_dtk 2:1ef167d1b7b8 330 // Iniciar comandos variables de cambio de velocidad
fmanzano_dtk 2:1ef167d1b7b8 331 sprintf(dry_Speed_CMD, "setparam 11104:%d;50092:%d", dry_Speed_Warning, dry_Speed_Limit);
fmanzano_dtk 2:1ef167d1b7b8 332 sprintf(wet_Speed_CMD, "setparam 11104:%d;50092:%d", wet_Speed_Warning, wet_Speed_Limit);
fmanzano_dtk 2:1ef167d1b7b8 333
fmanzano_dtk 2:1ef167d1b7b8 334 /**
fmanzano_dtk 2:1ef167d1b7b8 335 * @brief Se asignan las funciones para los eventos temporizados de titilar
fmanzano_dtk 2:1ef167d1b7b8 336 * el LED de usuario, realizar el muestreo de las entradas digitales
fmanzano_dtk 2:1ef167d1b7b8 337 * y la consulta al sensor de lluvia.
fmanzano_dtk 2:1ef167d1b7b8 338 */
fmanzano_dtk 2:1ef167d1b7b8 339 tick_blink.attach(&blink_led, 2.0);
fmanzano_dtk 2:1ef167d1b7b8 340 tick_readInputs.attach(&readInputs, 0.250);
fmanzano_dtk 2:1ef167d1b7b8 341 if (functionality_rain_sensor) {
fmanzano_dtk 2:1ef167d1b7b8 342 tick_rain_sensor.attach(&queryRG9, time_sample_rain);
fmanzano_dtk 2:1ef167d1b7b8 343 }
fmanzano_dtk 2:1ef167d1b7b8 344 if (functionality_ble_autoreset) {
fmanzano_dtk 2:1ef167d1b7b8 345 tick_autoreset_ble.attach(&BLE_reset, time_ble_autoreset);
fmanzano_dtk 2:1ef167d1b7b8 346 }
fmanzano_dtk 2:1ef167d1b7b8 347
fmanzano_dtk 2:1ef167d1b7b8 348 /**
fmanzano_dtk 2:1ef167d1b7b8 349 * @brief INICIAR WATCHDOG
fmanzano_dtk 2:1ef167d1b7b8 350 * Se crea una instancia para el Watchdog, se define el pre-escaler
fmanzano_dtk 2:1ef167d1b7b8 351 * y el valor máximo en caso que no se actualice se genera el reinicio.
fmanzano_dtk 2:1ef167d1b7b8 352 */
fmanzano_dtk 2:1ef167d1b7b8 353 my_iwdg.Instance = IWDG;
fmanzano_dtk 2:1ef167d1b7b8 354 my_iwdg.Init.Prescaler = IWDG_PRESCALER_256;
fmanzano_dtk 2:1ef167d1b7b8 355 my_iwdg.Init.Reload = 0x0FFF;
fmanzano_dtk 2:1ef167d1b7b8 356 //my_iwdg.Init.Window = IWDG_WINDOW_DISABLE;
fmanzano_dtk 2:1ef167d1b7b8 357 HAL_IWDG_Init(&my_iwdg);
fmanzano_dtk 2:1ef167d1b7b8 358 eeprom_size = ep.getSize();
fmanzano_dtk 2:1ef167d1b7b8 359
fmanzano_dtk 0:2d7ac38345d8 360 while (true) {
fmanzano_dtk 2:1ef167d1b7b8 361
fmanzano_dtk 2:1ef167d1b7b8 362 //! Procesamiento del puerto serial vinculado al FMU130 vía Bluetooth.
fmanzano_dtk 2:1ef167d1b7b8 363 process_FMU130();
fmanzano_dtk 2:1ef167d1b7b8 364
fmanzano_dtk 2:1ef167d1b7b8 365 //! Verificar si deben efectuarse la lectura de entradas digitales.
fmanzano_dtk 2:1ef167d1b7b8 366 if(flag_read_inputs) {
fmanzano_dtk 2:1ef167d1b7b8 367 process_Inputs();
fmanzano_dtk 2:1ef167d1b7b8 368 }
fmanzano_dtk 2:1ef167d1b7b8 369
fmanzano_dtk 2:1ef167d1b7b8 370 //! Verificar si debe activarse el lector de huellas.
fmanzano_dtk 2:1ef167d1b7b8 371 if (flag_fingerprint_query) {
fmanzano_dtk 2:1ef167d1b7b8 372 HAL_IWDG_Refresh(&my_iwdg);
fmanzano_dtk 2:1ef167d1b7b8 373 identify_fingerPrint();
fmanzano_dtk 2:1ef167d1b7b8 374 }
fmanzano_dtk 2:1ef167d1b7b8 375
fmanzano_dtk 2:1ef167d1b7b8 376 //! Verificar si se debe apagar el lector de huellas.
fmanzano_dtk 2:1ef167d1b7b8 377 if (fingerprint_flag_poweroff) {
fmanzano_dtk 2:1ef167d1b7b8 378 out3_gt521fx = out4_gt521fx = finterprint_flag_working = fingerprint_flag_poweroff = false;
fmanzano_dtk 2:1ef167d1b7b8 379 #ifdef DEBUG
fmanzano_dtk 2:1ef167d1b7b8 380 myPC_debug.printf("[MAIN] - OUT3:FALSE\r\n");
fmanzano_dtk 2:1ef167d1b7b8 381 #endif
fmanzano_dtk 2:1ef167d1b7b8 382 }
fmanzano_dtk 2:1ef167d1b7b8 383
fmanzano_dtk 2:1ef167d1b7b8 384
fmanzano_dtk 2:1ef167d1b7b8 385 //! Verificar si debe consultarse el estado del sensor de lluvia.
fmanzano_dtk 2:1ef167d1b7b8 386 if (flag_query_rain_sensor) {
fmanzano_dtk 2:1ef167d1b7b8 387 //process_rainSensor();
fmanzano_dtk 2:1ef167d1b7b8 388 process_inputRainSensor();
fmanzano_dtk 2:1ef167d1b7b8 389 }
fmanzano_dtk 2:1ef167d1b7b8 390
fmanzano_dtk 2:1ef167d1b7b8 391 //! verificar si debe ejecutarse un evento de apagado por ralentí.
fmanzano_dtk 2:1ef167d1b7b8 392 if (flag_idle_force_shutdown) {
fmanzano_dtk 2:1ef167d1b7b8 393 exe_idle_shutdown();
fmanzano_dtk 2:1ef167d1b7b8 394 }
fmanzano_dtk 2:1ef167d1b7b8 395
fmanzano_dtk 2:1ef167d1b7b8 396 if (flag_idle_reminder) {
fmanzano_dtk 2:1ef167d1b7b8 397 exe_idle_reminder();
fmanzano_dtk 2:1ef167d1b7b8 398 }
fmanzano_dtk 2:1ef167d1b7b8 399
fmanzano_dtk 2:1ef167d1b7b8 400 if (flag_safety_tip) {
fmanzano_dtk 2:1ef167d1b7b8 401 exe_SafetyTip();
fmanzano_dtk 2:1ef167d1b7b8 402 }
fmanzano_dtk 2:1ef167d1b7b8 403
fmanzano_dtk 2:1ef167d1b7b8 404 if (flag_fri_ics) {
fmanzano_dtk 2:1ef167d1b7b8 405 tx_fri_ics();
fmanzano_dtk 2:1ef167d1b7b8 406 }
fmanzano_dtk 2:1ef167d1b7b8 407
fmanzano_dtk 2:1ef167d1b7b8 408 if (!(flag_playingSound)) {
fmanzano_dtk 2:1ef167d1b7b8 409 processPlaylist();
fmanzano_dtk 2:1ef167d1b7b8 410 }
fmanzano_dtk 2:1ef167d1b7b8 411
fmanzano_dtk 2:1ef167d1b7b8 412
fmanzano_dtk 2:1ef167d1b7b8 413 //! Actualizar Watchdog
fmanzano_dtk 2:1ef167d1b7b8 414 HAL_IWDG_Refresh(&my_iwdg);
fmanzano_dtk 0:2d7ac38345d8 415 }
fmanzano_dtk 2:1ef167d1b7b8 416 }