<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>SISTEMAS O.R.P</title>
	
	<link>http://www.sistemasorp.es</link>
	<description>Blog sobre desarrollos y otros temas</description>
	<lastBuildDate>Sat, 10 Mar 2012 15:56:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/sistemasorp" /><feedburner:info uri="sistemasorp" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Explorer.exe en Windows</title>
		<link>http://feedproxy.google.com/~r/sistemasorp/~3/TN7wCPV6nuk/</link>
		<comments>http://www.sistemasorp.es/2012/02/16/explorer-exe-en-windows/#comments</comments>
		<pubDate>Thu, 16 Feb 2012 15:41:28 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Informática]]></category>

		<guid isPermaLink="false">http://www.sistemasorp.es/?p=586</guid>
		<description><![CDATA[Hace poco tuvimos en mi trabajo la necesidad de sustituir el proceso explorer.exe de un portátil para que sólo mostrase una ventana con 3 opciones y que el usuario no pudiese hacer nada más. El explorer.exe es un proceso que cuando se ejecuta al principio muestra el escritorio de Windows y en las sucesivas ocasiones [...]]]></description>
			<content:encoded><![CDATA[<p>Hace poco tuvimos en mi trabajo la necesidad de sustituir el proceso <em>explorer.exe</em> de un portátil para que sólo mostrase una ventana con 3 opciones y que el usuario no pudiese hacer nada más.</p>
<p>El <em>explorer.exe</em> es un proceso que cuando se ejecuta al principio muestra el escritorio de Windows y en las sucesivas ocasiones muestra el explorador de ficheros.</p>
<p>Se puede sustituir fácilmente accediendo a la entrada del registro <em>HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon</em> y modificando el valor <em>Shell</em> por otro ejecutable.</p>
<p>El ejecutable debe estar normalmente en la ruta <em>C:\Windows</em> y puede ser cualquier programa con interfaz gráfica. El nuestro creaba una ventana que ocupaba todo el monitor, con un logotipo de fondo, sin marco y tenía varios botones para cargar otras aplicaciones, reiniciar y apagar.</p>
<p>Para labores de mantenimiento teníamos un botón que debía poner el escritorio de Windows cuando se pulsaba, y lo lógico era pensar que si desde nuestra aplicación ejecutábamos el fichero <em>explorer.exe</em> se mostraría, pero eso no ocurría y solamente nos aparecía el explorador de ficheros. Al final comprobamos que este comportamiento se debía a que el proceso <em>explorer.exe</em> sólo muestra el escritorio de Windows si se cumplen dos condiciones:</p>
<ol>
<li>Que no exista otro proceso <em>explorer.exe</em> ya ejecutándose.</li>
<li>Que en el registro de Windows que he puesto antes esté apuntando a si mismo.</li>
</ol>
<p>Por ello lo que tendremos que hacer para mostrar el escritorio es cambiar la variable <em>Shell</em> del registro expuesto anteriomente a <em>explorer.exe</em>, ejecutar el fichero <em>C:\Windows\explorer.exe</em> y pasados unos segundos volver a modificar la variable <em>Shell</em> con el nombre de nuestro ejecutable para asegurarnos que en el siguiente arranque se vuelve a cargar nuestro programa.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/bxPXCo-OHC_lMsYH8pxhSRhc_9U/0/da"><img src="http://feedads.g.doubleclick.net/~a/bxPXCo-OHC_lMsYH8pxhSRhc_9U/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/bxPXCo-OHC_lMsYH8pxhSRhc_9U/1/da"><img src="http://feedads.g.doubleclick.net/~a/bxPXCo-OHC_lMsYH8pxhSRhc_9U/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/sistemasorp/~4/TN7wCPV6nuk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.sistemasorp.es/2012/02/16/explorer-exe-en-windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.sistemasorp.es/2012/02/16/explorer-exe-en-windows/</feedburner:origLink></item>
		<item>
		<title>Probando el marco digital Parrot DF3120 (parte 3 y final)</title>
		<link>http://feedproxy.google.com/~r/sistemasorp/~3/0_ck6WohJa0/</link>
		<comments>http://www.sistemasorp.es/2012/02/12/probando-el-marco-digital-parrot-df3120-parte-3-y-final/#comments</comments>
		<pubDate>Sun, 12 Feb 2012 08:29:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Electrónica]]></category>
		<category><![CDATA[Informática]]></category>
		<category><![CDATA[Proyectos]]></category>

		<guid isPermaLink="false">http://www.sistemasorp.es/?p=546</guid>
		<description><![CDATA[Con este artículo termino de explicar cómo explotar todas las características de este marco digital. Este artículo lo dividiré en 3 partes debido a su extensión. La primera parte consiste en explicar cómo usar la librería SDL (Simple Directmedia Layer) para dibujar en la pantalla. Lo bueno de esta librería es que es muy sencilla [...]]]></description>
			<content:encoded><![CDATA[<p>Con este artículo termino de explicar cómo explotar todas las características de este marco digital. Este artículo lo dividiré en 3 partes debido a su extensión.</p>
<p>La primera parte consiste en explicar cómo usar la librería <a href="http://www.libsdl.org/" target="_blank">SDL</a> (Simple Directmedia Layer) para dibujar en la pantalla. Lo bueno de esta librería es que es muy sencilla de usar y te facilita bastante el dibujar gráficos en la pantalla mediante programación.</p>
<p>La segunda parte trata sobre usar las entradas de información del marco. Se va a leer el estado de los 3 botones, del inclinómetro y la cantidad de luz que hay en el ambiente .</p>
<p>La tercera parte la he reservado para las comunicaciones. Dado que el marco tiene bluetooth y una tarjeta de red configurada voy a explicar cómo intercambiar información entre el marco y otros dispositivos.</p>
<h1>1- Librería SDL</h1>
<p>Antes de empezar a explicar, lo mejor será que ponga un vídeo, después el código fuente, a continuación cómo compilarlo, ejecutarlo y finalmente explicar su funcionamiento.</p>
<h3>[VÍDEO]</h3>
<p><iframe width="425" height="349" src="http://www.youtube.com/embed/LPs3OpsmVmQ?hl=es&#038;fs=1" frameborder="0" allowfullscreen></iframe></p>
<h3>[CÓDIGO]</h3>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &lt;stdio.h&gt; </span>
<span style="color: #339933;">#include &lt;stdlib.h&gt; </span>
<span style="color: #339933;">#include &lt;math.h&gt;</span>
<span style="color: #339933;">#include &lt;signal.h&gt;</span>
<span style="color: #339933;">#include &lt;SDL/SDL.h&gt;</span>
<span style="color: #339933;">#include &lt;SDL/SDL_image.h&gt;</span>
&nbsp;
<span style="color: #993333;">volatile</span> <span style="color: #993333;">char</span> salir <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">void</span> salida<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> sig<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	salir <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span> 
<span style="color: #009900;">&#123;</span> 
	SDL_Surface <span style="color: #339933;">*</span>izquierda<span style="color: #339933;">;</span>
	SDL_Surface <span style="color: #339933;">*</span>derecha<span style="color: #339933;">;</span>
	SDL_Surface <span style="color: #339933;">*</span>ok<span style="color: #339933;">;</span>
	SDL_Surface <span style="color: #339933;">*</span>diamante<span style="color: #339933;">;</span>
	SDL_Surface <span style="color: #339933;">*</span>sol<span style="color: #339933;">;</span>
	SDL_Surface <span style="color: #339933;">*</span>pantalla<span style="color: #339933;">;</span> 
 	SDL_Rect destino<span style="color: #339933;">;</span>
	<span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> alpha <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
	<span style="color: #993333;">float</span> radianes<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>SDL_Init<span style="color: #009900;">&#40;</span>SDL_INIT_VIDEO<span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> 
	<span style="color: #009900;">&#123;</span> 
		<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;No se pudo iniciar SDL: %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>SDL_GetError<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		exit<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	<span style="color: #009900;">&#125;</span> 
&nbsp;
	atexit<span style="color: #009900;">&#40;</span>SDL_Quit<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	pantalla <span style="color: #339933;">=</span> SDL_SetVideoMode<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">320</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">240</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">16</span><span style="color: #339933;">,</span> 
		SDL_HWSURFACE <span style="color: #339933;">|</span> SDL_DOUBLEBUF<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>pantalla <span style="color: #339933;">==</span> NULL<span style="color: #009900;">&#41;</span> 
	<span style="color: #009900;">&#123;</span> 
	  	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;No se puede inicializar el modo gráfico: %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>
			SDL_GetError<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		exit<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	<span style="color: #009900;">&#125;</span> 
&nbsp;
	SDL_ShowCursor<span style="color: #009900;">&#40;</span>SDL_DISABLE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
	izquierda <span style="color: #339933;">=</span> IMG_Load<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;izquierda.png&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>izquierda <span style="color: #339933;">==</span> NULL<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span> 
		<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;No pude cargar gráfico: %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> SDL_GetError<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		exit<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	<span style="color: #009900;">&#125;</span> 
&nbsp;
	derecha <span style="color: #339933;">=</span> IMG_Load<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;derecha.png&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>derecha <span style="color: #339933;">==</span> NULL<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span> 
        	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;No pude cargar gráfico: %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> SDL_GetError<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		exit<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	<span style="color: #009900;">&#125;</span>
&nbsp;
	ok <span style="color: #339933;">=</span> IMG_Load<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;ok.png&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>ok <span style="color: #339933;">==</span> NULL<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span> 
        	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;No pude cargar gráfico: %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> SDL_GetError<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
        	exit<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	<span style="color: #009900;">&#125;</span>
&nbsp;
	diamante <span style="color: #339933;">=</span> IMG_Load<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;diamante.png&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>diamante <span style="color: #339933;">==</span> NULL<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span> 
        	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;No pude cargar gráfico: %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> SDL_GetError<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
        	exit<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
    	<span style="color: #009900;">&#125;</span>
&nbsp;
	sol <span style="color: #339933;">=</span> IMG_Load<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;sol.gif&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>sol <span style="color: #339933;">==</span> NULL<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span> 
		<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;No pude cargar gráfico: %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> SDL_GetError<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		exit<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
    	<span style="color: #009900;">&#125;</span> 
&nbsp;
	signal<span style="color: #009900;">&#40;</span>SIGINT<span style="color: #339933;">,</span> salida<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	destino.<span style="color: #202020;">x</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
	destino.<span style="color: #202020;">y</span> <span style="color: #339933;">=</span> pantalla<span style="color: #339933;">-&gt;</span>h <span style="color: #339933;">/</span> <span style="color: #0000dd;">2</span> <span style="color: #339933;">-</span> izquierda<span style="color: #339933;">-&gt;</span>h <span style="color: #339933;">/</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">;</span> 
	destino.<span style="color: #202020;">w</span> <span style="color: #339933;">=</span> izquierda<span style="color: #339933;">-&gt;</span>w<span style="color: #339933;">;</span> 
	destino.<span style="color: #202020;">h</span> <span style="color: #339933;">=</span> izquierda<span style="color: #339933;">-&gt;</span>h<span style="color: #339933;">;</span> 
	SDL_BlitSurface<span style="color: #009900;">&#40;</span>izquierda<span style="color: #339933;">,</span> NULL<span style="color: #339933;">,</span> pantalla<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>destino<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
	destino.<span style="color: #202020;">x</span> <span style="color: #339933;">=</span> pantalla<span style="color: #339933;">-&gt;</span>w <span style="color: #339933;">/</span> <span style="color: #0000dd;">2</span> <span style="color: #339933;">-</span> ok<span style="color: #339933;">-&gt;</span>w <span style="color: #339933;">/</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">;</span>
	SDL_BlitSurface<span style="color: #009900;">&#40;</span>ok<span style="color: #339933;">,</span> NULL<span style="color: #339933;">,</span> pantalla<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>destino<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
	destino.<span style="color: #202020;">x</span> <span style="color: #339933;">=</span> pantalla<span style="color: #339933;">-&gt;</span>w <span style="color: #339933;">-</span> derecha<span style="color: #339933;">-&gt;</span>w<span style="color: #339933;">;</span>
	SDL_BlitSurface<span style="color: #009900;">&#40;</span>derecha<span style="color: #339933;">,</span> NULL<span style="color: #339933;">,</span> pantalla<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>destino<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
	radianes <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>salir<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		destino.<span style="color: #202020;">x</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
		destino.<span style="color: #202020;">y</span> <span style="color: #339933;">=</span> pantalla<span style="color: #339933;">-&gt;</span>h <span style="color: #339933;">-</span> sol<span style="color: #339933;">-&gt;</span>h<span style="color: #339933;">;</span>
		SDL_SetAlpha<span style="color: #009900;">&#40;</span>sol<span style="color: #339933;">,</span> SDL_SRCALPHA <span style="color: #339933;">|</span> SDL_RLEACCEL<span style="color: #339933;">,</span> alpha<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		SDL_BlitSurface<span style="color: #009900;">&#40;</span>sol<span style="color: #339933;">,</span> NULL<span style="color: #339933;">,</span> pantalla<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>destino<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
		destino.<span style="color: #202020;">x</span> <span style="color: #339933;">=</span> pantalla<span style="color: #339933;">-&gt;</span>w <span style="color: #339933;">/</span> <span style="color: #0000dd;">2</span> <span style="color: #339933;">+</span> sin<span style="color: #009900;">&#40;</span>radianes<span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #0000dd;">60</span> <span style="color: #339933;">-</span> diamante<span style="color: #339933;">-&gt;</span>w <span style="color: #339933;">/</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">;</span>
		destino.<span style="color: #202020;">y</span> <span style="color: #339933;">=</span> pantalla<span style="color: #339933;">-&gt;</span>h <span style="color: #339933;">/</span> <span style="color: #0000dd;">2</span> <span style="color: #339933;">+</span> cos<span style="color: #009900;">&#40;</span>radianes<span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #0000dd;">60</span> <span style="color: #339933;">-</span> diamante<span style="color: #339933;">-&gt;</span>h <span style="color: #339933;">/</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">;</span>
		SDL_BlitSurface<span style="color: #009900;">&#40;</span>diamante<span style="color: #339933;">,</span> NULL<span style="color: #339933;">,</span> pantalla<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>destino<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		SDL_Flip<span style="color: #009900;">&#40;</span>pantalla<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		SDL_Delay<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		SDL_FillRect<span style="color: #009900;">&#40;</span>pantalla<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>destino<span style="color: #339933;">,</span> 
			SDL_MapRGB<span style="color: #009900;">&#40;</span>pantalla<span style="color: #339933;">-&gt;</span>format<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		destino.<span style="color: #202020;">x</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
		destino.<span style="color: #202020;">y</span> <span style="color: #339933;">=</span> pantalla<span style="color: #339933;">-&gt;</span>h <span style="color: #339933;">-</span> sol<span style="color: #339933;">-&gt;</span>h<span style="color: #339933;">;</span>
		SDL_FillRect<span style="color: #009900;">&#40;</span>pantalla<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>destino<span style="color: #339933;">,</span>
			SDL_MapRGB<span style="color: #009900;">&#40;</span>pantalla<span style="color: #339933;">-&gt;</span>format<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		radianes <span style="color: #339933;">+=</span> <span style="color:#800080;">0.02</span><span style="color: #339933;">;</span>
		alpha <span style="color: #339933;">+=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	SDL_FreeSurface<span style="color: #009900;">&#40;</span>izquierda<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	SDL_FreeSurface<span style="color: #009900;">&#40;</span>derecha<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	SDL_FreeSurface<span style="color: #009900;">&#40;</span>ok<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	SDL_FreeSurface<span style="color: #009900;">&#40;</span>diamante<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	SDL_FreeSurface<span style="color: #009900;">&#40;</span>sol<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	SDL_FreeSurface<span style="color: #009900;">&#40;</span>pantalla<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>Fin del programa<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> 
<span style="color: #009900;">&#125;</span></pre></div></div>

<h3>[COMPILACIÓN]</h3>
<p>Para compilar el programa, copiad el código fuente y guardarlo en la carpeta <em>minifs</em> con el nombre <em>pruebasdl.c</em>, después desde ese mismo directorio ejecutad el comando:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">toolchain<span style="color: #000000; font-weight: bold;">/</span>arm-v4t-linux-uclibcgnueabi<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>arm-v4t-linux-uclibcgnueabi-gcc <span style="color: #660033;">-I</span> build-df3120<span style="color: #000000; font-weight: bold;">/</span>staging<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>include <span style="color: #660033;">-L</span> build-df3120<span style="color: #000000; font-weight: bold;">/</span>staging<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib <span style="color: #660033;">-lSDL</span> -lSDL_image <span style="color: #660033;">-liconv</span> <span style="color: #660033;">-o</span> pruebasdl pruebasdl.c</pre></div></div>

<h3>[EJECUCIÓN]</h3>
<p>Una vez se haya creado el fichero <em>pruebasdl</em>, descargarlo en el marco junto con las siguientes imágenes:</p>
<p><a href="http://www.sistemasorp.es/wp-content/uploads/2012/02/izquierda.png"><img class="alignnone size-full wp-image-549" title="izquierda" src="http://www.sistemasorp.es/wp-content/uploads/2012/02/izquierda.png" alt="" width="50" height="49" /></a><a href="http://www.sistemasorp.es/wp-content/uploads/2012/02/ok.png"><img class="alignnone size-full wp-image-550" title="ok" src="http://www.sistemasorp.es/wp-content/uploads/2012/02/ok.png" alt="" width="50" height="50" /></a><a href="http://www.sistemasorp.es/wp-content/uploads/2012/02/derecha.png"><img class="alignnone size-full wp-image-547" title="derecha" src="http://www.sistemasorp.es/wp-content/uploads/2012/02/derecha.png" alt="" width="50" height="49" /></a><a href="http://www.sistemasorp.es/wp-content/uploads/2012/02/diamante.png"><img class="alignnone size-full wp-image-548" title="diamante" src="http://www.sistemasorp.es/wp-content/uploads/2012/02/diamante.png" alt="" width="50" height="50" /></a><a href="http://www.sistemasorp.es/wp-content/uploads/2012/02/sol.gif"><img class="alignnone size-full wp-image-551" title="sol" src="http://www.sistemasorp.es/wp-content/uploads/2012/02/sol.gif" alt="" width="50" height="50" /></a></p>
<p>tal y como explicaba en el <a href="http://www.sistemasorp.es/2012/01/22/probando-el-marco-digital-parrot-df3120-parte-2/" target="_blank">anterior artículo</a> y ejecutarlo. Si todo ha ido bien veréis lo mismo que en el vídeo. Para salir del programa simplemente pulsar las teclas CONTROL y C simultáneamente.</p>
<h3>[EXPLICACIÓN]</h3>
<p>Explicaré cómo funciona el programa. Un buen tutorial de SDL en español lo podéis descargar de <a href="http://www.agserrano.com/libros/sdl/%5Bebook%5DProgramacion%20de%20videojuegos%20con%20SDL.pdf" target="_blank">aquí</a>.</p>
<ul>
<li>Se declaran los punteros <em>SDL_Surface</em>, que son los que contendrán las imágenes y el buffer de la pantalla.</li>
<li>La función <strong>SDL_Init</strong> se llama con el parámetro <em>SDL_INIT_VIDEO</em> para inicializar la librería SDL internamente.</li>
<li>La función <strong>SDL_GetError</strong> devuelve una cadena con el último error ocurrido en la librería SDL.</li>
<li>La función <strong>atexit</strong> con el puntero a la función <em>SDL_Quit</em> se llama para que, cuando la aplicación termine, se llame a la función <em>SDL_Quit</em> y libere todos los recursos usados por la librería.</li>
<li>La función <strong>SDL_SetVideoMode</strong> se llama para inicializar el buffer de la pantalla con los parámetros de anchura, altura, profundidad de color y que use la memoria de vídeo con la técnica de doble buffer (haciendo un OR de los valores SDL_HWSURFACE y SDL_DOUBLEBUF). Esta función nos devuelve la estructura <em>SDL_Surface</em> de ese buffer de pantalla.</li>
<li>La función <strong>SDL_ShowCursor</strong> se llama con el parámetro <em>SDL_DISABLE</em> para ocultar el puntero del ratón en la pantalla.</li>
<li>La función <strong>IMG_Load</strong> se llama con la ruta de una imagen como parámetro para cargar la imagen. Esta función nos devuelve la estructura <em>SDL_Surface</em> de la imagen.</li>
<li>La función <strong>signal</strong> se llama con el parámetro <em>SIGINT</em> y un puntero a una función para que se capture la pulsación de las teclas CTRL y C. Cuando se pulsen se llamará a la función <strong>salida</strong> que simplemente cambiará el valor de la variable <em>salir</em>. Esto se usa para poder salir del bucle principal y terminar el programa de una forma limpia.</li>
<li>La función <strong>SDL_BlitSurface</strong> se llama con una imagen, un valor nulo, el buffer de la pantalla y una estructura <em>SDL_Rect</em> como parámetros. Esto copia la imagen en el buffer de la pantalla en el lugar indicado por la estructura <em>SDL_Rect</em>.</li>
<li>La función <strong>SDL_SetAlpha</strong> se llama con una imagen, con los valores <em>SDL_SRCALPHA</em> y <em>SDL_RLEACCEL</em> y un número como parámetros. Esto modifica la transparencia de una imagen (valor 0 para transparente y valor 255 para opaca). No funciona bien con los <em>PNG</em>, por eso la imagen del sol es un <em>GIF</em>.</li>
<li>La función <strong>SDL_Flip</strong> se llama con el parámetro del buffer de pantalla para traspasar todos los pixels del buffer de pantalla a la tarjeta de vídeo y así mostrarlos.</li>
<li>La función <strong>SDL_Delay</strong> se llama con un número como parámetro para parar la ejecución del programa durante un tiempo especificado en milisegundos.</li>
<li>La función <strong>SDL_FillRect</strong> se llama con el buffer de pantalla, una estructura <em>SDL_Rect</em> y un color como parámetros para que dibuje en la zona determinada por la estructura <em>SDL_Rect</em> un rectángulo con el color especificado. En las animaciones se usa para eliminar el dibujo anterior al que se va a pintar y así dar un efecto de movimiento.</li>
<li>La función <strong>SDL_MapRGB</strong> se llama con el formato del buffer de la pantalla y 3 números como parámetros. Sirve para mapear un color RGB al formato del buffer de la pantalla y así adaptarlo a su profundidad de color.</li>
<li>La función <strong>SDL_FreeSurface</strong> se llama con una estructura <em>SDL_Rect</em> como parámetro para liberar todos los recursos utilizados por esta.</li>
</ul>
<p>Con todo esto hemos logrado dibujar en la pantalla imágenes png y gif, además de animar dos de ellas en un bucle (una haciendo círculos gracias a las funciones trigonométricas de seno y coseno y la otra a fundirse mediante transparencia) a la espera de que el usuario pulse la combinación de teclas CTRL+C para salir del programa.</p>
<h1>2- Entradas de información</h1>
<p>Al igual que antes pongo un vídeo, después el código fuente, a continuación cómo compilarlo, ejecutarlo y finalmente explicar su funcionamiento.</p>
<h3>[VÍDEO]</h3>
<p><iframe width="425" height="349" src="http://www.youtube.com/embed/LK56STGGTTY?hl=es&#038;fs=1" frameborder="0" allowfullscreen></iframe></p>
<h3>[CÓDIGO]</h3>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &lt;stdio.h&gt; </span>
<span style="color: #339933;">#include &lt;stdlib.h&gt; </span>
<span style="color: #339933;">#include &lt;math.h&gt;</span>
<span style="color: #339933;">#include &lt;signal.h&gt;</span>
<span style="color: #339933;">#include &lt;sys/mman.h&gt;</span>
<span style="color: #339933;">#include &lt;fcntl.h&gt;</span>
<span style="color: #339933;">#include &lt;SDL/SDL.h&gt;</span>
<span style="color: #339933;">#include &lt;SDL/SDL_image.h&gt;</span>
&nbsp;
<span style="color: #339933;">#define BASE_PUERTOS 0x56000000</span>
<span style="color: #339933;">#define BASE_ADC 0x58000000</span>
<span style="color: #339933;">#define PUERTO_F_CONFIGURACION 0x50</span>
<span style="color: #339933;">#define PUERTO_G_CONFIGURACION 0x60</span>
<span style="color: #339933;">#define PUERTO_F_DATOS PUERTO_F_CONFIGURACION + 4</span>
<span style="color: #339933;">#define PUERTO_G_DATOS PUERTO_G_CONFIGURACION + 4</span>
<span style="color: #339933;">#define ADC_0 0x0C</span>
<span style="color: #339933;">#define BOTON_I  3</span>
<span style="color: #339933;">#define BOTON_C  4</span>
<span style="color: #339933;">#define BOTON_D  2</span>
<span style="color: #339933;">#define INCLINOMETRO_1  9</span>
<span style="color: #339933;">#define INCLINOMETRO_2  10</span>
<span style="color: #339933;">#define CONFIGURA_F 0xFC0F</span>
<span style="color: #339933;">#define CONFIGURA_G 0xFFC3FFFF</span>
<span style="color: #339933;">#define CONFIGURA_ADC 0x7FC2</span>
&nbsp;
<span style="color: #993333;">typedef</span> <span style="color: #993333;">struct</span>
<span style="color: #009900;">&#123;</span>
 <span style="color: #993333;">char</span> boton_izquierdo<span style="color: #339933;">;</span>
 <span style="color: #993333;">char</span> boton_central<span style="color: #339933;">;</span>
 <span style="color: #993333;">char</span> boton_derecho<span style="color: #339933;">;</span>
 <span style="color: #993333;">char</span> inclinacion<span style="color: #339933;">;</span>
 <span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> luminosidad<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
ENTRADAS<span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #993333;">volatile</span> <span style="color: #993333;">char</span> salir <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #993333;">static</span> <span style="color: #993333;">volatile</span> <span style="color: #993333;">void</span> <span style="color: #339933;">*</span>memoria_puertos<span style="color: #339933;">;</span>
<span style="color: #993333;">static</span> <span style="color: #993333;">volatile</span> <span style="color: #993333;">void</span> <span style="color: #339933;">*</span>memoria_adc<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">void</span> salida<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> sig<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	salir <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> inicializa_entradas<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">int</span> fd <span style="color: #339933;">=</span> open<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;/dev/mem&quot;</span><span style="color: #339933;">,</span> O_RDWR<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>fd <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		perror<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;/dev/mem&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		exit<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	memoria_puertos <span style="color: #339933;">=</span> mmap<span style="color: #009900;">&#40;</span>NULL<span style="color: #339933;">,</span> getpagesize<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> PROT_READ <span style="color: #339933;">|</span> PROT_WRITE<span style="color: #339933;">,</span> MAP_SHARED<span style="color: #339933;">,</span> fd<span style="color: #339933;">,</span> BASE_PUERTOS<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>memoria_puertos <span style="color: #339933;">==</span> MAP_FAILED<span style="color: #009900;">&#41;</span> 
	<span style="color: #009900;">&#123;</span>
		perror<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;mmap puertos&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		exit<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	memoria_adc <span style="color: #339933;">=</span> mmap<span style="color: #009900;">&#40;</span>NULL<span style="color: #339933;">,</span> getpagesize<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> PROT_READ <span style="color: #339933;">|</span> PROT_WRITE<span style="color: #339933;">,</span> MAP_SHARED<span style="color: #339933;">,</span> fd<span style="color: #339933;">,</span> BASE_ADC<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>memoria_adc <span style="color: #339933;">==</span> MAP_FAILED<span style="color: #009900;">&#41;</span> 
	<span style="color: #009900;">&#123;</span>
		perror<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;mmap adc&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		exit<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #993333;">uint32_t</span> configuracion <span style="color: #339933;">=</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">uint32_t</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span>memoria_puertos <span style="color: #339933;">+</span> PUERTO_F_CONFIGURACION<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	configuracion <span style="color: #339933;">&amp;=</span> CONFIGURA_F<span style="color: #339933;">;</span>
	<span style="color: #339933;">*</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">uint32_t</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span>memoria_puertos <span style="color: #339933;">+</span> PUERTO_F_CONFIGURACION<span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> configuracion<span style="color: #339933;">;</span>
&nbsp;
	configuracion <span style="color: #339933;">=</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">uint32_t</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span>memoria_puertos <span style="color: #339933;">+</span> PUERTO_G_CONFIGURACION<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	configuracion <span style="color: #339933;">&amp;=</span> CONFIGURA_G<span style="color: #339933;">;</span>
	<span style="color: #339933;">*</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">uint32_t</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span>memoria_puertos <span style="color: #339933;">+</span> PUERTO_G_CONFIGURACION<span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> configuracion<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #339933;">*</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">uint32_t</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span>memoria_adc<span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> CONFIGURA_ADC<span style="color: #339933;">;</span>
	configuracion <span style="color: #339933;">=</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">uint32_t</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span>memoria_adc <span style="color: #339933;">+</span> ADC_0<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> lee_entradas<span style="color: #009900;">&#40;</span>ENTRADAS <span style="color: #339933;">*</span>entradas<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">uint32_t</span> datos <span style="color: #339933;">=</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">uint32_t</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span>memoria_puertos <span style="color: #339933;">+</span> PUERTO_F_DATOS<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	entradas<span style="color: #339933;">-&gt;</span>boton_derecho <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>datos <span style="color: #339933;">&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span>pow<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">2</span><span style="color: #339933;">,</span> BOTON_D<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;&gt;</span> BOTON_D<span style="color: #339933;">;</span>
	entradas<span style="color: #339933;">-&gt;</span>boton_izquierdo <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>datos <span style="color: #339933;">&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span>pow<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">2</span><span style="color: #339933;">,</span> BOTON_I<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;&gt;</span> BOTON_I<span style="color: #339933;">;</span>
	entradas<span style="color: #339933;">-&gt;</span>boton_central <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>datos <span style="color: #339933;">&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span>pow<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">2</span><span style="color: #339933;">,</span> BOTON_C<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;&gt;</span> BOTON_C<span style="color: #339933;">;</span>
	datos <span style="color: #339933;">=</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">uint32_t</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span>memoria_puertos <span style="color: #339933;">+</span> PUERTO_G_DATOS<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	entradas<span style="color: #339933;">-&gt;</span>inclinacion <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>datos <span style="color: #339933;">&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span>pow<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">2</span><span style="color: #339933;">,</span> INCLINOMETRO_2<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>datos <span style="color: #339933;">&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span>pow<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">2</span><span style="color: #339933;">,</span> INCLINOMETRO_1<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;&gt;</span> INCLINOMETRO_1<span style="color: #339933;">;</span>
	datos <span style="color: #339933;">=</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">uint32_t</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span> memoria_adc<span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>datos <span style="color: #339933;">&amp;</span> <span style="color: #208080;">0x8000</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		datos <span style="color: #339933;">=</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">uint32_t</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span>memoria_adc <span style="color: #339933;">+</span> ADC_0<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		entradas<span style="color: #339933;">-&gt;</span>luminosidad <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>datos <span style="color: #339933;">&amp;</span> <span style="color: #208080;">0x3FF</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #0000dd;">255</span> <span style="color: #339933;">/</span> <span style="color: #0000dd;">1023</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span> 
<span style="color: #009900;">&#123;</span> 
	SDL_Surface <span style="color: #339933;">*</span>izquierda<span style="color: #339933;">;</span>
	SDL_Surface <span style="color: #339933;">*</span>derecha<span style="color: #339933;">;</span>
	SDL_Surface <span style="color: #339933;">*</span>ok<span style="color: #339933;">;</span>
	SDL_Surface <span style="color: #339933;">*</span>diamante<span style="color: #339933;">;</span>
	SDL_Surface <span style="color: #339933;">*</span>sol<span style="color: #339933;">;</span>
	SDL_Surface <span style="color: #339933;">*</span>pantalla<span style="color: #339933;">;</span>
 	SDL_Rect destino<span style="color: #339933;">;</span>
	<span style="color: #993333;">float</span> radianes <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
	<span style="color: #993333;">float</span> destino_radianes<span style="color: #339933;">;</span>
	<span style="color: #993333;">float</span> suma_radianes<span style="color: #339933;">;</span>
	ENTRADAS entradas<span style="color: #339933;">;</span>
&nbsp;
	inicializa_entradas<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>SDL_Init<span style="color: #009900;">&#40;</span>SDL_INIT_VIDEO<span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> 
	<span style="color: #009900;">&#123;</span> 
		<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;No se pudo iniciar SDL: %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>SDL_GetError<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		exit<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	<span style="color: #009900;">&#125;</span> 
&nbsp;
	atexit<span style="color: #009900;">&#40;</span>SDL_Quit<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	pantalla <span style="color: #339933;">=</span> SDL_SetVideoMode<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">320</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">240</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">16</span><span style="color: #339933;">,</span> 
		SDL_HWSURFACE <span style="color: #339933;">|</span> SDL_DOUBLEBUF<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>pantalla <span style="color: #339933;">==</span> NULL<span style="color: #009900;">&#41;</span> 
	<span style="color: #009900;">&#123;</span> 
	  	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;No se puede inicializar el modo gráfico: %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>
			SDL_GetError<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		exit<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	<span style="color: #009900;">&#125;</span> 
&nbsp;
	SDL_ShowCursor<span style="color: #009900;">&#40;</span>SDL_DISABLE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
	izquierda <span style="color: #339933;">=</span> IMG_Load<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;izquierda.png&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>izquierda <span style="color: #339933;">==</span> NULL<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span> 
		<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;No pude cargar gráfico: %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> SDL_GetError<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		exit<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	<span style="color: #009900;">&#125;</span> 
&nbsp;
	derecha <span style="color: #339933;">=</span> IMG_Load<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;derecha.png&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>derecha <span style="color: #339933;">==</span> NULL<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span> 
        	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;No pude cargar gráfico: %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> SDL_GetError<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		exit<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	<span style="color: #009900;">&#125;</span>
&nbsp;
	ok <span style="color: #339933;">=</span> IMG_Load<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;ok.png&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>ok <span style="color: #339933;">==</span> NULL<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span> 
        	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;No pude cargar gráfico: %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> SDL_GetError<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
        	exit<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	<span style="color: #009900;">&#125;</span>
&nbsp;
	diamante <span style="color: #339933;">=</span> IMG_Load<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;diamante.png&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>diamante <span style="color: #339933;">==</span> NULL<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span> 
        	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;No pude cargar gráfico: %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> SDL_GetError<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
        	exit<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
    	<span style="color: #009900;">&#125;</span>
&nbsp;
	sol <span style="color: #339933;">=</span> IMG_Load<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;sol.gif&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>sol <span style="color: #339933;">==</span> NULL<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span> 
		<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;No pude cargar gráfico: %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> SDL_GetError<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		exit<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
    	<span style="color: #009900;">&#125;</span> 
&nbsp;
	signal<span style="color: #009900;">&#40;</span>SIGINT<span style="color: #339933;">,</span> salida<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>salir<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		lee_entradas<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>entradas<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// dibujamos el boton izquierdo</span>
		destino.<span style="color: #202020;">x</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
		destino.<span style="color: #202020;">y</span> <span style="color: #339933;">=</span> pantalla<span style="color: #339933;">-&gt;</span>h <span style="color: #339933;">/</span> <span style="color: #0000dd;">2</span> <span style="color: #339933;">-</span> izquierda<span style="color: #339933;">-&gt;</span>h <span style="color: #339933;">/</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">;</span> 
		destino.<span style="color: #202020;">w</span> <span style="color: #339933;">=</span> izquierda<span style="color: #339933;">-&gt;</span>w<span style="color: #339933;">;</span> 
		destino.<span style="color: #202020;">h</span> <span style="color: #339933;">=</span> izquierda<span style="color: #339933;">-&gt;</span>h<span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>entradas.<span style="color: #202020;">boton_izquierdo</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			SDL_BlitSurface<span style="color: #009900;">&#40;</span>izquierda<span style="color: #339933;">,</span> NULL<span style="color: #339933;">,</span> pantalla<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>destino<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">else</span>
		<span style="color: #009900;">&#123;</span>
			SDL_FillRect<span style="color: #009900;">&#40;</span>pantalla<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>destino<span style="color: #339933;">,</span> SDL_MapRGB<span style="color: #009900;">&#40;</span>pantalla<span style="color: #339933;">-&gt;</span>format<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #666666; font-style: italic;">// dibujamos el boton central</span>
		destino.<span style="color: #202020;">x</span> <span style="color: #339933;">=</span> pantalla<span style="color: #339933;">-&gt;</span>w <span style="color: #339933;">/</span> <span style="color: #0000dd;">2</span> <span style="color: #339933;">-</span> ok<span style="color: #339933;">-&gt;</span>w <span style="color: #339933;">/</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>entradas.<span style="color: #202020;">boton_central</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			SDL_BlitSurface<span style="color: #009900;">&#40;</span>ok<span style="color: #339933;">,</span> NULL<span style="color: #339933;">,</span> pantalla<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>destino<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">else</span>
		<span style="color: #009900;">&#123;</span>
			SDL_FillRect<span style="color: #009900;">&#40;</span>pantalla<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>destino<span style="color: #339933;">,</span> SDL_MapRGB<span style="color: #009900;">&#40;</span>pantalla<span style="color: #339933;">-&gt;</span>format<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #666666; font-style: italic;">// dibujamos el boton derecho</span>
		destino.<span style="color: #202020;">x</span> <span style="color: #339933;">=</span> pantalla<span style="color: #339933;">-&gt;</span>w <span style="color: #339933;">-</span> derecha<span style="color: #339933;">-&gt;</span>w<span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>entradas.<span style="color: #202020;">boton_derecho</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			SDL_BlitSurface<span style="color: #009900;">&#40;</span>derecha<span style="color: #339933;">,</span> NULL<span style="color: #339933;">,</span> pantalla<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>destino<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">else</span>
		<span style="color: #009900;">&#123;</span>
			SDL_FillRect<span style="color: #009900;">&#40;</span>pantalla<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>destino<span style="color: #339933;">,</span> SDL_MapRGB<span style="color: #009900;">&#40;</span>pantalla<span style="color: #339933;">-&gt;</span>format<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #666666; font-style: italic;">// dibujamos el sol de luminosidad</span>
		destino.<span style="color: #202020;">x</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
		destino.<span style="color: #202020;">y</span> <span style="color: #339933;">=</span> pantalla<span style="color: #339933;">-&gt;</span>h <span style="color: #339933;">-</span> sol<span style="color: #339933;">-&gt;</span>h<span style="color: #339933;">;</span>
		SDL_SetAlpha<span style="color: #009900;">&#40;</span>sol<span style="color: #339933;">,</span> SDL_SRCALPHA <span style="color: #339933;">|</span> SDL_RLEACCEL<span style="color: #339933;">,</span> entradas.<span style="color: #202020;">luminosidad</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		SDL_BlitSurface<span style="color: #009900;">&#40;</span>sol<span style="color: #339933;">,</span> NULL<span style="color: #339933;">,</span> pantalla<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>destino<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		<span style="color: #666666; font-style: italic;">// dibujamos el diamante de inclinación</span>
		<span style="color: #b1b100;">switch</span><span style="color: #009900;">&#40;</span>entradas.<span style="color: #202020;">inclinacion</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">case</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">:</span> <span style="color: #666666; font-style: italic;">// izquierda</span>
				destino_radianes <span style="color: #339933;">=</span> <span style="color: #0000dd;">3</span> <span style="color: #339933;">*</span> M_PI <span style="color: #339933;">/</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">;</span>
				suma_radianes <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color:#800080;">0.10</span><span style="color: #339933;">;</span>
				<span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">case</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">:</span> <span style="color: #666666; font-style: italic;">// derecha</span>
				destino_radianes <span style="color: #339933;">=</span> M_PI_2<span style="color: #339933;">;</span>
				suma_radianes <span style="color: #339933;">=</span> <span style="color:#800080;">0.10</span><span style="color: #339933;">;</span>
				<span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">case</span> <span style="color: #0000dd;">3</span><span style="color: #339933;">:</span> <span style="color: #666666; font-style: italic;">// abajo</span>
				<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>radianes <span style="color: #339933;">&gt;</span> M_PI<span style="color: #009900;">&#41;</span>
				<span style="color: #009900;">&#123;</span>
					destino_radianes <span style="color: #339933;">=</span> <span style="color: #0000dd;">2</span> <span style="color: #339933;">*</span> M_PI<span style="color: #339933;">;</span>
					suma_radianes <span style="color: #339933;">=</span> <span style="color:#800080;">0.10</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
				<span style="color: #b1b100;">else</span>
				<span style="color: #009900;">&#123;</span>
					destino_radianes <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
					suma_radianes <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color:#800080;">0.10</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
				<span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>radianes <span style="color: #339933;">&gt;</span> <span style="color: #009900;">&#40;</span>destino_radianes <span style="color: #339933;">+</span> <span style="color:#800080;">0.10</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span>radianes <span style="color: #339933;">&lt;</span> <span style="color: #009900;">&#40;</span>destino_radianes <span style="color: #339933;">-</span> <span style="color:#800080;">0.10</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			radianes <span style="color: #339933;">+=</span> suma_radianes<span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>radianes <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				radianes <span style="color: #339933;">=</span> <span style="color: #0000dd;">2</span> <span style="color: #339933;">*</span> M_PI<span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>radianes <span style="color: #339933;">&gt;</span> <span style="color: #009900;">&#40;</span><span style="color: #0000dd;">2</span> <span style="color: #339933;">*</span> M_PI<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				radianes <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		destino.<span style="color: #202020;">x</span> <span style="color: #339933;">=</span> pantalla<span style="color: #339933;">-&gt;</span>w <span style="color: #339933;">/</span> <span style="color: #0000dd;">2</span> <span style="color: #339933;">+</span> sin<span style="color: #009900;">&#40;</span>radianes<span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> diamante<span style="color: #339933;">-&gt;</span>w <span style="color: #339933;">-</span> diamante<span style="color: #339933;">-&gt;</span>w <span style="color: #339933;">/</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">;</span>
		destino.<span style="color: #202020;">y</span> <span style="color: #339933;">=</span> pantalla<span style="color: #339933;">-&gt;</span>h <span style="color: #339933;">/</span> <span style="color: #0000dd;">2</span> <span style="color: #339933;">+</span> cos<span style="color: #009900;">&#40;</span>radianes<span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> diamante<span style="color: #339933;">-&gt;</span>h <span style="color: #339933;">-</span> diamante<span style="color: #339933;">-&gt;</span>h <span style="color: #339933;">/</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">;</span>
		SDL_BlitSurface<span style="color: #009900;">&#40;</span>diamante<span style="color: #339933;">,</span> NULL<span style="color: #339933;">,</span> pantalla<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>destino<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		SDL_Flip<span style="color: #009900;">&#40;</span>pantalla<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		SDL_Delay<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		SDL_FillRect<span style="color: #009900;">&#40;</span>pantalla<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>destino<span style="color: #339933;">,</span> 
			SDL_MapRGB<span style="color: #009900;">&#40;</span>pantalla<span style="color: #339933;">-&gt;</span>format<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		destino.<span style="color: #202020;">x</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
		destino.<span style="color: #202020;">y</span> <span style="color: #339933;">=</span> pantalla<span style="color: #339933;">-&gt;</span>h <span style="color: #339933;">-</span> sol<span style="color: #339933;">-&gt;</span>h<span style="color: #339933;">;</span>
		SDL_FillRect<span style="color: #009900;">&#40;</span>pantalla<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>destino<span style="color: #339933;">,</span>
			SDL_MapRGB<span style="color: #009900;">&#40;</span>pantalla<span style="color: #339933;">-&gt;</span>format<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	SDL_FreeSurface<span style="color: #009900;">&#40;</span>izquierda<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	SDL_FreeSurface<span style="color: #009900;">&#40;</span>derecha<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	SDL_FreeSurface<span style="color: #009900;">&#40;</span>ok<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	SDL_FreeSurface<span style="color: #009900;">&#40;</span>diamante<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	SDL_FreeSurface<span style="color: #009900;">&#40;</span>sol<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	SDL_FreeSurface<span style="color: #009900;">&#40;</span>pantalla<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>Fin del programa<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> 
<span style="color: #009900;">&#125;</span></pre></div></div>

<h3>[COMPILACIÓN]</h3>
<p>Hay que hacer lo mismo que en la <em>COMPILACIÓN</em> del apartado <em>Librería SDL</em>. Sólo que esta vez el fichero de salida se llama <em>pruebaentradas</em> y el del código fuente <em>pruebaentradas.c</em>.</p>
<h3>[EJECUCIÓN]</h3>
<p>Hay que hacer lo mismo que en la <em>EJECUCIÓN</em> del apartado <em>Librería SDL</em>, incluidas las imágenes si no las tenéis ya. Sólo que esta vez el fichero se llama <em>pruebaentradas</em>.</p>
<h3>[EXPLICACIÓN]</h3>
<p>En esta ocasión he aprovechado el código del anterior apartado y le he modificado para que responda a eventos. Ahora cada vez que se pulse un botón saldrá en la pantalla el icono correspondiente, se mostrará hacia que lado del marco está la gravedad y cuanta luz llega al sensor trasero.</p>
<p>Me centraré en explicar cómo he recuperado la información de las entradas de las que dispone el marco (botones, inclinómetro y fotoresistencia).</p>
<p>Si os acordáis en el <a href="http://www.sistemasorp.es/2012/01/19/probando-el-marco-digital-parrot-df3120-parte-1/" target="_blank">primer artículo</a> explicaba cómo acceder a la memoria del vídeo para escribir los píxeles de la imagen directamente en ella. Aquí lo que vamos a hacer es abrir el fichero <em>/dev/mem</em> ya que desde él podemos acceder a los registros del microprocesador que contienen la información de las entradas y poder configurarlas. Si queréis saber a fondo cómo funciona el microprocesador s3c2412 que gobierna el marco os podéis bajar su <a href="http://www.sistemasorp.es/blog/S3C2410 - datasheet.pdf" target="_blank">datasheet</a>. Las entradas de los botones se pueden leer desde los pines 2, 3 y 4 del puerto F y las del inclinómetro desde los pines 9 y 10 del puerto G, en ambos casos son <a href="http://en.wikipedia.org/wiki/General_Purpose_Input/Output" target="_blank">GPIO</a> y los leeremos mediante <a href="http://es.wikipedia.org/wiki/Polling" target="_blank">polling</a>. El valor de la fotoresistencia se puede leer del pin ADC0 y como indica el nombre es un <a href="http://es.wikipedia.org/wiki/Conversi%C3%B3n_anal%C3%B3gica-digital" target="_blank">ADC</a> que leeremos igualmente mediante polling.</p>
<p>En la función <strong>inicializa_entradas</strong> inicializaremos los registros:</p>
<ul>
<li>Con la función <strong>open</strong> abrimos el fichero <em>/dev/mem</em> como lectura y escritura.</li>
<li>Con la función <strong>mmap</strong> abrimos las posición de memoria 0&#215;56000000 para poder acceder desde el <a href="http://es.wikipedia.org/wiki/Espacio_de_usuario" target="_blank">espacio de usuario</a> a los registros de configuración y de datos de los puertos GPIO y la posición de memoria 0&#215;58000000 para leer los canales ADC. Estos números se pueden encontrar en las páginas 68 y 69 del datasheet que he puesto antes.</li>
<li>Para leer los puertos F y G debemos configurarlos antes. Para esto debemos acceder a las direcciones de memoria de configuración del puerto F (<em>GPFCON </em>0&#215;56000050) y del puerto G (<em>GPGCON </em>0&#215;56000060) e indicar qué bits serán de lectura. En el puerto F serán los bits 2, 3 y 4 por lo que el valor de configuración para este registro (según las página 275 del datasheet) será xxxxxx000000xxxx, o lo que es lo mismo, para dejar el resto de bits a su valor original y sólo cambiar los 6 bits de los botones hay que hacer una operación AND del valor 0xFC0F. En el puerto G serán los bits 9 y 10 por lo que el valor de configuración para este registro (según la página 276 del datasheet) será xxxxxxxxxx0000xxxxxxxxxxxxxxxxxx, o lo que es lo mismo, para dejar el resto de bits a su valor original y sólo cambiar los 4 bits del inclinómetro hay que hacer una operación AND del valor 0xFFC3FFFF.</li>
<li>Para leer continuamente el valor del canal 0 del ADC donde se encuentra conectada la fotoresistencia debemos configurar el registro <em>ADCCON</em> situado en la dirección de memoria 0&#215;58000000.  Lo inicializaremos asignándole el valor 0x7FC2 (según la página 420 del datasheet). Finalmente leemos el valor del ADC para activarlo.</li>
</ul>
<p>En la función <strong>lee_entradas</strong> leeremos el valor de las entradas y los guardaremos en una estructura llamada ENTRADAS:</p>
<ul>
<li>Accedemos a las direcciones de memoria de datos del puerto F (<em>GPFDAT</em> 0&#215;56000054) y G (<em>GPGDAT</em> 0&#215;56000064), extraemos uno por uno los valores de los pines con una operación AND, desplazamos esos valores mediante shifting hasta dejarlos en el primer bit  y los vamos guardando en la variable correspondiente de la estructura. Los botones cuando están libres tienen un valor de 1, pero cuando están pulsados tienen un valor de 0. El botón izquierdo corresponde al pin 3, el botón central corresponde al pin 4 y el botón derecho al pin 2. El inclinómetro tiene un valor de 3 cuando el marco reposa sobre su base , un valor de 2 si reposa sobre el lado derecho y un valor de 1 si reposa sobre el lado izquierdo. No detecta cuando el marco reposa por el lado contrario a la base (que sería un valor de 0).</li>
<li>Para el ADC0 accedemos a su dirección de memoria de configuración (<em>ADCCON</em><em> 0&#215;58000000</em>), leemos su valor y comprobamos que el último bit está a 1 para saber si podemos leer el resultado de la conversión o todavía la está haciendo, si está a 1 leemos la dirección de memoria de datos (<em>ADCDAT0 </em>0x5800000C), nos quedamos con los primeros 10 bits y hacemos una conversión a 8 bits para que se pueda usar directamente en la función  <em>SDL_SetAlpha</em>.</li>
</ul>
<p>Con todo esto hemos modificado el programa del apartado <em>Librería SDL</em> para que ahora sólo represente las imágenes dependiendo del estado de las distintas entradas que componen el marco digital.</p>
<h1>3- Comunicaciones</h1>
<p>Como en los casos anteriores pongo un vídeo, después el código fuente, a continuación cómo compilarlo, ejecutarlo y finalmente explicar su funcionamiento.</p>
<h3>[VÍDEO]</h3>
<p><iframe width="425" height="349" src="http://www.youtube.com/embed/z4KlFS4SZSY?hl=es&#038;fs=1" frameborder="0" allowfullscreen></iframe></p>
<h3>[CÓDIGO]</h3>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &lt;stdio.h&gt; </span>
<span style="color: #339933;">#include &lt;stdlib.h&gt; </span>
<span style="color: #339933;">#include &lt;math.h&gt;</span>
<span style="color: #339933;">#include &lt;signal.h&gt;</span>
<span style="color: #339933;">#include &lt;fcntl.h&gt;</span>
<span style="color: #339933;">#include &lt;netinet/in.h&gt;</span>
<span style="color: #339933;">#include &lt;sys/socket.h&gt;</span>
<span style="color: #339933;">#include &lt;netdb.h&gt;</span>
<span style="color: #339933;">#include &lt;SDL/SDL.h&gt;</span>
<span style="color: #339933;">#include &lt;SDL/SDL_image.h&gt;</span>
&nbsp;
<span style="color: #993333;">volatile</span> <span style="color: #993333;">char</span> salir <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">void</span> salida<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> sig<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	salir <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> carga_imagen<span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span> <span style="color: #339933;">*</span>cadena<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">int</span> conexion<span style="color: #339933;">,</span> recibidos<span style="color: #339933;">,</span> reales<span style="color: #339933;">;</span>
	<span style="color: #993333;">char</span> cabecera <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
	<span style="color: #993333;">char</span> <span style="color: #339933;">*</span>puntero<span style="color: #339933;">;</span>
	<span style="color: #993333;">char</span> buffer<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1024</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #993333;">struct</span> addrinfo parametros<span style="color: #339933;">,</span> <span style="color: #339933;">*</span>servidores<span style="color: #339933;">,</span> <span style="color: #339933;">*</span>coincidencia<span style="color: #339933;">;</span>
	<span style="color: #993333;">int</span> rv<span style="color: #339933;">;</span>
	FILE <span style="color: #339933;">*</span>fichero<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>fichero <span style="color: #339933;">=</span> fopen<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;texto.png&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;wb&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> NULL<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		perror<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;fichero texto.png&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
    	memset<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>parametros<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #993333;">sizeof</span> parametros<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    	parametros.<span style="color: #202020;">ai_family</span> <span style="color: #339933;">=</span> AF_UNSPEC<span style="color: #339933;">;</span>
    	parametros.<span style="color: #202020;">ai_socktype</span> <span style="color: #339933;">=</span> SOCK_STREAM<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>rv <span style="color: #339933;">=</span> getaddrinfo<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;sistemasorp.es&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;80&quot;</span><span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>parametros<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>servidores<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
	        fprintf<span style="color: #009900;">&#40;</span>stderr<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;getaddrinfo: %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> gai_strerror<span style="color: #009900;">&#40;</span>rv<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	        <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>coincidencia <span style="color: #339933;">=</span> servidores<span style="color: #339933;">;</span> coincidencia <span style="color: #339933;">!=</span> NULL<span style="color: #339933;">;</span> coincidencia <span style="color: #339933;">=</span> coincidencia<span style="color: #339933;">-&gt;</span>ai_next<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>conexion <span style="color: #339933;">=</span> socket<span style="color: #009900;">&#40;</span>coincidencia<span style="color: #339933;">-&gt;</span>ai_family<span style="color: #339933;">,</span> coincidencia<span style="color: #339933;">-&gt;</span>ai_socktype<span style="color: #339933;">,</span>
                coincidencia<span style="color: #339933;">-&gt;</span>ai_protocol<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			perror<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;socket&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>connect<span style="color: #009900;">&#40;</span>conexion<span style="color: #339933;">,</span> coincidencia<span style="color: #339933;">-&gt;</span>ai_addr<span style="color: #339933;">,</span> coincidencia<span style="color: #339933;">-&gt;</span>ai_addrlen<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
		    close<span style="color: #009900;">&#40;</span>conexion<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		    perror<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;connect&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		    <span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
	        <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>coincidencia <span style="color: #339933;">==</span> NULL<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
	        fprintf<span style="color: #009900;">&#40;</span>stderr<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;No se puedo conectar<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    	<span style="color: #009900;">&#125;</span>
&nbsp;
	freeaddrinfo<span style="color: #009900;">&#40;</span>servidores<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	sprintf<span style="color: #009900;">&#40;</span>buffer<span style="color: #339933;">,</span><span style="color: #ff0000;">&quot;GET /blog/imagen.php?cadena=%s HTTP/1.0<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>Host:www.sistemasorp.es<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> cadena<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	send<span style="color: #009900;">&#40;</span>conexion<span style="color: #339933;">,</span> buffer<span style="color: #339933;">,</span> strlen<span style="color: #009900;">&#40;</span>buffer<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>recibidos <span style="color: #339933;">=</span> recv<span style="color: #009900;">&#40;</span>conexion<span style="color: #339933;">,</span> buffer<span style="color: #339933;">,</span> <span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span>buffer<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> 
	<span style="color: #009900;">&#123;</span>
		puntero <span style="color: #339933;">=</span> buffer<span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>cabecera<span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			puntero <span style="color: #339933;">=</span> strstr<span style="color: #009900;">&#40;</span>buffer<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			puntero <span style="color: #339933;">+=</span> <span style="color: #0000dd;">4</span><span style="color: #339933;">;</span>
			reales <span style="color: #339933;">=</span> recibidos <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span>puntero <span style="color: #339933;">-</span> buffer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			recibidos <span style="color: #339933;">=</span> reales<span style="color: #339933;">;</span>
			cabecera <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		fwrite<span style="color: #009900;">&#40;</span>puntero<span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">,</span> recibidos<span style="color: #339933;">,</span> fichero<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
	close<span style="color: #009900;">&#40;</span>conexion<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	fclose<span style="color: #009900;">&#40;</span>fichero<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span> 
<span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">char</span> caracter<span style="color: #339933;">;</span>
	<span style="color: #993333;">char</span> cadena<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">100</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #993333;">char</span> <span style="color: #339933;">*</span>puntero <span style="color: #339933;">=</span> cadena<span style="color: #339933;">;</span>
	FILE <span style="color: #339933;">*</span>fichero<span style="color: #339933;">;</span>
	fd_set lista<span style="color: #339933;">;</span>
	<span style="color: #993333;">struct</span> timeval tv<span style="color: #339933;">;</span>
	SDL_Surface <span style="color: #339933;">*</span>texto<span style="color: #339933;">;</span>
	SDL_Surface <span style="color: #339933;">*</span>pantalla<span style="color: #339933;">;</span> 
 	SDL_Rect destino<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>SDL_Init<span style="color: #009900;">&#40;</span>SDL_INIT_VIDEO<span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> 
	<span style="color: #009900;">&#123;</span> 
		<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;No se pudo iniciar SDL: %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>SDL_GetError<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		exit<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	<span style="color: #009900;">&#125;</span> 
&nbsp;
	atexit<span style="color: #009900;">&#40;</span>SDL_Quit<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	pantalla <span style="color: #339933;">=</span> SDL_SetVideoMode<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">320</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">240</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">16</span><span style="color: #339933;">,</span> 
		SDL_HWSURFACE <span style="color: #339933;">|</span> SDL_DOUBLEBUF<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>pantalla <span style="color: #339933;">==</span> NULL<span style="color: #009900;">&#41;</span> 
	<span style="color: #009900;">&#123;</span> 
	  	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;No se puede inicializar el modo gráfico: %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>
			SDL_GetError<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		exit<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	<span style="color: #009900;">&#125;</span> 
&nbsp;
	SDL_ShowCursor<span style="color: #009900;">&#40;</span>SDL_DISABLE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
	fichero <span style="color: #339933;">=</span> fopen<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;/dev/rfcomm0&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;r&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>fichero <span style="color: #339933;">==</span> NULL<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		perror<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;NO se pudo abrir /dev/rfcomm0&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		exit<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	<span style="color: #009900;">&#125;</span>
&nbsp;
	signal<span style="color: #009900;">&#40;</span>SIGINT<span style="color: #339933;">,</span> salida<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	destino.<span style="color: #202020;">x</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
	destino.<span style="color: #202020;">y</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> 
	destino.<span style="color: #202020;">w</span> <span style="color: #339933;">=</span> pantalla<span style="color: #339933;">-&gt;</span>w<span style="color: #339933;">;</span> 
	destino.<span style="color: #202020;">h</span> <span style="color: #339933;">=</span> pantalla<span style="color: #339933;">-&gt;</span>h<span style="color: #339933;">;</span> 
	SDL_FillRect<span style="color: #009900;">&#40;</span>pantalla<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>destino<span style="color: #339933;">,</span> 
		SDL_MapRGB<span style="color: #009900;">&#40;</span>pantalla<span style="color: #339933;">-&gt;</span>format<span style="color: #339933;">,</span> <span style="color: #0000dd;">255</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">255</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">255</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	SDL_Flip<span style="color: #009900;">&#40;</span>pantalla<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	destino.<span style="color: #202020;">x</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
	destino.<span style="color: #202020;">y</span> <span style="color: #339933;">=</span> pantalla<span style="color: #339933;">-&gt;</span>h <span style="color: #339933;">/</span> <span style="color: #0000dd;">2</span> <span style="color: #339933;">-</span> <span style="color: #0000dd;">15</span><span style="color: #339933;">;</span> 
	destino.<span style="color: #202020;">w</span> <span style="color: #339933;">=</span> pantalla<span style="color: #339933;">-&gt;</span>w<span style="color: #339933;">;</span> 
	destino.<span style="color: #202020;">h</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">30</span><span style="color: #339933;">;</span>
&nbsp;
	memset<span style="color: #009900;">&#40;</span>cadena<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span>cadena<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>salir<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
&nbsp;
		fread<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>caracter<span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">,</span> fichero<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		putchar<span style="color: #009900;">&#40;</span>caracter<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>caracter <span style="color: #339933;">==</span> <span style="color: #ff0000;">' '</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			caracter <span style="color: #339933;">=</span> <span style="color: #ff0000;">'+'</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>caracter <span style="color: #339933;">==</span> <span style="color: #ff0000;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			salir <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">else</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #339933;">*</span>puntero<span style="color: #339933;">++</span> <span style="color: #339933;">=</span> caracter<span style="color: #339933;">;</span>
			<span style="color: #339933;">*</span>puntero <span style="color: #339933;">=</span> <span style="color: #ff0000;">'<span style="color: #006699; font-weight: bold;">\0</span>'</span><span style="color: #339933;">;</span>
			carga_imagen<span style="color: #009900;">&#40;</span>cadena<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		texto <span style="color: #339933;">=</span> IMG_Load<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;texto.png&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>texto <span style="color: #339933;">!=</span> NULL<span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			SDL_BlitSurface<span style="color: #009900;">&#40;</span>texto<span style="color: #339933;">,</span> NULL<span style="color: #339933;">,</span> pantalla<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>destino<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			SDL_Flip<span style="color: #009900;">&#40;</span>pantalla<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	    	<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	fclose<span style="color: #009900;">&#40;</span>fichero<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	SDL_FreeSurface<span style="color: #009900;">&#40;</span>pantalla<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>Fin del programa<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> 
<span style="color: #009900;">&#125;</span></pre></div></div>

<h3>[COMPILACIÓN]</h3>
<p>Hay que hacer lo mismo que en la <em>COMPILACIÓN</em> del apartado <em>Librería SDL</em>. Sólo que esta vez el fichero de salida se llama <em>pruebacomunicaciones</em> y el del código fuente<em> pruebacomunicaciones.c</em>.</p>
<h3>[EJECUCIÓN]</h3>
<p>En el ordenador</strong> debéis tener bluetooth ya sea incorporado o mediante un usb y conexión a internet.</p>
<p>En el ordenador activar el ruteo de paquetes tcp/ip para la interfaz de red del marco (ejecutarlo todo como usuario root, en ubuntu con <strong>sudo -s</strong>)</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">iptables <span style="color: #660033;">--table</span> nat <span style="color: #660033;">--append</span> POSTROUTING <span style="color: #660033;">--out-interface</span> eth0 <span style="color: #660033;">-j</span> MASQUERADE
iptables <span style="color: #660033;">--append</span> FORWARD <span style="color: #660033;">--in-interface</span> usb0 <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>net<span style="color: #000000; font-weight: bold;">/</span>ipv4<span style="color: #000000; font-weight: bold;">/</span>ip_forward</pre></div></div>

<p>En el marco activar la ruta por defecto de los paquetes tcp/ip</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">route add default gw 172.16.61.2</pre></div></div>

<p>En el marco dejar visible a todos el bluetooth y permitir conexiones al marco</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">hciconfig hci0 piscan</pre></div></div>

<p>En el marco mostrar la MAC ADDRESS del bluetooth (para saber a donde se debe conectar el ordenador por rfcomm)</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">hciconfig hci0</pre></div></div>

<p>En el marco dejar en modo de escucha para rfcomm</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">rfcomm listen <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>rfcomm0</pre></div></div>

<p>En el ordenador conectarse al marco mediante rfcomm</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> rfcomm connect <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>rfcomm0 <span style="color: #000000; font-weight: bold;">&lt;</span>MAC ADDRESS<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>En el ordenador descargarse el programa <em>screen</em> (si no se tenía antes)</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #c20cb9; font-weight: bold;">screen</span></pre></div></div>

<p>En el ordenador conectarse al dispositivo rfcomm0 con el programa <em>screen</em></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">screen</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>rfcomm0</pre></div></div>

<p>En el marco ejecutar el programa</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>pruebacomunicaciones</pre></div></div>

<p>En el ordenador desde el programa <em>screen</em> escribir caracteres. ENTER para hacer salir el programa del marco.</p>
<p><strong>Anotaciones</strong></p>
<p>Tendreis que abrir una consola nueva tanto en el ordenador como en el marco después de ejecutar el comando rfcomm puesto que se queda permanentemente conectado hasta que se pulse CTRL + C.</p>
<p>Para salir del programa <em>screen</em> simplemente pulsad CTRL y A a la vez y después de soltarlos pulsad la tecla K.</p>
<h3>[EXPLICACIÓN]</h3>
<p>Por un lado se pretende conectar mediante bluetooth al marco usando las utilidades <a href="http://www.bluez.org/" target="_blank">BlueZ</a> mediante <a href="http://es.wikipedia.org/wiki/Protocolos_Bluetooth#RFCOMM" target="_blank">RFCOMM</a>. Así conseguimos que desde nuestro ordenador podamos enviarle datos al marco.</p>
<p>Por otro lado pretendemos conectarnos a una página de Internet para recuperar una imagen y mostrarla en el marco.</p>
<p>La unión de ambas cosas es lo que habéis visto en el vídeo. Mientras escribo en el programa <em>screen</em> caracteres, estos se envían al marco mediante bluetooth. Despueś el marco los va concatenando y va llamando a una página web que he hecho a tal efecto para que vaya generando la cadena de texto en una imagen PNG. Esta imagen se la descarga el marco y posteriormente la muestra.</p>
<p>Gracias a las utilidades de BlueZ la conexión bluetooth ya se establece mediante comandos y nosotros nos tenemos que dedicar simplemente a abrir el fichero <em>/dev/rfcomm0</em> y desde este escribir o leer con las funciones básicas que proporciona C para manejo de ficheros.</p>
<p>Las conexiones a Internet se consiguen mediante programación de sockets y esto nos da mucho juego para poder pedir información (descargar una imagen, llamar a un servicio web, etc.) y luego mostrarla en nuestro marco. En el ejemplo cuando se llama a la función <strong>carga_imagen</strong> hacemos una conexión http a <a href="http://www.sistemasorp.es/blog/imagen.php?cadena=Vaya!+Pulsaste" target="_blank">http://www.sistemasorp.es/blog/imagen.php</a> con la cadena pasada como parámetro y guardamos en el fichero <em>texto.png</em> la imagen PNG que se ha generado. No voy a explicar qué hace cada función de los sockets, pero si os recomiendo leer el mejor manual que hay en internet para saber cómo programarlos: <a href="http://beej.us/guide/bgnet/output/html/singlepage/bgnet.html" target="_blank">Beej&#8217;s Guide to Network Programming</a>.</p>
<p>Y aquí acaban esta serie de artículos esperando que os haya servido de ayuda para que podáis empezar a juguetear con el marco y sacarle muchas utilidades. Me gustaría que si hicieseis algo con el lo pusierais en los comentarios, además de vuestras dudas o lo que sea.</p>
<p><a href="http://www.sistemasorp.es/2012/01/19/probando-el-marco-digital-parrot-df3120-parte-1/" target="_blank">1º artículo</a></p>
<p><a href="http://www.sistemasorp.es/2012/01/22/probando-el-marco-digital-parrot-df3120-parte-2/" target="_blank">2º artículo</a></p>

<p><a href="http://feedads.g.doubleclick.net/~a/rMe4wFnsGgWjeNsXecl-oE9qoyQ/0/da"><img src="http://feedads.g.doubleclick.net/~a/rMe4wFnsGgWjeNsXecl-oE9qoyQ/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/rMe4wFnsGgWjeNsXecl-oE9qoyQ/1/da"><img src="http://feedads.g.doubleclick.net/~a/rMe4wFnsGgWjeNsXecl-oE9qoyQ/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/sistemasorp/~4/0_ck6WohJa0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.sistemasorp.es/2012/02/12/probando-el-marco-digital-parrot-df3120-parte-3-y-final/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		<feedburner:origLink>http://www.sistemasorp.es/2012/02/12/probando-el-marco-digital-parrot-df3120-parte-3-y-final/</feedburner:origLink></item>
		<item>
		<title>Recuperar una cámara Zaapa CIP-RW después de un fallo de actualización</title>
		<link>http://feedproxy.google.com/~r/sistemasorp/~3/0O-ckqX0bBs/</link>
		<comments>http://www.sistemasorp.es/2012/02/02/recuperar-una-camara-zaapa-cip-rw-despues-de-un-fallo-de-actualizacion/#comments</comments>
		<pubDate>Thu, 02 Feb 2012 15:38:13 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Electrónica]]></category>
		<category><![CDATA[Informática]]></category>
		<category><![CDATA[Proyectos]]></category>
		<category><![CDATA[Reseñas]]></category>

		<guid isPermaLink="false">http://www.sistemasorp.es/?p=538</guid>
		<description><![CDATA[Hace tiempo que mi amigo Roberto quiso actualizar su cámara IP (la cual compró por recomendación mía). El caso es que al actualizar el firmware el proceso falló y la cámara quedó inutilizada. Así han pasado ya muchos meses hasta que hace unos días me encontré con esta página que hablaba de cómo recuperar una cámara [...]]]></description>
			<content:encoded><![CDATA[<p>Hace tiempo que mi amigo <a href="http://nebula.posterous.com/" target="_blank">Roberto</a> quiso actualizar su cámara IP (la cual compró por recomendación mía). El caso es que al actualizar el firmware el proceso falló y la cámara quedó inutilizada. Así han pasado ya muchos meses hasta que hace unos días me encontré con <a href="http://www.gadgetvictims.com/2009/12/bring-your-fi8908w-paperweight-back-to.html" target="_blank">esta página</a> que hablaba de cómo recuperar una cámara Foscam FI8908W cuando el proceso de actualización de firmware ha fallado.</p>
<p>Lo bueno de esta página es que habla de que las cámaras foscam (y la zaapa ciprw es una de ellas con el modelo FI8901W) no mueren del todo, sino que tienen un puerto serie escondido al que se puede acceder y comunicarse con una consola para cargar un firmware. Yo me he comunicado con la cámara con un conversor serie TTL a USB:</p>
<p><a href="http://www.sistemasorp.es/wp-content/uploads/2012/02/IMAG0112.jpg"><img class="aligncenter size-medium wp-image-539" title="Programando la Zaapa" src="http://www.sistemasorp.es/wp-content/uploads/2012/02/IMAG0112-300x200.jpg" alt="" width="300" height="200" /></a></p>
<p>La solución ya estaba, sólo tenía que conseguir el firmware de la zaapa (ya que otros no valen) y decirle a mi amigo que me dejase su cámara para arreglársela. Pero no ha sido así de fácil y he tenido que pelearme con varios frentes.</p>
<p>El primero es el servicio técnico de Foscam. En el comentario 101 del anterior enlace un tal David comentaba que Doris de Foscam había sido muy amable y que le había dado los ficheros de recuperación. Yo probé la misma suerte con el servicio técnico de Foscam y esta fué la primera respuesta que obtuve:</p>
<blockquote><p>Hi,</p>
<p>We do not have a model No. FI8901W camera, could you please double check the model No.?</p></blockquote>
<p>Es decir, que no saben ni los modelos que han fabricado. Le dije que <a href="http://www.ipcam-store.com/fi8901w.html" target="_blank">si existía</a> ese modelo de cámara en su marca y me contesto esto otro:</p>
<blockquote><p>Hi,</p>
<p>Sorry for my mistake. We have stopped produce this product for a long time. We do not have the firmware now. Sorry for this.</p></blockquote>
<p>Vamos que no querían ayudarme en nada (David, que suerte tuviste&#8230;).</p>
<p>Buscando por Internet unos ficheros de recupercación para la zaapa o para la FOSCAM FI8901W no encontré nada. Pero por suerte encontré <a href="http://www.openipcam.com/forum/index.php/topic,39.0.html" target="_blank">esto otro</a>. Una forma de extraer de una cámara que funcionase su firmware a través de la consola serie oculta. El proceso fue pesado: me tuve que bajar el kermit 95 y buscar cómo demonios abrir una consola serie, después esperé un rato largo a que se ejecutara el script, convertir con el jedit una salida en otro fichero y finalmente pasar el convertidor de hexadecimal a binario, el cual tuve que compilar, modificar y compilar de nuevo para que funcionase. Todo esto para que al final no se hubiera decargado correctamente el firmware <em>linux.bin</em> y <em>romfs.img</em> necesarios para reprogramar la cámara estropeada, dando esta errores nada más arrancar.</p>
<p>Parecía que no iba a dar con la solución, pero <a href="http://blog.morrison.nl/2011/01/foscam-clone-recovery-tool/" target="_blank">encontré</a> un <a href="http://www.openipcam.com/files/FoscamCloneRecovery.zip" target="_blank">programa</a> que te descargaba automáticamente los ficheros necesarios del firmware. Lo ejecuté y parecía que había hecho bien su trabajo, pero pasó lo mismo que en el anterior párrafo aunque esta vez sólo con el fichero <em>linux.bin</em>. Sin embargo gracias a esta <a href="http://www.computersolutions.cn/blog/2010/04/ip-cam-hacking-pt4/" target="_blank">otra página</a> descubro que el fichero linux.bin es en realidad un archivo .zip y que lo que había hecho está aplicación es comerse los últimos 168 bytes, asi que leyendo la memoria de  la cámara que funcionaba recuperé esos 168 bytes.</p>
<p>Finalmente seguí <a href="http://www.gadgetvictims.com/2009/12/bring-your-fi8908w-paperweight-back-to.html" target="_blank">paso por paso el proceso de nuevo</a> pero cambiando los comandos fx por estos:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">fx <span style="color: #000000;">6</span> romfs.img 0x7F0D0000 0x7F0D0000 <span style="color: #660033;">-a</span>
fx <span style="color: #000000;">7</span> linux.bin 0x7F020000 0x00008000 <span style="color: #660033;">-acxz</span></pre></div></div>

<p>Para Windows 7 como no existe el Hyperterminal, he usado el <a href="http://ttssh2.sourceforge.jp/" target="_blank">Tera Term</a>.</p>
<p>Finalmente la cámara de mi amigo ha dejado de ser un pisapapeles y ha vuelto a funcionar, pudiéndola manejar ahora con Firefox, con su IPhone, etc.</p>
<p>Para evitaros las incomodidades por las que yo he pasado os dejo los enlaces de los ficheros de recuperación de la versión que le instalé a mi amigo y que es la última que proporciona Zaapa:</p>
<p><a href="http://www.sistemasorp.es/blog/romfs.img" target="_blank">romfs.img</a></p>
<p><a href="http://www.sistemasorp.es/blog/linux.bin" target="_blank">linux.bin</a></p>
<p><a href="http://www.sistemasorp.es/blog/Embeded Web UI 2.0.0.16.bin" target="_blank">Embeded Web UI 2.0.0.16.bin</a></p>
<p>&nbsp;</p>

<p><a href="http://feedads.g.doubleclick.net/~a/wqZSuXFJ83oLnbiKdOM57vuZzxg/0/da"><img src="http://feedads.g.doubleclick.net/~a/wqZSuXFJ83oLnbiKdOM57vuZzxg/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/wqZSuXFJ83oLnbiKdOM57vuZzxg/1/da"><img src="http://feedads.g.doubleclick.net/~a/wqZSuXFJ83oLnbiKdOM57vuZzxg/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/sistemasorp/~4/0O-ckqX0bBs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.sistemasorp.es/2012/02/02/recuperar-una-camara-zaapa-cip-rw-despues-de-un-fallo-de-actualizacion/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		<feedburner:origLink>http://www.sistemasorp.es/2012/02/02/recuperar-una-camara-zaapa-cip-rw-despues-de-un-fallo-de-actualizacion/</feedburner:origLink></item>
		<item>
		<title>Probando el marco digital Parrot DF3120 (parte 2)</title>
		<link>http://feedproxy.google.com/~r/sistemasorp/~3/NdR9gZ8SZRc/</link>
		<comments>http://www.sistemasorp.es/2012/01/22/probando-el-marco-digital-parrot-df3120-parte-2/#comments</comments>
		<pubDate>Sun, 22 Jan 2012 15:19:04 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Proyectos]]></category>

		<guid isPermaLink="false">http://www.sistemasorp.es/?p=514</guid>
		<description><![CDATA[En el anterior artículo explicaba cómo instalar linux en el marco digital Parrot DF3120. En este explicaré cómo generar el toolchain para poder crear programas que funcionen en el marco digital. De paso crearemos una versión de la imagen más moderna para nuestro marco. El artículo original que lo explicaba es este, pero está desfasado [...]]]></description>
			<content:encoded><![CDATA[<p>En el <a href="http://www.sistemasorp.es/2012/01/19/probando-el-marco-digital-parrot-df3120-parte-1/" target="_blank">anterior artículo</a> explicaba cómo instalar linux en el marco digital Parrot DF3120. En este explicaré cómo generar el <a href="http://es.wikipedia.org/wiki/Cadena_de_herramientas" target="_blank">toolchain</a> para poder crear programas que funcionen en el marco digital. De paso crearemos una versión de la imagen más moderna para nuestro marco. El artículo original que lo explicaba es <a href="https://sites.google.com/site/repurposelinux/df3120/install_minifs" target="_blank">este</a>, pero está desfasado y hay que hacer retoques para que funcione bien.</p>
<p>Lo voy a hacer todo desde mi linux Ubuntu 11.10, por lo que es posible que algunas cosas haya que modificarlas si usáis otra distribución.</p>
<p>Lo primero es instalarse usa serie de paquetes que son necesarios para que todo el proceso sea correcto:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> git-core
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> tig
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> lzop
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> uboot-mkimage
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> libelf-dev
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> libncurses-dev
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> gtk-doc-tools
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> checkinstall
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> e2fsprogs
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> libglib2.0-dev
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> libxml2-dev
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> genext2fs
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> lzma
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> subversion
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #c20cb9; font-weight: bold;">cvs</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #c20cb9; font-weight: bold;">gawk</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #c20cb9; font-weight: bold;">bison</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #c20cb9; font-weight: bold;">flex</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #c20cb9; font-weight: bold;">automake</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #c20cb9; font-weight: bold;">gcc</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> build-essential
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> texinfo
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> curl</pre></div></div>

<p>Después hay que bajarse minifs con el git:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git</span> clone http:<span style="color: #000000; font-weight: bold;">//</span>oomz.net<span style="color: #000000; font-weight: bold;">/</span>git<span style="color: #000000; font-weight: bold;">/</span>minifs.git minifs</pre></div></div>

<p>A continuación hay que hacer un par de modificaciones:</p>
<ul>
<li>Edita el fichero <em>minifs/conf/board/df3120/config_busybox.conf</em> y reemplaza la línea <strong># CONFIG_CHMOD is not set</strong> por <strong>CONFIG_CHMOD=y</strong></li>
<li>Edita el fichero <em>minifs/conf/packages/05crosstools.sh</em> y reemplaza la línea <strong>hset libtool url &#8220;http://ftp.gnu.org/gnu/libtool/libtool-2.4.2.tar.gz&#8221;</strong> por <strong>hset libtool url &#8220;http://ftp.gnu.org/gnu/libtool/libtool-2.4.tar.gz&#8221;</strong></li>
<li>Edita el fichero <em>minifs/conf/packages/11graphical.sh</em> y reemplaza la línea <strong>hset libpng url &#8220;ftp://ftp.simplesystems.org/pub/libpng/png/src/libpng-1.4.8.tar.bz2&#8243;</strong> por <strong>hset libpng url &#8220;ftp://ftp.simplesystems.org/pub/libpng/png/src/libpng-1.4.9.tar.bz2&#8243;</strong></li>
</ul>
<p>Después ya podemos ejecutar el script de la siguiente forma (Puede tardar varios minutos):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> minifs
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">MINIFS_BOARD</span>=df3120
.<span style="color: #000000; font-weight: bold;">/</span>minifs_build.sh</pre></div></div>

<p>Ahora vemos que entre otras cosas se han creado dos ficheros en el directorio <em>build-df3120</em>, un .img y un .plt. Pues bien con ellos hay que volver a hacer lo mismo que comentaba en el <a href="http://www.sistemasorp.es/2012/01/19/probando-el-marco-digital-parrot-df3120-parte-1/" target="_blank">anterior artículo</a>. Si todo ha ido bien veremos la nueva versión del firmware donde lo más destacado es que aparecen los mensajes de arranque:</p>
<p><a href="http://www.sistemasorp.es/wp-content/uploads/2012/01/IMGP2486.jpg"><img class="aligncenter size-medium wp-image-517" title="nuevo firmware" src="http://www.sistemasorp.es/wp-content/uploads/2012/01/IMGP2486-300x225.jpg" alt="" width="300" height="225" /></a></p>
<p>Ahora vamos a compilar nuestro primer programa, y cómo no, tenía que ser un Hola Mundo:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &lt;stdio.h&gt;</span>
&nbsp;
<span style="color: #993333;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
 <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Hola Mundo.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Copiamos el código que aparece arriba y lo guardamos en un fichero llamado <em>holamundo.c</em>. Después ejecutamos el siguiente comando:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">toolchain<span style="color: #000000; font-weight: bold;">/</span>arm-v4t-linux-uclibcgnueabi<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>arm-v4t-linux-uclibcgnueabi-gcc holamundo.c <span style="color: #660033;">-o</span> holamundo</pre></div></div>

<p>Esto habrá generado un fichero ejecutable llamado <em>holamundo</em>, pero ¿cómo lo subimos al marco para ejecutarlo?. Pues bien entre otros comandos el marco tiene dos, el <em>tftp</em> y <em>wget</em> para descargar ficheros mediante el protocolo tftp y http respectivamente, por tanto hay que instalar un servidor web o tftpd en nuestra máquina linux.</p>
<p>Servidor web apache:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> apache2</pre></div></div>

<p>Servidor tftp: <a href="http://www.davidsudjiman.info/2006/03/27/installing-and-setting-tftpd-in-ubuntu/" target="_blank">Instrucciones</a></p>
<p>Si hemos optado por el servidor web sólo hay que copiar el fichero <em>holamundo</em> al directorio <em>/var/www</em>. Si la elección ha sido tftpd entonces hay que copiar el fichero <em>holamundo</em> al directorio que se haya configurado.</p>
<p>Ahora tenemos que descargarlo desde el marco digital. Hacemos un telnet como explicaba en el anterior artículo. En el firmware actual todo el disco está montado como sólo lectura, por lo que tendremos que remontarlo como escritura también de la siguiente forma:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">mount</span> <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #660033;">-o</span> remount,rw</pre></div></div>

<p>Ahora nos vamos al directorio <em>/tmp</em> y descargamos el programa.</p>
<p>Para tftp el comando sería:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">tftp <span style="color: #660033;">-g</span> <span style="color: #660033;">-r</span> holamundo <span style="color: #000000; font-weight: bold;">&lt;</span>IP DEL SERVIDOR TFTP<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>Para wget el comando sería:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//&lt;</span>IP DEL SERVIDOR WEB<span style="color: #000000; font-weight: bold;">&gt;/</span>holamundo</pre></div></div>

<p>Ahora que tenemos el fichero, hay que darle permisos de ejecución y finalmente ejecutarlo:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">chmod</span> a+x holamundo
.<span style="color: #000000; font-weight: bold;">/</span>holamundo</pre></div></div>

<p>Obtendremos esto:</p>
<p><a href="http://www.sistemasorp.es/wp-content/uploads/2012/01/holamundo.png"><img class="aligncenter size-medium wp-image-519" title="holamundo" src="http://www.sistemasorp.es/wp-content/uploads/2012/01/holamundo-300x192.png" alt="" width="300" height="192" /></a></p>
<p>Ya hemos compilado nuestro primer programa y lo hemos hecho funcionar, pero claro, nos interesa que se pueda dibujar en la pantalla algo para ver cómo se ve en el marco. Lo primero que hay que saber es que la pantalla tiene asignado el dispositivo <em>/dev/fb0</em> y que lo que tenemos que conseguir es acceder a su memoria para escribir directamente los colores. Esto se consigue de la siguiente forma:</p>
<p>Con la función <strong>open</strong> abrimos el dispositivo como lectura/escritura:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">int</span> g_fb <span style="color: #339933;">=</span> open<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;/dev/fb0&quot;</span><span style="color: #339933;">,</span> O_RDWR<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Con la función <strong>ioctl</strong> recibimos en una estructura información sobre la pantalla:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">struct</span> fb_var_screeninfo var_info<span style="color: #339933;">;</span>
ioctl<span style="color: #009900;">&#40;</span>g_fb<span style="color: #339933;">,</span> FBIOGET_VSCREENINFO<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>var_info<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Con la función <strong>mmap</strong> obtenemos el buffer de la memoria de vídeo para leerlo y escribir en el:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">char</span> <span style="color: #339933;">*</span>buffer <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>mmap<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">153600</span><span style="color: #339933;">,</span> PROT_READ<span style="color: #339933;">|</span>PROT_WRITE<span style="color: #339933;">,</span> MAP_SHARED<span style="color: #339933;">,</span> g_fb<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Ahora sólo queda dibujar los bytes en la memoria para que se vean reflejados como pixeles en la pantalla. Al poder representar la pantalla 64k colores estos se codifican a RGB mediante 16 bit con el formato 5-6-5 (rrrrrggggggbbbbb). Así el rojo es 1111100000000000 (0xF800), el verde es 0000011111100000 (0x07E0) y el azul es 0000000000011111 (0x001F). Por tanto cada pixel en la pantalla ocupa 16 bits.</p>
<p>Para probar todo esto he creado un programa que muestra un cuadro verde rebotando por el marco usando la técnica de <a href="http://es.wikipedia.org/wiki/Buffer_m%C3%BAltiple#En_gr.C3.A1ficos_por_ordenador" target="_blank">doble buffer</a> para evitar parpadeos:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &lt;unistd.h&gt;</span>
<span style="color: #339933;">#include &lt;stdio.h&gt;</span>
<span style="color: #339933;">#include &lt;stdlib.h&gt;</span>
<span style="color: #339933;">#include &lt;string.h&gt;</span>
<span style="color: #339933;">#include &lt;fcntl.h&gt;</span>
<span style="color: #339933;">#include &lt;linux/fb.h&gt;</span>
<span style="color: #339933;">#include &lt;sys/mman.h&gt;</span>
<span style="color: #339933;">#include &lt;sys/ioctl.h&gt;</span>
&nbsp;
&nbsp;
<span style="color: #993333;">char</span> <span style="color: #339933;">*</span>inicializa<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> <span style="color: #339933;">*</span>cuantos<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #993333;">char</span><span style="color: #339933;">*</span> buffer<span style="color: #339933;">;</span>
  <span style="color: #993333;">int</span> g_fb<span style="color: #339933;">;</span>
  <span style="color: #993333;">struct</span> fb_var_screeninfo var_info<span style="color: #339933;">;</span>
&nbsp;
  g_fb <span style="color: #339933;">=</span> open<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;/dev/fb0&quot;</span><span style="color: #339933;">,</span> O_RDWR<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>g_fb <span style="color: #339933;">==</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;No se puede abrir /dev/fb0<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    _exit<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;/dev/fb0 abierto con el handle 0x%x<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span><span style="color: #009900;">&#41;</span>g_fb<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>ioctl<span style="color: #009900;">&#40;</span>g_fb<span style="color: #339933;">,</span> FBIOGET_VSCREENINFO<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>var_info<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;No se puede obtener la información variable de la pantalla<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    _exit<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;xres: %d<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> var_info.<span style="color: #202020;">xres</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;yres: %d<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> var_info.<span style="color: #202020;">yres</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;bpp: %d<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> var_info.<span style="color: #202020;">bits_per_pixel</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #339933;">*</span>cuantos <span style="color: #339933;">=</span> var_info.<span style="color: #202020;">xres</span> <span style="color: #339933;">*</span> var_info.<span style="color: #202020;">yres</span> <span style="color: #339933;">*</span> var_info.<span style="color: #202020;">bits_per_pixel</span> <span style="color: #339933;">/</span><span style="color: #0000dd;">8</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;El tamaño del buffer de pantalla es de %d bytes<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #339933;">*</span>cuantos<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  buffer <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>mmap<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #339933;">*</span>cuantos<span style="color: #339933;">,</span> PROT_READ<span style="color: #339933;">|</span>PROT_WRITE<span style="color: #339933;">,</span> MAP_SHARED<span style="color: #339933;">,</span> g_fb<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span>buffer <span style="color: #339933;">==</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> 
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;falló mmap().<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
    exit<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Pantalla devuelta<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">return</span> buffer<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> cuadro<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> x<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> y<span style="color: #339933;">,</span> <span style="color: #993333;">short</span> <span style="color: #993333;">int</span> <span style="color: #339933;">*</span>buffer<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> color<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
 <span style="color: #993333;">int</span> anchura<span style="color: #339933;">;</span>
 <span style="color: #993333;">int</span> altura<span style="color: #339933;">;</span>
 <span style="color: #993333;">short</span> <span style="color: #993333;">int</span> <span style="color: #339933;">*</span>puntero<span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>altura <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> altura <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">50</span><span style="color: #339933;">;</span> altura<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
  puntero <span style="color: #339933;">=</span> buffer <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>y <span style="color: #339933;">+</span> altura<span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #0000dd;">320</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>anchura <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> anchura <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">50</span><span style="color: #339933;">;</span> anchura<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
   <span style="color: #339933;">*</span><span style="color: #009900;">&#40;</span>puntero <span style="color: #339933;">+</span> x <span style="color: #339933;">+</span> anchura<span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> color<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
 <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
 <span style="color: #993333;">int</span> indice<span style="color: #339933;">;</span>
 <span style="color: #993333;">int</span> cuantos<span style="color: #339933;">;</span>
 <span style="color: #993333;">int</span> x <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
 <span style="color: #993333;">int</span> y <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
 <span style="color: #993333;">int</span> suma_x <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
 <span style="color: #993333;">int</span> suma_y <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #993333;">short</span> <span style="color: #993333;">int</span> <span style="color: #339933;">*</span>buffer <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">short</span> <span style="color: #993333;">int</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>inicializa<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>cuantos<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #993333;">short</span> <span style="color: #993333;">int</span> <span style="color: #339933;">*</span>ventana <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">short</span> <span style="color: #993333;">int</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>malloc<span style="color: #009900;">&#40;</span>cuantos<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>ventana <span style="color: #339933;">==</span> NULL<span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
  <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;No se puede crear el doble buffer<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  _exit<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
 <span style="color: #666666; font-style: italic;">// fondo negro</span>
 <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>indice <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> indice <span style="color: #339933;">&lt;</span> <span style="color: #009900;">&#40;</span>cuantos <span style="color: #339933;">/</span> <span style="color: #0000dd;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> indice<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
  buffer<span style="color: #009900;">&#91;</span>indice<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> 
 <span style="color: #009900;">&#125;</span>
&nbsp;
 <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">;;</span><span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
  usleep<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">10000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  cuadro<span style="color: #009900;">&#40;</span>x<span style="color: #339933;">,</span> y<span style="color: #339933;">,</span> ventana<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  x <span style="color: #339933;">+=</span> suma_x<span style="color: #339933;">;</span>
  y <span style="color: #339933;">+=</span> suma_y<span style="color: #339933;">;</span>
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>x <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">269</span> <span style="color: #339933;">||</span> x <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
   suma_x <span style="color: #339933;">*=</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
   x <span style="color: #339933;">+=</span> suma_x<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>y <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">189</span> <span style="color: #339933;">||</span> y <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
   suma_y <span style="color: #339933;">*=</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
   y <span style="color: #339933;">+=</span> suma_y<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  cuadro<span style="color: #009900;">&#40;</span>x<span style="color: #339933;">,</span> y<span style="color: #339933;">,</span> ventana<span style="color: #339933;">,</span> <span style="color: #208080;">0x7E0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  memcpy<span style="color: #009900;">&#40;</span>buffer<span style="color: #339933;">,</span> ventana<span style="color: #339933;">,</span> cuantos<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Que ejecutándolo quedaría así:</p>
<p><iframe width="425" height="349" src="http://www.youtube.com/embed/7xjNjfk0Vu0?hl=en&#038;fs=1" frameborder="0" allowfullscreen></iframe></p>
<p>En un próximo artículo explicaré como acceder a la interfaz con <a href="http://www.libsdl.org/" target="_blank">SDL</a>, comunicarse con bluetooth mediante <a href="http://es.wikipedia.org/wiki/Protocolos_Bluetooth#RFCOMM" target="_blank">RFCOMM</a> y obtener los valores de los botones traseros y del inclinómetro.</p>
<p><strong>Edición 12/02/2012:</strong></p>
<p><a href="http://www.sistemasorp.es/2012/01/19/probando-el-marco-digital-parrot-df3120-parte-1/" target="_blank">1º artículo</a></p>
<p><a href="http://www.sistemasorp.es/2012/02/12/probando-el-marco-digital-parrot-df3120-parte-3-y-final/" target="_blank">3º artículo</a></p>

<p><a href="http://feedads.g.doubleclick.net/~a/a1nmtWyRS9ULM4k78JwepodP0VM/0/da"><img src="http://feedads.g.doubleclick.net/~a/a1nmtWyRS9ULM4k78JwepodP0VM/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/a1nmtWyRS9ULM4k78JwepodP0VM/1/da"><img src="http://feedads.g.doubleclick.net/~a/a1nmtWyRS9ULM4k78JwepodP0VM/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/sistemasorp/~4/NdR9gZ8SZRc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.sistemasorp.es/2012/01/22/probando-el-marco-digital-parrot-df3120-parte-2/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		<feedburner:origLink>http://www.sistemasorp.es/2012/01/22/probando-el-marco-digital-parrot-df3120-parte-2/</feedburner:origLink></item>
		<item>
		<title>Probando el marco digital Parrot DF3120 (parte 1)</title>
		<link>http://feedproxy.google.com/~r/sistemasorp/~3/bGXiPKlFmaQ/</link>
		<comments>http://www.sistemasorp.es/2012/01/19/probando-el-marco-digital-parrot-df3120-parte-1/#comments</comments>
		<pubDate>Thu, 19 Jan 2012 01:33:36 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Electrónica]]></category>
		<category><![CDATA[Proyectos]]></category>
		<category><![CDATA[Reseñas]]></category>

		<guid isPermaLink="false">http://www.sistemasorp.es/?p=486</guid>
		<description><![CDATA[He adquirido el marco digital de fotos Parrot DF3120. Es un marco que por menos de 20€ puede representar fotografías en una pantalla de 320&#215;240 (3.5&#8243;). Sus puntos fuertes es que tiene bluetooth para poder subir las imagenes desde, por ejemplo, un móvil y una entrada para tarjetas SD con la misma función. Este marco [...]]]></description>
			<content:encoded><![CDATA[<p>He adquirido el marco digital de fotos <a href="http://www.parrot.com/usa/products/digitalphotoframes/parrotdf3120" target="_blank">Parrot DF3120</a>. Es un marco que <a href="http://www.ebay.es/itm/Parrot-DF3120-3-5-Wireless-Bluetooth-High-Res-Compact-Digital-Photo-Frame-/170711947116?pt=UK_Photography_DigitalCamAccess_RL&amp;hash=item27bf39976c" target="_blank">por menos de 20€</a> puede representar fotografías en una pantalla de 320&#215;240 (3.5&#8243;). Sus puntos fuertes es que tiene bluetooth para poder subir las imagenes desde, por ejemplo, un móvil y una entrada para tarjetas SD con la misma función.</p>
<p><a href="http://www.sistemasorp.es/wp-content/uploads/2012/01/IMAG0107.jpg"><img class="aligncenter size-medium wp-image-490" title="Parrot DF3120" src="http://www.sistemasorp.es/wp-content/uploads/2012/01/IMAG0107-300x200.jpg" alt="" width="300" height="200" /></a></p>
<p>Este marco <a href="https://sites.google.com/site/repurposelinux/df3120" target="_blank">ha sido hackeado</a> y se le puede instalar un linux, con las ventajas que ello representa. El objetivo de este primer artículo es mostrar el proceso de instalación de linux y cómo acceder a este de una forma sencilla.</p>
<p>Lo primero es hacer un duplicado de disco del siguiente fichero: <a href="http://www.sistemasorp.es/blog/minifs-full-ext.img">minifs-full-ext.img</a>. Esto en linux, siendo root, se consigue con el siguiente comando (disco SD es el nombre que le haya asignado el sistema):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">dd</span> <span style="color: #007800;">if</span>=minifs-full-ext.img <span style="color: #007800;">of</span>=<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/&lt;</span>disco SD<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>Lo siguiente es actualizar el firmware del marco. Para ello hay que encender el marco sin ninguna tarjeta SD insertada y enchufar el cable usb. Cuando podamos acceder al contenido del disco, crear una carpeta llamada <strong>update</strong> y dentro de esta copiar el fichero <a href="http://www.sistemasorp.es/blog/parrotDF3120.plf">parrotDF3120.plf</a>. Después sacar el usb de forma segura y veremos que aparecen 4 cuadros en la pantalla (uno azul y el resto verde), momento en el cual ya se ha actualizado el firmware.</p>
<p><a href="http://www.sistemasorp.es/wp-content/uploads/2012/01/IMAG0108.jpg"><img class="aligncenter size-medium wp-image-493" title="Parrot USB" src="http://www.sistemasorp.es/wp-content/uploads/2012/01/IMAG0108-e1326932968101-300x200.jpg" alt="" width="300" height="200" /></a></p>
<p>Ahora tenemos un modo de arranque dual. Por un lado si encendemos el marco sin más veremos su funcionalidad de siempre, es decir, se visualizarán las imágenes que tengamos almacenadas una detrás de otra. Pero si metemos la tarjeta SD y antes de encenderlo pulsamos los botones izquierdo y central de la parte de atrás y, sin soltarlos, encendemos el marco, se arrancará  linux y <a href="http://busybox.net/" target="_blank">busybox</a>.</p>
<p>Finalmente para acceder a la consola en el modo linux podemos hacerlo de dos formas (la dificil y la fácil):</p>
<p>La dificil es sacar todos los tornillos para quedarnos con la placa y la pantalla. A continuación soldamos en los agujeros del J4 (la consola serie) los tres pines (1: GND, 2: RX, 3: TX) y nos buscamos un conversor TTL a puerto serie o <a href="http://www.dealextreme.com/p/usb-to-uart-5-pin-cp2102-module-serial-converter-81872" target="_blank">a usb</a> para poder comunicarnos con el dispositivo usando los siguientes parámetros de conexión: 115200 8,N,1 (recomiendo <em>screen</em> en linux o mac y <em>putty</em> en windows). Esta es la consola serie donde se ven los mensajes de estado del arranque y luego se obtiene una shell donde interactuar con linux:</p>
<p><a href="http://www.sistemasorp.es/wp-content/uploads/2012/01/IMGP2485.jpg"><img class="aligncenter size-medium wp-image-494" title="Parrot desarmado" src="http://www.sistemasorp.es/wp-content/uploads/2012/01/IMGP2485-300x225.jpg" alt="" width="300" height="225" /></a></p>
<p><a href="http://www.sistemasorp.es/wp-content/uploads/2012/01/consola-serie.png"><img class="aligncenter size-medium wp-image-499" title="consola serie" src="http://www.sistemasorp.es/wp-content/uploads/2012/01/consola-serie-274x300.png" alt="" width="274" height="300" /></a></p>
<p>La fácil es simplemente conectar el cable usb al marco y a nuestro ordenador, lo que nos configurará una conexión ethernet por usb llamada <em>Ethernet Gadget</em>, la cual será una tarjeta de red que debemos configurar con la IP 172.16.61.2 y la máscara de red 255.255.255.0. Si todo ha ido bien y hacemos un ping a la dirección 172.16.61.1 el marco nos debería responder. Finalmente para acceder a una shell sólo hay que hacer un telnet a la IP comentada.</p>
<p><a href="http://www.sistemasorp.es/wp-content/uploads/2012/01/telnet.png"><img class="aligncenter size-medium wp-image-498" title="telnet" src="http://www.sistemasorp.es/wp-content/uploads/2012/01/telnet-274x300.png" alt="" width="274" height="300" /></a></p>
<p><strong>Edición 22/01/2011:</strong><br />
En el marco vienen unos programas para probar la pantalla gráfica. Podeis ejecutar cualquiera de ellos:<br />
<em>/usr/bin/plasma</em>: Una bonita demo sobre el efecto plasma.<br />
<em>/usr/bin/newvox</em>: Un paisaje que si tuvieramos teclado podríamos recorrerlo.</p>
<p><strong>Edición 12/02/2011:</strong></p>
<p><a href="http://www.sistemasorp.es/2012/01/22/probando-el-marco-digital-parrot-df3120-parte-2/" target="_blank">2º artículo</a></p>
<p><a href="http://www.sistemasorp.es/2012/02/12/probando-el-marco-digital-parrot-df3120-parte-3-y-final/" target="_blank">3º artículo</a></p>

<p><a href="http://feedads.g.doubleclick.net/~a/g_6gjTbZhjngetClOZnjqM7Xbk4/0/da"><img src="http://feedads.g.doubleclick.net/~a/g_6gjTbZhjngetClOZnjqM7Xbk4/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/g_6gjTbZhjngetClOZnjqM7Xbk4/1/da"><img src="http://feedads.g.doubleclick.net/~a/g_6gjTbZhjngetClOZnjqM7Xbk4/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/sistemasorp/~4/bGXiPKlFmaQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.sistemasorp.es/2012/01/19/probando-el-marco-digital-parrot-df3120-parte-1/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		<feedburner:origLink>http://www.sistemasorp.es/2012/01/19/probando-el-marco-digital-parrot-df3120-parte-1/</feedburner:origLink></item>
		<item>
		<title>Por fin se puede programar la cámara IP Zaapa CIPRW (ZA-CIPRW) fácilmente</title>
		<link>http://feedproxy.google.com/~r/sistemasorp/~3/JrZ54kZ15ao/</link>
		<comments>http://www.sistemasorp.es/2012/01/17/por-fin-se-puede-programar-la-camara-ip-zaapa-ciprw-za-ciprw-facilmente/#comments</comments>
		<pubDate>Mon, 16 Jan 2012 23:46:30 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Informática]]></category>
		<category><![CDATA[Proyectos]]></category>
		<category><![CDATA[Reseñas]]></category>

		<guid isPermaLink="false">http://www.sistemasorp.es/?p=478</guid>
		<description><![CDATA[Hacía tiempo que no volvía a escribir sobre la cámara ip Zaapa CIPRW. Escribí dos artículos: Uno sobre la descripción de la cámara en septiembre de 2008 y otro sobre cómo programarla en .NET en Agosto de 2009. Lo cierto es que desde entonces dejé abandonado el tema y por necesidades he tenido que retomarlo [...]]]></description>
			<content:encoded><![CDATA[<p>Hacía tiempo que no volvía a escribir sobre la cámara ip Zaapa CIPRW. Escribí dos artículos: Uno sobre <a href="http://www.sistemasorp.es/2008/09/14/zaapa-ciprw-za-ciprw/" target="_blank">la descripción de la cámara</a> en septiembre de 2008 y otro sobre <a href="http://www.sistemasorp.es/2009/08/12/programar-la-camara-ip-zaapa-ciprw-za-ciprw-en-net/" target="_blank">cómo programarla en .NET</a> en Agosto de 2009.</p>
<p>Lo cierto es que desde entonces dejé abandonado el tema y por necesidades he tenido que retomarlo para poder interactuar con ella. Poco tiempo después de escribir el último artículo se publicó en la página de Gadget Victims <a href="http://www.gadgetvictims.com/2009/09/yet-another-firmware-for-foscam-fi8908w.html" target="_blank">información sobre un nuevo firmware para las cámaras Foscam FI908W</a> (La de Zaapa es la FI8901W) en septiembre de 2009 donde entre otras cosas se habla de la documentación oficial de <a href="http://www.foscam.es/" target="_blank">FOSCAM</a> para sus cámaras IP. Lo mejor de esto es que en esta documentación hay dos textos que pueden servirnos a los programadores para interactuar definitivamente con la cámara Zaapa y a los usuarios para poder ver sus cámaras en navegadores como Firefox, Chrome, Safari, etc.</p>
<p>Se trata del <a href="http://www.sistemasorp.es/blog/IPCAMCGISDKV2.1.pdf" target="_blank">IPCAM CGI SDK 2.1</a> y del <a href="http://www.sistemasorp.es/blog/IPCameraProtocol.doc" target="_blank">IPCAM Protocol</a>. El primero es un documento PDF donde se explica cómo haciendo peticiones HTTP se puede descargar la imagen de la cámara y enviar ordenes a esta. El segundo es un documento de Word donde se explica el protocolo de la cámara para comunicarse con ella mediante socket. En este artículo me centraré en el primero por su facilidad de uso.</p>
<p>En el primer documento se explica qué peticiones hay que hacer para interactuar con la cámara. Se trata de acceder a páginas web <a href="http://es.wikipedia.org/wiki/Interfaz_de_entrada_com%C3%BAn" target="_blank">CGI</a> pasándole normalmente los parámetros mediante el método <a href="http://es.wikipedia.org/wiki/Hypertext_Transfer_Protocol#M.C3.A9todos_de_petici.C3.B3n" target="_blank">GET</a>, que es como en realidad nosotros hacemos las llamadas desde un navegador web normalmente.</p>
<p>Antes de empezar a probar hay que cerciorarse de que la cámara Zaapa tiene el último firmware y el último Embeded Web UI. Si en la sección <em>Device Info</em> del panel del administrador son distintos de <em>11.4.1.40</em> y <em>2.0.0.16</em> respectivamente, hay que actualizar. En la <a href="http://www.zaapa.co.uk/Public/ficha_producto.asp?CPRO=761" target="_blank">página del producto</a> se pueden descargar pero hay que introducir el número de serie que aparece como código de barras en la parte inferior de la cámara. Una vez que empieza la descarga empieza lo gracioso y es que veremos algo raro en el fichero que descargamos pues no tiene extensión y que no sirve para actualizar ya que no es un <em>.bin</em>. Pues bien el fichero es un archivo .rar por lo que hay que renombrarlo, ponerle esa extensión y ya podemos abrirlo. Dentro de este veremos dos ficheros .bin y aquí esta lo segundo más gracioso ¡¡¡ están al revés !!! <em>Embeded Web UI 11.4.1.40.bin</em> tendría que ser <em>Firmware 11.4.1.40.bin </em>y<em> Firmware 2.0.0.16.bin</em> tendría que ser <em>Embeded Web UI</em> <em>2.0.0.16.bin</em>. Una vez arreglado ese desaguisado ya podemos actualizarlo desde la sección <em><span style="font-family: Arial;">Upgrade Device Firmware</span></em> del panel de administrador y actualizar el firmware primero y el Web UI después (en ambos casos se reinicia la cámara).</p>
<p>Hay unos cuantos CGI y lo mejor es leerse la documentación, pero voy a explicar 3 de ellos que me parecen fundamentales:</p>
<ul>
<ul>
<li>El primero de ellos es el <em>snapshot.cgi</em>. Sirve para capturar una imagen estática de la cámara. Si ponemos en un navegador web <strong>http://ip de la cámara/snapshot.cgi</strong> nos pedirá un usuario y una contraseña. Cuando la hayamos introducido veremos la imagen jpg. Podemos evitar que salga el recuadro que nos pide el usuario y la contraseña simplemente añadiendo los parámetros <em>user</em> y <em>pwd</em> a la url de la siguiente forma <strong>http://ip de la cámara/snapshot.cgi?user=usuario&amp;pwd=contraseña</strong> para que ya directamente nos muestre la imagen. Tiene otro parámetro llamado <em>next_url</em> para indicar el nombre del fichero pero no lo veo útil.</li>
<li>El segundo de ellos son en realidad dos: <em>videostream.cgi</em> y <em>videostream.asf</em>. Sirven para mostrar un flujo continuo de imagenes a modo de vídeo. El que tiene extensión .cgi envía imágenes jpg sucesivas (ideal para verlas con una navegador), el que tiene extensión asf envía las imágenes con el formato <a href="http://es.wikipedia.org/wiki/Advanced_Streaming_Format" target="_blank">Advanced Streaming Format</a> (ideal para verlas con el VLC o con el MPlayer). Si ponemos en un navegador web <strong></strong><strong>http://ip de la cámara/videostream.cgi?user=usuario&amp;pwd=contraseña</strong> podemos ver el flujo continuo de lo que la cámara está enfocando en ese momento. Tiene otro parámetro llamado <em>resolution</em> para indicar con un 8 o un 32 si queremos que la imagen tenga de tamaño 320&#215;240 o 640&#215;480 respectivamente.</li>
<li>El tecero de ellos es el <em>decoder_control.cgi</em>. Sirve para interactuar con la cámara. Si ponemos en el navegador web <strong></strong><strong>http://ip de la cámara/videostream.cgi?user=usuario&amp;pwd=contraseña&amp;command=comando</strong> donde comando sea un número que indica qué hacer a la cámara (0 = empezar a mover hacia arriba, 1 = parar de mover hacia arriba, 2 = empezar a mover hacia abajo, etc) veremos como se mueve esta.</li>
</ul>
</ul>
<p>Finalmente he creado una página HTML para probar los dos últimos CGIs que he explicado. La página muestra la sucesión de imágenes de la cámara y tiene unos botones que permiten mover la cámara. Para adecuarlo a la vuestra sólo teneis que cambiar en la sección javascript el usuario, la clave y la ruta a vuestra cámara:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">html</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">style</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span>&gt;</span>
		.comando {background-color:#FFFF00; border-radius: 10px; font-family:Arial; font-size:10pt; font-weight:bold; width:70px; text-align:center}
		#imagen {visibility:hidden; width:640px; height:480px;}
		#marco {visibility:hidden;}
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">style</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span>
		var usuario = &quot;usuario&quot;;
		var clave = &quot;clave&quot;;
		var ruta = &quot;http://192.168.0.12/&quot;;
&nbsp;
		function cargado()
		{
			var imagen = document.getElementById(&quot;imagen&quot;);
			imagen.src = ruta + &quot;videostream.cgi?user=&quot; + usuario + &quot;<span style="color: #ddbb00;">&amp;pwd=&quot; + clave + &quot;&amp;resolution=32&quot;;</span>
			imagen.style.visibility = &quot;visible&quot;;
		}
&nbsp;
		function empieza_arriba()
		{
			var marco = document.getElementById(&quot;marco&quot;);
			marco.src = ruta + &quot;decoder_control.cgi?user=&quot; + usuario + &quot;<span style="color: #ddbb00;">&amp;pwd=&quot; + clave + &quot;&amp;command=0&quot;;</span>
		}
&nbsp;
		function termina_arriba()
		{
			var marco = document.getElementById(&quot;marco&quot;);
			marco.src = ruta + &quot;decoder_control.cgi?user=&quot; + usuario + &quot;<span style="color: #ddbb00;">&amp;pwd=&quot; + clave + &quot;&amp;command=1&quot;;</span>
		}
&nbsp;
		function empieza_abajo()
		{
			var marco = document.getElementById(&quot;marco&quot;);
			marco.src = ruta + &quot;decoder_control.cgi?user=&quot; + usuario + &quot;<span style="color: #ddbb00;">&amp;pwd=&quot; + clave + &quot;&amp;command=2&quot;;</span>
		}
&nbsp;
		function termina_abajo()
		{
			var marco = document.getElementById(&quot;marco&quot;);
			marco.src = ruta + &quot;decoder_control.cgi?user=&quot; + usuario + &quot;<span style="color: #ddbb00;">&amp;pwd=&quot; + clave + &quot;&amp;command=3&quot;;</span>
		}
&nbsp;
		function empieza_izquierda()
		{
			var marco = document.getElementById(&quot;marco&quot;);
			marco.src = ruta + &quot;decoder_control.cgi?user=&quot; + usuario + &quot;<span style="color: #ddbb00;">&amp;pwd=&quot; + clave + &quot;&amp;command=4&quot;;</span>
		}
&nbsp;
		function termina_izquierda()
		{
			var marco = document.getElementById(&quot;marco&quot;);
			marco.src = ruta + &quot;decoder_control.cgi?user=&quot; + usuario + &quot;<span style="color: #ddbb00;">&amp;pwd=&quot; + clave + &quot;&amp;command=5&quot;;</span>
		}
&nbsp;
		function empieza_derecha()
		{
			var marco = document.getElementById(&quot;marco&quot;);
			marco.src = ruta + &quot;decoder_control.cgi?user=&quot; + usuario + &quot;<span style="color: #ddbb00;">&amp;pwd=&quot; + clave + &quot;&amp;command=6&quot;;</span>
		}
&nbsp;
		function termina_derecha()
		{
			var marco = document.getElementById(&quot;marco&quot;);
			marco.src = ruta + &quot;decoder_control.cgi?user=&quot; + usuario + &quot;<span style="color: #ddbb00;">&amp;pwd=&quot; + clave + &quot;&amp;command=7&quot;;</span>
		}
&nbsp;
&nbsp;
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span> <span style="color: #000066;">onload</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cargado()&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;imagen&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">table</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span><span style="color: #ddbb00;">&amp;nbsp;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">td</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;comando&quot;</span> <span style="color: #000066;">onmousedown</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;empieza_arriba()&quot;</span> <span style="color: #000066;">onmouseup</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;termina_arriba()&quot;</span>&gt;</span>Arriba<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span><span style="color: #ddbb00;">&amp;nbsp;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">td</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;comando&quot;</span> <span style="color: #000066;">onmousedown</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;empieza_izquierda()&quot;</span> <span style="color: #000066;">onmouseup</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;termina_izquierda()&quot;</span>&gt;</span>Izquierda<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span><span style="color: #ddbb00;">&amp;nbsp;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">td</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;comando&quot;</span> <span style="color: #000066;">onmousedown</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;empieza_derecha()&quot;</span> <span style="color: #000066;">onmouseup</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;termina_derecha()&quot;</span>&gt;</span>Derecha<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span><span style="color: #ddbb00;">&amp;nbsp;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">td</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;comando&quot;</span> <span style="color: #000066;">onmousedown</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;empieza_abajo()&quot;</span> <span style="color: #000066;">onmouseup</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;termina_abajo()&quot;</span>&gt;</span>Abajo<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span><span style="color: #ddbb00;">&amp;nbsp;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">table</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">iframe</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;marco&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">iframe</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></pre></div></div>

<p>El funcionamiento es muy sencillo. Una etiqueta <em>img</em> muestra el CGI <em>videostream.cgi</em>. Las celdas de la tabla tienen los eventos <em>onmousedown</em> y <em>onmouseup</em> para detectar cuando se pulsan y cargar en el marco oculto el CGI <em>decoder_control.cgi</em> con la orden correspondiente. Así es como se ve funcionando en un MAC y Safari:</p>
<p><iframe width="420" height="315" src="http://www.youtube.com/embed/pqqLyt2Q5Us" frameborder="0" allowfullscreen></iframe></p>
<p>Y de paso pongo otro vídeo de cómo se puede usar esta cámara con un móvil con las múltiples aplicaciones que hay en android market y en app store simplemente eligiendo en estas como marca de cámara la FOSCAM:</p>
<p><iframe width="420" height="315" src="http://www.youtube.com/embed/TOsncyamTKQ" frameborder="0" allowfullscreen></iframe></p>

<p><a href="http://feedads.g.doubleclick.net/~a/qiZk7z1pK_tjUzezAtNzYfoN4Fk/0/da"><img src="http://feedads.g.doubleclick.net/~a/qiZk7z1pK_tjUzezAtNzYfoN4Fk/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/qiZk7z1pK_tjUzezAtNzYfoN4Fk/1/da"><img src="http://feedads.g.doubleclick.net/~a/qiZk7z1pK_tjUzezAtNzYfoN4Fk/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/sistemasorp/~4/JrZ54kZ15ao" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.sistemasorp.es/2012/01/17/por-fin-se-puede-programar-la-camara-ip-zaapa-ciprw-za-ciprw-facilmente/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.sistemasorp.es/2012/01/17/por-fin-se-puede-programar-la-camara-ip-zaapa-ciprw-za-ciprw-facilmente/</feedburner:origLink></item>
		<item>
		<title>Fuerza bruta en .net para resolver las cifras del concurso cifras y letras</title>
		<link>http://feedproxy.google.com/~r/sistemasorp/~3/w8FdYl3nTnY/</link>
		<comments>http://www.sistemasorp.es/2011/11/04/fuerza-bruta-en-net-para-resolver-las-cifras-del-concurso-cifras-y-letras/#comments</comments>
		<pubDate>Fri, 04 Nov 2011 11:59:10 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Informática]]></category>
		<category><![CDATA[Proyectos]]></category>

		<guid isPermaLink="false">http://www.sistemasorp.es/?p=436</guid>
		<description><![CDATA[Hacía tiempo que no me ponía a mi mismo un reto de programación y el otro día viendo en la tele el programa cifras y letras me animé a hacer una aplicación que resolviese la sección de cifras. Primero me leí las normas y luego empecé a pensar cómo resolver este tipo de problema. Buscando [...]]]></description>
			<content:encoded><![CDATA[<p>Hacía tiempo que no me ponía a mi mismo un reto de programación y el otro día viendo en la tele el programa cifras y letras me animé a hacer una aplicación que resolviese la sección de cifras. Primero me <a href="http://es.wikipedia.org/wiki/Cifras_y_letras#Cifras" target="_blank">leí las normas</a> y luego empecé a pensar cómo resolver este tipo de problema. Buscando por Internet encontré estos artículos: (<a href="http://eltamiz.com/elcedazo/2011/06/27/resolviendo-cifras-y-letras-i/" target="_blank">uno</a>, <a href="http://eltamiz.com/elcedazo/2011/07/06/resolviendo-cifras-y-letras-ii/" target="_blank">dos </a>y <a href="http://eltamiz.com/elcedazo/2011/09/05/resolviendo-%E2%80%9Ccifras-y-letras%E2%80%9D-y-iii/" target="_blank">tres</a>) donde de 30.965.760 combinaciones posibles entre los 6 números y sus cuatro operaciones se reduce a 488.642 combinaciones. Además me encontré con dos páginas que resuelven el problema on-line: <a href="http://pedroreina.net/ciflet/anarit.php" target="_blank">esta</a> y <a href="http://antoniovillena.es/2011/07/cifras-y-letras" target="_blank">esta</a> (ambas usando la técnica de <a href="http://es.wikipedia.org/wiki/Vuelta_Atr%C3%A1s" target="_blank">backtracking</a>).</p>
<p>Como mi objetivo era hacerlo mediante fuerza bruta, la técnica de backtracking me pareció lo mejor para abordar el problema. Se crea un <a href="http://es.wikipedia.org/wiki/%C3%81rbol_%28teor%C3%ADa_de_grafos%29" target="_blank">árbol</a> donde cada nodo contendrá los números con los que se operan, la operación que ha generado ese nodo y el resultado de la misma (excepto el primer nodo que sólo contiene el conjunto de números original).</p>
<p>Vamos combinando uno por uno todos los números con todas las operaciones para encontrar el resultado que buscamos. El orden de las operaciones es suma, resta, multiplicación y división. Como esto puede generar una ingente cantidad de cálculos, podemos podar (acotar) el árbol para reducir estos y el tiempo empleado. Esto se consigue eliminando aquellos casos que no deben darse: En la resta que el resultado sea 0, en la división que el divisor sea 1 o que el resto sea distinto de 0 y que en la multiplicación uno de los factores sea 1. Para evitar números negativos en la resta o que el divsor sea mayor que el dividendo ponemos primero el mayor y después el menor en la operación.</p>
<p>A medida que vamos avanzando en la profundidad del árbol, el conjunto de números con los que operar se irá reduciendo ya que cada pareja de números se convertirá en uno por la operación matemática que se les aplique, siendo esto así recursivamente hasta que sólo haya un número, momento en el cual si el resultado no coincide con el esperado, se retrocede un nodo y se continúa con las siguientes combinaciones.</p>
<p>Para entenderlo mejor un gráfico donde dado un conjunto de tres números (1, 2 y 3) debemos operar con ellos hasta que obtengamos 7 como resultado:</p>
<p><a href="http://www.sistemasorp.es/wp-content/uploads/2011/11/backtracking.png"><img class="aligncenter size-full wp-image-446" title="backtracking" src="http://www.sistemasorp.es/wp-content/uploads/2011/11/backtracking.png" alt="" width="490" height="367" /></a><a href="http://www.sistemasorp.es/wp-content/uploads/2011/11/backtracking.png"><br />
</a>En el ejemplo después de buscar varias combinaciones entre sumas y restas (puntos suspensivos en el gráfico) hemos llegado a las combinaciones de multiplicaciones. Existen tres combinaciones de multiplicaciones: <em>Op: 1 * 2</em> (que no he puesto en el gráfico por simplificarlo), <em>Op: 1 * 3</em> y <em>Op: 2 * 3</em>.</p>
<ul>
<li>En el nodo de la multiplicación de <em>1 * 3</em> el resultado (Res:) es 3 y no 7 como andamos buscando por lo que hay que seguir calculando. El conjunto de números de este nodo se ha reducido de <em>Nu: 1, 2, 3</em> a <em>Nu: 2, 3</em>.</li>
<ul>
<li>A continuación hay que crear otro nodo con la suma de los únicos números que quedan: 2 + 3, pero el resultado es 5 con lo que volvemos al nodo anterior.</li>
<li>Vamos a hacer la resta: 3-2, pero sigue sin servirnos el resultado, por tanto volvemos al nodo anterior.</li>
<li>Hacemos la multiplicación: 2 * 3, pero seguimos igual, por lo que nos vamos al nodo anterior.</li>
<li>La división se descarta porque <em>3 / 2</em> no dá como resto 0, con lo que no se crea ese nodo y se vuelve al anterior (que en este ejemplo es el principal).</li>
</ul>
<li>Continuamos con la creación del nodo de la multiplicación de <em>2 * 3</em> donde el resultado (Res:) es 6 y no 7 como andamos buscando por lo que hay que seguir calculando. El conjunto de números de este nodo se ha reducido de <em>Nu: 1, 2, 3</em> a <em>Nu: 1, 6</em>.</li>
<ul>
<li>Hay que crear otro nodo con la suma de los únicos números que quedan: 1 + 6, y como el resultado es 7, que es el que buscábamos, ya no hacemos ninguna operación más y vamos retrocediendo por todo el árbol (que os recuerdo que se ha construido mediante una función recursiva) hasta salir de la función que lo ha generado.</li>
</ul>
</ul>
<p>El nivel de profundidad de los árboles depende de la cantidad de números inicial. Si son un conjunto de 3 números la profundidad será de 3 niveles, si es de 6 pues &#8230; ya sabeis la respuesta <img src='http://www.sistemasorp.es/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Como se trata de una estructura de árbol, cada nodo debe tener un puntero al siguiente nodo para trazar un camino desde el nodo inicial hasta el nodo que contiene el resultado que buscamos (en el cual el puntero estará vacío).  Dado que hemos aplicado la técnica de backtracking los nodos que previamente hayamos calculado y no pertenezcan a ese camino desaparecerán porque no nos sirven. Finalmente mediante un bucle recorreremos todos los nodos del camino mostrando por pantalla la operación que lo ha creado hasta el nodo final. Así en el ejemplo quedaría:</p>
<pre>3 * 2 = 6
6 + 1 = 7</pre>
<p>Sin embargo en el juego de cifras y letras si no se encuentra el número exacto se puntúa el número que más se acerque a este. La problemática aquí es que con el bactracking, si no se encuentra el número exacto, el camino que se habrá generado cuando retorne la función es el de la última operación, que con toda probabilidad no será el camino hacia el número que más se aproxime al original.</p>
<p>En este caso tenemos dos posibles formas de solucionarlo:</p>
<ul>
<li>A medida que vamos generando los nodos debemos comparar el resultado con el número que buscamos, si se acerca más que el anterior valor que hayamos comparado guardamos este resultado como el número que más se aproxima al buscado. Después cuando haya salido de la función y no se haya encontrado el exacto, se vuelve a llamar a esta misma pero buscando en esta ocasión el resultado aproximado (ya que tenemos la certeza de que se puede calcular) obteniendo así el camino hasta llegar al que más se acerca.</li>
<li>El problema de la solución anterior es que tenemos que llamar dos veces a la función que genera el árbol: una para buscar el exacto y otra para buscar el aproximado. Lo ideal es ir guardando un camino alternativo hacia el número aproximado, para que, en caso de no hallar el exacto, recorrer el camino alternativo mediante un bucle para mostrar las operaciones que obtengan el número aproximado. Todo desde la misma llamada a la función. Esto provoca que también se necesite un puntero al nodo anterior.</li>
</ul>
<p>Aquí dejo el código fuente en C# que pone en práctica todo lo comentado. Se trata de una aplicación de consola donde como parámetros se le pasa todo el conjunto de números separados por espacio y como último número el resultado que se desea averiguar.</p>
<p><strong>Program.cs:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Collections.Generic</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Collections</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Text</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">namespace</span> Cifras
<span style="color: #008000;">&#123;</span>
    <span style="color: #6666cc; font-weight: bold;">class</span> Program
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">int</span> Main<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> args<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">// Ncesitamos como mínimo dos números para operar y un resultado</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>args<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span> <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">3</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                Console<span style="color: #008000;">.</span><span style="color: #0000FF;">Write</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;La sintaxis es &quot;</span> <span style="color: #008000;">+</span> <span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">AppDomain</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CurrentDomain</span><span style="color: #008000;">.</span><span style="color: #0000FF;">FriendlyName</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot; &lt;número 1&gt;...&lt;número n&gt; &lt;número buscado&gt;&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
            Console<span style="color: #008000;">.</span><span style="color: #0000FF;">Write</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Set de números: &quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            ArrayList posibilidades <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ArrayList<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #6666cc; font-weight: bold;">int</span> indice <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
            <span style="color: #008080; font-style: italic;">// Creamos el conjunto de números a partir de la línea de comandos.</span>
            <span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">;</span> indice <span style="color: #008000;">&lt;</span> args<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span> <span style="color: #008000;">-</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">;</span> indice<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                Console<span style="color: #008000;">.</span><span style="color: #0000FF;">Write</span><span style="color: #008000;">&#40;</span>args<span style="color: #008000;">&#91;</span>indice<span style="color: #008000;">&#93;</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot; &quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                posibilidades<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>Int32<span style="color: #008000;">.</span><span style="color: #0000FF;">Parse</span><span style="color: #008000;">&#40;</span>args<span style="color: #008000;">&#91;</span>indice<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
            <span style="color: #6666cc; font-weight: bold;">int</span> descubre <span style="color: #008000;">=</span> Int16<span style="color: #008000;">.</span><span style="color: #0000FF;">Parse</span><span style="color: #008000;">&#40;</span>args<span style="color: #008000;">&#91;</span>indice<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;<span style="color: #008080; font-weight: bold;">\n</span>Número buscado: &quot;</span> <span style="color: #008000;">+</span> descubre <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;<span style="color: #008080; font-weight: bold;">\n</span>&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008080; font-style: italic;">// Creamos el primer nodo del árbol.</span>
            Nodo encuentra <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Nodo<span style="color: #008000;">&#40;</span>posibilidades, descubre<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008080; font-style: italic;">// Creamos un contador</span>
            DateTime hora <span style="color: #008000;">=</span> DateTime<span style="color: #008000;">.</span><span style="color: #0000FF;">Now</span><span style="color: #008000;">;</span>
            TimeSpan tiempo<span style="color: #008000;">;</span>
            <span style="color: #008080; font-style: italic;">// Si se ha encontrado el exacto</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>encuentra<span style="color: #008000;">.</span><span style="color: #0000FF;">busca</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                tiempo <span style="color: #008000;">=</span> DateTime<span style="color: #008000;">.</span><span style="color: #0000FF;">Now</span> <span style="color: #008000;">-</span> hora<span style="color: #008000;">;</span>
                Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Se encontró el exacto.<span style="color: #008080; font-weight: bold;">\n</span>&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
            <span style="color: #008080; font-style: italic;">// En caso de no encontrarse el exacto</span>
            <span style="color: #0600FF; font-weight: bold;">else</span>
            <span style="color: #008000;">&#123;</span>
                tiempo <span style="color: #008000;">=</span> DateTime<span style="color: #008000;">.</span><span style="color: #0000FF;">Now</span> <span style="color: #008000;">-</span> hora<span style="color: #008000;">;</span>
                Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;No se ha encontrado el exacto.<span style="color: #008080; font-weight: bold;">\n</span>&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #008080; font-style: italic;">// Sustituimos el camino original por el camino del aproximado</span>
                encuentra <span style="color: #008000;">=</span> Nodo<span style="color: #008000;">.</span><span style="color: #0000FF;">Cercano</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
            Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Número de nodos calculados: &quot;</span> <span style="color: #008000;">+</span> Nodo<span style="color: #008000;">.</span><span style="color: #0000FF;">NumeroNodos</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Tiempo en calcularlo: &quot;</span> <span style="color: #008000;">+</span> tiempo<span style="color: #008000;">.</span><span style="color: #0000FF;">TotalMilliseconds</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot; ms.<span style="color: #008080; font-weight: bold;">\n</span>&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Operaciones:&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008080; font-style: italic;">// Recorremos todos los nodos del camino para mostrar las operaciones que se han ido ejecutando.</span>
            <span style="color: #0600FF; font-weight: bold;">while</span> <span style="color: #008000;">&#40;</span>encuentra<span style="color: #008000;">.</span><span style="color: #0000FF;">Hijo</span> <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                encuentra <span style="color: #008000;">=</span> encuentra<span style="color: #008000;">.</span><span style="color: #0000FF;">Hijo</span><span style="color: #008000;">;</span>
                Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span>encuentra<span style="color: #008000;">.</span><span style="color: #0000FF;">Valor1</span> <span style="color: #008000;">+</span> encuentra<span style="color: #008000;">.</span><span style="color: #0000FF;">Signo</span> <span style="color: #008000;">+</span> encuentra<span style="color: #008000;">.</span><span style="color: #0000FF;">Valor2</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;=&quot;</span> <span style="color: #008000;">+</span> encuentra<span style="color: #008000;">.</span><span style="color: #0000FF;">Resultado</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
            <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p><strong>Nodo.cs:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Collections.Generic</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Collections</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Text</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">namespace</span> Cifras
<span style="color: #008000;">&#123;</span>
    <span style="color: #6666cc; font-weight: bold;">class</span> Nodo
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">enum</span> OPERACIONES <span style="color: #008000;">&#123;</span> SUMA, RESTA, MULTIPLICACION, DIVISION <span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">int</span> buscado<span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// El número exacto que debemos encontrar.</span>
        <span style="color: #0600FF; font-weight: bold;">private</span> ArrayList numeros<span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// El conjunto de números con los que pueden operar los hijos del nodo.</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">private</span> Nodo padre<span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// El nodo padre del nodo actual.</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">private</span> Nodo hijo<span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// El nodo hijo del nodo actual.</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> Nodo Hijo
        <span style="color: #008000;">&#123;</span>
            get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> hijo<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">int</span> valor1<span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// El primer operando.</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> Valor1
        <span style="color: #008000;">&#123;</span>
            get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> valor1<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">int</span> valor2<span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// El segundo operando.</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> Valor2
        <span style="color: #008000;">&#123;</span>
            get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> valor2<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">string</span> signo<span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// El signo de la operación.</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> Signo
        <span style="color: #008000;">&#123;</span>
            get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> signo<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">int</span> resultado<span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// El resultado de la operación.</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> Resultado
        <span style="color: #008000;">&#123;</span>
            get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> resultado<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> Nodo cercano<span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// Camino donde se llega al número más aproximado al buscado.</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> Nodo Cercano
        <span style="color: #008000;">&#123;</span>
            get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> Nodo<span style="color: #008000;">.</span><span style="color: #0000FF;">cercano</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">int</span> aproximado<span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// Variable que va guardando qué número es el más aproximado.</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">int</span> numeroNodos<span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// Número total de nodos creados.</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">int</span> NumeroNodos
        <span style="color: #008000;">&#123;</span>
            get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> Nodo<span style="color: #008000;">.</span><span style="color: #0000FF;">numeroNodos</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">// Contructor para crear el primer nodo del arbol</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> Nodo<span style="color: #008000;">&#40;</span>ArrayList numeros, <span style="color: #6666cc; font-weight: bold;">int</span> buscado<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">numeros</span> <span style="color: #008000;">=</span> numeros<span style="color: #008000;">;</span>
            Nodo<span style="color: #008000;">.</span><span style="color: #0000FF;">buscado</span> <span style="color: #008000;">=</span> buscado<span style="color: #008000;">;</span>
            padre <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
            hijo <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
            Nodo<span style="color: #008000;">.</span><span style="color: #0000FF;">cercano</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
            Nodo<span style="color: #008000;">.</span><span style="color: #0000FF;">aproximado</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
            Nodo<span style="color: #008000;">.</span><span style="color: #0000FF;">numeroNodos</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">// Constructor para crear los restantes nodos del arbol.</span>
        <span style="color: #0600FF; font-weight: bold;">private</span> Nodo<span style="color: #008000;">&#40;</span>ArrayList numeros, <span style="color: #6666cc; font-weight: bold;">int</span> valor1, <span style="color: #6666cc; font-weight: bold;">int</span> valor2, <span style="color: #6666cc; font-weight: bold;">int</span> resultado, <span style="color: #6666cc; font-weight: bold;">string</span> signo, Nodo padre<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">numeros</span> <span style="color: #008000;">=</span> numeros<span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">valor1</span> <span style="color: #008000;">=</span> valor1<span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">valor2</span> <span style="color: #008000;">=</span> valor2<span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">resultado</span> <span style="color: #008000;">=</span> resultado<span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">signo</span> <span style="color: #008000;">=</span> signo<span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">padre</span> <span style="color: #008000;">=</span> padre<span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">hijo</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
            <span style="color: #008080; font-style: italic;">// Para saber cuantos nodos se han creado.</span>
            Nodo<span style="color: #008000;">.</span><span style="color: #0000FF;">numeroNodos</span><span style="color: #008000;">++;</span>
            <span style="color: #008080; font-style: italic;">// Vamos guardando el número cercano más próximo al buscado.</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Abs</span><span style="color: #008000;">&#40;</span>buscado <span style="color: #008000;">-</span> resultado<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&lt;</span> Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Abs</span><span style="color: #008000;">&#40;</span>buscado <span style="color: #008000;">-</span> aproximado<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #008080; font-style: italic;">// Creamos un camino alternativo duplicando los nodos.</span>
                <span style="color: #008080; font-style: italic;">// Esto es necesario porque en backtracking los nodos que no sirven se eliminan y necesitamos</span>
                <span style="color: #008080; font-style: italic;">// tener un camino hacia el resultado aproximado que perdure en toda la ejecución de la función.</span>
                Nodo historico <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">;</span>
                Nodo copia <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>Nodo<span style="color: #008000;">&#41;</span><span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">MemberwiseClone</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF; font-weight: bold;">while</span> <span style="color: #008000;">&#40;</span>historico<span style="color: #008000;">.</span><span style="color: #0000FF;">padre</span> <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    copia<span style="color: #008000;">.</span><span style="color: #0000FF;">padre</span> <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>Nodo<span style="color: #008000;">&#41;</span>historico<span style="color: #008000;">.</span><span style="color: #0000FF;">padre</span><span style="color: #008000;">.</span><span style="color: #0000FF;">MemberwiseClone</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                    copia<span style="color: #008000;">.</span><span style="color: #0000FF;">padre</span><span style="color: #008000;">.</span><span style="color: #0000FF;">hijo</span> <span style="color: #008000;">=</span> copia<span style="color: #008000;">;</span>
                    historico <span style="color: #008000;">=</span> historico<span style="color: #008000;">.</span><span style="color: #0000FF;">padre</span><span style="color: #008000;">;</span>
                    copia <span style="color: #008000;">=</span> copia<span style="color: #008000;">.</span><span style="color: #0000FF;">padre</span><span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
                cercano <span style="color: #008000;">=</span> copia<span style="color: #008000;">;</span>
                aproximado <span style="color: #008000;">=</span> resultado<span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">// La función principal que busca el resultado combinando el conjunto de números del nodo con las</span>
        <span style="color: #008080; font-style: italic;">// operaciones de suma, resta, multiplicación y división.</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">bool</span> busca<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">// Si el nodo actual contiene el número buscado ya no hacemos más búsquedas</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>resultado <span style="color: #008000;">==</span> buscado<span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// Vamos recorriendo cada elemento del conjunto de números operándolo con los demás.</span>
            <span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> indice1 <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> indice1 <span style="color: #008000;">&lt;</span> numeros<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span><span style="color: #008000;">;</span> indice1<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> indice2 <span style="color: #008000;">=</span> indice1 <span style="color: #008000;">+</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">;</span> indice2 <span style="color: #008000;">&lt;</span> numeros<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span><span style="color: #008000;">;</span> indice2<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>calculos<span style="color: #008000;">&#40;</span>indice1, indice2, OPERACIONES<span style="color: #008000;">.</span><span style="color: #0000FF;">SUMA</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&#41;</span>
                    <span style="color: #008000;">&#123;</span>
                        <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
                    <span style="color: #008000;">&#125;</span>
                    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>calculos<span style="color: #008000;">&#40;</span>indice1, indice2, OPERACIONES<span style="color: #008000;">.</span><span style="color: #0000FF;">RESTA</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&#41;</span>
                    <span style="color: #008000;">&#123;</span>
                        <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
                    <span style="color: #008000;">&#125;</span>
                    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>calculos<span style="color: #008000;">&#40;</span>indice1, indice2, OPERACIONES<span style="color: #008000;">.</span><span style="color: #0000FF;">MULTIPLICACION</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&#41;</span>
                    <span style="color: #008000;">&#123;</span>
                        <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
                    <span style="color: #008000;">&#125;</span>
                    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>calculos<span style="color: #008000;">&#40;</span>indice1, indice2, OPERACIONES<span style="color: #008000;">.</span><span style="color: #0000FF;">DIVISION</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&#41;</span>
                    <span style="color: #008000;">&#123;</span>
                        <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
                    <span style="color: #008000;">&#125;</span>
                <span style="color: #008000;">&#125;</span>
            <span style="color: #008000;">&#125;</span>
            <span style="color: #008080; font-style: italic;">// Si llegamos aquí es que todos los cálculos en esta rama del arbol han sido infructuosos.</span>
            <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">// Esta función crea un nuevo nodo después de operar los números. Le asigna un nuevo conjunto de números, </span>
        <span style="color: #008080; font-style: italic;">// el resultado de la operación, y los números involucrados.</span>
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">bool</span> calculos<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> indice1, <span style="color: #6666cc; font-weight: bold;">int</span> indice2, OPERACIONES operacion<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #6666cc; font-weight: bold;">int</span> resultado <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
            <span style="color: #6666cc; font-weight: bold;">string</span> signo <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;&quot;</span><span style="color: #008000;">;</span>
            <span style="color: #6666cc; font-weight: bold;">int</span> valor1 <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>numeros<span style="color: #008000;">&#91;</span>indice1<span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
            <span style="color: #6666cc; font-weight: bold;">int</span> valor2 <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>numeros<span style="color: #008000;">&#91;</span>indice2<span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// Hacemos que en la resta, división y multiplicación el primer operando sea mayor que el segundo</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>operacion <span style="color: #008000;">==</span> OPERACIONES<span style="color: #008000;">.</span><span style="color: #0000FF;">RESTA</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">||</span> <span style="color: #008000;">&#40;</span>operacion <span style="color: #008000;">==</span> OPERACIONES<span style="color: #008000;">.</span><span style="color: #0000FF;">DIVISION</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">||</span> <span style="color: #008000;">&#40;</span>operacion <span style="color: #008000;">==</span> OPERACIONES<span style="color: #008000;">.</span><span style="color: #0000FF;">MULTIPLICACION</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>valor1 <span style="color: #008000;">&lt;</span> valor2<span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    <span style="color: #6666cc; font-weight: bold;">int</span> valor3 <span style="color: #008000;">=</span> valor1<span style="color: #008000;">;</span>
                    valor1 <span style="color: #008000;">=</span> valor2<span style="color: #008000;">;</span>
                    valor2 <span style="color: #008000;">=</span> valor3<span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
            <span style="color: #008000;">&#125;</span>
            <span style="color: #008080; font-style: italic;">// Calculamos la operación con los números, haciendo la poda del arbol si es necesario.</span>
            <span style="color: #0600FF; font-weight: bold;">switch</span> <span style="color: #008000;">&#40;</span>operacion<span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">case</span> OPERACIONES<span style="color: #008000;">.</span><span style="color: #0000FF;">SUMA</span><span style="color: #008000;">:</span>
                    resultado <span style="color: #008000;">=</span> valor1 <span style="color: #008000;">+</span> valor2<span style="color: #008000;">;</span>
                    signo <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;+&quot;</span><span style="color: #008000;">;</span>
                    <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF; font-weight: bold;">case</span> OPERACIONES<span style="color: #008000;">.</span><span style="color: #0000FF;">RESTA</span><span style="color: #008000;">:</span>
                    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>valor1 <span style="color: #008000;">-</span> valor2<span style="color: #008000;">&#41;</span> <span style="color: #008000;">==</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span> <span style="color: #008080; font-style: italic;">// Un número que da cero no sirve para seguir</span>
                    <span style="color: #008000;">&#123;</span>
                        <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
                    <span style="color: #008000;">&#125;</span>
                    resultado <span style="color: #008000;">=</span> valor1 <span style="color: #008000;">-</span> valor2<span style="color: #008000;">;</span>
                    signo <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;-&quot;</span><span style="color: #008000;">;</span>
                    <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF; font-weight: bold;">case</span> OPERACIONES<span style="color: #008000;">.</span><span style="color: #0000FF;">MULTIPLICACION</span><span style="color: #008000;">:</span>
                    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>valor2 <span style="color: #008000;">==</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span> <span style="color: #008080; font-style: italic;">// Una multiplicación que por 1 da el mismo resultado no sirve</span>
                    <span style="color: #008000;">&#123;</span>
                        <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
                    <span style="color: #008000;">&#125;</span>
                    resultado <span style="color: #008000;">=</span> valor1 <span style="color: #008000;">*</span> valor2<span style="color: #008000;">;</span>
                    signo <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;*&quot;</span><span style="color: #008000;">;</span>
                    <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF; font-weight: bold;">case</span> OPERACIONES<span style="color: #008000;">.</span><span style="color: #0000FF;">DIVISION</span><span style="color: #008000;">:</span>
                    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>valor2 <span style="color: #008000;">==</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">||</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>valor1 <span style="color: #008000;">%</span> valor2<span style="color: #008000;">&#41;</span> <span style="color: #008000;">!=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008080; font-style: italic;">// Un división que por 1 da el mismo resultado o que tiene decimales no sirve</span>
                    <span style="color: #008000;">&#123;</span>
                        <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
                    <span style="color: #008000;">&#125;</span>
                    resultado <span style="color: #008000;">=</span> valor1 <span style="color: #008000;">/</span> valor2<span style="color: #008000;">;</span>
                    signo <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;/&quot;</span><span style="color: #008000;">;</span>
                    <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
            <span style="color: #008080; font-style: italic;">// Generamos el nuevo conjunto de números sobre los que operar.</span>
            ArrayList posibilidades <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ArrayList<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            posibilidades<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>resultado<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> indice <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> indice <span style="color: #008000;">&lt;</span> numeros<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span><span style="color: #008000;">;</span> indice<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #008080; font-style: italic;">// No permitimos que se incluyan los números que ya se han operado.</span>
                <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>indice <span style="color: #008000;">!=</span> indice1<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&amp;&amp;</span> <span style="color: #008000;">&#40;</span>indice <span style="color: #008000;">!=</span> indice2<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    posibilidades<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>numeros<span style="color: #008000;">&#91;</span>indice<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
            <span style="color: #008000;">&#125;</span>
            <span style="color: #008080; font-style: italic;">// Creamos el nuevo nodo.</span>
            Nodo opcion <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Nodo<span style="color: #008000;">&#40;</span>posibilidades, valor1, valor2, resultado, signo, <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008080; font-style: italic;">// Hacemos la búsqueda recursiva. Si lo encontramos vamos generando el camino hacia el nodo con el</span>
            <span style="color: #008080; font-style: italic;">// número exacto.</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>opcion<span style="color: #008000;">.</span><span style="color: #0000FF;">busca</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                hijo <span style="color: #008000;">=</span> opcion<span style="color: #008000;">;</span>
                <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
            <span style="color: #0600FF; font-weight: bold;">else</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>También podéis descargaros el <a href="http://www.sistemasorp.es/blog/cifras.zip" target="_blank">ejecutable del programa</a> para poder hacer las pruebas.</p>
<p>Así por ejemplo este reto:</p>
<p><iframe width="420" height="315" src="http://www.youtube.com/embed/Kr5NOAbYfyo" frameborder="0" allowfullscreen></iframe></p>
<p>Se resuelve como:</p>
<p><a href="http://www.sistemasorp.es/wp-content/uploads/2011/11/reto.png"><img src="http://www.sistemasorp.es/wp-content/uploads/2011/11/reto.png" alt="" title="reto" width="373" height="335" class="aligncenter size-full wp-image-473" /></a></p>

<p><a href="http://feedads.g.doubleclick.net/~a/mDSp0uKOa4o6RqiPE8q1RuPZTcs/0/da"><img src="http://feedads.g.doubleclick.net/~a/mDSp0uKOa4o6RqiPE8q1RuPZTcs/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/mDSp0uKOa4o6RqiPE8q1RuPZTcs/1/da"><img src="http://feedads.g.doubleclick.net/~a/mDSp0uKOa4o6RqiPE8q1RuPZTcs/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/sistemasorp/~4/w8FdYl3nTnY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.sistemasorp.es/2011/11/04/fuerza-bruta-en-net-para-resolver-las-cifras-del-concurso-cifras-y-letras/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://www.sistemasorp.es/2011/11/04/fuerza-bruta-en-net-para-resolver-las-cifras-del-concurso-cifras-y-letras/</feedburner:origLink></item>
		<item>
		<title>Microchip va a sacar microcontroladores PIC de 32 bit con encapsulado DIP</title>
		<link>http://feedproxy.google.com/~r/sistemasorp/~3/2fsjDYd_PU4/</link>
		<comments>http://www.sistemasorp.es/2011/10/27/microchip-va-a-sacar-microcontroladores-pic-de-32-bit-con-encapsulado-dip/#comments</comments>
		<pubDate>Thu, 27 Oct 2011 18:28:06 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Proyectos]]></category>

		<guid isPermaLink="false">http://www.sistemasorp.es/?p=431</guid>
		<description><![CDATA[El hecho de que Microchip saque al mercado PICs de 32 bit con encapsulado DIP va a revolucionar el mundo de los aficionados a la electrónica. Un simple chip con 28 pines tan potente como el primer 386 de intel (salvando las arquitecturas Harvard y von Neumann) que podemos poner en nuestras protoboards. Puede correr [...]]]></description>
			<content:encoded><![CDATA[<p>El hecho de que Microchip saque al mercado <a href="http://www.microchip.com/en_US/family/32bit/" target="_blank">PICs de 32 bit</a> con encapsulado <a href="http://es.wikipedia.org/wiki/Dual_in-line_package" target="_blank">DIP</a> va a revolucionar el mundo de los aficionados a la electrónica. Un simple chip con 28 pines tan potente como el primer 386 de intel (salvando las arquitecturas Harvard y von Neumann) que podemos poner en nuestras protoboards. Puede correr hasta 80 Mhz., 512KB de Flash (donde se almacena el código), 128KB. de SRAM (donde se almacenan los datos) y la posibilidad de conectar con periféricos mediante <a href="http://es.wikipedia.org/wiki/DMA" target="_blank">DMA</a>.</p>
<p><a href="http://www.sistemasorp.es/wp-content/uploads/2011/10/32bitOverviewArchGraph_Large.jpg"><img class="aligncenter size-medium wp-image-437" title="32bitOverviewArchGraph_Large" src="http://www.sistemasorp.es/wp-content/uploads/2011/10/32bitOverviewArchGraph_Large-300x178.jpg" alt="" width="300" height="178" /></a></p>
<p>Se pueden pedir <a href="https://www.microchip.com/samples/default.aspx" target="_blank">samples</a>, pero pueden tardar 42 días en enviarlos.</p>
<p><a href="http://www.sistemasorp.es/wp-content/uploads/2011/10/microchip.png"><img class="aligncenter size-medium wp-image-438" title="microchip" src="http://www.sistemasorp.es/wp-content/uploads/2011/10/microchip-300x200.png" alt="" width="300" height="200" /></a></p>

<p><a href="http://feedads.g.doubleclick.net/~a/ZBxtrNHhOwj3p3M3g981Lzdo4kQ/0/da"><img src="http://feedads.g.doubleclick.net/~a/ZBxtrNHhOwj3p3M3g981Lzdo4kQ/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/ZBxtrNHhOwj3p3M3g981Lzdo4kQ/1/da"><img src="http://feedads.g.doubleclick.net/~a/ZBxtrNHhOwj3p3M3g981Lzdo4kQ/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/sistemasorp/~4/2fsjDYd_PU4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.sistemasorp.es/2011/10/27/microchip-va-a-sacar-microcontroladores-pic-de-32-bit-con-encapsulado-dip/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.sistemasorp.es/2011/10/27/microchip-va-a-sacar-microcontroladores-pic-de-32-bit-con-encapsulado-dip/</feedburner:origLink></item>
		<item>
		<title>Descansa en paz Dennis MacAlistair Ritchie</title>
		<link>http://feedproxy.google.com/~r/sistemasorp/~3/DXtHATBp840/</link>
		<comments>http://www.sistemasorp.es/2011/10/13/descansa-en-paz-dennis-macalistair-ritchie/#comments</comments>
		<pubDate>Thu, 13 Oct 2011 07:45:54 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Informática]]></category>

		<guid isPermaLink="false">http://www.sistemasorp.es/?p=429</guid>
		<description><![CDATA[Todo el mundo ha hablado de la reciente muerte de Steve Jobs. Sin embargo también recientemente ha fallecido una persona que ha contribuido enormemente al desarrollo de la informática: Dennis Ritchie. Este hombre fue el creador junto a Ken Thompson del sistema operativo Unix (en el cual está basado GNU/Linux de Richard Stallman y Linus [...]]]></description>
			<content:encoded><![CDATA[<p>Todo el mundo ha hablado de la reciente muerte de Steve Jobs. Sin embargo también recientemente ha fallecido una persona que ha contribuido enormemente al desarrollo de la informática: <a href="http://es.wikipedia.org/wiki/Dennis_Ritchie" target="_blank"><strong>Dennis Ritchie</strong></a>. Este hombre fue el creador junto a Ken Thompson del sistema operativo Unix (en el cual está basado GNU/Linux de Richard Stallman y Linus Torvalds) pero su mayor aportación fue crear el lenguaje de programación C, quizá el más usado de la historia y del que derivan otros tantos como objective-c, java y c#. Hasta siempre Dennis.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">int</span> <span style="color: #339933;">*</span>born1941 <span style="color: #339933;">=</span> malloc<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">70</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #993333;">int</span> <span style="color: #339933;">*</span>die2011 <span style="color: #339933;">=</span> born1941<span style="color: #339933;">;</span>
free<span style="color: #009900;">&#40;</span>die2011<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;bye world<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><a href="http://www.sistemasorp.es/wp-content/uploads/2011/10/ritchie1.jpg"><img class="aligncenter size-medium wp-image-432" title="ritchie1" src="http://www.sistemasorp.es/wp-content/uploads/2011/10/ritchie1-300x289.jpg" alt="" width="300" height="289" /></a></p>
<h6 style="text-align: center;">(Fuente: chw.net)</h6>

<p><a href="http://feedads.g.doubleclick.net/~a/H1-o-e7NjhE51UTF96jBR2Y2Xu8/0/da"><img src="http://feedads.g.doubleclick.net/~a/H1-o-e7NjhE51UTF96jBR2Y2Xu8/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/H1-o-e7NjhE51UTF96jBR2Y2Xu8/1/da"><img src="http://feedads.g.doubleclick.net/~a/H1-o-e7NjhE51UTF96jBR2Y2Xu8/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/sistemasorp/~4/DXtHATBp840" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.sistemasorp.es/2011/10/13/descansa-en-paz-dennis-macalistair-ritchie/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.sistemasorp.es/2011/10/13/descansa-en-paz-dennis-macalistair-ritchie/</feedburner:origLink></item>
		<item>
		<title>Mi charla de telemetría</title>
		<link>http://feedproxy.google.com/~r/sistemasorp/~3/Sr-LXw_Pxsc/</link>
		<comments>http://www.sistemasorp.es/2011/10/11/mi-charla-de-telemetria/#comments</comments>
		<pubDate>Tue, 11 Oct 2011 07:32:12 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Electrónica]]></category>
		<category><![CDATA[Informática]]></category>
		<category><![CDATA[Proyectos]]></category>

		<guid isPermaLink="false">http://www.sistemasorp.es/?p=422</guid>
		<description><![CDATA[Ya han publicado el vídeo de la charla de telemetría que di en la OSHWCON 2011. Toda la documentación de mi charla (presentación, código fuente, esquemáticos, etc.) lo podeis descargar aquí. Agradecer a los organizadores su tiempo, esfuerzo y ganas por sacar adelante algo tan novedoso y pionero. También dignos de mención son los ponentes [...]]]></description>
			<content:encoded><![CDATA[<p>Ya han publicado el vídeo de la charla de telemetría que di en la <a href="http://oshwcon.org/" target="_blank">OSHWCON 2011</a>.</p>
<p><iframe width="420" height="236" src="http://www.youtube.com/embed/cb4OX4HuePQ" frameborder="0" allowfullscreen></iframe></p>
<p>Toda la documentación de mi charla (presentación, código fuente, esquemáticos, etc.) <a href="http://www.sistemasorp.es/blog/oshwcon.zip">lo podeis descargar aquí</a>.</p>
<p>Agradecer a los organizadores su tiempo, esfuerzo y ganas por sacar adelante algo tan novedoso y pionero. También dignos de mención son los ponentes que de forma altruista hemos hecho realidad este fantástico evento. Por supuesto no nos olvidemos de los patrocinadores que han permitido que este evento tuviese un nivel alto y de calidad.</p>
<p>A todos, nos vemos en la OSHWCON 2012.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/NMJ6y4zNp0_JP_8Aw3WSC6osxRU/0/da"><img src="http://feedads.g.doubleclick.net/~a/NMJ6y4zNp0_JP_8Aw3WSC6osxRU/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/NMJ6y4zNp0_JP_8Aw3WSC6osxRU/1/da"><img src="http://feedads.g.doubleclick.net/~a/NMJ6y4zNp0_JP_8Aw3WSC6osxRU/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/sistemasorp/~4/Sr-LXw_Pxsc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.sistemasorp.es/2011/10/11/mi-charla-de-telemetria/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.sistemasorp.es/2011/10/11/mi-charla-de-telemetria/</feedburner:origLink></item>
	</channel>
</rss>

