
TP
Dependencies: mbed tsi_sensor MMA8451Q
func.cpp@0:6ab157599e7f, 2020-12-14 (annotated)
- Committer:
- lucianotrujillo
- Date:
- Mon Dec 14 07:38:57 2020 +0000
- Revision:
- 0:6ab157599e7f
TP Luciano Trujillo
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lucianotrujillo | 0:6ab157599e7f | 1 | #include "mbed.h" |
lucianotrujillo | 0:6ab157599e7f | 2 | #include "func.h" |
lucianotrujillo | 0:6ab157599e7f | 3 | |
lucianotrujillo | 0:6ab157599e7f | 4 | //Salidas digitales |
lucianotrujillo | 0:6ab157599e7f | 5 | DigitalOut lr(LED_RED); |
lucianotrujillo | 0:6ab157599e7f | 6 | DigitalOut lg(LED_GREEN); |
lucianotrujillo | 0:6ab157599e7f | 7 | DigitalOut lb(LED_BLUE); |
lucianotrujillo | 0:6ab157599e7f | 8 | |
lucianotrujillo | 0:6ab157599e7f | 9 | //Entrada ADC |
lucianotrujillo | 0:6ab157599e7f | 10 | AnalogIn ValorConversor(A0); |
lucianotrujillo | 0:6ab157599e7f | 11 | |
lucianotrujillo | 0:6ab157599e7f | 12 | //Defino pines I2C |
lucianotrujillo | 0:6ab157599e7f | 13 | PinName const SDA = PTE25; |
lucianotrujillo | 0:6ab157599e7f | 14 | PinName const SCL = PTE24; |
lucianotrujillo | 0:6ab157599e7f | 15 | |
lucianotrujillo | 0:6ab157599e7f | 16 | //Variables globales |
lucianotrujillo | 0:6ab157599e7f | 17 | int ValoresMedidos[20]; |
lucianotrujillo | 0:6ab157599e7f | 18 | int fMuestras = TRUE; |
lucianotrujillo | 0:6ab157599e7f | 19 | int fLr=ON, fLg=ON; |
lucianotrujillo | 0:6ab157599e7f | 20 | unsigned char TiempoDeMuestreo; //Guarda el set del tiempo entre muestras (asumo segundos) |
lucianotrujillo | 0:6ab157599e7f | 21 | unsigned char ModoDeMuestreo;//Guarda el modo en que se dispara el muestreo |
lucianotrujillo | 0:6ab157599e7f | 22 | unsigned char RX_in,RX_out; //indices de entrada y salida de datos del buffer circular |
lucianotrujillo | 0:6ab157599e7f | 23 | unsigned char bufferRX [MAX_BUFFER]; // buffer circular de recepcion |
lucianotrujillo | 0:6ab157599e7f | 24 | |
lucianotrujillo | 0:6ab157599e7f | 25 | //INICIALIZO PERIF |
lucianotrujillo | 0:6ab157599e7f | 26 | TSIAnalogSlider tsi(ELEC0, ELEC1, 40); |
lucianotrujillo | 0:6ab157599e7f | 27 | MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS); |
lucianotrujillo | 0:6ab157599e7f | 28 | |
lucianotrujillo | 0:6ab157599e7f | 29 | //MAQUINA DE ESTADOS |
lucianotrujillo | 0:6ab157599e7f | 30 | void MaquinaDeEstados ( void ) |
lucianotrujillo | 0:6ab157599e7f | 31 | { |
lucianotrujillo | 0:6ab157599e7f | 32 | static unsigned char Estados = DESHABILITADO , indice = 0; |
lucianotrujillo | 0:6ab157599e7f | 33 | static int resultado; |
lucianotrujillo | 0:6ab157599e7f | 34 | static double ValorAcelerometro, ValorTouch; |
lucianotrujillo | 0:6ab157599e7f | 35 | |
lucianotrujillo | 0:6ab157599e7f | 36 | switch ( Estados ) { |
lucianotrujillo | 0:6ab157599e7f | 37 | |
lucianotrujillo | 0:6ab157599e7f | 38 | case DESHABILITADO: |
lucianotrujillo | 0:6ab157599e7f | 39 | //Sistema no configurado |
lucianotrujillo | 0:6ab157599e7f | 40 | |
lucianotrujillo | 0:6ab157599e7f | 41 | //Led rojo ON |
lucianotrujillo | 0:6ab157599e7f | 42 | lr = ON; |
lucianotrujillo | 0:6ab157599e7f | 43 | lg = OFF; |
lucianotrujillo | 0:6ab157599e7f | 44 | lb = OFF; |
lucianotrujillo | 0:6ab157599e7f | 45 | |
lucianotrujillo | 0:6ab157599e7f | 46 | //Leo trama |
lucianotrujillo | 0:6ab157599e7f | 47 | resultado = RecepcionDeTrama ( ); |
lucianotrujillo | 0:6ab157599e7f | 48 | if ( resultado == CONFIGURACION_RECIBIDA ) |
lucianotrujillo | 0:6ab157599e7f | 49 | { |
lucianotrujillo | 0:6ab157599e7f | 50 | // Los valores de configuracion quedaron en: |
lucianotrujillo | 0:6ab157599e7f | 51 | // TiempoDeMuestreo y ModoDeMuestreo |
lucianotrujillo | 0:6ab157599e7f | 52 | printf("ESTADO REPOSO\r\n"); |
lucianotrujillo | 0:6ab157599e7f | 53 | Estados = REPOSO; |
lucianotrujillo | 0:6ab157599e7f | 54 | } |
lucianotrujillo | 0:6ab157599e7f | 55 | break; |
lucianotrujillo | 0:6ab157599e7f | 56 | |
lucianotrujillo | 0:6ab157599e7f | 57 | case REPOSO: |
lucianotrujillo | 0:6ab157599e7f | 58 | // Sistema configurado, en Reposo (no mido datos) |
lucianotrujillo | 0:6ab157599e7f | 59 | |
lucianotrujillo | 0:6ab157599e7f | 60 | //Led verde parpadeando |
lucianotrujillo | 0:6ab157599e7f | 61 | lr = OFF; |
lucianotrujillo | 0:6ab157599e7f | 62 | blink_lg (); |
lucianotrujillo | 0:6ab157599e7f | 63 | |
lucianotrujillo | 0:6ab157599e7f | 64 | //Leo trama |
lucianotrujillo | 0:6ab157599e7f | 65 | resultado = RecepcionDeTrama ( ); |
lucianotrujillo | 0:6ab157599e7f | 66 | |
lucianotrujillo | 0:6ab157599e7f | 67 | // Si me consultan trasmito la configuracion |
lucianotrujillo | 0:6ab157599e7f | 68 | if ( resultado == SOLICITUD_DE_CONFIGURACION ) |
lucianotrujillo | 0:6ab157599e7f | 69 | Transmitir_RC ( ); |
lucianotrujillo | 0:6ab157599e7f | 70 | |
lucianotrujillo | 0:6ab157599e7f | 71 | // Si me consultan trasmito datos |
lucianotrujillo | 0:6ab157599e7f | 72 | if((resultado == SOLICITUD_DE_MUESTRAS)&&(indice!=0)) |
lucianotrujillo | 0:6ab157599e7f | 73 | Transmitir_RM ( ); |
lucianotrujillo | 0:6ab157599e7f | 74 | |
lucianotrujillo | 0:6ab157599e7f | 75 | // Si estoy configurado en A, leo Acelerometro |
lucianotrujillo | 0:6ab157599e7f | 76 | if ( ModoDeMuestreo == 'A' ) |
lucianotrujillo | 0:6ab157599e7f | 77 | { |
lucianotrujillo | 0:6ab157599e7f | 78 | ValorAcelerometro = acc.getAccZ()*1000; //1000 plano // 707 45° // <707 Casi vertical |
lucianotrujillo | 0:6ab157599e7f | 79 | //Si estoy mas inclinado q 45°, voy a leer adc |
lucianotrujillo | 0:6ab157599e7f | 80 | if ( ValorAcelerometro < SET_ACELEROMETRO ) { |
lucianotrujillo | 0:6ab157599e7f | 81 | Estados = CAPTURANDO_ADC; |
lucianotrujillo | 0:6ab157599e7f | 82 | printf("ESTADO MUESTREANDO\r\n"); |
lucianotrujillo | 0:6ab157599e7f | 83 | } |
lucianotrujillo | 0:6ab157599e7f | 84 | } |
lucianotrujillo | 0:6ab157599e7f | 85 | |
lucianotrujillo | 0:6ab157599e7f | 86 | // Si estoy configurado en T, leo TSI |
lucianotrujillo | 0:6ab157599e7f | 87 | if ( ModoDeMuestreo == 'T' ) |
lucianotrujillo | 0:6ab157599e7f | 88 | { |
lucianotrujillo | 0:6ab157599e7f | 89 | //Si estoy tocando en 0.7, voy a leer adc |
lucianotrujillo | 0:6ab157599e7f | 90 | ValorTouch = tsi.readPercentage(); |
lucianotrujillo | 0:6ab157599e7f | 91 | if ( ValorTouch > SET_TOUCH ) |
lucianotrujillo | 0:6ab157599e7f | 92 | Estados = CAPTURANDO_ADC; |
lucianotrujillo | 0:6ab157599e7f | 93 | } |
lucianotrujillo | 0:6ab157599e7f | 94 | break; |
lucianotrujillo | 0:6ab157599e7f | 95 | |
lucianotrujillo | 0:6ab157599e7f | 96 | case CAPTURANDO_ADC: |
lucianotrujillo | 0:6ab157599e7f | 97 | //Sistema midiendo |
lucianotrujillo | 0:6ab157599e7f | 98 | |
lucianotrujillo | 0:6ab157599e7f | 99 | //Led verde ON |
lucianotrujillo | 0:6ab157599e7f | 100 | lg = ON; |
lucianotrujillo | 0:6ab157599e7f | 101 | |
lucianotrujillo | 0:6ab157599e7f | 102 | //Me fijo que no se haya puesto la placa horizontal de nuevo |
lucianotrujillo | 0:6ab157599e7f | 103 | if ( ModoDeMuestreo == 'A' ) |
lucianotrujillo | 0:6ab157599e7f | 104 | { |
lucianotrujillo | 0:6ab157599e7f | 105 | ValorAcelerometro = acc.getAccZ()*1000; |
lucianotrujillo | 0:6ab157599e7f | 106 | if ( ValorAcelerometro >= SET_ACELEROMETRO ) { |
lucianotrujillo | 0:6ab157599e7f | 107 | Estados = REPOSO; |
lucianotrujillo | 0:6ab157599e7f | 108 | printf("ESTADO REPOSO\r\n"); |
lucianotrujillo | 0:6ab157599e7f | 109 | } |
lucianotrujillo | 0:6ab157599e7f | 110 | } |
lucianotrujillo | 0:6ab157599e7f | 111 | |
lucianotrujillo | 0:6ab157599e7f | 112 | //Me fijo que no se haya corrido el dedo del TSI |
lucianotrujillo | 0:6ab157599e7f | 113 | if ( ModoDeMuestreo == 'T' ) |
lucianotrujillo | 0:6ab157599e7f | 114 | { |
lucianotrujillo | 0:6ab157599e7f | 115 | ValorTouch = tsi.readPercentage(); |
lucianotrujillo | 0:6ab157599e7f | 116 | if ( ValorTouch <= SET_TOUCH ) { |
lucianotrujillo | 0:6ab157599e7f | 117 | Estados = REPOSO; |
lucianotrujillo | 0:6ab157599e7f | 118 | printf("ESTADO REPOSO\r\n"); |
lucianotrujillo | 0:6ab157599e7f | 119 | } |
lucianotrujillo | 0:6ab157599e7f | 120 | } |
lucianotrujillo | 0:6ab157599e7f | 121 | |
lucianotrujillo | 0:6ab157599e7f | 122 | //Si el timer me lo permite, leo ADC |
lucianotrujillo | 0:6ab157599e7f | 123 | if ( fMuestras == TRUE ) |
lucianotrujillo | 0:6ab157599e7f | 124 | { |
lucianotrujillo | 0:6ab157599e7f | 125 | fMuestras = FALSE; |
lucianotrujillo | 0:6ab157599e7f | 126 | ValoresMedidos[ indice ] = ValorConversor*100; |
lucianotrujillo | 0:6ab157599e7f | 127 | printf("GUARDADO %i \r\n",ValoresMedidos[ indice ]); |
lucianotrujillo | 0:6ab157599e7f | 128 | indice ++; |
lucianotrujillo | 0:6ab157599e7f | 129 | if ( indice == 20 ) { |
lucianotrujillo | 0:6ab157599e7f | 130 | //Si llegue a los 20 datos, me voy al estado FULL |
lucianotrujillo | 0:6ab157599e7f | 131 | Estados = DATOS_FULL; |
lucianotrujillo | 0:6ab157599e7f | 132 | printf("ESTADO FULL\r\n"); |
lucianotrujillo | 0:6ab157599e7f | 133 | } |
lucianotrujillo | 0:6ab157599e7f | 134 | } |
lucianotrujillo | 0:6ab157599e7f | 135 | break; |
lucianotrujillo | 0:6ab157599e7f | 136 | |
lucianotrujillo | 0:6ab157599e7f | 137 | case DATOS_FULL: |
lucianotrujillo | 0:6ab157599e7f | 138 | //Sistema con 20 muestras tomadas. |
lucianotrujillo | 0:6ab157599e7f | 139 | |
lucianotrujillo | 0:6ab157599e7f | 140 | //Led rojo titilando |
lucianotrujillo | 0:6ab157599e7f | 141 | lg = OFF; |
lucianotrujillo | 0:6ab157599e7f | 142 | blink_lr(); |
lucianotrujillo | 0:6ab157599e7f | 143 | |
lucianotrujillo | 0:6ab157599e7f | 144 | //Me pueden preguntar configuracion |
lucianotrujillo | 0:6ab157599e7f | 145 | resultado = RecepcionDeTrama ( ); |
lucianotrujillo | 0:6ab157599e7f | 146 | if(resultado == SOLICITUD_DE_CONFIGURACION) |
lucianotrujillo | 0:6ab157599e7f | 147 | Transmitir_RC ( ); |
lucianotrujillo | 0:6ab157599e7f | 148 | |
lucianotrujillo | 0:6ab157599e7f | 149 | //Me pueden decir que libere los datos |
lucianotrujillo | 0:6ab157599e7f | 150 | if(resultado == SOLICITUD_DE_MUESTRAS) { |
lucianotrujillo | 0:6ab157599e7f | 151 | Transmitir_RM ( ); |
lucianotrujillo | 0:6ab157599e7f | 152 | printf("ESTADO DESHABILITADO\r\n"); |
lucianotrujillo | 0:6ab157599e7f | 153 | Estados = DESHABILITADO; //Consigna no lo aclara, hago que vuelva a reposo |
lucianotrujillo | 0:6ab157599e7f | 154 | } |
lucianotrujillo | 0:6ab157599e7f | 155 | break; |
lucianotrujillo | 0:6ab157599e7f | 156 | } |
lucianotrujillo | 0:6ab157599e7f | 157 | } |
lucianotrujillo | 0:6ab157599e7f | 158 | |
lucianotrujillo | 0:6ab157599e7f | 159 | //PARPADEO LED ROJO |
lucianotrujillo | 0:6ab157599e7f | 160 | void blink_lr() { |
lucianotrujillo | 0:6ab157599e7f | 161 | if(fLr) |
lucianotrujillo | 0:6ab157599e7f | 162 | lr = ON; |
lucianotrujillo | 0:6ab157599e7f | 163 | else |
lucianotrujillo | 0:6ab157599e7f | 164 | lr = OFF; |
lucianotrujillo | 0:6ab157599e7f | 165 | } |
lucianotrujillo | 0:6ab157599e7f | 166 | |
lucianotrujillo | 0:6ab157599e7f | 167 | //PARPADEO LED VERDE |
lucianotrujillo | 0:6ab157599e7f | 168 | void blink_lg() { |
lucianotrujillo | 0:6ab157599e7f | 169 | if(fLg) |
lucianotrujillo | 0:6ab157599e7f | 170 | lg = ON; |
lucianotrujillo | 0:6ab157599e7f | 171 | else |
lucianotrujillo | 0:6ab157599e7f | 172 | lg = OFF; |
lucianotrujillo | 0:6ab157599e7f | 173 | } |
lucianotrujillo | 0:6ab157599e7f | 174 | |
lucianotrujillo | 0:6ab157599e7f | 175 | //SACO DATO, SI ESTABA VACIA LE MANDO -1 |
lucianotrujillo | 0:6ab157599e7f | 176 | int LeerDatoDelBufferCircular ( void ) |
lucianotrujillo | 0:6ab157599e7f | 177 | { |
lucianotrujillo | 0:6ab157599e7f | 178 | int dato = -1; |
lucianotrujillo | 0:6ab157599e7f | 179 | if ( RX_in != RX_out ) |
lucianotrujillo | 0:6ab157599e7f | 180 | { |
lucianotrujillo | 0:6ab157599e7f | 181 | dato = bufferRX [RX_out]; |
lucianotrujillo | 0:6ab157599e7f | 182 | RX_out ++; |
lucianotrujillo | 0:6ab157599e7f | 183 | if ( RX_out == MAX_BUFFER ) |
lucianotrujillo | 0:6ab157599e7f | 184 | RX_out = 0; |
lucianotrujillo | 0:6ab157599e7f | 185 | } |
lucianotrujillo | 0:6ab157599e7f | 186 | return dato; |
lucianotrujillo | 0:6ab157599e7f | 187 | } |
lucianotrujillo | 0:6ab157599e7f | 188 | |
lucianotrujillo | 0:6ab157599e7f | 189 | //CARGO A LA COLA |
lucianotrujillo | 0:6ab157599e7f | 190 | void CargarDatoAlBufferCircular ( unsigned char dato ) |
lucianotrujillo | 0:6ab157599e7f | 191 | { |
lucianotrujillo | 0:6ab157599e7f | 192 | bufferRX [RX_in] = dato; |
lucianotrujillo | 0:6ab157599e7f | 193 | RX_in ++; |
lucianotrujillo | 0:6ab157599e7f | 194 | if ( RX_in == MAX_BUFFER ) |
lucianotrujillo | 0:6ab157599e7f | 195 | RX_in = 0; |
lucianotrujillo | 0:6ab157599e7f | 196 | } |
lucianotrujillo | 0:6ab157599e7f | 197 | |
lucianotrujillo | 0:6ab157599e7f | 198 | // RTA AL PEDIDO DE DATOS >QM*1C< |
lucianotrujillo | 0:6ab157599e7f | 199 | void Transmitir_RM ( void ) |
lucianotrujillo | 0:6ab157599e7f | 200 | { |
lucianotrujillo | 0:6ab157599e7f | 201 | int i, myxor = 0; |
lucianotrujillo | 0:6ab157599e7f | 202 | myxor = 'R'; |
lucianotrujillo | 0:6ab157599e7f | 203 | myxor = myxor ^ 'M'; |
lucianotrujillo | 0:6ab157599e7f | 204 | // aca tendria que hacer xor = xor ^ ',' PERO NO LO HAGO |
lucianotrujillo | 0:6ab157599e7f | 205 | // CUANDO SALGO DEL for ME QUEDA SOBRANDO UNO |
lucianotrujillo | 0:6ab157599e7f | 206 | for (i = 0 ; i < 20 ; i++ ) |
lucianotrujillo | 0:6ab157599e7f | 207 | { |
lucianotrujillo | 0:6ab157599e7f | 208 | myxor = myxor ^ ValoresMedidos[i]; |
lucianotrujillo | 0:6ab157599e7f | 209 | myxor = myxor ^ ','; |
lucianotrujillo | 0:6ab157599e7f | 210 | } |
lucianotrujillo | 0:6ab157599e7f | 211 | |
lucianotrujillo | 0:6ab157599e7f | 212 | printf(">RM"); |
lucianotrujillo | 0:6ab157599e7f | 213 | |
lucianotrujillo | 0:6ab157599e7f | 214 | for (i = 0 ; i < 20 ; i++ ) |
lucianotrujillo | 0:6ab157599e7f | 215 | { |
lucianotrujillo | 0:6ab157599e7f | 216 | printf( ",%02X" , ValoresMedidos[i] ); |
lucianotrujillo | 0:6ab157599e7f | 217 | } |
lucianotrujillo | 0:6ab157599e7f | 218 | printf("*%02X<\r\n", myxor); |
lucianotrujillo | 0:6ab157599e7f | 219 | } |
lucianotrujillo | 0:6ab157599e7f | 220 | |
lucianotrujillo | 0:6ab157599e7f | 221 | // RTA AL PEDIDO DE CONFIG >QC*12< |
lucianotrujillo | 0:6ab157599e7f | 222 | void Transmitir_RC ( void ) |
lucianotrujillo | 0:6ab157599e7f | 223 | { |
lucianotrujillo | 0:6ab157599e7f | 224 | int myxor = 0; |
lucianotrujillo | 0:6ab157599e7f | 225 | myxor = 'R'; |
lucianotrujillo | 0:6ab157599e7f | 226 | myxor = myxor ^ 'C'; |
lucianotrujillo | 0:6ab157599e7f | 227 | myxor = myxor ^ ','; |
lucianotrujillo | 0:6ab157599e7f | 228 | myxor = myxor ^ ( TiempoDeMuestreo + '0'); |
lucianotrujillo | 0:6ab157599e7f | 229 | myxor = myxor ^ ','; |
lucianotrujillo | 0:6ab157599e7f | 230 | myxor = myxor ^ ModoDeMuestreo; |
lucianotrujillo | 0:6ab157599e7f | 231 | printf(">RC,%d,%c*%02X<\r\n" , TiempoDeMuestreo , ModoDeMuestreo ,myxor); |
lucianotrujillo | 0:6ab157599e7f | 232 | } |
lucianotrujillo | 0:6ab157599e7f | 233 | |
lucianotrujillo | 0:6ab157599e7f | 234 | |
lucianotrujillo | 0:6ab157599e7f | 235 | //COMUNICACION |
lucianotrujillo | 0:6ab157599e7f | 236 | |
lucianotrujillo | 0:6ab157599e7f | 237 | // analiza las tranas recibidas |
lucianotrujillo | 0:6ab157599e7f | 238 | // devuelve el resultado del analisis |
lucianotrujillo | 0:6ab157599e7f | 239 | // CONFIGURACION_RECIBIDA 1 |
lucianotrujillo | 0:6ab157599e7f | 240 | // SOLICITUD_DE_CONFIGURACION 2 |
lucianotrujillo | 0:6ab157599e7f | 241 | // SOLICITUD_DE_MUESTRAS 3 |
lucianotrujillo | 0:6ab157599e7f | 242 | // si no es ningun caso anterior -1 |
lucianotrujillo | 0:6ab157599e7f | 243 | int RecepcionDeTrama ( void ) |
lucianotrujillo | 0:6ab157599e7f | 244 | { |
lucianotrujillo | 0:6ab157599e7f | 245 | static unsigned char EstadoRecepcion = ENCABEZADO; |
lucianotrujillo | 0:6ab157599e7f | 246 | static unsigned char chequeoCalculado = 0 ; |
lucianotrujillo | 0:6ab157599e7f | 247 | static unsigned char EstadoSiguienteComa ; |
lucianotrujillo | 0:6ab157599e7f | 248 | static unsigned char inx = 0 , accion; |
lucianotrujillo | 0:6ab157599e7f | 249 | static char chequeo[ 3 ] ; |
lucianotrujillo | 0:6ab157599e7f | 250 | static int salida = -1; |
lucianotrujillo | 0:6ab157599e7f | 251 | int requerimiento = -1; |
lucianotrujillo | 0:6ab157599e7f | 252 | int dato ; |
lucianotrujillo | 0:6ab157599e7f | 253 | unsigned char chequeoRecibido , resultado; |
lucianotrujillo | 0:6ab157599e7f | 254 | |
lucianotrujillo | 0:6ab157599e7f | 255 | dato = LeerDatoDelBufferCircular ( ); |
lucianotrujillo | 0:6ab157599e7f | 256 | |
lucianotrujillo | 0:6ab157599e7f | 257 | if ( dato != -1 ) |
lucianotrujillo | 0:6ab157599e7f | 258 | { |
lucianotrujillo | 0:6ab157599e7f | 259 | switch ( EstadoRecepcion ) |
lucianotrujillo | 0:6ab157599e7f | 260 | { |
lucianotrujillo | 0:6ab157599e7f | 261 | case ENCABEZADO : |
lucianotrujillo | 0:6ab157599e7f | 262 | inx = 0; |
lucianotrujillo | 0:6ab157599e7f | 263 | chequeoCalculado = 0; |
lucianotrujillo | 0:6ab157599e7f | 264 | if ( dato == '>') |
lucianotrujillo | 0:6ab157599e7f | 265 | EstadoRecepcion = ACCION; |
lucianotrujillo | 0:6ab157599e7f | 266 | break; |
lucianotrujillo | 0:6ab157599e7f | 267 | case ACCION : |
lucianotrujillo | 0:6ab157599e7f | 268 | if ( dato == 'S' || dato == 'Q') |
lucianotrujillo | 0:6ab157599e7f | 269 | { |
lucianotrujillo | 0:6ab157599e7f | 270 | accion = (unsigned char) dato ; |
lucianotrujillo | 0:6ab157599e7f | 271 | chequeoCalculado = (unsigned char) dato ; |
lucianotrujillo | 0:6ab157599e7f | 272 | EstadoRecepcion = COMANDO; |
lucianotrujillo | 0:6ab157599e7f | 273 | break; |
lucianotrujillo | 0:6ab157599e7f | 274 | } |
lucianotrujillo | 0:6ab157599e7f | 275 | |
lucianotrujillo | 0:6ab157599e7f | 276 | EstadoRecepcion = ENCABEZADO; |
lucianotrujillo | 0:6ab157599e7f | 277 | if( dato == '>' ) { |
lucianotrujillo | 0:6ab157599e7f | 278 | EstadoRecepcion = ACCION; |
lucianotrujillo | 0:6ab157599e7f | 279 | inx = 0; |
lucianotrujillo | 0:6ab157599e7f | 280 | chequeoCalculado = 0; |
lucianotrujillo | 0:6ab157599e7f | 281 | } |
lucianotrujillo | 0:6ab157599e7f | 282 | break; |
lucianotrujillo | 0:6ab157599e7f | 283 | case COMANDO : |
lucianotrujillo | 0:6ab157599e7f | 284 | if ( accion == 'S' && dato == 'C') // Me setean la configuracion si es configuracion! |
lucianotrujillo | 0:6ab157599e7f | 285 | { |
lucianotrujillo | 0:6ab157599e7f | 286 | salida = CONFIGURACION_RECIBIDA; |
lucianotrujillo | 0:6ab157599e7f | 287 | EstadoRecepcion = COMA; |
lucianotrujillo | 0:6ab157599e7f | 288 | EstadoSiguienteComa = TIEMPO_MUESTREO; |
lucianotrujillo | 0:6ab157599e7f | 289 | chequeoCalculado = chequeoCalculado ^ (unsigned char) dato ; |
lucianotrujillo | 0:6ab157599e7f | 290 | break; |
lucianotrujillo | 0:6ab157599e7f | 291 | } |
lucianotrujillo | 0:6ab157599e7f | 292 | |
lucianotrujillo | 0:6ab157599e7f | 293 | if ( accion == 'Q' && dato == 'C') // Me consultan la configuracion! |
lucianotrujillo | 0:6ab157599e7f | 294 | { |
lucianotrujillo | 0:6ab157599e7f | 295 | salida = SOLICITUD_DE_CONFIGURACION; |
lucianotrujillo | 0:6ab157599e7f | 296 | EstadoRecepcion = ASTERISCO; |
lucianotrujillo | 0:6ab157599e7f | 297 | chequeoCalculado = chequeoCalculado ^ (unsigned char) dato ; |
lucianotrujillo | 0:6ab157599e7f | 298 | break; |
lucianotrujillo | 0:6ab157599e7f | 299 | } |
lucianotrujillo | 0:6ab157599e7f | 300 | |
lucianotrujillo | 0:6ab157599e7f | 301 | if ( dato == 'M') // me piden las muestras! |
lucianotrujillo | 0:6ab157599e7f | 302 | { |
lucianotrujillo | 0:6ab157599e7f | 303 | salida = SOLICITUD_DE_MUESTRAS; |
lucianotrujillo | 0:6ab157599e7f | 304 | EstadoRecepcion = ASTERISCO; |
lucianotrujillo | 0:6ab157599e7f | 305 | chequeoCalculado = chequeoCalculado ^ (unsigned char) dato ; |
lucianotrujillo | 0:6ab157599e7f | 306 | break; |
lucianotrujillo | 0:6ab157599e7f | 307 | } |
lucianotrujillo | 0:6ab157599e7f | 308 | |
lucianotrujillo | 0:6ab157599e7f | 309 | EstadoRecepcion = ENCABEZADO; |
lucianotrujillo | 0:6ab157599e7f | 310 | if( dato == '>' ) { |
lucianotrujillo | 0:6ab157599e7f | 311 | EstadoRecepcion = ACCION; |
lucianotrujillo | 0:6ab157599e7f | 312 | inx = 0; |
lucianotrujillo | 0:6ab157599e7f | 313 | chequeoCalculado = 0; |
lucianotrujillo | 0:6ab157599e7f | 314 | } |
lucianotrujillo | 0:6ab157599e7f | 315 | break; |
lucianotrujillo | 0:6ab157599e7f | 316 | |
lucianotrujillo | 0:6ab157599e7f | 317 | case COMA : |
lucianotrujillo | 0:6ab157599e7f | 318 | if ( dato == ',') |
lucianotrujillo | 0:6ab157599e7f | 319 | { |
lucianotrujillo | 0:6ab157599e7f | 320 | EstadoRecepcion = EstadoSiguienteComa; |
lucianotrujillo | 0:6ab157599e7f | 321 | chequeoCalculado = chequeoCalculado ^ (unsigned char) dato ; |
lucianotrujillo | 0:6ab157599e7f | 322 | break; |
lucianotrujillo | 0:6ab157599e7f | 323 | } |
lucianotrujillo | 0:6ab157599e7f | 324 | EstadoRecepcion = ENCABEZADO; |
lucianotrujillo | 0:6ab157599e7f | 325 | if( dato == '>' ) { |
lucianotrujillo | 0:6ab157599e7f | 326 | EstadoRecepcion = ACCION; |
lucianotrujillo | 0:6ab157599e7f | 327 | inx = 0; |
lucianotrujillo | 0:6ab157599e7f | 328 | chequeoCalculado = 0; |
lucianotrujillo | 0:6ab157599e7f | 329 | } |
lucianotrujillo | 0:6ab157599e7f | 330 | break; |
lucianotrujillo | 0:6ab157599e7f | 331 | |
lucianotrujillo | 0:6ab157599e7f | 332 | case TIEMPO_MUESTREO : |
lucianotrujillo | 0:6ab157599e7f | 333 | if ( dato >= '1' && dato <= '7' ) |
lucianotrujillo | 0:6ab157599e7f | 334 | { |
lucianotrujillo | 0:6ab157599e7f | 335 | TiempoDeMuestreo = dato - '0'; |
lucianotrujillo | 0:6ab157599e7f | 336 | EstadoRecepcion = COMA; |
lucianotrujillo | 0:6ab157599e7f | 337 | EstadoSiguienteComa = MODO_DE_MUESTREO; |
lucianotrujillo | 0:6ab157599e7f | 338 | chequeoCalculado = chequeoCalculado ^ (unsigned char) dato ; |
lucianotrujillo | 0:6ab157599e7f | 339 | break; |
lucianotrujillo | 0:6ab157599e7f | 340 | } |
lucianotrujillo | 0:6ab157599e7f | 341 | EstadoRecepcion = ENCABEZADO; |
lucianotrujillo | 0:6ab157599e7f | 342 | if( dato == '>' ) { |
lucianotrujillo | 0:6ab157599e7f | 343 | EstadoRecepcion = ACCION; |
lucianotrujillo | 0:6ab157599e7f | 344 | inx = 0; |
lucianotrujillo | 0:6ab157599e7f | 345 | chequeoCalculado = 0; |
lucianotrujillo | 0:6ab157599e7f | 346 | } |
lucianotrujillo | 0:6ab157599e7f | 347 | break; |
lucianotrujillo | 0:6ab157599e7f | 348 | |
lucianotrujillo | 0:6ab157599e7f | 349 | case MODO_DE_MUESTREO : |
lucianotrujillo | 0:6ab157599e7f | 350 | if ( dato == 'A' || dato == 'T' ) |
lucianotrujillo | 0:6ab157599e7f | 351 | { |
lucianotrujillo | 0:6ab157599e7f | 352 | ModoDeMuestreo = dato ; |
lucianotrujillo | 0:6ab157599e7f | 353 | EstadoRecepcion = ASTERISCO; |
lucianotrujillo | 0:6ab157599e7f | 354 | chequeoCalculado = chequeoCalculado ^ (unsigned char) dato ; |
lucianotrujillo | 0:6ab157599e7f | 355 | break; |
lucianotrujillo | 0:6ab157599e7f | 356 | } |
lucianotrujillo | 0:6ab157599e7f | 357 | EstadoRecepcion = ENCABEZADO; |
lucianotrujillo | 0:6ab157599e7f | 358 | if( dato == '>' ) { |
lucianotrujillo | 0:6ab157599e7f | 359 | EstadoRecepcion = ACCION; |
lucianotrujillo | 0:6ab157599e7f | 360 | inx = 0; |
lucianotrujillo | 0:6ab157599e7f | 361 | chequeoCalculado = 0; |
lucianotrujillo | 0:6ab157599e7f | 362 | } |
lucianotrujillo | 0:6ab157599e7f | 363 | break; |
lucianotrujillo | 0:6ab157599e7f | 364 | |
lucianotrujillo | 0:6ab157599e7f | 365 | case ASTERISCO : |
lucianotrujillo | 0:6ab157599e7f | 366 | if ( dato == '*' ) |
lucianotrujillo | 0:6ab157599e7f | 367 | { |
lucianotrujillo | 0:6ab157599e7f | 368 | EstadoRecepcion = CHEQUEO; |
lucianotrujillo | 0:6ab157599e7f | 369 | break; |
lucianotrujillo | 0:6ab157599e7f | 370 | } |
lucianotrujillo | 0:6ab157599e7f | 371 | EstadoRecepcion = ENCABEZADO; |
lucianotrujillo | 0:6ab157599e7f | 372 | if( dato == '>' ) { |
lucianotrujillo | 0:6ab157599e7f | 373 | EstadoRecepcion = ACCION; |
lucianotrujillo | 0:6ab157599e7f | 374 | inx = 0; |
lucianotrujillo | 0:6ab157599e7f | 375 | chequeoCalculado = 0; |
lucianotrujillo | 0:6ab157599e7f | 376 | } |
lucianotrujillo | 0:6ab157599e7f | 377 | break; |
lucianotrujillo | 0:6ab157599e7f | 378 | |
lucianotrujillo | 0:6ab157599e7f | 379 | case CHEQUEO : |
lucianotrujillo | 0:6ab157599e7f | 380 | if ( (dato >= '0' && dato <= '9') || (dato >= 'a' && dato <= 'f' ) || (dato >= 'A' && dato <= 'F' )) |
lucianotrujillo | 0:6ab157599e7f | 381 | { |
lucianotrujillo | 0:6ab157599e7f | 382 | if (dato >= '0' && dato <= '9') |
lucianotrujillo | 0:6ab157599e7f | 383 | dato = dato - '0'; |
lucianotrujillo | 0:6ab157599e7f | 384 | if (dato >= 'a' && dato <= 'f') |
lucianotrujillo | 0:6ab157599e7f | 385 | dato = dato - 'a' + 10; |
lucianotrujillo | 0:6ab157599e7f | 386 | if (dato >= 'A' && dato <= 'F') |
lucianotrujillo | 0:6ab157599e7f | 387 | dato = dato - 'A' + 10; |
lucianotrujillo | 0:6ab157599e7f | 388 | chequeo[ inx ] = (char) dato; |
lucianotrujillo | 0:6ab157599e7f | 389 | inx ++; |
lucianotrujillo | 0:6ab157599e7f | 390 | if ( inx == 2 ) |
lucianotrujillo | 0:6ab157599e7f | 391 | { |
lucianotrujillo | 0:6ab157599e7f | 392 | chequeoRecibido = chequeo[ 0 ] * 16 + chequeo[ 1 ]; |
lucianotrujillo | 0:6ab157599e7f | 393 | resultado = chequeoRecibido ^ chequeoCalculado; |
lucianotrujillo | 0:6ab157599e7f | 394 | if ( resultado == 0 ) |
lucianotrujillo | 0:6ab157599e7f | 395 | EstadoRecepcion = FIN_DE_TRAMA; |
lucianotrujillo | 0:6ab157599e7f | 396 | else |
lucianotrujillo | 0:6ab157599e7f | 397 | EstadoRecepcion = ENCABEZADO; |
lucianotrujillo | 0:6ab157599e7f | 398 | } |
lucianotrujillo | 0:6ab157599e7f | 399 | break; |
lucianotrujillo | 0:6ab157599e7f | 400 | } |
lucianotrujillo | 0:6ab157599e7f | 401 | EstadoRecepcion = ENCABEZADO; |
lucianotrujillo | 0:6ab157599e7f | 402 | if( dato == '>' ) { |
lucianotrujillo | 0:6ab157599e7f | 403 | EstadoRecepcion = ACCION; |
lucianotrujillo | 0:6ab157599e7f | 404 | inx = 0; |
lucianotrujillo | 0:6ab157599e7f | 405 | chequeoCalculado = 0; |
lucianotrujillo | 0:6ab157599e7f | 406 | } |
lucianotrujillo | 0:6ab157599e7f | 407 | break; |
lucianotrujillo | 0:6ab157599e7f | 408 | |
lucianotrujillo | 0:6ab157599e7f | 409 | case FIN_DE_TRAMA : |
lucianotrujillo | 0:6ab157599e7f | 410 | if ( dato != '<' ) |
lucianotrujillo | 0:6ab157599e7f | 411 | requerimiento = -1; |
lucianotrujillo | 0:6ab157599e7f | 412 | else |
lucianotrujillo | 0:6ab157599e7f | 413 | requerimiento = salida; |
lucianotrujillo | 0:6ab157599e7f | 414 | EstadoRecepcion = ENCABEZADO; |
lucianotrujillo | 0:6ab157599e7f | 415 | if( dato == '>' ) { |
lucianotrujillo | 0:6ab157599e7f | 416 | EstadoRecepcion = ACCION; |
lucianotrujillo | 0:6ab157599e7f | 417 | inx = 0; |
lucianotrujillo | 0:6ab157599e7f | 418 | chequeoCalculado = 0; |
lucianotrujillo | 0:6ab157599e7f | 419 | } |
lucianotrujillo | 0:6ab157599e7f | 420 | break; |
lucianotrujillo | 0:6ab157599e7f | 421 | } |
lucianotrujillo | 0:6ab157599e7f | 422 | } |
lucianotrujillo | 0:6ab157599e7f | 423 | return requerimiento; |
lucianotrujillo | 0:6ab157599e7f | 424 | } |