teste de publish

Revision:
3:75223647cf3d
Parent:
2:ca3723da6668
Child:
4:3f92979d1ffb
--- a/devices.cpp	Wed May 10 12:56:46 2017 +0000
+++ b/devices.cpp	Fri Jun 02 13:22:07 2017 +0000
@@ -175,7 +175,17 @@
                             &leitura_float
                         );
                     }else{
-                        leitura_float = temperaturas[this->alarms[alarmIndex].regModbusRead];
+                        //leitura_float = temperaturas[this->alarms[alarmIndex].regModbusRead];
+                        //Busca Interna                        
+                        if(this->alarms[alarmIndex].regModbusRead<100){//Registradores das entradas de temperatura
+                            //Populando floatBuffer com a temperaturas
+                            if(this->alarms[alarmIndex].regModbusRead < num_temperatureSensors){
+                                leitura_float = temperaturas[this->alarms[alarmIndex].regModbusRead];
+                            }    
+                        }
+                        if((this->alarms[alarmIndex].regModbusRead>100)&&(this->alarms[alarmIndex].regModbusRead<104)){//Registradores das entradas analógicas
+                            leitura_float = aiFiltrada[this->alarms[alarmIndex].regModbusRead - 100];                            
+                        }
                      }
             
                     if(this->alarms[alarmIndex].max!=0){
@@ -226,14 +236,18 @@
                     //Montar uint32_t!
                     this->uint32_t_ToBin(0,&value_uint32_t,&this->alarms[alarmIndex].value[0]);                    
                     
-                    //Bloco de leitura da variável modBus;
-                    modBusMaster1::readRegister32BIT(
-                        this->alarms[alarmIndex].addrModbusRead,
-                        this->alarms[alarmIndex].funcModbusRead,
-                        this->alarms[alarmIndex].regModbusRead,
-                        1,
-                        &leitura_uint32_t
-                    );                                       
+                    if(this->alarms[alarmIndex].addrModbusRead != enderecoControladoraVirtual){//Bloco de leitura da variável modBus;
+                        //Bloco de leitura da variável modBus;
+                        modBusMaster1::readRegister32BIT(
+                            this->alarms[alarmIndex].addrModbusRead,
+                            this->alarms[alarmIndex].funcModbusRead,
+                            this->alarms[alarmIndex].regModbusRead,
+                            1,
+                            &leitura_uint32_t
+                        );
+                    }else{
+                        leitura_uint32_t = pulsosEDs[this->alarms[alarmIndex].regModbusRead];
+                     }                                       
             
                     if(this->alarms[alarmIndex].max!=0){
                         if(leitura_uint32_t > value_uint32_t){
@@ -241,6 +255,7 @@
                             if(this->alarms[alarmIndex].secAlarm >= this->alarms[alarmIndex].seconds){
                                 this->alarms[alarmIndex].secAlarm = this->alarms[alarmIndex].seconds;
                                 alarmFound = true;
+                                pulsosEDs[this->alarms[alarmIndex].regModbusRead]=0;
                             }
                         }else{
                             if(this->alarms[alarmIndex].secAlarm==1){
@@ -262,6 +277,7 @@
                             if(this->alarms[alarmIndex].secAlarm >= this->alarms[alarmIndex].seconds){
                                 this->alarms[alarmIndex].secAlarm = this->alarms[alarmIndex].seconds;
                                 alarmFound = true;
+                                pulsosEDs[this->alarms[alarmIndex].regModbusRead]=0;
                             }
                         }else{
                             if(this->alarms[alarmIndex].secAlarm==1){
@@ -1221,10 +1237,15 @@
                     }else{
                         //Busca Interna
                         floatBuffer = (float*) malloc(sizeof(float));
-                        //Populando floatBuffer com a entrada analógica
-                        if(this->readings[readingIndex].reg < num_temperatureSensors){
-                            floatBuffer[0] = temperaturas[this->readings[readingIndex].reg];
+                        if((this->readings[readingIndex].reg<100)&&(this->readings[readingIndex].reg < num_temperatureSensors)){//Registradores das entradas de temperatura
+                            //Populando floatBuffer com a temperaturas                            
+                            floatBuffer[0] = temperaturas[this->readings[readingIndex].reg];                            
                         }
+                        if((this->readings[readingIndex].reg>100)&&(this->readings[readingIndex].reg<104)){
+                            //Registradores das entradas analógicas                            
+                            floatBuffer[0] = aiFiltrada[this->readings[readingIndex].reg - 100];                            
+                        }
+                        this->readings[readingIndex].numRegs = 1;
                      }
                     
                     //pc.printf("Lido dentro de modBusMaster1::teste() <%f>.\n",modBusMaster1::teste());
@@ -1233,14 +1254,20 @@
                 break;
             case modBusType_uint32_t:
                     uint32_tBuffer = (uint32_t*) malloc((this->readings[readingIndex].numRegs*sizeof(uint32_t))+1); //Alocando mais um byte para status
-                    modBusMaster1::readRegister32BIT(//Ponho o status no ultimo byte
-                        this->readings[readingIndex].addr,
-                        this->readings[readingIndex].func,
-                        this->readings[readingIndex].reg,
-                        this->readings[readingIndex].numRegs,
-                        uint32_tBuffer
-                    );
-                    //pc.printf("Lido dentro de modBusMaster1::teste() <%f>.\n",modBusMaster1::teste());
+                    if(this->readings[readingIndex].addr != enderecoControladoraVirtual){
+                        modBusMaster1::readRegister32BIT(//Ponho o status no ultimo byte
+                            this->readings[readingIndex].addr,
+                            this->readings[readingIndex].func,
+                            this->readings[readingIndex].reg,
+                            this->readings[readingIndex].numRegs,
+                            uint32_tBuffer
+                        );
+                        //pc.printf("Lido dentro de modBusMaster1::teste() <%f>.\n",modBusMaster1::teste());
+                    }else{
+                        uint32_tBuffer[0] = pulsosEDs[this->readings[readingIndex].reg];
+                        this->readings[readingIndex].numRegs = 1;
+                        pulsosEDs[this->readings[readingIndex].reg] = 0;
+                     }
                     sdCardBuf.fill((char *)uint32_tBuffer,((sizeof(uint32_t)*this->readings[readingIndex].numRegs)+1));//Ao fim appendo o byte de status
                     free(uint32_tBuffer);            
                 break;