teste de publish

Committer:
brunofgc
Date:
Fri Jun 02 13:22:07 2017 +0000
Revision:
3:75223647cf3d
Parent:
2:ca3723da6668
Child:
4:3f92979d1ffb
Vers?o est?vel instalada no arcondicionado AP201. Preparando para adi??o de exce??es de agendamentos.

Who changed what in which revision?

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