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