Proyecto ABInBev para la tarjeta Guaria 1/2.

Committer:
fmanzano_dtk
Date:
Mon Jul 04 22:28:16 2022 -0600
Revision:
5:07720e3f99d2
Parent:
4:9b1a4a9b2cdf
Child:
6:f4907ba89e16
Se restaura la libreria de Flash como alternativa adicional a la memoria externa de EEPROM

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 "BufferedSerial.h"
fmanzano_dtk 2:1ef167d1b7b8 22 #include "ics5_pinout.hpp"
fmanzano_dtk 2:1ef167d1b7b8 23 #include "jq8400_voice.hpp"
fmanzano_dtk 2:1ef167d1b7b8 24 #include "voice_cn_pa.hpp"
fmanzano_dtk 2:1ef167d1b7b8 25 #include "New_GT521Fx.hpp"
fmanzano_dtk 2:1ef167d1b7b8 26 #include "gpio_exe.hpp"
fmanzano_dtk 2:1ef167d1b7b8 27 #include "fmu130_exe.hpp"
fmanzano_dtk 2:1ef167d1b7b8 28 #include "fingerprint_exe.hpp"
fmanzano_dtk 2:1ef167d1b7b8 29 #include "playlist_exe.hpp"
fmanzano_dtk 2:1ef167d1b7b8 30 #include "playlist.hpp"
fmanzano_dtk 2:1ef167d1b7b8 31 #include "teltonika_fmu130.hpp"
fmanzano_dtk 2:1ef167d1b7b8 32 #include "fireup_exe.hpp"
fmanzano_dtk 2:1ef167d1b7b8 33 #include "safety_tip_exe.hpp"
fmanzano_dtk 2:1ef167d1b7b8 34 #include "eeprom.h"
fmanzano_dtk 5:07720e3f99d2 35 #include "eeprom_exe.hpp"
fmanzano_dtk 2:1ef167d1b7b8 36 #include "USBSerial.h"
fmanzano_dtk 5:07720e3f99d2 37 #include "custom_def.hpp"
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 3:6e55713bc91d 46 #define M_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 3:6e55713bc91d 53 #ifdef M_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 5:07720e3f99d2 93 // FLASH
fmanzano_dtk 5:07720e3f99d2 94 #define FLASH_USER_START_ADDR ADDR_FLASH_SECTOR_2 /* Start @ of user Flash area */
fmanzano_dtk 5:07720e3f99d2 95 #define FLASH_USER_END_ADDR ADDR_FLASH_SECTOR_7
fmanzano_dtk 5:07720e3f99d2 96 + GetSectorSize(ADDR_FLASH_SECTOR_7) -1 /* End @ of user Flash area : sector start address + sector size -1 */
fmanzano_dtk 5:07720e3f99d2 97 #define DATA_32 ((uint32_t)0x12345678)
fmanzano_dtk 2:1ef167d1b7b8 98
fmanzano_dtk 2:1ef167d1b7b8 99 // VOICE
fmanzano_dtk 2:1ef167d1b7b8 100 queue colaPlaylist(10);
fmanzano_dtk 2:1ef167d1b7b8 101
fmanzano_dtk 2:1ef167d1b7b8 102 // HAL BASED
fmanzano_dtk 2:1ef167d1b7b8 103 static IWDG_HandleTypeDef my_iwdg;
fmanzano_dtk 0:2d7ac38345d8 104
fmanzano_dtk 0:2d7ac38345d8 105
fmanzano_dtk 2:1ef167d1b7b8 106 // FUNCIONALIDADES
fmanzano_dtk 2:1ef167d1b7b8 107 // Nuevas banderas para habilitar/deshabilitar funciones.
fmanzano_dtk 2:1ef167d1b7b8 108 bool functionality_idle_shutdown;
fmanzano_dtk 2:1ef167d1b7b8 109 bool functionality_idle_reminder;
fmanzano_dtk 2:1ef167d1b7b8 110 bool functionality_seatbelt_reading;
fmanzano_dtk 2:1ef167d1b7b8 111 bool functionality_force_driver_buclke;
fmanzano_dtk 2:1ef167d1b7b8 112 bool functionality_rain_sensor;
fmanzano_dtk 2:1ef167d1b7b8 113 bool functionality_rainSensor_silentMode;
fmanzano_dtk 2:1ef167d1b7b8 114 bool functionality_fingerprint_reader;
fmanzano_dtk 2:1ef167d1b7b8 115 bool functionality_safety_tip;
fmanzano_dtk 2:1ef167d1b7b8 116 bool functionality_geo_warning;
fmanzano_dtk 2:1ef167d1b7b8 117 bool functionality_ble_autoreset;
fmanzano_dtk 2:1ef167d1b7b8 118 bool fingerprint_remotly_disable;
fmanzano_dtk 2:1ef167d1b7b8 119 bool fingerprint_override;
fmanzano_dtk 2:1ef167d1b7b8 120 bool finterprint_flag_working = false;
fmanzano_dtk 2:1ef167d1b7b8 121 bool fingerprint_flag_poweroff = false;
fmanzano_dtk 2:1ef167d1b7b8 122
fmanzano_dtk 2:1ef167d1b7b8 123 /**
fmanzano_dtk 2:1ef167d1b7b8 124 * BANDERAS:
fmanzano_dtk 2:1ef167d1b7b8 125 * Se utiliza un esquema de banderas para indicar el cambio de un estado
fmanzano_dtk 2:1ef167d1b7b8 126 * y que se debe realizar un procesamiento especial (transmitir un
fmanzano_dtk 2:1ef167d1b7b8 127 * evento, activar un accesorio, etc.)
fmanzano_dtk 2:1ef167d1b7b8 128 */
fmanzano_dtk 2:1ef167d1b7b8 129
fmanzano_dtk 2:1ef167d1b7b8 130 float time_safety_tip; // 15 minutos = 900
fmanzano_dtk 2:1ef167d1b7b8 131 float time_sample_rain; // muestras a 9 equivalen a 90 segundos o minuto y medio.
fmanzano_dtk 2:1ef167d1b7b8 132 float time_ble_autoreset;
fmanzano_dtk 2:1ef167d1b7b8 133 bool flag_rain_no_answer = false;
fmanzano_dtk 2:1ef167d1b7b8 134 bool flag_idle_force_shutdown = false;
fmanzano_dtk 2:1ef167d1b7b8 135 bool flag_idle_reminder = false;
fmanzano_dtk 2:1ef167d1b7b8 136 bool flag_fingerprint_Sleep = false;
fmanzano_dtk 2:1ef167d1b7b8 137 bool flag_driver_loggin = false;
fmanzano_dtk 2:1ef167d1b7b8 138 bool flag_playingSound = false;
fmanzano_dtk 2:1ef167d1b7b8 139 bool flag_safety_tip = false;
fmanzano_dtk 2:1ef167d1b7b8 140 bool rain_sensor_type = false; // True = RS232, False = DIN
fmanzano_dtk 2:1ef167d1b7b8 141 bool flag_query_rain_sensor;
fmanzano_dtk 2:1ef167d1b7b8 142 bool flag_notify_rain_sensor;
fmanzano_dtk 2:1ef167d1b7b8 143 bool flag_read_inputs;
fmanzano_dtk 2:1ef167d1b7b8 144 bool flag_fingerprint_turOn;
fmanzano_dtk 2:1ef167d1b7b8 145 bool flag_fri_ics;
fmanzano_dtk 2:1ef167d1b7b8 146 int flag_fingerprint_query;
fmanzano_dtk 2:1ef167d1b7b8 147 int flag_ignition;
fmanzano_dtk 2:1ef167d1b7b8 148 int flag_pilot_seatbelt;
fmanzano_dtk 2:1ef167d1b7b8 149 int flag_copilot_seatbelt;
fmanzano_dtk 2:1ef167d1b7b8 150 int flag_crew_pilot_seatbelt;
fmanzano_dtk 2:1ef167d1b7b8 151 int flag_ble_connection_state;
fmanzano_dtk 2:1ef167d1b7b8 152 int flag_rainsensorDigInput;
fmanzano_dtk 2:1ef167d1b7b8 153
fmanzano_dtk 2:1ef167d1b7b8 154 /**
fmanzano_dtk 2:1ef167d1b7b8 155 * ENTRADAS:
fmanzano_dtk 2:1ef167d1b7b8 156 * Para la lectura de entradas digitales se utiliza un estructura de 4
fmanzano_dtk 2:1ef167d1b7b8 157 * variables que incluyen el estado actual de la entrada, el estado previo
fmanzano_dtk 2:1ef167d1b7b8 158 * de la entrada, un arreglo de cuatro posiciones para tomar muestras y
fmanzano_dtk 2:1ef167d1b7b8 159 * realizar la función de debug y un contador para indicar la posición en
fmanzano_dtk 2:1ef167d1b7b8 160 * el arreglo para capturar la muestra de la entrada.
fmanzano_dtk 2:1ef167d1b7b8 161 */
fmanzano_dtk 2:1ef167d1b7b8 162 bool ignition;
fmanzano_dtk 2:1ef167d1b7b8 163 bool estado_actual_ignicion;
fmanzano_dtk 2:1ef167d1b7b8 164 bool ignition_prev;
fmanzano_dtk 2:1ef167d1b7b8 165 bool ignition_samples[4];
fmanzano_dtk 2:1ef167d1b7b8 166 int ignition_counter;
fmanzano_dtk 2:1ef167d1b7b8 167
fmanzano_dtk 2:1ef167d1b7b8 168 bool pilot_seatbelt;
fmanzano_dtk 2:1ef167d1b7b8 169 bool pilot_seatbelt_prev;
fmanzano_dtk 2:1ef167d1b7b8 170 bool pilot_seatbelt_samples[4];
fmanzano_dtk 2:1ef167d1b7b8 171 int pilot_seatbelt_c;
fmanzano_dtk 2:1ef167d1b7b8 172
fmanzano_dtk 2:1ef167d1b7b8 173 bool copilot_seatbelt;
fmanzano_dtk 2:1ef167d1b7b8 174 bool copilot_seatbelt_prev;
fmanzano_dtk 2:1ef167d1b7b8 175 bool copilot_seatbelt_samples[4];
fmanzano_dtk 2:1ef167d1b7b8 176 int copilot_seatbelt_c;
fmanzano_dtk 2:1ef167d1b7b8 177
fmanzano_dtk 2:1ef167d1b7b8 178 bool crew_seatbelt;
fmanzano_dtk 2:1ef167d1b7b8 179 bool crew_seatbelt_prev;
fmanzano_dtk 2:1ef167d1b7b8 180 bool crew_seatbelt_samples[4];
fmanzano_dtk 2:1ef167d1b7b8 181 int crew_seatbelt_c;
fmanzano_dtk 2:1ef167d1b7b8 182
fmanzano_dtk 2:1ef167d1b7b8 183 bool ble_connection_state;
fmanzano_dtk 2:1ef167d1b7b8 184 bool ble_connection_state_prev;
fmanzano_dtk 2:1ef167d1b7b8 185 bool ble_connection_state_samples[4];
fmanzano_dtk 2:1ef167d1b7b8 186 int ble_connection_state_samples_c;
fmanzano_dtk 2:1ef167d1b7b8 187
fmanzano_dtk 2:1ef167d1b7b8 188 bool rg9_raining;
fmanzano_dtk 2:1ef167d1b7b8 189 bool rg9_raining_prev;
fmanzano_dtk 2:1ef167d1b7b8 190 bool rg9_raining_samples[10];
fmanzano_dtk 2:1ef167d1b7b8 191 int rg9_raining_samples_c;
fmanzano_dtk 2:1ef167d1b7b8 192
fmanzano_dtk 2:1ef167d1b7b8 193
fmanzano_dtk 2:1ef167d1b7b8 194 /**
fmanzano_dtk 2:1ef167d1b7b8 195 * FMU130:
fmanzano_dtk 2:1ef167d1b7b8 196 * Se definen las variables para recepción de datos del equipo FMU130 vía
fmanzano_dtk 2:1ef167d1b7b8 197 * enlace Bluetooth SPP
fmanzano_dtk 2:1ef167d1b7b8 198 */
fmanzano_dtk 2:1ef167d1b7b8 199 char fmu130_payload[1024];
fmanzano_dtk 2:1ef167d1b7b8 200 int fmu130_payload_type;
fmanzano_dtk 2:1ef167d1b7b8 201 int incoming_bytes;
fmanzano_dtk 2:1ef167d1b7b8 202 int temp_JQ8400_Volume;
fmanzano_dtk 2:1ef167d1b7b8 203
fmanzano_dtk 2:1ef167d1b7b8 204
fmanzano_dtk 2:1ef167d1b7b8 205 /**
fmanzano_dtk 2:1ef167d1b7b8 206 * HUELLAS:
fmanzano_dtk 2:1ef167d1b7b8 207 * Se definen las variables para el procesamiento del módulo lector de
fmanzano_dtk 2:1ef167d1b7b8 208 * huellas conectado a un UART-TTL
fmanzano_dtk 2:1ef167d1b7b8 209 */
fmanzano_dtk 2:1ef167d1b7b8 210 int bluetooth_cmd_id;
fmanzano_dtk 2:1ef167d1b7b8 211 int fingerprint_id;
fmanzano_dtk 2:1ef167d1b7b8 212 int fingerprint_login;
fmanzano_dtk 2:1ef167d1b7b8 213 char fingerprint_hex[997];
fmanzano_dtk 2:1ef167d1b7b8 214 char fingerprint_asc[499];
fmanzano_dtk 2:1ef167d1b7b8 215 char fingerprint_cmd[4];
fmanzano_dtk 0:2d7ac38345d8 216
fmanzano_dtk 0:2d7ac38345d8 217
fmanzano_dtk 2:1ef167d1b7b8 218 /**
fmanzano_dtk 2:1ef167d1b7b8 219 * EVENTOS_TELTONIKA:
fmanzano_dtk 2:1ef167d1b7b8 220 * Se definen las variables para el procesamiento de Tramas del equipo
fmanzano_dtk 2:1ef167d1b7b8 221 * Teltonika FMU130 con eventos como los hábitos de manejo.
fmanzano_dtk 2:1ef167d1b7b8 222 */
fmanzano_dtk 2:1ef167d1b7b8 223 char avl_fmu130_header[2];
fmanzano_dtk 2:1ef167d1b7b8 224 char avl_fmu130_imei[16];
fmanzano_dtk 2:1ef167d1b7b8 225 int avl_fmu130_id;
fmanzano_dtk 2:1ef167d1b7b8 226 int avl_fmu130_status;
fmanzano_dtk 2:1ef167d1b7b8 227
fmanzano_dtk 2:1ef167d1b7b8 228 /**
fmanzano_dtk 2:1ef167d1b7b8 229 * SENSOR DE LLUVIA RG9:
fmanzano_dtk 2:1ef167d1b7b8 230 * Se definen las variables para el procesamiento de tramas del sensor
fmanzano_dtk 2:1ef167d1b7b8 231 * de lluvia HYDREON RG9.
fmanzano_dtk 2:1ef167d1b7b8 232
fmanzano_dtk 2:1ef167d1b7b8 233 bool rg9_raining;
fmanzano_dtk 2:1ef167d1b7b8 234 char rg9_payload[64];
fmanzano_dtk 2:1ef167d1b7b8 235 int rg9_weather_id;
fmanzano_dtk 2:1ef167d1b7b8 236 int rg9_weather_id_prev;
fmanzano_dtk 2:1ef167d1b7b8 237 int rg9_count_noAnser = 0;
fmanzano_dtk 2:1ef167d1b7b8 238 */
fmanzano_dtk 2:1ef167d1b7b8 239
fmanzano_dtk 2:1ef167d1b7b8 240 // Inicialización de variables de Velocidad
fmanzano_dtk 2:1ef167d1b7b8 241 int wet_Speed_Warning;
fmanzano_dtk 2:1ef167d1b7b8 242 int wet_Speed_Limit;
fmanzano_dtk 2:1ef167d1b7b8 243 int dry_Speed_Warning;
fmanzano_dtk 2:1ef167d1b7b8 244 int dry_Speed_Limit;
fmanzano_dtk 2:1ef167d1b7b8 245 char wet_Speed_CMD[30];
fmanzano_dtk 2:1ef167d1b7b8 246 char dry_Speed_CMD[30];
fmanzano_dtk 2:1ef167d1b7b8 247
fmanzano_dtk 2:1ef167d1b7b8 248
fmanzano_dtk 2:1ef167d1b7b8 249 // Fingerprint Override
fmanzano_dtk 2:1ef167d1b7b8 250 int fp_override_limit; // Limite de lecturas fallidas antes de autorizar
fmanzano_dtk 2:1ef167d1b7b8 251 int fp_unauthorized_count = 0;
fmanzano_dtk 2:1ef167d1b7b8 252 int items_queue = 0;
fmanzano_dtk 2:1ef167d1b7b8 253
fmanzano_dtk 2:1ef167d1b7b8 254 // Inicialización de Entradas Digitales para Cinturón de Seguridad
fmanzano_dtk 2:1ef167d1b7b8 255 // Detalle de entradas por cada cinturon
fmanzano_dtk 2:1ef167d1b7b8 256 bool pilot_buckle_type;
fmanzano_dtk 2:1ef167d1b7b8 257 int pilot_buckleUp;
fmanzano_dtk 2:1ef167d1b7b8 258 int pilot_unfasten;
fmanzano_dtk 2:1ef167d1b7b8 259 bool copilot_buckle_type;
fmanzano_dtk 2:1ef167d1b7b8 260 int copilot_buckleUp;
fmanzano_dtk 2:1ef167d1b7b8 261 int copilot_unfasten;
fmanzano_dtk 2:1ef167d1b7b8 262 bool crew_buckle_type;
fmanzano_dtk 2:1ef167d1b7b8 263 int crew_buckleUp;
fmanzano_dtk 2:1ef167d1b7b8 264 int crew_unfasten;
fmanzano_dtk 2:1ef167d1b7b8 265
fmanzano_dtk 2:1ef167d1b7b8 266 /**
fmanzano_dtk 2:1ef167d1b7b8 267 * TICKER DE mbed:
fmanzano_dtk 2:1ef167d1b7b8 268 * Definición de eventos gestionados por eventos temporizados.
fmanzano_dtk 2:1ef167d1b7b8 269 */
fmanzano_dtk 2:1ef167d1b7b8 270 Ticker tick_blink;
fmanzano_dtk 2:1ef167d1b7b8 271 Ticker tick_rain_sensor; // para comunicación vía UART
fmanzano_dtk 2:1ef167d1b7b8 272 Ticker tick_readInputs;
fmanzano_dtk 2:1ef167d1b7b8 273 Ticker tick_fingerprint;
fmanzano_dtk 2:1ef167d1b7b8 274 Ticker tick_idle_shutdown;
fmanzano_dtk 2:1ef167d1b7b8 275 Ticker tick_idle_reminder;
fmanzano_dtk 2:1ef167d1b7b8 276 Ticker tick_safety_tip;
fmanzano_dtk 2:1ef167d1b7b8 277 Ticker tick_playingAudio;
fmanzano_dtk 2:1ef167d1b7b8 278 Ticker tick_fri_ics;
fmanzano_dtk 2:1ef167d1b7b8 279 Ticker tick_autoreset_ble;
fmanzano_dtk 2:1ef167d1b7b8 280
fmanzano_dtk 2:1ef167d1b7b8 281 /**
fmanzano_dtk 2:1ef167d1b7b8 282 * @brief Función para hacer titilar el LED de usuario.
fmanzano_dtk 2:1ef167d1b7b8 283 *
fmanzano_dtk 2:1ef167d1b7b8 284 */
fmanzano_dtk 2:1ef167d1b7b8 285 void blink_led() {
fmanzano_dtk 2:1ef167d1b7b8 286 myled = !myled;
fmanzano_dtk 2:1ef167d1b7b8 287 }
fmanzano_dtk 2:1ef167d1b7b8 288
fmanzano_dtk 2:1ef167d1b7b8 289 /**
fmanzano_dtk 2:1ef167d1b7b8 290 * @brief Activación de la bandera para leer entradas digitales.
fmanzano_dtk 2:1ef167d1b7b8 291 *
fmanzano_dtk 2:1ef167d1b7b8 292 */
fmanzano_dtk 2:1ef167d1b7b8 293 void readInputs() {
fmanzano_dtk 2:1ef167d1b7b8 294 flag_read_inputs = true;
fmanzano_dtk 2:1ef167d1b7b8 295 }
fmanzano_dtk 2:1ef167d1b7b8 296
fmanzano_dtk 2:1ef167d1b7b8 297 // Función al presionar boton
fmanzano_dtk 2:1ef167d1b7b8 298 void pressed() {
fmanzano_dtk 2:1ef167d1b7b8 299 eeprom_Default();
fmanzano_dtk 2:1ef167d1b7b8 300 wait_ms(100);
fmanzano_dtk 2:1ef167d1b7b8 301 NVIC_SystemReset();
fmanzano_dtk 2:1ef167d1b7b8 302 }
fmanzano_dtk 0:2d7ac38345d8 303
fmanzano_dtk 2:1ef167d1b7b8 304 int main() {
fmanzano_dtk 2:1ef167d1b7b8 305
fmanzano_dtk 2:1ef167d1b7b8 306 /**
fmanzano_dtk 2:1ef167d1b7b8 307 * @brief INICIAR INTERFACES
fmanzano_dtk 2:1ef167d1b7b8 308 * Se define el baudrate para las interfaces USART, y el modo para
fmanzano_dtk 2:1ef167d1b7b8 309 * las entradas digitales. También se envía a tierra el pin para la
fmanzano_dtk 2:1ef167d1b7b8 310 * interface Bluetooth.
fmanzano_dtk 2:1ef167d1b7b8 311 */
fmanzano_dtk 2:1ef167d1b7b8 312 avl_uart.baud(115200);
fmanzano_dtk 2:1ef167d1b7b8 313 fingerprint.baud(9600);
fmanzano_dtk 2:1ef167d1b7b8 314 voice_uart.baud(9600);
fmanzano_dtk 2:1ef167d1b7b8 315 in1_ignition.mode(PullDown);
fmanzano_dtk 2:1ef167d1b7b8 316 in2_pilot.mode(PullDown);
fmanzano_dtk 2:1ef167d1b7b8 317 in3_copilot.mode(PullDown);
fmanzano_dtk 2:1ef167d1b7b8 318 in4_crew.mode(PullDown);
fmanzano_dtk 2:1ef167d1b7b8 319 in5_rain_sensor.mode(PullDown);
fmanzano_dtk 2:1ef167d1b7b8 320 wait_us(1000000);
fmanzano_dtk 2:1ef167d1b7b8 321 out1_fingerprint = 0;
fmanzano_dtk 2:1ef167d1b7b8 322 out2_ble_reset = 0;
fmanzano_dtk 2:1ef167d1b7b8 323 out3_gt521fx = 0;
fmanzano_dtk 2:1ef167d1b7b8 324 out4_gt521fx = 0;
fmanzano_dtk 2:1ef167d1b7b8 325 mybutton.fall(&pressed);
fmanzano_dtk 2:1ef167d1b7b8 326
fmanzano_dtk 2:1ef167d1b7b8 327 //Flash
fmanzano_dtk 2:1ef167d1b7b8 328 boot_message();
fmanzano_dtk 3:6e55713bc91d 329 load_eepromVar();
fmanzano_dtk 2:1ef167d1b7b8 330
fmanzano_dtk 2:1ef167d1b7b8 331
fmanzano_dtk 2:1ef167d1b7b8 332 // Configuración Inicial de Nivel de volumen.
fmanzano_dtk 2:1ef167d1b7b8 333 jq8400_iniVol(temp_JQ8400_Volume, &voice_uart);
fmanzano_dtk 2:1ef167d1b7b8 334
fmanzano_dtk 2:1ef167d1b7b8 335 // Iniciar comandos variables de cambio de velocidad
fmanzano_dtk 2:1ef167d1b7b8 336 sprintf(dry_Speed_CMD, "setparam 11104:%d;50092:%d", dry_Speed_Warning, dry_Speed_Limit);
fmanzano_dtk 2:1ef167d1b7b8 337 sprintf(wet_Speed_CMD, "setparam 11104:%d;50092:%d", wet_Speed_Warning, wet_Speed_Limit);
fmanzano_dtk 2:1ef167d1b7b8 338
fmanzano_dtk 2:1ef167d1b7b8 339 /**
fmanzano_dtk 2:1ef167d1b7b8 340 * @brief Se asignan las funciones para los eventos temporizados de titilar
fmanzano_dtk 2:1ef167d1b7b8 341 * el LED de usuario, realizar el muestreo de las entradas digitales
fmanzano_dtk 2:1ef167d1b7b8 342 * y la consulta al sensor de lluvia.
fmanzano_dtk 2:1ef167d1b7b8 343 */
fmanzano_dtk 2:1ef167d1b7b8 344 tick_blink.attach(&blink_led, 2.0);
fmanzano_dtk 2:1ef167d1b7b8 345 tick_readInputs.attach(&readInputs, 0.250);
fmanzano_dtk 2:1ef167d1b7b8 346 if (functionality_rain_sensor) {
fmanzano_dtk 2:1ef167d1b7b8 347 tick_rain_sensor.attach(&queryRG9, time_sample_rain);
fmanzano_dtk 2:1ef167d1b7b8 348 }
fmanzano_dtk 2:1ef167d1b7b8 349 if (functionality_ble_autoreset) {
fmanzano_dtk 2:1ef167d1b7b8 350 tick_autoreset_ble.attach(&BLE_reset, time_ble_autoreset);
fmanzano_dtk 2:1ef167d1b7b8 351 }
fmanzano_dtk 2:1ef167d1b7b8 352
fmanzano_dtk 2:1ef167d1b7b8 353 /**
fmanzano_dtk 2:1ef167d1b7b8 354 * @brief INICIAR WATCHDOG
fmanzano_dtk 2:1ef167d1b7b8 355 * Se crea una instancia para el Watchdog, se define el pre-escaler
fmanzano_dtk 2:1ef167d1b7b8 356 * y el valor máximo en caso que no se actualice se genera el reinicio.
fmanzano_dtk 2:1ef167d1b7b8 357 */
fmanzano_dtk 2:1ef167d1b7b8 358 my_iwdg.Instance = IWDG;
fmanzano_dtk 4:9b1a4a9b2cdf 359 my_iwdg.Init.Prescaler = IWDG_PRESCALER_32;
fmanzano_dtk 2:1ef167d1b7b8 360 my_iwdg.Init.Reload = 0x0FFF;
fmanzano_dtk 2:1ef167d1b7b8 361 HAL_IWDG_Init(&my_iwdg);
fmanzano_dtk 4:9b1a4a9b2cdf 362
fmanzano_dtk 4:9b1a4a9b2cdf 363 // Inicializar la EEPROM
fmanzano_dtk 2:1ef167d1b7b8 364 eeprom_size = ep.getSize();
fmanzano_dtk 2:1ef167d1b7b8 365
fmanzano_dtk 0:2d7ac38345d8 366 while (true) {
fmanzano_dtk 2:1ef167d1b7b8 367
fmanzano_dtk 2:1ef167d1b7b8 368 //! Procesamiento del puerto serial vinculado al FMU130 vía Bluetooth.
fmanzano_dtk 2:1ef167d1b7b8 369 process_FMU130();
fmanzano_dtk 2:1ef167d1b7b8 370
fmanzano_dtk 2:1ef167d1b7b8 371 //! Verificar si deben efectuarse la lectura de entradas digitales.
fmanzano_dtk 2:1ef167d1b7b8 372 if(flag_read_inputs) {
fmanzano_dtk 2:1ef167d1b7b8 373 process_Inputs();
fmanzano_dtk 2:1ef167d1b7b8 374 }
fmanzano_dtk 2:1ef167d1b7b8 375
fmanzano_dtk 2:1ef167d1b7b8 376 //! Verificar si debe activarse el lector de huellas.
fmanzano_dtk 2:1ef167d1b7b8 377 if (flag_fingerprint_query) {
fmanzano_dtk 2:1ef167d1b7b8 378 HAL_IWDG_Refresh(&my_iwdg);
fmanzano_dtk 2:1ef167d1b7b8 379 identify_fingerPrint();
fmanzano_dtk 2:1ef167d1b7b8 380 }
fmanzano_dtk 2:1ef167d1b7b8 381
fmanzano_dtk 2:1ef167d1b7b8 382 //! Verificar si se debe apagar el lector de huellas.
fmanzano_dtk 2:1ef167d1b7b8 383 if (fingerprint_flag_poweroff) {
fmanzano_dtk 2:1ef167d1b7b8 384 out3_gt521fx = out4_gt521fx = finterprint_flag_working = fingerprint_flag_poweroff = false;
fmanzano_dtk 3:6e55713bc91d 385 #ifdef M_DEBUG
fmanzano_dtk 2:1ef167d1b7b8 386 myPC_debug.printf("[MAIN] - OUT3:FALSE\r\n");
fmanzano_dtk 2:1ef167d1b7b8 387 #endif
fmanzano_dtk 2:1ef167d1b7b8 388 }
fmanzano_dtk 2:1ef167d1b7b8 389
fmanzano_dtk 2:1ef167d1b7b8 390 //! Verificar si debe consultarse el estado del sensor de lluvia.
fmanzano_dtk 2:1ef167d1b7b8 391 if (flag_query_rain_sensor) {
fmanzano_dtk 2:1ef167d1b7b8 392 //process_rainSensor();
fmanzano_dtk 2:1ef167d1b7b8 393 process_inputRainSensor();
fmanzano_dtk 2:1ef167d1b7b8 394 }
fmanzano_dtk 2:1ef167d1b7b8 395
fmanzano_dtk 2:1ef167d1b7b8 396 //! verificar si debe ejecutarse un evento de apagado por ralentí.
fmanzano_dtk 2:1ef167d1b7b8 397 if (flag_idle_force_shutdown) {
fmanzano_dtk 2:1ef167d1b7b8 398 exe_idle_shutdown();
fmanzano_dtk 2:1ef167d1b7b8 399 }
fmanzano_dtk 2:1ef167d1b7b8 400
fmanzano_dtk 2:1ef167d1b7b8 401 if (flag_idle_reminder) {
fmanzano_dtk 2:1ef167d1b7b8 402 exe_idle_reminder();
fmanzano_dtk 2:1ef167d1b7b8 403 }
fmanzano_dtk 2:1ef167d1b7b8 404
fmanzano_dtk 2:1ef167d1b7b8 405 if (flag_safety_tip) {
fmanzano_dtk 2:1ef167d1b7b8 406 exe_SafetyTip();
fmanzano_dtk 2:1ef167d1b7b8 407 }
fmanzano_dtk 2:1ef167d1b7b8 408
fmanzano_dtk 2:1ef167d1b7b8 409 if (flag_fri_ics) {
fmanzano_dtk 2:1ef167d1b7b8 410 tx_fri_ics();
fmanzano_dtk 2:1ef167d1b7b8 411 }
fmanzano_dtk 2:1ef167d1b7b8 412
fmanzano_dtk 2:1ef167d1b7b8 413 if (!(flag_playingSound)) {
fmanzano_dtk 2:1ef167d1b7b8 414 processPlaylist();
fmanzano_dtk 2:1ef167d1b7b8 415 }
fmanzano_dtk 2:1ef167d1b7b8 416
fmanzano_dtk 2:1ef167d1b7b8 417 //! Actualizar Watchdog
fmanzano_dtk 2:1ef167d1b7b8 418 HAL_IWDG_Refresh(&my_iwdg);
fmanzano_dtk 0:2d7ac38345d8 419 }
fmanzano_dtk 2:1ef167d1b7b8 420 }