EZR
Dependencies: CRC16 FreescaleIAP FreescaleWatchdog GGSProtocol LM75B PIMA Parameters PersistentCircularQueue SerialNumberV2COM mbed-dev-watchdog_2016_03_04
Fork of smartRamalKW by
Revision 24:69e7e7079915, committed 2015-10-27
- Comitter:
- tpadovani
- Date:
- Tue Oct 27 21:54:09 2015 +0000
- Parent:
- 23:85202a52482d
- Child:
- 25:2c578b923ea9
- Commit message:
- Modificada deteccao de tensao na carga e retorno de potencial. Novo comando para ler as temperaturas.
Changed in this revision
--- a/PIMA.lib Tue Oct 20 21:53:16 2015 +0000 +++ b/PIMA.lib Tue Oct 27 21:54:09 2015 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/teams/Equipe-Firmware-V2COM/code/PIMA/#69bfca22ff6b +https://developer.mbed.org/teams/Equipe-Firmware-V2COM/code/PIMA/#47413cd01766
--- a/appCommands.cpp Tue Oct 20 21:53:16 2015 +0000 +++ b/appCommands.cpp Tue Oct 27 21:54:09 2015 +0000 @@ -58,17 +58,11 @@ case CMD_LER_RELOGIO: cmdLerRelogio(); break; - case CMD_TENSAO_INSTANTANEA: - cmdTensaoInstantanea(dados[0]); - break; - case CMD_CORRENTE_INSTANTANEA: - cmdCorrenteInstantanea(); + case CMD_GRANDEZA_INSTANTANEA: + cmdGrandezaInstantanea(dados[0]); break; - case CMD_MM_TENSAO: - cmdMMTensao(dados[0], dados[1]); - break; - case CMD_MM_CORRENTE: - cmdMMCorrente(dados[0]); + case CMD_MEMORIA_MASSA: + cmdMemoriaMassa(dados[0], dados[1]); break; // case CMD_DETECTA_CARGA: // cmdDetectaCarga(); @@ -91,6 +85,9 @@ case CMD_GRAVAR_RELOGIO: cmdGravarRelogio(dados, tamanho - TAMANHO_MINIMO_PACOTE); break; + case CMD_TEMPERATURA: + cmdLerTemperatura(dados[0]); + break; } }
--- a/appCommands.h Tue Oct 20 21:53:16 2015 +0000 +++ b/appCommands.h Tue Oct 27 21:54:09 2015 +0000 @@ -41,14 +41,14 @@ #define RESP_CONFIGURAR_PARAMETROS 0x1e #define CMD_LER_RELOGIO 0x1f #define RESP_LER_RELOGIO 0x20 -#define CMD_TENSAO_INSTANTANEA 0x21 -#define RESP_TENSAO_INSTANTANEA 0x22 -#define CMD_CORRENTE_INSTANTANEA 0x23 -#define RESP_CORRENTE_INSTANTANEA 0x24 -#define CMD_MM_TENSAO 0x25 -#define RESP_MM_TENSAO 0x26 -#define CMD_MM_CORRENTE 0x27 -#define RESP_MM_CORRENTE 0x28 +#define CMD_GRANDEZA_INSTANTANEA 0x21 +#define RESP_GRANDEZA_INSTANTANEA 0x22 +#define CMD_TEMPERATURA 0x23 +#define RESP_TEMPERATURA 0x24 +#define CMD_MEMORIA_MASSA 0x25 +#define RESP_MEMORIA_MASSA 0x26 +//#define RESERVADO 0x27 +//#define RESERVADO 0x28 //#define CMD_DETECTA_CARGA 0x29 //#define RESP_DETECTA_CARGA 0x2a #define CMD_LER_CICLOS_CORTE 0x2b @@ -97,12 +97,10 @@ //void cmdGravarParamBluetooth(char * dados, unsigned char tamanhoDados); //void cmdExecCmdBtm(char* dados, unsigned char tamanhoDados); -void cmdTensaoInstantanea(int lineOrLoad); -void cmdMMTensao(int lineOrLoad, int block); -void cmdCorrenteInstantanea(); -void cmdMMCorrente(int block); - +void cmdGrandezaInstantanea(int channel); +void cmdMemoriaMassa(int channel, int block); void cmdLerAlarmes(int block); +void cmdLerTemperatura(int channel); void atualizaEstadoRele(unsigned char estado); unsigned char lerEstadoRele();
--- a/cmd/correnteInstantanea.cpp Tue Oct 20 21:53:16 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ -#include "appCommands.h" -#include "sensor.h" - -void cmdCorrenteInstantanea(){ - union{ - float current; - char bytes[4]; - } resp; - - resp.current = getInstCurrent(); - - exec.enviaResposta(RESP_CORRENTE_INSTANTANEA, resp.bytes, 4); -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cmd/grandezaInstantanea.cpp Tue Oct 27 21:54:09 2015 +0000 @@ -0,0 +1,28 @@ +#include "appCommands.h" +#include "sensor.h" + +void cmdGrandezaInstantanea(int channel){ + int ch; + union{ + float measure; + char bytes[4]; + } resp; + + switch(channel){ + case 0: // Tensao de Carga + ch = APP_PARAMETERS.LOAD_CHANNEL; + int lineChannel = APP_PARAMETERS.LOAD_CHANNEL == 0 ? 1 : 0; + float line = getInstVoltage(lineChannel); + resp.measure = line - getInstVoltage(ch); + break; + case 1: // Tensao de Linha + ch = APP_PARAMETERS.LOAD_CHANNEL == 0 ? 1 : 0; + resp.measure = getInstVoltage(ch); + break; + case 2: // Corrente + resp.measure = getInstCurrent(); + break; + } + + exec.enviaResposta(RESP_GRANDEZA_INSTANTANEA, resp.bytes, 4); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cmd/lerTemperatura.cpp Tue Oct 27 21:54:09 2015 +0000 @@ -0,0 +1,27 @@ +#include "appCommands.h" +#include "LM75B.h" + +extern LM75B temperature1; +extern LM75B temperature2; +extern LM75B temperature3; + +void cmdLerTemperatura(int channel){ + union{ + float measure; + char bytes[4]; + } resp; + + switch(channel){ + case 0: // Sensor 1 + resp.measure = temperature1; + break; + case 1: // Sensor 2 + resp.measure = temperature2; + break; + case 2: // Sensor 3 + resp.measure = temperature3; + break; + } + + exec.enviaResposta(RESP_TEMPERATURA, resp.bytes, 4); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cmd/mm.cpp Tue Oct 27 21:54:09 2015 +0000 @@ -0,0 +1,55 @@ +#include "appCommands.h" +#include "sensor.h" +#include "memoriaMassa.h" + +#define MM_FALHA 1 +#define MM_FIM 2 + +extern MemoriaMassa mm; +char* respMM[3]; + +void cmdMemoriaMassa(int channel, int block){ + int ch; + switch(channel){ + case 0: // Tensao de Carga + ch = APP_PARAMETERS.LOAD_CHANNEL; + break; + case 1: // Tensao de Linha + ch = APP_PARAMETERS.LOAD_CHANNEL == 0 ? 1 : 0; + break; + case 2: // Corrente + ch = 2; + break; + } + + if(block == 0){ + free(respMM[ch]); + respMM[ch] = mm.getMM(ch); + } + + if(respMM[ch] == NULL){ + exec.enviaResposta(RESP_MEMORIA_MASSA, MM_FALHA); + } else{ + int mmSize = APP_PARAMETERS.MM_SIZE; + if(mmSize < 0 || mmSize > 127){ + mmSize = 100; // Use default + } + int blocks = ceil(mmSize / 25.0); + if(blocks < 0 || blocks > 6){ + blocks = 4; // Use default of 100 entries + } + if(block >= blocks){ + exec.enviaResposta(RESP_MEMORIA_MASSA, MM_FIM); + free(respMM[ch]); + } else{ + int size = 8*25; + if(block == blocks-1){ + size = 8*(APP_PARAMETERS.MM_SIZE % 25); + if(size == 0){ + size = 8*25; + } + } + exec.enviaResposta(RESP_MEMORIA_MASSA, respMM[ch]+block*8*25, size); + } + } +}
--- a/cmd/mmCorrente.cpp Tue Oct 20 21:53:16 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,42 +0,0 @@ -#include "appCommands.h" -#include "sensor.h" -#include "memoriaMassa.h" - -#define MM_CORRENTE_FALHA 1 -#define MM_CORRENTE_FIM 2 - -extern MemoriaMassa mm; -char* respMMcurrent; - -void cmdMMCorrente(int block){ - if(block == 0){ - free(respMMcurrent); - respMMcurrent = mm.getMM(2); - } - - if(respMMcurrent == NULL){ - exec.enviaResposta(RESP_MM_CORRENTE, MM_CORRENTE_FALHA); - } else{ - int mmSize = APP_PARAMETERS.MM_SIZE; - if(mmSize < 0 || mmSize > 127){ - mmSize = 100; // Use default - } - int blocks = ceil(mmSize / 25.0); - if(blocks < 0 || blocks > 6){ - blocks = 4; // Use default of 100 entries - } - if(block >= blocks){ - exec.enviaResposta(RESP_MM_CORRENTE, MM_CORRENTE_FIM); - free(respMMcurrent); - } else{ - int size = 8*25; - if(block == blocks-1){ - size = 8*(APP_PARAMETERS.MM_SIZE % 25); - if(size == 0){ - size = 8*25; - } - } - exec.enviaResposta(RESP_MM_CORRENTE, respMMcurrent+block*8*25, size); - } - } -}
--- a/cmd/mmTensao.cpp Tue Oct 20 21:53:16 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -#include "appCommands.h" -#include "sensor.h" -#include "memoriaMassa.h" - -#define MM_TENSAO_FALHA 1 -#define MM_TENSAO_FIM 2 - -extern MemoriaMassa mm; -char* respMM[2]; - -void cmdMMTensao(int lineOrLoad, int block){ - int channel; - if(lineOrLoad == APP_PARAMETERS.LOAD_CHANNEL){ - channel = 0; - } else{ - channel = 1; - } - - if(block == 0){ - free(respMM[channel]); - respMM[channel] = mm.getMM(channel); - } - - if(respMM[channel] == NULL){ - exec.enviaResposta(RESP_MM_TENSAO, MM_TENSAO_FALHA); - } else{ - int mmSize = APP_PARAMETERS.MM_SIZE; - if(mmSize < 0 || mmSize > 127){ - mmSize = 100; // Use default - } - int blocks = ceil(mmSize / 25.0); - if(blocks < 0 || blocks > 6){ - blocks = 4; // Use default of 100 entries - } - if(block >= blocks){ - exec.enviaResposta(RESP_MM_TENSAO, MM_TENSAO_FIM); - free(respMM[channel]); - } else{ - int size = 8*25; - if(block == blocks-1){ - size = 8*(APP_PARAMETERS.MM_SIZE % 25); - if(size == 0){ - size = 8*25; - } - } - exec.enviaResposta(RESP_MM_TENSAO, respMM[channel]+block*8*25, size); - } - } -}
--- a/cmd/religar.cpp Tue Oct 20 21:53:16 2015 +0000 +++ b/cmd/religar.cpp Tue Oct 27 21:54:09 2015 +0000 @@ -35,7 +35,7 @@ char resp = RELIGAR_ESTADO_ILEGAL; switch(rele){ case ESTADO_RELE_INDEFINIDO: - if(getSensorState(APP_PARAMETERS.LOAD_CHANNEL) == SENSOR_COM_FORNECIMENTO){ + if(checkVoltageReturn(APP_PARAMETERS.LOAD_CHANNEL) == SENSOR_COM_FORNECIMENTO){ resp = RELIGAR_POSSIVEL_RETORNO_POTENCIAL; } else{ enviaPulso(); @@ -48,7 +48,7 @@ break; case ESTADO_RELE_ABERTO: - if(getSensorState(APP_PARAMETERS.LOAD_CHANNEL) == SENSOR_COM_FORNECIMENTO){ + if(checkVoltageReturn(APP_PARAMETERS.LOAD_CHANNEL) == SENSOR_COM_FORNECIMENTO){ resp = RELIGAR_RETORNO_POTENCIAL; alarm.writeAlarm(ALARME_RETORNO_POTENCIAL, true, false); } else{
--- a/cmd/tensaoInstantanea.cpp Tue Oct 20 21:53:16 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,26 +0,0 @@ -#include "appCommands.h" -#include "sensor.h" - -void cmdTensaoInstantanea(int lineOrLoad){ - int channel; - if(lineOrLoad == APP_PARAMETERS.LOAD_CHANNEL){ - channel = 0; - } else{ - channel = 1; - } - - union{ - float voltage; - char bytes[4]; - } resp; - - if(lineOrLoad == 0){ // Leitura da tensao da carga - int lineChannel = channel == 0 ? 1 : 0; - float line = getInstVoltage(lineChannel); - resp.voltage = line - getInstVoltage(channel); - } else{ - resp.voltage = getInstVoltage(channel); - } - - exec.enviaResposta(RESP_TENSAO_INSTANTANEA, resp.bytes, 4); -}
--- a/memoriaMassa.cpp Tue Oct 20 21:53:16 2015 +0000 +++ b/memoriaMassa.cpp Tue Oct 27 21:54:09 2015 +0000 @@ -71,7 +71,9 @@ carga = (int)ch2; } - if(carga > APP_PARAMETERS.LIMITE_TENSAO_SENSOR_V){ + if((linha - carga) > (linha*APP_PARAMETERS.LIMITE_TENSAO_SENSOR_V)/100.0){ + ledLoad = LED_ON; + } else if((linha - carga) < -(linha*APP_PARAMETERS.LIMITE_TENSAO_SENSOR_V)/100.0){ ledLoad = LED_ON; } else{ ledLoad = LED_OFF;
--- a/sensor.cpp Tue Oct 20 21:53:16 2015 +0000 +++ b/sensor.cpp Tue Oct 27 21:54:09 2015 +0000 @@ -64,15 +64,30 @@ float line = getInstVoltage(lineChannel); float load = getInstVoltage(channel); - if(load > (line + line*APP_PARAMETERS.LIMITE_TENSAO_SENSOR_V/100)){ + if((line - load) > (line*APP_PARAMETERS.LIMITE_TENSAO_SENSOR_V)/100.0){ ledLoad = LED_ON; return SENSOR_COM_FORNECIMENTO; + } else if((line - load) < -(line*APP_PARAMETERS.LIMITE_TENSAO_SENSOR_V)/100.0){ + ledLoad = LED_ON; + return SENSOR_SEM_FORNECIMENTO; } else{ ledLoad = LED_OFF; return SENSOR_SEM_FORNECIMENTO; } } +bool checkVoltageReturn(unsigned char channel){ + unsigned char lineChannel = channel == 1 ? 0 : 1; + float line = getInstVoltage(lineChannel); + float load = getInstVoltage(channel); + + if(load > (line + (line*APP_PARAMETERS.LIMITE_TENSAO_SENSOR_V)/100.0)){ + return SENSOR_COM_FORNECIMENTO; + } else{ + return SENSOR_SEM_FORNECIMENTO; + } +} + void readSample(){ sample[currentSample++] = voltage[currentChannel]; if(currentSample == DEFAULT_SAMPLES){
--- a/sensor.h Tue Oct 20 21:53:16 2015 +0000 +++ b/sensor.h Tue Oct 27 21:54:09 2015 +0000 @@ -9,6 +9,7 @@ float getInstVoltage(unsigned char channel); float getInstCurrent(); bool getSensorState(unsigned char channel); +bool checkVoltageReturn(unsigned char channel); void readSample(); void timeoutReadingSamples(); float calculateRMS(float angCoef, float linCoef);
--- a/settings.h Tue Oct 20 21:53:16 2015 +0000 +++ b/settings.h Tue Oct 27 21:54:09 2015 +0000 @@ -23,7 +23,7 @@ #define DEFAULT_DELAY_SENSOR_MS 500 #define DEFAULT_INTERVALO_SILENCIO_S 2 #define DEFAULT_INTERVALO_WD_NETWORK_S 0 // 0 desabilita o watchdog de rede -#define DEFAULT_LIMITE_TENSAO_SENSOR_V 10 +#define DEFAULT_LIMITE_TENSAO_SENSOR_V 20 #define DEFAULT_SAMPLES 500 #define DEFAULT_SAMPLES_DELAY_US 2000 #define DEFAULT_SAMPLES_VOLTAGE_ANG_COEF 2719.85f @@ -56,6 +56,6 @@ #define DEFAULT_LIMITE_CORRENTE_MAXIMA_A 100 #define DEFAULT_SAMPLES_CURRENT_ANG_COEF 265.0f #define DEFAULT_SAMPLES_CURRENT_LIN_COEF -132.394f // 265 * (-0.4996) -#define DEFAULT_ENABLE_LOAD_PROFILE 0 +#define DEFAULT_ENABLE_LOAD_PROFILE 1 #endif
--- a/v2hardware.h Tue Oct 20 21:53:16 2015 +0000 +++ b/v2hardware.h Tue Oct 27 21:54:09 2015 +0000 @@ -3,6 +3,7 @@ #include "mbed.h" #include "settings.h" +#include "LM75B.h" #ifdef TEST_MODE DigitalOut ledPowerON(LED1); @@ -17,6 +18,9 @@ Serial ggsStream(PTE22, PTE23); Serial meter(D14, D15); AnalogIn voltage[] = {PTE20, PTE29, PTE20}; + LM75B temperature1(PTB3, PTB2, LM75B::ADDRESS_0); + LM75B temperature2(PTB3, PTB2, LM75B::ADDRESS_1); + LM75B temperature3(PTB3, PTB2, LM75B::ADDRESS_2); #else DigitalOut ledPowerON(PTB0); DigitalOut ledNetwork(PTA2); @@ -30,6 +34,9 @@ Serial ggsStream(PTD3, PTD2); Serial meter(NC, PTE21); AnalogIn voltage[] = {PTE20, PTE29, PTB1}; + LM75B temperature1(PTB3, PTB2, LM75B::ADDRESS_0); + LM75B temperature2(PTB3, PTB2, LM75B::ADDRESS_1); + LM75B temperature3(PTB3, PTB2, LM75B::ADDRESS_2); #endif // TEST_MODE #endif // V2_HARDWARE_H
--- a/version.h Tue Oct 20 21:53:16 2015 +0000 +++ b/version.h Tue Oct 27 21:54:09 2015 +0000 @@ -4,9 +4,9 @@ #include "settings.h" #ifdef TEST_MODE - static const char version[] = "SmartBreakerKW v0.11 TST"; + static const char version[] = "SmartBreakerKW v0.12 TST"; #else - static const char version[] = "SmartBreakerKW v0.11"; + static const char version[] = "SmartBreakerKW v0.12"; #endif #endif