teste de publish
Dependencies: DS1820 HighSpeedAnalogIn devices mbed
IRPack.cpp@6:d4ebbaaba295, 2017-06-15 (annotated)
- Committer:
- brunofgc
- Date:
- Thu Jun 15 12:50:58 2017 +0000
- Revision:
- 6:d4ebbaaba295
- Parent:
- 5:7801f913384e
- Child:
- 7:ae9c47f62946
Ultima vers?o antes da adi??o de Exce??es de calend?rio e persist?ncias
Who changed what in which revision?
User | Revision | Line number | New 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 | 5:7801f913384e | 4 | int indexIr=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 | 6:d4ebbaaba295 | 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 | 5:7801f913384e | 52 | float sd6Duty = SD6.read(); |
brunofgc | 5:7801f913384e | 53 | float frequencia = freq*1000.0; |
brunofgc | 6:d4ebbaaba295 | 54 | float periodo = 1000000.0/frequencia; |
brunofgc | 6:d4ebbaaba295 | 55 | PwmOut *SD; |
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 | 6:d4ebbaaba295 | 84 | //pc.printf("Enviando o pacote IR na porta %lu com periodo %f e frequencia %f.\r\n",port,periodo,frequencia); |
brunofgc | 5:7801f913384e | 85 | |
brunofgc | 5:7801f913384e | 86 | //SD->period(1.0/(freq*1000.0)); |
brunofgc | 6:d4ebbaaba295 | 87 | SD->period_us(periodo); |
brunofgc | 5:7801f913384e | 88 | |
brunofgc | 5:7801f913384e | 89 | pc.printf("Iniciando o envio IR.\r\n"); |
brunofgc | 5:7801f913384e | 90 | |
brunofgc | 6:d4ebbaaba295 | 91 | /*SD->write(0.5); |
brunofgc | 0:1c0a769988ee | 92 | if(startBitAlto!=65535){wait_us(startBitAlto);} |
brunofgc | 0:1c0a769988ee | 93 | SD->write(0.0); |
brunofgc | 6:d4ebbaaba295 | 94 | if(startBitBaixo!=65535){wait_us(startBitBaixo);}*/ |
brunofgc | 5:7801f913384e | 95 | for(i=0;i<indexIr;i++){ |
brunofgc | 0:1c0a769988ee | 96 | SD->write(0.5); |
brunofgc | 0:1c0a769988ee | 97 | if(bitAlto[i]!=65535){wait_us(bits[i][0]);} |
brunofgc | 0:1c0a769988ee | 98 | SD->write(0.0); |
brunofgc | 0:1c0a769988ee | 99 | if(bitBaixo[i]!=65535){wait_us(bits[i][1]);} |
brunofgc | 0:1c0a769988ee | 100 | } |
brunofgc | 6:d4ebbaaba295 | 101 | |
brunofgc | 5:7801f913384e | 102 | pc.printf("Finalizado o envio IR.\r\n"); |
brunofgc | 0:1c0a769988ee | 103 | SD1.period_us(pwmPeriod); |
brunofgc | 0:1c0a769988ee | 104 | SD1.write(sd1Duty); |
brunofgc | 0:1c0a769988ee | 105 | SD2.write(sd2Duty); |
brunofgc | 0:1c0a769988ee | 106 | SD3.write(sd3Duty); |
brunofgc | 0:1c0a769988ee | 107 | SD4.write(sd4Duty); |
brunofgc | 0:1c0a769988ee | 108 | SD5.write(sd5Duty); |
brunofgc | 6:d4ebbaaba295 | 109 | SD6.write(sd6Duty); |
brunofgc | 6:d4ebbaaba295 | 110 | |
brunofgc | 0:1c0a769988ee | 111 | } |
brunofgc | 0:1c0a769988ee | 112 | |
brunofgc | 0:1c0a769988ee | 113 | |
brunofgc | 5:7801f913384e | 114 | /*static const long hextable[] = { |
brunofgc | 0:1c0a769988ee | 115 | [0 ... 255] = -1, // bit aligned access into this table is considerably |
brunofgc | 0:1c0a769988ee | 116 | ['0'] = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, // faster for most modern processors, |
brunofgc | 0:1c0a769988ee | 117 | ['A'] = 10, 11, 12, 13, 14, 15, // for the space conscious, reduce to |
brunofgc | 0:1c0a769988ee | 118 | ['a'] = 10, 11, 12, 13, 14, 15 // signed char. |
brunofgc | 5:7801f913384e | 119 | };*/ |
brunofgc | 5:7801f913384e | 120 | |
brunofgc | 5:7801f913384e | 121 | uint8_t hextable(char c){ |
brunofgc | 5:7801f913384e | 122 | uint8_t ret=0; |
brunofgc | 5:7801f913384e | 123 | if(c>='a'){ |
brunofgc | 5:7801f913384e | 124 | ret = c-87; |
brunofgc | 5:7801f913384e | 125 | }else if(c>='A'){ |
brunofgc | 5:7801f913384e | 126 | ret = c-55; |
brunofgc | 5:7801f913384e | 127 | }else{ |
brunofgc | 5:7801f913384e | 128 | ret = c-48; |
brunofgc | 5:7801f913384e | 129 | } |
brunofgc | 5:7801f913384e | 130 | return ret; |
brunofgc | 5:7801f913384e | 131 | } |
brunofgc | 0:1c0a769988ee | 132 | |
brunofgc | 0:1c0a769988ee | 133 | uint16_t hexdec(char *hex,uint16_t tam) { |
brunofgc | 0:1c0a769988ee | 134 | uint16_t ret = 0; |
brunofgc | 5:7801f913384e | 135 | uint8_t auxHex=0; |
brunofgc | 5:7801f913384e | 136 | uint16_t i; |
brunofgc | 0:1c0a769988ee | 137 | for(i=0;i<tam;i++){ |
brunofgc | 5:7801f913384e | 138 | //ret += hextable[hex[i]] << (i*4); |
brunofgc | 5:7801f913384e | 139 | ret += hextable(hex[i]) << (i*4); |
brunofgc | 5:7801f913384e | 140 | //pc.printf("%c",hex[i]); |
brunofgc | 5:7801f913384e | 141 | } |
brunofgc | 5:7801f913384e | 142 | //pc.printf("\r\n"); |
brunofgc | 0:1c0a769988ee | 143 | return ret; |
brunofgc | 0:1c0a769988ee | 144 | } |
brunofgc | 0:1c0a769988ee | 145 | |
brunofgc | 0:1c0a769988ee | 146 | |
brunofgc | 5:7801f913384e | 147 | void deserializaPacoteIR(char *strIr){ |
brunofgc | 5:7801f913384e | 148 | uint16_t len; |
brunofgc | 0:1c0a769988ee | 149 | uint16_t i; |
brunofgc | 6:d4ebbaaba295 | 150 | /*union{ |
brunofgc | 5:7801f913384e | 151 | char c[2]; |
brunofgc | 5:7801f913384e | 152 | uint16_t v; |
brunofgc | 6:d4ebbaaba295 | 153 | }u;*/ |
brunofgc | 5:7801f913384e | 154 | |
brunofgc | 6:d4ebbaaba295 | 155 | //pc.printf("String dentro de deserializaPacoteIR <%s>.\r\n",strIr); |
brunofgc | 5:7801f913384e | 156 | //pc.printf("Deserializando pacote <"); |
brunofgc | 5:7801f913384e | 157 | len = strlen(strIr); |
brunofgc | 0:1c0a769988ee | 158 | len = len/4; //Separando de quatro em quatro pra formar um uint16_t |
brunofgc | 0:1c0a769988ee | 159 | //printf("%lu bits\n",len/2); |
brunofgc | 0:1c0a769988ee | 160 | for(i=0;i<len;i++){ |
brunofgc | 5:7801f913384e | 161 | /*bits[i/2][(i%2)]=hexdec(&strIr[i*4],4); |
brunofgc | 5:7801f913384e | 162 | pc.printf("%02X",hexdec(&strIr[i*4],4));*/ |
brunofgc | 5:7801f913384e | 163 | bits[i/2][(i%2)]=hexdec(strIr,4); |
brunofgc | 5:7801f913384e | 164 | strIr = strIr+4; |
brunofgc | 0:1c0a769988ee | 165 | } |
brunofgc | 5:7801f913384e | 166 | //pc.printf(">.\r\n"); |
brunofgc | 5:7801f913384e | 167 | |
brunofgc | 0:1c0a769988ee | 168 | /*for(i=0;i<len;i++){ |
brunofgc | 0:1c0a769988ee | 169 | printf("bits[%u][%u]=%lu\n",i/2,(i%2),bits[i/2][(i%2)]); |
brunofgc | 0:1c0a769988ee | 170 | }*/ |
brunofgc | 5:7801f913384e | 171 | indexIr = len/2; |
brunofgc | 5:7801f913384e | 172 | |
brunofgc | 6:d4ebbaaba295 | 173 | /*pc.printf("Pacote deserializado <"); |
brunofgc | 5:7801f913384e | 174 | for(i=0;i<indexIr;i++){ |
brunofgc | 5:7801f913384e | 175 | u.v = bits[i][0]; |
brunofgc | 5:7801f913384e | 176 | pc.printf("%01X%01X%01X%01X" |
brunofgc | 5:7801f913384e | 177 | ,u.c[0]&0xF |
brunofgc | 5:7801f913384e | 178 | ,u.c[0]>>4 |
brunofgc | 5:7801f913384e | 179 | ,u.c[1]&0xF |
brunofgc | 5:7801f913384e | 180 | ,u.c[1]>>4 |
brunofgc | 5:7801f913384e | 181 | ); |
brunofgc | 5:7801f913384e | 182 | u.v = bits[i][1]; |
brunofgc | 5:7801f913384e | 183 | pc.printf("%01X%01X%01X%01X" |
brunofgc | 5:7801f913384e | 184 | ,u.c[0]&0xF |
brunofgc | 5:7801f913384e | 185 | ,u.c[0]>>4 |
brunofgc | 5:7801f913384e | 186 | ,u.c[1]&0xF |
brunofgc | 5:7801f913384e | 187 | ,u.c[1]>>4 |
brunofgc | 5:7801f913384e | 188 | ); |
brunofgc | 5:7801f913384e | 189 | |
brunofgc | 5:7801f913384e | 190 | } |
brunofgc | 6:d4ebbaaba295 | 191 | pc.printf(">.\r\n");*/ |
brunofgc | 0:1c0a769988ee | 192 | } |
brunofgc | 0:1c0a769988ee | 193 | |
brunofgc | 0:1c0a769988ee | 194 | void serializaPacoteIR(uint8_t connectionID){ |
brunofgc | 2:55b7b466e742 | 195 | char aux[50]; |
brunofgc | 0:1c0a769988ee | 196 | uint32_t length; |
brunofgc | 0:1c0a769988ee | 197 | char *ptr; |
brunofgc | 0:1c0a769988ee | 198 | uint16_t i; |
brunofgc | 0:1c0a769988ee | 199 | union{ |
brunofgc | 0:1c0a769988ee | 200 | char c[2]; |
brunofgc | 0:1c0a769988ee | 201 | uint16_t v; |
brunofgc | 0:1c0a769988ee | 202 | }u; |
brunofgc | 2:55b7b466e742 | 203 | sdCardBuf.del(); |
brunofgc | 5:7801f913384e | 204 | for(i=0;i<indexIr;i++){ |
brunofgc | 0:1c0a769988ee | 205 | u.v = bits[i][0]; |
brunofgc | 0:1c0a769988ee | 206 | sprintf(aux,"%01X%01X%01X%01X" |
brunofgc | 0:1c0a769988ee | 207 | ,u.c[0]&0xF |
brunofgc | 0:1c0a769988ee | 208 | ,u.c[0]>>4 |
brunofgc | 0:1c0a769988ee | 209 | ,u.c[1]&0xF |
brunofgc | 0:1c0a769988ee | 210 | ,u.c[1]>>4 |
brunofgc | 0:1c0a769988ee | 211 | ); |
brunofgc | 0:1c0a769988ee | 212 | sdCardBuf.fill(aux,strlen(aux)); |
brunofgc | 0:1c0a769988ee | 213 | |
brunofgc | 0:1c0a769988ee | 214 | u.v = bits[i][1]; |
brunofgc | 0:1c0a769988ee | 215 | sprintf(aux,"%01X%01X%01X%01X" |
brunofgc | 0:1c0a769988ee | 216 | ,u.c[0]&0xF |
brunofgc | 0:1c0a769988ee | 217 | ,u.c[0]>>4 |
brunofgc | 0:1c0a769988ee | 218 | ,u.c[1]&0xF |
brunofgc | 0:1c0a769988ee | 219 | ,u.c[1]>>4 |
brunofgc | 0:1c0a769988ee | 220 | ); |
brunofgc | 0:1c0a769988ee | 221 | sdCardBuf.fill(aux,strlen(aux)); |
brunofgc | 0:1c0a769988ee | 222 | } |
brunofgc | 0:1c0a769988ee | 223 | length = sdCardBuf.getLength(); |
brunofgc | 0:1c0a769988ee | 224 | ptr = sdCardBuf.get(); |
brunofgc | 0:1c0a769988ee | 225 | modemCom::cipSend(connID,ptr,length); |
brunofgc | 2:55b7b466e742 | 226 | //pc.printf("Conteudo de sdCardBuf <%s>.\r\n",ptr); |
brunofgc | 0:1c0a769988ee | 227 | } |
brunofgc | 0:1c0a769988ee | 228 | |
brunofgc | 0:1c0a769988ee | 229 | bool detectaIRIn(){ |
brunofgc | 0:1c0a769988ee | 230 | bool detectado=0; |
brunofgc | 0:1c0a769988ee | 231 | if((irInAntes!=IrIn) && (!IrIn)){ |
brunofgc | 0:1c0a769988ee | 232 | bits[0][0] = pulseDuration_us(0,IrIn,10000); |
brunofgc | 0:1c0a769988ee | 233 | bits[0][1] = pulseDuration_us(1,IrIn,10000); |
brunofgc | 0:1c0a769988ee | 234 | if((bits[0][0]>1000)&&(bits[0][1]>1000)){ |
brunofgc | 5:7801f913384e | 235 | indexIr = 1; |
brunofgc | 0:1c0a769988ee | 236 | do{ |
brunofgc | 5:7801f913384e | 237 | bits[indexIr][0] = pulseDuration_us(0,IrIn,10000); |
brunofgc | 5:7801f913384e | 238 | bits[indexIr][1] = pulseDuration_us(1,IrIn,10000); |
brunofgc | 5:7801f913384e | 239 | indexIr++; |
brunofgc | 0:1c0a769988ee | 240 | |
brunofgc | 5:7801f913384e | 241 | }while((bits[indexIr-1][0]!=65535)&&(bits[indexIr-1][1]!=65535)); |
brunofgc | 0:1c0a769988ee | 242 | detectado=1; |
brunofgc | 0:1c0a769988ee | 243 | } |
brunofgc | 0:1c0a769988ee | 244 | } |
brunofgc | 0:1c0a769988ee | 245 | irInAntes = IrIn; |
brunofgc | 0:1c0a769988ee | 246 | led2 = !IrIn; |
brunofgc | 0:1c0a769988ee | 247 | return detectado; |
brunofgc | 0:1c0a769988ee | 248 | } |
brunofgc | 0:1c0a769988ee | 249 | |
brunofgc | 0:1c0a769988ee | 250 | void pesquisaIRIn(){ |
brunofgc | 0:1c0a769988ee | 251 | if((irInAntes!=IrIn) && (!IrIn)){ |
brunofgc | 0:1c0a769988ee | 252 | startBitAlto = pulseDuration_us(0,IrIn,10000); |
brunofgc | 0:1c0a769988ee | 253 | startBitBaixo = pulseDuration_us(1,IrIn,10000); |
brunofgc | 0:1c0a769988ee | 254 | if((startBitAlto>1000)&&(startBitBaixo>1000)){ |
brunofgc | 5:7801f913384e | 255 | indexIr = 0; |
brunofgc | 0:1c0a769988ee | 256 | do{ |
brunofgc | 5:7801f913384e | 257 | bitAlto[indexIr] = pulseDuration_us(0,IrIn,10000); |
brunofgc | 5:7801f913384e | 258 | bitBaixo[indexIr] = pulseDuration_us(1,IrIn,10000); |
brunofgc | 5:7801f913384e | 259 | //dataIn[indexIr] = (bitBaixo[indexIr] > 1000); |
brunofgc | 5:7801f913384e | 260 | indexIr++; |
brunofgc | 0:1c0a769988ee | 261 | |
brunofgc | 5:7801f913384e | 262 | }while((bitAlto[indexIr-1]!=(-1))&&(bitBaixo[indexIr-1]!=(-1))); |
brunofgc | 0:1c0a769988ee | 263 | |
brunofgc | 5:7801f913384e | 264 | pc.printf("Capturado um quadro com %lu bits. sbH %ld, sbL %ld <",indexIr,startBitAlto, startBitBaixo); |
brunofgc | 5:7801f913384e | 265 | for(i=0;i<(indexIr);i++){ |
brunofgc | 0:1c0a769988ee | 266 | pc.printf("[H%ld L%ld] ",bitAlto[i],bitBaixo[i]); |
brunofgc | 0:1c0a769988ee | 267 | } |
brunofgc | 0:1c0a769988ee | 268 | pc.printf(">.\n\n"); |
brunofgc | 0:1c0a769988ee | 269 | |
brunofgc | 5:7801f913384e | 270 | /*pc.printf("%lu bits 0b",indexIr); |
brunofgc | 5:7801f913384e | 271 | for(i=0;i<indexIr;i++){ |
brunofgc | 0:1c0a769988ee | 272 | pc.printf("%u",dataIn[i]); |
brunofgc | 0:1c0a769988ee | 273 | } |
brunofgc | 0:1c0a769988ee | 274 | pc.printf("\n\n");*/ |
brunofgc | 0:1c0a769988ee | 275 | |
brunofgc | 0:1c0a769988ee | 276 | /*//Montando os bytes; |
brunofgc | 0:1c0a769988ee | 277 | byte=0; |
brunofgc | 0:1c0a769988ee | 278 | msgBytes=0; |
brunofgc | 5:7801f913384e | 279 | for(i=0;i<=indexIr;i++){ |
brunofgc | 0:1c0a769988ee | 280 | if((i!=0)&&((i%8) == 0)){ |
brunofgc | 0:1c0a769988ee | 281 | msg[msgBytes]=byte; |
brunofgc | 0:1c0a769988ee | 282 | msgBytes++; |
brunofgc | 0:1c0a769988ee | 283 | byte=0; |
brunofgc | 0:1c0a769988ee | 284 | } |
brunofgc | 0:1c0a769988ee | 285 | byte+= dataIn[i]<<(i%8); |
brunofgc | 0:1c0a769988ee | 286 | |
brunofgc | 0:1c0a769988ee | 287 | } |
brunofgc | 0:1c0a769988ee | 288 | |
brunofgc | 0:1c0a769988ee | 289 | //Exibindo pacote |
brunofgc | 0:1c0a769988ee | 290 | pc.printf("Resultado 0x"); |
brunofgc | 0:1c0a769988ee | 291 | for(i=0;i<msgBytes;i++){ |
brunofgc | 0:1c0a769988ee | 292 | pc.printf("%02X",msg[i]); |
brunofgc | 0:1c0a769988ee | 293 | } |
brunofgc | 0:1c0a769988ee | 294 | pc.printf("\n\n"); |
brunofgc | 0:1c0a769988ee | 295 | |
brunofgc | 0:1c0a769988ee | 296 | //Atuando nos leds |
brunofgc | 0:1c0a769988ee | 297 | botao=0; |
brunofgc | 0:1c0a769988ee | 298 | for(i=0;i<msgBytes;i++){ |
brunofgc | 0:1c0a769988ee | 299 | botao+=msg[i]<<(8*i); |
brunofgc | 0:1c0a769988ee | 300 | |
brunofgc | 0:1c0a769988ee | 301 | } |
brunofgc | 0:1c0a769988ee | 302 | //pc.printf("Botao pressionado %X\n",botao); |
brunofgc | 0:1c0a769988ee | 303 | switch(botao){ |
brunofgc | 0:1c0a769988ee | 304 | case 0xfb040707: //1 |
brunofgc | 0:1c0a769988ee | 305 | led2=1; |
brunofgc | 0:1c0a769988ee | 306 | break; |
brunofgc | 0:1c0a769988ee | 307 | case 0xfa050707: //2 |
brunofgc | 0:1c0a769988ee | 308 | led3=1; |
brunofgc | 0:1c0a769988ee | 309 | break; |
brunofgc | 0:1c0a769988ee | 310 | case 0xf9060707: //3 |
brunofgc | 0:1c0a769988ee | 311 | led4=1; |
brunofgc | 0:1c0a769988ee | 312 | break; |
brunofgc | 0:1c0a769988ee | 313 | case 0xf7080707: //4 |
brunofgc | 0:1c0a769988ee | 314 | led2=0; |
brunofgc | 0:1c0a769988ee | 315 | break; |
brunofgc | 0:1c0a769988ee | 316 | case 0xf6090707: //5 |
brunofgc | 0:1c0a769988ee | 317 | led3=0; |
brunofgc | 0:1c0a769988ee | 318 | break; |
brunofgc | 0:1c0a769988ee | 319 | case 0xf50a0707: //6 |
brunofgc | 0:1c0a769988ee | 320 | led4=0; |
brunofgc | 0:1c0a769988ee | 321 | break; |
brunofgc | 0:1c0a769988ee | 322 | }*/ |
brunofgc | 0:1c0a769988ee | 323 | //descritorPacoteIR(int startBitAlto, int startBitBaixo, int *bitAlto, int *bitBaixo, int numBits) |
brunofgc | 5:7801f913384e | 324 | //descritorPacoteIR(startBitAlto,startBitBaixo,bitAlto,bitBaixo,indexIr); |
brunofgc | 0:1c0a769988ee | 325 | } |
brunofgc | 0:1c0a769988ee | 326 | } |
brunofgc | 0:1c0a769988ee | 327 | irInAntes = IrIn; |
brunofgc | 0:1c0a769988ee | 328 | led2 = !IrIn; |
brunofgc | 0:1c0a769988ee | 329 | } |
brunofgc | 0:1c0a769988ee | 330 | |
brunofgc | 0:1c0a769988ee | 331 | /* |
brunofgc | 0:1c0a769988ee | 332 | |
brunofgc | 0:1c0a769988ee | 333 | float razaoBit(int iH, int iL){ |
brunofgc | 0:1c0a769988ee | 334 | float H=(float)iH,L=(float)iL; |
brunofgc | 0:1c0a769988ee | 335 | float razao = L/H; |
brunofgc | 0:1c0a769988ee | 336 | |
brunofgc | 0:1c0a769988ee | 337 | if(razao>=1){ |
brunofgc | 0:1c0a769988ee | 338 | return (float) round(razao); |
brunofgc | 0:1c0a769988ee | 339 | }else if(razao>=0.5){ |
brunofgc | 0:1c0a769988ee | 340 | return 0.5; |
brunofgc | 0:1c0a769988ee | 341 | }else if(razao>=0.25){ |
brunofgc | 0:1c0a769988ee | 342 | return 0.25; |
brunofgc | 0:1c0a769988ee | 343 | }else if(razao>=0.125){ |
brunofgc | 0:1c0a769988ee | 344 | return 0.125; |
brunofgc | 0:1c0a769988ee | 345 | }else{ |
brunofgc | 0:1c0a769988ee | 346 | return -1; |
brunofgc | 0:1c0a769988ee | 347 | } |
brunofgc | 0:1c0a769988ee | 348 | |
brunofgc | 0:1c0a769988ee | 349 | } |
brunofgc | 0:1c0a769988ee | 350 | |
brunofgc | 0:1c0a769988ee | 351 | void descritorPacoteIR(int startBitAlto, int startBitBaixo, int *bitAlto, int *bitBaixo, int numBits){ |
brunofgc | 0:1c0a769988ee | 352 | unsigned int razao_maiorQue4=0; |
brunofgc | 0:1c0a769988ee | 353 | unsigned int razao_4=0; |
brunofgc | 0:1c0a769988ee | 354 | unsigned int razao_3=0; |
brunofgc | 0:1c0a769988ee | 355 | unsigned int razao_2=0; |
brunofgc | 0:1c0a769988ee | 356 | unsigned int razao_1=0; |
brunofgc | 0:1c0a769988ee | 357 | unsigned int razao_0_5=0; |
brunofgc | 0:1c0a769988ee | 358 | unsigned int razao_0_25=0; |
brunofgc | 0:1c0a769988ee | 359 | unsigned int razao_0_125=0; |
brunofgc | 0:1c0a769988ee | 360 | unsigned int razao_menorQue_0_125=0; |
brunofgc | 0:1c0a769988ee | 361 | |
brunofgc | 0:1c0a769988ee | 362 | //Indice 0 ALto, 1 Baixo; |
brunofgc | 0:1c0a769988ee | 363 | unsigned long int bitRazao_maiorQue4[2]= {0,0}; |
brunofgc | 0:1c0a769988ee | 364 | unsigned long int bitRazao_4[2]= {0,0}; |
brunofgc | 0:1c0a769988ee | 365 | unsigned long int bitRazao_3[2]= {0,0}; |
brunofgc | 0:1c0a769988ee | 366 | unsigned long int bitRazao_2[2]= {0,0}; |
brunofgc | 0:1c0a769988ee | 367 | unsigned long int bitRazao_1[2]= {0,0}; |
brunofgc | 0:1c0a769988ee | 368 | unsigned long int bitRazao_0_5[2]= {0,0}; |
brunofgc | 0:1c0a769988ee | 369 | unsigned long int bitRazao_0_25[2]= {0,0}; |
brunofgc | 0:1c0a769988ee | 370 | unsigned long int bitRazao_0_125[2]= {0,0}; |
brunofgc | 0:1c0a769988ee | 371 | unsigned long int bitRazao_menorQue_0_125[2]= {0,0}; |
brunofgc | 0:1c0a769988ee | 372 | |
brunofgc | 0:1c0a769988ee | 373 | unsigned long int indiceMaiorNEventos[2] = {0,0}; |
brunofgc | 0:1c0a769988ee | 374 | unsigned long int indiceSegundoMaiorNEventos[2] = {0,0}; |
brunofgc | 0:1c0a769988ee | 375 | |
brunofgc | 0:1c0a769988ee | 376 | |
brunofgc | 0:1c0a769988ee | 377 | |
brunofgc | 0:1c0a769988ee | 378 | unsigned int bitAlto_H=0; |
brunofgc | 0:1c0a769988ee | 379 | unsigned int bitAlto_L=0; |
brunofgc | 0:1c0a769988ee | 380 | unsigned int bitBaixo_H=0; |
brunofgc | 0:1c0a769988ee | 381 | unsigned int bitBaixo_L=0; |
brunofgc | 0:1c0a769988ee | 382 | |
brunofgc | 0:1c0a769988ee | 383 | unsigned int stopBitAlto = bitAlto[numBits-1]; |
brunofgc | 0:1c0a769988ee | 384 | |
brunofgc | 0:1c0a769988ee | 385 | int i; |
brunofgc | 0:1c0a769988ee | 386 | |
brunofgc | 0:1c0a769988ee | 387 | //printf("startBitAlto %d, startBitBaixo %d, stopBitAlto %d, stopBitBaixo %d numBits %d\n",startBitAlto,startBitBaixo,bitAlto[numBits-1],bitBaixo[numBits-1],numBits); |
brunofgc | 0:1c0a769988ee | 388 | |
brunofgc | 0:1c0a769988ee | 389 | //Despresando o stopBit pois esse já sabemos como faz |
brunofgc | 0:1c0a769988ee | 390 | for(i=0;i<numBits-1;i++){ |
brunofgc | 0:1c0a769988ee | 391 | //printf("Razao entre [L %05d e H %05d]=%1.2f\n",bitBaixo[i],bitAlto[i],razaoBit(bitAlto[i],bitBaixo[i])); |
brunofgc | 0:1c0a769988ee | 392 | //Detecção de padroes |
brunofgc | 0:1c0a769988ee | 393 | if(razaoBit(bitAlto[i],bitBaixo[i])>=4){ |
brunofgc | 0:1c0a769988ee | 394 | razao_maiorQue4++; |
brunofgc | 0:1c0a769988ee | 395 | bitRazao_maiorQue4[0]+= bitAlto[i]; |
brunofgc | 0:1c0a769988ee | 396 | bitRazao_maiorQue4[1]+=bitBaixo[i]; |
brunofgc | 0:1c0a769988ee | 397 | |
brunofgc | 0:1c0a769988ee | 398 | }else if(razaoBit(bitAlto[i],bitBaixo[i])==4){ |
brunofgc | 0:1c0a769988ee | 399 | razao_4++; |
brunofgc | 0:1c0a769988ee | 400 | bitRazao_4[0]+= bitAlto[i]; |
brunofgc | 0:1c0a769988ee | 401 | bitRazao_4[1]+=bitBaixo[i]; |
brunofgc | 0:1c0a769988ee | 402 | }else if(razaoBit(bitAlto[i],bitBaixo[i])==3){ |
brunofgc | 0:1c0a769988ee | 403 | razao_3++; |
brunofgc | 0:1c0a769988ee | 404 | bitRazao_3[0]+= bitAlto[i]; |
brunofgc | 0:1c0a769988ee | 405 | bitRazao_3[1]+=bitBaixo[i]; |
brunofgc | 0:1c0a769988ee | 406 | }else if(razaoBit(bitAlto[i],bitBaixo[i])==2){ |
brunofgc | 0:1c0a769988ee | 407 | razao_2++; |
brunofgc | 0:1c0a769988ee | 408 | bitRazao_2[0]+= bitAlto[i]; |
brunofgc | 0:1c0a769988ee | 409 | bitRazao_2[1]+=bitBaixo[i]; |
brunofgc | 0:1c0a769988ee | 410 | }else if(razaoBit(bitAlto[i],bitBaixo[i])==1){ |
brunofgc | 0:1c0a769988ee | 411 | razao_1++; |
brunofgc | 0:1c0a769988ee | 412 | bitRazao_1[0]+= bitAlto[i]; |
brunofgc | 0:1c0a769988ee | 413 | bitRazao_1[1]+=bitBaixo[i]; |
brunofgc | 0:1c0a769988ee | 414 | }else if(razaoBit(bitAlto[i],bitBaixo[i])==0.5){ |
brunofgc | 0:1c0a769988ee | 415 | razao_0_5++; |
brunofgc | 0:1c0a769988ee | 416 | bitRazao_0_5[0]+= bitAlto[i]; |
brunofgc | 0:1c0a769988ee | 417 | bitRazao_0_5[1]+=bitBaixo[i]; |
brunofgc | 0:1c0a769988ee | 418 | }else if(razaoBit(bitAlto[i],bitBaixo[i])==0.25){ |
brunofgc | 0:1c0a769988ee | 419 | razao_0_25++; |
brunofgc | 0:1c0a769988ee | 420 | bitRazao_0_25[0]+= bitAlto[i]; |
brunofgc | 0:1c0a769988ee | 421 | bitRazao_0_25[1]+=bitBaixo[i]; |
brunofgc | 0:1c0a769988ee | 422 | }else if(razaoBit(bitAlto[i],bitBaixo[i])==0.125){ |
brunofgc | 0:1c0a769988ee | 423 | razao_0_125++; |
brunofgc | 0:1c0a769988ee | 424 | bitRazao_0_125[0]+= bitAlto[i]; |
brunofgc | 0:1c0a769988ee | 425 | bitRazao_0_125[1]+=bitBaixo[i]; |
brunofgc | 0:1c0a769988ee | 426 | }else { |
brunofgc | 0:1c0a769988ee | 427 | razao_menorQue_0_125++; |
brunofgc | 0:1c0a769988ee | 428 | bitRazao_menorQue_0_125[0]+= bitAlto[i]; |
brunofgc | 0:1c0a769988ee | 429 | bitRazao_menorQue_0_125[1]+=bitBaixo[i]; |
brunofgc | 0:1c0a769988ee | 430 | } |
brunofgc | 0:1c0a769988ee | 431 | |
brunofgc | 0:1c0a769988ee | 432 | } |
brunofgc | 0:1c0a769988ee | 433 | 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 | 434 | ,razao_menorQue_0_125 |
brunofgc | 0:1c0a769988ee | 435 | ,razao_0_125 |
brunofgc | 0:1c0a769988ee | 436 | ,razao_0_25 |
brunofgc | 0:1c0a769988ee | 437 | ,razao_0_5 |
brunofgc | 0:1c0a769988ee | 438 | ,razao_1 |
brunofgc | 0:1c0a769988ee | 439 | ,razao_2 |
brunofgc | 0:1c0a769988ee | 440 | ,razao_3 |
brunofgc | 0:1c0a769988ee | 441 | ,razao_4 |
brunofgc | 0:1c0a769988ee | 442 | ,razao_maiorQue4 |
brunofgc | 0:1c0a769988ee | 443 | ); |
brunofgc | 0:1c0a769988ee | 444 | |
brunofgc | 0:1c0a769988ee | 445 | //Buscando os dois maiores em numero de eventos por Indice; |
brunofgc | 0:1c0a769988ee | 446 | //Buscando o primeiro |
brunofgc | 0:1c0a769988ee | 447 | for(i=0;i<9;i++){ |
brunofgc | 0:1c0a769988ee | 448 | //Buscando nos indices maior numero eventos |
brunofgc | 0:1c0a769988ee | 449 | switch(i){ |
brunofgc | 0:1c0a769988ee | 450 | case 0: |
brunofgc | 0:1c0a769988ee | 451 | if(razao_maiorQue4>indiceMaiorNEventos[0]){ |
brunofgc | 0:1c0a769988ee | 452 | indiceMaiorNEventos[0] = razao_maiorQue4; |
brunofgc | 0:1c0a769988ee | 453 | indiceMaiorNEventos[1] = i; |
brunofgc | 0:1c0a769988ee | 454 | } |
brunofgc | 0:1c0a769988ee | 455 | break; |
brunofgc | 0:1c0a769988ee | 456 | |
brunofgc | 0:1c0a769988ee | 457 | case 1: |
brunofgc | 0:1c0a769988ee | 458 | if(razao_4>indiceMaiorNEventos[0]){ |
brunofgc | 0:1c0a769988ee | 459 | indiceMaiorNEventos[0] = razao_4; |
brunofgc | 0:1c0a769988ee | 460 | indiceMaiorNEventos[1] = i; |
brunofgc | 0:1c0a769988ee | 461 | } |
brunofgc | 0:1c0a769988ee | 462 | break; |
brunofgc | 0:1c0a769988ee | 463 | case 2: |
brunofgc | 0:1c0a769988ee | 464 | if(razao_3>indiceMaiorNEventos[0]){ |
brunofgc | 0:1c0a769988ee | 465 | indiceMaiorNEventos[0] = razao_3; |
brunofgc | 0:1c0a769988ee | 466 | indiceMaiorNEventos[1] = i; |
brunofgc | 0:1c0a769988ee | 467 | } |
brunofgc | 0:1c0a769988ee | 468 | break; |
brunofgc | 0:1c0a769988ee | 469 | case 3: |
brunofgc | 0:1c0a769988ee | 470 | if(razao_2>indiceMaiorNEventos[0]){ |
brunofgc | 0:1c0a769988ee | 471 | indiceMaiorNEventos[0] = razao_2; |
brunofgc | 0:1c0a769988ee | 472 | indiceMaiorNEventos[1] = i; |
brunofgc | 0:1c0a769988ee | 473 | } |
brunofgc | 0:1c0a769988ee | 474 | break; |
brunofgc | 0:1c0a769988ee | 475 | case 4: |
brunofgc | 0:1c0a769988ee | 476 | if(razao_1>indiceMaiorNEventos[0]){ |
brunofgc | 0:1c0a769988ee | 477 | indiceMaiorNEventos[0] = razao_1; |
brunofgc | 0:1c0a769988ee | 478 | indiceMaiorNEventos[1] = i; |
brunofgc | 0:1c0a769988ee | 479 | } |
brunofgc | 0:1c0a769988ee | 480 | break; |
brunofgc | 0:1c0a769988ee | 481 | case 5: |
brunofgc | 0:1c0a769988ee | 482 | if(razao_0_5>indiceMaiorNEventos[0]){ |
brunofgc | 0:1c0a769988ee | 483 | indiceMaiorNEventos[0] = razao_0_5; |
brunofgc | 0:1c0a769988ee | 484 | indiceMaiorNEventos[1] = i; |
brunofgc | 0:1c0a769988ee | 485 | } |
brunofgc | 0:1c0a769988ee | 486 | break; |
brunofgc | 0:1c0a769988ee | 487 | case 6: |
brunofgc | 0:1c0a769988ee | 488 | if(razao_0_25>indiceMaiorNEventos[0]){ |
brunofgc | 0:1c0a769988ee | 489 | indiceMaiorNEventos[0] = razao_0_25; |
brunofgc | 0:1c0a769988ee | 490 | indiceMaiorNEventos[1] = i; |
brunofgc | 0:1c0a769988ee | 491 | } |
brunofgc | 0:1c0a769988ee | 492 | break; |
brunofgc | 0:1c0a769988ee | 493 | case 7: |
brunofgc | 0:1c0a769988ee | 494 | if(razao_0_125>indiceMaiorNEventos[0]){ |
brunofgc | 0:1c0a769988ee | 495 | indiceMaiorNEventos[0] = razao_0_125; |
brunofgc | 0:1c0a769988ee | 496 | indiceMaiorNEventos[1] = i; |
brunofgc | 0:1c0a769988ee | 497 | } |
brunofgc | 0:1c0a769988ee | 498 | break; |
brunofgc | 0:1c0a769988ee | 499 | case 8: |
brunofgc | 0:1c0a769988ee | 500 | if(razao_menorQue_0_125>indiceMaiorNEventos[0]){ |
brunofgc | 0:1c0a769988ee | 501 | indiceMaiorNEventos[0] = razao_menorQue_0_125; |
brunofgc | 0:1c0a769988ee | 502 | indiceMaiorNEventos[1] = i; |
brunofgc | 0:1c0a769988ee | 503 | } |
brunofgc | 0:1c0a769988ee | 504 | break; |
brunofgc | 0:1c0a769988ee | 505 | |
brunofgc | 0:1c0a769988ee | 506 | } |
brunofgc | 0:1c0a769988ee | 507 | } |
brunofgc | 0:1c0a769988ee | 508 | |
brunofgc | 0:1c0a769988ee | 509 | //Buscando o segundo |
brunofgc | 0:1c0a769988ee | 510 | //Buscando o primeiro |
brunofgc | 0:1c0a769988ee | 511 | for(i=0;i<9;i++){ |
brunofgc | 0:1c0a769988ee | 512 | //Buscando nos indices maior numero eventos |
brunofgc | 0:1c0a769988ee | 513 | if(i!=indiceMaiorNEventos[1]){ |
brunofgc | 0:1c0a769988ee | 514 | switch(i){ |
brunofgc | 0:1c0a769988ee | 515 | case 0: |
brunofgc | 0:1c0a769988ee | 516 | if(razao_maiorQue4>indiceSegundoMaiorNEventos[0]){ |
brunofgc | 0:1c0a769988ee | 517 | indiceSegundoMaiorNEventos[0] = razao_maiorQue4; |
brunofgc | 0:1c0a769988ee | 518 | indiceSegundoMaiorNEventos[1] = i; |
brunofgc | 0:1c0a769988ee | 519 | } |
brunofgc | 0:1c0a769988ee | 520 | break; |
brunofgc | 0:1c0a769988ee | 521 | |
brunofgc | 0:1c0a769988ee | 522 | case 1: |
brunofgc | 0:1c0a769988ee | 523 | if(razao_4>indiceSegundoMaiorNEventos[0]){ |
brunofgc | 0:1c0a769988ee | 524 | indiceSegundoMaiorNEventos[0] = razao_4; |
brunofgc | 0:1c0a769988ee | 525 | indiceSegundoMaiorNEventos[1] = i; |
brunofgc | 0:1c0a769988ee | 526 | } |
brunofgc | 0:1c0a769988ee | 527 | break; |
brunofgc | 0:1c0a769988ee | 528 | case 2: |
brunofgc | 0:1c0a769988ee | 529 | if(razao_3>indiceSegundoMaiorNEventos[0]){ |
brunofgc | 0:1c0a769988ee | 530 | indiceSegundoMaiorNEventos[0] = razao_3; |
brunofgc | 0:1c0a769988ee | 531 | indiceSegundoMaiorNEventos[1] = i; |
brunofgc | 0:1c0a769988ee | 532 | } |
brunofgc | 0:1c0a769988ee | 533 | break; |
brunofgc | 0:1c0a769988ee | 534 | case 3: |
brunofgc | 0:1c0a769988ee | 535 | if(razao_2>indiceSegundoMaiorNEventos[0]){ |
brunofgc | 0:1c0a769988ee | 536 | indiceSegundoMaiorNEventos[0] = razao_2; |
brunofgc | 0:1c0a769988ee | 537 | indiceSegundoMaiorNEventos[1] = i; |
brunofgc | 0:1c0a769988ee | 538 | } |
brunofgc | 0:1c0a769988ee | 539 | break; |
brunofgc | 0:1c0a769988ee | 540 | case 4: |
brunofgc | 0:1c0a769988ee | 541 | if(razao_1>indiceSegundoMaiorNEventos[0]){ |
brunofgc | 0:1c0a769988ee | 542 | indiceSegundoMaiorNEventos[0] = razao_1; |
brunofgc | 0:1c0a769988ee | 543 | indiceSegundoMaiorNEventos[1] = i; |
brunofgc | 0:1c0a769988ee | 544 | } |
brunofgc | 0:1c0a769988ee | 545 | break; |
brunofgc | 0:1c0a769988ee | 546 | case 5: |
brunofgc | 0:1c0a769988ee | 547 | if(razao_0_5>indiceSegundoMaiorNEventos[0]){ |
brunofgc | 0:1c0a769988ee | 548 | indiceSegundoMaiorNEventos[0] = razao_0_5; |
brunofgc | 0:1c0a769988ee | 549 | indiceSegundoMaiorNEventos[1] = i; |
brunofgc | 0:1c0a769988ee | 550 | } |
brunofgc | 0:1c0a769988ee | 551 | break; |
brunofgc | 0:1c0a769988ee | 552 | case 6: |
brunofgc | 0:1c0a769988ee | 553 | if(razao_0_25>indiceSegundoMaiorNEventos[0]){ |
brunofgc | 0:1c0a769988ee | 554 | indiceSegundoMaiorNEventos[0] = razao_0_25; |
brunofgc | 0:1c0a769988ee | 555 | indiceSegundoMaiorNEventos[1] = i; |
brunofgc | 0:1c0a769988ee | 556 | } |
brunofgc | 0:1c0a769988ee | 557 | break; |
brunofgc | 0:1c0a769988ee | 558 | case 7: |
brunofgc | 0:1c0a769988ee | 559 | if(razao_0_125>indiceSegundoMaiorNEventos[0]){ |
brunofgc | 0:1c0a769988ee | 560 | indiceSegundoMaiorNEventos[0] = razao_0_125; |
brunofgc | 0:1c0a769988ee | 561 | indiceSegundoMaiorNEventos[1] = i; |
brunofgc | 0:1c0a769988ee | 562 | } |
brunofgc | 0:1c0a769988ee | 563 | break; |
brunofgc | 0:1c0a769988ee | 564 | case 8: |
brunofgc | 0:1c0a769988ee | 565 | if(razao_menorQue_0_125>indiceSegundoMaiorNEventos[0]){ |
brunofgc | 0:1c0a769988ee | 566 | indiceSegundoMaiorNEventos[0] = razao_menorQue_0_125; |
brunofgc | 0:1c0a769988ee | 567 | indiceSegundoMaiorNEventos[1] = i; |
brunofgc | 0:1c0a769988ee | 568 | } |
brunofgc | 0:1c0a769988ee | 569 | break; |
brunofgc | 0:1c0a769988ee | 570 | |
brunofgc | 0:1c0a769988ee | 571 | } |
brunofgc | 0:1c0a769988ee | 572 | } |
brunofgc | 0:1c0a769988ee | 573 | } |
brunofgc | 0:1c0a769988ee | 574 | |
brunofgc | 0:1c0a769988ee | 575 | |
brunofgc | 0:1c0a769988ee | 576 | //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 | 577 | |
brunofgc | 0:1c0a769988ee | 578 | //Calculando bitAlto |
brunofgc | 0:1c0a769988ee | 579 | switch(indiceMaiorNEventos[1]){ |
brunofgc | 0:1c0a769988ee | 580 | case 0: |
brunofgc | 0:1c0a769988ee | 581 | bitAlto_H = round(bitRazao_maiorQue4[0]/indiceMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 582 | bitAlto_L = round(bitRazao_maiorQue4[1]/indiceMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 583 | break; |
brunofgc | 0:1c0a769988ee | 584 | case 1: |
brunofgc | 0:1c0a769988ee | 585 | bitAlto_H = round(bitRazao_4[0]/indiceMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 586 | bitAlto_L = round(bitRazao_4[1]/indiceMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 587 | break; |
brunofgc | 0:1c0a769988ee | 588 | case 2: |
brunofgc | 0:1c0a769988ee | 589 | bitAlto_H = round(bitRazao_3[0]/indiceMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 590 | bitAlto_L = round(bitRazao_3[1]/indiceMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 591 | break; |
brunofgc | 0:1c0a769988ee | 592 | case 3: |
brunofgc | 0:1c0a769988ee | 593 | bitAlto_H = round(bitRazao_2[0]/indiceMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 594 | bitAlto_L = round(bitRazao_2[1]/indiceMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 595 | break; |
brunofgc | 0:1c0a769988ee | 596 | case 4: |
brunofgc | 0:1c0a769988ee | 597 | bitAlto_H = round(bitRazao_1[0]/indiceMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 598 | bitAlto_L = round(bitRazao_1[1]/indiceMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 599 | break; |
brunofgc | 0:1c0a769988ee | 600 | case 5: |
brunofgc | 0:1c0a769988ee | 601 | bitAlto_H = round(bitRazao_0_5[0]/indiceMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 602 | bitAlto_L = round(bitRazao_0_5[1]/indiceMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 603 | break; |
brunofgc | 0:1c0a769988ee | 604 | case 6: |
brunofgc | 0:1c0a769988ee | 605 | bitAlto_H = round(bitRazao_0_25[0]/indiceMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 606 | bitAlto_L = round(bitRazao_0_25[1]/indiceMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 607 | break; |
brunofgc | 0:1c0a769988ee | 608 | case 7: |
brunofgc | 0:1c0a769988ee | 609 | bitAlto_H = round(bitRazao_0_125[0]/indiceMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 610 | bitAlto_L = round(bitRazao_0_125[1]/indiceMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 611 | break; |
brunofgc | 0:1c0a769988ee | 612 | case 8: |
brunofgc | 0:1c0a769988ee | 613 | bitAlto_H = round(bitRazao_menorQue_0_125[0]/indiceMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 614 | bitAlto_L = round(bitRazao_menorQue_0_125[1]/indiceMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 615 | break; |
brunofgc | 0:1c0a769988ee | 616 | } |
brunofgc | 0:1c0a769988ee | 617 | |
brunofgc | 0:1c0a769988ee | 618 | //Calculando bitBaixo |
brunofgc | 0:1c0a769988ee | 619 | switch(indiceSegundoMaiorNEventos[1]){ |
brunofgc | 0:1c0a769988ee | 620 | case 0: |
brunofgc | 0:1c0a769988ee | 621 | bitBaixo_H = round(bitRazao_maiorQue4[0]/indiceSegundoMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 622 | bitBaixo_L = round(bitRazao_maiorQue4[1]/indiceSegundoMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 623 | break; |
brunofgc | 0:1c0a769988ee | 624 | case 1: |
brunofgc | 0:1c0a769988ee | 625 | bitBaixo_H = round(bitRazao_4[0]/indiceSegundoMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 626 | bitBaixo_L = round(bitRazao_4[1]/indiceSegundoMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 627 | break; |
brunofgc | 0:1c0a769988ee | 628 | case 2: |
brunofgc | 0:1c0a769988ee | 629 | bitBaixo_H = round(bitRazao_3[0]/indiceSegundoMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 630 | bitBaixo_L = round(bitRazao_3[1]/indiceSegundoMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 631 | break; |
brunofgc | 0:1c0a769988ee | 632 | case 3: |
brunofgc | 0:1c0a769988ee | 633 | bitBaixo_H = round(bitRazao_2[0]/indiceSegundoMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 634 | bitBaixo_L = round(bitRazao_2[1]/indiceSegundoMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 635 | break; |
brunofgc | 0:1c0a769988ee | 636 | case 4: |
brunofgc | 0:1c0a769988ee | 637 | bitBaixo_H = round(bitRazao_1[0]/indiceSegundoMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 638 | bitBaixo_L = round(bitRazao_1[1]/indiceSegundoMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 639 | break; |
brunofgc | 0:1c0a769988ee | 640 | case 5: |
brunofgc | 0:1c0a769988ee | 641 | bitBaixo_H = round(bitRazao_0_5[0]/indiceSegundoMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 642 | bitBaixo_L = round(bitRazao_0_5[1]/indiceSegundoMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 643 | break; |
brunofgc | 0:1c0a769988ee | 644 | case 6: |
brunofgc | 0:1c0a769988ee | 645 | bitBaixo_H = round(bitRazao_0_25[0]/indiceSegundoMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 646 | bitBaixo_L = round(bitRazao_0_25[1]/indiceSegundoMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 647 | break; |
brunofgc | 0:1c0a769988ee | 648 | case 7: |
brunofgc | 0:1c0a769988ee | 649 | bitBaixo_H = round(bitRazao_0_125[0]/indiceSegundoMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 650 | bitBaixo_L = round(bitRazao_0_125[1]/indiceSegundoMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 651 | break; |
brunofgc | 0:1c0a769988ee | 652 | case 8: |
brunofgc | 0:1c0a769988ee | 653 | bitBaixo_H = round(bitRazao_menorQue_0_125[0]/indiceSegundoMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 654 | bitBaixo_L = round(bitRazao_menorQue_0_125[1]/indiceSegundoMaiorNEventos[0]); |
brunofgc | 0:1c0a769988ee | 655 | break; |
brunofgc | 0:1c0a769988ee | 656 | } |
brunofgc | 0:1c0a769988ee | 657 | |
brunofgc | 0:1c0a769988ee | 658 | printf("\n\nFinalmente.\n"); |
brunofgc | 0:1c0a769988ee | 659 | printf("startBitAlto = %ld, startBitBaixo = %ld\n", startBitAlto,startBitBaixo); |
brunofgc | 0:1c0a769988ee | 660 | printf("bitAlto_H = %ld bitAlto_l = %ld\n",bitAlto_H,bitAlto_L); |
brunofgc | 0:1c0a769988ee | 661 | printf("bitBaixo_H = %ld bitBaixo_l = %ld\n",bitBaixo_H,bitBaixo_L); |
brunofgc | 0:1c0a769988ee | 662 | printf("stopBitAlto = %ld\n",stopBitAlto); |
brunofgc | 0:1c0a769988ee | 663 | |
brunofgc | 0:1c0a769988ee | 664 | return; |
brunofgc | 0:1c0a769988ee | 665 | }*/ |