teste de publish

Dependencies:   DS1820 HighSpeedAnalogIn devices mbed

Committer:
brunofgc
Date:
Wed May 10 12:57:13 2017 +0000
Revision:
2:55b7b466e742
Parent:
0:1c0a769988ee
Child:
5:7801f913384e
Ainda com bug em configRede.htm

Who changed what in which revision?

UserRevisionLine numberNew contents of line
brunofgc 0:1c0a769988ee 1 #include "IRPack.h"
brunofgc 0:1c0a769988ee 2 //bool dataIn[maxBytesMsg*8];
brunofgc 0:1c0a769988ee 3 uint16_t bits[maxBitsMsg*2][2];
brunofgc 0:1c0a769988ee 4 int index=0,botao;
brunofgc 0:1c0a769988ee 5 int startBitAlto=0, startBitBaixo=0, bitBaixo[maxBitsMsg], bitAlto[maxBitsMsg], i;
brunofgc 0:1c0a769988ee 6 //unsigned char byte=0,msg[maxBytesMsg],msgBytes=0;
brunofgc 0:1c0a769988ee 7
brunofgc 0:1c0a769988ee 8 Timer IrTmr;
brunofgc 0:1c0a769988ee 9 Timer IrDetect;
brunofgc 0:1c0a769988ee 10 bool irInAntes=1;
brunofgc 0:1c0a769988ee 11 CircularBuffer bufIROut(maxBitsMsg*2*4);
brunofgc 0:1c0a769988ee 12
brunofgc 0:1c0a769988ee 13 //PwmOut IrOut(P1_18);
brunofgc 0:1c0a769988ee 14 DigitalIn IrIn(P1_24); //Não utilizado na placa
brunofgc 0:1c0a769988ee 15
brunofgc 0:1c0a769988ee 16 int round(float in){
brunofgc 0:1c0a769988ee 17 int x = floor(in);
brunofgc 0:1c0a769988ee 18 float y = in-x;
brunofgc 0:1c0a769988ee 19 if(y>=0.5){
brunofgc 0:1c0a769988ee 20 x++;
brunofgc 0:1c0a769988ee 21 }
brunofgc 0:1c0a769988ee 22 return x;
brunofgc 0:1c0a769988ee 23 }
brunofgc 0:1c0a769988ee 24
brunofgc 0:1c0a769988ee 25 uint16_t pulseDuration_us(bool high,DigitalIn pin,unsigned long int timeout){
brunofgc 0:1c0a769988ee 26 unsigned long int duration;
brunofgc 0:1c0a769988ee 27 IrTmr.reset();
brunofgc 0:1c0a769988ee 28 IrTmr.start();
brunofgc 0:1c0a769988ee 29
brunofgc 0:1c0a769988ee 30 do{
brunofgc 0:1c0a769988ee 31 duration = IrTmr.read_us();
brunofgc 0:1c0a769988ee 32 }while((duration < timeout) && (pin==high));
brunofgc 0:1c0a769988ee 33
brunofgc 0:1c0a769988ee 34
brunofgc 0:1c0a769988ee 35 IrTmr.stop();
brunofgc 0:1c0a769988ee 36 if(duration < timeout){
brunofgc 0:1c0a769988ee 37 return duration;
brunofgc 0:1c0a769988ee 38 }
brunofgc 0:1c0a769988ee 39 else{
brunofgc 0:1c0a769988ee 40 return 65535;
brunofgc 0:1c0a769988ee 41 }
brunofgc 0:1c0a769988ee 42 }
brunofgc 0:1c0a769988ee 43
brunofgc 0:1c0a769988ee 44
brunofgc 0:1c0a769988ee 45
brunofgc 0:1c0a769988ee 46 void enviaComandoIR(uint8_t freq,uint8_t port){
brunofgc 0:1c0a769988ee 47 float sd1Duty = SD1.read();
brunofgc 0:1c0a769988ee 48 float sd2Duty = SD2.read();
brunofgc 0:1c0a769988ee 49 float sd3Duty = SD3.read();
brunofgc 0:1c0a769988ee 50 float sd4Duty = SD4.read();
brunofgc 0:1c0a769988ee 51 float sd5Duty = SD5.read();
brunofgc 0:1c0a769988ee 52 float sd6Duty = SD6.read();
brunofgc 0:1c0a769988ee 53
brunofgc 0:1c0a769988ee 54 PwmOut *SD;
brunofgc 0:1c0a769988ee 55
brunofgc 0:1c0a769988ee 56 switch(port){
brunofgc 0:1c0a769988ee 57 case 0:
brunofgc 0:1c0a769988ee 58 SD = &SD1;
brunofgc 0:1c0a769988ee 59 break;
brunofgc 0:1c0a769988ee 60 case 1:
brunofgc 0:1c0a769988ee 61 SD = &SD2;
brunofgc 0:1c0a769988ee 62 break;
brunofgc 0:1c0a769988ee 63 case 2:
brunofgc 0:1c0a769988ee 64 SD = &SD3;
brunofgc 0:1c0a769988ee 65 break;
brunofgc 0:1c0a769988ee 66 case 3:
brunofgc 0:1c0a769988ee 67 SD = &SD4;
brunofgc 0:1c0a769988ee 68 break;
brunofgc 0:1c0a769988ee 69 case 4:
brunofgc 0:1c0a769988ee 70 SD = &SD5;
brunofgc 0:1c0a769988ee 71 break;
brunofgc 0:1c0a769988ee 72 case 5:
brunofgc 0:1c0a769988ee 73 SD = &SD6;
brunofgc 0:1c0a769988ee 74 break;
brunofgc 0:1c0a769988ee 75 }
brunofgc 0:1c0a769988ee 76
brunofgc 0:1c0a769988ee 77 SD1.write(0.0f);
brunofgc 0:1c0a769988ee 78 SD2.write(0.0f);
brunofgc 0:1c0a769988ee 79 SD3.write(0.0f);
brunofgc 0:1c0a769988ee 80 SD4.write(0.0f);
brunofgc 0:1c0a769988ee 81 SD5.write(0.0f);
brunofgc 0:1c0a769988ee 82 SD6.write(0.0f);
brunofgc 0:1c0a769988ee 83
brunofgc 0:1c0a769988ee 84 SD->period(1.0/(freq*1000.0));
brunofgc 0:1c0a769988ee 85 SD->write(0.5);
brunofgc 0:1c0a769988ee 86 if(startBitAlto!=65535){wait_us(startBitAlto);}
brunofgc 0:1c0a769988ee 87 SD->write(0.0);
brunofgc 0:1c0a769988ee 88 if(startBitBaixo!=65535){wait_us(startBitBaixo);}
brunofgc 0:1c0a769988ee 89 for(i=0;i<index;i++){
brunofgc 0:1c0a769988ee 90 SD->write(0.5);
brunofgc 0:1c0a769988ee 91 if(bitAlto[i]!=65535){wait_us(bits[i][0]);}
brunofgc 0:1c0a769988ee 92 SD->write(0.0);
brunofgc 0:1c0a769988ee 93 if(bitBaixo[i]!=65535){wait_us(bits[i][1]);}
brunofgc 0:1c0a769988ee 94 }
brunofgc 0:1c0a769988ee 95
brunofgc 0:1c0a769988ee 96 SD1.period_us(pwmPeriod);
brunofgc 0:1c0a769988ee 97 SD1.write(sd1Duty);
brunofgc 0:1c0a769988ee 98 SD2.write(sd2Duty);
brunofgc 0:1c0a769988ee 99 SD3.write(sd3Duty);
brunofgc 0:1c0a769988ee 100 SD4.write(sd4Duty);
brunofgc 0:1c0a769988ee 101 SD5.write(sd5Duty);
brunofgc 0:1c0a769988ee 102 SD6.write(sd6Duty);
brunofgc 0:1c0a769988ee 103 }
brunofgc 0:1c0a769988ee 104
brunofgc 0:1c0a769988ee 105
brunofgc 0:1c0a769988ee 106 static const long hextable[] = {
brunofgc 0:1c0a769988ee 107 [0 ... 255] = -1, // bit aligned access into this table is considerably
brunofgc 0:1c0a769988ee 108 ['0'] = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, // faster for most modern processors,
brunofgc 0:1c0a769988ee 109 ['A'] = 10, 11, 12, 13, 14, 15, // for the space conscious, reduce to
brunofgc 0:1c0a769988ee 110 ['a'] = 10, 11, 12, 13, 14, 15 // signed char.
brunofgc 0:1c0a769988ee 111 };
brunofgc 0:1c0a769988ee 112
brunofgc 0:1c0a769988ee 113 uint16_t hexdec(char *hex,uint16_t tam) {
brunofgc 0:1c0a769988ee 114 uint16_t ret = 0;
brunofgc 0:1c0a769988ee 115 uint16_t i;
brunofgc 0:1c0a769988ee 116 for(i=0;i<tam;i++){
brunofgc 0:1c0a769988ee 117 ret += hextable[hex[i]] << (i*4);
brunofgc 0:1c0a769988ee 118 }
brunofgc 0:1c0a769988ee 119 return ret;
brunofgc 0:1c0a769988ee 120 }
brunofgc 0:1c0a769988ee 121
brunofgc 0:1c0a769988ee 122
brunofgc 0:1c0a769988ee 123 void deserializaPacoteIR(char *str){
brunofgc 0:1c0a769988ee 124 uint16_t len;
brunofgc 0:1c0a769988ee 125 uint16_t i;
brunofgc 0:1c0a769988ee 126 len = strlen(str);
brunofgc 0:1c0a769988ee 127 len = len/4; //Separando de quatro em quatro pra formar um uint16_t
brunofgc 0:1c0a769988ee 128 //printf("%lu bits\n",len/2);
brunofgc 0:1c0a769988ee 129 for(i=0;i<len;i++){
brunofgc 0:1c0a769988ee 130 bits[i/2][(i%2)]=hexdec(&str[i*4],4);
brunofgc 0:1c0a769988ee 131 }
brunofgc 0:1c0a769988ee 132 /*for(i=0;i<len;i++){
brunofgc 0:1c0a769988ee 133 printf("bits[%u][%u]=%lu\n",i/2,(i%2),bits[i/2][(i%2)]);
brunofgc 0:1c0a769988ee 134 }*/
brunofgc 0:1c0a769988ee 135 index = len/2;
brunofgc 0:1c0a769988ee 136 }
brunofgc 0:1c0a769988ee 137
brunofgc 0:1c0a769988ee 138 void serializaPacoteIR(uint8_t connectionID){
brunofgc 2:55b7b466e742 139 char aux[50];
brunofgc 0:1c0a769988ee 140 uint32_t length;
brunofgc 0:1c0a769988ee 141 char *ptr;
brunofgc 0:1c0a769988ee 142 uint16_t i;
brunofgc 0:1c0a769988ee 143 union{
brunofgc 0:1c0a769988ee 144 char c[2];
brunofgc 0:1c0a769988ee 145 uint16_t v;
brunofgc 0:1c0a769988ee 146 }u;
brunofgc 2:55b7b466e742 147 sdCardBuf.del();
brunofgc 0:1c0a769988ee 148 for(i=0;i<index;i++){
brunofgc 0:1c0a769988ee 149 u.v = bits[i][0];
brunofgc 0:1c0a769988ee 150 sprintf(aux,"%01X%01X%01X%01X"
brunofgc 0:1c0a769988ee 151 ,u.c[0]&0xF
brunofgc 0:1c0a769988ee 152 ,u.c[0]>>4
brunofgc 0:1c0a769988ee 153 ,u.c[1]&0xF
brunofgc 0:1c0a769988ee 154 ,u.c[1]>>4
brunofgc 0:1c0a769988ee 155 );
brunofgc 0:1c0a769988ee 156 sdCardBuf.fill(aux,strlen(aux));
brunofgc 0:1c0a769988ee 157
brunofgc 0:1c0a769988ee 158 u.v = bits[i][1];
brunofgc 0:1c0a769988ee 159 sprintf(aux,"%01X%01X%01X%01X"
brunofgc 0:1c0a769988ee 160 ,u.c[0]&0xF
brunofgc 0:1c0a769988ee 161 ,u.c[0]>>4
brunofgc 0:1c0a769988ee 162 ,u.c[1]&0xF
brunofgc 0:1c0a769988ee 163 ,u.c[1]>>4
brunofgc 0:1c0a769988ee 164 );
brunofgc 0:1c0a769988ee 165 sdCardBuf.fill(aux,strlen(aux));
brunofgc 0:1c0a769988ee 166 }
brunofgc 0:1c0a769988ee 167 length = sdCardBuf.getLength();
brunofgc 0:1c0a769988ee 168 ptr = sdCardBuf.get();
brunofgc 0:1c0a769988ee 169 modemCom::cipSend(connID,ptr,length);
brunofgc 2:55b7b466e742 170 //pc.printf("Conteudo de sdCardBuf <%s>.\r\n",ptr);
brunofgc 0:1c0a769988ee 171 }
brunofgc 0:1c0a769988ee 172
brunofgc 0:1c0a769988ee 173 bool detectaIRIn(){
brunofgc 0:1c0a769988ee 174 bool detectado=0;
brunofgc 0:1c0a769988ee 175 if((irInAntes!=IrIn) && (!IrIn)){
brunofgc 0:1c0a769988ee 176 bits[0][0] = pulseDuration_us(0,IrIn,10000);
brunofgc 0:1c0a769988ee 177 bits[0][1] = pulseDuration_us(1,IrIn,10000);
brunofgc 0:1c0a769988ee 178 if((bits[0][0]>1000)&&(bits[0][1]>1000)){
brunofgc 0:1c0a769988ee 179 index = 1;
brunofgc 0:1c0a769988ee 180 do{
brunofgc 0:1c0a769988ee 181 bits[index][0] = pulseDuration_us(0,IrIn,10000);
brunofgc 0:1c0a769988ee 182 bits[index][1] = pulseDuration_us(1,IrIn,10000);
brunofgc 0:1c0a769988ee 183 index++;
brunofgc 0:1c0a769988ee 184
brunofgc 0:1c0a769988ee 185 }while((bits[index-1][0]!=65535)&&(bits[index-1][1]!=65535));
brunofgc 0:1c0a769988ee 186 detectado=1;
brunofgc 0:1c0a769988ee 187 }
brunofgc 0:1c0a769988ee 188 }
brunofgc 0:1c0a769988ee 189 irInAntes = IrIn;
brunofgc 0:1c0a769988ee 190 led2 = !IrIn;
brunofgc 0:1c0a769988ee 191 return detectado;
brunofgc 0:1c0a769988ee 192 }
brunofgc 0:1c0a769988ee 193
brunofgc 0:1c0a769988ee 194 void pesquisaIRIn(){
brunofgc 0:1c0a769988ee 195 if((irInAntes!=IrIn) && (!IrIn)){
brunofgc 0:1c0a769988ee 196 startBitAlto = pulseDuration_us(0,IrIn,10000);
brunofgc 0:1c0a769988ee 197 startBitBaixo = pulseDuration_us(1,IrIn,10000);
brunofgc 0:1c0a769988ee 198 if((startBitAlto>1000)&&(startBitBaixo>1000)){
brunofgc 0:1c0a769988ee 199 index = 0;
brunofgc 0:1c0a769988ee 200 do{
brunofgc 0:1c0a769988ee 201 bitAlto[index] = pulseDuration_us(0,IrIn,10000);
brunofgc 0:1c0a769988ee 202 bitBaixo[index] = pulseDuration_us(1,IrIn,10000);
brunofgc 0:1c0a769988ee 203 //dataIn[index] = (bitBaixo[index] > 1000);
brunofgc 0:1c0a769988ee 204 index++;
brunofgc 0:1c0a769988ee 205
brunofgc 0:1c0a769988ee 206 }while((bitAlto[index-1]!=(-1))&&(bitBaixo[index-1]!=(-1)));
brunofgc 0:1c0a769988ee 207
brunofgc 0:1c0a769988ee 208 pc.printf("Capturado um quadro com %lu bits. sbH %ld, sbL %ld <",index,startBitAlto, startBitBaixo);
brunofgc 0:1c0a769988ee 209 for(i=0;i<(index);i++){
brunofgc 0:1c0a769988ee 210 pc.printf("[H%ld L%ld] ",bitAlto[i],bitBaixo[i]);
brunofgc 0:1c0a769988ee 211 }
brunofgc 0:1c0a769988ee 212 pc.printf(">.\n\n");
brunofgc 0:1c0a769988ee 213
brunofgc 0:1c0a769988ee 214 /*pc.printf("%lu bits 0b",index);
brunofgc 0:1c0a769988ee 215 for(i=0;i<index;i++){
brunofgc 0:1c0a769988ee 216 pc.printf("%u",dataIn[i]);
brunofgc 0:1c0a769988ee 217 }
brunofgc 0:1c0a769988ee 218 pc.printf("\n\n");*/
brunofgc 0:1c0a769988ee 219
brunofgc 0:1c0a769988ee 220 /*//Montando os bytes;
brunofgc 0:1c0a769988ee 221 byte=0;
brunofgc 0:1c0a769988ee 222 msgBytes=0;
brunofgc 0:1c0a769988ee 223 for(i=0;i<=index;i++){
brunofgc 0:1c0a769988ee 224 if((i!=0)&&((i%8) == 0)){
brunofgc 0:1c0a769988ee 225 msg[msgBytes]=byte;
brunofgc 0:1c0a769988ee 226 msgBytes++;
brunofgc 0:1c0a769988ee 227 byte=0;
brunofgc 0:1c0a769988ee 228 }
brunofgc 0:1c0a769988ee 229 byte+= dataIn[i]<<(i%8);
brunofgc 0:1c0a769988ee 230
brunofgc 0:1c0a769988ee 231 }
brunofgc 0:1c0a769988ee 232
brunofgc 0:1c0a769988ee 233 //Exibindo pacote
brunofgc 0:1c0a769988ee 234 pc.printf("Resultado 0x");
brunofgc 0:1c0a769988ee 235 for(i=0;i<msgBytes;i++){
brunofgc 0:1c0a769988ee 236 pc.printf("%02X",msg[i]);
brunofgc 0:1c0a769988ee 237 }
brunofgc 0:1c0a769988ee 238 pc.printf("\n\n");
brunofgc 0:1c0a769988ee 239
brunofgc 0:1c0a769988ee 240 //Atuando nos leds
brunofgc 0:1c0a769988ee 241 botao=0;
brunofgc 0:1c0a769988ee 242 for(i=0;i<msgBytes;i++){
brunofgc 0:1c0a769988ee 243 botao+=msg[i]<<(8*i);
brunofgc 0:1c0a769988ee 244
brunofgc 0:1c0a769988ee 245 }
brunofgc 0:1c0a769988ee 246 //pc.printf("Botao pressionado %X\n",botao);
brunofgc 0:1c0a769988ee 247 switch(botao){
brunofgc 0:1c0a769988ee 248 case 0xfb040707: //1
brunofgc 0:1c0a769988ee 249 led2=1;
brunofgc 0:1c0a769988ee 250 break;
brunofgc 0:1c0a769988ee 251 case 0xfa050707: //2
brunofgc 0:1c0a769988ee 252 led3=1;
brunofgc 0:1c0a769988ee 253 break;
brunofgc 0:1c0a769988ee 254 case 0xf9060707: //3
brunofgc 0:1c0a769988ee 255 led4=1;
brunofgc 0:1c0a769988ee 256 break;
brunofgc 0:1c0a769988ee 257 case 0xf7080707: //4
brunofgc 0:1c0a769988ee 258 led2=0;
brunofgc 0:1c0a769988ee 259 break;
brunofgc 0:1c0a769988ee 260 case 0xf6090707: //5
brunofgc 0:1c0a769988ee 261 led3=0;
brunofgc 0:1c0a769988ee 262 break;
brunofgc 0:1c0a769988ee 263 case 0xf50a0707: //6
brunofgc 0:1c0a769988ee 264 led4=0;
brunofgc 0:1c0a769988ee 265 break;
brunofgc 0:1c0a769988ee 266 }*/
brunofgc 0:1c0a769988ee 267 //descritorPacoteIR(int startBitAlto, int startBitBaixo, int *bitAlto, int *bitBaixo, int numBits)
brunofgc 0:1c0a769988ee 268 //descritorPacoteIR(startBitAlto,startBitBaixo,bitAlto,bitBaixo,index);
brunofgc 0:1c0a769988ee 269 }
brunofgc 0:1c0a769988ee 270 }
brunofgc 0:1c0a769988ee 271 irInAntes = IrIn;
brunofgc 0:1c0a769988ee 272 led2 = !IrIn;
brunofgc 0:1c0a769988ee 273 }
brunofgc 0:1c0a769988ee 274
brunofgc 0:1c0a769988ee 275 /*
brunofgc 0:1c0a769988ee 276
brunofgc 0:1c0a769988ee 277 float razaoBit(int iH, int iL){
brunofgc 0:1c0a769988ee 278 float H=(float)iH,L=(float)iL;
brunofgc 0:1c0a769988ee 279 float razao = L/H;
brunofgc 0:1c0a769988ee 280
brunofgc 0:1c0a769988ee 281 if(razao>=1){
brunofgc 0:1c0a769988ee 282 return (float) round(razao);
brunofgc 0:1c0a769988ee 283 }else if(razao>=0.5){
brunofgc 0:1c0a769988ee 284 return 0.5;
brunofgc 0:1c0a769988ee 285 }else if(razao>=0.25){
brunofgc 0:1c0a769988ee 286 return 0.25;
brunofgc 0:1c0a769988ee 287 }else if(razao>=0.125){
brunofgc 0:1c0a769988ee 288 return 0.125;
brunofgc 0:1c0a769988ee 289 }else{
brunofgc 0:1c0a769988ee 290 return -1;
brunofgc 0:1c0a769988ee 291 }
brunofgc 0:1c0a769988ee 292
brunofgc 0:1c0a769988ee 293 }
brunofgc 0:1c0a769988ee 294
brunofgc 0:1c0a769988ee 295 void descritorPacoteIR(int startBitAlto, int startBitBaixo, int *bitAlto, int *bitBaixo, int numBits){
brunofgc 0:1c0a769988ee 296 unsigned int razao_maiorQue4=0;
brunofgc 0:1c0a769988ee 297 unsigned int razao_4=0;
brunofgc 0:1c0a769988ee 298 unsigned int razao_3=0;
brunofgc 0:1c0a769988ee 299 unsigned int razao_2=0;
brunofgc 0:1c0a769988ee 300 unsigned int razao_1=0;
brunofgc 0:1c0a769988ee 301 unsigned int razao_0_5=0;
brunofgc 0:1c0a769988ee 302 unsigned int razao_0_25=0;
brunofgc 0:1c0a769988ee 303 unsigned int razao_0_125=0;
brunofgc 0:1c0a769988ee 304 unsigned int razao_menorQue_0_125=0;
brunofgc 0:1c0a769988ee 305
brunofgc 0:1c0a769988ee 306 //Indice 0 ALto, 1 Baixo;
brunofgc 0:1c0a769988ee 307 unsigned long int bitRazao_maiorQue4[2]= {0,0};
brunofgc 0:1c0a769988ee 308 unsigned long int bitRazao_4[2]= {0,0};
brunofgc 0:1c0a769988ee 309 unsigned long int bitRazao_3[2]= {0,0};
brunofgc 0:1c0a769988ee 310 unsigned long int bitRazao_2[2]= {0,0};
brunofgc 0:1c0a769988ee 311 unsigned long int bitRazao_1[2]= {0,0};
brunofgc 0:1c0a769988ee 312 unsigned long int bitRazao_0_5[2]= {0,0};
brunofgc 0:1c0a769988ee 313 unsigned long int bitRazao_0_25[2]= {0,0};
brunofgc 0:1c0a769988ee 314 unsigned long int bitRazao_0_125[2]= {0,0};
brunofgc 0:1c0a769988ee 315 unsigned long int bitRazao_menorQue_0_125[2]= {0,0};
brunofgc 0:1c0a769988ee 316
brunofgc 0:1c0a769988ee 317 unsigned long int indiceMaiorNEventos[2] = {0,0};
brunofgc 0:1c0a769988ee 318 unsigned long int indiceSegundoMaiorNEventos[2] = {0,0};
brunofgc 0:1c0a769988ee 319
brunofgc 0:1c0a769988ee 320
brunofgc 0:1c0a769988ee 321
brunofgc 0:1c0a769988ee 322 unsigned int bitAlto_H=0;
brunofgc 0:1c0a769988ee 323 unsigned int bitAlto_L=0;
brunofgc 0:1c0a769988ee 324 unsigned int bitBaixo_H=0;
brunofgc 0:1c0a769988ee 325 unsigned int bitBaixo_L=0;
brunofgc 0:1c0a769988ee 326
brunofgc 0:1c0a769988ee 327 unsigned int stopBitAlto = bitAlto[numBits-1];
brunofgc 0:1c0a769988ee 328
brunofgc 0:1c0a769988ee 329 int i;
brunofgc 0:1c0a769988ee 330
brunofgc 0:1c0a769988ee 331 //printf("startBitAlto %d, startBitBaixo %d, stopBitAlto %d, stopBitBaixo %d numBits %d\n",startBitAlto,startBitBaixo,bitAlto[numBits-1],bitBaixo[numBits-1],numBits);
brunofgc 0:1c0a769988ee 332
brunofgc 0:1c0a769988ee 333 //Despresando o stopBit pois esse já sabemos como faz
brunofgc 0:1c0a769988ee 334 for(i=0;i<numBits-1;i++){
brunofgc 0:1c0a769988ee 335 //printf("Razao entre [L %05d e H %05d]=%1.2f\n",bitBaixo[i],bitAlto[i],razaoBit(bitAlto[i],bitBaixo[i]));
brunofgc 0:1c0a769988ee 336 //Detecção de padroes
brunofgc 0:1c0a769988ee 337 if(razaoBit(bitAlto[i],bitBaixo[i])>=4){
brunofgc 0:1c0a769988ee 338 razao_maiorQue4++;
brunofgc 0:1c0a769988ee 339 bitRazao_maiorQue4[0]+= bitAlto[i];
brunofgc 0:1c0a769988ee 340 bitRazao_maiorQue4[1]+=bitBaixo[i];
brunofgc 0:1c0a769988ee 341
brunofgc 0:1c0a769988ee 342 }else if(razaoBit(bitAlto[i],bitBaixo[i])==4){
brunofgc 0:1c0a769988ee 343 razao_4++;
brunofgc 0:1c0a769988ee 344 bitRazao_4[0]+= bitAlto[i];
brunofgc 0:1c0a769988ee 345 bitRazao_4[1]+=bitBaixo[i];
brunofgc 0:1c0a769988ee 346 }else if(razaoBit(bitAlto[i],bitBaixo[i])==3){
brunofgc 0:1c0a769988ee 347 razao_3++;
brunofgc 0:1c0a769988ee 348 bitRazao_3[0]+= bitAlto[i];
brunofgc 0:1c0a769988ee 349 bitRazao_3[1]+=bitBaixo[i];
brunofgc 0:1c0a769988ee 350 }else if(razaoBit(bitAlto[i],bitBaixo[i])==2){
brunofgc 0:1c0a769988ee 351 razao_2++;
brunofgc 0:1c0a769988ee 352 bitRazao_2[0]+= bitAlto[i];
brunofgc 0:1c0a769988ee 353 bitRazao_2[1]+=bitBaixo[i];
brunofgc 0:1c0a769988ee 354 }else if(razaoBit(bitAlto[i],bitBaixo[i])==1){
brunofgc 0:1c0a769988ee 355 razao_1++;
brunofgc 0:1c0a769988ee 356 bitRazao_1[0]+= bitAlto[i];
brunofgc 0:1c0a769988ee 357 bitRazao_1[1]+=bitBaixo[i];
brunofgc 0:1c0a769988ee 358 }else if(razaoBit(bitAlto[i],bitBaixo[i])==0.5){
brunofgc 0:1c0a769988ee 359 razao_0_5++;
brunofgc 0:1c0a769988ee 360 bitRazao_0_5[0]+= bitAlto[i];
brunofgc 0:1c0a769988ee 361 bitRazao_0_5[1]+=bitBaixo[i];
brunofgc 0:1c0a769988ee 362 }else if(razaoBit(bitAlto[i],bitBaixo[i])==0.25){
brunofgc 0:1c0a769988ee 363 razao_0_25++;
brunofgc 0:1c0a769988ee 364 bitRazao_0_25[0]+= bitAlto[i];
brunofgc 0:1c0a769988ee 365 bitRazao_0_25[1]+=bitBaixo[i];
brunofgc 0:1c0a769988ee 366 }else if(razaoBit(bitAlto[i],bitBaixo[i])==0.125){
brunofgc 0:1c0a769988ee 367 razao_0_125++;
brunofgc 0:1c0a769988ee 368 bitRazao_0_125[0]+= bitAlto[i];
brunofgc 0:1c0a769988ee 369 bitRazao_0_125[1]+=bitBaixo[i];
brunofgc 0:1c0a769988ee 370 }else {
brunofgc 0:1c0a769988ee 371 razao_menorQue_0_125++;
brunofgc 0:1c0a769988ee 372 bitRazao_menorQue_0_125[0]+= bitAlto[i];
brunofgc 0:1c0a769988ee 373 bitRazao_menorQue_0_125[1]+=bitBaixo[i];
brunofgc 0:1c0a769988ee 374 }
brunofgc 0:1c0a769988ee 375
brunofgc 0:1c0a769988ee 376 }
brunofgc 0:1c0a769988ee 377 printf("Razoes <0.125 = %d\n 0.125 = %d\n 0.25 = %d\n 0.5 = %d\n 1 = %d\n 2 = %d\n 3 = %d\n 4 = %d\n maior que 4 = %d\n"
brunofgc 0:1c0a769988ee 378 ,razao_menorQue_0_125
brunofgc 0:1c0a769988ee 379 ,razao_0_125
brunofgc 0:1c0a769988ee 380 ,razao_0_25
brunofgc 0:1c0a769988ee 381 ,razao_0_5
brunofgc 0:1c0a769988ee 382 ,razao_1
brunofgc 0:1c0a769988ee 383 ,razao_2
brunofgc 0:1c0a769988ee 384 ,razao_3
brunofgc 0:1c0a769988ee 385 ,razao_4
brunofgc 0:1c0a769988ee 386 ,razao_maiorQue4
brunofgc 0:1c0a769988ee 387 );
brunofgc 0:1c0a769988ee 388
brunofgc 0:1c0a769988ee 389 //Buscando os dois maiores em numero de eventos por Indice;
brunofgc 0:1c0a769988ee 390 //Buscando o primeiro
brunofgc 0:1c0a769988ee 391 for(i=0;i<9;i++){
brunofgc 0:1c0a769988ee 392 //Buscando nos indices maior numero eventos
brunofgc 0:1c0a769988ee 393 switch(i){
brunofgc 0:1c0a769988ee 394 case 0:
brunofgc 0:1c0a769988ee 395 if(razao_maiorQue4>indiceMaiorNEventos[0]){
brunofgc 0:1c0a769988ee 396 indiceMaiorNEventos[0] = razao_maiorQue4;
brunofgc 0:1c0a769988ee 397 indiceMaiorNEventos[1] = i;
brunofgc 0:1c0a769988ee 398 }
brunofgc 0:1c0a769988ee 399 break;
brunofgc 0:1c0a769988ee 400
brunofgc 0:1c0a769988ee 401 case 1:
brunofgc 0:1c0a769988ee 402 if(razao_4>indiceMaiorNEventos[0]){
brunofgc 0:1c0a769988ee 403 indiceMaiorNEventos[0] = razao_4;
brunofgc 0:1c0a769988ee 404 indiceMaiorNEventos[1] = i;
brunofgc 0:1c0a769988ee 405 }
brunofgc 0:1c0a769988ee 406 break;
brunofgc 0:1c0a769988ee 407 case 2:
brunofgc 0:1c0a769988ee 408 if(razao_3>indiceMaiorNEventos[0]){
brunofgc 0:1c0a769988ee 409 indiceMaiorNEventos[0] = razao_3;
brunofgc 0:1c0a769988ee 410 indiceMaiorNEventos[1] = i;
brunofgc 0:1c0a769988ee 411 }
brunofgc 0:1c0a769988ee 412 break;
brunofgc 0:1c0a769988ee 413 case 3:
brunofgc 0:1c0a769988ee 414 if(razao_2>indiceMaiorNEventos[0]){
brunofgc 0:1c0a769988ee 415 indiceMaiorNEventos[0] = razao_2;
brunofgc 0:1c0a769988ee 416 indiceMaiorNEventos[1] = i;
brunofgc 0:1c0a769988ee 417 }
brunofgc 0:1c0a769988ee 418 break;
brunofgc 0:1c0a769988ee 419 case 4:
brunofgc 0:1c0a769988ee 420 if(razao_1>indiceMaiorNEventos[0]){
brunofgc 0:1c0a769988ee 421 indiceMaiorNEventos[0] = razao_1;
brunofgc 0:1c0a769988ee 422 indiceMaiorNEventos[1] = i;
brunofgc 0:1c0a769988ee 423 }
brunofgc 0:1c0a769988ee 424 break;
brunofgc 0:1c0a769988ee 425 case 5:
brunofgc 0:1c0a769988ee 426 if(razao_0_5>indiceMaiorNEventos[0]){
brunofgc 0:1c0a769988ee 427 indiceMaiorNEventos[0] = razao_0_5;
brunofgc 0:1c0a769988ee 428 indiceMaiorNEventos[1] = i;
brunofgc 0:1c0a769988ee 429 }
brunofgc 0:1c0a769988ee 430 break;
brunofgc 0:1c0a769988ee 431 case 6:
brunofgc 0:1c0a769988ee 432 if(razao_0_25>indiceMaiorNEventos[0]){
brunofgc 0:1c0a769988ee 433 indiceMaiorNEventos[0] = razao_0_25;
brunofgc 0:1c0a769988ee 434 indiceMaiorNEventos[1] = i;
brunofgc 0:1c0a769988ee 435 }
brunofgc 0:1c0a769988ee 436 break;
brunofgc 0:1c0a769988ee 437 case 7:
brunofgc 0:1c0a769988ee 438 if(razao_0_125>indiceMaiorNEventos[0]){
brunofgc 0:1c0a769988ee 439 indiceMaiorNEventos[0] = razao_0_125;
brunofgc 0:1c0a769988ee 440 indiceMaiorNEventos[1] = i;
brunofgc 0:1c0a769988ee 441 }
brunofgc 0:1c0a769988ee 442 break;
brunofgc 0:1c0a769988ee 443 case 8:
brunofgc 0:1c0a769988ee 444 if(razao_menorQue_0_125>indiceMaiorNEventos[0]){
brunofgc 0:1c0a769988ee 445 indiceMaiorNEventos[0] = razao_menorQue_0_125;
brunofgc 0:1c0a769988ee 446 indiceMaiorNEventos[1] = i;
brunofgc 0:1c0a769988ee 447 }
brunofgc 0:1c0a769988ee 448 break;
brunofgc 0:1c0a769988ee 449
brunofgc 0:1c0a769988ee 450 }
brunofgc 0:1c0a769988ee 451 }
brunofgc 0:1c0a769988ee 452
brunofgc 0:1c0a769988ee 453 //Buscando o segundo
brunofgc 0:1c0a769988ee 454 //Buscando o primeiro
brunofgc 0:1c0a769988ee 455 for(i=0;i<9;i++){
brunofgc 0:1c0a769988ee 456 //Buscando nos indices maior numero eventos
brunofgc 0:1c0a769988ee 457 if(i!=indiceMaiorNEventos[1]){
brunofgc 0:1c0a769988ee 458 switch(i){
brunofgc 0:1c0a769988ee 459 case 0:
brunofgc 0:1c0a769988ee 460 if(razao_maiorQue4>indiceSegundoMaiorNEventos[0]){
brunofgc 0:1c0a769988ee 461 indiceSegundoMaiorNEventos[0] = razao_maiorQue4;
brunofgc 0:1c0a769988ee 462 indiceSegundoMaiorNEventos[1] = i;
brunofgc 0:1c0a769988ee 463 }
brunofgc 0:1c0a769988ee 464 break;
brunofgc 0:1c0a769988ee 465
brunofgc 0:1c0a769988ee 466 case 1:
brunofgc 0:1c0a769988ee 467 if(razao_4>indiceSegundoMaiorNEventos[0]){
brunofgc 0:1c0a769988ee 468 indiceSegundoMaiorNEventos[0] = razao_4;
brunofgc 0:1c0a769988ee 469 indiceSegundoMaiorNEventos[1] = i;
brunofgc 0:1c0a769988ee 470 }
brunofgc 0:1c0a769988ee 471 break;
brunofgc 0:1c0a769988ee 472 case 2:
brunofgc 0:1c0a769988ee 473 if(razao_3>indiceSegundoMaiorNEventos[0]){
brunofgc 0:1c0a769988ee 474 indiceSegundoMaiorNEventos[0] = razao_3;
brunofgc 0:1c0a769988ee 475 indiceSegundoMaiorNEventos[1] = i;
brunofgc 0:1c0a769988ee 476 }
brunofgc 0:1c0a769988ee 477 break;
brunofgc 0:1c0a769988ee 478 case 3:
brunofgc 0:1c0a769988ee 479 if(razao_2>indiceSegundoMaiorNEventos[0]){
brunofgc 0:1c0a769988ee 480 indiceSegundoMaiorNEventos[0] = razao_2;
brunofgc 0:1c0a769988ee 481 indiceSegundoMaiorNEventos[1] = i;
brunofgc 0:1c0a769988ee 482 }
brunofgc 0:1c0a769988ee 483 break;
brunofgc 0:1c0a769988ee 484 case 4:
brunofgc 0:1c0a769988ee 485 if(razao_1>indiceSegundoMaiorNEventos[0]){
brunofgc 0:1c0a769988ee 486 indiceSegundoMaiorNEventos[0] = razao_1;
brunofgc 0:1c0a769988ee 487 indiceSegundoMaiorNEventos[1] = i;
brunofgc 0:1c0a769988ee 488 }
brunofgc 0:1c0a769988ee 489 break;
brunofgc 0:1c0a769988ee 490 case 5:
brunofgc 0:1c0a769988ee 491 if(razao_0_5>indiceSegundoMaiorNEventos[0]){
brunofgc 0:1c0a769988ee 492 indiceSegundoMaiorNEventos[0] = razao_0_5;
brunofgc 0:1c0a769988ee 493 indiceSegundoMaiorNEventos[1] = i;
brunofgc 0:1c0a769988ee 494 }
brunofgc 0:1c0a769988ee 495 break;
brunofgc 0:1c0a769988ee 496 case 6:
brunofgc 0:1c0a769988ee 497 if(razao_0_25>indiceSegundoMaiorNEventos[0]){
brunofgc 0:1c0a769988ee 498 indiceSegundoMaiorNEventos[0] = razao_0_25;
brunofgc 0:1c0a769988ee 499 indiceSegundoMaiorNEventos[1] = i;
brunofgc 0:1c0a769988ee 500 }
brunofgc 0:1c0a769988ee 501 break;
brunofgc 0:1c0a769988ee 502 case 7:
brunofgc 0:1c0a769988ee 503 if(razao_0_125>indiceSegundoMaiorNEventos[0]){
brunofgc 0:1c0a769988ee 504 indiceSegundoMaiorNEventos[0] = razao_0_125;
brunofgc 0:1c0a769988ee 505 indiceSegundoMaiorNEventos[1] = i;
brunofgc 0:1c0a769988ee 506 }
brunofgc 0:1c0a769988ee 507 break;
brunofgc 0:1c0a769988ee 508 case 8:
brunofgc 0:1c0a769988ee 509 if(razao_menorQue_0_125>indiceSegundoMaiorNEventos[0]){
brunofgc 0:1c0a769988ee 510 indiceSegundoMaiorNEventos[0] = razao_menorQue_0_125;
brunofgc 0:1c0a769988ee 511 indiceSegundoMaiorNEventos[1] = i;
brunofgc 0:1c0a769988ee 512 }
brunofgc 0:1c0a769988ee 513 break;
brunofgc 0:1c0a769988ee 514
brunofgc 0:1c0a769988ee 515 }
brunofgc 0:1c0a769988ee 516 }
brunofgc 0:1c0a769988ee 517 }
brunofgc 0:1c0a769988ee 518
brunofgc 0:1c0a769988ee 519
brunofgc 0:1c0a769988ee 520 //printf("Indice de maior aparecimento foi o de %d.\nIndice de segundo maior aparecimento foi o de %d.\n",indiceMaiorNEventos[1],indiceSegundoMaiorNEventos[1]);
brunofgc 0:1c0a769988ee 521
brunofgc 0:1c0a769988ee 522 //Calculando bitAlto
brunofgc 0:1c0a769988ee 523 switch(indiceMaiorNEventos[1]){
brunofgc 0:1c0a769988ee 524 case 0:
brunofgc 0:1c0a769988ee 525 bitAlto_H = round(bitRazao_maiorQue4[0]/indiceMaiorNEventos[0]);
brunofgc 0:1c0a769988ee 526 bitAlto_L = round(bitRazao_maiorQue4[1]/indiceMaiorNEventos[0]);
brunofgc 0:1c0a769988ee 527 break;
brunofgc 0:1c0a769988ee 528 case 1:
brunofgc 0:1c0a769988ee 529 bitAlto_H = round(bitRazao_4[0]/indiceMaiorNEventos[0]);
brunofgc 0:1c0a769988ee 530 bitAlto_L = round(bitRazao_4[1]/indiceMaiorNEventos[0]);
brunofgc 0:1c0a769988ee 531 break;
brunofgc 0:1c0a769988ee 532 case 2:
brunofgc 0:1c0a769988ee 533 bitAlto_H = round(bitRazao_3[0]/indiceMaiorNEventos[0]);
brunofgc 0:1c0a769988ee 534 bitAlto_L = round(bitRazao_3[1]/indiceMaiorNEventos[0]);
brunofgc 0:1c0a769988ee 535 break;
brunofgc 0:1c0a769988ee 536 case 3:
brunofgc 0:1c0a769988ee 537 bitAlto_H = round(bitRazao_2[0]/indiceMaiorNEventos[0]);
brunofgc 0:1c0a769988ee 538 bitAlto_L = round(bitRazao_2[1]/indiceMaiorNEventos[0]);
brunofgc 0:1c0a769988ee 539 break;
brunofgc 0:1c0a769988ee 540 case 4:
brunofgc 0:1c0a769988ee 541 bitAlto_H = round(bitRazao_1[0]/indiceMaiorNEventos[0]);
brunofgc 0:1c0a769988ee 542 bitAlto_L = round(bitRazao_1[1]/indiceMaiorNEventos[0]);
brunofgc 0:1c0a769988ee 543 break;
brunofgc 0:1c0a769988ee 544 case 5:
brunofgc 0:1c0a769988ee 545 bitAlto_H = round(bitRazao_0_5[0]/indiceMaiorNEventos[0]);
brunofgc 0:1c0a769988ee 546 bitAlto_L = round(bitRazao_0_5[1]/indiceMaiorNEventos[0]);
brunofgc 0:1c0a769988ee 547 break;
brunofgc 0:1c0a769988ee 548 case 6:
brunofgc 0:1c0a769988ee 549 bitAlto_H = round(bitRazao_0_25[0]/indiceMaiorNEventos[0]);
brunofgc 0:1c0a769988ee 550 bitAlto_L = round(bitRazao_0_25[1]/indiceMaiorNEventos[0]);
brunofgc 0:1c0a769988ee 551 break;
brunofgc 0:1c0a769988ee 552 case 7:
brunofgc 0:1c0a769988ee 553 bitAlto_H = round(bitRazao_0_125[0]/indiceMaiorNEventos[0]);
brunofgc 0:1c0a769988ee 554 bitAlto_L = round(bitRazao_0_125[1]/indiceMaiorNEventos[0]);
brunofgc 0:1c0a769988ee 555 break;
brunofgc 0:1c0a769988ee 556 case 8:
brunofgc 0:1c0a769988ee 557 bitAlto_H = round(bitRazao_menorQue_0_125[0]/indiceMaiorNEventos[0]);
brunofgc 0:1c0a769988ee 558 bitAlto_L = round(bitRazao_menorQue_0_125[1]/indiceMaiorNEventos[0]);
brunofgc 0:1c0a769988ee 559 break;
brunofgc 0:1c0a769988ee 560 }
brunofgc 0:1c0a769988ee 561
brunofgc 0:1c0a769988ee 562 //Calculando bitBaixo
brunofgc 0:1c0a769988ee 563 switch(indiceSegundoMaiorNEventos[1]){
brunofgc 0:1c0a769988ee 564 case 0:
brunofgc 0:1c0a769988ee 565 bitBaixo_H = round(bitRazao_maiorQue4[0]/indiceSegundoMaiorNEventos[0]);
brunofgc 0:1c0a769988ee 566 bitBaixo_L = round(bitRazao_maiorQue4[1]/indiceSegundoMaiorNEventos[0]);
brunofgc 0:1c0a769988ee 567 break;
brunofgc 0:1c0a769988ee 568 case 1:
brunofgc 0:1c0a769988ee 569 bitBaixo_H = round(bitRazao_4[0]/indiceSegundoMaiorNEventos[0]);
brunofgc 0:1c0a769988ee 570 bitBaixo_L = round(bitRazao_4[1]/indiceSegundoMaiorNEventos[0]);
brunofgc 0:1c0a769988ee 571 break;
brunofgc 0:1c0a769988ee 572 case 2:
brunofgc 0:1c0a769988ee 573 bitBaixo_H = round(bitRazao_3[0]/indiceSegundoMaiorNEventos[0]);
brunofgc 0:1c0a769988ee 574 bitBaixo_L = round(bitRazao_3[1]/indiceSegundoMaiorNEventos[0]);
brunofgc 0:1c0a769988ee 575 break;
brunofgc 0:1c0a769988ee 576 case 3:
brunofgc 0:1c0a769988ee 577 bitBaixo_H = round(bitRazao_2[0]/indiceSegundoMaiorNEventos[0]);
brunofgc 0:1c0a769988ee 578 bitBaixo_L = round(bitRazao_2[1]/indiceSegundoMaiorNEventos[0]);
brunofgc 0:1c0a769988ee 579 break;
brunofgc 0:1c0a769988ee 580 case 4:
brunofgc 0:1c0a769988ee 581 bitBaixo_H = round(bitRazao_1[0]/indiceSegundoMaiorNEventos[0]);
brunofgc 0:1c0a769988ee 582 bitBaixo_L = round(bitRazao_1[1]/indiceSegundoMaiorNEventos[0]);
brunofgc 0:1c0a769988ee 583 break;
brunofgc 0:1c0a769988ee 584 case 5:
brunofgc 0:1c0a769988ee 585 bitBaixo_H = round(bitRazao_0_5[0]/indiceSegundoMaiorNEventos[0]);
brunofgc 0:1c0a769988ee 586 bitBaixo_L = round(bitRazao_0_5[1]/indiceSegundoMaiorNEventos[0]);
brunofgc 0:1c0a769988ee 587 break;
brunofgc 0:1c0a769988ee 588 case 6:
brunofgc 0:1c0a769988ee 589 bitBaixo_H = round(bitRazao_0_25[0]/indiceSegundoMaiorNEventos[0]);
brunofgc 0:1c0a769988ee 590 bitBaixo_L = round(bitRazao_0_25[1]/indiceSegundoMaiorNEventos[0]);
brunofgc 0:1c0a769988ee 591 break;
brunofgc 0:1c0a769988ee 592 case 7:
brunofgc 0:1c0a769988ee 593 bitBaixo_H = round(bitRazao_0_125[0]/indiceSegundoMaiorNEventos[0]);
brunofgc 0:1c0a769988ee 594 bitBaixo_L = round(bitRazao_0_125[1]/indiceSegundoMaiorNEventos[0]);
brunofgc 0:1c0a769988ee 595 break;
brunofgc 0:1c0a769988ee 596 case 8:
brunofgc 0:1c0a769988ee 597 bitBaixo_H = round(bitRazao_menorQue_0_125[0]/indiceSegundoMaiorNEventos[0]);
brunofgc 0:1c0a769988ee 598 bitBaixo_L = round(bitRazao_menorQue_0_125[1]/indiceSegundoMaiorNEventos[0]);
brunofgc 0:1c0a769988ee 599 break;
brunofgc 0:1c0a769988ee 600 }
brunofgc 0:1c0a769988ee 601
brunofgc 0:1c0a769988ee 602 printf("\n\nFinalmente.\n");
brunofgc 0:1c0a769988ee 603 printf("startBitAlto = %ld, startBitBaixo = %ld\n", startBitAlto,startBitBaixo);
brunofgc 0:1c0a769988ee 604 printf("bitAlto_H = %ld bitAlto_l = %ld\n",bitAlto_H,bitAlto_L);
brunofgc 0:1c0a769988ee 605 printf("bitBaixo_H = %ld bitBaixo_l = %ld\n",bitBaixo_H,bitBaixo_L);
brunofgc 0:1c0a769988ee 606 printf("stopBitAlto = %ld\n",stopBitAlto);
brunofgc 0:1c0a769988ee 607
brunofgc 0:1c0a769988ee 608 return;
brunofgc 0:1c0a769988ee 609 }*/