teste de publish
devices.cpp@23:d3ef6bb8412a, 2018-06-07 (annotated)
- Committer:
- brunofgc
- Date:
- Thu Jun 07 16:18:50 2018 +0000
- Revision:
- 23:d3ef6bb8412a
- Parent:
- 22:e0d8c8fe26c6
- Child:
- 24:4d44626e5b78
Devices com Release "mole" ainda precisa igualar o release ao Found. Zerando os segundos de histerese ao inv?s de decrescer eles.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
brunofgc | 0:8c59a494a451 | 1 | #include "devices.h" |
brunofgc | 0:8c59a494a451 | 2 | |
brunofgc | 0:8c59a494a451 | 3 | enum { |
brunofgc | 0:8c59a494a451 | 4 | estadoConfiguracao_idle = 0, |
brunofgc | 0:8c59a494a451 | 5 | estadoConfiguracao_creatingDevice, |
brunofgc | 0:8c59a494a451 | 6 | estadoConfiguracao_alarmSet, |
brunofgc | 0:8c59a494a451 | 7 | estadoConfiguracao_readingsSet, |
brunofgc | 4:3f92979d1ffb | 8 | estadoConfiguracao_scheduleSet, |
brunofgc | 4:3f92979d1ffb | 9 | estadoConfiguracao_scheduleExceptionSet |
brunofgc | 0:8c59a494a451 | 10 | }; |
brunofgc | 0:8c59a494a451 | 11 | |
brunofgc | 19:d52176ff683d | 12 | uint8_t numAlarms; |
brunofgc | 19:d52176ff683d | 13 | uint8_t numSchedules; |
brunofgc | 19:d52176ff683d | 14 | uint8_t numScheduleExceptions; |
brunofgc | 19:d52176ff683d | 15 | uint16_t numReadings; |
brunofgc | 19:d52176ff683d | 16 | alarm alarms[maxAlarms] __attribute__ ((section("AHBSRAM0"))); |
brunofgc | 19:d52176ff683d | 17 | reading readings[maxReadings] __attribute__ ((section("AHBSRAM0"))); |
brunofgc | 19:d52176ff683d | 18 | schedule schedules[maxSchedules] __attribute__ ((section("AHBSRAM0"))); |
brunofgc | 19:d52176ff683d | 19 | scheduleException scheduleExceptions[maxSchedulesExceptions] __attribute__ ((section("AHBSRAM0"))); |
brunofgc | 1:3f9e5b86d9e4 | 20 | |
brunofgc | 19:d52176ff683d | 21 | void floatToBin(uint8_t dir, float *v,uint8_t *p) |
brunofgc | 0:8c59a494a451 | 22 | { |
brunofgc | 0:8c59a494a451 | 23 | //Variáveis locais |
brunofgc | 0:8c59a494a451 | 24 | union { |
brunofgc | 0:8c59a494a451 | 25 | char c[4]; |
brunofgc | 0:8c59a494a451 | 26 | float v; |
brunofgc | 0:8c59a494a451 | 27 | }u; |
brunofgc | 0:8c59a494a451 | 28 | int i; |
brunofgc | 0:8c59a494a451 | 29 | |
brunofgc | 0:8c59a494a451 | 30 | if(dir) { |
brunofgc | 0:8c59a494a451 | 31 | u.v = *v; |
brunofgc | 0:8c59a494a451 | 32 | for(i=0; i<4; i++) { |
brunofgc | 0:8c59a494a451 | 33 | p[i]=u.c[3-i]; |
brunofgc | 0:8c59a494a451 | 34 | } |
brunofgc | 0:8c59a494a451 | 35 | } else { |
brunofgc | 0:8c59a494a451 | 36 | for(i=0; i<4; i++) { |
brunofgc | 0:8c59a494a451 | 37 | u.c[3-i]=p[i]; |
brunofgc | 0:8c59a494a451 | 38 | } |
brunofgc | 0:8c59a494a451 | 39 | *v = u.v; |
brunofgc | 0:8c59a494a451 | 40 | } |
brunofgc | 0:8c59a494a451 | 41 | } |
brunofgc | 0:8c59a494a451 | 42 | |
brunofgc | 19:d52176ff683d | 43 | void uint32_t_ToBin(uint8_t dir, uint32_t *v,uint8_t *p) |
brunofgc | 0:8c59a494a451 | 44 | { |
brunofgc | 0:8c59a494a451 | 45 | //Variáveis locais |
brunofgc | 0:8c59a494a451 | 46 | union { |
brunofgc | 0:8c59a494a451 | 47 | char c[4]; |
brunofgc | 0:8c59a494a451 | 48 | uint32_t v; |
brunofgc | 0:8c59a494a451 | 49 | }u; |
brunofgc | 0:8c59a494a451 | 50 | int i; |
brunofgc | 0:8c59a494a451 | 51 | |
brunofgc | 0:8c59a494a451 | 52 | if(dir) { |
brunofgc | 0:8c59a494a451 | 53 | u.v = *v; |
brunofgc | 0:8c59a494a451 | 54 | for(i=0; i<4; i++) { |
brunofgc | 0:8c59a494a451 | 55 | p[i]=u.c[3-i]; |
brunofgc | 0:8c59a494a451 | 56 | } |
brunofgc | 0:8c59a494a451 | 57 | } else { |
brunofgc | 0:8c59a494a451 | 58 | for(i=0; i<4; i++) { |
brunofgc | 0:8c59a494a451 | 59 | u.c[3-i]=p[i]; |
brunofgc | 0:8c59a494a451 | 60 | } |
brunofgc | 0:8c59a494a451 | 61 | *v = u.v; |
brunofgc | 0:8c59a494a451 | 62 | } |
brunofgc | 0:8c59a494a451 | 63 | } |
brunofgc | 0:8c59a494a451 | 64 | |
brunofgc | 19:d52176ff683d | 65 | void uint16_t_ToBin(uint8_t dir, uint16_t *v,uint8_t *p) |
brunofgc | 0:8c59a494a451 | 66 | { |
brunofgc | 0:8c59a494a451 | 67 | //Variáveis locais |
brunofgc | 0:8c59a494a451 | 68 | union { |
brunofgc | 0:8c59a494a451 | 69 | char c[2]; |
brunofgc | 0:8c59a494a451 | 70 | uint32_t v; |
brunofgc | 0:8c59a494a451 | 71 | }u; |
brunofgc | 0:8c59a494a451 | 72 | int i; |
brunofgc | 0:8c59a494a451 | 73 | |
brunofgc | 0:8c59a494a451 | 74 | if(dir) { |
brunofgc | 0:8c59a494a451 | 75 | u.v = *v; |
brunofgc | 0:8c59a494a451 | 76 | for(i=0; i<2; i++) { |
brunofgc | 0:8c59a494a451 | 77 | p[i]=u.c[1-i]; |
brunofgc | 0:8c59a494a451 | 78 | } |
brunofgc | 0:8c59a494a451 | 79 | } else { |
brunofgc | 0:8c59a494a451 | 80 | for(i=0; i<2; i++) { |
brunofgc | 0:8c59a494a451 | 81 | u.c[1-i]=p[i]; |
brunofgc | 0:8c59a494a451 | 82 | } |
brunofgc | 0:8c59a494a451 | 83 | *v = u.v; |
brunofgc | 0:8c59a494a451 | 84 | } |
brunofgc | 0:8c59a494a451 | 85 | } |
brunofgc | 0:8c59a494a451 | 86 | |
brunofgc | 19:d52176ff683d | 87 | void mostraAlarmeEmExecucao(uint32_t indice){ |
brunofgc | 19:d52176ff683d | 88 | printf("Alarme %u:\n",indice); |
brunofgc | 19:d52176ff683d | 89 | printf("\tId <%lu>.\n",alarms[indice].id); |
brunofgc | 19:d52176ff683d | 90 | printf("\tSeconds <%lu>.\n",alarms[indice].seconds); |
brunofgc | 19:d52176ff683d | 91 | printf("\tAddr %u, func %u, reg %lu.\n",alarms[indice].addrModbusRead,alarms[indice].funcModbusRead,alarms[indice].regModbusRead); |
brunofgc | 19:d52176ff683d | 92 | if(alarms[indice].type==modBusType_float) { |
brunofgc | 19:d52176ff683d | 93 | float value; |
brunofgc | 19:d52176ff683d | 94 | floatToBin(0,&value,&alarms[indice].value[0]); |
brunofgc | 19:d52176ff683d | 95 | if(alarms[indice].max){ |
brunofgc | 23:d3ef6bb8412a | 96 | //printf("\tFloat max <%f>.\n",value); |
brunofgc | 19:d52176ff683d | 97 | } |
brunofgc | 23:d3ef6bb8412a | 98 | // else{printf("\tFloat min <%f>.\n",value);} |
brunofgc | 19:d52176ff683d | 99 | } |
brunofgc | 19:d52176ff683d | 100 | |
brunofgc | 19:d52176ff683d | 101 | if(alarms[indice].type==modBusType_uint32_t) { |
brunofgc | 19:d52176ff683d | 102 | uint32_t value; |
brunofgc | 19:d52176ff683d | 103 | uint32_t_ToBin(0,&value,&alarms[indice].value[0]); |
brunofgc | 19:d52176ff683d | 104 | if(alarms[indice].max){ |
brunofgc | 19:d52176ff683d | 105 | printf("\tuint32_t max <%lu>.\n",value); |
brunofgc | 19:d52176ff683d | 106 | } |
brunofgc | 19:d52176ff683d | 107 | else{printf("\tuint32_t min <%lu>.\n",value);} |
brunofgc | 19:d52176ff683d | 108 | } |
brunofgc | 19:d52176ff683d | 109 | |
brunofgc | 19:d52176ff683d | 110 | if(alarms[indice].type==modBusType_uint16_t) { |
brunofgc | 19:d52176ff683d | 111 | uint16_t value; |
brunofgc | 19:d52176ff683d | 112 | uint16_t_ToBin(0,&value,&alarms[indice].value[0]); |
brunofgc | 19:d52176ff683d | 113 | if(alarms[indice].max){ |
brunofgc | 19:d52176ff683d | 114 | printf("\tuint16_t max <%lu>.\n",value); |
brunofgc | 19:d52176ff683d | 115 | } |
brunofgc | 19:d52176ff683d | 116 | else{printf("\tuint16_t min <%lu>.\n",value);} |
brunofgc | 19:d52176ff683d | 117 | } |
brunofgc | 19:d52176ff683d | 118 | |
brunofgc | 19:d52176ff683d | 119 | if(alarms[indice].type==modBusType_int32_t) { |
brunofgc | 19:d52176ff683d | 120 | uint32_t value; |
brunofgc | 19:d52176ff683d | 121 | uint32_t_ToBin(0,&value,&alarms[indice].value[0]); |
brunofgc | 19:d52176ff683d | 122 | if(alarms[indice].max){ |
brunofgc | 19:d52176ff683d | 123 | printf("\tint32_t max <%ld>.\n",(int32_t)value); |
brunofgc | 19:d52176ff683d | 124 | } |
brunofgc | 19:d52176ff683d | 125 | else{printf("\tint32_t min <%ld>.\n",(int32_t)value);} |
brunofgc | 19:d52176ff683d | 126 | } |
brunofgc | 19:d52176ff683d | 127 | |
brunofgc | 19:d52176ff683d | 128 | if(alarms[indice].type==modBusType_int16_t) { |
brunofgc | 19:d52176ff683d | 129 | uint16_t value; |
brunofgc | 19:d52176ff683d | 130 | uint16_t_ToBin(0,&value,&alarms[indice].value[0]); |
brunofgc | 19:d52176ff683d | 131 | if(alarms[indice].max){ |
brunofgc | 19:d52176ff683d | 132 | printf("\tint16_t max <%ld>.\n",(int16_t)value); |
brunofgc | 19:d52176ff683d | 133 | } |
brunofgc | 19:d52176ff683d | 134 | else{printf("\tint16_t min <%ld>.\n",(int16_t)value);} |
brunofgc | 19:d52176ff683d | 135 | } |
brunofgc | 19:d52176ff683d | 136 | |
brunofgc | 19:d52176ff683d | 137 | if(alarms[indice].type==modBusType_bit) { |
brunofgc | 19:d52176ff683d | 138 | uint8_t value; |
brunofgc | 19:d52176ff683d | 139 | value=alarms[indice].value[0]; |
brunofgc | 19:d52176ff683d | 140 | if(alarms[indice].max){ |
brunofgc | 19:d52176ff683d | 141 | printf("\tBIT max <%lu>.\n",value); |
brunofgc | 19:d52176ff683d | 142 | } |
brunofgc | 19:d52176ff683d | 143 | else{printf("\tBIT min <%lu>.\n",value);} |
brunofgc | 19:d52176ff683d | 144 | } |
brunofgc | 19:d52176ff683d | 145 | |
brunofgc | 19:d52176ff683d | 146 | printf("\tact:%lu\n",alarms[indice].idAct); |
brunofgc | 19:d52176ff683d | 147 | } |
brunofgc | 19:d52176ff683d | 148 | |
brunofgc | 1:3f9e5b86d9e4 | 149 | //Funcao restaurada |
brunofgc | 19:d52176ff683d | 150 | void verifyAlarms(){ |
brunofgc | 0:8c59a494a451 | 151 | //Inicio da verificação |
brunofgc | 0:8c59a494a451 | 152 | uint16_t alarmIndex; |
brunofgc | 0:8c59a494a451 | 153 | float leitura_float,value_float; |
brunofgc | 0:8c59a494a451 | 154 | uint32_t leitura_uint32_t,value_uint32_t; |
brunofgc | 0:8c59a494a451 | 155 | uint16_t leitura_uint16_t,value_uint16_t; |
brunofgc | 0:8c59a494a451 | 156 | bool leitura_bit,value_bit; |
brunofgc | 0:8c59a494a451 | 157 | bool alarmFound; |
brunofgc | 0:8c59a494a451 | 158 | char aux[30]; |
brunofgc | 5:8efd609dea7d | 159 | |
brunofgc | 19:d52176ff683d | 160 | //for(alarmIndex = 0;alarmIndex < alarmes;alarmIndex++){ |
brunofgc | 19:d52176ff683d | 161 | for(alarmIndex = 0;alarmIndex < alarmes;alarmIndex++){ |
brunofgc | 22:e0d8c8fe26c6 | 162 | diversos::wdt.kick(180.0); |
brunofgc | 19:d52176ff683d | 163 | /*pc.printf("\r\nTeste Alarm, id<%lu>.\r\n",alarms[alarmIndex].id); |
brunofgc | 19:d52176ff683d | 164 | pc.printf("ON<%lu>.\r\n",alarms[alarmIndex].on); |
brunofgc | 19:d52176ff683d | 165 | pc.printf("secAlarm<%lu>.\r\n",alarms[alarmIndex].secAlarm); |
brunofgc | 19:d52176ff683d | 166 | pc.printf("alarmFound<%lu>.\r\n",alarms[alarmIndex].alarmFound);*/ |
brunofgc | 19:d52176ff683d | 167 | //if((alarms[alarmIndex].on)&&(alarms[alarmIndex].id<100000000)){ |
brunofgc | 19:d52176ff683d | 168 | if(alarms[alarmIndex].on){ |
brunofgc | 19:d52176ff683d | 169 | if(debug){mostraAlarmeEmExecucao(alarmIndex);} |
brunofgc | 19:d52176ff683d | 170 | alarmFound=alarms[alarmIndex].alarmFound; |
brunofgc | 19:d52176ff683d | 171 | switch(alarms[alarmIndex].type){ |
brunofgc | 5:8efd609dea7d | 172 | case modBusType_float: |
brunofgc | 5:8efd609dea7d | 173 | //Montar float! |
brunofgc | 19:d52176ff683d | 174 | floatToBin(0,&value_float,&alarms[alarmIndex].value[0]); |
brunofgc | 5:8efd609dea7d | 175 | |
brunofgc | 19:d52176ff683d | 176 | if(alarms[alarmIndex].addrModbusRead != enderecoControladoraVirtual){//Bloco de leitura da variável modBus; |
brunofgc | 5:8efd609dea7d | 177 | modBusMaster1::readFloat( |
brunofgc | 19:d52176ff683d | 178 | alarms[alarmIndex].addrModbusRead, |
brunofgc | 19:d52176ff683d | 179 | alarms[alarmIndex].funcModbusRead, |
brunofgc | 19:d52176ff683d | 180 | alarms[alarmIndex].regModbusRead, |
brunofgc | 5:8efd609dea7d | 181 | 1, |
brunofgc | 5:8efd609dea7d | 182 | &leitura_float |
brunofgc | 5:8efd609dea7d | 183 | ); |
brunofgc | 5:8efd609dea7d | 184 | }else{ |
brunofgc | 19:d52176ff683d | 185 | //leitura_float = temperaturas[alarms[alarmIndex].regModbusRead]; |
brunofgc | 5:8efd609dea7d | 186 | //Busca Interna |
brunofgc | 19:d52176ff683d | 187 | if(alarms[alarmIndex].regModbusRead<100){//Registradores das entradas de temperatura |
brunofgc | 5:8efd609dea7d | 188 | //Populando floatBuffer com a temperaturas |
brunofgc | 19:d52176ff683d | 189 | if(alarms[alarmIndex].regModbusRead < num_temperatureSensors){ |
brunofgc | 19:d52176ff683d | 190 | leitura_float = temperaturas[alarms[alarmIndex].regModbusRead]; |
brunofgc | 5:8efd609dea7d | 191 | } |
brunofgc | 5:8efd609dea7d | 192 | } |
brunofgc | 19:d52176ff683d | 193 | if((alarms[alarmIndex].regModbusRead>99)&&(alarms[alarmIndex].regModbusRead<104)){//Registradores das entradas analógicas |
brunofgc | 19:d52176ff683d | 194 | leitura_float = aiFiltrada[alarms[alarmIndex].regModbusRead - 100]; |
brunofgc | 5:8efd609dea7d | 195 | } |
brunofgc | 5:8efd609dea7d | 196 | } |
brunofgc | 5:8efd609dea7d | 197 | |
brunofgc | 19:d52176ff683d | 198 | if(alarms[alarmIndex].max!=0){ |
brunofgc | 5:8efd609dea7d | 199 | if(leitura_float > value_float){ |
brunofgc | 19:d52176ff683d | 200 | alarms[alarmIndex].secAlarm++; |
brunofgc | 19:d52176ff683d | 201 | if(alarms[alarmIndex].secAlarm >= alarms[alarmIndex].seconds){ |
brunofgc | 19:d52176ff683d | 202 | alarms[alarmIndex].secAlarm = alarms[alarmIndex].seconds; |
brunofgc | 5:8efd609dea7d | 203 | alarmFound = true; |
brunofgc | 5:8efd609dea7d | 204 | } |
brunofgc | 5:8efd609dea7d | 205 | }else{ |
brunofgc | 19:d52176ff683d | 206 | if(alarms[alarmIndex].secAlarm==1){ |
brunofgc | 19:d52176ff683d | 207 | alarms[alarmIndex].secAlarm=0; |
brunofgc | 5:8efd609dea7d | 208 | alarmFound = false; |
brunofgc | 5:8efd609dea7d | 209 | }else{ |
brunofgc | 19:d52176ff683d | 210 | if(alarms[alarmIndex].secAlarm){ |
brunofgc | 5:8efd609dea7d | 211 | if(alarmFound){ |
brunofgc | 19:d52176ff683d | 212 | alarms[alarmIndex].secAlarm--; |
brunofgc | 5:8efd609dea7d | 213 | }else{ |
brunofgc | 19:d52176ff683d | 214 | alarms[alarmIndex].secAlarm=0; |
brunofgc | 5:8efd609dea7d | 215 | } |
brunofgc | 5:8efd609dea7d | 216 | } |
brunofgc | 5:8efd609dea7d | 217 | } |
brunofgc | 5:8efd609dea7d | 218 | } |
brunofgc | 5:8efd609dea7d | 219 | }else{ |
brunofgc | 5:8efd609dea7d | 220 | if(leitura_float < value_float){ |
brunofgc | 19:d52176ff683d | 221 | alarms[alarmIndex].secAlarm++; |
brunofgc | 19:d52176ff683d | 222 | if(alarms[alarmIndex].secAlarm >= alarms[alarmIndex].seconds){ |
brunofgc | 19:d52176ff683d | 223 | alarms[alarmIndex].secAlarm = alarms[alarmIndex].seconds; |
brunofgc | 5:8efd609dea7d | 224 | alarmFound = true; |
brunofgc | 5:8efd609dea7d | 225 | } |
brunofgc | 5:8efd609dea7d | 226 | }else{ |
brunofgc | 19:d52176ff683d | 227 | if(alarms[alarmIndex].secAlarm==1){ |
brunofgc | 19:d52176ff683d | 228 | alarms[alarmIndex].secAlarm=0; |
brunofgc | 5:8efd609dea7d | 229 | alarmFound = false; |
brunofgc | 5:8efd609dea7d | 230 | }else{ |
brunofgc | 19:d52176ff683d | 231 | if(alarms[alarmIndex].secAlarm){ |
brunofgc | 5:8efd609dea7d | 232 | if(alarmFound){ |
brunofgc | 19:d52176ff683d | 233 | alarms[alarmIndex].secAlarm--; |
brunofgc | 5:8efd609dea7d | 234 | }else{ |
brunofgc | 19:d52176ff683d | 235 | alarms[alarmIndex].secAlarm=0; |
brunofgc | 5:8efd609dea7d | 236 | } |
brunofgc | 5:8efd609dea7d | 237 | } |
brunofgc | 5:8efd609dea7d | 238 | } |
brunofgc | 5:8efd609dea7d | 239 | } |
brunofgc | 5:8efd609dea7d | 240 | } |
brunofgc | 5:8efd609dea7d | 241 | break; |
brunofgc | 5:8efd609dea7d | 242 | case modBusType_uint32_t: |
brunofgc | 5:8efd609dea7d | 243 | //Montar uint32_t! |
brunofgc | 19:d52176ff683d | 244 | uint32_t_ToBin(0,&value_uint32_t,&alarms[alarmIndex].value[0]); |
brunofgc | 5:8efd609dea7d | 245 | |
brunofgc | 19:d52176ff683d | 246 | if(alarms[alarmIndex].addrModbusRead != enderecoControladoraVirtual){//Bloco de leitura da variável modBus; |
brunofgc | 5:8efd609dea7d | 247 | //Bloco de leitura da variável modBus; |
brunofgc | 5:8efd609dea7d | 248 | modBusMaster1::readRegister32BIT( |
brunofgc | 19:d52176ff683d | 249 | alarms[alarmIndex].addrModbusRead, |
brunofgc | 19:d52176ff683d | 250 | alarms[alarmIndex].funcModbusRead, |
brunofgc | 19:d52176ff683d | 251 | alarms[alarmIndex].regModbusRead, |
brunofgc | 5:8efd609dea7d | 252 | 1, |
brunofgc | 5:8efd609dea7d | 253 | &leitura_uint32_t |
brunofgc | 5:8efd609dea7d | 254 | ); |
brunofgc | 5:8efd609dea7d | 255 | }else{ |
brunofgc | 19:d52176ff683d | 256 | leitura_uint32_t = pulsosEDs[alarms[alarmIndex].regModbusRead]; |
brunofgc | 5:8efd609dea7d | 257 | } |
brunofgc | 5:8efd609dea7d | 258 | |
brunofgc | 19:d52176ff683d | 259 | if(alarms[alarmIndex].max!=0){ |
brunofgc | 5:8efd609dea7d | 260 | if(leitura_uint32_t > value_uint32_t){ |
brunofgc | 19:d52176ff683d | 261 | alarms[alarmIndex].secAlarm++; |
brunofgc | 19:d52176ff683d | 262 | if(alarms[alarmIndex].secAlarm >= alarms[alarmIndex].seconds){ |
brunofgc | 19:d52176ff683d | 263 | alarms[alarmIndex].secAlarm = alarms[alarmIndex].seconds; |
brunofgc | 5:8efd609dea7d | 264 | alarmFound = true; |
brunofgc | 19:d52176ff683d | 265 | pulsosEDs[alarms[alarmIndex].regModbusRead]=0; |
brunofgc | 5:8efd609dea7d | 266 | } |
brunofgc | 5:8efd609dea7d | 267 | }else{ |
brunofgc | 19:d52176ff683d | 268 | if(alarms[alarmIndex].secAlarm==1){ |
brunofgc | 19:d52176ff683d | 269 | alarms[alarmIndex].secAlarm=0; |
brunofgc | 5:8efd609dea7d | 270 | alarmFound = false; |
brunofgc | 5:8efd609dea7d | 271 | }else{ |
brunofgc | 19:d52176ff683d | 272 | if(alarms[alarmIndex].secAlarm){ |
brunofgc | 5:8efd609dea7d | 273 | if(alarmFound){ |
brunofgc | 19:d52176ff683d | 274 | alarms[alarmIndex].secAlarm--; |
brunofgc | 5:8efd609dea7d | 275 | }else{ |
brunofgc | 19:d52176ff683d | 276 | alarms[alarmIndex].secAlarm=0; |
brunofgc | 5:8efd609dea7d | 277 | } |
brunofgc | 5:8efd609dea7d | 278 | } |
brunofgc | 5:8efd609dea7d | 279 | } |
brunofgc | 5:8efd609dea7d | 280 | } |
brunofgc | 5:8efd609dea7d | 281 | }else{ |
brunofgc | 5:8efd609dea7d | 282 | if(leitura_uint32_t < value_uint32_t){ |
brunofgc | 19:d52176ff683d | 283 | alarms[alarmIndex].secAlarm++; |
brunofgc | 19:d52176ff683d | 284 | if(alarms[alarmIndex].secAlarm >= alarms[alarmIndex].seconds){ |
brunofgc | 19:d52176ff683d | 285 | alarms[alarmIndex].secAlarm = alarms[alarmIndex].seconds; |
brunofgc | 5:8efd609dea7d | 286 | alarmFound = true; |
brunofgc | 19:d52176ff683d | 287 | pulsosEDs[alarms[alarmIndex].regModbusRead]=0; |
brunofgc | 5:8efd609dea7d | 288 | } |
brunofgc | 5:8efd609dea7d | 289 | }else{ |
brunofgc | 19:d52176ff683d | 290 | if(alarms[alarmIndex].secAlarm==1){ |
brunofgc | 19:d52176ff683d | 291 | alarms[alarmIndex].secAlarm=0; |
brunofgc | 5:8efd609dea7d | 292 | alarmFound = false; |
brunofgc | 5:8efd609dea7d | 293 | }else{ |
brunofgc | 19:d52176ff683d | 294 | if(alarms[alarmIndex].secAlarm){ |
brunofgc | 5:8efd609dea7d | 295 | if(alarmFound){ |
brunofgc | 19:d52176ff683d | 296 | alarms[alarmIndex].secAlarm--; |
brunofgc | 5:8efd609dea7d | 297 | }else{ |
brunofgc | 19:d52176ff683d | 298 | alarms[alarmIndex].secAlarm=0; |
brunofgc | 5:8efd609dea7d | 299 | } |
brunofgc | 5:8efd609dea7d | 300 | } |
brunofgc | 5:8efd609dea7d | 301 | } |
brunofgc | 5:8efd609dea7d | 302 | } |
brunofgc | 5:8efd609dea7d | 303 | } |
brunofgc | 5:8efd609dea7d | 304 | break; |
brunofgc | 0:8c59a494a451 | 305 | |
brunofgc | 5:8efd609dea7d | 306 | case modBusType_uint16_t: |
brunofgc | 5:8efd609dea7d | 307 | //Montar uint16_t! |
brunofgc | 19:d52176ff683d | 308 | uint16_t_ToBin(0,&value_uint16_t,&alarms[alarmIndex].value[0]); |
brunofgc | 5:8efd609dea7d | 309 | |
brunofgc | 19:d52176ff683d | 310 | if(alarms[alarmIndex].addrModbusRead!=enderecoControladoraVirtual){ |
brunofgc | 5:8efd609dea7d | 311 | //Bloco de leitura da variável modBus; |
brunofgc | 5:8efd609dea7d | 312 | modBusMaster1::readRegister16BIT( |
brunofgc | 19:d52176ff683d | 313 | alarms[alarmIndex].addrModbusRead, |
brunofgc | 19:d52176ff683d | 314 | alarms[alarmIndex].funcModbusRead, |
brunofgc | 19:d52176ff683d | 315 | alarms[alarmIndex].regModbusRead, |
brunofgc | 5:8efd609dea7d | 316 | 1, |
brunofgc | 5:8efd609dea7d | 317 | &leitura_uint16_t |
brunofgc | 5:8efd609dea7d | 318 | ); |
brunofgc | 5:8efd609dea7d | 319 | }else{ |
brunofgc | 19:d52176ff683d | 320 | if(alarms[alarmIndex].regModbusRead<4){ |
brunofgc | 19:d52176ff683d | 321 | leitura_uint16_t = aiFiltrada[alarms[alarmIndex].regModbusRead]; |
brunofgc | 5:8efd609dea7d | 322 | } |
brunofgc | 5:8efd609dea7d | 323 | } |
brunofgc | 5:8efd609dea7d | 324 | |
brunofgc | 19:d52176ff683d | 325 | if(alarms[alarmIndex].max!=0){ |
brunofgc | 5:8efd609dea7d | 326 | if(leitura_uint16_t > value_uint16_t){ |
brunofgc | 19:d52176ff683d | 327 | alarms[alarmIndex].secAlarm++; |
brunofgc | 19:d52176ff683d | 328 | if(alarms[alarmIndex].secAlarm >= alarms[alarmIndex].seconds){ |
brunofgc | 19:d52176ff683d | 329 | alarms[alarmIndex].secAlarm = alarms[alarmIndex].seconds; |
brunofgc | 5:8efd609dea7d | 330 | alarmFound = true; |
brunofgc | 5:8efd609dea7d | 331 | } |
brunofgc | 5:8efd609dea7d | 332 | }else{ |
brunofgc | 19:d52176ff683d | 333 | if(alarms[alarmIndex].secAlarm==1){ |
brunofgc | 19:d52176ff683d | 334 | alarms[alarmIndex].secAlarm=0; |
brunofgc | 5:8efd609dea7d | 335 | alarmFound = false; |
brunofgc | 5:8efd609dea7d | 336 | }else{ |
brunofgc | 19:d52176ff683d | 337 | if(alarms[alarmIndex].secAlarm){ |
brunofgc | 5:8efd609dea7d | 338 | if(alarmFound){ |
brunofgc | 19:d52176ff683d | 339 | alarms[alarmIndex].secAlarm--; |
brunofgc | 5:8efd609dea7d | 340 | }else{ |
brunofgc | 19:d52176ff683d | 341 | alarms[alarmIndex].secAlarm=0; |
brunofgc | 5:8efd609dea7d | 342 | } |
brunofgc | 5:8efd609dea7d | 343 | } |
brunofgc | 5:8efd609dea7d | 344 | } |
brunofgc | 5:8efd609dea7d | 345 | } |
brunofgc | 5:8efd609dea7d | 346 | }else{ |
brunofgc | 5:8efd609dea7d | 347 | if(leitura_uint16_t < value_uint16_t){ |
brunofgc | 19:d52176ff683d | 348 | alarms[alarmIndex].secAlarm++; |
brunofgc | 19:d52176ff683d | 349 | if(alarms[alarmIndex].secAlarm >= alarms[alarmIndex].seconds){ |
brunofgc | 19:d52176ff683d | 350 | alarms[alarmIndex].secAlarm = alarms[alarmIndex].seconds; |
brunofgc | 5:8efd609dea7d | 351 | alarmFound = true; |
brunofgc | 5:8efd609dea7d | 352 | } |
brunofgc | 5:8efd609dea7d | 353 | }else{ |
brunofgc | 19:d52176ff683d | 354 | if(alarms[alarmIndex].secAlarm==1){ |
brunofgc | 19:d52176ff683d | 355 | alarms[alarmIndex].secAlarm=0; |
brunofgc | 5:8efd609dea7d | 356 | alarmFound = false; |
brunofgc | 5:8efd609dea7d | 357 | }else{ |
brunofgc | 19:d52176ff683d | 358 | if(alarms[alarmIndex].secAlarm){ |
brunofgc | 5:8efd609dea7d | 359 | if(alarmFound){ |
brunofgc | 19:d52176ff683d | 360 | alarms[alarmIndex].secAlarm--; |
brunofgc | 5:8efd609dea7d | 361 | }else{ |
brunofgc | 19:d52176ff683d | 362 | alarms[alarmIndex].secAlarm=0; |
brunofgc | 5:8efd609dea7d | 363 | } |
brunofgc | 5:8efd609dea7d | 364 | } |
brunofgc | 5:8efd609dea7d | 365 | } |
brunofgc | 5:8efd609dea7d | 366 | } |
brunofgc | 5:8efd609dea7d | 367 | } |
brunofgc | 5:8efd609dea7d | 368 | break; |
brunofgc | 5:8efd609dea7d | 369 | |
brunofgc | 17:c046e4b07ded | 370 | case modBusType_int32_t: |
brunofgc | 17:c046e4b07ded | 371 | //Montar uint32_t! |
brunofgc | 19:d52176ff683d | 372 | uint32_t_ToBin(0,&value_uint32_t,&alarms[alarmIndex].value[0]); |
brunofgc | 17:c046e4b07ded | 373 | |
brunofgc | 19:d52176ff683d | 374 | if(alarms[alarmIndex].addrModbusRead != enderecoControladoraVirtual){//Bloco de leitura da variável modBus; |
brunofgc | 17:c046e4b07ded | 375 | //Bloco de leitura da variável modBus; |
brunofgc | 17:c046e4b07ded | 376 | modBusMaster1::readRegister32BIT( |
brunofgc | 19:d52176ff683d | 377 | alarms[alarmIndex].addrModbusRead, |
brunofgc | 19:d52176ff683d | 378 | alarms[alarmIndex].funcModbusRead, |
brunofgc | 19:d52176ff683d | 379 | alarms[alarmIndex].regModbusRead, |
brunofgc | 17:c046e4b07ded | 380 | 1, |
brunofgc | 17:c046e4b07ded | 381 | &leitura_uint32_t |
brunofgc | 17:c046e4b07ded | 382 | ); |
brunofgc | 17:c046e4b07ded | 383 | }else{ |
brunofgc | 19:d52176ff683d | 384 | leitura_uint32_t = pulsosEDs[alarms[alarmIndex].regModbusRead]; |
brunofgc | 17:c046e4b07ded | 385 | } |
brunofgc | 17:c046e4b07ded | 386 | |
brunofgc | 19:d52176ff683d | 387 | if(alarms[alarmIndex].max!=0){ |
brunofgc | 17:c046e4b07ded | 388 | if(((int32_t)leitura_uint32_t) > ((int32_t)value_uint32_t)){ |
brunofgc | 19:d52176ff683d | 389 | alarms[alarmIndex].secAlarm++; |
brunofgc | 19:d52176ff683d | 390 | if(alarms[alarmIndex].secAlarm >= alarms[alarmIndex].seconds){ |
brunofgc | 19:d52176ff683d | 391 | alarms[alarmIndex].secAlarm = alarms[alarmIndex].seconds; |
brunofgc | 17:c046e4b07ded | 392 | alarmFound = true; |
brunofgc | 19:d52176ff683d | 393 | pulsosEDs[alarms[alarmIndex].regModbusRead]=0; |
brunofgc | 17:c046e4b07ded | 394 | } |
brunofgc | 17:c046e4b07ded | 395 | }else{ |
brunofgc | 19:d52176ff683d | 396 | if(alarms[alarmIndex].secAlarm==1){ |
brunofgc | 19:d52176ff683d | 397 | alarms[alarmIndex].secAlarm=0; |
brunofgc | 17:c046e4b07ded | 398 | alarmFound = false; |
brunofgc | 17:c046e4b07ded | 399 | }else{ |
brunofgc | 19:d52176ff683d | 400 | if(alarms[alarmIndex].secAlarm){ |
brunofgc | 17:c046e4b07ded | 401 | if(alarmFound){ |
brunofgc | 19:d52176ff683d | 402 | alarms[alarmIndex].secAlarm--; |
brunofgc | 17:c046e4b07ded | 403 | }else{ |
brunofgc | 19:d52176ff683d | 404 | alarms[alarmIndex].secAlarm=0; |
brunofgc | 17:c046e4b07ded | 405 | } |
brunofgc | 17:c046e4b07ded | 406 | } |
brunofgc | 17:c046e4b07ded | 407 | } |
brunofgc | 17:c046e4b07ded | 408 | } |
brunofgc | 17:c046e4b07ded | 409 | }else{ |
brunofgc | 17:c046e4b07ded | 410 | if(((int32_t)leitura_uint32_t) < ((int32_t)value_uint32_t)){ |
brunofgc | 19:d52176ff683d | 411 | alarms[alarmIndex].secAlarm++; |
brunofgc | 19:d52176ff683d | 412 | if(alarms[alarmIndex].secAlarm >= alarms[alarmIndex].seconds){ |
brunofgc | 19:d52176ff683d | 413 | alarms[alarmIndex].secAlarm = alarms[alarmIndex].seconds; |
brunofgc | 17:c046e4b07ded | 414 | alarmFound = true; |
brunofgc | 19:d52176ff683d | 415 | pulsosEDs[alarms[alarmIndex].regModbusRead]=0; |
brunofgc | 17:c046e4b07ded | 416 | } |
brunofgc | 17:c046e4b07ded | 417 | }else{ |
brunofgc | 19:d52176ff683d | 418 | if(alarms[alarmIndex].secAlarm==1){ |
brunofgc | 19:d52176ff683d | 419 | alarms[alarmIndex].secAlarm=0; |
brunofgc | 17:c046e4b07ded | 420 | alarmFound = false; |
brunofgc | 17:c046e4b07ded | 421 | }else{ |
brunofgc | 19:d52176ff683d | 422 | if(alarms[alarmIndex].secAlarm){ |
brunofgc | 17:c046e4b07ded | 423 | if(alarmFound){ |
brunofgc | 19:d52176ff683d | 424 | alarms[alarmIndex].secAlarm--; |
brunofgc | 17:c046e4b07ded | 425 | }else{ |
brunofgc | 19:d52176ff683d | 426 | alarms[alarmIndex].secAlarm=0; |
brunofgc | 17:c046e4b07ded | 427 | } |
brunofgc | 17:c046e4b07ded | 428 | } |
brunofgc | 17:c046e4b07ded | 429 | } |
brunofgc | 17:c046e4b07ded | 430 | } |
brunofgc | 17:c046e4b07ded | 431 | } |
brunofgc | 17:c046e4b07ded | 432 | break; |
brunofgc | 17:c046e4b07ded | 433 | |
brunofgc | 17:c046e4b07ded | 434 | case modBusType_int16_t: |
brunofgc | 17:c046e4b07ded | 435 | //Montar uint16_t! |
brunofgc | 19:d52176ff683d | 436 | uint16_t_ToBin(0,&value_uint16_t,&alarms[alarmIndex].value[0]); |
brunofgc | 17:c046e4b07ded | 437 | |
brunofgc | 19:d52176ff683d | 438 | if(alarms[alarmIndex].addrModbusRead!=enderecoControladoraVirtual){ |
brunofgc | 17:c046e4b07ded | 439 | //Bloco de leitura da variável modBus; |
brunofgc | 17:c046e4b07ded | 440 | modBusMaster1::readRegister16BIT( |
brunofgc | 19:d52176ff683d | 441 | alarms[alarmIndex].addrModbusRead, |
brunofgc | 19:d52176ff683d | 442 | alarms[alarmIndex].funcModbusRead, |
brunofgc | 19:d52176ff683d | 443 | alarms[alarmIndex].regModbusRead, |
brunofgc | 17:c046e4b07ded | 444 | 1, |
brunofgc | 17:c046e4b07ded | 445 | &leitura_uint16_t |
brunofgc | 17:c046e4b07ded | 446 | ); |
brunofgc | 17:c046e4b07ded | 447 | }else{ |
brunofgc | 19:d52176ff683d | 448 | if(alarms[alarmIndex].regModbusRead<4){ |
brunofgc | 19:d52176ff683d | 449 | leitura_uint16_t = aiFiltrada[alarms[alarmIndex].regModbusRead]; |
brunofgc | 17:c046e4b07ded | 450 | } |
brunofgc | 17:c046e4b07ded | 451 | } |
brunofgc | 17:c046e4b07ded | 452 | |
brunofgc | 19:d52176ff683d | 453 | if(alarms[alarmIndex].max!=0){ |
brunofgc | 17:c046e4b07ded | 454 | if(((int16_t)leitura_uint16_t) > ((int16_t)value_uint16_t)){ |
brunofgc | 19:d52176ff683d | 455 | alarms[alarmIndex].secAlarm++; |
brunofgc | 19:d52176ff683d | 456 | if(alarms[alarmIndex].secAlarm >= alarms[alarmIndex].seconds){ |
brunofgc | 19:d52176ff683d | 457 | alarms[alarmIndex].secAlarm = alarms[alarmIndex].seconds; |
brunofgc | 17:c046e4b07ded | 458 | alarmFound = true; |
brunofgc | 17:c046e4b07ded | 459 | } |
brunofgc | 17:c046e4b07ded | 460 | }else{ |
brunofgc | 19:d52176ff683d | 461 | if(alarms[alarmIndex].secAlarm==1){ |
brunofgc | 19:d52176ff683d | 462 | alarms[alarmIndex].secAlarm=0; |
brunofgc | 17:c046e4b07ded | 463 | alarmFound = false; |
brunofgc | 17:c046e4b07ded | 464 | }else{ |
brunofgc | 19:d52176ff683d | 465 | if(alarms[alarmIndex].secAlarm){ |
brunofgc | 17:c046e4b07ded | 466 | if(alarmFound){ |
brunofgc | 19:d52176ff683d | 467 | alarms[alarmIndex].secAlarm--; |
brunofgc | 17:c046e4b07ded | 468 | }else{ |
brunofgc | 19:d52176ff683d | 469 | alarms[alarmIndex].secAlarm=0; |
brunofgc | 17:c046e4b07ded | 470 | } |
brunofgc | 17:c046e4b07ded | 471 | } |
brunofgc | 17:c046e4b07ded | 472 | } |
brunofgc | 17:c046e4b07ded | 473 | } |
brunofgc | 17:c046e4b07ded | 474 | }else{ |
brunofgc | 17:c046e4b07ded | 475 | if(((int16_t)leitura_uint16_t) < ((int16_t)value_uint16_t)){ |
brunofgc | 19:d52176ff683d | 476 | alarms[alarmIndex].secAlarm++; |
brunofgc | 19:d52176ff683d | 477 | if(alarms[alarmIndex].secAlarm >= alarms[alarmIndex].seconds){ |
brunofgc | 19:d52176ff683d | 478 | alarms[alarmIndex].secAlarm = alarms[alarmIndex].seconds; |
brunofgc | 17:c046e4b07ded | 479 | alarmFound = true; |
brunofgc | 17:c046e4b07ded | 480 | } |
brunofgc | 17:c046e4b07ded | 481 | }else{ |
brunofgc | 19:d52176ff683d | 482 | if(alarms[alarmIndex].secAlarm==1){ |
brunofgc | 19:d52176ff683d | 483 | alarms[alarmIndex].secAlarm=0; |
brunofgc | 17:c046e4b07ded | 484 | alarmFound = false; |
brunofgc | 17:c046e4b07ded | 485 | }else{ |
brunofgc | 19:d52176ff683d | 486 | if(alarms[alarmIndex].secAlarm){ |
brunofgc | 17:c046e4b07ded | 487 | if(alarmFound){ |
brunofgc | 19:d52176ff683d | 488 | alarms[alarmIndex].secAlarm--; |
brunofgc | 17:c046e4b07ded | 489 | }else{ |
brunofgc | 19:d52176ff683d | 490 | alarms[alarmIndex].secAlarm=0; |
brunofgc | 17:c046e4b07ded | 491 | } |
brunofgc | 17:c046e4b07ded | 492 | } |
brunofgc | 17:c046e4b07ded | 493 | } |
brunofgc | 17:c046e4b07ded | 494 | } |
brunofgc | 17:c046e4b07ded | 495 | } |
brunofgc | 17:c046e4b07ded | 496 | break; |
brunofgc | 17:c046e4b07ded | 497 | |
brunofgc | 17:c046e4b07ded | 498 | |
brunofgc | 6:f20c0e094294 | 499 | case modBusType_bit: |
brunofgc | 5:8efd609dea7d | 500 | //Montar bit! |
brunofgc | 5:8efd609dea7d | 501 | //O valor de alarm para bit é o value[0]!!! |
brunofgc | 19:d52176ff683d | 502 | value_bit = (alarms[alarmIndex].value[0] > 0); //Qualquer valor maior que zero da saída 1 |
brunofgc | 5:8efd609dea7d | 503 | |
brunofgc | 19:d52176ff683d | 504 | if(alarms[alarmIndex].addrModbusRead != enderecoControladoraVirtual){//Bloco de leitura da variável modBus; |
brunofgc | 6:f20c0e094294 | 505 | //Bloco de leitura da variável modBus; |
brunofgc | 6:f20c0e094294 | 506 | modBusMaster1::readCoils( |
brunofgc | 19:d52176ff683d | 507 | alarms[alarmIndex].addrModbusRead, |
brunofgc | 19:d52176ff683d | 508 | alarms[alarmIndex].regModbusRead, |
brunofgc | 6:f20c0e094294 | 509 | 1, |
brunofgc | 6:f20c0e094294 | 510 | &leitura_bit |
brunofgc | 6:f20c0e094294 | 511 | ); |
brunofgc | 6:f20c0e094294 | 512 | }else{ |
brunofgc | 19:d52176ff683d | 513 | leitura_bit = entradasDigitais[alarms[alarmIndex].regModbusRead]; |
brunofgc | 6:f20c0e094294 | 514 | } |
brunofgc | 5:8efd609dea7d | 515 | if(leitura_bit == value_bit){ |
brunofgc | 19:d52176ff683d | 516 | alarms[alarmIndex].secAlarm++; |
brunofgc | 19:d52176ff683d | 517 | if(alarms[alarmIndex].secAlarm >= alarms[alarmIndex].seconds){ |
brunofgc | 19:d52176ff683d | 518 | alarms[alarmIndex].secAlarm = alarms[alarmIndex].seconds; |
brunofgc | 0:8c59a494a451 | 519 | alarmFound = true; |
brunofgc | 0:8c59a494a451 | 520 | } |
brunofgc | 0:8c59a494a451 | 521 | }else{ |
brunofgc | 19:d52176ff683d | 522 | if(alarms[alarmIndex].secAlarm==1){ |
brunofgc | 19:d52176ff683d | 523 | alarms[alarmIndex].secAlarm=0; |
brunofgc | 0:8c59a494a451 | 524 | alarmFound = false; |
brunofgc | 0:8c59a494a451 | 525 | }else{ |
brunofgc | 19:d52176ff683d | 526 | if(alarms[alarmIndex].secAlarm){ |
brunofgc | 0:8c59a494a451 | 527 | if(alarmFound){ |
brunofgc | 19:d52176ff683d | 528 | alarms[alarmIndex].secAlarm--; |
brunofgc | 0:8c59a494a451 | 529 | }else{ |
brunofgc | 19:d52176ff683d | 530 | alarms[alarmIndex].secAlarm=0; |
brunofgc | 0:8c59a494a451 | 531 | } |
brunofgc | 0:8c59a494a451 | 532 | } |
brunofgc | 0:8c59a494a451 | 533 | } |
brunofgc | 5:8efd609dea7d | 534 | } |
brunofgc | 5:8efd609dea7d | 535 | break; |
brunofgc | 0:8c59a494a451 | 536 | |
brunofgc | 5:8efd609dea7d | 537 | } |
brunofgc | 19:d52176ff683d | 538 | |
brunofgc | 5:8efd609dea7d | 539 | //Verifico se houve alarme não tratado |
brunofgc | 19:d52176ff683d | 540 | if(alarms[alarmIndex].alarmFound!=alarmFound){ |
brunofgc | 19:d52176ff683d | 541 | alarms[alarmIndex].alarmFound=alarmFound; |
brunofgc | 5:8efd609dea7d | 542 | if(alarmFound){ |
brunofgc | 19:d52176ff683d | 543 | printf("Alarm FOUND! Id <%lu>.\n",alarms[alarmIndex].id); |
brunofgc | 5:8efd609dea7d | 544 | sdCardBuf.fill("log{alarm:event:found;id:",25); |
brunofgc | 19:d52176ff683d | 545 | sprintf(aux,"%lu",alarms[alarmIndex].id); |
brunofgc | 5:8efd609dea7d | 546 | sdCardBuf.fill(aux,strlen(aux)); |
brunofgc | 5:8efd609dea7d | 547 | |
brunofgc | 5:8efd609dea7d | 548 | sdCardBuf.fill(";timestamp:",11); |
brunofgc | 5:8efd609dea7d | 549 | sprintf(aux,"%lu",time(NULL)); |
brunofgc | 5:8efd609dea7d | 550 | sdCardBuf.fill(aux,strlen(aux)); |
brunofgc | 5:8efd609dea7d | 551 | |
brunofgc | 5:8efd609dea7d | 552 | sdCardBuf.fill(";reading:",9); |
brunofgc | 19:d52176ff683d | 553 | if(alarms[alarmIndex].type == modBusType_float){ |
brunofgc | 5:8efd609dea7d | 554 | sprintf(aux,"%f",leitura_float); |
brunofgc | 19:d52176ff683d | 555 | }else if(alarms[alarmIndex].type == modBusType_uint32_t){ |
brunofgc | 5:8efd609dea7d | 556 | sprintf(aux,"%lu",leitura_uint32_t); |
brunofgc | 19:d52176ff683d | 557 | }else if(alarms[alarmIndex].type == modBusType_uint16_t){ |
brunofgc | 5:8efd609dea7d | 558 | sprintf(aux,"%lu",leitura_uint16_t); |
brunofgc | 19:d52176ff683d | 559 | }else if(alarms[alarmIndex].type == modBusType_int32_t){ |
brunofgc | 18:66fa6fcba212 | 560 | sprintf(aux,"%ld",(int32_t)leitura_uint32_t); |
brunofgc | 19:d52176ff683d | 561 | }else if(alarms[alarmIndex].type == modBusType_int16_t){ |
brunofgc | 18:66fa6fcba212 | 562 | sprintf(aux,"%ld",(int16_t)leitura_uint16_t); |
brunofgc | 19:d52176ff683d | 563 | }else if(alarms[alarmIndex].type == modBusType_bit){ |
brunofgc | 5:8efd609dea7d | 564 | sprintf(aux,"%lu",leitura_bit); |
brunofgc | 5:8efd609dea7d | 565 | } |
brunofgc | 5:8efd609dea7d | 566 | sdCardBuf.fill(aux,strlen(aux)); |
brunofgc | 5:8efd609dea7d | 567 | leitura_uint16_t = sdCardBuf.fill("}log",4); //Reaproveitando uma variável de 16bit |
brunofgc | 8:25061210fcc9 | 568 | sdCard::insereDadosBank(sdCardBuf.get(),leitura_uint16_t); |
brunofgc | 5:8efd609dea7d | 569 | |
brunofgc | 5:8efd609dea7d | 570 | boolExecAct=true; |
brunofgc | 19:d52176ff683d | 571 | act = alarms[alarmIndex].idAct; |
brunofgc | 5:8efd609dea7d | 572 | }else{ |
brunofgc | 19:d52176ff683d | 573 | printf("Alarm RELEASE! id <%lu>.\n",alarms[alarmIndex].id); |
brunofgc | 5:8efd609dea7d | 574 | sdCardBuf.fill("log{alarm:event:release;id:",27); |
brunofgc | 19:d52176ff683d | 575 | sprintf(aux,"%lu",alarms[alarmIndex].id); |
brunofgc | 5:8efd609dea7d | 576 | sdCardBuf.fill(aux,strlen(aux)); |
brunofgc | 5:8efd609dea7d | 577 | |
brunofgc | 5:8efd609dea7d | 578 | sdCardBuf.fill(";timestamp:",11); |
brunofgc | 5:8efd609dea7d | 579 | sprintf(aux,"%lu",time(NULL)); |
brunofgc | 5:8efd609dea7d | 580 | sdCardBuf.fill(aux,strlen(aux)); |
brunofgc | 5:8efd609dea7d | 581 | |
brunofgc | 5:8efd609dea7d | 582 | leitura_uint16_t = sdCardBuf.fill("}log",4); //Reaproveitando uma variável de 16bit |
brunofgc | 5:8efd609dea7d | 583 | sdCard::arquivoAberto(40000); |
brunofgc | 8:25061210fcc9 | 584 | sdCard::insereDadosBank(sdCardBuf.get(),leitura_uint16_t); |
brunofgc | 5:8efd609dea7d | 585 | } |
brunofgc | 5:8efd609dea7d | 586 | //atrasa o envio em 3 segundos para que possa ser gravado o registro do alarme. |
brunofgc | 5:8efd609dea7d | 587 | enviaDadosPorAlarme=10; |
brunofgc | 5:8efd609dea7d | 588 | } |
brunofgc | 0:8c59a494a451 | 589 | } |
brunofgc | 0:8c59a494a451 | 590 | } |
brunofgc | 0:8c59a494a451 | 591 | } |
brunofgc | 0:8c59a494a451 | 592 | |
brunofgc | 19:d52176ff683d | 593 | void verifySchedules(){ |
brunofgc | 5:8efd609dea7d | 594 | char stringTime[30]; |
brunofgc | 0:8c59a494a451 | 595 | char *weekdayString; |
brunofgc | 5:8efd609dea7d | 596 | time_t seconds = time(NULL)+5; |
brunofgc | 0:8c59a494a451 | 597 | uint8_t hora; |
brunofgc | 0:8c59a494a451 | 598 | uint16_t minuto; |
brunofgc | 0:8c59a494a451 | 599 | uint8_t weekday=0; |
brunofgc | 5:8efd609dea7d | 600 | uint16_t anoAtual=0; |
brunofgc | 5:8efd609dea7d | 601 | uint16_t diaAtual=0; |
brunofgc | 5:8efd609dea7d | 602 | uint16_t mesAtual=0; |
brunofgc | 5:8efd609dea7d | 603 | uint16_t anoScheduleException=0; |
brunofgc | 5:8efd609dea7d | 604 | uint16_t diaScheduleException=0; |
brunofgc | 5:8efd609dea7d | 605 | uint16_t mesScheduleException=0; |
brunofgc | 0:8c59a494a451 | 606 | const char* weekdayTable[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"}; |
brunofgc | 0:8c59a494a451 | 607 | uint8_t indexSchedule; |
brunofgc | 5:8efd609dea7d | 608 | uint8_t indexScheduleException; |
brunofgc | 5:8efd609dea7d | 609 | bool exceptionDetected=false; |
brunofgc | 0:8c59a494a451 | 610 | |
brunofgc | 23:d3ef6bb8412a | 611 | puts("Verifing schedule.\r\n"); |
brunofgc | 0:8c59a494a451 | 612 | |
brunofgc | 5:8efd609dea7d | 613 | strftime(stringTime, 30, "%a,%R,%y,%d,%m", localtime(&seconds)); |
brunofgc | 5:8efd609dea7d | 614 | //pc.printf("VerifySchedule <%s>.\r\n",stringTime); |
brunofgc | 5:8efd609dea7d | 615 | //Thu,20:48,17,2,7 |
brunofgc | 0:8c59a494a451 | 616 | weekdayString = strtok(stringTime,","); |
brunofgc | 0:8c59a494a451 | 617 | weekday = 0; |
brunofgc | 0:8c59a494a451 | 618 | while((weekday<10)&&(strstr(weekdayTable[weekday],weekdayString)==NULL)){ |
brunofgc | 0:8c59a494a451 | 619 | weekday++; |
brunofgc | 0:8c59a494a451 | 620 | } |
brunofgc | 0:8c59a494a451 | 621 | hora = atoi(strtok(NULL,":")); |
brunofgc | 5:8efd609dea7d | 622 | minuto = atoi(strtok(NULL,",")); |
brunofgc | 5:8efd609dea7d | 623 | minuto = (hora*60)+minuto; |
brunofgc | 5:8efd609dea7d | 624 | anoAtual = atoi(strtok(NULL,",")); |
brunofgc | 5:8efd609dea7d | 625 | diaAtual = atoi(strtok(NULL,",")); |
brunofgc | 5:8efd609dea7d | 626 | mesAtual = atoi(strtok(NULL,"")); |
brunofgc | 5:8efd609dea7d | 627 | |
brunofgc | 5:8efd609dea7d | 628 | //pc.printf("Passo 1 .\r\n"); |
brunofgc | 5:8efd609dea7d | 629 | for(indexSchedule = 0; indexSchedule < qtdSchedules; indexSchedule++){ |
brunofgc | 20:e0656406d5b8 | 630 | //pc.printf("Passo 2.\r\n"); |
brunofgc | 22:e0d8c8fe26c6 | 631 | diversos::wdt.kick(180.0); |
brunofgc | 19:d52176ff683d | 632 | if(schedules[indexSchedule].weekday&(0x1<<weekday)){ |
brunofgc | 5:8efd609dea7d | 633 | //pc.printf("Passo 3.\r\n"); |
brunofgc | 19:d52176ff683d | 634 | if(schedules[indexSchedule].minute == minuto){ |
brunofgc | 5:8efd609dea7d | 635 | //pc.printf("Passo 4.\r\n"); |
brunofgc | 0:8c59a494a451 | 636 | //Verifico se já executei e então executo a ação. |
brunofgc | 19:d52176ff683d | 637 | if(!schedules[indexSchedule].actSent){ |
brunofgc | 5:8efd609dea7d | 638 | //pc.printf("Passo 5 .\r\n"); |
brunofgc | 0:8c59a494a451 | 639 | //Executa a ação; |
brunofgc | 19:d52176ff683d | 640 | for(indexScheduleException = 0;indexScheduleException<numScheduleExceptions;indexScheduleException++){ |
brunofgc | 5:8efd609dea7d | 641 | //pc.printf("Passo 6.\r\n"); |
brunofgc | 19:d52176ff683d | 642 | if(schedules[indexSchedule].id == scheduleExceptions[indexScheduleException].id_schedule){ |
brunofgc | 5:8efd609dea7d | 643 | //pc.printf("Passo 7.\r\n"); |
brunofgc | 19:d52176ff683d | 644 | seconds = scheduleExceptions[indexScheduleException].timestamp; |
brunofgc | 5:8efd609dea7d | 645 | strftime(stringTime, 30, "%y,%d,%m", localtime(&seconds)); |
brunofgc | 5:8efd609dea7d | 646 | anoScheduleException=atoi(strtok(stringTime,",")); |
brunofgc | 5:8efd609dea7d | 647 | diaScheduleException=atoi(strtok(NULL,",")); |
brunofgc | 5:8efd609dea7d | 648 | mesScheduleException=atoi(strtok(NULL,"")); |
brunofgc | 5:8efd609dea7d | 649 | /* |
brunofgc | 5:8efd609dea7d | 650 | pc.printf("\r\nDebug ScheduleException.\r\n"); |
brunofgc | 5:8efd609dea7d | 651 | pc.printf("stringTime <%s>.\r\n",stringTime); |
brunofgc | 5:8efd609dea7d | 652 | pc.printf("anoScheduleException %lu.",anoScheduleException); |
brunofgc | 5:8efd609dea7d | 653 | pc.printf("diaScheduleException %lu.",diaScheduleException); |
brunofgc | 5:8efd609dea7d | 654 | pc.printf("mesScheduleException %lu.",mesScheduleException); |
brunofgc | 5:8efd609dea7d | 655 | pc.printf("anoAtual %lu.",anoAtual); |
brunofgc | 5:8efd609dea7d | 656 | pc.printf("diaAtual %lu.",diaAtual); |
brunofgc | 5:8efd609dea7d | 657 | pc.printf("mesAtual %lu.",mesAtual); |
brunofgc | 5:8efd609dea7d | 658 | pc.printf("\r\n"); |
brunofgc | 5:8efd609dea7d | 659 | */ |
brunofgc | 5:8efd609dea7d | 660 | if( |
brunofgc | 5:8efd609dea7d | 661 | ((anoScheduleException == anoAtual) || (anoScheduleException == 70)) |
brunofgc | 5:8efd609dea7d | 662 | && |
brunofgc | 5:8efd609dea7d | 663 | (diaAtual == diaScheduleException) |
brunofgc | 5:8efd609dea7d | 664 | && |
brunofgc | 5:8efd609dea7d | 665 | (mesAtual == mesScheduleException) |
brunofgc | 5:8efd609dea7d | 666 | ) |
brunofgc | 5:8efd609dea7d | 667 | { |
brunofgc | 5:8efd609dea7d | 668 | pc.printf("ScheduleException detected.\r\n"); |
brunofgc | 5:8efd609dea7d | 669 | exceptionDetected=true; |
brunofgc | 5:8efd609dea7d | 670 | } |
brunofgc | 5:8efd609dea7d | 671 | } |
brunofgc | 5:8efd609dea7d | 672 | } |
brunofgc | 20:e0656406d5b8 | 673 | if(!exceptionDetected){ |
brunofgc | 19:d52176ff683d | 674 | execAct(schedules[indexSchedule].idAct); |
brunofgc | 19:d52176ff683d | 675 | schedules[indexSchedule].actSent = true; |
brunofgc | 5:8efd609dea7d | 676 | } |
brunofgc | 0:8c59a494a451 | 677 | } |
brunofgc | 0:8c59a494a451 | 678 | }else{ |
brunofgc | 19:d52176ff683d | 679 | schedules[indexSchedule].actSent = false; |
brunofgc | 0:8c59a494a451 | 680 | } |
brunofgc | 5:8efd609dea7d | 681 | } |
brunofgc | 0:8c59a494a451 | 682 | } |
brunofgc | 0:8c59a494a451 | 683 | } |
brunofgc | 0:8c59a494a451 | 684 | |
brunofgc | 0:8c59a494a451 | 685 | /* |
brunofgc | 19:d52176ff683d | 686 | void verifySchedules(){ |
brunofgc | 0:8c59a494a451 | 687 | char stringTime[15]; |
brunofgc | 0:8c59a494a451 | 688 | char *weekdayString; |
brunofgc | 0:8c59a494a451 | 689 | time_t seconds = time(NULL); |
brunofgc | 0:8c59a494a451 | 690 | uint8_t hora; |
brunofgc | 0:8c59a494a451 | 691 | uint16_t minuto; |
brunofgc | 0:8c59a494a451 | 692 | uint8_t weekday=0; |
brunofgc | 0:8c59a494a451 | 693 | const char* weekdayTable[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"}; |
brunofgc | 0:8c59a494a451 | 694 | uint8_t indexSchedule; |
brunofgc | 0:8c59a494a451 | 695 | |
brunofgc | 0:8c59a494a451 | 696 | //Tue,19:09 |
brunofgc | 0:8c59a494a451 | 697 | strftime(stringTime, 15, "%a,%R", localtime(&seconds)); |
brunofgc | 0:8c59a494a451 | 698 | |
brunofgc | 0:8c59a494a451 | 699 | weekdayString = strtok(stringTime,","); |
brunofgc | 0:8c59a494a451 | 700 | weekday = 0; |
brunofgc | 0:8c59a494a451 | 701 | while((weekday<10)&&(strstr(weekdayTable[weekday],weekdayString)==NULL)){ |
brunofgc | 0:8c59a494a451 | 702 | weekday++; |
brunofgc | 0:8c59a494a451 | 703 | } |
brunofgc | 0:8c59a494a451 | 704 | weekday++; |
brunofgc | 0:8c59a494a451 | 705 | hora = atoi(strtok(NULL,":")); |
brunofgc | 0:8c59a494a451 | 706 | minuto = atoi(strtok(NULL,"")); |
brunofgc | 0:8c59a494a451 | 707 | minuto = (hora*60)+minuto; |
brunofgc | 0:8c59a494a451 | 708 | //printf("\r\n\r\nMinuto %lu.\r\n\r\n",minuto); |
brunofgc | 0:8c59a494a451 | 709 | for(indexSchedule = 0; indexSchedule < qtdSchedules; indexSchedule++){ |
brunofgc | 0:8c59a494a451 | 710 | //printf("Executando item %u do for de schedules.\r\n\r\n",indexSchedule); |
brunofgc | 19:d52176ff683d | 711 | if((schedules[indexSchedule].weekday == weekday)||(schedules[indexSchedule].weekday == 0)){ |
brunofgc | 0:8c59a494a451 | 712 | //Se for um alarme para o dia de hoje ou o alarme independer de dia (Se o dia for zero) |
brunofgc | 0:8c59a494a451 | 713 | //printf("Hoje eh dia de executar a acão do schedule indice %u.\r\n\r\n",indexSchedule); |
brunofgc | 19:d52176ff683d | 714 | if(schedules[indexSchedule].minute == minuto){ |
brunofgc | 0:8c59a494a451 | 715 | //Verifico se já executei e então executo a ação. |
brunofgc | 19:d52176ff683d | 716 | if(!schedules[indexSchedule].actSent){ |
brunofgc | 0:8c59a494a451 | 717 | //Executa a ação; |
brunofgc | 0:8c59a494a451 | 718 | //printf("Executando a acao!\r\n\r\n"); |
brunofgc | 19:d52176ff683d | 719 | execAct(schedules[indexSchedule].idAct); |
brunofgc | 19:d52176ff683d | 720 | schedules[indexSchedule].actSent = true; |
brunofgc | 0:8c59a494a451 | 721 | } |
brunofgc | 0:8c59a494a451 | 722 | }else{ |
brunofgc | 19:d52176ff683d | 723 | schedules[indexSchedule].actSent = false; |
brunofgc | 0:8c59a494a451 | 724 | } |
brunofgc | 0:8c59a494a451 | 725 | } |
brunofgc | 0:8c59a494a451 | 726 | } |
brunofgc | 0:8c59a494a451 | 727 | } |
brunofgc | 0:8c59a494a451 | 728 | */ |
brunofgc | 0:8c59a494a451 | 729 | /* |
brunofgc | 19:d52176ff683d | 730 | uint8_t execActSchedule(uint32_t index){ |
brunofgc | 19:d52176ff683d | 731 | switch(schedules[index].actType){ |
brunofgc | 0:8c59a494a451 | 732 | case modBusType_float: |
brunofgc | 0:8c59a494a451 | 733 | float floatValueToWrite; |
brunofgc | 0:8c59a494a451 | 734 | //writeFloat(uint8_t,uint16_t,uint8_t,float*); |
brunofgc | 19:d52176ff683d | 735 | floatToBin(0,&floatValueToWrite,&schedules[index].actValue[0]); |
brunofgc | 0:8c59a494a451 | 736 | modBusMaster1::writeFloat( |
brunofgc | 19:d52176ff683d | 737 | schedules[index].param1, |
brunofgc | 19:d52176ff683d | 738 | schedules[index].param2, |
brunofgc | 19:d52176ff683d | 739 | schedules[index].param3, |
brunofgc | 0:8c59a494a451 | 740 | &floatValueToWrite |
brunofgc | 0:8c59a494a451 | 741 | ); |
brunofgc | 0:8c59a494a451 | 742 | break; |
brunofgc | 0:8c59a494a451 | 743 | case modBusType_uint32_t: |
brunofgc | 0:8c59a494a451 | 744 | uint32_t uint32ValueToWrite; |
brunofgc | 19:d52176ff683d | 745 | uint32_t_ToBin(0,&uint32ValueToWrite,&schedules[index].actValue[0]); |
brunofgc | 0:8c59a494a451 | 746 | modBusMaster1::writeRegister32BIT( |
brunofgc | 19:d52176ff683d | 747 | schedules[index].param1, |
brunofgc | 19:d52176ff683d | 748 | schedules[index].param2, |
brunofgc | 19:d52176ff683d | 749 | schedules[index].param3, |
brunofgc | 0:8c59a494a451 | 750 | &uint32ValueToWrite |
brunofgc | 0:8c59a494a451 | 751 | ); |
brunofgc | 0:8c59a494a451 | 752 | break; |
brunofgc | 0:8c59a494a451 | 753 | case modBusType_uint16_t: |
brunofgc | 0:8c59a494a451 | 754 | uint16_t uint16ValueToWrite; |
brunofgc | 19:d52176ff683d | 755 | uint16_t_ToBin(0,&uint16ValueToWrite,&schedules[index].actValue[0]); |
brunofgc | 0:8c59a494a451 | 756 | modBusMaster1::writeRegister16BIT( |
brunofgc | 19:d52176ff683d | 757 | schedules[index].param1, |
brunofgc | 19:d52176ff683d | 758 | schedules[index].param2, |
brunofgc | 19:d52176ff683d | 759 | schedules[index].param3, |
brunofgc | 0:8c59a494a451 | 760 | &uint16ValueToWrite |
brunofgc | 0:8c59a494a451 | 761 | ); |
brunofgc | 0:8c59a494a451 | 762 | break; |
brunofgc | 0:8c59a494a451 | 763 | case modBusType_bit: |
brunofgc | 0:8c59a494a451 | 764 | bool boolValueToWrite; |
brunofgc | 19:d52176ff683d | 765 | boolValueToWrite = (schedules[index].actValue[0] != 0); |
brunofgc | 0:8c59a494a451 | 766 | modBusMaster1::writeSingleCoil( |
brunofgc | 19:d52176ff683d | 767 | schedules[index].param1, |
brunofgc | 19:d52176ff683d | 768 | schedules[index].param3, |
brunofgc | 0:8c59a494a451 | 769 | boolValueToWrite |
brunofgc | 0:8c59a494a451 | 770 | ); |
brunofgc | 0:8c59a494a451 | 771 | break; |
brunofgc | 0:8c59a494a451 | 772 | case IrCommandType: |
brunofgc | 0:8c59a494a451 | 773 | //Busca no arquivo |
brunofgc | 0:8c59a494a451 | 774 | //Abre arquivo |
brunofgc | 0:8c59a494a451 | 775 | char comandoIr[1024]; |
brunofgc | 0:8c59a494a451 | 776 | char indexBusca[10]; |
brunofgc | 0:8c59a494a451 | 777 | bool endOfFile = false; |
brunofgc | 0:8c59a494a451 | 778 | |
brunofgc | 0:8c59a494a451 | 779 | //printf("\r\n===================DEBUG(Schedule)===================\r\n"); |
brunofgc | 0:8c59a494a451 | 780 | //"Ir:0,6E01FFFFS" |
brunofgc | 19:d52176ff683d | 781 | sprintf(indexBusca,"Ir:%u,",schedules[index].param3); |
brunofgc | 0:8c59a494a451 | 782 | //printf("indexBusca = <%s>.\r\n",indexBusca); |
brunofgc | 0:8c59a494a451 | 783 | if(sdCard::abreArquivo(&sdCard::devices,"r")){ |
brunofgc | 0:8c59a494a451 | 784 | do{ |
brunofgc | 0:8c59a494a451 | 785 | fgets(comandoIr,1024,sdCard::devices.fp); |
brunofgc | 0:8c59a494a451 | 786 | endOfFile = feof(sdCard::devices.fp); |
brunofgc | 0:8c59a494a451 | 787 | //printf("Linha comando Ir = <%s>.\r\nendOfFile = %u\r\n",comandoIr,endOfFile); |
brunofgc | 0:8c59a494a451 | 788 | }while((strstr(comandoIr,indexBusca)==NULL)&&(endOfFile==0)); |
brunofgc | 0:8c59a494a451 | 789 | sdCard::fechaArquivo(&sdCard::devices); |
brunofgc | 0:8c59a494a451 | 790 | |
brunofgc | 0:8c59a494a451 | 791 | //Vê se deu tudo certo, se não encontrou, retorna false |
brunofgc | 0:8c59a494a451 | 792 | if(!endOfFile){ |
brunofgc | 0:8c59a494a451 | 793 | //Encontrado o comando, vou desempacotar ele. |
brunofgc | 0:8c59a494a451 | 794 | strtok(comandoIr,","); |
brunofgc | 0:8c59a494a451 | 795 | //Neste ponto já tenho o meu comando pronto para ser executado dentro de comandoIr; |
brunofgc | 0:8c59a494a451 | 796 | //printf("\r\n\r\n\r\nEstou enviando o comando %s de dentro do schedule.\r\n\r\n\r\n",strtok(NULL,"S")); |
brunofgc | 0:8c59a494a451 | 797 | deserializaPacoteIR(strtok(NULL,"S")); |
brunofgc | 19:d52176ff683d | 798 | enviaComandoIR(schedules[index].param1,schedules[index].param2); |
brunofgc | 0:8c59a494a451 | 799 | } |
brunofgc | 0:8c59a494a451 | 800 | }else{ |
brunofgc | 0:8c59a494a451 | 801 | return false; |
brunofgc | 0:8c59a494a451 | 802 | } |
brunofgc | 0:8c59a494a451 | 803 | //printf("\r\n===================DEBUG(Schedule)===================\r\n"); |
brunofgc | 0:8c59a494a451 | 804 | break; |
brunofgc | 0:8c59a494a451 | 805 | } |
brunofgc | 0:8c59a494a451 | 806 | return true; |
brunofgc | 0:8c59a494a451 | 807 | } |
brunofgc | 0:8c59a494a451 | 808 | */ |
brunofgc | 0:8c59a494a451 | 809 | /* |
brunofgc | 19:d52176ff683d | 810 | uint8_t execActAlarm(uint32_t index){ |
brunofgc | 19:d52176ff683d | 811 | switch(alarms[index].actType){ |
brunofgc | 0:8c59a494a451 | 812 | case modBusType_float: |
brunofgc | 0:8c59a494a451 | 813 | float floatValueToWrite; |
brunofgc | 0:8c59a494a451 | 814 | //writeFloat(uint8_t,uint16_t,uint8_t,float*); |
brunofgc | 19:d52176ff683d | 815 | floatToBin(0,&floatValueToWrite,&alarms[index].actValue[0]); |
brunofgc | 0:8c59a494a451 | 816 | modBusMaster1::writeFloat( |
brunofgc | 19:d52176ff683d | 817 | alarms[index].addrModbusWrite, |
brunofgc | 19:d52176ff683d | 818 | alarms[index].funcModbusWrite, |
brunofgc | 19:d52176ff683d | 819 | alarms[index].regModbusWrite, |
brunofgc | 0:8c59a494a451 | 820 | &floatValueToWrite |
brunofgc | 0:8c59a494a451 | 821 | ); |
brunofgc | 0:8c59a494a451 | 822 | break; |
brunofgc | 0:8c59a494a451 | 823 | case modBusType_uint32_t: |
brunofgc | 0:8c59a494a451 | 824 | uint32_t uint32ValueToWrite; |
brunofgc | 19:d52176ff683d | 825 | uint32_t_ToBin(0,&uint32ValueToWrite,&alarms[index].actValue[0]); |
brunofgc | 0:8c59a494a451 | 826 | modBusMaster1::writeRegister32BIT( |
brunofgc | 19:d52176ff683d | 827 | alarms[index].addrModbusWrite, |
brunofgc | 19:d52176ff683d | 828 | alarms[index].funcModbusWrite, |
brunofgc | 19:d52176ff683d | 829 | alarms[index].regModbusWrite, |
brunofgc | 0:8c59a494a451 | 830 | &uint32ValueToWrite |
brunofgc | 0:8c59a494a451 | 831 | ); |
brunofgc | 0:8c59a494a451 | 832 | break; |
brunofgc | 0:8c59a494a451 | 833 | case modBusType_uint16_t: |
brunofgc | 0:8c59a494a451 | 834 | uint16_t uint16ValueToWrite; |
brunofgc | 19:d52176ff683d | 835 | uint16_t_ToBin(0,&uint16ValueToWrite,&alarms[index].actValue[0]); |
brunofgc | 0:8c59a494a451 | 836 | modBusMaster1::writeRegister16BIT( |
brunofgc | 19:d52176ff683d | 837 | alarms[index].addrModbusWrite, |
brunofgc | 19:d52176ff683d | 838 | alarms[index].funcModbusWrite, |
brunofgc | 19:d52176ff683d | 839 | alarms[index].regModbusWrite, |
brunofgc | 0:8c59a494a451 | 840 | &uint16ValueToWrite |
brunofgc | 0:8c59a494a451 | 841 | ); |
brunofgc | 0:8c59a494a451 | 842 | break; |
brunofgc | 0:8c59a494a451 | 843 | case modBusType_bit: |
brunofgc | 0:8c59a494a451 | 844 | bool boolValueToWrite; |
brunofgc | 19:d52176ff683d | 845 | boolValueToWrite = (alarms[index].actValue[0] != 0); |
brunofgc | 0:8c59a494a451 | 846 | modBusMaster1::writeSingleCoil( |
brunofgc | 19:d52176ff683d | 847 | alarms[index].addrModbusWrite, |
brunofgc | 19:d52176ff683d | 848 | alarms[index].regModbusWrite, |
brunofgc | 0:8c59a494a451 | 849 | boolValueToWrite |
brunofgc | 0:8c59a494a451 | 850 | ); |
brunofgc | 0:8c59a494a451 | 851 | break; |
brunofgc | 0:8c59a494a451 | 852 | } |
brunofgc | 0:8c59a494a451 | 853 | return true; |
brunofgc | 0:8c59a494a451 | 854 | } |
brunofgc | 0:8c59a494a451 | 855 | */ |
brunofgc | 0:8c59a494a451 | 856 | |
brunofgc | 19:d52176ff683d | 857 | void setReading(char *linha) |
brunofgc | 0:8c59a494a451 | 858 | { |
brunofgc | 0:8c59a494a451 | 859 | uint8_t addr=0; |
brunofgc | 0:8c59a494a451 | 860 | uint8_t func=0; |
brunofgc | 0:8c59a494a451 | 861 | uint16_t reg=0; |
brunofgc | 0:8c59a494a451 | 862 | uint8_t numRegs=0; |
brunofgc | 0:8c59a494a451 | 863 | char *pChar; |
brunofgc | 0:8c59a494a451 | 864 | bool inputData = false; |
brunofgc | 0:8c59a494a451 | 865 | |
brunofgc | 0:8c59a494a451 | 866 | //printf("Linha <%s>.\n",linha); |
brunofgc | 0:8c59a494a451 | 867 | if(strstr(linha,"readingsSet")) { |
brunofgc | 0:8c59a494a451 | 868 | return; |
brunofgc | 0:8c59a494a451 | 869 | } |
brunofgc | 0:8c59a494a451 | 870 | |
brunofgc | 19:d52176ff683d | 871 | numReadings++; |
brunofgc | 0:8c59a494a451 | 872 | |
brunofgc | 0:8c59a494a451 | 873 | if(strstr(linha,"float,")) { |
brunofgc | 19:d52176ff683d | 874 | readings[numReadings-1].type=modBusType_float; |
brunofgc | 0:8c59a494a451 | 875 | inputData = true; |
brunofgc | 0:8c59a494a451 | 876 | } |
brunofgc | 0:8c59a494a451 | 877 | |
brunofgc | 18:66fa6fcba212 | 878 | if(strstr(linha,"int32_t,")) { |
brunofgc | 19:d52176ff683d | 879 | readings[numReadings-1].type=modBusType_int32_t; |
brunofgc | 18:66fa6fcba212 | 880 | inputData = true; |
brunofgc | 18:66fa6fcba212 | 881 | } |
brunofgc | 18:66fa6fcba212 | 882 | |
brunofgc | 18:66fa6fcba212 | 883 | if(strstr(linha,"int16_t,")) { |
brunofgc | 19:d52176ff683d | 884 | readings[numReadings-1].type=modBusType_int16_t; |
brunofgc | 18:66fa6fcba212 | 885 | inputData = true; |
brunofgc | 18:66fa6fcba212 | 886 | } |
brunofgc | 18:66fa6fcba212 | 887 | |
brunofgc | 0:8c59a494a451 | 888 | if(strstr(linha,"uint32_t,")) { |
brunofgc | 19:d52176ff683d | 889 | readings[numReadings-1].type=modBusType_uint32_t; |
brunofgc | 0:8c59a494a451 | 890 | inputData = true; |
brunofgc | 0:8c59a494a451 | 891 | } |
brunofgc | 0:8c59a494a451 | 892 | |
brunofgc | 0:8c59a494a451 | 893 | if(strstr(linha,"uint16_t,")) { |
brunofgc | 19:d52176ff683d | 894 | readings[numReadings-1].type=modBusType_uint16_t; |
brunofgc | 0:8c59a494a451 | 895 | inputData = true; |
brunofgc | 17:c046e4b07ded | 896 | } |
brunofgc | 17:c046e4b07ded | 897 | |
brunofgc | 0:8c59a494a451 | 898 | if(strstr(linha,"uint8_t,")) { |
brunofgc | 19:d52176ff683d | 899 | readings[numReadings-1].type=modBusType_uint8_t; |
brunofgc | 0:8c59a494a451 | 900 | inputData = true; |
brunofgc | 0:8c59a494a451 | 901 | } |
brunofgc | 0:8c59a494a451 | 902 | |
brunofgc | 0:8c59a494a451 | 903 | if(strstr(linha,"bit,")) { |
brunofgc | 19:d52176ff683d | 904 | readings[numReadings-1].type=modBusType_bit; |
brunofgc | 0:8c59a494a451 | 905 | inputData = true; |
brunofgc | 0:8c59a494a451 | 906 | } |
brunofgc | 0:8c59a494a451 | 907 | |
brunofgc | 0:8c59a494a451 | 908 | if(inputData){ |
brunofgc | 0:8c59a494a451 | 909 | pChar = strtok(linha,","); |
brunofgc | 0:8c59a494a451 | 910 | |
brunofgc | 0:8c59a494a451 | 911 | pChar = strtok(NULL,","); |
brunofgc | 0:8c59a494a451 | 912 | addr = atoi(pChar); |
brunofgc | 0:8c59a494a451 | 913 | |
brunofgc | 0:8c59a494a451 | 914 | pChar = strtok(NULL,","); |
brunofgc | 0:8c59a494a451 | 915 | func = atoi(pChar); |
brunofgc | 0:8c59a494a451 | 916 | |
brunofgc | 0:8c59a494a451 | 917 | pChar = strtok(NULL,","); |
brunofgc | 0:8c59a494a451 | 918 | reg = atoi(pChar); |
brunofgc | 0:8c59a494a451 | 919 | |
brunofgc | 0:8c59a494a451 | 920 | pChar = strtok(NULL,","); |
brunofgc | 0:8c59a494a451 | 921 | numRegs = atoi(pChar); |
brunofgc | 0:8c59a494a451 | 922 | |
brunofgc | 19:d52176ff683d | 923 | readings[numReadings-1].addr=addr; |
brunofgc | 19:d52176ff683d | 924 | readings[numReadings-1].func=func; |
brunofgc | 19:d52176ff683d | 925 | readings[numReadings-1].reg=reg; |
brunofgc | 19:d52176ff683d | 926 | readings[numReadings-1].numRegs=numRegs; |
brunofgc | 0:8c59a494a451 | 927 | } |
brunofgc | 0:8c59a494a451 | 928 | |
brunofgc | 0:8c59a494a451 | 929 | } |
brunofgc | 0:8c59a494a451 | 930 | |
brunofgc | 19:d52176ff683d | 931 | void setAlarm(char *linha) |
brunofgc | 0:8c59a494a451 | 932 | { |
brunofgc | 0:8c59a494a451 | 933 | float floatVar; |
brunofgc | 0:8c59a494a451 | 934 | uint32_t aux32_t; |
brunofgc | 0:8c59a494a451 | 935 | uint16_t aux16_t; |
brunofgc | 0:8c59a494a451 | 936 | char *pChar; |
brunofgc | 0:8c59a494a451 | 937 | |
brunofgc | 0:8c59a494a451 | 938 | if(strstr(linha,"alarmSet")) { |
brunofgc | 2:ca3723da6668 | 939 | //Inicialização de contadores de alarme |
brunofgc | 2:ca3723da6668 | 940 | //É necessário inicializar estes dados para quando a máquina de alarmes rodar ter um inicio correto. |
brunofgc | 19:d52176ff683d | 941 | alarms[alarmes].secAlarm=0; |
brunofgc | 19:d52176ff683d | 942 | alarms[alarmes].idAct=0; |
brunofgc | 19:d52176ff683d | 943 | alarms[alarmes].on=0; |
brunofgc | 19:d52176ff683d | 944 | alarms[alarmes].alarmFound = false; |
brunofgc | 0:8c59a494a451 | 945 | //Inicialização de contadores de alarme |
brunofgc | 19:d52176ff683d | 946 | alarmes++; |
brunofgc | 18:66fa6fcba212 | 947 | return; |
brunofgc | 0:8c59a494a451 | 948 | } |
brunofgc | 0:8c59a494a451 | 949 | |
brunofgc | 5:8efd609dea7d | 950 | if(strstr(linha,"idAlarm:")){ |
brunofgc | 0:8c59a494a451 | 951 | strtok(linha,":"); |
brunofgc | 19:d52176ff683d | 952 | alarms[alarmes-1].id = atoi(strtok(NULL,"\r\n")); |
brunofgc | 18:66fa6fcba212 | 953 | return; |
brunofgc | 0:8c59a494a451 | 954 | } |
brunofgc | 0:8c59a494a451 | 955 | |
brunofgc | 5:8efd609dea7d | 956 | if(strstr(linha,"seconds:")) { |
brunofgc | 0:8c59a494a451 | 957 | strtok(linha,":"); |
brunofgc | 0:8c59a494a451 | 958 | pChar = strtok(NULL,"\r\n"); |
brunofgc | 19:d52176ff683d | 959 | alarms[alarmes-1].seconds = atoi(pChar); |
brunofgc | 18:66fa6fcba212 | 960 | return; |
brunofgc | 0:8c59a494a451 | 961 | } |
brunofgc | 0:8c59a494a451 | 962 | |
brunofgc | 5:8efd609dea7d | 963 | if(strstr(linha,"on:")) { |
brunofgc | 5:8efd609dea7d | 964 | strtok(linha,":"); |
brunofgc | 5:8efd609dea7d | 965 | pChar = strtok(NULL,"\r\n"); |
brunofgc | 19:d52176ff683d | 966 | alarms[alarmes-1].on = atoi(pChar); |
brunofgc | 18:66fa6fcba212 | 967 | return; |
brunofgc | 5:8efd609dea7d | 968 | } |
brunofgc | 5:8efd609dea7d | 969 | |
brunofgc | 5:8efd609dea7d | 970 | if(strstr(linha,"idAct:")) { |
brunofgc | 0:8c59a494a451 | 971 | strtok(linha,":"); |
brunofgc | 19:d52176ff683d | 972 | alarms[alarmes-1].idAct = atoi(strtok(NULL,"")); |
brunofgc | 0:8c59a494a451 | 973 | return; |
brunofgc | 5:8efd609dea7d | 974 | } |
brunofgc | 5:8efd609dea7d | 975 | |
brunofgc | 5:8efd609dea7d | 976 | if(strstr(linha,"bit,")){ |
brunofgc | 19:d52176ff683d | 977 | alarms[alarmes-1].type=modBusType_bit; |
brunofgc | 5:8efd609dea7d | 978 | |
brunofgc | 0:8c59a494a451 | 979 | pChar = strtok(linha,","); |
brunofgc | 0:8c59a494a451 | 980 | |
brunofgc | 0:8c59a494a451 | 981 | //Parametro1 |
brunofgc | 0:8c59a494a451 | 982 | pChar = strtok(NULL,","); |
brunofgc | 19:d52176ff683d | 983 | alarms[alarmes-1].addrModbusRead = atoi(pChar); |
brunofgc | 0:8c59a494a451 | 984 | |
brunofgc | 0:8c59a494a451 | 985 | //Parametro2 |
brunofgc | 0:8c59a494a451 | 986 | pChar = strtok(NULL,","); |
brunofgc | 19:d52176ff683d | 987 | alarms[alarmes-1].funcModbusRead = atoi(pChar); |
brunofgc | 0:8c59a494a451 | 988 | |
brunofgc | 0:8c59a494a451 | 989 | //Parametro3 |
brunofgc | 0:8c59a494a451 | 990 | pChar = strtok(NULL,","); |
brunofgc | 19:d52176ff683d | 991 | alarms[alarmes-1].regModbusRead = atoi(pChar); |
brunofgc | 0:8c59a494a451 | 992 | |
brunofgc | 0:8c59a494a451 | 993 | //Parametro4 |
brunofgc | 0:8c59a494a451 | 994 | pChar = strtok(NULL,","); |
brunofgc | 19:d52176ff683d | 995 | alarms[alarmes-1].max = (atoi(pChar) != 0); //Qualquer valor diferente de 0 é um |
brunofgc | 0:8c59a494a451 | 996 | |
brunofgc | 0:8c59a494a451 | 997 | //Parametro5 |
brunofgc | 0:8c59a494a451 | 998 | pChar = strtok(NULL,","); |
brunofgc | 19:d52176ff683d | 999 | alarms[alarmes-1].value[0]= (atoi(pChar) != 0); //Qualquer valor diferente de 0 é um |
brunofgc | 18:66fa6fcba212 | 1000 | return; |
brunofgc | 0:8c59a494a451 | 1001 | } |
brunofgc | 0:8c59a494a451 | 1002 | |
brunofgc | 0:8c59a494a451 | 1003 | if(strstr(linha,"float,")) { |
brunofgc | 19:d52176ff683d | 1004 | alarms[alarmes-1].type=modBusType_float; |
brunofgc | 0:8c59a494a451 | 1005 | strtok(linha,","); |
brunofgc | 0:8c59a494a451 | 1006 | |
brunofgc | 0:8c59a494a451 | 1007 | //Parametro 1; |
brunofgc | 0:8c59a494a451 | 1008 | pChar = strtok(NULL,","); |
brunofgc | 19:d52176ff683d | 1009 | alarms[alarmes-1].addrModbusRead = atoi(pChar); |
brunofgc | 0:8c59a494a451 | 1010 | |
brunofgc | 0:8c59a494a451 | 1011 | //Parametro 2; |
brunofgc | 0:8c59a494a451 | 1012 | pChar = strtok(NULL,","); |
brunofgc | 19:d52176ff683d | 1013 | alarms[alarmes-1].funcModbusRead = atoi(pChar); |
brunofgc | 0:8c59a494a451 | 1014 | |
brunofgc | 0:8c59a494a451 | 1015 | //Parametro 3; |
brunofgc | 0:8c59a494a451 | 1016 | pChar = strtok(NULL,","); |
brunofgc | 19:d52176ff683d | 1017 | alarms[alarmes-1].regModbusRead = atoi(pChar); |
brunofgc | 0:8c59a494a451 | 1018 | |
brunofgc | 0:8c59a494a451 | 1019 | //Parametro 4; |
brunofgc | 0:8c59a494a451 | 1020 | pChar = strtok(NULL,","); |
brunofgc | 19:d52176ff683d | 1021 | alarms[alarmes-1].max = (atoi(pChar) != 0); //Qualquer valor diferente de 0 é um |
brunofgc | 0:8c59a494a451 | 1022 | |
brunofgc | 0:8c59a494a451 | 1023 | //Parametro 5; |
brunofgc | 0:8c59a494a451 | 1024 | pChar = strtok(NULL,"\r\n"); |
brunofgc | 0:8c59a494a451 | 1025 | //floatVar = diversos::stringToFloat(pChar,100); |
brunofgc | 0:8c59a494a451 | 1026 | floatVar = atof(pChar); |
brunofgc | 5:8efd609dea7d | 1027 | |
brunofgc | 19:d52176ff683d | 1028 | floatToBin(1,&floatVar,&alarms[alarmes-1].value[0]); |
brunofgc | 18:66fa6fcba212 | 1029 | return; |
brunofgc | 0:8c59a494a451 | 1030 | } |
brunofgc | 5:8efd609dea7d | 1031 | |
brunofgc | 0:8c59a494a451 | 1032 | if(strstr(linha,"uint32_t,")) { |
brunofgc | 19:d52176ff683d | 1033 | alarms[alarmes-1].type=modBusType_uint32_t; |
brunofgc | 0:8c59a494a451 | 1034 | //sscanf(linha,"max:uint32_t,%lu,%lu,%lu,%lu",&aux1,&aux2,&aux3,&aux4); |
brunofgc | 0:8c59a494a451 | 1035 | strtok(linha,","); |
brunofgc | 0:8c59a494a451 | 1036 | |
brunofgc | 0:8c59a494a451 | 1037 | //parametro1 |
brunofgc | 5:8efd609dea7d | 1038 | pChar = strtok(NULL,","); |
brunofgc | 19:d52176ff683d | 1039 | alarms[alarmes-1].addrModbusRead = atoi(pChar); |
brunofgc | 0:8c59a494a451 | 1040 | |
brunofgc | 0:8c59a494a451 | 1041 | //parametro2 |
brunofgc | 5:8efd609dea7d | 1042 | pChar = strtok(NULL,","); |
brunofgc | 19:d52176ff683d | 1043 | alarms[alarmes-1].funcModbusRead = atoi(pChar); |
brunofgc | 0:8c59a494a451 | 1044 | |
brunofgc | 0:8c59a494a451 | 1045 | //parametro3 |
brunofgc | 5:8efd609dea7d | 1046 | pChar = strtok(NULL,","); |
brunofgc | 19:d52176ff683d | 1047 | alarms[alarmes-1].regModbusRead = atoi(pChar); |
brunofgc | 0:8c59a494a451 | 1048 | |
brunofgc | 0:8c59a494a451 | 1049 | //Parametro 4; |
brunofgc | 0:8c59a494a451 | 1050 | pChar = strtok(NULL,","); |
brunofgc | 19:d52176ff683d | 1051 | alarms[alarmes-1].max = (atoi(pChar) != 0); //Qualquer valor diferente de 0 é um |
brunofgc | 0:8c59a494a451 | 1052 | |
brunofgc | 0:8c59a494a451 | 1053 | //parametro5 |
brunofgc | 5:8efd609dea7d | 1054 | pChar = strtok(NULL,"\r\n"); |
brunofgc | 0:8c59a494a451 | 1055 | aux32_t = atoi(pChar); |
brunofgc | 5:8efd609dea7d | 1056 | |
brunofgc | 19:d52176ff683d | 1057 | uint32_t_ToBin(1,&aux32_t,&alarms[alarmes-1].value[0]); |
brunofgc | 18:66fa6fcba212 | 1058 | return; |
brunofgc | 0:8c59a494a451 | 1059 | } |
brunofgc | 0:8c59a494a451 | 1060 | |
brunofgc | 0:8c59a494a451 | 1061 | |
brunofgc | 0:8c59a494a451 | 1062 | |
brunofgc | 0:8c59a494a451 | 1063 | if(strstr(linha,"uint16_t,")) { |
brunofgc | 19:d52176ff683d | 1064 | alarms[alarmes-1].type=modBusType_uint16_t; |
brunofgc | 0:8c59a494a451 | 1065 | strtok(linha,","); |
brunofgc | 0:8c59a494a451 | 1066 | |
brunofgc | 0:8c59a494a451 | 1067 | //parametro1 |
brunofgc | 0:8c59a494a451 | 1068 | pChar = strtok(NULL,","); |
brunofgc | 19:d52176ff683d | 1069 | alarms[alarmes-1].addrModbusRead = atoi(pChar); |
brunofgc | 0:8c59a494a451 | 1070 | |
brunofgc | 0:8c59a494a451 | 1071 | //parametro2 |
brunofgc | 5:8efd609dea7d | 1072 | pChar = strtok(NULL,","); |
brunofgc | 19:d52176ff683d | 1073 | alarms[alarmes-1].funcModbusRead = atoi(pChar); |
brunofgc | 0:8c59a494a451 | 1074 | |
brunofgc | 0:8c59a494a451 | 1075 | //parametro3 |
brunofgc | 5:8efd609dea7d | 1076 | pChar = strtok(NULL,","); |
brunofgc | 19:d52176ff683d | 1077 | alarms[alarmes-1].regModbusRead = atoi(pChar); |
brunofgc | 0:8c59a494a451 | 1078 | |
brunofgc | 0:8c59a494a451 | 1079 | //Parametro 4; |
brunofgc | 0:8c59a494a451 | 1080 | pChar = strtok(NULL,","); |
brunofgc | 19:d52176ff683d | 1081 | alarms[alarmes-1].max = (atoi(pChar) != 0); //Qualquer valor diferente de 0 é um |
brunofgc | 0:8c59a494a451 | 1082 | |
brunofgc | 0:8c59a494a451 | 1083 | //parametro5 |
brunofgc | 5:8efd609dea7d | 1084 | pChar = strtok(NULL,"\r\n"); |
brunofgc | 0:8c59a494a451 | 1085 | aux16_t = atoi(pChar); |
brunofgc | 5:8efd609dea7d | 1086 | |
brunofgc | 19:d52176ff683d | 1087 | uint16_t_ToBin(1,&aux16_t,&alarms[alarmes-1].value[0]); |
brunofgc | 18:66fa6fcba212 | 1088 | return; |
brunofgc | 5:8efd609dea7d | 1089 | } |
brunofgc | 17:c046e4b07ded | 1090 | |
brunofgc | 17:c046e4b07ded | 1091 | if(strstr(linha,"int32_t,")) { |
brunofgc | 19:d52176ff683d | 1092 | alarms[alarmes-1].type=modBusType_int32_t; |
brunofgc | 17:c046e4b07ded | 1093 | //sscanf(linha,"max:uint32_t,%lu,%lu,%lu,%lu",&aux1,&aux2,&aux3,&aux4); |
brunofgc | 17:c046e4b07ded | 1094 | strtok(linha,","); |
brunofgc | 17:c046e4b07ded | 1095 | |
brunofgc | 17:c046e4b07ded | 1096 | //parametro1 |
brunofgc | 17:c046e4b07ded | 1097 | pChar = strtok(NULL,","); |
brunofgc | 19:d52176ff683d | 1098 | alarms[alarmes-1].addrModbusRead = atoi(pChar); |
brunofgc | 17:c046e4b07ded | 1099 | |
brunofgc | 17:c046e4b07ded | 1100 | //parametro2 |
brunofgc | 17:c046e4b07ded | 1101 | pChar = strtok(NULL,","); |
brunofgc | 19:d52176ff683d | 1102 | alarms[alarmes-1].funcModbusRead = atoi(pChar); |
brunofgc | 17:c046e4b07ded | 1103 | |
brunofgc | 17:c046e4b07ded | 1104 | //parametro3 |
brunofgc | 17:c046e4b07ded | 1105 | pChar = strtok(NULL,","); |
brunofgc | 19:d52176ff683d | 1106 | alarms[alarmes-1].regModbusRead = atol(pChar); |
brunofgc | 17:c046e4b07ded | 1107 | |
brunofgc | 17:c046e4b07ded | 1108 | //Parametro 4; |
brunofgc | 17:c046e4b07ded | 1109 | pChar = strtok(NULL,","); |
brunofgc | 19:d52176ff683d | 1110 | alarms[alarmes-1].max = (atoi(pChar) != 0); //Qualquer valor diferente de 0 é um |
brunofgc | 17:c046e4b07ded | 1111 | |
brunofgc | 17:c046e4b07ded | 1112 | //parametro5 |
brunofgc | 17:c046e4b07ded | 1113 | pChar = strtok(NULL,"\r\n"); |
brunofgc | 17:c046e4b07ded | 1114 | aux32_t = atol(pChar); |
brunofgc | 17:c046e4b07ded | 1115 | |
brunofgc | 19:d52176ff683d | 1116 | uint32_t_ToBin(1,&aux32_t,&alarms[alarmes-1].value[0]); |
brunofgc | 18:66fa6fcba212 | 1117 | return; |
brunofgc | 17:c046e4b07ded | 1118 | } |
brunofgc | 17:c046e4b07ded | 1119 | |
brunofgc | 17:c046e4b07ded | 1120 | |
brunofgc | 17:c046e4b07ded | 1121 | |
brunofgc | 17:c046e4b07ded | 1122 | if(strstr(linha,"int16_t,")) { |
brunofgc | 19:d52176ff683d | 1123 | alarms[alarmes-1].type=modBusType_int16_t; |
brunofgc | 17:c046e4b07ded | 1124 | strtok(linha,","); |
brunofgc | 17:c046e4b07ded | 1125 | |
brunofgc | 17:c046e4b07ded | 1126 | //parametro1 |
brunofgc | 17:c046e4b07ded | 1127 | pChar = strtok(NULL,","); |
brunofgc | 19:d52176ff683d | 1128 | alarms[alarmes-1].addrModbusRead = atoi(pChar); |
brunofgc | 17:c046e4b07ded | 1129 | |
brunofgc | 17:c046e4b07ded | 1130 | //parametro2 |
brunofgc | 17:c046e4b07ded | 1131 | pChar = strtok(NULL,","); |
brunofgc | 19:d52176ff683d | 1132 | alarms[alarmes-1].funcModbusRead = atoi(pChar); |
brunofgc | 17:c046e4b07ded | 1133 | |
brunofgc | 17:c046e4b07ded | 1134 | //parametro3 |
brunofgc | 17:c046e4b07ded | 1135 | pChar = strtok(NULL,","); |
brunofgc | 19:d52176ff683d | 1136 | alarms[alarmes-1].regModbusRead = atoi(pChar); |
brunofgc | 17:c046e4b07ded | 1137 | |
brunofgc | 17:c046e4b07ded | 1138 | //Parametro 4; |
brunofgc | 17:c046e4b07ded | 1139 | pChar = strtok(NULL,","); |
brunofgc | 19:d52176ff683d | 1140 | alarms[alarmes-1].max = (atoi(pChar) != 0); //Qualquer valor diferente de 0 é um |
brunofgc | 17:c046e4b07ded | 1141 | |
brunofgc | 17:c046e4b07ded | 1142 | //parametro5 |
brunofgc | 17:c046e4b07ded | 1143 | pChar = strtok(NULL,"\r\n"); |
brunofgc | 17:c046e4b07ded | 1144 | aux16_t = atoi(pChar); |
brunofgc | 17:c046e4b07ded | 1145 | |
brunofgc | 19:d52176ff683d | 1146 | uint16_t_ToBin(1,&aux16_t,&alarms[alarmes-1].value[0]); |
brunofgc | 18:66fa6fcba212 | 1147 | return; |
brunofgc | 17:c046e4b07ded | 1148 | } |
brunofgc | 0:8c59a494a451 | 1149 | } |
brunofgc | 0:8c59a494a451 | 1150 | |
brunofgc | 19:d52176ff683d | 1151 | void setSchedule(char *linha) |
brunofgc | 0:8c59a494a451 | 1152 | { |
brunofgc | 0:8c59a494a451 | 1153 | //float floatVar; |
brunofgc | 0:8c59a494a451 | 1154 | //uint32_t aux32_t; |
brunofgc | 0:8c59a494a451 | 1155 | //uint16_t aux16_t; |
brunofgc | 5:8efd609dea7d | 1156 | char *pChar; |
brunofgc | 5:8efd609dea7d | 1157 | |
brunofgc | 2:ca3723da6668 | 1158 | if(strstr(linha,"scheduleSet")) { |
brunofgc | 0:8c59a494a451 | 1159 | //Inicialização de contadores de schedules |
brunofgc | 2:ca3723da6668 | 1160 | //É necessário inicializar estes dados para quando a máquina de schedules rodar ter um inicio correto. |
brunofgc | 19:d52176ff683d | 1161 | schedules[numSchedules].actSent = false; |
brunofgc | 2:ca3723da6668 | 1162 | //Inicialização de contadores de schedules |
brunofgc | 19:d52176ff683d | 1163 | numSchedules++; |
brunofgc | 0:8c59a494a451 | 1164 | } |
brunofgc | 0:8c59a494a451 | 1165 | |
brunofgc | 5:8efd609dea7d | 1166 | if(strstr(linha,"idSchedule:")) { |
brunofgc | 0:8c59a494a451 | 1167 | strtok(linha,":"); |
brunofgc | 5:8efd609dea7d | 1168 | pChar = strtok(NULL,""); |
brunofgc | 19:d52176ff683d | 1169 | schedules[numSchedules-1].id = atoi(pChar); |
brunofgc | 0:8c59a494a451 | 1170 | } |
brunofgc | 0:8c59a494a451 | 1171 | |
brunofgc | 5:8efd609dea7d | 1172 | if(strstr(linha,"dayTime:")) { |
brunofgc | 0:8c59a494a451 | 1173 | strtok(linha,":"); |
brunofgc | 0:8c59a494a451 | 1174 | pChar = strtok(NULL,","); |
brunofgc | 19:d52176ff683d | 1175 | schedules[numSchedules-1].weekday = atoi(pChar); |
brunofgc | 5:8efd609dea7d | 1176 | pChar = strtok(NULL,""); |
brunofgc | 19:d52176ff683d | 1177 | schedules[numSchedules-1].minute = atoi(pChar); |
brunofgc | 0:8c59a494a451 | 1178 | } |
brunofgc | 5:8efd609dea7d | 1179 | |
brunofgc | 5:8efd609dea7d | 1180 | if(strstr(linha,"idAct:")) { |
brunofgc | 0:8c59a494a451 | 1181 | strtok(linha,":"); |
brunofgc | 0:8c59a494a451 | 1182 | pChar = strtok(NULL,""); |
brunofgc | 19:d52176ff683d | 1183 | schedules[numSchedules-1].idAct = atoi(pChar); |
brunofgc | 5:8efd609dea7d | 1184 | } |
brunofgc | 5:8efd609dea7d | 1185 | /*pc.printf("Debugando erro em scheduleSet.\r\n"); |
brunofgc | 5:8efd609dea7d | 1186 | pc.printf("Linha <%s>\r\n",linha); |
brunofgc | 19:d52176ff683d | 1187 | pc.printf("actSent = %lu",schedules[numSchedules-1].actSent); |
brunofgc | 19:d52176ff683d | 1188 | pc.printf("idSchedule = %lu",schedules[numSchedules-1].id); |
brunofgc | 19:d52176ff683d | 1189 | pc.printf("dayTime = %lu",schedules[numSchedules-1].weekday); |
brunofgc | 19:d52176ff683d | 1190 | pc.printf("idAct = %lu",schedules[numSchedules-1].idAct); |
brunofgc | 5:8efd609dea7d | 1191 | pc.printf("Debugando erro em scheduleSet.\r\n");*/ |
brunofgc | 0:8c59a494a451 | 1192 | } |
brunofgc | 0:8c59a494a451 | 1193 | |
brunofgc | 19:d52176ff683d | 1194 | void setScheduleException(char *linha) |
brunofgc | 4:3f92979d1ffb | 1195 | { |
brunofgc | 4:3f92979d1ffb | 1196 | //float floatVar; |
brunofgc | 4:3f92979d1ffb | 1197 | //uint32_t aux32_t; |
brunofgc | 4:3f92979d1ffb | 1198 | //uint16_t aux16_t; |
brunofgc | 5:8efd609dea7d | 1199 | char *pChar; |
brunofgc | 5:8efd609dea7d | 1200 | if(strstr(linha,"scheduleExceptionSet")) { |
brunofgc | 4:3f92979d1ffb | 1201 | //Inicialização de contadores de schedulesExceptions |
brunofgc | 19:d52176ff683d | 1202 | numScheduleExceptions++; |
brunofgc | 4:3f92979d1ffb | 1203 | } |
brunofgc | 4:3f92979d1ffb | 1204 | |
brunofgc | 5:8efd609dea7d | 1205 | if(strstr(linha,"idSchedule:")) { |
brunofgc | 4:3f92979d1ffb | 1206 | strtok(linha,":"); |
brunofgc | 19:d52176ff683d | 1207 | scheduleExceptions[numScheduleExceptions-1].id_schedule = atoi(strtok(NULL,"\r\n")); |
brunofgc | 4:3f92979d1ffb | 1208 | } |
brunofgc | 4:3f92979d1ffb | 1209 | |
brunofgc | 5:8efd609dea7d | 1210 | if(strstr(linha,"timestamp:")) { |
brunofgc | 4:3f92979d1ffb | 1211 | strtok(linha,":"); |
brunofgc | 4:3f92979d1ffb | 1212 | pChar = strtok(NULL,","); |
brunofgc | 19:d52176ff683d | 1213 | scheduleExceptions[numScheduleExceptions-1].timestamp = atoi(pChar); |
brunofgc | 5:8efd609dea7d | 1214 | } |
brunofgc | 4:3f92979d1ffb | 1215 | } |
brunofgc | 4:3f92979d1ffb | 1216 | |
brunofgc | 19:d52176ff683d | 1217 | /*void writeReadingsToSD(){ |
brunofgc | 0:8c59a494a451 | 1218 | //Esta função faz a inserção de todos os dados no arquivo armazenamento. |
brunofgc | 5:8efd609dea7d | 1219 | uint16_t readingIndex=0; |
brunofgc | 5:8efd609dea7d | 1220 | |
brunofgc | 0:8c59a494a451 | 1221 | float *floatBuffer; |
brunofgc | 0:8c59a494a451 | 1222 | uint32_t *uint32_tBuffer; |
brunofgc | 5:8efd609dea7d | 1223 | uint16_t *uint16_tBuffer; |
brunofgc | 5:8efd609dea7d | 1224 | bool *boolBuffer; |
brunofgc | 0:8c59a494a451 | 1225 | uint32_t seconds_uint32_t; |
brunofgc | 0:8c59a494a451 | 1226 | |
brunofgc | 0:8c59a494a451 | 1227 | //char registro[1024]; |
brunofgc | 0:8c59a494a451 | 1228 | //uint16_t indexRegistro; |
brunofgc | 0:8c59a494a451 | 1229 | |
brunofgc | 0:8c59a494a451 | 1230 | seconds_uint32_t = (uint32_t) time(NULL); |
brunofgc | 0:8c59a494a451 | 1231 | |
brunofgc | 0:8c59a494a451 | 1232 | //Inicio da string dentro do arquivo binario |
brunofgc | 8:25061210fcc9 | 1233 | sdCard::insereDadosBank("log{data:",9); |
brunofgc | 0:8c59a494a451 | 1234 | |
brunofgc | 0:8c59a494a451 | 1235 | //O timestamp é posto nos 4 primeiros bytes (segundos) |
brunofgc | 8:25061210fcc9 | 1236 | sdCard::insereDadosBank(&sdCard::armazenamento,(char *)&seconds_uint32_t,4); |
brunofgc | 0:8c59a494a451 | 1237 | |
brunofgc | 19:d52176ff683d | 1238 | for(readingIndex = 0;readingIndex < numReadings;readingIndex++){ |
brunofgc | 19:d52176ff683d | 1239 | switch(readings[readingIndex].type){ |
brunofgc | 0:8c59a494a451 | 1240 | case modBusType_float: |
brunofgc | 19:d52176ff683d | 1241 | floatBuffer = (float*) malloc(readings[readingIndex].numRegs*sizeof(float)); |
brunofgc | 0:8c59a494a451 | 1242 | modBusMaster1::readFloat( |
brunofgc | 19:d52176ff683d | 1243 | readings[readingIndex].addr, |
brunofgc | 19:d52176ff683d | 1244 | readings[readingIndex].func, |
brunofgc | 19:d52176ff683d | 1245 | readings[readingIndex].reg, |
brunofgc | 19:d52176ff683d | 1246 | readings[readingIndex].numRegs, |
brunofgc | 0:8c59a494a451 | 1247 | floatBuffer |
brunofgc | 0:8c59a494a451 | 1248 | ); |
brunofgc | 0:8c59a494a451 | 1249 | //pc.printf("Lido dentro de modBusMaster1::teste() <%f>.\n",modBusMaster1::teste()); |
brunofgc | 19:d52176ff683d | 1250 | sdCard::insereDadosBank((char *)floatBuffer,sizeof(float)*readings[readingIndex].numRegs); |
brunofgc | 0:8c59a494a451 | 1251 | free(floatBuffer); |
brunofgc | 0:8c59a494a451 | 1252 | break; |
brunofgc | 0:8c59a494a451 | 1253 | case modBusType_uint32_t: |
brunofgc | 19:d52176ff683d | 1254 | uint32_tBuffer = (uint32_t*) malloc(readings[readingIndex].numRegs*sizeof(uint32_t)); |
brunofgc | 0:8c59a494a451 | 1255 | modBusMaster1::readRegister32BIT( |
brunofgc | 19:d52176ff683d | 1256 | readings[readingIndex].addr, |
brunofgc | 19:d52176ff683d | 1257 | readings[readingIndex].func, |
brunofgc | 19:d52176ff683d | 1258 | readings[readingIndex].reg, |
brunofgc | 19:d52176ff683d | 1259 | readings[readingIndex].numRegs, |
brunofgc | 0:8c59a494a451 | 1260 | uint32_tBuffer |
brunofgc | 0:8c59a494a451 | 1261 | ); |
brunofgc | 0:8c59a494a451 | 1262 | //pc.printf("Lido dentro de modBusMaster1::teste() <%f>.\n",modBusMaster1::teste()); |
brunofgc | 19:d52176ff683d | 1263 | sdCard::insereDadosBank((char *)uint32_tBuffer,sizeof(uint32_t)*readings[readingIndex].numRegs); |
brunofgc | 0:8c59a494a451 | 1264 | free(uint32_tBuffer); |
brunofgc | 0:8c59a494a451 | 1265 | break; |
brunofgc | 0:8c59a494a451 | 1266 | |
brunofgc | 0:8c59a494a451 | 1267 | case modBusType_uint16_t: |
brunofgc | 19:d52176ff683d | 1268 | uint16_tBuffer = (uint16_t*) malloc(readings[readingIndex].numRegs*sizeof(uint16_t)); |
brunofgc | 0:8c59a494a451 | 1269 | modBusMaster1::readRegister16BIT( |
brunofgc | 19:d52176ff683d | 1270 | readings[readingIndex].addr, |
brunofgc | 19:d52176ff683d | 1271 | readings[readingIndex].func, |
brunofgc | 19:d52176ff683d | 1272 | readings[readingIndex].reg, |
brunofgc | 19:d52176ff683d | 1273 | readings[readingIndex].numRegs, |
brunofgc | 0:8c59a494a451 | 1274 | uint16_tBuffer |
brunofgc | 0:8c59a494a451 | 1275 | ); |
brunofgc | 0:8c59a494a451 | 1276 | //pc.printf("Lido dentro de modBusMaster1::teste() <%f>.\n",modBusMaster1::teste()); |
brunofgc | 19:d52176ff683d | 1277 | sdCard::insereDadosBank((char *)uint16_tBuffer,sizeof(uint16_t)*readings[readingIndex].numRegs); |
brunofgc | 0:8c59a494a451 | 1278 | free(uint16_tBuffer); |
brunofgc | 0:8c59a494a451 | 1279 | break; |
brunofgc | 0:8c59a494a451 | 1280 | |
brunofgc | 0:8c59a494a451 | 1281 | case modBusType_bit: |
brunofgc | 19:d52176ff683d | 1282 | boolBuffer = (bool*) malloc(readings[readingIndex].numRegs*sizeof(bool)); |
brunofgc | 0:8c59a494a451 | 1283 | modBusMaster1::readCoils( |
brunofgc | 19:d52176ff683d | 1284 | readings[readingIndex].addr, |
brunofgc | 19:d52176ff683d | 1285 | readings[readingIndex].reg, |
brunofgc | 19:d52176ff683d | 1286 | readings[readingIndex].numRegs, |
brunofgc | 0:8c59a494a451 | 1287 | boolBuffer |
brunofgc | 0:8c59a494a451 | 1288 | ); |
brunofgc | 0:8c59a494a451 | 1289 | //pc.printf("Lido dentro de modBusMaster1::teste() <%f>.\n",modBusMaster1::teste()); |
brunofgc | 19:d52176ff683d | 1290 | sdCard::insereDadosBank((char *)boolBuffer,sizeof(bool)*readings[readingIndex].numRegs); |
brunofgc | 0:8c59a494a451 | 1291 | free(boolBuffer); |
brunofgc | 0:8c59a494a451 | 1292 | break; |
brunofgc | 0:8c59a494a451 | 1293 | |
brunofgc | 0:8c59a494a451 | 1294 | } |
brunofgc | 0:8c59a494a451 | 1295 | } |
brunofgc | 8:25061210fcc9 | 1296 | sdCard::insereDadosBank("}log",4); |
brunofgc | 0:8c59a494a451 | 1297 | }*/ |
brunofgc | 0:8c59a494a451 | 1298 | |
brunofgc | 19:d52176ff683d | 1299 | uint8_t execAct(uint32_t index){ |
brunofgc | 0:8c59a494a451 | 1300 | //Primeiro preciso decidir que tipo de act estou lidando para tanto preciso pegar a ACT inteira. |
brunofgc | 0:8c59a494a451 | 1301 | //Busca no arquivo |
brunofgc | 0:8c59a494a451 | 1302 | //Abre arquivo |
brunofgc | 0:8c59a494a451 | 1303 | char actString[1024]; |
brunofgc | 0:8c59a494a451 | 1304 | char indexBusca[15]; |
brunofgc | 5:8efd609dea7d | 1305 | char alarmsSetString[256]; |
brunofgc | 5:8efd609dea7d | 1306 | char alarmsResetString[256]; |
brunofgc | 0:8c59a494a451 | 1307 | char *pTipoComando; |
brunofgc | 18:66fa6fcba212 | 1308 | uint8_t tipoComando=0; |
brunofgc | 0:8c59a494a451 | 1309 | bool endOfFile = false; |
brunofgc | 18:66fa6fcba212 | 1310 | uint8_t indexAlarms=0; |
brunofgc | 5:8efd609dea7d | 1311 | char *pChar; |
brunofgc | 9:0230ec4d2e68 | 1312 | bool commandExecOk = true; |
brunofgc | 12:254c32b4ece7 | 1313 | uint8_t i; |
brunofgc | 12:254c32b4ece7 | 1314 | |
brunofgc | 0:8c59a494a451 | 1315 | //Variáveis comuns; |
brunofgc | 0:8c59a494a451 | 1316 | uint8_t param1; |
brunofgc | 0:8c59a494a451 | 1317 | uint8_t param2; |
brunofgc | 0:8c59a494a451 | 1318 | uint16_t param3; |
brunofgc | 0:8c59a494a451 | 1319 | uint32_t param4; |
brunofgc | 0:8c59a494a451 | 1320 | |
brunofgc | 0:8c59a494a451 | 1321 | //printf("\r\n===================DEBUG(execAct)===================\r\n"); |
brunofgc | 5:8efd609dea7d | 1322 | sprintf(indexBusca,"idAct:%lu;",index); |
brunofgc | 5:8efd609dea7d | 1323 | pc.printf("Lido <%s>.\r\n",indexBusca); |
brunofgc | 0:8c59a494a451 | 1324 | //printf("Buscando por indexBusca<%s>.\r\n",indexBusca); |
brunofgc | 0:8c59a494a451 | 1325 | if(sdCard::abreArquivo(&sdCard::devices,"r")){ |
brunofgc | 0:8c59a494a451 | 1326 | do{ |
brunofgc | 0:8c59a494a451 | 1327 | endOfFile = feof(sdCard::devices.fp); |
brunofgc | 5:8efd609dea7d | 1328 | if(!endOfFile){fgets(actString,1024,sdCard::devices.fp);} |
brunofgc | 5:8efd609dea7d | 1329 | }while((strstr(actString,"actList")==NULL)&&(endOfFile==0)); |
brunofgc | 6:f20c0e094294 | 1330 | pc.printf("Achei o actList.\r\n"); |
brunofgc | 5:8efd609dea7d | 1331 | do{ |
brunofgc | 5:8efd609dea7d | 1332 | endOfFile = feof(sdCard::devices.fp); |
brunofgc | 0:8c59a494a451 | 1333 | if(!endOfFile){fgets(actString,1024,sdCard::devices.fp);} |
brunofgc | 5:8efd609dea7d | 1334 | //printf("Linha ACT = <%s>.\r\nendOfFile = %u\r\n",actString,endOfFile); |
brunofgc | 5:8efd609dea7d | 1335 | }while((strstr(actString,indexBusca)==NULL)&&(endOfFile==0)); |
brunofgc | 0:8c59a494a451 | 1336 | sdCard::fechaArquivo(&sdCard::devices); |
brunofgc | 0:8c59a494a451 | 1337 | |
brunofgc | 0:8c59a494a451 | 1338 | //Vê se deu tudo certo, se não encontrou, retorna false |
brunofgc | 0:8c59a494a451 | 1339 | if(endOfFile){ |
brunofgc | 0:8c59a494a451 | 1340 | return false; |
brunofgc | 0:8c59a494a451 | 1341 | } |
brunofgc | 0:8c59a494a451 | 1342 | //Tudo correndo bem. |
brunofgc | 0:8c59a494a451 | 1343 | |
brunofgc | 0:8c59a494a451 | 1344 | //printf("\r\nPoint 1\r\n"); |
brunofgc | 0:8c59a494a451 | 1345 | |
brunofgc | 0:8c59a494a451 | 1346 | //Encontrado o tipo de comando reutilizando a string indexBusca; |
brunofgc | 5:8efd609dea7d | 1347 | pChar = strtok(actString,";"); |
brunofgc | 5:8efd609dea7d | 1348 | pc.printf("1- <%s>.\r\n",pChar); |
brunofgc | 5:8efd609dea7d | 1349 | pChar = strtok(NULL,";"); |
brunofgc | 5:8efd609dea7d | 1350 | strcpy(alarmsSetString,pChar); |
brunofgc | 5:8efd609dea7d | 1351 | pChar = strtok(NULL,";"); |
brunofgc | 5:8efd609dea7d | 1352 | strcpy(alarmsResetString,pChar); |
brunofgc | 5:8efd609dea7d | 1353 | |
brunofgc | 5:8efd609dea7d | 1354 | pTipoComando = strtok(NULL,","); |
brunofgc | 5:8efd609dea7d | 1355 | |
brunofgc | 5:8efd609dea7d | 1356 | printf("\r\nPoint 2 comando <%s>\r\n",pTipoComando); |
brunofgc | 0:8c59a494a451 | 1357 | if(strstr(pTipoComando,"float")){tipoComando = modBusType_float;} |
brunofgc | 0:8c59a494a451 | 1358 | if(strstr(pTipoComando,"bit")){tipoComando = modBusType_bit;} |
brunofgc | 0:8c59a494a451 | 1359 | if(strstr(pTipoComando,"uint8_t")){tipoComando = modBusType_uint8_t;} |
brunofgc | 17:c046e4b07ded | 1360 | if(strstr(pTipoComando,"int16_t")){tipoComando = modBusType_int16_t;} |
brunofgc | 17:c046e4b07ded | 1361 | if(strstr(pTipoComando,"int32_t")){tipoComando = modBusType_int32_t;} |
brunofgc | 18:66fa6fcba212 | 1362 | if(strstr(pTipoComando,"uint16_t")){tipoComando = modBusType_uint16_t;} |
brunofgc | 18:66fa6fcba212 | 1363 | if(strstr(pTipoComando,"uint32_t")){tipoComando = modBusType_uint32_t;} |
brunofgc | 1:3f9e5b86d9e4 | 1364 | if(strstr(pTipoComando,"IR")){tipoComando = IrCommandType;} |
brunofgc | 1:3f9e5b86d9e4 | 1365 | if(strstr(pTipoComando,"PWM")){tipoComando = PWMCommandType;} |
brunofgc | 0:8c59a494a451 | 1366 | }else{ |
brunofgc | 0:8c59a494a451 | 1367 | return false; |
brunofgc | 0:8c59a494a451 | 1368 | } |
brunofgc | 0:8c59a494a451 | 1369 | |
brunofgc | 0:8c59a494a451 | 1370 | switch(tipoComando){ |
brunofgc | 0:8c59a494a451 | 1371 | case modBusType_float: |
brunofgc | 0:8c59a494a451 | 1372 | float floatValueToWrite; |
brunofgc | 0:8c59a494a451 | 1373 | uint32_t auxMod; |
brunofgc | 0:8c59a494a451 | 1374 | param1 = atoi(strtok(NULL,",")); |
brunofgc | 0:8c59a494a451 | 1375 | param2 = atoi(strtok(NULL,",")); |
brunofgc | 0:8c59a494a451 | 1376 | param3 = atoi(strtok(NULL,",")); |
brunofgc | 0:8c59a494a451 | 1377 | //floatValueToWrite = diversos::stringToFloat(strtok(NULL,","),100); |
brunofgc | 0:8c59a494a451 | 1378 | floatValueToWrite = atof(strtok(NULL,",")); |
brunofgc | 5:8efd609dea7d | 1379 | |
brunofgc | 1:3f9e5b86d9e4 | 1380 | //Envio comando via Modbus |
brunofgc | 9:0230ec4d2e68 | 1381 | if(modBusMaster1::writeFloat( |
brunofgc | 1:3f9e5b86d9e4 | 1382 | param1, |
brunofgc | 1:3f9e5b86d9e4 | 1383 | param3, |
brunofgc | 10:b61bb770f7b2 | 1384 | 1, |
brunofgc | 1:3f9e5b86d9e4 | 1385 | &floatValueToWrite |
brunofgc | 9:0230ec4d2e68 | 1386 | )){commandExecOk = false;} |
brunofgc | 0:8c59a494a451 | 1387 | break; |
brunofgc | 17:c046e4b07ded | 1388 | case modBusType_uint32_t: |
brunofgc | 17:c046e4b07ded | 1389 | case modBusType_int32_t: |
brunofgc | 0:8c59a494a451 | 1390 | param1 = atoi(strtok(NULL,",")); |
brunofgc | 0:8c59a494a451 | 1391 | param2 = atoi(strtok(NULL,",")); |
brunofgc | 0:8c59a494a451 | 1392 | param3 = atoi(strtok(NULL,",")); |
brunofgc | 17:c046e4b07ded | 1393 | param4 = atol(strtok(NULL,",")); |
brunofgc | 0:8c59a494a451 | 1394 | |
brunofgc | 9:0230ec4d2e68 | 1395 | if(modBusMaster1::writeRegister32BIT( |
brunofgc | 0:8c59a494a451 | 1396 | param1, |
brunofgc | 0:8c59a494a451 | 1397 | param3, |
brunofgc | 10:b61bb770f7b2 | 1398 | 1, |
brunofgc | 0:8c59a494a451 | 1399 | ¶m4 |
brunofgc | 9:0230ec4d2e68 | 1400 | )){commandExecOk = false;} |
brunofgc | 0:8c59a494a451 | 1401 | break; |
brunofgc | 0:8c59a494a451 | 1402 | case modBusType_uint16_t: |
brunofgc | 17:c046e4b07ded | 1403 | case modBusType_int16_t: |
brunofgc | 0:8c59a494a451 | 1404 | uint16_t param4_uint16_t; |
brunofgc | 0:8c59a494a451 | 1405 | param1 = atoi(strtok(NULL,",")); |
brunofgc | 0:8c59a494a451 | 1406 | param2 = atoi(strtok(NULL,",")); |
brunofgc | 0:8c59a494a451 | 1407 | param3 = atoi(strtok(NULL,",")); |
brunofgc | 0:8c59a494a451 | 1408 | param4_uint16_t = atoi(strtok(NULL,",")); |
brunofgc | 0:8c59a494a451 | 1409 | |
brunofgc | 9:0230ec4d2e68 | 1410 | if(modBusMaster1::writeRegister16BIT( |
brunofgc | 0:8c59a494a451 | 1411 | param1, |
brunofgc | 0:8c59a494a451 | 1412 | param3, |
brunofgc | 10:b61bb770f7b2 | 1413 | 1, |
brunofgc | 0:8c59a494a451 | 1414 | ¶m4_uint16_t |
brunofgc | 9:0230ec4d2e68 | 1415 | )){commandExecOk = false;} |
brunofgc | 0:8c59a494a451 | 1416 | break; |
brunofgc | 0:8c59a494a451 | 1417 | case modBusType_bit: |
brunofgc | 0:8c59a494a451 | 1418 | param1 = atoi(strtok(NULL,",")); |
brunofgc | 0:8c59a494a451 | 1419 | param2 = atoi(strtok(NULL,",")); |
brunofgc | 0:8c59a494a451 | 1420 | param3 = atoi(strtok(NULL,",")); |
brunofgc | 0:8c59a494a451 | 1421 | param4 = atoi(strtok(NULL,",")); |
brunofgc | 0:8c59a494a451 | 1422 | |
brunofgc | 0:8c59a494a451 | 1423 | if(param1 != 254){ |
brunofgc | 0:8c59a494a451 | 1424 | //Envia comando via Modbus |
brunofgc | 9:0230ec4d2e68 | 1425 | if(modBusMaster1::writeSingleCoil( |
brunofgc | 0:8c59a494a451 | 1426 | param1, |
brunofgc | 0:8c59a494a451 | 1427 | param3, |
brunofgc | 0:8c59a494a451 | 1428 | (bool)param4 |
brunofgc | 9:0230ec4d2e68 | 1429 | )){commandExecOk = false;} |
brunofgc | 0:8c59a494a451 | 1430 | }else{ |
brunofgc | 0:8c59a494a451 | 1431 | //Executa comando interno; |
brunofgc | 0:8c59a494a451 | 1432 | switch(param3){ |
brunofgc | 0:8c59a494a451 | 1433 | case 0: |
brunofgc | 0:8c59a494a451 | 1434 | SD1.write(param4*1.0f); |
brunofgc | 0:8c59a494a451 | 1435 | break; |
brunofgc | 0:8c59a494a451 | 1436 | case 1: |
brunofgc | 0:8c59a494a451 | 1437 | SD2.write(param4*1.0f); |
brunofgc | 0:8c59a494a451 | 1438 | break; |
brunofgc | 0:8c59a494a451 | 1439 | case 2: |
brunofgc | 0:8c59a494a451 | 1440 | SD3.write(param4*1.0f); |
brunofgc | 0:8c59a494a451 | 1441 | break; |
brunofgc | 0:8c59a494a451 | 1442 | case 3: |
brunofgc | 0:8c59a494a451 | 1443 | SD4.write(param4*1.0f); |
brunofgc | 0:8c59a494a451 | 1444 | break; |
brunofgc | 0:8c59a494a451 | 1445 | case 4: |
brunofgc | 0:8c59a494a451 | 1446 | SD5.write(param4*1.0f); |
brunofgc | 0:8c59a494a451 | 1447 | break; |
brunofgc | 0:8c59a494a451 | 1448 | case 5: |
brunofgc | 0:8c59a494a451 | 1449 | SD6.write(param4*1.0f); |
brunofgc | 0:8c59a494a451 | 1450 | break; |
brunofgc | 0:8c59a494a451 | 1451 | case 6: |
brunofgc | 0:8c59a494a451 | 1452 | SD7 = param4; |
brunofgc | 0:8c59a494a451 | 1453 | break; |
brunofgc | 0:8c59a494a451 | 1454 | case 7: |
brunofgc | 0:8c59a494a451 | 1455 | SD8 = param4; |
brunofgc | 0:8c59a494a451 | 1456 | break; |
brunofgc | 0:8c59a494a451 | 1457 | } |
brunofgc | 0:8c59a494a451 | 1458 | } |
brunofgc | 0:8c59a494a451 | 1459 | break; |
brunofgc | 0:8c59a494a451 | 1460 | case IrCommandType: |
brunofgc | 0:8c59a494a451 | 1461 | //Busca no arquivo |
brunofgc | 0:8c59a494a451 | 1462 | //Abre arquivo |
brunofgc | 0:8c59a494a451 | 1463 | //printf("\r\nIniciando execucao de comando IR\r\n"); |
brunofgc | 0:8c59a494a451 | 1464 | param1 = atoi(strtok(NULL,",")); |
brunofgc | 0:8c59a494a451 | 1465 | param2 = atoi(strtok(NULL,",")); |
brunofgc | 0:8c59a494a451 | 1466 | //printf("\r\nparam 1 %lu, param2 %lu\r\n",param1,param2); |
brunofgc | 0:8c59a494a451 | 1467 | pTipoComando = strtok(NULL,"S");//Reaproveitando variável pTipoComando |
brunofgc | 0:8c59a494a451 | 1468 | //printf("\r\nPacote IR <%s>.\r\n",pTipoComando); |
brunofgc | 0:8c59a494a451 | 1469 | deserializaPacoteIR(pTipoComando); |
brunofgc | 5:8efd609dea7d | 1470 | //printf("Deserializado.\r\nInicio do envio.\r\n"); |
brunofgc | 12:254c32b4ece7 | 1471 | if(param1){ |
brunofgc | 12:254c32b4ece7 | 1472 | enviaComandoIR(param1,param2); |
brunofgc | 12:254c32b4ece7 | 1473 | }else{ |
brunofgc | 12:254c32b4ece7 | 1474 | for(i=33;i<41;i++){ |
brunofgc | 12:254c32b4ece7 | 1475 | enviaComandoIR(i,param2); |
brunofgc | 12:254c32b4ece7 | 1476 | if(i!=40){osDelay(100);} |
brunofgc | 12:254c32b4ece7 | 1477 | } |
brunofgc | 12:254c32b4ece7 | 1478 | } |
brunofgc | 5:8efd609dea7d | 1479 | //printf("Fim do envio.\r\n"); |
brunofgc | 0:8c59a494a451 | 1480 | break; |
brunofgc | 1:3f9e5b86d9e4 | 1481 | |
brunofgc | 1:3f9e5b86d9e4 | 1482 | case PWMCommandType: |
brunofgc | 1:3f9e5b86d9e4 | 1483 | //float floatValuePWM; |
brunofgc | 1:3f9e5b86d9e4 | 1484 | //uint32_t auxPeriod; |
brunofgc | 1:3f9e5b86d9e4 | 1485 | param1 = atoi(strtok(NULL,",")); |
brunofgc | 1:3f9e5b86d9e4 | 1486 | param2 = atoi(strtok(NULL,",")); |
brunofgc | 1:3f9e5b86d9e4 | 1487 | param3 = atoi(strtok(NULL,",")); |
brunofgc | 1:3f9e5b86d9e4 | 1488 | //floatValueToWrite = diversos::stringToFloat(strtok(NULL,","),100); |
brunofgc | 1:3f9e5b86d9e4 | 1489 | floatValueToWrite = atof(strtok(NULL,",")); |
brunofgc | 1:3f9e5b86d9e4 | 1490 | |
brunofgc | 1:3f9e5b86d9e4 | 1491 | //Executa comando interno; |
brunofgc | 1:3f9e5b86d9e4 | 1492 | auxMod = floatValueToWrite/10; |
brunofgc | 1:3f9e5b86d9e4 | 1493 | floatValueToWrite = floatValueToWrite-(auxMod*10); |
brunofgc | 1:3f9e5b86d9e4 | 1494 | SD1.period_us(auxMod); |
brunofgc | 1:3f9e5b86d9e4 | 1495 | pwmPeriod = auxMod; |
brunofgc | 1:3f9e5b86d9e4 | 1496 | switch(param3){ |
brunofgc | 1:3f9e5b86d9e4 | 1497 | case 0: |
brunofgc | 1:3f9e5b86d9e4 | 1498 | SD1.write(floatValueToWrite); |
brunofgc | 1:3f9e5b86d9e4 | 1499 | break; |
brunofgc | 1:3f9e5b86d9e4 | 1500 | case 1: |
brunofgc | 1:3f9e5b86d9e4 | 1501 | SD2.write(floatValueToWrite); |
brunofgc | 1:3f9e5b86d9e4 | 1502 | break; |
brunofgc | 1:3f9e5b86d9e4 | 1503 | case 2: |
brunofgc | 1:3f9e5b86d9e4 | 1504 | SD3.write(floatValueToWrite); |
brunofgc | 1:3f9e5b86d9e4 | 1505 | break; |
brunofgc | 1:3f9e5b86d9e4 | 1506 | case 3: |
brunofgc | 1:3f9e5b86d9e4 | 1507 | SD4.write(floatValueToWrite); |
brunofgc | 1:3f9e5b86d9e4 | 1508 | break; |
brunofgc | 1:3f9e5b86d9e4 | 1509 | case 4: |
brunofgc | 1:3f9e5b86d9e4 | 1510 | SD5.write(floatValueToWrite); |
brunofgc | 1:3f9e5b86d9e4 | 1511 | break; |
brunofgc | 1:3f9e5b86d9e4 | 1512 | case 5: |
brunofgc | 1:3f9e5b86d9e4 | 1513 | SD6.write(floatValueToWrite); |
brunofgc | 1:3f9e5b86d9e4 | 1514 | break; |
brunofgc | 1:3f9e5b86d9e4 | 1515 | } |
brunofgc | 1:3f9e5b86d9e4 | 1516 | break; |
brunofgc | 1:3f9e5b86d9e4 | 1517 | |
brunofgc | 0:8c59a494a451 | 1518 | default: |
brunofgc | 0:8c59a494a451 | 1519 | //printf("comando nao encontrado\r\n"); |
brunofgc | 0:8c59a494a451 | 1520 | break; |
brunofgc | 0:8c59a494a451 | 1521 | } |
brunofgc | 5:8efd609dea7d | 1522 | //Coletando dados do alarmSet e alarmReset |
brunofgc | 5:8efd609dea7d | 1523 | |
brunofgc | 5:8efd609dea7d | 1524 | pChar = strtok(alarmsSetString,","); |
brunofgc | 5:8efd609dea7d | 1525 | while(pChar!=NULL){ |
brunofgc | 5:8efd609dea7d | 1526 | pc.printf("Lido Alarm Set %lu - <%lu>.\r\n",indexAlarms,atoi(pChar)); |
brunofgc | 13:c1122e7b0b36 | 1527 | if(atoi(pChar)){ |
brunofgc | 19:d52176ff683d | 1528 | alarmOnOff(atoi(pChar),1); |
brunofgc | 13:c1122e7b0b36 | 1529 | } |
brunofgc | 5:8efd609dea7d | 1530 | pChar = strtok(NULL,","); |
brunofgc | 5:8efd609dea7d | 1531 | } |
brunofgc | 5:8efd609dea7d | 1532 | |
brunofgc | 5:8efd609dea7d | 1533 | pChar = strtok(alarmsResetString,","); |
brunofgc | 5:8efd609dea7d | 1534 | while(pChar!=NULL){ |
brunofgc | 5:8efd609dea7d | 1535 | pc.printf("Lido Alarm Reset %lu - <%lu>.\r\n",indexAlarms,atoi(pChar)); |
brunofgc | 13:c1122e7b0b36 | 1536 | if(atoi(pChar)){ |
brunofgc | 19:d52176ff683d | 1537 | alarmOnOff(atoi(pChar),0); |
brunofgc | 13:c1122e7b0b36 | 1538 | } |
brunofgc | 5:8efd609dea7d | 1539 | pChar = strtok(NULL,","); |
brunofgc | 5:8efd609dea7d | 1540 | } |
brunofgc | 5:8efd609dea7d | 1541 | |
brunofgc | 0:8c59a494a451 | 1542 | //printf("\r\n===================DEBUG(execAct)===================\r\n"); |
brunofgc | 9:0230ec4d2e68 | 1543 | return commandExecOk; |
brunofgc | 0:8c59a494a451 | 1544 | } |
brunofgc | 0:8c59a494a451 | 1545 | |
brunofgc | 19:d52176ff683d | 1546 | void alarmOnOff(uint32_t idAlarm,bool state){ |
brunofgc | 5:8efd609dea7d | 1547 | uint16_t alarmIndex; |
brunofgc | 5:8efd609dea7d | 1548 | char indexBusca[30]; |
brunofgc | 5:8efd609dea7d | 1549 | char alarmString[40]; |
brunofgc | 5:8efd609dea7d | 1550 | uint32_t seekPosition; |
brunofgc | 5:8efd609dea7d | 1551 | bool endOfFile; |
brunofgc | 5:8efd609dea7d | 1552 | char charState; |
brunofgc | 5:8efd609dea7d | 1553 | |
brunofgc | 5:8efd609dea7d | 1554 | for(alarmIndex = 0; alarmIndex < alarmes; alarmIndex++){ |
brunofgc | 19:d52176ff683d | 1555 | if(alarms[alarmIndex].id == idAlarm){ |
brunofgc | 19:d52176ff683d | 1556 | alarms[alarmIndex].on = state; |
brunofgc | 5:8efd609dea7d | 1557 | } |
brunofgc | 5:8efd609dea7d | 1558 | } |
brunofgc | 5:8efd609dea7d | 1559 | |
brunofgc | 5:8efd609dea7d | 1560 | if(!sdCard::abreArquivo(&sdCard::devices,"rb+")){return;} |
brunofgc | 5:8efd609dea7d | 1561 | |
brunofgc | 7:b4b2b8720166 | 1562 | sprintf(indexBusca,"idAlarm:%lu\r",idAlarm); |
brunofgc | 5:8efd609dea7d | 1563 | do{ |
brunofgc | 5:8efd609dea7d | 1564 | endOfFile = feof(sdCard::devices.fp); |
brunofgc | 5:8efd609dea7d | 1565 | if(!endOfFile){fgets(alarmString,40,sdCard::devices.fp);} |
brunofgc | 5:8efd609dea7d | 1566 | }while((strstr(alarmString,indexBusca)==NULL)&&(endOfFile==0)); |
brunofgc | 5:8efd609dea7d | 1567 | |
brunofgc | 5:8efd609dea7d | 1568 | |
brunofgc | 5:8efd609dea7d | 1569 | do{ |
brunofgc | 5:8efd609dea7d | 1570 | endOfFile = feof(sdCard::devices.fp); |
brunofgc | 5:8efd609dea7d | 1571 | if(!endOfFile){fgets(alarmString,40,sdCard::devices.fp);} |
brunofgc | 5:8efd609dea7d | 1572 | }while((strstr(alarmString,"on:")==NULL)&&(endOfFile==0)); |
brunofgc | 5:8efd609dea7d | 1573 | |
brunofgc | 5:8efd609dea7d | 1574 | |
brunofgc | 5:8efd609dea7d | 1575 | if(endOfFile){ |
brunofgc | 5:8efd609dea7d | 1576 | sdCard::fechaArquivo(&sdCard::devices); |
brunofgc | 5:8efd609dea7d | 1577 | return; |
brunofgc | 5:8efd609dea7d | 1578 | } |
brunofgc | 5:8efd609dea7d | 1579 | |
brunofgc | 5:8efd609dea7d | 1580 | seekPosition = ftell(sdCard::devices.fp)-3; |
brunofgc | 5:8efd609dea7d | 1581 | fseek(sdCard::devices.fp,seekPosition,SEEK_SET); |
brunofgc | 5:8efd609dea7d | 1582 | if(state){charState='1';}else{charState='0';} |
brunofgc | 5:8efd609dea7d | 1583 | fputc(charState,sdCard::devices.fp); |
brunofgc | 5:8efd609dea7d | 1584 | //fprintf(sdCard::devices.fp,"%u",state); |
brunofgc | 5:8efd609dea7d | 1585 | fflush(sdCard::devices.fp); |
brunofgc | 5:8efd609dea7d | 1586 | sdCard::fechaArquivo(&sdCard::devices); |
brunofgc | 5:8efd609dea7d | 1587 | } |
brunofgc | 5:8efd609dea7d | 1588 | |
brunofgc | 19:d52176ff683d | 1589 | void writeReadingsToSD(){ |
brunofgc | 0:8c59a494a451 | 1590 | //Buffering before insertData |
brunofgc | 0:8c59a494a451 | 1591 | //Esta função faz a inserção de todos os dados no arquivo armazenamento. |
brunofgc | 0:8c59a494a451 | 1592 | uint16_t readingIndex=0; |
brunofgc | 0:8c59a494a451 | 1593 | /* |
brunofgc | 0:8c59a494a451 | 1594 | union { |
brunofgc | 0:8c59a494a451 | 1595 | char c[4]; |
brunofgc | 0:8c59a494a451 | 1596 | float v; |
brunofgc | 0:8c59a494a451 | 1597 | }uFloat; |
brunofgc | 0:8c59a494a451 | 1598 | */ |
brunofgc | 0:8c59a494a451 | 1599 | float *floatBuffer; |
brunofgc | 0:8c59a494a451 | 1600 | uint32_t *uint32_tBuffer; |
brunofgc | 0:8c59a494a451 | 1601 | uint16_t *uint16_tBuffer; |
brunofgc | 0:8c59a494a451 | 1602 | bool *boolBuffer; |
brunofgc | 0:8c59a494a451 | 1603 | uint32_t seconds_uint32_t; |
brunofgc | 0:8c59a494a451 | 1604 | char seconds_char[5]; |
brunofgc | 0:8c59a494a451 | 1605 | |
brunofgc | 0:8c59a494a451 | 1606 | seconds_uint32_t = (uint32_t) time(NULL); |
brunofgc | 0:8c59a494a451 | 1607 | seconds_char[0]=(seconds_uint32_t >> 0) & 0xFF; |
brunofgc | 0:8c59a494a451 | 1608 | seconds_char[1]=(seconds_uint32_t >> 8) & 0xFF; |
brunofgc | 0:8c59a494a451 | 1609 | seconds_char[2]=(seconds_uint32_t >> 16) & 0xFF; |
brunofgc | 0:8c59a494a451 | 1610 | seconds_char[3]=(seconds_uint32_t >> 24) & 0xFF; |
brunofgc | 0:8c59a494a451 | 1611 | seconds_char[4]=0; |
brunofgc | 0:8c59a494a451 | 1612 | |
brunofgc | 0:8c59a494a451 | 1613 | |
brunofgc | 0:8c59a494a451 | 1614 | //Inicio da string dentro do arquivo binario |
brunofgc | 16:1b43a57ee676 | 1615 | sdCardBuf.del(); |
brunofgc | 0:8c59a494a451 | 1616 | sdCardBuf.fill("log{data:",9); |
brunofgc | 0:8c59a494a451 | 1617 | |
brunofgc | 0:8c59a494a451 | 1618 | //O timestamp é posto nos 4 primeiros bytes (segundos) |
brunofgc | 0:8c59a494a451 | 1619 | sdCardBuf.fill(seconds_char,5); |
brunofgc | 0:8c59a494a451 | 1620 | |
brunofgc | 19:d52176ff683d | 1621 | for(readingIndex = 0;readingIndex < numReadings;readingIndex++){ |
brunofgc | 22:e0d8c8fe26c6 | 1622 | diversos::wdt.kick(180.0); |
brunofgc | 19:d52176ff683d | 1623 | switch(readings[readingIndex].type){ |
brunofgc | 0:8c59a494a451 | 1624 | case modBusType_float: |
brunofgc | 19:d52176ff683d | 1625 | if(readings[readingIndex].addr != enderecoControladoraVirtual){ |
brunofgc | 19:d52176ff683d | 1626 | //Busca fora do drome via Modbus |
brunofgc | 19:d52176ff683d | 1627 | floatBuffer = (float*) malloc(((readings[readingIndex].numRegs*sizeof(float))+1)); //Alocando mais um byte para status |
brunofgc | 19:d52176ff683d | 1628 | ((char *)floatBuffer)[(readings[readingIndex].numRegs*sizeof(float))] = modBusMaster1::readFloat( |
brunofgc | 19:d52176ff683d | 1629 | readings[readingIndex].addr, |
brunofgc | 19:d52176ff683d | 1630 | readings[readingIndex].func, |
brunofgc | 19:d52176ff683d | 1631 | readings[readingIndex].reg, |
brunofgc | 19:d52176ff683d | 1632 | readings[readingIndex].numRegs, |
brunofgc | 0:8c59a494a451 | 1633 | floatBuffer |
brunofgc | 0:8c59a494a451 | 1634 | ); |
brunofgc | 0:8c59a494a451 | 1635 | }else{ |
brunofgc | 0:8c59a494a451 | 1636 | //Busca Interna |
brunofgc | 0:8c59a494a451 | 1637 | floatBuffer = (float*) malloc(sizeof(float)); |
brunofgc | 19:d52176ff683d | 1638 | if((readings[readingIndex].reg<100)&&(readings[readingIndex].reg < num_temperatureSensors)){//Registradores das entradas de temperatura |
brunofgc | 3:75223647cf3d | 1639 | //Populando floatBuffer com a temperaturas |
brunofgc | 19:d52176ff683d | 1640 | floatBuffer[0] = temperaturas[readings[readingIndex].reg]; |
brunofgc | 1:3f9e5b86d9e4 | 1641 | } |
brunofgc | 19:d52176ff683d | 1642 | if((readings[readingIndex].reg>=100)&&(readings[readingIndex].reg<104)){ |
brunofgc | 3:75223647cf3d | 1643 | //Registradores das entradas analógicas |
brunofgc | 19:d52176ff683d | 1644 | floatBuffer[0] = aiFiltrada[readings[readingIndex].reg - 100]; |
brunofgc | 3:75223647cf3d | 1645 | } |
brunofgc | 19:d52176ff683d | 1646 | readings[readingIndex].numRegs = 1; |
brunofgc | 0:8c59a494a451 | 1647 | } |
brunofgc | 0:8c59a494a451 | 1648 | |
brunofgc | 0:8c59a494a451 | 1649 | //pc.printf("Lido dentro de modBusMaster1::teste() <%f>.\n",modBusMaster1::teste()); |
brunofgc | 19:d52176ff683d | 1650 | sdCardBuf.fill((char *)floatBuffer,((sizeof(float)*readings[readingIndex].numRegs)+1));//Ao fim appendo o byte de status |
brunofgc | 0:8c59a494a451 | 1651 | free(floatBuffer); |
brunofgc | 0:8c59a494a451 | 1652 | break; |
brunofgc | 17:c046e4b07ded | 1653 | case modBusType_uint32_t: |
brunofgc | 17:c046e4b07ded | 1654 | case modBusType_int32_t: |
brunofgc | 19:d52176ff683d | 1655 | if(readings[readingIndex].addr != enderecoControladoraVirtual){ |
brunofgc | 19:d52176ff683d | 1656 | uint32_tBuffer = (uint32_t*) malloc((readings[readingIndex].numRegs*sizeof(uint32_t))+1); //Alocando mais um byte para status |
brunofgc | 19:d52176ff683d | 1657 | ((char *)uint32_tBuffer)[(readings[readingIndex].numRegs*sizeof(uint32_t))] = modBusMaster1::readRegister32BIT(//Ponho o status no ultimo byte |
brunofgc | 19:d52176ff683d | 1658 | readings[readingIndex].addr, |
brunofgc | 19:d52176ff683d | 1659 | readings[readingIndex].func, |
brunofgc | 19:d52176ff683d | 1660 | readings[readingIndex].reg, |
brunofgc | 19:d52176ff683d | 1661 | readings[readingIndex].numRegs, |
brunofgc | 3:75223647cf3d | 1662 | uint32_tBuffer |
brunofgc | 3:75223647cf3d | 1663 | ); |
brunofgc | 3:75223647cf3d | 1664 | //pc.printf("Lido dentro de modBusMaster1::teste() <%f>.\n",modBusMaster1::teste()); |
brunofgc | 3:75223647cf3d | 1665 | }else{ |
brunofgc | 15:6d9e9cafe138 | 1666 | uint32_tBuffer = (uint32_t*) malloc(sizeof(uint32_t)+1); //Alocando mais um byte para status |
brunofgc | 19:d52176ff683d | 1667 | uint32_tBuffer[0] = pulsosEDs[readings[readingIndex].reg]; |
brunofgc | 19:d52176ff683d | 1668 | readings[readingIndex].numRegs = 1; |
brunofgc | 19:d52176ff683d | 1669 | pulsosEDs[readings[readingIndex].reg] = 0; |
brunofgc | 3:75223647cf3d | 1670 | } |
brunofgc | 19:d52176ff683d | 1671 | sdCardBuf.fill((char *)uint32_tBuffer,((sizeof(uint32_t)*readings[readingIndex].numRegs)+1));//Ao fim appendo o byte de status |
brunofgc | 0:8c59a494a451 | 1672 | free(uint32_tBuffer); |
brunofgc | 0:8c59a494a451 | 1673 | break; |
brunofgc | 0:8c59a494a451 | 1674 | |
brunofgc | 17:c046e4b07ded | 1675 | case modBusType_uint16_t: |
brunofgc | 17:c046e4b07ded | 1676 | case modBusType_int16_t: |
brunofgc | 19:d52176ff683d | 1677 | if(readings[readingIndex].addr!=enderecoControladoraVirtual){ |
brunofgc | 19:d52176ff683d | 1678 | uint16_tBuffer = (uint16_t*) malloc(((readings[readingIndex].numRegs*sizeof(uint16_t))+1));//Alocando mais um byte para status |
brunofgc | 19:d52176ff683d | 1679 | ((char *)uint16_tBuffer)[(readings[readingIndex].numRegs*sizeof(uint16_t))] = modBusMaster1::readRegister16BIT(// |
brunofgc | 19:d52176ff683d | 1680 | readings[readingIndex].addr, |
brunofgc | 19:d52176ff683d | 1681 | readings[readingIndex].func, |
brunofgc | 19:d52176ff683d | 1682 | readings[readingIndex].reg, |
brunofgc | 19:d52176ff683d | 1683 | readings[readingIndex].numRegs, |
brunofgc | 0:8c59a494a451 | 1684 | uint16_tBuffer |
brunofgc | 0:8c59a494a451 | 1685 | ); |
brunofgc | 0:8c59a494a451 | 1686 | //pc.printf("Lido dentro de modBusMaster1::teste() <%f>.\n",modBusMaster1::teste()); |
brunofgc | 19:d52176ff683d | 1687 | sdCardBuf.fill((char *)uint16_tBuffer,((sizeof(uint16_t)*readings[readingIndex].numRegs)+1));//Ao fim appendo o byte de status |
brunofgc | 0:8c59a494a451 | 1688 | free(uint16_tBuffer); |
brunofgc | 15:6d9e9cafe138 | 1689 | }else{ |
brunofgc | 19:d52176ff683d | 1690 | if((readings[readingIndex].reg>0)&&((readings[readingIndex].reg + readings[readingIndex].numRegs)<=4)){ |
brunofgc | 19:d52176ff683d | 1691 | sdCardBuf.fill((char *)&aiFiltrada[readings[readingIndex].reg-1],sizeof(uint16_t)*readings[readingIndex].numRegs); |
brunofgc | 15:6d9e9cafe138 | 1692 | seconds_char[4]=0; |
brunofgc | 15:6d9e9cafe138 | 1693 | sdCardBuf.fill((char *)&seconds_char[4],1); |
brunofgc | 0:8c59a494a451 | 1694 | } |
brunofgc | 0:8c59a494a451 | 1695 | } |
brunofgc | 0:8c59a494a451 | 1696 | break; |
brunofgc | 0:8c59a494a451 | 1697 | |
brunofgc | 0:8c59a494a451 | 1698 | case modBusType_bit: |
brunofgc | 15:6d9e9cafe138 | 1699 | boolBuffer = (bool*) malloc(sizeof(bool)+1);//Alocando mais um byte para status |
brunofgc | 19:d52176ff683d | 1700 | if(readings[readingIndex].addr != enderecoControladoraVirtual){ |
brunofgc | 19:d52176ff683d | 1701 | ((char *)boolBuffer)[(readings[readingIndex].numRegs*sizeof(bool))] = modBusMaster1::readCoils( |
brunofgc | 19:d52176ff683d | 1702 | readings[readingIndex].addr, |
brunofgc | 19:d52176ff683d | 1703 | readings[readingIndex].reg, |
brunofgc | 19:d52176ff683d | 1704 | readings[readingIndex].numRegs, |
brunofgc | 0:8c59a494a451 | 1705 | boolBuffer |
brunofgc | 0:8c59a494a451 | 1706 | ); |
brunofgc | 15:6d9e9cafe138 | 1707 | }else{ |
brunofgc | 19:d52176ff683d | 1708 | boolBuffer[0] = entradasDigitais[readings[readingIndex].reg]; |
brunofgc | 15:6d9e9cafe138 | 1709 | ((char *)boolBuffer)[1]=0; |
brunofgc | 0:8c59a494a451 | 1710 | } |
brunofgc | 0:8c59a494a451 | 1711 | //pc.printf("Lido dentro de modBusMaster1::teste() <%f>.\n",modBusMaster1::teste()); |
brunofgc | 19:d52176ff683d | 1712 | sdCardBuf.fill((char *)boolBuffer,((sizeof(bool)*readings[readingIndex].numRegs)+1));//Ao fim appendo o byte de status |
brunofgc | 0:8c59a494a451 | 1713 | free(boolBuffer); |
brunofgc | 0:8c59a494a451 | 1714 | break; |
brunofgc | 0:8c59a494a451 | 1715 | |
brunofgc | 0:8c59a494a451 | 1716 | } |
brunofgc | 0:8c59a494a451 | 1717 | } |
brunofgc | 0:8c59a494a451 | 1718 | readingIndex = sdCardBuf.fill("}log",4); //Reaproveitando a variável de 16bit readingIndex |
brunofgc | 5:8efd609dea7d | 1719 | sdCard::arquivoAberto(40000); |
brunofgc | 5:8efd609dea7d | 1720 | //Insiro os dados se for possível. |
brunofgc | 8:25061210fcc9 | 1721 | sdCard::insereDadosBank(sdCardBuf.get(),readingIndex); |
brunofgc | 0:8c59a494a451 | 1722 | } |
brunofgc | 0:8c59a494a451 | 1723 | |
brunofgc | 0:8c59a494a451 | 1724 | |
brunofgc | 0:8c59a494a451 | 1725 | |
brunofgc | 0:8c59a494a451 | 1726 | |
brunofgc | 0:8c59a494a451 | 1727 | |
brunofgc | 0:8c59a494a451 | 1728 | |
brunofgc | 0:8c59a494a451 | 1729 | |
brunofgc | 0:8c59a494a451 | 1730 | |
brunofgc | 19:d52176ff683d | 1731 | |
brunofgc | 0:8c59a494a451 | 1732 | |
brunofgc | 0:8c59a494a451 | 1733 | int criaDevices(FILE *devicesCfg) |
brunofgc | 0:8c59a494a451 | 1734 | { |
brunofgc | 0:8c59a494a451 | 1735 | char linha[maxCaractereLeLinha]; |
brunofgc | 0:8c59a494a451 | 1736 | int linhas = 0; |
brunofgc | 0:8c59a494a451 | 1737 | devices = 0; |
brunofgc | 0:8c59a494a451 | 1738 | |
brunofgc | 0:8c59a494a451 | 1739 | while(fgets(linha,maxCaractereLeLinha,devicesCfg)) { |
brunofgc | 0:8c59a494a451 | 1740 | if(strstr(linha,"deviceCreate\\")) { |
brunofgc | 0:8c59a494a451 | 1741 | devices++; |
brunofgc | 0:8c59a494a451 | 1742 | } |
brunofgc | 0:8c59a494a451 | 1743 | linhas++; |
brunofgc | 0:8c59a494a451 | 1744 | } |
brunofgc | 0:8c59a494a451 | 1745 | |
brunofgc | 19:d52176ff683d | 1746 | printf("Contei %u linha(s), %u device(s).\n",linhas,devices); |
brunofgc | 19:d52176ff683d | 1747 | |
brunofgc | 19:d52176ff683d | 1748 | alarmes=0; |
brunofgc | 19:d52176ff683d | 1749 | numSchedules=0; |
brunofgc | 19:d52176ff683d | 1750 | numScheduleExceptions=0; |
brunofgc | 19:d52176ff683d | 1751 | numReadings=0; |
brunofgc | 2:ca3723da6668 | 1752 | rewind(devicesCfg); |
brunofgc | 0:8c59a494a451 | 1753 | return 1; |
brunofgc | 0:8c59a494a451 | 1754 | } |
brunofgc | 0:8c59a494a451 | 1755 | |
brunofgc | 0:8c59a494a451 | 1756 | |
brunofgc | 0:8c59a494a451 | 1757 | int configuraDevices(FILE *devicesCfg) |
brunofgc | 0:8c59a494a451 | 1758 | { |
brunofgc | 21:19135fa28bc3 | 1759 | |
brunofgc | 0:8c59a494a451 | 1760 | //uint16_t leituras = 0; |
brunofgc | 2:ca3723da6668 | 1761 | char linha[maxCaractereLeLinha]; |
brunofgc | 0:8c59a494a451 | 1762 | uint8_t estadoConfiguracao=estadoConfiguracao_idle; |
brunofgc | 19:d52176ff683d | 1763 | alarmes = 0; |
brunofgc | 19:d52176ff683d | 1764 | bool condicaoDeSaida = false; |
brunofgc | 2:ca3723da6668 | 1765 | |
brunofgc | 19:d52176ff683d | 1766 | while(fgets(linha,maxCaractereLeLinha,devicesCfg)&&(!condicaoDeSaida)){ |
brunofgc | 19:d52176ff683d | 1767 | if(strstr(linha,"deviceCreate\\")) { |
brunofgc | 0:8c59a494a451 | 1768 | //printf("Configurando dispositivo de indice %u.\n",dispositivoEmConfiguracao); |
brunofgc | 0:8c59a494a451 | 1769 | estadoConfiguracao = estadoConfiguracao_creatingDevice; |
brunofgc | 0:8c59a494a451 | 1770 | } |
brunofgc | 0:8c59a494a451 | 1771 | |
brunofgc | 0:8c59a494a451 | 1772 | if(strstr(linha,"alarmSet")) { |
brunofgc | 0:8c59a494a451 | 1773 | //printf("Criando alarme no dispositivo de indice %u.\n",dispositivoEmConfiguracao); |
brunofgc | 19:d52176ff683d | 1774 | //alarmes++; |
brunofgc | 0:8c59a494a451 | 1775 | estadoConfiguracao = estadoConfiguracao_alarmSet; |
brunofgc | 0:8c59a494a451 | 1776 | } |
brunofgc | 0:8c59a494a451 | 1777 | |
brunofgc | 15:6d9e9cafe138 | 1778 | if(strstr(linha,"readingsEnd")) { |
brunofgc | 0:8c59a494a451 | 1779 | //printf("Criando leituras no dispositivo de indice %u.\n",dispositivoEmConfiguracao); |
brunofgc | 15:6d9e9cafe138 | 1780 | estadoConfiguracao = estadoConfiguracao_idle; |
brunofgc | 15:6d9e9cafe138 | 1781 | } |
brunofgc | 15:6d9e9cafe138 | 1782 | |
brunofgc | 15:6d9e9cafe138 | 1783 | if(estadoConfiguracao == estadoConfiguracao_readingsSet){ |
brunofgc | 2:ca3723da6668 | 1784 | leituras++; |
brunofgc | 15:6d9e9cafe138 | 1785 | } |
brunofgc | 15:6d9e9cafe138 | 1786 | |
brunofgc | 15:6d9e9cafe138 | 1787 | |
brunofgc | 15:6d9e9cafe138 | 1788 | if(strstr(linha,"readingsSet")) { |
brunofgc | 15:6d9e9cafe138 | 1789 | //printf("Criando leituras no dispositivo de indice %u.\n",dispositivoEmConfiguracao); |
brunofgc | 0:8c59a494a451 | 1790 | estadoConfiguracao = estadoConfiguracao_readingsSet; |
brunofgc | 0:8c59a494a451 | 1791 | } |
brunofgc | 0:8c59a494a451 | 1792 | |
brunofgc | 4:3f92979d1ffb | 1793 | if(strstr(linha,"scheduleExceptionSet")) { |
brunofgc | 4:3f92979d1ffb | 1794 | //printf("Criando leituras no dispositivo de indice %u.\n",dispositivoEmConfiguracao); |
brunofgc | 4:3f92979d1ffb | 1795 | qtdScheduleExceptions++; |
brunofgc | 4:3f92979d1ffb | 1796 | estadoConfiguracao = estadoConfiguracao_scheduleExceptionSet; |
brunofgc | 15:6d9e9cafe138 | 1797 | } |
brunofgc | 0:8c59a494a451 | 1798 | |
brunofgc | 0:8c59a494a451 | 1799 | if(strstr(linha,"scheduleSet")) { |
brunofgc | 0:8c59a494a451 | 1800 | //printf("Criando leituras no dispositivo de indice %u.\n",dispositivoEmConfiguracao); |
brunofgc | 0:8c59a494a451 | 1801 | qtdSchedules++; |
brunofgc | 0:8c59a494a451 | 1802 | estadoConfiguracao = estadoConfiguracao_scheduleSet; |
brunofgc | 5:8efd609dea7d | 1803 | } |
brunofgc | 0:8c59a494a451 | 1804 | |
brunofgc | 0:8c59a494a451 | 1805 | if(strstr(linha,">")) { |
brunofgc | 0:8c59a494a451 | 1806 | //printf("Fechando dispositivo de indice %u.\n",dispositivoEmConfiguracao); |
brunofgc | 19:d52176ff683d | 1807 | condicaoDeSaida = true; |
brunofgc | 0:8c59a494a451 | 1808 | estadoConfiguracao = estadoConfiguracao_idle; |
brunofgc | 0:8c59a494a451 | 1809 | } |
brunofgc | 0:8c59a494a451 | 1810 | |
brunofgc | 0:8c59a494a451 | 1811 | switch(estadoConfiguracao) { |
brunofgc | 0:8c59a494a451 | 1812 | case estadoConfiguracao_creatingDevice: |
brunofgc | 0:8c59a494a451 | 1813 | /*if(strstr(linha,"id:")) { |
brunofgc | 19:d52176ff683d | 1814 | sscanf(linha,"id:%u",&id); |
brunofgc | 0:8c59a494a451 | 1815 | }*/ |
brunofgc | 0:8c59a494a451 | 1816 | break; |
brunofgc | 0:8c59a494a451 | 1817 | case estadoConfiguracao_alarmSet: |
brunofgc | 0:8c59a494a451 | 1818 | //Inclue linha nos alarmes do dispositivo em configuração |
brunofgc | 19:d52176ff683d | 1819 | setAlarm(linha); |
brunofgc | 0:8c59a494a451 | 1820 | break; |
brunofgc | 0:8c59a494a451 | 1821 | case estadoConfiguracao_readingsSet: |
brunofgc | 0:8c59a494a451 | 1822 | //Inclue linha nas leituras do dispositivo em configuração |
brunofgc | 19:d52176ff683d | 1823 | setReading(linha); |
brunofgc | 0:8c59a494a451 | 1824 | break; |
brunofgc | 0:8c59a494a451 | 1825 | case estadoConfiguracao_scheduleSet: |
brunofgc | 4:3f92979d1ffb | 1826 | //Inclue linha nos agendamentos do dispositivo em configuração |
brunofgc | 19:d52176ff683d | 1827 | setSchedule(linha); |
brunofgc | 4:3f92979d1ffb | 1828 | break; |
brunofgc | 4:3f92979d1ffb | 1829 | case estadoConfiguracao_scheduleExceptionSet: |
brunofgc | 4:3f92979d1ffb | 1830 | //Inclue linha nas excessões dos agendamentos do dispositivo em configuração |
brunofgc | 19:d52176ff683d | 1831 | setScheduleException(linha); |
brunofgc | 0:8c59a494a451 | 1832 | break; |
brunofgc | 0:8c59a494a451 | 1833 | } |
brunofgc | 19:d52176ff683d | 1834 | } |
brunofgc | 0:8c59a494a451 | 1835 | return 1; |
brunofgc | 0:8c59a494a451 | 1836 | } |
brunofgc | 0:8c59a494a451 | 1837 | |
brunofgc | 0:8c59a494a451 | 1838 | |
brunofgc | 0:8c59a494a451 | 1839 | |
brunofgc | 0:8c59a494a451 | 1840 | void testaTudoDevices() |
brunofgc | 0:8c59a494a451 | 1841 | { |
brunofgc | 0:8c59a494a451 | 1842 | int j; |
brunofgc | 19:d52176ff683d | 1843 | |
brunofgc | 19:d52176ff683d | 1844 | printf("O dispositivo tem %u alarmes sendo eles:\n",alarmes); |
brunofgc | 0:8c59a494a451 | 1845 | |
brunofgc | 19:d52176ff683d | 1846 | for(j=0; j<alarmes; j++) { |
brunofgc | 19:d52176ff683d | 1847 | printf("Alarme %u:\n",j); |
brunofgc | 19:d52176ff683d | 1848 | printf("\tId <%lu>.\n",alarms[j].id); |
brunofgc | 19:d52176ff683d | 1849 | printf("\tSeconds <%lu>.\n",alarms[j].seconds); |
brunofgc | 19:d52176ff683d | 1850 | printf("\tAddr %u, func %u, reg %lu.\n",alarms[j].addrModbusRead,alarms[j].funcModbusRead,alarms[j].regModbusRead); |
brunofgc | 19:d52176ff683d | 1851 | if(alarms[j].type==modBusType_float) { |
brunofgc | 19:d52176ff683d | 1852 | float value; |
brunofgc | 19:d52176ff683d | 1853 | floatToBin(0,&value,&alarms[j].value[0]); |
brunofgc | 19:d52176ff683d | 1854 | if(alarms[j].max){ |
brunofgc | 19:d52176ff683d | 1855 | printf("\tFloat max <%f>.\n",value); |
brunofgc | 0:8c59a494a451 | 1856 | } |
brunofgc | 19:d52176ff683d | 1857 | else{printf("\tFloat min <%f>.\n",value);} |
brunofgc | 19:d52176ff683d | 1858 | } |
brunofgc | 19:d52176ff683d | 1859 | |
brunofgc | 19:d52176ff683d | 1860 | if(alarms[j].type==modBusType_uint32_t) { |
brunofgc | 19:d52176ff683d | 1861 | uint32_t value; |
brunofgc | 19:d52176ff683d | 1862 | uint32_t_ToBin(0,&value,&alarms[j].value[0]); |
brunofgc | 19:d52176ff683d | 1863 | if(alarms[j].max){ |
brunofgc | 19:d52176ff683d | 1864 | printf("\tuint32_t max <%lu>.\n",value); |
brunofgc | 17:c046e4b07ded | 1865 | } |
brunofgc | 19:d52176ff683d | 1866 | else{printf("\tuint32_t min <%lu>.\n",value);} |
brunofgc | 19:d52176ff683d | 1867 | } |
brunofgc | 19:d52176ff683d | 1868 | |
brunofgc | 19:d52176ff683d | 1869 | if(alarms[j].type==modBusType_uint16_t) { |
brunofgc | 19:d52176ff683d | 1870 | uint16_t value; |
brunofgc | 19:d52176ff683d | 1871 | uint16_t_ToBin(0,&value,&alarms[j].value[0]); |
brunofgc | 19:d52176ff683d | 1872 | if(alarms[j].max){ |
brunofgc | 19:d52176ff683d | 1873 | printf("\tuint16_t max <%lu>.\n",value); |
brunofgc | 19:d52176ff683d | 1874 | } |
brunofgc | 19:d52176ff683d | 1875 | else{printf("\tuint16_t min <%lu>.\n",value);} |
brunofgc | 19:d52176ff683d | 1876 | } |
brunofgc | 19:d52176ff683d | 1877 | |
brunofgc | 19:d52176ff683d | 1878 | if(alarms[j].type==modBusType_int32_t) { |
brunofgc | 19:d52176ff683d | 1879 | uint32_t value; |
brunofgc | 19:d52176ff683d | 1880 | uint32_t_ToBin(0,&value,&alarms[j].value[0]); |
brunofgc | 19:d52176ff683d | 1881 | if(alarms[j].max){ |
brunofgc | 19:d52176ff683d | 1882 | printf("\tint32_t max <%ld>.\n",(int32_t)value); |
brunofgc | 19:d52176ff683d | 1883 | } |
brunofgc | 19:d52176ff683d | 1884 | else{printf("\tint32_t min <%ld>.\n",(int32_t)value);} |
brunofgc | 0:8c59a494a451 | 1885 | } |
brunofgc | 0:8c59a494a451 | 1886 | |
brunofgc | 19:d52176ff683d | 1887 | if(alarms[j].type==modBusType_int16_t) { |
brunofgc | 19:d52176ff683d | 1888 | uint16_t value; |
brunofgc | 19:d52176ff683d | 1889 | uint16_t_ToBin(0,&value,&alarms[j].value[0]); |
brunofgc | 19:d52176ff683d | 1890 | if(alarms[j].max){ |
brunofgc | 19:d52176ff683d | 1891 | printf("\tint16_t max <%ld>.\n",(int16_t)value); |
brunofgc | 19:d52176ff683d | 1892 | } |
brunofgc | 19:d52176ff683d | 1893 | else{printf("\tint16_t min <%ld>.\n",(int16_t)value);} |
brunofgc | 19:d52176ff683d | 1894 | } |
brunofgc | 19:d52176ff683d | 1895 | |
brunofgc | 19:d52176ff683d | 1896 | if(alarms[j].type==modBusType_bit) { |
brunofgc | 19:d52176ff683d | 1897 | uint8_t value; |
brunofgc | 19:d52176ff683d | 1898 | value=alarms[j].value[0]; |
brunofgc | 19:d52176ff683d | 1899 | if(alarms[j].max){ |
brunofgc | 19:d52176ff683d | 1900 | printf("\tBIT max <%lu>.\n",value); |
brunofgc | 19:d52176ff683d | 1901 | } |
brunofgc | 19:d52176ff683d | 1902 | else{printf("\tBIT min <%lu>.\n",value);} |
brunofgc | 19:d52176ff683d | 1903 | } |
brunofgc | 4:3f92979d1ffb | 1904 | |
brunofgc | 19:d52176ff683d | 1905 | printf("\tact:%lu\n",alarms[j].idAct); |
brunofgc | 19:d52176ff683d | 1906 | } |
brunofgc | 19:d52176ff683d | 1907 | |
brunofgc | 21:19135fa28bc3 | 1908 | printf("O dispositivo tem %u schedules sendo eles:\n",numSchedules); |
brunofgc | 19:d52176ff683d | 1909 | for(j=0; j<numSchedules; j++) { |
brunofgc | 19:d52176ff683d | 1910 | printf("Schedule %u:\n",j); |
brunofgc | 19:d52176ff683d | 1911 | printf("\tId <%lu>.\n",schedules[j].id); |
brunofgc | 19:d52176ff683d | 1912 | printf("\tweekday <%lu>.\n",schedules[j].weekday); |
brunofgc | 19:d52176ff683d | 1913 | printf("\tminute <%lu>.\n",schedules[j].minute); |
brunofgc | 19:d52176ff683d | 1914 | printf("\tidAct <%lu>.\n",schedules[j].idAct); |
brunofgc | 19:d52176ff683d | 1915 | } |
brunofgc | 19:d52176ff683d | 1916 | |
brunofgc | 19:d52176ff683d | 1917 | printf("O dispositivo tem %u scheduleExceptions sendo eles:\n",numScheduleExceptions); |
brunofgc | 19:d52176ff683d | 1918 | for(j=0; j<numScheduleExceptions; j++) { |
brunofgc | 19:d52176ff683d | 1919 | printf("scheduleException %u:\n",j); |
brunofgc | 19:d52176ff683d | 1920 | printf("\tid_schedule <%lu>.\n",scheduleExceptions[j].id_schedule); |
brunofgc | 19:d52176ff683d | 1921 | printf("\ttimestamp <%lu>.\n",scheduleExceptions[j].timestamp); |
brunofgc | 19:d52176ff683d | 1922 | } |
brunofgc | 0:8c59a494a451 | 1923 | |
brunofgc | 19:d52176ff683d | 1924 | printf("O dispositivo tem %u leituras sendo elas:\n",numReadings); |
brunofgc | 19:d52176ff683d | 1925 | for(j=0; j<numReadings; j++) { |
brunofgc | 19:d52176ff683d | 1926 | printf("Leitura %u:",j); |
brunofgc | 19:d52176ff683d | 1927 | switch(readings[j].type) { |
brunofgc | 19:d52176ff683d | 1928 | case modBusType_float: |
brunofgc | 19:d52176ff683d | 1929 | printf("Tipo float "); |
brunofgc | 19:d52176ff683d | 1930 | break; |
brunofgc | 19:d52176ff683d | 1931 | case modBusType_uint32_t: |
brunofgc | 19:d52176ff683d | 1932 | printf("Tipo uint32_t "); |
brunofgc | 19:d52176ff683d | 1933 | break; |
brunofgc | 19:d52176ff683d | 1934 | case modBusType_uint16_t: |
brunofgc | 19:d52176ff683d | 1935 | printf("Tipo uint16_t "); |
brunofgc | 19:d52176ff683d | 1936 | break; |
brunofgc | 19:d52176ff683d | 1937 | case modBusType_int32_t: |
brunofgc | 19:d52176ff683d | 1938 | printf("Tipo int32_t "); |
brunofgc | 19:d52176ff683d | 1939 | break; |
brunofgc | 19:d52176ff683d | 1940 | case modBusType_int16_t: |
brunofgc | 19:d52176ff683d | 1941 | printf("Tipo int16_t "); |
brunofgc | 19:d52176ff683d | 1942 | break; |
brunofgc | 19:d52176ff683d | 1943 | case modBusType_uint8_t: |
brunofgc | 19:d52176ff683d | 1944 | printf("Tipo uint8_t "); |
brunofgc | 19:d52176ff683d | 1945 | break; |
brunofgc | 19:d52176ff683d | 1946 | case modBusType_bit: |
brunofgc | 19:d52176ff683d | 1947 | printf("Tipo bool "); |
brunofgc | 19:d52176ff683d | 1948 | break; |
brunofgc | 0:8c59a494a451 | 1949 | } |
brunofgc | 19:d52176ff683d | 1950 | printf("addr %u, func %u, reg %u, numRegs %u.\n",readings[j].addr,readings[j].func,readings[j].reg,readings[j].numRegs); |
brunofgc | 0:8c59a494a451 | 1951 | } |
brunofgc | 0:8c59a494a451 | 1952 | } |
brunofgc | 19:d52176ff683d | 1953 |