Proyecto de Tesis en Mecatrónica. Universidad Técnica del Norte. Ernesto Palacios <mecatronica.mid@gmail.com>
Dependencies: EthernetNetIf HTTPServer QEI_hw RPCInterface mbed
setup.cpp@26:dad0b2031173, 2013-12-29 (annotated)
- Committer:
- Yo_Robot
- Date:
- Sun Dec 29 21:47:15 2013 +0000
- Revision:
- 26:dad0b2031173
- Parent:
- 25:1910a55ff0a3
- Child:
- 27:b8254b76ec57
Agregado el "OK\n\r" como ACK
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Yo_Robot | 4:552beeda4722 | 1 | /** |
Yo_Robot | 4:552beeda4722 | 2 | * @file setup.cpp |
Yo_Robot | 4:552beeda4722 | 3 | * @author Ernesto Palacios |
Yo_Robot | 20:4b154134ab20 | 4 | * @brief Codigo Fuente de las funciones para el deslizador. |
Yo_Robot | 4:552beeda4722 | 5 | * |
Yo_Robot | 4:552beeda4722 | 6 | * Created on 25 de Marzo de 2012 |
Yo_Robot | 4:552beeda4722 | 7 | * |
Yo_Robot | 4:552beeda4722 | 8 | * Licencia GPL v3.0 |
Yo_Robot | 4:552beeda4722 | 9 | * http://www.gnu.org/licenses/gpl-3.0.html |
Yo_Robot | 4:552beeda4722 | 10 | */ |
Yo_Robot | 4:552beeda4722 | 11 | |
Yo_Robot | 25:1910a55ff0a3 | 12 | #include "mbed.h" |
Yo_Robot | 25:1910a55ff0a3 | 13 | #include "qeihw.h" |
Yo_Robot | 3:8d5a9e3cd680 | 14 | #include "setup.h" |
Yo_Robot | 18:cf1e07d82630 | 15 | #include "EthernetNetIf.h" |
Yo_Robot | 25:1910a55ff0a3 | 16 | |
Yo_Robot | 3:8d5a9e3cd680 | 17 | |
Yo_Robot | 24:a1d16835201c | 18 | extern Serial pc; // Salida Serial de mbed |
Yo_Robot | 24:a1d16835201c | 19 | extern Serial RS_232; // Salida Serial a MAX232 |
Yo_Robot | 25:1910a55ff0a3 | 20 | //extern I2C encoder; // Comunicacion I2C con encoder |
Yo_Robot | 25:1910a55ff0a3 | 21 | extern QEIHW encoder; |
Yo_Robot | 24:a1d16835201c | 22 | extern Timer crono; // Cronometro interno del microcontrolador |
Yo_Robot | 24:a1d16835201c | 23 | extern DigitalIn isPC; // Bit de configuracion serial en la placa |
Yo_Robot | 12:c02b08dacc45 | 24 | extern DigitalOut pin_son; // SON |
Yo_Robot | 12:c02b08dacc45 | 25 | extern DigitalOut pin_dir; // SIGN+ |
Yo_Robot | 12:c02b08dacc45 | 26 | extern InterruptIn pin_alm; // ALM |
Yo_Robot | 12:c02b08dacc45 | 27 | extern AnalogOut aout; // +-10V |
Yo_Robot | 22:d5431fff164b | 28 | extern DigitalOut led_verde; // Led verde del conector Ethernet |
Yo_Robot | 24:a1d16835201c | 29 | extern DigitalOut led_rojo; // Led naranja del conector Ethernet |
Yo_Robot | 20:4b154134ab20 | 30 | |
Yo_Robot | 15:a1ffa32ce9d1 | 31 | int fq_posicion = 10000; // Variable global donde se almacenara |
Yo_Robot | 15:a1ffa32ce9d1 | 32 | // la velocidad de posicionamiento en Hz |
Yo_Robot | 24:a1d16835201c | 33 | float t_alto; // para el posicionamiento del motor |
Yo_Robot | 23:2126e38bb48c | 34 | |
Yo_Robot | 26:dad0b2031173 | 35 | int fq_actual = 0; // Ultimo valor seteado para el tren de pulsos |
Yo_Robot | 22:d5431fff164b | 36 | |
Yo_Robot | 22:d5431fff164b | 37 | int read_encoder() |
Yo_Robot | 22:d5431fff164b | 38 | { |
Yo_Robot | 25:1910a55ff0a3 | 39 | return encoder.GetPosition(); |
Yo_Robot | 22:d5431fff164b | 40 | } |
Yo_Robot | 22:d5431fff164b | 41 | |
Yo_Robot | 22:d5431fff164b | 42 | void clear_encoder() |
Yo_Robot | 22:d5431fff164b | 43 | { |
Yo_Robot | 25:1910a55ff0a3 | 44 | encoder.Reset( QEI_RESET_POS ); // reset position |
Yo_Robot | 22:d5431fff164b | 45 | } |
Yo_Robot | 22:d5431fff164b | 46 | |
Yo_Robot | 4:552beeda4722 | 47 | void setTimer2() |
Yo_Robot | 3:8d5a9e3cd680 | 48 | { |
Yo_Robot | 3:8d5a9e3cd680 | 49 | // Encender Timer2 (PCONP[22]) |
Yo_Robot | 3:8d5a9e3cd680 | 50 | LPC_SC->PCONP |= 1 << 22; |
Yo_Robot | 3:8d5a9e3cd680 | 51 | |
Yo_Robot | 3:8d5a9e3cd680 | 52 | // Resetear y parar el Timer |
Yo_Robot | 3:8d5a9e3cd680 | 53 | LPC_TIM2->TCR = 0x2; |
Yo_Robot | 3:8d5a9e3cd680 | 54 | LPC_TIM2->CTCR = 0x0; |
Yo_Robot | 3:8d5a9e3cd680 | 55 | |
Yo_Robot | 4:552beeda4722 | 56 | // Establecer el Preescaler en cero |
Yo_Robot | 4:552beeda4722 | 57 | // SIn Preesclaer |
Yo_Robot | 4:552beeda4722 | 58 | LPC_TIM2->PR = 0; |
Yo_Robot | 3:8d5a9e3cd680 | 59 | |
Yo_Robot | 4:552beeda4722 | 60 | // Calcular el periodo Inicial |
Yo_Robot | 4:552beeda4722 | 61 | uint32_t periodo = ( SystemCoreClock / 400 ); |
Yo_Robot | 3:8d5a9e3cd680 | 62 | |
Yo_Robot | 3:8d5a9e3cd680 | 63 | // Establecer los Registros de Coincidencia |
Yo_Robot | 3:8d5a9e3cd680 | 64 | // ( Match Register ) |
Yo_Robot | 3:8d5a9e3cd680 | 65 | LPC_TIM2->MR2 = periodo; |
Yo_Robot | 4:552beeda4722 | 66 | LPC_TIM2->MR3 = periodo; // Legacy, salidas identicas |
Yo_Robot | 3:8d5a9e3cd680 | 67 | |
Yo_Robot | 4:552beeda4722 | 68 | LPC_TIM2->MCR |= 1 << 7; // Resetear Timer en MR2 |
Yo_Robot | 3:8d5a9e3cd680 | 69 | |
Yo_Robot | 3:8d5a9e3cd680 | 70 | LPC_TIM2->EMR |= 15UL << 8; // Alternar Pin MAT2.2 |
Yo_Robot | 3:8d5a9e3cd680 | 71 | // y MAT2.3 |
Yo_Robot | 3:8d5a9e3cd680 | 72 | |
Yo_Robot | 3:8d5a9e3cd680 | 73 | LPC_PINCON->PINSEL0 |= 15UL << 16; //Activar MAT2.2 |
Yo_Robot | 8:958dfe5052b9 | 74 | // y MAT2.3 como salidas |
Yo_Robot | 8:958dfe5052b9 | 75 | |
Yo_Robot | 6:b4dae934e1ea | 76 | } |
Yo_Robot | 6:b4dae934e1ea | 77 | |
Yo_Robot | 12:c02b08dacc45 | 78 | void ISR_Serial() |
Yo_Robot | 12:c02b08dacc45 | 79 | { |
Yo_Robot | 12:c02b08dacc45 | 80 | int value; // Nuevo Valor |
Yo_Robot | 12:c02b08dacc45 | 81 | char command; // Comando al que aplicar el nuevo valor |
Yo_Robot | 23:2126e38bb48c | 82 | |
Yo_Robot | 12:c02b08dacc45 | 83 | |
Yo_Robot | 19:c26cf8a48986 | 84 | if( isPC ) |
Yo_Robot | 23:2126e38bb48c | 85 | pc.scanf( "%d-%c", &value, &command ); |
Yo_Robot | 19:c26cf8a48986 | 86 | else |
Yo_Robot | 23:2126e38bb48c | 87 | RS_232.scanf( "%d-%c", &value, &command ); |
Yo_Robot | 23:2126e38bb48c | 88 | |
Yo_Robot | 23:2126e38bb48c | 89 | switch( command ) |
Yo_Robot | 23:2126e38bb48c | 90 | { |
Yo_Robot | 19:c26cf8a48986 | 91 | |
Yo_Robot | 24:a1d16835201c | 92 | case 'R': // Leer la velocidad en RPMs del encoder |
Yo_Robot | 24:a1d16835201c | 93 | { |
Yo_Robot | 23:2126e38bb48c | 94 | int ang = 0; |
Yo_Robot | 23:2126e38bb48c | 95 | float rpm; |
Yo_Robot | 23:2126e38bb48c | 96 | |
Yo_Robot | 23:2126e38bb48c | 97 | clear_encoder(); // Encerar encoder |
Yo_Robot | 23:2126e38bb48c | 98 | crono.reset(); // Encerar el cronometro; |
Yo_Robot | 23:2126e38bb48c | 99 | |
Yo_Robot | 23:2126e38bb48c | 100 | while( ang == 0 ) // Esperar hasta q exista lectura del encoder |
Yo_Robot | 23:2126e38bb48c | 101 | ang = read_encoder(); // Leer nueva posicion |
Yo_Robot | 23:2126e38bb48c | 102 | |
Yo_Robot | 23:2126e38bb48c | 103 | crono.stop(); // detener cronometro |
Yo_Robot | 23:2126e38bb48c | 104 | rpm = ( ang * 500 ) / (crono.read_ms() * 3 ); |
Yo_Robot | 23:2126e38bb48c | 105 | |
Yo_Robot | 24:a1d16835201c | 106 | // grados 1000 ms 60 s 1 Rev 500 Rev |
Yo_Robot | 24:a1d16835201c | 107 | // ------ * -------- * ------ * ---------- = -------- |
Yo_Robot | 24:a1d16835201c | 108 | // ms 1s 1min 360 grad 3 Min |
Yo_Robot | 23:2126e38bb48c | 109 | |
Yo_Robot | 26:dad0b2031173 | 110 | if( isPC ) |
Yo_Robot | 26:dad0b2031173 | 111 | pc.printf("%f", rpm); |
Yo_Robot | 26:dad0b2031173 | 112 | else |
Yo_Robot | 26:dad0b2031173 | 113 | RS_232.printf("%f", rpm); |
Yo_Robot | 23:2126e38bb48c | 114 | break; |
Yo_Robot | 24:a1d16835201c | 115 | } |
Yo_Robot | 23:2126e38bb48c | 116 | case 'H': // Establecer nueva frecuencia |
Yo_Robot | 24:a1d16835201c | 117 | { |
Yo_Robot | 23:2126e38bb48c | 118 | setPTO( value ); |
Yo_Robot | 26:dad0b2031173 | 119 | fq_actual = value; |
Yo_Robot | 26:dad0b2031173 | 120 | |
Yo_Robot | 26:dad0b2031173 | 121 | // Envia un OK de comando recibido |
Yo_Robot | 26:dad0b2031173 | 122 | if( isPC ) |
Yo_Robot | 26:dad0b2031173 | 123 | pc.printf("OK\r\n"); |
Yo_Robot | 26:dad0b2031173 | 124 | else |
Yo_Robot | 26:dad0b2031173 | 125 | RS_232.printf("OK\r\n"); |
Yo_Robot | 26:dad0b2031173 | 126 | |
Yo_Robot | 23:2126e38bb48c | 127 | break; |
Yo_Robot | 24:a1d16835201c | 128 | } |
Yo_Robot | 23:2126e38bb48c | 129 | case 'K': |
Yo_Robot | 24:a1d16835201c | 130 | { |
Yo_Robot | 23:2126e38bb48c | 131 | setPTO( value * 1000 ); |
Yo_Robot | 26:dad0b2031173 | 132 | fq_actual = value; |
Yo_Robot | 26:dad0b2031173 | 133 | // Envia un OK de comando recibido |
Yo_Robot | 26:dad0b2031173 | 134 | if( isPC ) |
Yo_Robot | 26:dad0b2031173 | 135 | pc.printf("OK\r\n"); |
Yo_Robot | 26:dad0b2031173 | 136 | else |
Yo_Robot | 26:dad0b2031173 | 137 | RS_232.printf("OK\r\n"); |
Yo_Robot | 26:dad0b2031173 | 138 | |
Yo_Robot | 23:2126e38bb48c | 139 | break; |
Yo_Robot | 24:a1d16835201c | 140 | } |
Yo_Robot | 23:2126e38bb48c | 141 | case 'A': // Cambiar voltaje de salida |
Yo_Robot | 24:a1d16835201c | 142 | { |
Yo_Robot | 23:2126e38bb48c | 143 | aout = (float)( value + 10000.0 ) / 20000.0; |
Yo_Robot | 26:dad0b2031173 | 144 | |
Yo_Robot | 26:dad0b2031173 | 145 | // Envia un OK de comando recibido |
Yo_Robot | 26:dad0b2031173 | 146 | if( isPC ) |
Yo_Robot | 26:dad0b2031173 | 147 | pc.printf("OK\r\n"); |
Yo_Robot | 26:dad0b2031173 | 148 | else |
Yo_Robot | 26:dad0b2031173 | 149 | RS_232.printf("OK\r\n"); |
Yo_Robot | 26:dad0b2031173 | 150 | |
Yo_Robot | 23:2126e38bb48c | 151 | break; |
Yo_Robot | 24:a1d16835201c | 152 | } |
Yo_Robot | 23:2126e38bb48c | 153 | case 'D': // Cambiar la direccion |
Yo_Robot | 24:a1d16835201c | 154 | { |
Yo_Robot | 26:dad0b2031173 | 155 | |
Yo_Robot | 23:2126e38bb48c | 156 | stopTimer2(); |
Yo_Robot | 23:2126e38bb48c | 157 | pin_dir = value; |
Yo_Robot | 23:2126e38bb48c | 158 | wait_us( 2 ); |
Yo_Robot | 26:dad0b2031173 | 159 | |
Yo_Robot | 26:dad0b2031173 | 160 | if ( fq_actual != 0 ) |
Yo_Robot | 26:dad0b2031173 | 161 | { |
Yo_Robot | 26:dad0b2031173 | 162 | startTimer2(); |
Yo_Robot | 26:dad0b2031173 | 163 | } |
Yo_Robot | 26:dad0b2031173 | 164 | |
Yo_Robot | 26:dad0b2031173 | 165 | // Envia un OK de comando recibido |
Yo_Robot | 26:dad0b2031173 | 166 | if( isPC ) |
Yo_Robot | 26:dad0b2031173 | 167 | pc.printf("OK\r\n"); |
Yo_Robot | 26:dad0b2031173 | 168 | else |
Yo_Robot | 26:dad0b2031173 | 169 | RS_232.printf("OK\r\n"); |
Yo_Robot | 26:dad0b2031173 | 170 | |
Yo_Robot | 23:2126e38bb48c | 171 | break; |
Yo_Robot | 24:a1d16835201c | 172 | } |
Yo_Robot | 23:2126e38bb48c | 173 | case 'V': //Setear la velocidad de Posicionamiento |
Yo_Robot | 24:a1d16835201c | 174 | { |
Yo_Robot | 23:2126e38bb48c | 175 | fq_posicion = value; |
Yo_Robot | 26:dad0b2031173 | 176 | |
Yo_Robot | 26:dad0b2031173 | 177 | // Envia un OK de comando recibido |
Yo_Robot | 26:dad0b2031173 | 178 | if( isPC ) |
Yo_Robot | 26:dad0b2031173 | 179 | pc.printf("OK\r\n"); |
Yo_Robot | 26:dad0b2031173 | 180 | else |
Yo_Robot | 26:dad0b2031173 | 181 | RS_232.printf("OK\r\n"); |
Yo_Robot | 26:dad0b2031173 | 182 | |
Yo_Robot | 23:2126e38bb48c | 183 | break; |
Yo_Robot | 24:a1d16835201c | 184 | } |
Yo_Robot | 23:2126e38bb48c | 185 | // Generar un numero definido de pulsos a la velocidad de posicionamiento |
Yo_Robot | 23:2126e38bb48c | 186 | case 'G': |
Yo_Robot | 24:a1d16835201c | 187 | { |
Yo_Robot | 23:2126e38bb48c | 188 | int pulsos = value; //Numero de pulsos a generar |
Yo_Robot | 23:2126e38bb48c | 189 | t_alto = pulsos / fq_posicion; //Tiempo que debe ser generado el tren de pulsos. |
Yo_Robot | 23:2126e38bb48c | 190 | |
Yo_Robot | 23:2126e38bb48c | 191 | stopTimer2(); //Deten el tren de pulsos |
Yo_Robot | 23:2126e38bb48c | 192 | setPTO( fq_posicion ); //Nueva frecuencia de salida |
Yo_Robot | 23:2126e38bb48c | 193 | startTimer2(); //Inicia el tren de pulsos |
Yo_Robot | 23:2126e38bb48c | 194 | wait( t_alto ); //Espera hasta llegar a la posicion |
Yo_Robot | 23:2126e38bb48c | 195 | stopTimer2(); //Posicion alcanzada ALTO. |
Yo_Robot | 26:dad0b2031173 | 196 | |
Yo_Robot | 26:dad0b2031173 | 197 | |
Yo_Robot | 26:dad0b2031173 | 198 | // Envia un OK de comando recibido |
Yo_Robot | 26:dad0b2031173 | 199 | if( isPC ) |
Yo_Robot | 26:dad0b2031173 | 200 | pc.printf("OK\r\n"); |
Yo_Robot | 26:dad0b2031173 | 201 | else |
Yo_Robot | 26:dad0b2031173 | 202 | RS_232.printf("OK\r\n"); |
Yo_Robot | 26:dad0b2031173 | 203 | |
Yo_Robot | 26:dad0b2031173 | 204 | |
Yo_Robot | 23:2126e38bb48c | 205 | break; |
Yo_Robot | 24:a1d16835201c | 206 | } |
Yo_Robot | 24:a1d16835201c | 207 | case 'E': //Leer posicion angular relativa del encoder |
Yo_Robot | 24:a1d16835201c | 208 | { |
Yo_Robot | 23:2126e38bb48c | 209 | if( isPC ) |
Yo_Robot | 23:2126e38bb48c | 210 | pc.printf( "%d",read_encoder() ); |
Yo_Robot | 23:2126e38bb48c | 211 | else |
Yo_Robot | 23:2126e38bb48c | 212 | RS_232.printf( "%d",read_encoder() ); |
Yo_Robot | 23:2126e38bb48c | 213 | break; |
Yo_Robot | 24:a1d16835201c | 214 | } |
Yo_Robot | 26:dad0b2031173 | 215 | |
Yo_Robot | 23:2126e38bb48c | 216 | case 'Z': //Limpiar contador encoder |
Yo_Robot | 23:2126e38bb48c | 217 | clear_encoder(); |
Yo_Robot | 26:dad0b2031173 | 218 | |
Yo_Robot | 26:dad0b2031173 | 219 | // Envia un OK de comando recibido |
Yo_Robot | 26:dad0b2031173 | 220 | if( isPC ) |
Yo_Robot | 26:dad0b2031173 | 221 | pc.printf("OK\r\n"); |
Yo_Robot | 26:dad0b2031173 | 222 | else |
Yo_Robot | 26:dad0b2031173 | 223 | RS_232.printf("OK\r\n"); |
Yo_Robot | 26:dad0b2031173 | 224 | |
Yo_Robot | 23:2126e38bb48c | 225 | break; |
Yo_Robot | 23:2126e38bb48c | 226 | |
Yo_Robot | 23:2126e38bb48c | 227 | case 'S': //Encender el Servo |
Yo_Robot | 26:dad0b2031173 | 228 | |
Yo_Robot | 23:2126e38bb48c | 229 | pin_son = value; |
Yo_Robot | 26:dad0b2031173 | 230 | |
Yo_Robot | 26:dad0b2031173 | 231 | // Envia un OK de comando recibido |
Yo_Robot | 26:dad0b2031173 | 232 | if( isPC ) |
Yo_Robot | 26:dad0b2031173 | 233 | pc.printf("OK\r\n"); |
Yo_Robot | 26:dad0b2031173 | 234 | else |
Yo_Robot | 26:dad0b2031173 | 235 | RS_232.printf("OK\r\n"); |
Yo_Robot | 26:dad0b2031173 | 236 | |
Yo_Robot | 23:2126e38bb48c | 237 | break; |
Yo_Robot | 18:cf1e07d82630 | 238 | } |
Yo_Robot | 23:2126e38bb48c | 239 | |
Yo_Robot | 12:c02b08dacc45 | 240 | } |
Yo_Robot | 12:c02b08dacc45 | 241 | |
Yo_Robot | 12:c02b08dacc45 | 242 | |
Yo_Robot | 12:c02b08dacc45 | 243 | void setPTO( int freq ) |
Yo_Robot | 12:c02b08dacc45 | 244 | { |
Yo_Robot | 12:c02b08dacc45 | 245 | if( freq != 0 ) |
Yo_Robot | 12:c02b08dacc45 | 246 | { |
Yo_Robot | 12:c02b08dacc45 | 247 | LPC_TIM2->TC = 0x00; //Resetear Timer |
Yo_Robot | 12:c02b08dacc45 | 248 | setMR2( getMRvalue( freq ) ); |
Yo_Robot | 12:c02b08dacc45 | 249 | startTimer2(); |
Yo_Robot | 12:c02b08dacc45 | 250 | |
Yo_Robot | 12:c02b08dacc45 | 251 | }else{ |
Yo_Robot | 12:c02b08dacc45 | 252 | |
Yo_Robot | 12:c02b08dacc45 | 253 | stopTimer2(); |
Yo_Robot | 12:c02b08dacc45 | 254 | LPC_TIM2->TC = 0x00; //Resetear Timer |
Yo_Robot | 12:c02b08dacc45 | 255 | } |
Yo_Robot | 12:c02b08dacc45 | 256 | } |
Yo_Robot | 12:c02b08dacc45 | 257 | |
Yo_Robot | 22:d5431fff164b | 258 | |
Yo_Robot | 22:d5431fff164b | 259 | |
Yo_Robot | 22:d5431fff164b | 260 | void ISR_Alarm() |
Yo_Robot | 22:d5431fff164b | 261 | { |
Yo_Robot | 22:d5431fff164b | 262 | pin_son = 0 ; |
Yo_Robot | 22:d5431fff164b | 263 | stopTimer2(); |
Yo_Robot | 22:d5431fff164b | 264 | aout = 0.5 ; |
Yo_Robot | 22:d5431fff164b | 265 | |
Yo_Robot | 22:d5431fff164b | 266 | if(isPC) |
Yo_Robot | 26:dad0b2031173 | 267 | pc.printf( "AL\r\n" ); //ALARMA! solo es AL para que |
Yo_Robot | 22:d5431fff164b | 268 | //sea conciso con el modo ETH y funcione |
Yo_Robot | 22:d5431fff164b | 269 | //bien en LabVIEW. |
Yo_Robot | 22:d5431fff164b | 270 | else |
Yo_Robot | 26:dad0b2031173 | 271 | RS_232.printf( "AL\r\n" ); |
Yo_Robot | 22:d5431fff164b | 272 | } |
Yo_Robot | 22:d5431fff164b | 273 | |
Yo_Robot | 22:d5431fff164b | 274 | int getMRvalue( int fout ) |
Yo_Robot | 22:d5431fff164b | 275 | { |
Yo_Robot | 22:d5431fff164b | 276 | int toRegister; |
Yo_Robot | 22:d5431fff164b | 277 | |
Yo_Robot | 22:d5431fff164b | 278 | toRegister = (24000000 /(fout*2.0) ) -1; |
Yo_Robot | 22:d5431fff164b | 279 | return toRegister; |
Yo_Robot | 22:d5431fff164b | 280 | } |
Yo_Robot | 22:d5431fff164b | 281 | |
Yo_Robot | 22:d5431fff164b | 282 | |
Yo_Robot | 22:d5431fff164b | 283 | void setMR2( int newValue ) |
Yo_Robot | 22:d5431fff164b | 284 | { |
Yo_Robot | 22:d5431fff164b | 285 | LPC_TIM2->MR2 = newValue; // Las dos salidas son identicas |
Yo_Robot | 22:d5431fff164b | 286 | LPC_TIM2->MR3 = newValue; // Para testear el programa. |
Yo_Robot | 22:d5431fff164b | 287 | } |
Yo_Robot | 22:d5431fff164b | 288 | |
Yo_Robot | 22:d5431fff164b | 289 | |
Yo_Robot | 22:d5431fff164b | 290 | |
Yo_Robot | 22:d5431fff164b | 291 | void startTimer2() |
Yo_Robot | 22:d5431fff164b | 292 | { |
Yo_Robot | 22:d5431fff164b | 293 | // Arrancer el Timer 2 |
Yo_Robot | 22:d5431fff164b | 294 | LPC_TIM2->TCR = 1; |
Yo_Robot | 22:d5431fff164b | 295 | } |
Yo_Robot | 22:d5431fff164b | 296 | |
Yo_Robot | 22:d5431fff164b | 297 | void stopTimer2() |
Yo_Robot | 22:d5431fff164b | 298 | { |
Yo_Robot | 22:d5431fff164b | 299 | // Detener el Timer 2 |
Yo_Robot | 22:d5431fff164b | 300 | LPC_TIM2->TCR = 0x2; |
Yo_Robot | 22:d5431fff164b | 301 | } |
Yo_Robot | 22:d5431fff164b | 302 | |
Yo_Robot | 22:d5431fff164b | 303 | int getBaud() |
Yo_Robot | 22:d5431fff164b | 304 | { |
Yo_Robot | 22:d5431fff164b | 305 | int baudios = 115200; //Valor por defecto |
Yo_Robot | 22:d5431fff164b | 306 | |
Yo_Robot | 22:d5431fff164b | 307 | FILE *fp = fopen("/local/config.mbd", "r"); // Abre el archivo y lo guarda en fp |
Yo_Robot | 22:d5431fff164b | 308 | |
Yo_Robot | 22:d5431fff164b | 309 | if(!fp) // En caso de no encontrarse el archivo |
Yo_Robot | 22:d5431fff164b | 310 | { |
Yo_Robot | 22:d5431fff164b | 311 | printf("\nEl archivo /mbed/config.txt no puede ser abierto!\n"); |
Yo_Robot | 22:d5431fff164b | 312 | printf("Cree un archivo de texto: config.mbd dentro de la unidad Mbed\n"); |
Yo_Robot | 22:d5431fff164b | 313 | printf("que contenga las lineas:\n\n"); |
Yo_Robot | 22:d5431fff164b | 314 | |
Yo_Robot | 22:d5431fff164b | 315 | printf(" 1\n"); |
Yo_Robot | 22:d5431fff164b | 316 | printf(" 2\n"); |
Yo_Robot | 22:d5431fff164b | 317 | printf(" 3\n"); |
Yo_Robot | 22:d5431fff164b | 318 | printf(" 4\n"); |
Yo_Robot | 22:d5431fff164b | 319 | printf(" baudios: 115200\n"); |
Yo_Robot | 22:d5431fff164b | 320 | |
Yo_Robot | 22:d5431fff164b | 321 | printf("Cambie el valor de 115200 por la velocidad a la que desea transmitir:\n"); |
Yo_Robot | 22:d5431fff164b | 322 | printf("luego reinicie el microcontrolador\n"); |
Yo_Robot | 22:d5431fff164b | 323 | exit(1); |
Yo_Robot | 22:d5431fff164b | 324 | |
Yo_Robot | 22:d5431fff164b | 325 | } |
Yo_Robot | 22:d5431fff164b | 326 | else |
Yo_Robot | 22:d5431fff164b | 327 | { |
Yo_Robot | 22:d5431fff164b | 328 | // Cadenas de caracteres desde el Archivo config.mbd |
Yo_Robot | 22:d5431fff164b | 329 | char notstr [04]; // linea vacia |
Yo_Robot | 22:d5431fff164b | 330 | char baud [40]; // valor en baudios |
Yo_Robot | 22:d5431fff164b | 331 | |
Yo_Robot | 22:d5431fff164b | 332 | // Leer linea a linea el archivo |
Yo_Robot | 22:d5431fff164b | 333 | // cuatro primeras lineas no sirven |
Yo_Robot | 22:d5431fff164b | 334 | fgets( notstr, 4, fp ); |
Yo_Robot | 22:d5431fff164b | 335 | fgets( notstr, 4, fp ); |
Yo_Robot | 22:d5431fff164b | 336 | fgets( notstr, 4, fp ); |
Yo_Robot | 22:d5431fff164b | 337 | fgets( notstr, 4, fp ); |
Yo_Robot | 22:d5431fff164b | 338 | fgets( baud, 40, fp ); |
Yo_Robot | 22:d5431fff164b | 339 | fclose(fp); |
Yo_Robot | 23:2126e38bb48c | 340 | |
Yo_Robot | 22:d5431fff164b | 341 | // Extraer los valores numericos |
Yo_Robot | 22:d5431fff164b | 342 | sscanf( baud,"%*s %d",&baudios ); |
Yo_Robot | 22:d5431fff164b | 343 | |
Yo_Robot | 22:d5431fff164b | 344 | |
Yo_Robot | 22:d5431fff164b | 345 | } |
Yo_Robot | 22:d5431fff164b | 346 | |
Yo_Robot | 22:d5431fff164b | 347 | return baudios; |
Yo_Robot | 22:d5431fff164b | 348 | } |
Yo_Robot | 22:d5431fff164b | 349 | |
Yo_Robot | 22:d5431fff164b | 350 | // **** Funciones Liberia Ethernet ***** // |
Yo_Robot | 12:c02b08dacc45 | 351 | void setPTO_eth( char * input, char * output ) |
Yo_Robot | 12:c02b08dacc45 | 352 | { |
Yo_Robot | 12:c02b08dacc45 | 353 | int freq = atoi( input ); |
Yo_Robot | 12:c02b08dacc45 | 354 | |
Yo_Robot | 12:c02b08dacc45 | 355 | if( freq != 0 ){ |
Yo_Robot | 12:c02b08dacc45 | 356 | LPC_TIM2->TC = 0x00; // Resetear Timer |
Yo_Robot | 12:c02b08dacc45 | 357 | setMR2( getMRvalue( freq ) ); // Cambiar frefuencia |
Yo_Robot | 12:c02b08dacc45 | 358 | startTimer2(); // Iniciar Timer |
Yo_Robot | 14:039d070732d5 | 359 | if( pin_alm == 0 ) |
Yo_Robot | 26:dad0b2031173 | 360 | sprintf( output,"OK\r\n" ); |
Yo_Robot | 14:039d070732d5 | 361 | else |
Yo_Robot | 14:039d070732d5 | 362 | sprintf( output,"AL" ); |
Yo_Robot | 12:c02b08dacc45 | 363 | }else{ |
Yo_Robot | 12:c02b08dacc45 | 364 | stopTimer2(); |
Yo_Robot | 12:c02b08dacc45 | 365 | LPC_TIM2->TC = 0x00; // Resetear Timer |
Yo_Robot | 14:039d070732d5 | 366 | if( pin_alm == 0 ) |
Yo_Robot | 26:dad0b2031173 | 367 | sprintf( output,"OK\r\n" ); |
Yo_Robot | 14:039d070732d5 | 368 | else |
Yo_Robot | 14:039d070732d5 | 369 | sprintf( output,"AL" ); |
Yo_Robot | 12:c02b08dacc45 | 370 | } |
Yo_Robot | 12:c02b08dacc45 | 371 | } |
Yo_Robot | 12:c02b08dacc45 | 372 | |
Yo_Robot | 15:a1ffa32ce9d1 | 373 | void setANG_eth( char * input, char * output ) |
Yo_Robot | 15:a1ffa32ce9d1 | 374 | { |
Yo_Robot | 15:a1ffa32ce9d1 | 375 | long int pulsos = atol( input ); //Numero de pulsos a generar |
Yo_Robot | 23:2126e38bb48c | 376 | t_alto = pulsos / fq_posicion; //Tiempo que debe ser generado el tren de pulsos. |
Yo_Robot | 15:a1ffa32ce9d1 | 377 | |
Yo_Robot | 15:a1ffa32ce9d1 | 378 | stopTimer2(); //Deten el tren de pulsos |
Yo_Robot | 15:a1ffa32ce9d1 | 379 | setPTO( fq_posicion ); //Nueva frecuencia de salida |
Yo_Robot | 15:a1ffa32ce9d1 | 380 | startTimer2(); //Inicia el tren de pulsos |
Yo_Robot | 15:a1ffa32ce9d1 | 381 | wait( t_alto ); //Espera hasta llegar a la posicion |
Yo_Robot | 18:cf1e07d82630 | 382 | stopTimer2(); //Posicion alcanzada ALTO. |
Yo_Robot | 15:a1ffa32ce9d1 | 383 | |
Yo_Robot | 15:a1ffa32ce9d1 | 384 | if( pin_alm == 0 ) |
Yo_Robot | 26:dad0b2031173 | 385 | sprintf( output,"OK\r\n" ); |
Yo_Robot | 15:a1ffa32ce9d1 | 386 | else |
Yo_Robot | 15:a1ffa32ce9d1 | 387 | sprintf( output,"AL" ); |
Yo_Robot | 15:a1ffa32ce9d1 | 388 | |
Yo_Robot | 15:a1ffa32ce9d1 | 389 | } |
Yo_Robot | 21:353b0fe8fc54 | 390 | |
Yo_Robot | 21:353b0fe8fc54 | 391 | |
Yo_Robot | 15:a1ffa32ce9d1 | 392 | void setSPD_eth( char * input, char * output ) |
Yo_Robot | 15:a1ffa32ce9d1 | 393 | { |
Yo_Robot | 15:a1ffa32ce9d1 | 394 | fq_posicion = atoi( input ); |
Yo_Robot | 15:a1ffa32ce9d1 | 395 | // Esta funcion cambia la velocidad con la que se |
Yo_Robot | 15:a1ffa32ce9d1 | 396 | // posicionara el eje del motor en un angulo determinado |
Yo_Robot | 15:a1ffa32ce9d1 | 397 | if( pin_alm == 0 ) |
Yo_Robot | 26:dad0b2031173 | 398 | sprintf( output,"OK\r\n" ); |
Yo_Robot | 15:a1ffa32ce9d1 | 399 | else |
Yo_Robot | 15:a1ffa32ce9d1 | 400 | sprintf( output,"AL" ); |
Yo_Robot | 15:a1ffa32ce9d1 | 401 | |
Yo_Robot | 15:a1ffa32ce9d1 | 402 | } |
Yo_Robot | 21:353b0fe8fc54 | 403 | |
Yo_Robot | 12:c02b08dacc45 | 404 | void setAout_eth( char * input, char * output ) |
Yo_Robot | 12:c02b08dacc45 | 405 | { |
Yo_Robot | 12:c02b08dacc45 | 406 | int vout = atoi( input ); |
Yo_Robot | 14:039d070732d5 | 407 | aout = (float)( vout + 10000 ) / 20000; |
Yo_Robot | 14:039d070732d5 | 408 | if( pin_alm == 0 ) |
Yo_Robot | 26:dad0b2031173 | 409 | sprintf( output,"OK\r\n" ); |
Yo_Robot | 14:039d070732d5 | 410 | else |
Yo_Robot | 14:039d070732d5 | 411 | sprintf( output,"AL" ); |
Yo_Robot | 12:c02b08dacc45 | 412 | } |
Yo_Robot | 12:c02b08dacc45 | 413 | |
Yo_Robot | 12:c02b08dacc45 | 414 | |
Yo_Robot | 12:c02b08dacc45 | 415 | |
Yo_Robot | 12:c02b08dacc45 | 416 | void setDir_eth ( char * input, char * output ) |
Yo_Robot | 12:c02b08dacc45 | 417 | { |
Yo_Robot | 12:c02b08dacc45 | 418 | int value = atoi( input ); |
Yo_Robot | 12:c02b08dacc45 | 419 | |
Yo_Robot | 12:c02b08dacc45 | 420 | pin_dir = value; |
Yo_Robot | 12:c02b08dacc45 | 421 | |
Yo_Robot | 14:039d070732d5 | 422 | if( pin_alm == 0 ) |
Yo_Robot | 26:dad0b2031173 | 423 | sprintf( output,"OK\r\n" ); |
Yo_Robot | 12:c02b08dacc45 | 424 | else |
Yo_Robot | 14:039d070732d5 | 425 | sprintf( output,"AL" ); |
Yo_Robot | 12:c02b08dacc45 | 426 | } |
Yo_Robot | 12:c02b08dacc45 | 427 | |
Yo_Robot | 12:c02b08dacc45 | 428 | |
Yo_Robot | 12:c02b08dacc45 | 429 | |
Yo_Robot | 12:c02b08dacc45 | 430 | void setSON_eth ( char * input, char * output ) |
Yo_Robot | 12:c02b08dacc45 | 431 | { |
Yo_Robot | 12:c02b08dacc45 | 432 | int value = atoi( input ); |
Yo_Robot | 12:c02b08dacc45 | 433 | |
Yo_Robot | 12:c02b08dacc45 | 434 | pin_son = value; |
Yo_Robot | 12:c02b08dacc45 | 435 | |
Yo_Robot | 14:039d070732d5 | 436 | if( pin_alm == 0 ) |
Yo_Robot | 26:dad0b2031173 | 437 | sprintf( output,"OK\r\n" ); |
Yo_Robot | 12:c02b08dacc45 | 438 | else |
Yo_Robot | 14:039d070732d5 | 439 | sprintf( output,"AL" ); |
Yo_Robot | 12:c02b08dacc45 | 440 | |
Yo_Robot | 12:c02b08dacc45 | 441 | } |
Yo_Robot | 12:c02b08dacc45 | 442 | |
Yo_Robot | 12:c02b08dacc45 | 443 | |
Yo_Robot | 22:d5431fff164b | 444 | void getENC_eth( char * input, char * output ) |
Yo_Robot | 20:4b154134ab20 | 445 | { |
Yo_Robot | 22:d5431fff164b | 446 | if( pin_alm == 0 ) |
Yo_Robot | 22:d5431fff164b | 447 | sprintf( output,"%d", read_encoder() ); |
Yo_Robot | 22:d5431fff164b | 448 | else |
Yo_Robot | 22:d5431fff164b | 449 | sprintf( output,"AL" ); |
Yo_Robot | 22:d5431fff164b | 450 | } |
Yo_Robot | 21:353b0fe8fc54 | 451 | |
Yo_Robot | 21:353b0fe8fc54 | 452 | |
Yo_Robot | 22:d5431fff164b | 453 | void setENC_eth( char * input, char * output ) |
Yo_Robot | 22:d5431fff164b | 454 | { |
Yo_Robot | 22:d5431fff164b | 455 | clear_encoder(); |
Yo_Robot | 22:d5431fff164b | 456 | |
Yo_Robot | 22:d5431fff164b | 457 | if( pin_alm == 0 ) |
Yo_Robot | 26:dad0b2031173 | 458 | sprintf( output,"OK\r\n" ); |
Yo_Robot | 22:d5431fff164b | 459 | else |
Yo_Robot | 22:d5431fff164b | 460 | sprintf( output,"AL" ); |
Yo_Robot | 22:d5431fff164b | 461 | |
Yo_Robot | 20:4b154134ab20 | 462 | } |
Yo_Robot | 12:c02b08dacc45 | 463 | |
Yo_Robot | 23:2126e38bb48c | 464 | void getRPM_eth( char * input, char * output ) |
Yo_Robot | 23:2126e38bb48c | 465 | { |
Yo_Robot | 23:2126e38bb48c | 466 | float rpm; |
Yo_Robot | 23:2126e38bb48c | 467 | |
Yo_Robot | 25:1910a55ff0a3 | 468 | rpm = encoder.CalculateRPM( encoder.GetVelocityCap() , // ultima velocidad leida desde el encoder |
Yo_Robot | 25:1910a55ff0a3 | 469 | 360 // numero de revoluciones por vuelta del encoder |
Yo_Robot | 25:1910a55ff0a3 | 470 | ); |
Yo_Robot | 25:1910a55ff0a3 | 471 | |
Yo_Robot | 23:2126e38bb48c | 472 | |
Yo_Robot | 23:2126e38bb48c | 473 | if( pin_alm == 0 ) |
Yo_Robot | 26:dad0b2031173 | 474 | sprintf( output,"OK\r\n" ); |
Yo_Robot | 23:2126e38bb48c | 475 | else |
Yo_Robot | 23:2126e38bb48c | 476 | sprintf( output,"%f", rpm ); |
Yo_Robot | 23:2126e38bb48c | 477 | |
Yo_Robot | 23:2126e38bb48c | 478 | |
Yo_Robot | 23:2126e38bb48c | 479 | } |
Yo_Robot | 23:2126e38bb48c | 480 | |
Yo_Robot | 21:353b0fe8fc54 | 481 | |
Yo_Robot | 22:d5431fff164b | 482 | |
Yo_Robot | 22:d5431fff164b | 483 | |
Yo_Robot | 22:d5431fff164b | 484 | |
Yo_Robot | 4:552beeda4722 | 485 | /* LEGACY FUNCTIONS |
Yo_Robot | 4:552beeda4722 | 486 | * |
Yo_Robot | 20:4b154134ab20 | 487 | * El siguiente codigo no es utilizado por el |
Yo_Robot | 20:4b154134ab20 | 488 | * programa. Sin embargo pueden servir como |
Yo_Robot | 20:4b154134ab20 | 489 | * futuras referencias. |
Yo_Robot | 4:552beeda4722 | 490 | */ |
Yo_Robot | 4:552beeda4722 | 491 | void setMR3( int newValue ) |
Yo_Robot | 4:552beeda4722 | 492 | { |
Yo_Robot | 4:552beeda4722 | 493 | LPC_TIM2->MR3 = newValue; |
Yo_Robot | 4:552beeda4722 | 494 | } |
Yo_Robot | 4:552beeda4722 | 495 | |
Yo_Robot | 4:552beeda4722 | 496 | |
Yo_Robot | 4:552beeda4722 | 497 | void setPrescaler( int newValue) |
Yo_Robot | 4:552beeda4722 | 498 | { |
Yo_Robot | 4:552beeda4722 | 499 | LPC_TIM2->PR = newValue; |
Yo_Robot | 4:552beeda4722 | 500 | } |
Yo_Robot | 20:4b154134ab20 | 501 | |
Yo_Robot | 20:4b154134ab20 | 502 | |
Yo_Robot | 20:4b154134ab20 | 503 | EthernetNetIf configurarEthernet() |
Yo_Robot | 20:4b154134ab20 | 504 | { |
Yo_Robot | 20:4b154134ab20 | 505 | //____________ *** ARCHIVO DE CONFIGURACION ***_______________________ // |
Yo_Robot | 20:4b154134ab20 | 506 | |
Yo_Robot | 20:4b154134ab20 | 507 | printf("\n *** CONFIGURACION ETHERNET DE MBED ***\n"); |
Yo_Robot | 20:4b154134ab20 | 508 | printf("Leyendo archivo de configuracion...\n\n"); |
Yo_Robot | 20:4b154134ab20 | 509 | |
Yo_Robot | 20:4b154134ab20 | 510 | FILE *fp = fopen("/local/config.txt", "r"); // Abre el archivo y lo guarda en fp |
Yo_Robot | 20:4b154134ab20 | 511 | |
Yo_Robot | 20:4b154134ab20 | 512 | if(!fp) // En caso de no encontrarse el archivo |
Yo_Robot | 20:4b154134ab20 | 513 | { |
Yo_Robot | 20:4b154134ab20 | 514 | printf("\nEl archivo /mbed/config.txt no puede ser abierto!\n"); |
Yo_Robot | 20:4b154134ab20 | 515 | exit(1); |
Yo_Robot | 20:4b154134ab20 | 516 | |
Yo_Robot | 20:4b154134ab20 | 517 | } |
Yo_Robot | 20:4b154134ab20 | 518 | else |
Yo_Robot | 20:4b154134ab20 | 519 | { |
Yo_Robot | 20:4b154134ab20 | 520 | // Cadenas de caracteres desde el Archivo config.txt |
Yo_Robot | 20:4b154134ab20 | 521 | char isDHCP [15]; //Modo Automatico o Manual |
Yo_Robot | 20:4b154134ab20 | 522 | char empty [2]; // Linea vacia |
Yo_Robot | 20:4b154134ab20 | 523 | char ip [40]; // Direccion IP |
Yo_Robot | 20:4b154134ab20 | 524 | char mask [40]; // Mascara de Subred |
Yo_Robot | 20:4b154134ab20 | 525 | char gate [40]; // Puerta de enlace |
Yo_Robot | 20:4b154134ab20 | 526 | char dns [40]; // Direccion DNS |
Yo_Robot | 20:4b154134ab20 | 527 | |
Yo_Robot | 20:4b154134ab20 | 528 | // Valores 'int' para agregar a la configuracion manual |
Yo_Robot | 20:4b154134ab20 | 529 | int DHCP; |
Yo_Robot | 20:4b154134ab20 | 530 | int n_ip[4]; |
Yo_Robot | 20:4b154134ab20 | 531 | int n_mask[4]; |
Yo_Robot | 20:4b154134ab20 | 532 | int n_gate[4]; |
Yo_Robot | 20:4b154134ab20 | 533 | int n_dns[4]; |
Yo_Robot | 20:4b154134ab20 | 534 | |
Yo_Robot | 20:4b154134ab20 | 535 | |
Yo_Robot | 20:4b154134ab20 | 536 | // Leer linea a linea el archivo |
Yo_Robot | 20:4b154134ab20 | 537 | fgets( isDHCP, 15, fp ); |
Yo_Robot | 20:4b154134ab20 | 538 | fgets( empty, 2, fp ); |
Yo_Robot | 20:4b154134ab20 | 539 | fgets( ip, 40, fp ); |
Yo_Robot | 20:4b154134ab20 | 540 | fgets( mask, 40, fp ); |
Yo_Robot | 20:4b154134ab20 | 541 | fgets( gate, 40, fp ); |
Yo_Robot | 20:4b154134ab20 | 542 | fgets( dns, 40, fp ); |
Yo_Robot | 20:4b154134ab20 | 543 | |
Yo_Robot | 20:4b154134ab20 | 544 | printf("Cerrando archivo...\n"); |
Yo_Robot | 20:4b154134ab20 | 545 | fclose(fp); |
Yo_Robot | 20:4b154134ab20 | 546 | |
Yo_Robot | 20:4b154134ab20 | 547 | // Extraer los valores numericos |
Yo_Robot | 20:4b154134ab20 | 548 | sscanf( isDHCP,"%*s %d",&DHCP ); |
Yo_Robot | 20:4b154134ab20 | 549 | |
Yo_Robot | 20:4b154134ab20 | 550 | sscanf( ip,"%*s %d.%d.%d.%d",&n_ip[0],&n_ip[1],&n_ip[2],&n_ip[3] ); |
Yo_Robot | 20:4b154134ab20 | 551 | sscanf( mask,"%*s %d.%d.%d.%d",&n_mask[0],&n_mask[1],&n_mask[2],&n_mask[3] ); |
Yo_Robot | 20:4b154134ab20 | 552 | sscanf( gate,"%*s %d.%d.%d.%d",&n_gate[0],&n_gate[1],&n_gate[2],&n_gate[3] ); |
Yo_Robot | 20:4b154134ab20 | 553 | sscanf( dns,"%*s %d.%d.%d.%d",&n_dns[0],&n_dns[1],&n_dns[2],&n_dns[3] ); |
Yo_Robot | 20:4b154134ab20 | 554 | |
Yo_Robot | 20:4b154134ab20 | 555 | |
Yo_Robot | 20:4b154134ab20 | 556 | if(DHCP) //En caso de modo DHCP |
Yo_Robot | 20:4b154134ab20 | 557 | { |
Yo_Robot | 20:4b154134ab20 | 558 | printf("\n Configurar red de manera automatica\n"); |
Yo_Robot | 20:4b154134ab20 | 559 | EthernetNetIf eth; //Crea la interfaz |
Yo_Robot | 20:4b154134ab20 | 560 | EthernetErr ethErr = eth.setup(); |
Yo_Robot | 20:4b154134ab20 | 561 | if( ethErr ) |
Yo_Robot | 20:4b154134ab20 | 562 | { |
Yo_Robot | 20:4b154134ab20 | 563 | printf( "Error %d en la configuracion\n", ethErr ); |
Yo_Robot | 20:4b154134ab20 | 564 | exit(1); |
Yo_Robot | 20:4b154134ab20 | 565 | } |
Yo_Robot | 20:4b154134ab20 | 566 | |
Yo_Robot | 20:4b154134ab20 | 567 | printf("Configuracion Correcta\n\n"); |
Yo_Robot | 20:4b154134ab20 | 568 | return eth; |
Yo_Robot | 20:4b154134ab20 | 569 | } |
Yo_Robot | 20:4b154134ab20 | 570 | else |
Yo_Robot | 20:4b154134ab20 | 571 | { |
Yo_Robot | 20:4b154134ab20 | 572 | sscanf( ip,"%*s %d.%d.%d.%d",&n_ip[0], &n_ip[1], &n_ip[2], &n_ip[3] ); |
Yo_Robot | 20:4b154134ab20 | 573 | sscanf( mask,"%*s %d.%d.%d.%d",&n_mask[0],&n_mask[1],&n_mask[2],&n_mask[3] ); |
Yo_Robot | 20:4b154134ab20 | 574 | sscanf( gate,"%*s %d.%d.%d.%d",&n_gate[0],&n_gate[1],&n_gate[2],&n_gate[3] ); |
Yo_Robot | 20:4b154134ab20 | 575 | sscanf( dns,"%*s %d.%d.%d.%d",&n_dns[0], &n_dns[1], &n_dns[2], &n_dns[3] ); |
Yo_Robot | 20:4b154134ab20 | 576 | printf(" %s %s %s %s %s\n " , isDHCP, ip, mask, gate, dns ); |
Yo_Robot | 20:4b154134ab20 | 577 | |
Yo_Robot | 20:4b154134ab20 | 578 | printf("\n Configurar red de manera manual\n"); |
Yo_Robot | 20:4b154134ab20 | 579 | EthernetNetIf eth( |
Yo_Robot | 20:4b154134ab20 | 580 | IpAddr( n_ip[0], n_ip[1], n_ip[2], n_ip[3]), //IP Address |
Yo_Robot | 20:4b154134ab20 | 581 | IpAddr( n_mask[0],n_mask[1],n_mask[2],n_mask[3]), //Network Mask |
Yo_Robot | 20:4b154134ab20 | 582 | IpAddr( n_gate[0],n_gate[1],n_gate[2],n_gate[3]), //Gateway |
Yo_Robot | 20:4b154134ab20 | 583 | IpAddr( n_dns[0], n_dns[1], n_dns[2], n_dns[3] ) //DNS |
Yo_Robot | 20:4b154134ab20 | 584 | ); |
Yo_Robot | 20:4b154134ab20 | 585 | |
Yo_Robot | 20:4b154134ab20 | 586 | EthernetErr ethErr = eth.setup(); |
Yo_Robot | 20:4b154134ab20 | 587 | if( ethErr ) |
Yo_Robot | 20:4b154134ab20 | 588 | { |
Yo_Robot | 20:4b154134ab20 | 589 | printf( "Error %d en la configuracion\n", ethErr ); |
Yo_Robot | 20:4b154134ab20 | 590 | exit(1); |
Yo_Robot | 20:4b154134ab20 | 591 | } |
Yo_Robot | 20:4b154134ab20 | 592 | |
Yo_Robot | 20:4b154134ab20 | 593 | printf("Configuracion Correcta\n\n"); |
Yo_Robot | 20:4b154134ab20 | 594 | return eth; |
Yo_Robot | 20:4b154134ab20 | 595 | } |
Yo_Robot | 20:4b154134ab20 | 596 | |
Yo_Robot | 20:4b154134ab20 | 597 | } |
Yo_Robot | 20:4b154134ab20 | 598 | |
Yo_Robot | 20:4b154134ab20 | 599 | EthernetNetIf eth; |
Yo_Robot | 20:4b154134ab20 | 600 | return eth; |
Yo_Robot | 20:4b154134ab20 | 601 | } |