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