Repositório para códigos do painel da plataforma SATC
Dependencies: MFRC522 mbed-STM32F103C8T6 mbed
Fork of C_005_EA_Painel_sem_bms by
main.h
00001 #include "helpers.h" 00002 #include "stm32f103c8t6.h" 00003 #include "mbed.h" 00004 #include <leitor_rfid.h> 00005 #include <string.h> 00006 00007 // Lista de possiveis botoes apertados. 00008 00009 typedef enum PainelButton{ 00010 BUTTON_none, 00011 BUTTON_forward, 00012 BUTTON_backward, 00013 BUTTON_headlights 00014 }PainelButton; 00015 // estados possiveis do farol 00016 typedef enum Farol{ 00017 FAROL_off = 0, 00018 FAROL_on 00019 }Farol; 00020 /* 00021 Struct contendo informacoes sobre o estado. 00022 'pressed_button': utilizado para aferir se algum botao esta sendo acionado 00023 'farol': utilizado para armazenar o estado do farol, se ligado ou desligado 00024 */ 00025 typedef struct Painel{ 00026 PainelButton pressed_button; 00027 Farol farol; 00028 }Painel; 00029 00030 typedef struct CanStatus{ 00031 bool can_bms_ok; 00032 bool can_inversor_ok; 00033 }CanStatus; 00034 00035 typedef struct FalhasEAlarmes{ 00036 uint16_t falha_weg; 00037 uint16_t falha_bms; 00038 uint16_t falha_mca; 00039 uint16_t alarme_weg; 00040 uint16_t alarme_mca; 00041 }FalhasEAlarmes; 00042 00043 enum CAN_ENVIO{ 00044 CAN_ID_acionamentos = 0x0CF00003, 00045 CAN_ID_falhas_e_alarmes = 0x0CF10003, 00046 CAN_ID_id_usuario = 0x0CF20003, 00047 CAN_ID_ESTADO_DO_CARRO = 0x0CF30003, 00048 }; 00049 00050 enum CAN_RECEBIMENTO{ 00051 CAN_ID_WEG_FALHAS_E_ALARMES = 0x0CF80002, 00052 CAN_ID_WEG_SENTIDO_DE_MOVIMENTO = 0x0CF10002, 00053 CAN_ID_BMS_FALHAS_E_ALARMES = 0x186455F4, 00054 CAN_ID_BMS_SOC = 0x186555F4, 00055 }; 00056 // Parametros de leds e PWM 00057 const uint8_t leds_pwm_period = 5; 00058 const int buzzer_period_us = 500; 00059 00060 // Duty cycle para saidas pwm conforme estados 00061 const float D_ON_LED_FRENTE_RE = 0.8; 00062 const float D_OFF_LED_FRENTE_RE = 0.001; 00063 const float D_ON_LED_HEADLIGHT = 0.8; 00064 const float D_OFF_LED_HEADLIGHT = 0.001; 00065 const float D_BUZZER_STD = 0.5; 00066 00067 // Definicoes de intensidade de leds 00068 const float led_max = 1; 00069 const float led_strong = 0.8; 00070 const float led_average = 0.5; 00071 const float led_weak = 0.1; 00072 00073 //Parametro para debounce dos botoes 00074 const uint8_t BUTTON_COOLDOWN_COUNTER_RESET = 6; 00075 // referente ao polling de botoes 00076 const int n_amostras = 5; 00077 const int button_treshold = 4; 00078 const float button_polling_period = 0.010; 00079 00080 const uint8_t VELOCIDADE_CARRO_PARADO = 3; 00081 const uint16_t SOC_BAIXA_CARGA = 10; 00082 const uint16_t CHARGE_CURRENT_CHARGING = 2; 00083 // Prototipos das funcoes 00084 00085 void checkButtons(); 00086 void beepBuzzer(int ms_duration); 00087 void initPWMs(); 00088 bool setLedsAndRelays(PainelButton button); 00089 void turnOnSetup(); 00090 void turnOffSetup(); 00091 void enableAntenna(); 00092 void setRfInterrupt(); 00093 void handlePressedButton(); 00094 void enviaEstadoDeAcionamentosFalhasEAlarmesViaCAN(); 00095 void buzzWrongCard(); 00096 void getMsg(); 00097 int sendCanMsg(int id=0, const char *data=0, char len=8, CANType type=CANData, CANFormat format=CANExtended); 00098 void populaArrayFalhasEAlarmes(char* array, size_t n); 00099 void tentaDesligarCarro(); 00100 void tentaLigarCarro(); 00101 void afirmaFalha(int flag_not_ok, uint16_t DTC_da_falha, volatile uint16_t* falha); 00102 int sendCanCarState();
Generated on Wed Jul 13 2022 23:43:00 by
1.7.2
