teste de publish
Diff: devices.cpp
- Revision:
- 17:c046e4b07ded
- Parent:
- 16:1b43a57ee676
- Child:
- 18:66fa6fcba212
--- a/devices.cpp Mon Apr 16 12:30:09 2018 +0000 +++ b/devices.cpp Tue May 01 03:27:47 2018 +0000 @@ -362,6 +362,135 @@ } break; + case modBusType_int32_t: + //Montar uint32_t! + this->uint32_t_ToBin(0,&value_uint32_t,&this->alarms[alarmIndex].value[0]); + + 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(((int32_t)leitura_uint32_t) > ((int32_t)value_uint32_t)){ + this->alarms[alarmIndex].secAlarm++; + 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){ + this->alarms[alarmIndex].secAlarm=0; + alarmFound = false; + }else{ + if(this->alarms[alarmIndex].secAlarm){ + if(alarmFound){ + this->alarms[alarmIndex].secAlarm--; + }else{ + this->alarms[alarmIndex].secAlarm=0; + } + } + } + } + }else{ + if(((int32_t)leitura_uint32_t) < ((int32_t)value_uint32_t)){ + this->alarms[alarmIndex].secAlarm++; + 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){ + this->alarms[alarmIndex].secAlarm=0; + alarmFound = false; + }else{ + if(this->alarms[alarmIndex].secAlarm){ + if(alarmFound){ + this->alarms[alarmIndex].secAlarm--; + }else{ + this->alarms[alarmIndex].secAlarm=0; + } + } + } + } + } + break; + + case modBusType_int16_t: + //Montar uint16_t! + this->uint16_t_ToBin(0,&value_uint16_t,&this->alarms[alarmIndex].value[0]); + + if(this->alarms[alarmIndex].addrModbusRead!=enderecoControladoraVirtual){ + //Bloco de leitura da variável modBus; + modBusMaster1::readRegister16BIT( + this->alarms[alarmIndex].addrModbusRead, + this->alarms[alarmIndex].funcModbusRead, + this->alarms[alarmIndex].regModbusRead, + 1, + &leitura_uint16_t + ); + }else{ + if(this->alarms[alarmIndex].regModbusRead<4){ + leitura_uint16_t = aiFiltrada[this->alarms[alarmIndex].regModbusRead]; + } + } + + if(this->alarms[alarmIndex].max!=0){ + if(((int16_t)leitura_uint16_t) > ((int16_t)value_uint16_t)){ + this->alarms[alarmIndex].secAlarm++; + if(this->alarms[alarmIndex].secAlarm >= this->alarms[alarmIndex].seconds){ + this->alarms[alarmIndex].secAlarm = this->alarms[alarmIndex].seconds; + alarmFound = true; + } + }else{ + if(this->alarms[alarmIndex].secAlarm==1){ + this->alarms[alarmIndex].secAlarm=0; + alarmFound = false; + }else{ + if(this->alarms[alarmIndex].secAlarm){ + if(alarmFound){ + this->alarms[alarmIndex].secAlarm--; + }else{ + this->alarms[alarmIndex].secAlarm=0; + } + } + } + } + }else{ + if(((int16_t)leitura_uint16_t) < ((int16_t)value_uint16_t)){ + this->alarms[alarmIndex].secAlarm++; + if(this->alarms[alarmIndex].secAlarm >= this->alarms[alarmIndex].seconds){ + this->alarms[alarmIndex].secAlarm = this->alarms[alarmIndex].seconds; + alarmFound = true; + } + }else{ + if(this->alarms[alarmIndex].secAlarm==1){ + this->alarms[alarmIndex].secAlarm=0; + alarmFound = false; + }else{ + if(this->alarms[alarmIndex].secAlarm){ + if(alarmFound){ + this->alarms[alarmIndex].secAlarm--; + }else{ + this->alarms[alarmIndex].secAlarm=0; + } + } + } + } + } + break; + + case modBusType_bit: //Montar bit! //O valor de alarm para bit é o value[0]!!! @@ -422,6 +551,10 @@ sprintf(aux,"%lu",leitura_uint32_t); }else if(this->alarms[alarmIndex].type == modBusType_uint16_t){ sprintf(aux,"%lu",leitura_uint16_t); + }else if(this->alarms[alarmIndex].type == modBusType_int32_t){ + sprintf(aux,"%l",leitura_uint32_t); + }else if(this->alarms[alarmIndex].type == modBusType_int16_t){ + sprintf(aux,"%l",leitura_uint16_t); }else if(this->alarms[alarmIndex].type == modBusType_bit){ sprintf(aux,"%lu",leitura_bit); } @@ -747,6 +880,16 @@ inputData = true; } + if(strstr(linha,"int32_t,")) { + this->readings[this->numReadings-1].type=modBusType_int32_t; + inputData = true; + } + + if(strstr(linha,"int16_t,")) { + this->readings[this->numReadings-1].type=modBusType_int16_t; + inputData = true; + } + if(strstr(linha,"uint8_t,")) { this->readings[this->numReadings-1].type=modBusType_uint8_t; inputData = true; @@ -931,6 +1074,63 @@ this->uint16_t_ToBin(1,&aux16_t,&this->alarms[this->numAlarms-1].value[0]); } + + if(strstr(linha,"int32_t,")) { + this->alarms[this->numAlarms-1].type=modBusType_int32_t; + //sscanf(linha,"max:uint32_t,%lu,%lu,%lu,%lu",&aux1,&aux2,&aux3,&aux4); + strtok(linha,","); + + //parametro1 + pChar = strtok(NULL,","); + this->alarms[this->numAlarms-1].addrModbusRead = atoi(pChar); + + //parametro2 + pChar = strtok(NULL,","); + this->alarms[this->numAlarms-1].funcModbusRead = atoi(pChar); + + //parametro3 + pChar = strtok(NULL,","); + this->alarms[this->numAlarms-1].regModbusRead = atol(pChar); + + //Parametro 4; + pChar = strtok(NULL,","); + this->alarms[this->numAlarms-1].max = (atoi(pChar) != 0); //Qualquer valor diferente de 0 é um + + //parametro5 + pChar = strtok(NULL,"\r\n"); + aux32_t = atol(pChar); + + this->uint32_t_ToBin(1,&aux32_t,&this->alarms[this->numAlarms-1].value[0]); + } + + + + if(strstr(linha,"int16_t,")) { + this->alarms[this->numAlarms-1].type=modBusType_uint16_t; + strtok(linha,","); + + //parametro1 + pChar = strtok(NULL,","); + this->alarms[this->numAlarms-1].addrModbusRead = atoi(pChar); + + //parametro2 + pChar = strtok(NULL,","); + this->alarms[this->numAlarms-1].funcModbusRead = atoi(pChar); + + //parametro3 + pChar = strtok(NULL,","); + this->alarms[this->numAlarms-1].regModbusRead = atoi(pChar); + + //Parametro 4; + pChar = strtok(NULL,","); + this->alarms[this->numAlarms-1].max = (atoi(pChar) != 0); //Qualquer valor diferente de 0 é um + + //parametro5 + pChar = strtok(NULL,"\r\n"); + aux16_t = atoi(pChar); + + this->uint16_t_ToBin(1,&aux16_t,&this->alarms[this->numAlarms-1].value[0]); + } } void device::setSchedule(char *linha) @@ -1144,6 +1344,8 @@ if(strstr(pTipoComando,"uint8_t")){tipoComando = modBusType_uint8_t;} if(strstr(pTipoComando,"uint16_t")){tipoComando = modBusType_uint16_t;} if(strstr(pTipoComando,"uint32_t")){tipoComando = modBusType_uint32_t;} + if(strstr(pTipoComando,"int16_t")){tipoComando = modBusType_int16_t;} + if(strstr(pTipoComando,"int32_t")){tipoComando = modBusType_int32_t;} if(strstr(pTipoComando,"IR")){tipoComando = IrCommandType;} if(strstr(pTipoComando,"PWM")){tipoComando = PWMCommandType;} }else{ @@ -1168,11 +1370,12 @@ &floatValueToWrite )){commandExecOk = false;} break; - case modBusType_uint32_t: + case modBusType_uint32_t: + case modBusType_int32_t: param1 = atoi(strtok(NULL,",")); param2 = atoi(strtok(NULL,",")); param3 = atoi(strtok(NULL,",")); - param4 = atoi(strtok(NULL,",")); + param4 = atol(strtok(NULL,",")); if(modBusMaster1::writeRegister32BIT( param1, @@ -1182,6 +1385,7 @@ )){commandExecOk = false;} break; case modBusType_uint16_t: + case modBusType_int16_t: uint16_t param4_uint16_t; param1 = atoi(strtok(NULL,",")); param2 = atoi(strtok(NULL,",")); @@ -1430,7 +1634,8 @@ sdCardBuf.fill((char *)floatBuffer,((sizeof(float)*this->readings[readingIndex].numRegs)+1));//Ao fim appendo o byte de status free(floatBuffer); break; - case modBusType_uint32_t: + case modBusType_uint32_t: + case modBusType_int32_t: if(this->readings[readingIndex].addr != enderecoControladoraVirtual){ uint32_tBuffer = (uint32_t*) malloc((this->readings[readingIndex].numRegs*sizeof(uint32_t))+1); //Alocando mais um byte para status ((char *)uint32_tBuffer)[(this->readings[readingIndex].numRegs*sizeof(uint32_t))] = modBusMaster1::readRegister32BIT(//Ponho o status no ultimo byte @@ -1451,7 +1656,8 @@ free(uint32_tBuffer); break; - case modBusType_uint16_t: + case modBusType_uint16_t: + case modBusType_int16_t: if(this->readings[readingIndex].addr!=enderecoControladoraVirtual){ uint16_tBuffer = (uint16_t*) malloc(((this->readings[readingIndex].numRegs*sizeof(uint16_t))+1));//Alocando mais um byte para status ((char *)uint16_tBuffer)[(this->readings[readingIndex].numRegs*sizeof(uint16_t))] = modBusMaster1::readRegister16BIT(// @@ -1714,6 +1920,24 @@ else{printf("\tuint16_t min <%lu>.\n",value);} } + if(dispositivos[i]->alarms[j].type==modBusType_int32_t) { + uint32_t value; + dispositivos[i]->uint32_t_ToBin(0,&value,&dispositivos[i]->alarms[j].value[0]); + if(dispositivos[i]->alarms[j].max){ + printf("\tint32_t max <%l>.\n",value); + } + else{printf("\tint32_t min <%l>.\n",value);} + } + + if(dispositivos[i]->alarms[j].type==modBusType_int16_t) { + uint16_t value; + dispositivos[i]->uint16_t_ToBin(0,&value,&dispositivos[i]->alarms[j].value[0]); + if(dispositivos[i]->alarms[j].max){ + printf("\tuint16_t max <%l>.\n",value); + } + else{printf("\tuint16_t min <%l>.\n",value);} + } + if(dispositivos[i]->alarms[j].type==modBusType_bit) { uint8_t value; value=dispositivos[i]->alarms[j].value[0]; @@ -1755,6 +1979,12 @@ case modBusType_uint16_t: printf("Tipo uint16_t "); break; + case modBusType_int32_t: + printf("Tipo int32_t "); + break; + case modBusType_int16_t: + printf("Tipo int16_t "); + break; case modBusType_uint8_t: printf("Tipo uint8_t "); break;