<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	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/"
	>

<channel>
	<title>La Cofradía Digital</title>
	<atom:link href="http://cofradia.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://cofradia.org</link>
	<description>Hermandad informática</description>
	<lastBuildDate>Thu, 16 May 2013 00:03:40 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>¿Y el histórico del CONSOL?</title>
		<link>http://cofradia.org/2013/05/14/y-el-historico-del-consol/</link>
		<comments>http://cofradia.org/2013/05/14/y-el-historico-del-consol/#comments</comments>
		<pubDate>Tue, 14 May 2013 17:32:43 +0000</pubDate>
		<dc:creator>vicm3</dc:creator>
				<category><![CDATA[internet]]></category>
		<category><![CDATA[Paranoia Fan Club]]></category>
		<category><![CDATA[WTF]]></category>
		<category><![CDATA[Archivo]]></category>
		<category><![CDATA[CONSOL]]></category>
		<category><![CDATA[Historico]]></category>
		<category><![CDATA[¿Qué paso?]]></category>

		<guid isPermaLink="false">http://cofradia.org/?p=7894</guid>
		<description><![CDATA[Recién me preguntaron por un archivo que puse en línea, que es el disco de 2005 del CONSOL, el cual contiene una versión estática del sitio de 2002 a 2005 incluyendo las ponencias [1] de hecho yo mismo no hice el trabajo de pasar wget por consol.org.mx porque daba por sentado que la mayor parte [...]]]></description>
				<content:encoded><![CDATA[<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin-left: 10px;"><g:plusone size="tall" count="1" href="http://cofradia.org/2013/05/14/y-el-historico-del-consol/"></g:plusone></div><p>Recién me preguntaron por un archivo que puse en línea, que es el disco de 2005 del CONSOL, el cual contiene una versión estática del sitio de 2002 a 2005 incluyendo las ponencias [1] de hecho yo mismo no hice el trabajo de pasar wget por consol.org.mx porque daba por sentado que la mayor parte del contenido estaría en archive.org en caso de que fallara la página o que de plano podría dirigirme a 2009/ y encontrar el sitio anterior, como decía anteriormente me preguntaron por el programa de conferencias de 2009 y resulta que no esta en 2009/ y peor aún el robots.txt de consol.org.mx bloquea a archive.org por lo que no se puede acceder por esa vía.</p>
<p>He escrito a comite arroba consol.org.mx, consol arroba consol.org.mx y a un par más de alias pero no he recibido respuesta, el whois del dominio me deja más dudas, pero como se que a mas de uno le interesa mejor pongo la pregunta por acá, ¿como podemos acceder a las ponencias de 2006-2009? y demás material. Parece preocupante que tenga uno que andar buscando en el histórico de la lista (o al menos de lo que esta archivado), o entre los blogs referencias a las ponencias, para ver si por ahí anda perdido el material de la ponencia o como en el caso de algunos, que no se pueda colocar el URL para ponerlo en el ridiculum o en los reportes de trabajo.</p>
<p>[1] <a href="http://ociologia.org/consol/">http://ociologia.org/consol/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://cofradia.org/2013/05/14/y-el-historico-del-consol/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Asterisk y Open Hardware para controlar dispositivos desde un teléfono</title>
		<link>http://cofradia.org/2013/05/13/asterisk-y-open-hardware-para-controlar-dispositivos-desde-un-telefono/</link>
		<comments>http://cofradia.org/2013/05/13/asterisk-y-open-hardware-para-controlar-dispositivos-desde-un-telefono/#comments</comments>
		<pubDate>Mon, 13 May 2013 06:46:29 +0000</pubDate>
		<dc:creator>El Pop</dc:creator>
				<category><![CDATA[Asterisk]]></category>
		<category><![CDATA[Comunicaciones]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Programacion]]></category>
		<category><![CDATA[Sistemas Operativos]]></category>
		<category><![CDATA[Tecnología]]></category>
		<category><![CDATA[VoIP]]></category>
		<category><![CDATA[¿Qué hacer en mi tiempo libre?]]></category>

		<guid isPermaLink="false">http://cofradia.org/?p=7836</guid>
		<description><![CDATA[Pues jugando un poco con Arduino y Asterisk, se me ocurrió hacer una interface entre estos dos para activar luces, puertas, etc. utilizando una extensión telefónica. http://www.youtube.com/watch?v=rcFMJC4n4dQ También hice un sistema de sockets para que desde una página web se pudieran activar estos eventos. Primero conseguí un control de relays para 8 canales. Este lo [...]]]></description>
				<content:encoded><![CDATA[<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin-left: 10px;"><g:plusone size="tall" count="1" href="http://cofradia.org/2013/05/13/asterisk-y-open-hardware-para-controlar-dispositivos-desde-un-telefono/"></g:plusone></div><p>Pues jugando un poco con <A HREF="http://www.arduino.cc/">Arduino</A> y <A HREF="http://www.asterisk.org/">Asterisk</A>, se me ocurrió hacer una interface entre estos dos para activar luces, puertas, etc. utilizando una extensión telefónica.</p>
<p><a href="http://www.youtube.com/watch?v=rcFMJC4n4dQ">http://www.youtube.com/watch?v=rcFMJC4n4dQ</a></p>
<p>También hice un sistema de sockets para que desde una página web se pudieran activar estos eventos.<br />
<span id="more-7836"></span><br />
<div id="attachment_7837" class="wp-caption alignnone" style="width: 310px"><a href="http://cofradia.org/wp-content/uploads/2013/05/focos_1.jpg"><img src="http://cofradia.org/wp-content/uploads/2013/05/focos_1-300x200.jpg" alt="Tablero con control de relay&#039;s, Arduino UNO y un Raspberry Pi corriendo Asterisk" width="300" height="200" class="size-medium wp-image-7837" /></a><p class="wp-caption-text">Tablero con control de relay&#8217;s, Arduino UNO y un Raspberry Pi corriendo Asterisk</p></div></p>
<p>Primero conseguí un control de relays para 8 canales. Este lo compré en <A HREF="http://www.buyincoins.com/new_en/details/new-5v-8-channel-relay-module-board-for-arduino-pic-avr-mcu-dsp-arm-electronic-product-11203.html">BuyInCoins.com</A>. Costó aproximadamente $8.00 USD</p>
<p><a href="http://cofradia.org/wp-content/uploads/2013/05/focos_5.jpg"><img src="http://cofradia.org/wp-content/uploads/2013/05/focos_5-300x200.jpg" alt="Control de 8 relay&#039;s" width="300" height="200" class="alignnone size-medium wp-image-7841" /></a></p>
<p>Despues compré un Arduino UNO en <A HREF="http://www.330ohms.com/products/arduino-uno-r3/">330 Ohms</A> en unos $30.00 USD. Pueden comprar <A HREF="http://www.buyincoins.com/new_en/details/high-quality-arduino-uno-atmega328p-pu-module-atmega8u2-avr-usb-cable-board-product-10252.html">la versión china</A> en BuyInCoins.com</A> en $13.00 USD</p>
<p><a href="http://cofradia.org/wp-content/uploads/2013/05/focos_6.jpg"><img src="http://cofradia.org/wp-content/uploads/2013/05/focos_6-300x200.jpg" alt="Arduino UNO" width="300" height="200" class="alignnone size-medium wp-image-7842" /></a></p>
<p>Para utilizar Asterisk use un <A HREF="http://www.raspberrypi.org/">Raspberry Pi</A> que compré en <A HREF="http://mexico.newark.com/raspberry-pi/raspbrry-modb-512m/model-b-assembled-board-only/dp/43W5302">newark</A> por $50.00 USD.</p>
<p><a href="http://cofradia.org/wp-content/uploads/2013/05/focos_7.jpg"><img src="http://cofradia.org/wp-content/uploads/2013/05/focos_7-300x200.jpg" alt="Raspberry Pi" width="300" height="200" class="alignnone size-medium wp-image-7843" /></a></p>
<p>Más una tabla, cable, tornillos, sockets y contactos por unos $35.00 USD. Agregen a esto un adaptador  WiFi <A HREF="">EnGenius</A> en otros $30.00 y una fuente de poder con salida USB para el Raspberry en $18 USD. En total unos $171.00 USD, mas el tiempo invertido en programación.</p>
<p>El armado de todo se ve así:</p>
<p><a href="http://cofradia.org/wp-content/uploads/2013/05/focos_4.jpg"><img src="http://cofradia.org/wp-content/uploads/2013/05/focos_4-300x133.jpg" alt="focos_4" width="300" height="133" class="alignnone size-medium wp-image-7840" /></a></p>
<p>El controlador de relay&#8217;s se conecta con un cable plano al arduino uno, este a su vez se conecta con un cable USB al raspberry Pi, el cual se alimenta con una fuente USB y se monta un modem WiFi de EnGenius para su control.</p>
<p>Use en la Raspberry Pi una distribusión de Linux para ARM, basada en Debian Wheezy, que incorpora Asterisk 11 en <A HREF="http://www.raspberry-asterisk.org/">www.raspberry-asterisk.org/</A>.</p>
<p>Escribí el siguiente Sketch para Arduino para el control de relay&#8217;s:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/*
#===================================================================#
# Program =&gt; relay.ino (Arduino Sketch)                 version 1.0 #
#===================================================================#
# Autor         =&gt; Fernando &quot;El Pop&quot; Romo        (pop@cofradia.org) #
# Creation date =&gt; 11/may/2013                                      #
#-------------------------------------------------------------------#
# Info =&gt; This program control relays to turn on|off electric       #
#         circuits.                                                 #
#         Use Digital Pins 4 to 11 of Arduino UNO R3 and take the   #
#         commands from the USB.                                    #
#-------------------------------------------------------------------#
# This code are released under the GPL 3.0 License. Any change must #
# be report to the author                                           #
#                  (c) 2013 - Fernando Romo                         #
#-------------------------------------------------------------------#
*/</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* Init the board on Power On or serial connection */</span>
<span style="color: #993333;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #666666; font-style: italic;">// initialize serial:</span>
   Serial.<span style="color: #202020;">begin</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">57600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #666666; font-style: italic;">// make the pins outputs:</span>
   <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> i <span style="color: #339933;">=</span> <span style="color: #0000dd;">4</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;=</span> <span style="color: #0000dd;">11</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
       pinMode<span style="color: #009900;">&#40;</span>i<span style="color: #339933;">,</span> OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
       <span style="color: #666666; font-style: italic;">// Turn off the signals to relays</span>
       digitalWrite<span style="color: #009900;">&#40;</span>i<span style="color: #339933;">,</span> HIGH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
   Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   Status<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* Send the state of the relays (on|off) */</span>
<span style="color: #993333;">void</span> Status<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
     Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Status&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> i <span style="color: #339933;">=</span> <span style="color: #0000dd;">4</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">12</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
         <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>digitalRead<span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> LOW<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
             Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;|on&quot;</span><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>
             Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;|off&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #009900;">&#125;</span>
     <span style="color: #009900;">&#125;</span>                 
     Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<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;
<span style="color: #808080; font-style: italic;">/* Turn off all the relays */</span>
<span style="color: #993333;">void</span> All_On<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> i <span style="color: #339933;">=</span> <span style="color: #0000dd;">4</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;=</span> <span style="color: #0000dd;">11</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        digitalWrite<span style="color: #009900;">&#40;</span>i<span style="color: #339933;">,</span> LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;all|on<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;
<span style="color: #808080; font-style: italic;">/* Turn off all the relays */</span>
<span style="color: #993333;">void</span> All_Off<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> i <span style="color: #339933;">=</span> <span style="color: #0000dd;">4</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;=</span> <span style="color: #0000dd;">11</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        digitalWrite<span style="color: #009900;">&#40;</span>i<span style="color: #339933;">,</span> HIGH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;all|off<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;
<span style="color: #808080; font-style: italic;">/* Turn ON a OFF relay and turn OFF and ON one*/</span>
<span style="color: #993333;">void</span> Change_State <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> digital_port<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>digitalRead<span style="color: #009900;">&#40;</span>digital_port<span style="color: #339933;">+</span><span style="color: #0000dd;">3</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> HIGH<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        digitalWrite<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>digital_port<span style="color: #339933;">+</span><span style="color: #0000dd;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span>digital_port<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;|on<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>
     <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
         digitalWrite<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>digital_port<span style="color: #339933;">+</span><span style="color: #0000dd;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> HIGH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span>digital_port<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;|off<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>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* Sequence to test the relays */</span>
<span style="color: #993333;">void</span> Test<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;test|on<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    All_Off<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> i <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;=</span> <span style="color: #0000dd;">8</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        Change_State<span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        delay<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        Change_State<span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    delay<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> x <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span> x <span style="color: #339933;">&lt;=</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">;</span> x<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> i <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;=</span> <span style="color: #0000dd;">8</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            Change_State<span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            delay<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    All_On<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    delay<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    All_Off<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>    
    Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;test|off<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;
<span style="color: #808080; font-style: italic;">/****************
 * Main program *
 ****************/</span>
<span style="color: #993333;">void</span> loop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// run over and over</span>
<span style="color: #009900;">&#123;</span>
   <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>Serial.<span style="color: #202020;">available</span><span style="color: #009900;">&#40;</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>
       <span style="color: #993333;">int</span> sw <span style="color: #339933;">=</span> Serial.<span style="color: #202020;">parseInt</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
       <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>Serial.<span style="color: #202020;">read</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <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: #339933;">||</span>
           <span style="color: #009900;">&#40;</span>Serial.<span style="color: #202020;">read</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #ff0000;">'<span style="color: #000099; font-weight: bold;">\r</span>'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>  <span style="color: #009900;">&#123;</span>
           <span style="color: #b1b100;">switch</span><span style="color: #009900;">&#40;</span>sw<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
               <span style="color: #b1b100;">case</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">:</span>
                   All_Off<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</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;">9</span><span style="color: #339933;">:</span>
                   All_On<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</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;">7828</span><span style="color: #339933;">:</span> <span style="color: #666666; font-style: italic;">// STAT</span>
                   Status<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</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;">8378</span><span style="color: #339933;">:</span> <span style="color: #666666; font-style: italic;">// TEST</span>
                   Test<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                   <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
               <span style="color: #b1b100;">default</span><span style="color: #339933;">:</span>
                   <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>sw <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span>sw <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">9</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                       Change_State<span style="color: #009900;">&#40;</span>sw<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                   <span style="color: #009900;">&#125;</span>
           <span style="color: #009900;">&#125;</span>
       <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #808080; font-style: italic;">/* End of program */</span></pre></td></tr></table></div>

<p>Este programa lo subí al arduino uno por medio del <A HREF="http://arduino.cc/en/Main/Software">IDE de Arduino</A> (se puede bajar desde la página del proyecto para Linux, Mac y Windows).</p>
<p>Despues escribí un programa en Perl un poco más complicado que usa un thread dedicado ala comunicación serial con el Arduino, y el proceso principal dialoga con Asterisk por medio del <A HREF="https://wiki.asterisk.org/wiki/pages/viewpage.action?pageId=4817239">AMI</A> (Asterisk Manager Interface). Ademas de manejar un socket para usar por medio de otros programas como CGI&#8217;s para usar vía WEB.</p>
<p>Use las siguientes librerias de Perl que se pueden obtener en <A HREF="http://www.cpan.org/">cpan.org</A>:<br />
<UL><br />
<LI><A HREF="http://search.cpan.org/~cook/Device-SerialPort-1.04/SerialPort.pm">Device::SerialPort</A> para el manejo de la comunicación serial con Arduino.</LI><br />
<LI><A HREF="http://search.cpan.org/~jdhedden/threads-1.86/lib/threads.pm">threads</A> pare el control de Threads.</LI><br />
<LI><A HREF="http://search.cpan.org/~jdhedden/Thread-Queue-3.02/lib/Thread/Queue.pm">Thread::Queue</A> para la comunicación entre threads.</LI><br />
</UL></p>
<p>Mas otras librerias comunes de Perl.</p>
<p>Aquí el código fuente del componente de interface entre el Arduino y Asterisk:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/usr/bin/perl</span>
<span style="color: #666666; font-style: italic;">#===================================================================#</span>
<span style="color: #666666; font-style: italic;"># Program =&gt; arduino_control.pl                       (In Perl 5.x) #</span>
<span style="color: #666666; font-style: italic;">#===================================================================#</span>
<span style="color: #666666; font-style: italic;"># Autor         =&gt; Fernando &quot;El Pop&quot; Romo        (pop@cofradia.org) #</span>
<span style="color: #666666; font-style: italic;"># Creation date =&gt; 2/may/2013                                       #</span>
<span style="color: #666666; font-style: italic;">#-------------------------------------------------------------------#</span>
<span style="color: #666666; font-style: italic;"># Info =&gt; This program is a server who make a connection with a     #</span>
<span style="color: #666666; font-style: italic;">#         asterisk server trough the TCP port 5038,take request     #</span>
<span style="color: #666666; font-style: italic;">#         from a TPC clients and dispach messages to them.          #</span>
<span style="color: #666666; font-style: italic;">#-------------------------------------------------------------------#</span>
<span style="color: #666666; font-style: italic;"># This code are released under the GPL 3.0 License. Any change must #</span>
<span style="color: #666666; font-style: italic;"># be report to the authors                                          #</span>
<span style="color: #666666; font-style: italic;">#              (c) 2013 - Fernando Romo / Incuvox                   #</span>
<span style="color: #666666; font-style: italic;">#-------------------------------------------------------------------#</span>
<span style="color: #666666; font-style: italic;">#        For the change history use &quot;cvs log&quot; command               #</span>
<span style="color: #666666; font-style: italic;">#===================================================================#</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Last update:</span>
<span style="color: #666666; font-style: italic;"># $Id: arduino_control.pl,v 1.2 2013/05/15 23:57:10 pop Exp $</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Load Modules</span>
<span style="color: #000000; font-weight: bold;">use</span> strict<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> DBI<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#use parms;</span>
<span style="color: #000000; font-weight: bold;">use</span> POSIX<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> IO<span style="color: #339933;">::</span><span style="color: #006600;">Socket</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> IO<span style="color: #339933;">::</span><span style="color: #006600;">Select</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> Socket<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> Fcntl<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> Tie<span style="color: #339933;">::</span><span style="color: #006600;">RefHash</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> Time<span style="color: #339933;">::</span><span style="color: #006600;">Local</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> Time<span style="color: #339933;">::</span><span style="color: #006600;">HiRes</span> <span style="color: #000066;">qw</span><span style="color: #009900;">&#40;</span>usleep<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> Proc<span style="color: #339933;">::</span><span style="color: #006600;">PID</span><span style="color: #339933;">::</span><span style="color: #006600;">File</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> File<span style="color: #339933;">::</span><span style="color: #006600;">Basename</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> Data<span style="color: #339933;">::</span><span style="color: #006600;">Dumper</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> threads<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> Thread<span style="color: #339933;">::</span><span style="color: #006600;">Queue</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> Device<span style="color: #339933;">::</span><span style="color: #006600;">SerialPort</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066;">defined</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$ARGV</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><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: #0000ff;">$ARGV</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">eq</span> <span style="color: #ff0000;">'-d'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066;">defined</span><span style="color: #009900;">&#40;</span><span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$pid</span> <span style="color: #339933;">=</span> <span style="color: #000066;">fork</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">or</span> <span style="color: #000066;">die</span> <span style="color: #ff0000;">&quot;Can't Fork: $!&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">exit</span> <span style="color: #b1b100;">if</span> <span style="color: #0000ff;">$pid</span><span style="color: #339933;">;</span>
        setsid <span style="color: #b1b100;">or</span> <span style="color: #000066;">die</span> <span style="color: #ff0000;">&quot;Can't start a new session: $!&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># check PID File</span>
<span style="color: #000066;">die</span> <span style="color: #ff0000;">'Already runnig'</span> <span style="color: #b1b100;">if</span> Proc<span style="color: #339933;">::</span><span style="color: #006600;">PID</span><span style="color: #339933;">::</span><span style="color: #006600;">File</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">running</span><span style="color: #009900;">&#40;</span> name <span style="color: #339933;">=&gt;</span> basename<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;$0&quot;</span><span style="color: #339933;">,</span><span style="color: #ff0000;">'.pl'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#--------------------#</span>
<span style="color: #666666; font-style: italic;"># Control Parameters #</span>
<span style="color: #666666; font-style: italic;">#--------------------#</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#--------------------------------------------------------------------</span>
<span style="color: #666666; font-style: italic;"># [Pop] Developer Note: The Sys_Parms() load the necesary values from</span>
<span style="color: #666666; font-style: italic;"># the Parameter table in the DB. I left this values comment for test</span>
<span style="color: #666666; font-style: italic;"># and documentation purposes.</span>
<span style="color: #666666; font-style: italic;">#--------------------------------------------------------------------</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">%Parm</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">##  Arduino server parameters</span>
<span style="color: #0000ff;">$Parm</span><span style="color: #009900;">&#123;</span>arduino<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#123;</span>debug<span style="color: #009900;">&#125;</span>            <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>              <span style="color: #666666; font-style: italic;"># Flag to print debug information</span>
<span style="color: #0000ff;">$Parm</span><span style="color: #009900;">&#123;</span>arduino<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#123;</span>port<span style="color: #009900;">&#125;</span>             <span style="color: #339933;">=</span> <span style="color: #cc66cc;">4446</span><span style="color: #339933;">;</span>           <span style="color: #666666; font-style: italic;"># port for clients</span>
<span style="color: #0000ff;">$Parm</span><span style="color: #009900;">&#123;</span>arduino<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#123;</span>dev<span style="color: #009900;">&#125;</span>              <span style="color: #339933;">=</span> <span style="color: #ff0000;">'/dev/ttyACM0'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">##  Asterisk manager parameters</span>
<span style="color: #0000ff;">$Parm</span><span style="color: #009900;">&#123;</span>asterisk<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#123;</span>host<span style="color: #009900;">&#125;</span>        <span style="color: #339933;">=</span> <span style="color: #ff0000;">'127.0.0.1'</span><span style="color: #339933;">;</span>    <span style="color: #666666; font-style: italic;"># IP address of * Server</span>
<span style="color: #0000ff;">$Parm</span><span style="color: #009900;">&#123;</span>asterisk<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#123;</span>port<span style="color: #009900;">&#125;</span>        <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5038</span><span style="color: #339933;">;</span>           <span style="color: #666666; font-style: italic;"># * manager port</span>
<span style="color: #0000ff;">$Parm</span><span style="color: #009900;">&#123;</span>asterisk<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#123;</span>user<span style="color: #009900;">&#125;</span>        <span style="color: #339933;">=</span> <span style="color: #ff0000;">'arduino'</span><span style="color: #339933;">;</span>      <span style="color: #666666; font-style: italic;"># * Manager user</span>
<span style="color: #0000ff;">$Parm</span><span style="color: #009900;">&#123;</span>asterisk<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#123;</span>pass<span style="color: #009900;">&#125;</span>        <span style="color: #339933;">=</span> <span style="color: #ff0000;">'openhardware'</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;"># * Manager password</span>
<span style="color: #0000ff;">$Parm</span><span style="color: #009900;">&#123;</span>asterisk<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#123;</span>events<span style="color: #009900;">&#125;</span>      <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>              <span style="color: #666666; font-style: italic;"># Flag to request event log to * manager</span>
<span style="color: #666666; font-style: italic;">#--------------------------------------------------------------------</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$PBX_ID</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#-------------------#</span>
<span style="color: #666666; font-style: italic;"># Working Variables #</span>
<span style="color: #666666; font-style: italic;">#-------------------#</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$VERSION</span> <span style="color: #339933;">=</span> <span style="color: #000066;">q</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$Id</span><span style="color: #339933;">:</span> arduino_control<span style="color: #339933;">.</span>pl<span style="color: #339933;">,</span>v <span style="color: #cc66cc;">1.2</span> <span style="color: #cc66cc;">2013</span><span style="color: #339933;">/</span>05<span style="color: #339933;">/</span><span style="color: #cc66cc;">15</span> <span style="color: #cc66cc;">23</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">57</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">10</span> <span style="color: #000066;">pop</span> Exp $<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
   <span style="color: #0000ff;">$VERSION</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">s/\$|Id:\s//g</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$HELP</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;$VERSION<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>Commands:<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Timers Info</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$Start_Time</span> <span style="color: #339933;">=</span> <span style="color: #000066;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$Reload_Time</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Socket handlers</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$asterisk_handler</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$asterisk_select</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$asterisk_client</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># signal traps</span>
<span style="color: #0000ff;">$SIG</span><span style="color: #009900;">&#123;</span>PIPE<span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'IGNORE'</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$SIG</span><span style="color: #009900;">&#123;</span>INT<span style="color: #009900;">&#125;</span>  <span style="color: #339933;">=</span> <span style="color: #0000ff;">$SIG</span><span style="color: #009900;">&#123;</span>TERM<span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$SIG</span><span style="color: #009900;">&#123;</span>HUP<span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'Terminate'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#Load_Parameters();</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Queues to pass data between Threads</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$Command_Queue</span>   <span style="color: #339933;">=</span> Thread<span style="color: #339933;">::</span><span style="color: #006600;">Queue</span><span style="color: #339933;">-&gt;</span><span style="color: #000000; font-weight: bold;">new</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$Response_Queue</span>  <span style="color: #339933;">=</span> Thread<span style="color: #339933;">::</span><span style="color: #006600;">Queue</span><span style="color: #339933;">-&gt;</span><span style="color: #000000; font-weight: bold;">new</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$tid</span>                 <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Open Socket connection to accept clients requests</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$server</span> <span style="color: #339933;">=</span> IO<span style="color: #339933;">::</span><span style="color: #006600;">Socket</span><span style="color: #339933;">::</span><span style="color: #006600;">INET</span><span style="color: #339933;">-&gt;</span><span style="color: #000000; font-weight: bold;">new</span><span style="color: #009900;">&#40;</span>LocalPort <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">$Parm</span><span style="color: #009900;">&#123;</span>arduino<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#123;</span>port<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
                                   Listen    <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">,</span>
                                   ReuseAddr <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#41;</span>
  <span style="color: #b1b100;">or</span> <span style="color: #000066;">die</span> <span style="color: #ff0000;">&quot;Can't make server socket: $@<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
Nonblock<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$server</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$select</span> <span style="color: #339933;">=</span> IO<span style="color: #339933;">::</span><span style="color: #006600;">Select</span><span style="color: #339933;">-&gt;</span><span style="color: #000000; font-weight: bold;">new</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$server</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># begin with empty buffers</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">%inbuffer</span>  <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">%outbuffer</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">%ready</span>     <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">%sessions</span>  <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">%who</span>       <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066;">tie</span> <span style="color: #0000ff;">%ready</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'Tie::RefHash'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$event_str</span> <span style="color: #339933;">=</span> <span style="color: #000066;">q</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$XML_msg</span>   <span style="color: #339933;">=</span> <span style="color: #000066;">q</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Flags to connect to Asterisk</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$manager_connect_time</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$manager_connect_flag</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#----------------------------------------------------------------------------------------------</span>
<span style="color: #666666; font-style: italic;"># [Developer Note]: the process of each client request is declared in the %Client_Handler</span>
<span style="color: #666666; font-style: italic;">#                   Hash and use references for speed operations in the event detection cycle.</span>
<span style="color: #666666; font-style: italic;">#----------------------------------------------------------------------------------------------</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">%Client_Handler</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>
    <span style="color: #666666; font-style: italic;">#----------------------------------------------------------------------------------------------------------------</span>
    <span style="color: #666666; font-style: italic;"># relay: [relay number]</span>
    <span style="color: #666666; font-style: italic;">#----------------------------------------------------------------------------------------------------------------</span>
    <span style="color: #ff0000;">&quot;relay&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">sub</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$client</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$control</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">@</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$control</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #0000ff;">$outbuffer</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$client</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;Missing relay number<span style="color: #000099; font-weight: bold;">\n</span>&quot;</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: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$control</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">/\d+/</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #0000ff;">$Command_Queue</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">enqueue</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'relay|'</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">$control</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><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>
                <span style="color: #0000ff;">$outbuffer</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$client</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;Invalid relay number (must be digits)<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>  <span style="color: #666666; font-style: italic;"># End if ($control-&gt;[1] =~ /\d+/)</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;"># End if (@{$control} &lt; 0)</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    <span style="color: #666666; font-style: italic;">#----------------------------------------------------------------------------------------------------------------</span>
    <span style="color: #666666; font-style: italic;"># HELP</span>
    <span style="color: #666666; font-style: italic;">#----------------------------------------------------------------------------------------------------------------</span>
    <span style="color: #ff0000;">&quot;help&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">sub</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$client</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
        <span style="color: #0000ff;">$outbuffer</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$client</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$HELP</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    <span style="color: #666666; font-style: italic;">#----------------------------------------------------------------------------------------------------------------</span>
    <span style="color: #666666; font-style: italic;"># PARM: List Process parameters</span>
    <span style="color: #666666; font-style: italic;">#----------------------------------------------------------------------------------------------------------------</span>
    <span style="color: #ff0000;">&quot;parm&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">sub</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$client</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$control</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">@</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$control</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #0000ff;">$outbuffer</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$client</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">''</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">foreach</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$category</span>  <span style="color: #009900;">&#40;</span><span style="color: #000066;">sort</span> <span style="color: #000066;">keys</span> <span style="color: #0000ff;">%Parm</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #0000ff;">$outbuffer</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$client</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">.=</span> <span style="color: #ff0000;">&quot;$category<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">foreach</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$keyword</span>  <span style="color: #009900;">&#40;</span><span style="color: #000066;">sort</span> <span style="color: #000066;">keys</span> <span style="color: #339933;">%</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$Parm</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$category</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    <span style="color: #0000ff;">$outbuffer</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$client</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">.=</span> <span style="color: #ff0000;">&quot;    $keyword =&gt; $Parm{$category}{$keyword}<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    <span style="color: #666666; font-style: italic;">#----------------------------------------------------------------------------------------------------------------</span>
    <span style="color: #666666; font-style: italic;"># QUIT or EXIT: terminate client session</span>
    <span style="color: #666666; font-style: italic;">#----------------------------------------------------------------------------------------------------------------</span>
    <span style="color: #ff0000;">&quot;quit&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">sub</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$client</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">delete</span> <span style="color: #0000ff;">$inbuffer</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$client</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">delete</span> <span style="color: #0000ff;">$outbuffer</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$client</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">delete</span> <span style="color: #0000ff;">$ready</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$client</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">delete</span> <span style="color: #0000ff;">$sessions</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$client</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">delete</span> <span style="color: #0000ff;">$who</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$client</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
        <span style="color: #0000ff;">$select</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$client</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">close</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$client</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    <span style="color: #666666; font-style: italic;">#----------------------------------------------------------------------------------------------------------------</span>
    <span style="color: #666666; font-style: italic;"># STATUS</span>
    <span style="color: #666666; font-style: italic;">#----------------------------------------------------------------------------------------------------------------</span>
    <span style="color: #ff0000;">&quot;status&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">sub</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$client</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
        <span style="color: #0000ff;">$Command_Queue</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">enqueue</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'relay|7828'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    <span style="color: #666666; font-style: italic;">#----------------------------------------------------------------------------------------------------------------</span>
    <span style="color: #666666; font-style: italic;"># UPTIME: elapsed time of the running service</span>
    <span style="color: #666666; font-style: italic;">#----------------------------------------------------------------------------------------------------------------</span>
    <span style="color: #ff0000;">&quot;uptime&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">sub</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$client</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
        <span style="color: #0000ff;">$outbuffer</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$client</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> Convert_To_Time<span style="color: #009900;">&#40;</span><span style="color: #000066;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #0000ff;">$Start_Time</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    <span style="color: #666666; font-style: italic;">#----------------------------------------------------------------------------------------------------------------</span>
    <span style="color: #666666; font-style: italic;"># TEST</span>
    <span style="color: #666666; font-style: italic;">#----------------------------------------------------------------------------------------------------------------</span>
    <span style="color: #ff0000;">&quot;test&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">sub</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$client</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
        <span style="color: #0000ff;">$Command_Queue</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">enqueue</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'relay|8378'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    <span style="color: #666666; font-style: italic;">#----------------------------------------------------------------------------------------------------------------</span>
    <span style="color: #666666; font-style: italic;"># TIME: current system time</span>
    <span style="color: #666666; font-style: italic;">#----------------------------------------------------------------------------------------------------------------</span>
    <span style="color: #ff0000;">&quot;time&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">sub</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$client</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
        <span style="color: #0000ff;">$outbuffer</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$client</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> Current_Time<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    <span style="color: #666666; font-style: italic;">#----------------------------------------------------------------------------------------------------------------</span>
    <span style="color: #666666; font-style: italic;"># VERSION: Bring information about this program</span>
    <span style="color: #666666; font-style: italic;">#----------------------------------------------------------------------------------------------------------------</span>
    <span style="color: #ff0000;">&quot;version&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">sub</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$client</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
        <span style="color: #0000ff;">$outbuffer</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$client</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;$VERSION<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    <span style="color: #666666; font-style: italic;">#----------------------------------------------------------------------------------------------------------------</span>
    <span style="color: #666666; font-style: italic;"># WHO: List agents and extensions active for control</span>
    <span style="color: #666666; font-style: italic;">#----------------------------------------------------------------------------------------------------------------</span>
    <span style="color: #ff0000;">&quot;who&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">sub</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$client</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
        <span style="color: #0000ff;">$outbuffer</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$client</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>Connections &quot;</span> <span style="color: #339933;">.</span> <span style="color: #009900;">&#40;</span><span style="color: #000066;">scalar</span> <span style="color: #000066;">keys</span> <span style="color: #0000ff;">%sessions</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">foreach</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$online</span> <span style="color: #009900;">&#40;</span><span style="color: #000066;">sort</span> <span style="color: #000066;">keys</span> <span style="color: #0000ff;">%who</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$port</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$address</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> unpack_sockaddr_in<span style="color: #009900;">&#40;</span><span style="color: #000066;">getpeername</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$who</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$online</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$ip_address</span> <span style="color: #339933;">=</span> inet_ntoa<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$address</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #0000ff;">$outbuffer</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$client</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">.=</span> <span style="color: #ff0000;">&quot;$ip_address<span style="color: #000099; font-weight: bold;">\:</span>$port<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#------------------------------------------------------------------#</span>
<span style="color: #666666; font-style: italic;"># [Pop] Developer Note: I declare the &quot;exit&quot; command Out of the    #</span>
<span style="color: #666666; font-style: italic;"># initial %Client_Handler Hash declaration to avoid perl compiler  #</span>
<span style="color: #666666; font-style: italic;"># errors because i try to invoque a non declare hash into the      #</span>
<span style="color: #666666; font-style: italic;"># same hash :P                                                     #</span>
<span style="color: #666666; font-style: italic;">#                                                                  #</span>
<span style="color: #666666; font-style: italic;"># The trick is receive the &quot;exit&quot; command and call the same        #</span>
<span style="color: #666666; font-style: italic;"># rutine of the &quot;quit&quot; event.                                      #</span>
<span style="color: #666666; font-style: italic;">#------------------------------------------------------------------#</span>
&nbsp;
<span style="color: #0000ff;">$Client_Handler</span><span style="color: #009900;">&#123;</span><span style="color: #000066;">exit</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">sub</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$client</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$Client_Handler</span><span style="color: #009900;">&#123;</span>quit<span style="color: #009900;">&#125;</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$client</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #0000ff;">$Client_Handler</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'?'</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">sub</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$client</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$Client_Handler</span><span style="color: #009900;">&#123;</span>help<span style="color: #009900;">&#125;</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$client</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">foreach</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$command</span> <span style="color: #009900;">&#40;</span><span style="color: #000066;">sort</span> <span style="color: #000066;">keys</span> <span style="color: #0000ff;">%Client_Handler</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #0000ff;">$HELP</span> <span style="color: #339933;">.=</span> <span style="color: #ff0000;">&quot;     $command<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#--------------------------------------------------------------------------------------#</span>
<span style="color: #666666; font-style: italic;"># [Developer Note]: the process of each packet comming from the asteris manager (AMI), #</span>
<span style="color: #666666; font-style: italic;">#                   is declared in the %Event_Handler Hash and use references for      #</span>
<span style="color: #666666; font-style: italic;">#                   speed operations in the event detection cycle.                     #</span>
<span style="color: #666666; font-style: italic;">#--------------------------------------------------------------------------------------#</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">%Event_Handler</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>
    <span style="color: #666666; font-style: italic;">#-----------------------------</span>
    <span style="color: #666666; font-style: italic;"># Event: UserEvent</span>
    <span style="color: #666666; font-style: italic;"># Privilege: user,all</span>
    <span style="color: #666666; font-style: italic;"># UserEvent: RELAY|1</span>
    <span style="color: #666666; font-style: italic;"># Action: UserEvent</span>
    <span style="color: #666666; font-style: italic;">#-----------------------------</span>
    <span style="color: #ff0000;">&quot;UserEvent&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">sub</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$packet_content_ref</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$userevent</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$$packet_content_ref</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">/UserEvent\:\s(.*?)\n/isx</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">#----------------------------------------------------------------------------------------------------------------</span>
        <span style="color: #666666; font-style: italic;"># UserEvent(RELAY|number)</span>
        <span style="color: #666666; font-style: italic;">#----------------------------------------------------------------------------------------------------------------</span>
        <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@Response</span> <span style="color: #339933;">=</span> <span style="color: #000066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/_/</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$userevent</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$Response</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">eq</span> <span style="color: #ff0000;">'RELAY'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #0000ff;">$Command_Queue</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">enqueue</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'relay|'</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">$Response</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    <span style="color: #666666; font-style: italic;">#-----------------------</span>
    <span style="color: #666666; font-style: italic;"># Event: Shutdown</span>
    <span style="color: #666666; font-style: italic;"># Privilege: system,all</span>
    <span style="color: #666666; font-style: italic;"># Shutdown: Cleanly</span>
    <span style="color: #666666; font-style: italic;"># Restart: False</span>
    <span style="color: #666666; font-style: italic;">#-----------------------</span>
    <span style="color: #ff0000;">&quot;Shutdown&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">sub</span>  <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$packet_content_ref</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;"># Terminate(); # if asterisk end then stop pms server</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#---------------------------------------------------------#</span>
<span style="color: #666666; font-style: italic;">#  Function: Terminate()                                  #</span>
<span style="color: #666666; font-style: italic;">#---------------------------------------------------------#</span>
<span style="color: #666666; font-style: italic;"># Objetive: catch the {INT}  signal and close connection  #</span>
<span style="color: #666666; font-style: italic;">#           to sockets and terminate program.             #</span>
<span style="color: #666666; font-style: italic;">#   Params: none                                          #</span>
<span style="color: #666666; font-style: italic;">#    Usage:                                               #</span>
<span style="color: #666666; font-style: italic;">#          $SIG{INT}  = 'Terminate';                      #</span>
<span style="color: #666666; font-style: italic;">#---------------------------------------------------------#</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> Terminate
<span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">#$thread_die = 1; # Flag to indicate to the child process die</span>
    <span style="color: #0000ff;">$Command_Queue</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">enqueue</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'stop'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$client</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;"># Clean up connections</span>
    <span style="color: #b1b100;">foreach</span> <span style="color: #0000ff;">$client</span> <span style="color: #009900;">&#40;</span><span style="color: #000066;">keys</span> <span style="color: #0000ff;">%sessions</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #0000ff;">$select</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$client</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">close</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$client</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066;">close</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$server</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>                   <span style="color: #666666; font-style: italic;"># destroy socket handler</span>
    <span style="color: #000066;">close</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$asterisk_handler</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>         <span style="color: #666666; font-style: italic;"># destroy asterisk manager conection</span>
    <span style="color: #0000ff;">$tid</span><span style="color: #339933;">-&gt;</span><span style="color: #000066;">join</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$tid</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>                          <span style="color: #666666; font-style: italic;"># Exit without error</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#-----------------------------------------------#</span>
<span style="color: #666666; font-style: italic;">#  Function: Nonblock([TCP socket handler])     #</span>
<span style="color: #666666; font-style: italic;">#-----------------------------------------------#</span>
<span style="color: #666666; font-style: italic;"># Objetive: puts socket into nonblocking mode   #</span>
<span style="color: #666666; font-style: italic;">#   Params: [TCP Socket Handler]                #</span>
<span style="color: #666666; font-style: italic;">#    Usage:                                     #</span>
<span style="color: #666666; font-style: italic;">#          Nonblock($socket);                   #</span>
<span style="color: #666666; font-style: italic;">#-----------------------------------------------#</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> Nonblock <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$socket</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$flags</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #0000ff;">$flags</span> <span style="color: #339933;">=</span> <span style="color: #000066;">fcntl</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$socket</span><span style="color: #339933;">,</span> F_GETFL<span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
             <span style="color: #b1b100;">or</span> <span style="color: #000066;">die</span> <span style="color: #ff0000;">&quot;Can't get flags for socket: $!<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">fcntl</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$socket</span><span style="color: #339933;">,</span> F_SETFL<span style="color: #339933;">,</span> <span style="color: #0000ff;">$flags</span> <span style="color: #339933;">|</span> O_NONBLOCK<span style="color: #009900;">&#41;</span>
             <span style="color: #b1b100;">or</span> <span style="color: #000066;">die</span> <span style="color: #ff0000;">&quot;Can't make socket nonblocking: $!<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#-----------------------------------------------#</span>
<span style="color: #666666; font-style: italic;">#  Function: Manager_Login                      #</span>
<span style="color: #666666; font-style: italic;">#-----------------------------------------------#</span>
<span style="color: #666666; font-style: italic;"># Objetive: Send Login Action to Asterisk API   #</span>
<span style="color: #666666; font-style: italic;">#   Params: none                                #</span>
<span style="color: #666666; font-style: italic;">#    Usage:                                     #</span>
<span style="color: #666666; font-style: italic;">#          Manager_Login();                     #</span>
<span style="color: #666666; font-style: italic;">#-----------------------------------------------#</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> Manager_Login <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$command</span>  <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;Action: Login<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>
    <span style="color: #0000ff;">$command</span> <span style="color: #339933;">.=</span> <span style="color: #ff0000;">&quot;Username: $Parm{asterisk}{user}<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>
    <span style="color: #0000ff;">$command</span> <span style="color: #339933;">.=</span> <span style="color: #ff0000;">&quot;Secret: $Parm{asterisk}{pass}<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>
    <span style="color: #0000ff;">$command</span> <span style="color: #339933;">.=</span> <span style="color: #ff0000;">&quot;Events: &quot;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$Parm</span><span style="color: #009900;">&#123;</span>asterisk<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#123;</span>events<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #0000ff;">$command</span> <span style="color: #339933;">.=</span> <span style="color: #ff0000;">'on'</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: #0000ff;">$command</span> <span style="color: #339933;">.=</span> <span style="color: #ff0000;">'off'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #0000ff;">$command</span> <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: #339933;">;</span>
    <span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;---------------<span style="color: #000099; font-weight: bold;">\n</span>$command<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$Parm</span><span style="color: #009900;">&#123;</span>arduino<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#123;</span>debug<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    Send_To_Asterisk<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">\$command</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#--------------------------------------------------#</span>
<span style="color: #666666; font-style: italic;"># Function: Connect_To_Asterisk()                  #</span>
<span style="color: #666666; font-style: italic;">#--------------------------------------------------#</span>
<span style="color: #666666; font-style: italic;"># Objetive: connect program with asterisk manager  #</span>
<span style="color: #666666; font-style: italic;">#   Params: None                                   #</span>
<span style="color: #666666; font-style: italic;">#    Usage:                                        #</span>
<span style="color: #666666; font-style: italic;">#          Connect_To_Asterisk();                  #</span>
<span style="color: #666666; font-style: italic;">#--------------------------------------------------#</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> Connect_To_Asterisk
<span style="color: #009900;">&#123;</span>
    <span style="color: #0000ff;">$asterisk_handler</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> IO<span style="color: #339933;">::</span><span style="color: #006600;">Socket</span><span style="color: #339933;">::</span><span style="color: #006600;">INET</span><span style="color: #339933;">-&gt;</span><span style="color: #000000; font-weight: bold;">new</span><span style="color: #009900;">&#40;</span> PeerAddr <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">$Parm</span><span style="color: #009900;">&#123;</span>asterisk<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#123;</span>host<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
                                                   PeerPort <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">$Parm</span><span style="color: #009900;">&#123;</span>asterisk<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#123;</span>port<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
                                                   Proto    <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">&quot;tcp&quot;</span><span style="color: #339933;">,</span>
                                                   ReuseAddr <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
                                                   Type     <span style="color: #339933;">=&gt;</span> SOCK_STREAM <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$asterisk_handler</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #0000ff;">$asterisk_handler</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">autoflush</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        Nonblock<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$asterisk_handler</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #0000ff;">$select</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$asterisk_handler</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #0000ff;">$manager_connect_time</span> <span style="color: #339933;">=</span> <span style="color: #000066;">time</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">return</span> <span style="color: #cc66cc;">0</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: #000066;">return</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#--------------------------------------------------------#</span>
<span style="color: #666666; font-style: italic;"># Function: Send_To_Asterisk([message])                  #</span>
<span style="color: #666666; font-style: italic;">#--------------------------------------------------------#</span>
<span style="color: #666666; font-style: italic;"># Objetive: Send  message to Asterik manager             #</span>
<span style="color: #666666; font-style: italic;">#   Params: message, socket_handler                      #</span>
<span style="color: #666666; font-style: italic;">#    Usage:                                              #</span>
<span style="color: #666666; font-style: italic;">#          Send_To_Asterisk($message,$socket)            #</span>
<span style="color: #666666; font-style: italic;">#--------------------------------------------------------#</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> Send_To_Asterisk
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$command_ref</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">unless</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$$command_ref</span> <span style="color: #b1b100;">eq</span> <span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #0000ff;">$manager_connect_flag</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">#--------------------------------------------------------------------------------#</span>
        <span style="color: #666666; font-style: italic;"># Developer Note: in some cases, the API Manager sufer of a requets override and #</span>
        <span style="color: #666666; font-style: italic;">#                 is necesary put a little time wait between requests.           #</span>
        <span style="color: #666666; font-style: italic;">#--------------------------------------------------------------------------------#</span>
        <span style="color: #666666; font-style: italic;"># usleep 200_000;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;"># if the socket exists send data, if not, turn on reconnection flag</span>
        <span style="color: #666666; font-style: italic;"># if (defined(getpeername($asterisk_handler))) {</span>
        <span style="color: #b1b100;">unless</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$asterisk_handler</span> <span style="color: #b1b100;">eq</span> <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$rv</span><span style="color: #339933;">;</span>
            <span style="color: #000066;">eval</span> <span style="color: #009900;">&#123;</span> <span style="color: #0000ff;">$rv</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$asterisk_handler</span><span style="color: #339933;">-&gt;</span><span style="color: #000066;">send</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$$command_ref</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">unless</span> <span style="color: #009900;">&#40;</span><span style="color: #000066;">defined</span> <span style="color: #0000ff;">$rv</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #666666; font-style: italic;"># if send fails, turn on reconnection flag</span>
                <span style="color: #0000ff;">$manager_connect_flag</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span> 
        <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #0000ff;">$manager_connect_flag</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><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: #666666; font-style: italic;">#-------------------------------------------------------#</span>
<span style="color: #666666; font-style: italic;">#  Fuction: Trim([var|array])                           #</span>
<span style="color: #666666; font-style: italic;">#-------------------------------------------------------#</span>
<span style="color: #666666; font-style: italic;"># Objetive: Take out blank spaces in the rigth and left #</span>
<span style="color: #666666; font-style: italic;">#           of the field                                #</span>
<span style="color: #666666; font-style: italic;">#   Params: one string or array                         #</span>
<span style="color: #666666; font-style: italic;">#    Usage:                                             #</span>
<span style="color: #666666; font-style: italic;">#          $sample = Trim(&quot; vs &quot;);                      #</span>
<span style="color: #666666; font-style: italic;">#          $sample = Trim($foo);                        #</span>
<span style="color: #666666; font-style: italic;">#          @sample = Trim(@data);                       #</span>
<span style="color: #666666; font-style: italic;">#-------------------------------------------------------#</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> Trim <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@out</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">@_</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">@out</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #009966; font-style: italic;">s/^\s+//g</span><span style="color: #339933;">;</span>
        <span style="color: #009966; font-style: italic;">s/\s+$//g</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066;">return</span> <span style="color: #000066;">wantarray</span> <span style="color: #339933;">?</span> <span style="color: #0000ff;">@out</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">$out</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#---------------------------------------------------#</span>
<span style="color: #666666; font-style: italic;"># Function: Dial([phone number],[agent],[campaign], #</span>
<span style="color: #666666; font-style: italic;">#                [Warehouse_id],[call_id])          #</span>
<span style="color: #666666; font-style: italic;">#---------------------------------------------------#</span>
<span style="color: #666666; font-style: italic;"># Objetive: originate a phone call via the asterisk #</span>
<span style="color: #666666; font-style: italic;">#                                                   #</span>
<span style="color: #666666; font-style: italic;">#   Params: phone number                            #</span>
<span style="color: #666666; font-style: italic;">#    Usage:                                         #</span>
<span style="color: #666666; font-style: italic;">#          Dial(&quot;85909000&quot;,&quot;1001&quot;)                  #</span>
<span style="color: #666666; font-style: italic;">#---------------------------------------------------#</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> Dial <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$tcp_client</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$class</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$number</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$wid</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$call_id</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">@_</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$command</span>  <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;Action: Originate<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>
    <span style="color: #666666; font-style: italic;"># $command .= &quot;Channel: Local/$number\@default/n\r\n&quot;;</span>
    <span style="color: #0000ff;">$command</span> <span style="color: #339933;">.=</span> <span style="color: #ff0000;">&quot;Channel: $Parm{asterisk}{trunk}/$number<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>
    <span style="color: #0000ff;">$command</span> <span style="color: #339933;">.=</span> <span style="color: #ff0000;">&quot;Context: default<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>
    <span style="color: #0000ff;">$command</span> <span style="color: #339933;">.=</span> <span style="color: #ff0000;">&quot;Priority: 1<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>
    <span style="color: #0000ff;">$command</span> <span style="color: #339933;">.=</span> <span style="color: #ff0000;">&quot;Async: true<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>
    <span style="color: #0000ff;">$command</span> <span style="color: #339933;">.=</span> <span style="color: #ff0000;">&quot;Timeout: 30000<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>
    <span style="color: #0000ff;">$command</span> <span style="color: #339933;">.=</span> <span style="color: #ff0000;">&quot;Variable: TIMEOUT(absolute)=$Parm{arduino}{absolute_timeout}<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>
    <span style="color: #0000ff;">$command</span> <span style="color: #339933;">.=</span> <span style="color: #ff0000;">&quot;Variable: CDR(dnis)=$number<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>
    <span style="color: #0000ff;">$command</span> <span style="color: #339933;">.=</span> <span style="color: #ff0000;">&quot;Variable: CDR(call_type)=2<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>
    <span style="color: #0000ff;">$command</span> <span style="color: #339933;">.=</span> <span style="color: #ff0000;">&quot;Variable: CDR(origin)=4<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>
    <span style="color: #0000ff;">$command</span> <span style="color: #339933;">.=</span> <span style="color: #ff0000;">&quot;Variable: CDR(pbx)=$PBX_ID<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>
    <span style="color: #0000ff;">$command</span> <span style="color: #339933;">.=</span> <span style="color: #ff0000;">&quot;Callerid: $number<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>
    <span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$tcp_client_hex_part</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$tcp_client</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">/\((.*?)\)/</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$command</span> <span style="color: #339933;">.=</span> <span style="color: #ff0000;">&quot;ActionID: C<span style="color: #000099; font-weight: bold;">\|</span>$tcp_client_hex_part<span style="color: #000099; font-weight: bold;">\|</span>$call_id<span style="color: #000099; font-weight: bold;">\|</span>$wid<span style="color: #000099; font-weight: bold;">\|</span>$number&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$command</span> <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: #339933;">;</span>
    Send_To_Asterisk<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">\$command</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#----------------------------------------------------#</span>
<span style="color: #666666; font-style: italic;"># Function: User_Event([Message])                    #</span>
<span style="color: #666666; font-style: italic;">#----------------------------------------------------#</span>
<span style="color: #666666; font-style: italic;"># Objetive: Send a User Event to communicate state   #</span>
<span style="color: #666666; font-style: italic;">#           with other process                       #</span>
<span style="color: #666666; font-style: italic;">#   Params: Agent, mode                              #</span>
<span style="color: #666666; font-style: italic;">#    Usage:                                          #</span>
<span style="color: #666666; font-style: italic;">#          User_Event($msg);                         #</span>
<span style="color: #666666; font-style: italic;">#----------------------------------------------------#</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> User_Event <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$msg</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">@_</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$command</span>  <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;Action: UserEvent<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>
    <span style="color: #0000ff;">$command</span> <span style="color: #339933;">.=</span> <span style="color: #ff0000;">&quot;UserEvent: $msg<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>
    Send_To_Asterisk<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">\$command</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#---------------------------------------------------------#</span>
<span style="color: #666666; font-style: italic;">#  Fuction: Pad([string],[Width],[fill_char],[Direction]) #</span>
<span style="color: #666666; font-style: italic;">#---------------------------------------------------------#</span>
<span style="color: #666666; font-style: italic;"># Objetive: Fill with character selected one string in    #</span>
<span style="color: #666666; font-style: italic;">#           the right or left                             #</span>
<span style="color: #666666; font-style: italic;">#   Params: string, Max_Width, fill_char,                 #</span>
<span style="color: #666666; font-style: italic;">#           Direction (0 = left, 1 = rigth)               #</span>
<span style="color: #666666; font-style: italic;">#    Usage:                                               #</span>
<span style="color: #666666; font-style: italic;">#          Pad($month,2,'0',0)                            #</span>
<span style="color: #666666; font-style: italic;">#---------------------------------------------------------#</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> Pad <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$string</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$lmax</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$char</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$dir</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">@_</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$l</span> <span style="color: #339933;">=</span> <span style="color: #000066;">length</span> <span style="color: #0000ff;">$string</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$l</span> <span style="color: #339933;">&gt;</span> <span style="color: #0000ff;">$lmax</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #0000ff;">$string</span> <span style="color: #339933;">=</span> <span style="color: #000066;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$string</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$lmax</span><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>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$dir</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #0000ff;">$string</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$string</span> <span style="color: #339933;">.</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$char</span> x <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$lmax</span> <span style="color: #339933;">-</span> <span style="color: #0000ff;">$l</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: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>    
            <span style="color: #0000ff;">$string</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$char</span> x <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$lmax</span> <span style="color: #339933;">-</span> <span style="color: #0000ff;">$l</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">$string</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066;">return</span> <span style="color: #0000ff;">$string</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#===========================================================#</span>
<span style="color: #666666; font-style: italic;"># Convert_To_Time                                           #</span>
<span style="color: #666666; font-style: italic;">#-----------------------------------------------------------#</span>
<span style="color: #666666; font-style: italic;"># Fuction to convert elapsed time in seconds to a friendly  #</span>
<span style="color: #666666; font-style: italic;"># format like hhh:mm:ss                                     #</span>
<span style="color: #666666; font-style: italic;">#                                                           #</span>
<span style="color: #666666; font-style: italic;"># Arguments:                                                #</span>
<span style="color: #666666; font-style: italic;">#            a integer number that mean seconds             #</span>
<span style="color: #666666; font-style: italic;"># Sample:                                                   #</span>
<span style="color: #666666; font-style: italic;">#            $seconds = 11145;                              #</span>
<span style="color: #666666; font-style: italic;">#            print &quot;call elapsed time = &quot;;                  #</span>
<span style="color: #666666; font-style: italic;">#            print Convert_To_Time($seconds);               #</span>
<span style="color: #666666; font-style: italic;"># Result:                                                   #</span>
<span style="color: #666666; font-style: italic;">#            call elapsed time = 3:05'45                    #</span>
<span style="color: #666666; font-style: italic;">#===========================================================#</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> Convert_To_Time <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$time</span><span style="color: #339933;">=</span><span style="color: #0000ff;">$_</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$days</span> <span style="color: #339933;">=</span> <span style="color: #000066;">int</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$time</span> <span style="color: #339933;">/</span> <span style="color: #cc66cc;">86400</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$aux</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$time</span> <span style="color: #339933;">%</span> <span style="color: #cc66cc;">86400</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$hours</span> <span style="color: #339933;">=</span> <span style="color: #000066;">int</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$aux</span> <span style="color: #339933;">/</span> <span style="color: #cc66cc;">3600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
       <span style="color: #0000ff;">$aux</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$aux</span> <span style="color: #339933;">%</span> <span style="color: #cc66cc;">3600</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$minutes</span> <span style="color: #339933;">=</span> <span style="color: #000066;">int</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$aux</span> <span style="color: #339933;">/</span> <span style="color: #cc66cc;">60</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$seconds</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$time</span> <span style="color: #339933;">%</span> <span style="color: #cc66cc;">60</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$result</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$days</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #0000ff;">$result</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;$days day &quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> 
    <span style="color: #b1b100;">elsif</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$days</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #0000ff;">$result</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;$days days &quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #0000ff;">$result</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">$hours</span><span style="color: #339933;">.</span><span style="color: #ff0000;">&quot;:&quot;</span><span style="color: #339933;">.</span>Pad<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$minutes</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span><span style="color: #ff0000;">'0'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #ff0000;">&quot;'&quot;</span><span style="color: #339933;">.</span>Pad<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$seconds</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span><span style="color: #ff0000;">'0'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">return</span> <span style="color: #0000ff;">$result</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#-------------------------------------------------#</span>
<span style="color: #666666; font-style: italic;">#  Function: Current_Time                         #</span>
<span style="color: #666666; font-style: italic;">#-------------------------------------------------#</span>
<span style="color: #666666; font-style: italic;"># Objetive: Return current formated date and time #</span>
<span style="color: #666666; font-style: italic;">#   Params: none                                  #</span>
<span style="color: #666666; font-style: italic;">#    Usage:                                       #</span>
<span style="color: #666666; font-style: italic;">#          $date = CurrentTime_();                #</span>
<span style="color: #666666; font-style: italic;">#-------------------------------------------------#</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> Current_Time <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$second</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$minute</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$hour</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$day</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$month</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$year</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066;">localtime</span><span style="color: #009900;">&#40;</span><span style="color: #000066;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$month</span><span style="color: #339933;">++;</span>
    <span style="color: #0000ff;">$year</span> <span style="color: #339933;">+=</span> <span style="color: #cc66cc;">1900</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">return</span> <span style="color: #ff0000;">&quot;$year-&quot;</span> <span style="color: #339933;">.</span> Pad<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$month</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span><span style="color: #ff0000;">'0'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #ff0000;">'-'</span> <span style="color: #339933;">.</span>Pad<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$day</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span><span style="color: #ff0000;">'0'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span><span style="color: #ff0000;">' '</span> <span style="color: #339933;">.</span>
            Pad<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$hour</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span><span style="color: #ff0000;">'0'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #ff0000;">':'</span> <span style="color: #339933;">.</span> Pad<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$minute</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span><span style="color: #ff0000;">'0'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #ff0000;">':'</span><span style="color: #339933;">.</span>Pad<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$second</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span><span style="color: #ff0000;">'0'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> 
&nbsp;
<span style="color: #666666; font-style: italic;">#--------------------------------------------------------#</span>
<span style="color: #666666; font-style: italic;"># Function: Arduino_Handler()                   [Thread] #</span>
<span style="color: #666666; font-style: italic;">#--------------------------------------------------------#</span>
<span style="color: #666666; font-style: italic;"># Objetive: Process serial comunication with Arduino USB #</span>
<span style="color: #666666; font-style: italic;">#   Params: file device                                  #</span>
<span style="color: #666666; font-style: italic;">#    Usage:                                              #</span>
<span style="color: #666666; font-style: italic;">#       $tid = threads-&gt;create(\&amp;Arduino_Handler,$dev);  #</span>
<span style="color: #666666; font-style: italic;">#--------------------------------------------------------#</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> Arduino_Handler <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$arduino_dev</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$port</span> <span style="color: #339933;">=</span> <span style="color: #000066;">undef</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$Serial_Connection_Flag</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">#-----------------------------------------------------------------------------------</span>
    <span style="color: #666666; font-style: italic;"># [Pop] Developer Note: This is tricky part of declare a sub into a sub to invoque</span>
    <span style="color: #666666; font-style: italic;">#                       on the thread start and on reload :P</span>
    <span style="color: #666666; font-style: italic;">#-----------------------------------------------------------------------------------</span>
    <span style="color: #666666; font-style: italic;"># _Connect_Arduino() - Star serial communication with Arduino using USB</span>
    <span style="color: #666666; font-style: italic;">#-----------------------------------------------------------------------------------</span>
    <span style="color: #000066;">local</span> <span style="color: #0000ff;">*_Connect_Arduino</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">sub</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> <span style="color: #339933;">-</span>e <span style="color: #0000ff;">$arduino_dev</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$Serial_Connection_Flag</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #0000ff;">$Serial_Connection_Flag</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
            <span style="color: #000066;">eval</span> <span style="color: #009900;">&#123;</span> <span style="color: #0000ff;">$port</span> <span style="color: #339933;">=</span> Device<span style="color: #339933;">::</span><span style="color: #006600;">SerialPort</span><span style="color: #339933;">-&gt;</span><span style="color: #000000; font-weight: bold;">new</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;$arduino_dev&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">unless</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$port</span> <span style="color: #b1b100;">eq</span> <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #0000ff;">$port</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">baudrate</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">57600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;"># you may change this value</span>
                <span style="color: #0000ff;">$port</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">databits</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">8</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;"># but not this and the two following</span>
                <span style="color: #0000ff;">$port</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">parity</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;none&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #0000ff;">$port</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">stopbits</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #0000ff;">$port</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">handshake</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;none&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #0000ff;">$port</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">read_char_time</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #0000ff;">$port</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">read_const_time</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">20</span><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>
                <span style="color: #0000ff;">$Serial_Connection_Flag</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #0000ff;">$Serial_Connection_Flag</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">#--------------------------------------------------------------------------</span>
    <span style="color: #666666; font-style: italic;"># __Send_To_Arduino() - Send Info to Arduino</span>
    <span style="color: #666666; font-style: italic;">#--------------------------------------------------------------------------</span>
    <span style="color: #000066;">local</span> <span style="color: #0000ff;">*_Send_To_Arduino</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">sub</span> <span style="color: #009900;">&#123;</span>
       <span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$relay</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
       <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$count</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
       <span style="color: #b1b100;">unless</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$port</span> <span style="color: #b1b100;">eq</span> <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
           <span style="color: #000066;">eval</span> <span style="color: #009900;">&#123;</span> <span style="color: #0000ff;">$count</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$port</span><span style="color: #339933;">-&gt;</span><span style="color: #000066;">write</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;$relay<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
           <span style="color: #b1b100;">unless</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$count</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
              <span style="color: #0000ff;">$Serial_Connection_Flag</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
           <span style="color: #009900;">&#125;</span>
       <span style="color: #009900;">&#125;</span>
       <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #0000ff;">$Serial_Connection_Flag</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
       <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066;">local</span> <span style="color: #0000ff;">*_Read_From_Arduino</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">sub</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$rx</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">''</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">eval</span> <span style="color: #009900;">&#123;</span> <span style="color: #0000ff;">$rx</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$port</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">lookfor</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$port</span> <span style="color: #b1b100;">eq</span> <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
              <span style="color: #0000ff;">$Serial_Connection_Flag</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">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: #000066;">return</span> <span style="color: #0000ff;">$rx</span><span style="color: #339933;">;;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">#-------------------#</span>
    <span style="color: #666666; font-style: italic;"># Main thread cycle #</span>
    <span style="color: #666666; font-style: italic;">#-------------------#</span>
&nbsp;
    <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><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: #0000ff;">$Serial_Connection_Flag</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            _Connect_Arduino<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$command</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$Command_Queue</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">dequeue_nb</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$command</span><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: #0000ff;">$command</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">/\|/</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$option</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #000066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/\|/</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$command</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$option</span> <span style="color: #b1b100;">eq</span> <span style="color: #ff0000;">'relay'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    _Send_To_Arduino<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #b1b100;">elsif</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$command</span> <span style="color: #b1b100;">eq</span> <span style="color: #ff0000;">'stop'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #0000ff;">$port</span><span style="color: #339933;">-&gt;</span><span style="color: #000066;">close</span><span style="color: #339933;">;</span>
                <span style="color: #000066;">return</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span> 
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$rx</span> <span style="color: #339933;">=</span> _Read_From_Arduino<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$rx</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #0000ff;">$Response_Queue</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">enqueue</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$rx</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
        <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
    <span style="color: #666666; font-style: italic;"># End Main thread cycle </span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#---------------------------------------------------------#</span>
<span style="color: #666666; font-style: italic;">#  Function: Handle_Clients([Client TCP handler])         #</span>
<span style="color: #666666; font-style: italic;">#---------------------------------------------------------#</span>
<span style="color: #666666; font-style: italic;"># Objetive: Take the requests of client programs and      #</span>
<span style="color: #666666; font-style: italic;">#           interface with Asterisk manager               #</span>
<span style="color: #666666; font-style: italic;">#   Params: [client TCP handler]                          #</span>
<span style="color: #666666; font-style: italic;">#    Usage:                                               #</span>
<span style="color: #666666; font-style: italic;">#          Handle_Clients($client);                       #</span>
<span style="color: #666666; font-style: italic;">#---------------------------------------------------------#</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> Handle_Clients <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;"># requests are in $ready{$client}</span>
    <span style="color: #666666; font-style: italic;"># send output to $outbuffer{$client}</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$client</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$request</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">foreach</span> <span style="color: #0000ff;">$request</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">@</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$ready</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$client</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
       <span style="color: #0000ff;">$request</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">s/\r|\n//g</span><span style="color: #339933;">;</span>
       <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$request</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
           <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@control</span> <span style="color: #339933;">=</span> <span style="color: #000066;">split</span> <span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/\s+/</span><span style="color: #339933;">,</span> Trim<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$request</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
           <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066;">exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$Client_Handler</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$control</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
               <span style="color: #0000ff;">$Client_Handler</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$control</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$client</span><span style="color: #339933;">,</span><span style="color: #0000ff;">\@control</span><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>
               <span style="color: #0000ff;">$outbuffer</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$client</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;Invalid command<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span> 
           <span style="color: #009900;">&#125;</span>
       <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066;">delete</span> <span style="color: #0000ff;">$ready</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$client</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#---------------------------------------------------------#</span>
<span style="color: #666666; font-style: italic;">#  Function: Handle_Events([Asterisk TCP handler])        #</span>
<span style="color: #666666; font-style: italic;">#---------------------------------------------------------#</span>
<span style="color: #666666; font-style: italic;"># Objetive: Take the requests of Asterisk and manipulate  #</span>
<span style="color: #666666; font-style: italic;">#           the asterisk Manager events.                  #</span>
<span style="color: #666666; font-style: italic;">#   Params: [Asterisk TCP handler]                        #</span>
<span style="color: #666666; font-style: italic;">#    Usage:                                               #</span>
<span style="color: #666666; font-style: italic;">#          Handle_Events($asterisk_handler);              #</span>
<span style="color: #666666; font-style: italic;">#---------------------------------------------------------#</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> Handle_Events <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;"># requests are in $ready{$client}</span>
    <span style="color: #666666; font-style: italic;"># send output to $outbuffer{$client}</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$client</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$request</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@packet</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">foreach</span> <span style="color: #0000ff;">$request</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">@</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$ready</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$client</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #0000ff;">$event_str</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">$request</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$request</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$event_str</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">/\r\n\r\n/</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
       <span style="color: #666666; font-style: italic;"># put each packet in separate area</span>
       <span style="color: #0000ff;">@packet</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$event_str</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">/(?:Action|Event|Message|Response).*?\r\n\r\n/isxg</span><span style="color: #339933;">;</span>
&nbsp;
       <span style="color: #666666; font-style: italic;"># process each individual packet </span>
       <span style="color: #b1b100;">foreach</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$packet_content</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">@packet</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
           <span style="color: #0000ff;">$packet_content</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">s/\r//g</span><span style="color: #339933;">;</span>
&nbsp;
           <span style="color: #666666; font-style: italic;"># Analyze each packet header and process according</span>
           <span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$event</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$packet_content</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">/^Event\:\s(.*?)\n/isx</span><span style="color: #339933;">;</span>
           <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066;">exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$Event_Handler</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$event</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
               <span style="color: #0000ff;">$Event_Handler</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$event</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">\$packet_content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
           <span style="color: #009900;">&#125;</span>
       <span style="color: #009900;">&#125;</span>
&nbsp;
       <span style="color: #666666; font-style: italic;"># if exists a remainder incomplet event, keep it to the next round  </span>
       <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$last_pos</span> <span style="color: #339933;">=</span> <span style="color: #000066;">rindex</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$event_str</span><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>
       <span style="color: #0000ff;">$last_pos</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$last_pos</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">4</span><span style="color: #339933;">;</span>
       <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$len</span> <span style="color: #339933;">=</span> <span style="color: #000066;">length</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$event_str</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
       <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$len</span> <span style="color: #339933;">&gt;</span> <span style="color: #0000ff;">$last_pos</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
           <span style="color: #0000ff;">$event_str</span> <span style="color: #339933;">=</span> <span style="color: #000066;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$event_str</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$last_pos</span><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>
           <span style="color: #0000ff;">$event_str</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #339933;">;</span>
       <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066;">delete</span> <span style="color: #0000ff;">$ready</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$client</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#---------------------------------------------------------#</span>
<span style="color: #666666; font-style: italic;">#  Function: Clean_Connection([TCP handler])              #</span>
<span style="color: #666666; font-style: italic;">#---------------------------------------------------------#</span>
<span style="color: #666666; font-style: italic;"># Objetive: Close client TCP connection                   #</span>
<span style="color: #666666; font-style: italic;">#   Params: [TCP handler]                                 #</span>
<span style="color: #666666; font-style: italic;">#    Usage:                                               #</span>
<span style="color: #666666; font-style: italic;">#          Clean_Connection($client_handler);             #</span>
<span style="color: #666666; font-style: italic;">#---------------------------------------------------------#</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> Clean_Connection <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$client_session</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;"># Delete working buffers</span>
    <span style="color: #000066;">delete</span> <span style="color: #0000ff;">$inbuffer</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$client_session</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">delete</span> <span style="color: #0000ff;">$outbuffer</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$client_session</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">delete</span> <span style="color: #0000ff;">$ready</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$client_session</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">delete</span> <span style="color: #0000ff;">$sessions</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$client_session</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">delete</span> <span style="color: #0000ff;">$who</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$client_session</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;"># Check if the connection to Asterisk Die and turn the reconnection Flag</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$client_session</span> <span style="color: #b1b100;">eq</span> <span style="color: #0000ff;">$asterisk_handler</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #0000ff;">$manager_connect_flag</span> <span style="color: #339933;">=</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #0000ff;">$select</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$client_session</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">close</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$client_session</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#======================#</span>
<span style="color: #666666; font-style: italic;">#      Main block      #</span>
<span style="color: #666666; font-style: italic;">#======================#</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># $/=&quot;\0&quot;;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Launch Configuration Thread for Arduino control</span>
<span style="color: #0000ff;">$tid</span> <span style="color: #339933;">=</span> threads<span style="color: #339933;">-&gt;</span><span style="color: #006600;">create</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">\&amp;Arduino_Handler</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$Parm</span><span style="color: #009900;">&#123;</span>arduino<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#123;</span>dev<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Main loop </span>
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$client</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$rv</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$data</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$manager_connect_flag</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #0000ff;">$manager_connect_flag</span> <span style="color: #339933;">=</span> Connect_To_Asterisk<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">unless</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$manager_connect_flag</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            Manager_Login<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> 
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;"># check for new information on the connections we have.</span>
    <span style="color: #666666; font-style: italic;"># anything to read or accept?</span>
    <span style="color: #b1b100;">foreach</span> <span style="color: #0000ff;">$client</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$select</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">can_read</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><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: #0000ff;">$client</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">$server</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #666666; font-style: italic;"># accept a new connection</span>
            <span style="color: #0000ff;">$client</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$server</span><span style="color: #339933;">-&gt;</span><span style="color: #000066;">accept</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #0000ff;">$select</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$client</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            Nonblock<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$client</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #0000ff;">$sessions</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$client</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
            <span style="color: #0000ff;">$who</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$client</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$client</span><span style="color: #339933;">;</span>
            <span style="color: #0000ff;">$outbuffer</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$client</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;$VERSION (? for help)<span style="color: #000099; font-weight: bold;">\n</span>&quot;</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: #666666; font-style: italic;"># read data</span>
            <span style="color: #0000ff;">$data</span> <span style="color: #339933;">=</span> <span style="color: #000066;">q</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
            <span style="color: #000066;">eval</span> <span style="color: #009900;">&#123;</span> <span style="color: #0000ff;">$rv</span>   <span style="color: #339933;">=</span> <span style="color: #0000ff;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #000066;">recv</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$data</span><span style="color: #339933;">,</span> POSIX<span style="color: #339933;">::</span><span style="color: #006600;">BUFSIZ</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">unless</span> <span style="color: #009900;">&#40;</span><span style="color: #000066;">defined</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$rv</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000066;">length</span> <span style="color: #0000ff;">$data</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #666666; font-style: italic;"># This would be the end of file, so close the client</span>
                Clean_Connection<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$client</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">next</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #0000ff;">$data</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">s/\0/\r\n/g</span><span style="color: #339933;">;</span>
            <span style="color: #0000ff;">$inbuffer</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$client</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">$data</span><span style="color: #339933;">;</span>
            <span style="color: #666666; font-style: italic;"># test whether the data in the buffer or the data we</span>
            <span style="color: #666666; font-style: italic;"># just read means there is a complete request waiting</span>
            <span style="color: #666666; font-style: italic;"># to be fulfilled.  If there is, set $ready{$client}</span>
            <span style="color: #666666; font-style: italic;"># to the requests waiting to be fulfilled.</span>
            <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$inbuffer</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$client</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=~</span> <span style="color: #000066;">s</span><span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">.*</span><span style="color: #0000ff;">\r</span><span style="color: #0000ff;">\n</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">//</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000066;">push</span><span style="color: #009900;">&#40;</span> <span style="color: #339933;">@</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$ready</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$client</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$1</span> <span style="color: #009900;">&#41;</span><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: #666666; font-style: italic;"># Read if exist response from Arduino</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$response</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$Response_Queue</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">dequeue_nb</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$response</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         <span style="color: #b1b100;">foreach</span> <span style="color: #0000ff;">$client</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$select</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">can_write</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
             <span style="color: #0000ff;">$outbuffer</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$client</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$response</span> <span style="color: #339933;">.</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;"># Any complete requests to process?</span>
    <span style="color: #b1b100;">foreach</span> <span style="color: #0000ff;">$client</span> <span style="color: #009900;">&#40;</span><span style="color: #000066;">keys</span> <span style="color: #0000ff;">%ready</span><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: #0000ff;">$client</span> <span style="color: #b1b100;">eq</span> <span style="color: #0000ff;">$asterisk_handler</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            Handle_Events<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$client</span><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>
            Handle_Clients<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$client</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;"># Buffers to flush?</span>
    <span style="color: #b1b100;">foreach</span> <span style="color: #0000ff;">$client</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$select</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">can_write</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;"># Skip this client if we have nothing to say</span>
        <span style="color: #b1b100;">next</span> <span style="color: #b1b100;">unless</span> <span style="color: #000066;">exists</span> <span style="color: #0000ff;">$outbuffer</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$client</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;"># Check if the socket exists before send</span>
        <span style="color: #666666; font-style: italic;">## if (defined(getpeername($client))) {</span>
        <span style="color: #b1b100;">unless</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$client</span> <span style="color: #b1b100;">eq</span> <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066;">eval</span> <span style="color: #009900;">&#123;</span> <span style="color: #0000ff;">$rv</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #000066;">send</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$outbuffer</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$client</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">unless</span> <span style="color: #009900;">&#40;</span><span style="color: #000066;">defined</span> <span style="color: #0000ff;">$rv</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #666666; font-style: italic;"># Whine, but move on.</span>
                <span style="color: #000066;">warn</span> <span style="color: #ff0000;">&quot;I was told I could write, but I can't.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">next</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$rv</span> <span style="color: #339933;">==</span> <span style="color: #000066;">length</span> <span style="color: #0000ff;">$outbuffer</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$client</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">||</span>
                <span style="color: #0000ff;">$!</span> <span style="color: #339933;">==</span> POSIX<span style="color: #339933;">::</span><span style="color: #006600;">EWOULDBLOCK</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000066;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$outbuffer</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$client</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$rv</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #000066;">q</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
                <span style="color: #000066;">delete</span> <span style="color: #0000ff;">$outbuffer</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$client</span><span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">unless</span> <span style="color: #000066;">length</span> <span style="color: #0000ff;">$outbuffer</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$client</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span> 
            <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
                Clean_Connection<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$client</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">next</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span> 
        <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
            Clean_Connection<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$client</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">next</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;"># Out of band data?</span>
    <span style="color: #b1b100;">foreach</span> <span style="color: #0000ff;">$client</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$select</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">has_exception</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>  <span style="color: #666666; font-style: italic;"># arg is timeout</span>
        <span style="color: #666666; font-style: italic;"># Deal with out-of-band data here, if you want to.</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;"># End of main loop</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#------------- End of Program ----------</span></pre></td></tr></table></div>

<p>Este programa lo arranco como servicio en Linux. usando este script en /etc/init.d/arduino</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #666666; font-style: italic;">### BEGIN INIT INFO</span>
<span style="color: #666666; font-style: italic;"># Provides:          arduino</span>
<span style="color: #666666; font-style: italic;"># Required-Start:    freepbx</span>
<span style="color: #666666; font-style: italic;"># Required-Stop:     freepbx</span>
<span style="color: #666666; font-style: italic;"># Default-Start:     2 3 4 5</span>
<span style="color: #666666; font-style: italic;"># Default-Stop:      0 1 6</span>
<span style="color: #666666; font-style: italic;"># Short-Description: Start Arduino Asterisk Control</span>
<span style="color: #666666; font-style: italic;"># Description:       Start Arduino Asterisk Control</span>
<span style="color: #666666; font-style: italic;">### END INIT INFO</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># chkconfig: 35 99 99</span>
<span style="color: #666666; font-style: italic;"># description: Arduino Server</span>
<span style="color: #666666; font-style: italic;"># processname: arduino_control.pl</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># source function library</span>
. <span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>lsb<span style="color: #000000; font-weight: bold;">/</span>init-functions
<span style="color: #666666; font-style: italic;">#. /etc/rc.d/init.d/functions</span>
&nbsp;
<span style="color: #007800;">DAEMON</span>=<span style="color: #ff0000;">&quot;/root/arduino/arduino_control.pl &gt;&gt; /dev/null 2&gt;&amp;1&quot;</span>
<span style="color: #007800;">OPTIONS</span>=-d
<span style="color: #007800;">RETVAL</span>=<span style="color: #000000;">0</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #000000; font-weight: bold;">in</span>
  start<span style="color: #7a0874; font-weight: bold;">&#41;</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Starting Arduino server: &quot;</span>
	daemon <span style="color: #007800;">$DAEMON</span> <span style="color: #007800;">$OPTIONS</span>
	<span style="color: #007800;">RETVAL</span>=<span style="color: #007800;">$?</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span>
	<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$RETVAL</span> <span style="color: #660033;">-eq</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">touch</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lock<span style="color: #000000; font-weight: bold;">/</span>arduino_control.pl
	<span style="color: #000000; font-weight: bold;">;;</span>
  stop<span style="color: #7a0874; font-weight: bold;">&#41;</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Shutting down Arduino server: &quot;</span>
	killproc arduino_control.pl
	<span style="color: #007800;">RETVAL</span>=<span style="color: #007800;">$?</span>
&nbsp;
	<span style="color: #7a0874; font-weight: bold;">echo</span>
	<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$RETVAL</span> <span style="color: #660033;">-eq</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lock<span style="color: #000000; font-weight: bold;">/</span>arduino_control.pl
	<span style="color: #000000; font-weight: bold;">;;</span>
  restart<span style="color: #7a0874; font-weight: bold;">&#41;</span>
	<span style="color: #007800;">$0</span> stop
	<span style="color: #007800;">$0</span> start
	<span style="color: #007800;">RETVAL</span>=<span style="color: #007800;">$?</span>
	<span style="color: #000000; font-weight: bold;">;;</span>
  reload<span style="color: #7a0874; font-weight: bold;">&#41;</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Reloading Arduino server: &quot;</span>
	killproc arduino_control.pl <span style="color: #660033;">-HUP</span>
	<span style="color: #007800;">RETVAL</span>=<span style="color: #007800;">$?</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span>
	<span style="color: #000000; font-weight: bold;">;;</span>
  status<span style="color: #7a0874; font-weight: bold;">&#41;</span>
	status arduino_control.pl
	<span style="color: #007800;">RETVAL</span>=<span style="color: #007800;">$?</span>
	<span style="color: #000000; font-weight: bold;">;;</span>
  <span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Usage: arduino_control {start|stop|status|restart|reload}&quot;</span>
	<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">esac</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$RETVAL</span></pre></td></tr></table></div>

<p>En Asterisk hay que poner lo siguiente en el archivo /etc/asterisk/manager.conf, si usan el freepbx que viene incluido en la disto lo ponen en /etc/astrisk/manager_custom.conf:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="text" style="font-family:monospace;">[arduino]
secret=openhardware
writetimeout = 10000
;read = system,call,log,verbose,agent,user,config,dtmf,reporting,cdr,dialplan
eventfilter=!Event: RTCPSent
eventfilter=!Event: RTCPReceived
read = system,call,log,agent,user,config,dtmf,reporting,cdr,dialplan
write = system,call,agent,user,config,command,reporting,originate</pre></td></tr></table></div>

<p>Para probar, ponemos en el archivo de /etc/asterisk/extensions.ael esto:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="text" style="font-family:monospace;">context from-internal {
    888 =&gt; {
        goto ivr,s,1;
    };
&nbsp;
    777 =&gt; {
        Answer;
        MusicOnHold();
        Hangup;
    };
&nbsp;
    8378 =&gt; {
        Answer;
        Playback(beep);
        UserEvent(RELAY_8378,);
        Hangup;
    }; 
    666 =&gt; {
        Answer;
        Playback(beep);
        UserEvent(RELAY_1,);
        wait(1);
        UserEvent(RELAY_1,);
        UserEvent(RELAY_2,);
        wait(1);
        UserEvent(RELAY_2,);
        UserEvent(RELAY_3,);
        wait(1);
        UserEvent(RELAY_3,);
        UserEvent(RELAY_4,);
        wait(1);
        UserEvent(RELAY_4,);
        UserEvent(RELAY_5,);
        wait(1);
        UserEvent(RELAY_5,);
        UserEvent(RELAY_6,);
        wait(1);
        UserEvent(RELAY_6,);
        UserEvent(RELAY_7,);
        wait(1);
        UserEvent(RELAY_7,);
        UserEvent(RELAY_8,);
        wait(1);
        UserEvent(RELAY_8,);
        Playback(beep);
        Hangup;
    };
}
&nbsp;
context ivr {
    s =&gt; {
        Answer;
        Background(silence/9);
    pregunta:
        Set(TIMEOUT(response)=5);
        Set(TIMEOUT(digit)=1);
        WaitExten();
        goto pregunta;
    };
    _X =&gt; {
       UserEvent(RELAY_${EXTEN},);
       goto s,pregunta;
    };
&nbsp;
    t =&gt; {
        goto ivr,s,pregunta;
    };
&nbsp;
    i =&gt; {
        goto ivr,s,pregunta;
    };
&nbsp;
}</pre></td></tr></table></div>

<p>Si se fijan, use un llamado a la función &#8220;UserEvent&#8221; que permite mandar mensajes usando el core de Asterisk, estos los proceso como eventos de AMI en el programa &#8220;arduino_control.pl&#8221; y así puedo disparar eventos desde el plan de marcación de Asterisk.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="text" style="font-family:monospace;">UserEvent(RELAY_X,);</pre></td></tr></table></div>

<p>Donde &#8220;X&#8221; es el número de relay que deseo activar. dejo reservado el número &#8220;8378&#8243; (TEST) para probar los relay&#8217;s. Uso el 7828 (STAT) para pedir el estatus de los relay&#8217;s.</p>
<p>Tambien se puede actuvar los eventos por medio de la interface por socket usando el puerto 4446 por TCP. por ejemplo usando Telnet:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="text" style="font-family:monospace;">$ telnet 192.168.1.89 4446
Trying 192.168.1.89...
Connected to raspbx.lan.
Escape character is '^]'.
arduino_control.pl v1.0 (? for help)
relay 8
8|on
relay 8
8|off
&nbsp;
status
Status|off|off|off|off|off|off|off|off</pre></td></tr></table></div>

<p>Para ver mas opciones le dan &#8220;help&#8221;.</p>
<p>Y suscriben una extensión SIP al Asterisk del Raspberry Pi.</p>
<p>Espero se diviertan jugando con este tipo de proyectos <img src='http://cofradia.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Autor: Fernando “El Pop” Romo (pop at cofradia.org), twitter @El_Pop</p>
]]></content:encoded>
			<wfw:commentRss>http://cofradia.org/2013/05/13/asterisk-y-open-hardware-para-controlar-dispositivos-desde-un-telefono/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>FLISOL Empresas y Software Libre</title>
		<link>http://cofradia.org/2013/05/02/flisol-empresas-y-software-libre/</link>
		<comments>http://cofradia.org/2013/05/02/flisol-empresas-y-software-libre/#comments</comments>
		<pubDate>Thu, 02 May 2013 11:33:38 +0000</pubDate>
		<dc:creator>El Pop</dc:creator>
				<category><![CDATA[Convocatorias]]></category>
		<category><![CDATA[Cultura Libre]]></category>
		<category><![CDATA[software libre]]></category>

		<guid isPermaLink="false">http://cofradia.org/?p=7832</guid>
		<description><![CDATA[El día de mañana 3 de mayo del 2013, se llevará al cabo una versión dirigida a Empresas del Festival Latinoamericano de Instalación de Software Libre (FLISoL). El objeto es acercar el potencial del Open Source a las empresas y público en general. En el marco de este evento, daré una platica sobre Call Centers [...]]]></description>
				<content:encoded><![CDATA[<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin-left: 10px;"><g:plusone size="tall" count="1" href="http://cofradia.org/2013/05/02/flisol-empresas-y-software-libre/"></g:plusone></div><p>El día de mañana 3 de mayo del 2013, se llevará al cabo una versión dirigida a Empresas del Festival Latinoamericano de Instalación de Software Libre (FLISoL). El objeto es acercar el potencial del Open Source a las empresas y público en general.</p>
<p>En el marco de este evento, daré una platica sobre Call Centers basados en Asterisk y Open Hardware y sus posibilidades.</p>
<p>La información del evento esta en <A HREF="http://flisoldf.mx/">flisoldf.mx</A>. </p>
<p>La sede es el hotel Fiesta Inn Teatro Insurgentes. Dir. Calle Mercaderes No. 20, Col. San José Insurgentes, C.P. 03900 México D.F, Tel. 5482-9140</p>
]]></content:encoded>
			<wfw:commentRss>http://cofradia.org/2013/05/02/flisol-empresas-y-software-libre/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Photoduino: Open Hardware para control fotográfico</title>
		<link>http://cofradia.org/2013/03/24/photoduino-open-hardware-para-control-fotografico/</link>
		<comments>http://cofradia.org/2013/03/24/photoduino-open-hardware-para-control-fotografico/#comments</comments>
		<pubDate>Sun, 24 Mar 2013 06:26:40 +0000</pubDate>
		<dc:creator>El Pop</dc:creator>
				<category><![CDATA[Foto y Video]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Tecnología]]></category>

		<guid isPermaLink="false">http://cofradia.org/?p=7785</guid>
		<description><![CDATA[Uno de las cosas que más me gustan, aparte de la tecnología y el desarrollo de software, es la fotografía, lo que me llevó a usar lo primero para ayudar a lo segundo. Hace un tiempo me puse a investigar como hacer un &#8220;Time lapse&#8221; (ver Tomando fotos para crear un “Time Lapse”) y lo [...]]]></description>
				<content:encoded><![CDATA[<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin-left: 10px;"><g:plusone size="tall" count="1" href="http://cofradia.org/2013/03/24/photoduino-open-hardware-para-control-fotografico/"></g:plusone></div><p>Uno de las cosas que más me gustan, aparte de la tecnología y el desarrollo de software, es la fotografía, lo que me llevó a usar lo primero para ayudar a lo segundo.</p>
<p>Hace un tiempo me puse a investigar como hacer un &#8220;Time lapse&#8221; (ver <A HREF="http://cofradia.org/2010/09/16/tomando-fotos-para-crear-un-time-lapse/">Tomando fotos para crear un “Time Lapse”</A>) y lo primero que tuve que hacer fue comprar un intervarómetro (un equipo que activa la cámara cada cierto tiempo), el equipo que compré fue un temporizador de Canon TC-80N3 que me costó alrededor de $300 USD.</p>
<p>Al ver lo caro que era y lo realmente poco que hacía, me dí a la tarea de ver si había proyectos libres con este enfoque, y me encontré con uno realizado por @kalanda llamado <A HREF="http://photoduino.github.com/">Photoduino</A>, este es un controlador de fotografía para alta velocidad. Este está basado en la plataforma de Open Hardware <A HREF="http://www.arduino.cc/">Arduino</A> y su objetivo es crear un &#8220;shield&#8221; (placa accesoria conectable a un Arduino ONE), que permite tener control de la cámara y diversos sensores que la activan, además de ser intervarómetro.<br />
<span id="more-7785"></span><br />
<div id="attachment_7791" class="wp-caption alignnone" style="width: 310px"><a href="http://cofradia.org/wp-content/uploads/2013/03/photoduino_proto.jpg"><img src="http://cofradia.org/wp-content/uploads/2013/03/photoduino_proto-300x240.jpg" alt="Modelo del circuito de Photoduino en un protoboard" width="300" height="240" class="size-medium wp-image-7791" /></a><p class="wp-caption-text">Modelo del circuito de Photoduino en un protoboard</p></div></p>
<p>Ví los diagramas del proyecto e hice mis pininos en un protoboard, funcionó y eso me animó a contactar con @kalanda para ver si había circuitos impresos y facilitar el ensamble. Me vendió algunas placas que tardaron mucho en llegar, ya que el está en España y sólo lo manda por correo ordinario.</p>
<div id="attachment_7797" class="wp-caption alignnone" style="width: 310px"><a href="http://cofradia.org/wp-content/uploads/2013/03/photoduino_pcb2_a_a.jpg"><img src="http://cofradia.org/wp-content/uploads/2013/03/photoduino_pcb2_a_a-300x198.jpg" alt="Armado con la versión 2 del PCB" width="300" height="198" class="size-medium wp-image-7797" /></a><p class="wp-caption-text">Armado con la versión 2 del PCB</p></div>
<p>De allí armé un par de equipos con acabado &#8220;soviético&#8221;, con unas cajas de plåstico que compre en <A HREF="http://www.steren.com.mx/catalogo/category.asp?f=9&#038;sf=111&#038;c=1605">Steren</A> y soldando conectores de RCA a la placa. Sin embargo, estos PCB&#8217;s no operaban correctamente con algunas cámaras. </p>
<div id="attachment_7793" class="wp-caption alignnone" style="width: 233px"><a href="http://cofradia.org/wp-content/uploads/2013/03/photoduinos-sovietico.jpg"><img src="http://cofradia.org/wp-content/uploads/2013/03/photoduinos-sovietico-223x300.jpg" alt="Prototipo con acabado &quot;Soviético&quot;" width="223" height="300" class="size-medium wp-image-7793" /></a><p class="wp-caption-text">Prototipo con acabado &#8220;Soviético&#8221;</p></div>
<p>Con el paso del tiempo @Kalanda liberó una versión nueva de su placa, pero para mi mala fortuna, él nunca tenía disponible los PCB&#8217;s (Printed Circuit Board), así que ví que tenía los planos del PCB hechos en un CAD para electrónica llamadao <A HREF="http://www.cadsoftusa.com/">Eagle CAD</A>, de los cuales puedes generar unos archivos conocidos como &#8220;<A HREF="http://en.wikipedia.org/wiki/Gerber_format">Gerber</A>&#8220;, estos son los archivos base para la fabricación de la tarjeta.</p>
<p>Todo parecía sencillo, pero la generación correcta de estos archivos es delicada (y si te falla costosa), por lo cual me puse a investigar cómo generarlos y encontré un tutoríal realizado por <A HREF="https://www.sparkfun.com/tutorials/109">Sparkfun</A>, que describe el proceso y uso de la herramienta de cración de PCB&#8217;s. De allí extraje un archivo llamado <A HREF="http://www.sparkfun.com/tutorial/BeginningEmbedded/9-EaglePCBs/sfe-gerb274x.cam">sfe-gerb274x.cam</A>, que es le que me permitr generar los archivos de Gerber para mandar hacer el PCB.</p>
<p>Dí muchas vueltas y encontré una empresa conocida como <A HREF="http://www.pcb-mexico.com/">PCB-México</A>, me cotizarón y realizaron el trabajo, pero había un punto de decisión fuerte: mandar hacer 10 placas me costaba alrededor de $500 USD y hacer 100, me costaba $800 USD. Así que me lance a pedir 100 piezas.</p>
<p>El trabajo fue impecable, cuando recibí las placas y las revisé, me encantó. Conseguí los circuitos y empecé a soldar. Aquí me encontré con graves problemas: Muchos de los componentes de electrónica básica que se necesitan no existen en México.</p>
<div id="attachment_7795" class="wp-caption alignnone" style="width: 310px"><a href="http://cofradia.org/wp-content/uploads/2013/03/photoduino_pcb3.jpg"><img src="http://cofradia.org/wp-content/uploads/2013/03/photoduino_pcb3-300x133.jpg" alt="PCB versión 3 de Photoduino hechos en México" width="300" height="133" class="size-medium wp-image-7795" /></a><p class="wp-caption-text">PCB versión 3 de Photoduino hechos en México</p></div>
<p>Después de recorrer la calle de República del Salvador en el centro de la ciudad de México, famosa por ser la que tiene el mayor número de provedores de electrónica en el país, me puse a investigar en internet y sólo pude conseguir los componentes en <A HREF="http://mx.mouser.com/">Mouser Electronics</A>. Esta es una tienda en Texas que manda los pedidos a México. Allí conseguí la mayoría de componentes: trisistores, optoacopladores y hasta resistencias. </p>
<div id="attachment_7799" class="wp-caption alignnone" style="width: 310px"><a href="http://cofradia.org/wp-content/uploads/2013/03/photoduino_shield.jpg"><img src="http://cofradia.org/wp-content/uploads/2013/03/photoduino_shield-300x189.jpg" alt="Shield de Photoduino Versión 3 ya ensamblado" width="300" height="189" class="size-medium wp-image-7799" /></a><p class="wp-caption-text">Shield de Photoduino Versión 3 ya ensamblado</p></div>
<p>Una versión del Photoduino que quería ensamblar usaba baterías recargables de una empresa llamada <A HREF="https://www.liquidware.com/shop/show/MBP/Lithium+Backpack">Liquidware</A>, algo caras pero se ajustaban al tamaño que tenía pensado.</p>
<p>Compré los Arduinos a una empresa llamada <A HREF="http://www.330ohms.com/">330 Ohms</A> y los LCD&#8217;s los conseguí en la mencionada calle del centro. No encontré una caja que tuviera las dimensiones requeridas, así que me dí a la tarea de diseñarla, lo cual me introdujo en la aventura del corte láser.</p>
<p>Diseñé mi caja con Adobe Ilustrator siguiendo medidas milimétricas y la exporté esto a formatos de Autocad para realizar el corte. La mencionada empresa de 330 Ohms tienen el cortador láser, así que lo mande a hacer con ellos.</p>
<div id="attachment_7801" class="wp-caption alignnone" style="width: 310px"><a href="http://cofradia.org/wp-content/uploads/2013/03/photoduino_box_a.jpg"><img src="http://cofradia.org/wp-content/uploads/2013/03/photoduino_box_a-300x200.jpg" alt="Modelo inicial de la caja que diseñe" width="300" height="200" class="size-medium wp-image-7801" /></a><p class="wp-caption-text">Modelo inicial de la caja que diseñe</p></div>
<p>Las primeras cajas no tenían un ajuste perfecto, pero una vez que compré un <A HREF="http://www.homedepot.com.mx/webapp/wcs/stores/servlet/Product_10752__33063">Vernier</A> y medí con precisión, quedó una caja que liberé al dominio público bajo licencia Creative Commons en <A HREF="http://www.thingiverse.com/thing:35976">Thingiverse</A>.</p>
<div id="attachment_7802" class="wp-caption alignnone" style="width: 310px"><a href="http://cofradia.org/wp-content/uploads/2013/03/photoduino_final_box_a.jpg"><img src="http://cofradia.org/wp-content/uploads/2013/03/photoduino_final_box_a-300x227.jpg" alt="Modelo final de la caja en acrílico transparente" width="300" height="227" class="size-medium wp-image-7802" /></a><p class="wp-caption-text">Modelo final de la caja en acrílico transparente</p></div>
<p>Ahora vendo los Photoduinos ya ensamblados en <A HREF="https://store.cofradia.com">Cofradía Store</A> <img src='http://cofradia.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<div id="attachment_7804" class="wp-caption alignnone" style="width: 310px"><a href="http://cofradia.org/wp-content/uploads/2013/03/photoduino_final_box_c.jpg"><img src="http://cofradia.org/wp-content/uploads/2013/03/photoduino_final_box_c-300x150.jpg" alt="Produvto final en acrílico y MDF" width="300" height="150" class="size-medium wp-image-7804" /></a><p class="wp-caption-text">Producto final en acrílico y MDF</p></div>
<div id="attachment_7816" class="wp-caption alignnone" style="width: 310px"><a href="http://cofradia.org/wp-content/uploads/2013/03/Photoduino_drop.jpg"><img src="http://cofradia.org/wp-content/uploads/2013/03/Photoduino_drop-300x200.jpg" alt="Caída de una gota de agua tomanda usando Photoduino y una cámara Canon 60D" width="300" height="200" class="size-medium wp-image-7816" /></a><p class="wp-caption-text">Caída de una gota de agua tomanda usando Photoduino y una cámara Canon 60D</p></div>
<p>Aquí la aventura apenas empieza. Estoy viendo como armar mi propia cortadora láser y sigo un proyecto Open Source muy interesante llamado <A HREF="http://labs.nortd.com/lasersaur/">Lasersaur</A>.</p>
<p>Pero no crean que aquí acaba esto, estoy aprendiendo como fabricar mi propio láser de alta intensidad. Referencias: <A HREF="http://www.wikihow.com/Build-a-Cutting-Laser">How to Build a Cutting Laser</A> y <A HREF="Make your own CO2 laser">Make your own CO2 laser</A> <img src='http://cofradia.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Autor: Fernando “El Pop” Romo (pop at cofradia.org), twitter @El_Pop</p>
]]></content:encoded>
			<wfw:commentRss>http://cofradia.org/2013/03/24/photoduino-open-hardware-para-control-fotografico/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Diez reglas para contratar personal tecnológico</title>
		<link>http://cofradia.org/2013/03/21/diez-reglas-para-contratar-personal-tecnologico/</link>
		<comments>http://cofradia.org/2013/03/21/diez-reglas-para-contratar-personal-tecnologico/#comments</comments>
		<pubDate>Fri, 22 Mar 2013 03:58:50 +0000</pubDate>
		<dc:creator>El Pop</dc:creator>
				<category><![CDATA[Humor]]></category>
		<category><![CDATA[Programacion]]></category>
		<category><![CDATA[software libre]]></category>
		<category><![CDATA[Tecnología]]></category>

		<guid isPermaLink="false">http://cofradia.org/?p=7781</guid>
		<description><![CDATA[Bueno, esto lo publiqué en Twitter previamente, pero lo consolido para que se use de referencia para la posteridad: Reglas para contratar personal tecnológico Si llega a la entrevista trajeado&#8230; ¡córrelo! Si llega fachoso como Richard Stallman, pero bañado, puede ser candidato Si llegó y hackeó tu red WiFi para ver su mail&#8230; es un [...]]]></description>
				<content:encoded><![CDATA[<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin-left: 10px;"><g:plusone size="tall" count="1" href="http://cofradia.org/2013/03/21/diez-reglas-para-contratar-personal-tecnologico/"></g:plusone></div><p>Bueno, esto lo publiqué en Twitter previamente, pero lo consolido para que se use de referencia para la posteridad:</p>
<p><span id="more-7781"></span><br />
<strong>Reglas para contratar personal tecnológico</strong></p>
<ol>
<li>Si llega a la entrevista trajeado&#8230; ¡córrelo!</li>
<li>Si llega fachoso como Richard Stallman, pero bañado, puede ser candidato</li>
<li>Si llegó y hackeó tu red WiFi para ver su mail&#8230; es un buen candidato</li>
<li>Si presume de certificaciones Java&#8230; dígale &#8220;despues le hablaremos&#8221;. Un buen programador no presume certificaciones, te muestra código que ha escrito</li>
<li>Si no puede armar un cubo Rubik en 3 minutos, no sabe trabajar bajo presión</li>
<li>Si no juega video juegos&#8230; ¿Por qué llegó a la entrevista?</li>
<li>Si es experto en Windows&#8230; tienes el derecho y la obligación de sacarlo a patadas</li>
<li>Si es mujer, programadora, gamer y guapa, no la contrates&#8230; cásate con ella</li>
<li>Si tiene 15 años, programa y es rico pídele empleo <img src='http://cofradia.org/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </li>
<li>Si cumple 8 de las 9 reglas anteriores y cobra poco&#8230; ¡contrátalo!</li>
</ol>
<p>Así que úsenlo como base para cuando entrevisten candidatos <img src='http://cofradia.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://cofradia.org/2013/03/21/diez-reglas-para-contratar-personal-tecnologico/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Buscando un sistema para implementar mediateca</title>
		<link>http://cofradia.org/2013/03/09/buscando-un-sistema-para-implementar-mediateca/</link>
		<comments>http://cofradia.org/2013/03/09/buscando-un-sistema-para-implementar-mediateca/#comments</comments>
		<pubDate>Sat, 09 Mar 2013 19:40:53 +0000</pubDate>
		<dc:creator>LinuxNT</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Pregúntale al gurú]]></category>
		<category><![CDATA[Programacion]]></category>

		<guid isPermaLink="false">http://cofradia.org/?p=7770</guid>
		<description><![CDATA[¡Buenas tardes, Cofrades! Ando a la búsqueda de alguna sugerencia que me permita implementar una aplicación para el manejo de archivos de documentos, audio y video. El caso es el siguiente: Una institución me ha hecho la encomienda de que busque la manera de publicar el acervo de la misma hacia la Internet. En un [...]]]></description>
				<content:encoded><![CDATA[<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin-left: 10px;"><g:plusone size="tall" count="1" href="http://cofradia.org/2013/03/09/buscando-un-sistema-para-implementar-mediateca/"></g:plusone></div><p>¡Buenas tardes, Cofrades!</p>
<p>Ando a la búsqueda de alguna sugerencia que me permita implementar una aplicación para el manejo de archivos de documentos, audio y video.</p>
<p>El caso es el siguiente: Una institución me ha hecho la encomienda de que busque la manera de publicar el acervo de la misma hacia la Internet. En un principio, lo ponían como una fácil tarea, lo cual se vino abajo cuando vi la cantidad de documentos que hay que organizar: la frisa de 50 GB entre documentos academicos, libros, programas de radio y programas de televisión.<br />
<span id="more-7770"></span><br />
El caso es que me piden que el sistema permita establecer una biblioteca digital que pueda accederse y organizarse con facilidad. A la vez, desean que tenga un buscador que permita localizar los documentos por rama, tema, categoría, etc.</p>
<p>Buscan algo así: <a href="http://dspace.unav.es/dspace/">http://dspace.unav.es/dspace/</a></p>
<p>De hecho, alguien sugirió que para evadir el problema del alojamiento, debieramos buscar una aplicación que pueda integrarse a Mega o a Dropbox (una sugerencia que hicieron en la junta).</p>
<p>Pues bien, ya me he dado vueltas por Open Source CMS y SourceForge además de Free Code y no he visto algo claro. La búsqueda la realizo por el concepto de  &#8220;digital asset management system&#8221; y son solo dSpace y EnterMedia lo que me trae, siendo el segundo bastante enfocado al uso Interno.</p>
<p>Espero puedan sugerirme algunas aplicaciones para realizar pruebas. La idea es ponerlo en un servidor dedicado (o virtualizado) y que en ese mismo servidor estén alojados los contenidos.</p>
<p>De antemano, gracias.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://cofradia.org/2013/03/09/buscando-un-sistema-para-implementar-mediateca/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Es importante verificar la caducidad de los certificados del SAT</title>
		<link>http://cofradia.org/2013/03/06/es-importante-verificar-la-caducidad-de-los-certificados-del-sat/</link>
		<comments>http://cofradia.org/2013/03/06/es-importante-verificar-la-caducidad-de-los-certificados-del-sat/#comments</comments>
		<pubDate>Wed, 06 Mar 2013 05:03:57 +0000</pubDate>
		<dc:creator>El Pop</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[Programacion]]></category>
		<category><![CDATA[Tips técnicos]]></category>

		<guid isPermaLink="false">http://cofradia.org/?p=7761</guid>
		<description><![CDATA[Pues al hacer mi reporte mensual ví que el sistema del SAT me denegó el servicio ya que mi FIEL (Firma electrónica avanzada) caducó hace 3 días. Ahora tengo que hacer un trámite engorroso en el SAT para que me den la renovación, siendo que si la FIEl está aún vigente, es muy fácil el [...]]]></description>
				<content:encoded><![CDATA[<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin-left: 10px;"><g:plusone size="tall" count="1" href="http://cofradia.org/2013/03/06/es-importante-verificar-la-caducidad-de-los-certificados-del-sat/"></g:plusone></div><p>Pues al hacer mi reporte mensual ví que el sistema del SAT me denegó el servicio ya que mi FIEL (Firma electrónica avanzada) caducó hace 3 días. Ahora tengo que hacer un trámite engorroso en el SAT para que me den la renovación, siendo que si la FIEl está aún vigente, es muy fácil el trámite de reposición.</p>
<p>Por eso les dejo un pequeño programa que hice en Perl para verificar los datos de sus certificados del SAT (y de cualquier certificado que use x509):<br />
<span id="more-7761"></span></p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/usr/bin/perl</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">use</span> strict<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> File<span style="color: #339933;">::</span><span style="color: #006600;">Copy</span><span style="color: #339933;">;</span> 
<span style="color: #000000; font-weight: bold;">use</span> File<span style="color: #339933;">::</span><span style="color: #006600;">Path</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> SAT_Path <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$file</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">return</span> <span style="color: #000066;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$file</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">6</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span>
           <span style="color: #ff0000;">'/'</span> <span style="color: #339933;">.</span>
           <span style="color: #000066;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$file</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">6</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">6</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span>
           <span style="color: #ff0000;">'/'</span> <span style="color: #339933;">.</span>
           <span style="color: #000066;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$file</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">12</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span>
           <span style="color: #ff0000;">'/'</span> <span style="color: #339933;">.</span>
           <span style="color: #000066;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$file</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">14</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span>
           <span style="color: #ff0000;">'/'</span> <span style="color: #339933;">.</span>
           <span style="color: #000066;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$file</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">16</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span> <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: #000000; font-weight: bold;">sub</span> Cert_Info <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$cert_file</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$cert_info</span> <span style="color: #339933;">=</span> <span style="color: #000066;">qx</span><span style="color: #009900;">&#40;</span>openssl x509 <span style="color: #339933;">-</span>inform DER <span style="color: #339933;">-</span>in <span style="color: #0000ff;">$cert_file</span> <span style="color: #339933;">-</span>serial <span style="color: #339933;">-</span>subject <span style="color: #339933;">-</span>startdate <span style="color: #339933;">-</span>enddate <span style="color: #339933;">-</span>noout<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$cert_info</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">s/\\xD1/Ñ/g</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$cert_info</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">s/\\xF1/ñ/g</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$cert_info</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">s/\\xC1/Á/g</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$cert_info</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">s/\\xC9/É/g</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$cert_info</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">s/\\xCD/Í/g</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$cert_info</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">s/\\xD3/Ó/g</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$cert_info</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">s/\\xDA/Ú/g</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$cert_info</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">s/\\xE1/á/g</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$cert_info</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">s/\\xE9/é/g</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$cert_info</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">s/\\xED/í/g</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$cert_info</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">s/\\xF3/ó/g</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$cert_info</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">s/\\xFA/ú/g</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$serial_cn</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$cert_info</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">/subject\=.*\/CN=(.*?)(\/OU\=|\/O\=|\/name\=|\/serialNumber\=|\/x500UniqueIdentifier\=|\n)/</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$rfc</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$cert_info</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">/subject\=.*\/x500UniqueIdentifier=(.*?)(\/CN\=|\/OU\=|\/O\=|\/name\=|\/serialNumber\=|\n)/</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$curp</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$cert_info</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">/subject\=.*\/serialNumber=(.*?)(\/CN\=|\/OU\=|\/O\=|\/name\=|\/x500UniqueIdentifier\=|\n)/</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$sucursal</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$cert_info</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">/subject.*\/OU=(.*?)(\/CN\=|\/O\=|\/name\=|\/serialNumber\=|\/x500UniqueIdentifier\=|\n)/</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$curp</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">s/\s//g</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$curp</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">s/^\///</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$rfc_rep</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">''</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$rfc</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">s/\s//g</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$rfc</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">/\//</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$rfc</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$rfc_rep</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #000066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/\//</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$rfc</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$serial_hex</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$cert_info</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">/serial\=(.*)/</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$notBefore</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$cert_info</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">/notBefore=(.*)/</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$notAfter</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$cert_info</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">/notAfter=(.*)/</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$public_key</span> <span style="color: #339933;">=</span> <span style="color: #000066;">qx</span><span style="color: #009900;">&#40;</span>openssl x509 <span style="color: #339933;">-</span>inform DER <span style="color: #339933;">-</span>in <span style="color: #0000ff;">$cert_file</span> <span style="color: #339933;">-</span>noout <span style="color: #339933;">-</span>pubkey<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$certificate</span> <span style="color: #339933;">=</span> <span style="color: #000066;">qx</span><span style="color: #009900;">&#40;</span>openssl x509 <span style="color: #339933;">-</span>inform DER <span style="color: #339933;">-</span>in <span style="color: #0000ff;">$cert_file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$serial</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">''</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@pairs</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$serial_hex</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">/(\d\d)/g</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">foreach</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$hex</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">@pairs</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #0000ff;">$serial</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$serial</span> <span style="color: #339933;">.</span> <span style="color: #000066;">chr</span><span style="color: #009900;">&#40;</span><span style="color: #000066;">hex</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$hex</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: #000066;">print</span> <span style="color: #ff0000;">&quot;-&quot;</span> x <span style="color: #cc66cc;">65</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;RFC        =&gt; $rfc<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;Serial     =&gt; $serial<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;Nombre     =&gt; $serial_cn<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;RFC Rep.   =&gt; $rfc_rep<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;CURP       =&gt; $curp<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;sucursal   =&gt; $sucursal<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;Begin date =&gt; $notBefore<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;End date   =&gt; $notAfter<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;-&quot;</span> x <span style="color: #cc66cc;">65</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;$public_key<span style="color: #000099; font-weight: bold;">\n</span>$certificate<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;SAT file:  =&gt; ftp://ftp2.sat.gob.mx/Certificados/FEA/&quot;</span> <span style="color: #339933;">.</span> SAT_Path<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$serial</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #ff0000;">&quot;$serial.cer<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000066;">chomp</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@Fields</span> <span style="color: #339933;">=</span> <span style="color: #000066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/\|/</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$_</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$ARGV</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">/\.cer/</span><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: #339933;">-</span>e <span style="color: #ff0000;">&quot;$ARGV[0]&quot;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        Cert_Info<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;$ARGV[0]&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Para usarlo sol le dan:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>cert_info.pl 00001000000103469712.cer</pre></td></tr></table></div>

<p>y les dará la siguiente información:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="text" style="font-family:monospace;">-----------------------------------------------------------------
RFC        =&gt; CAJU641218Q96
Serial     =&gt; 00001000000103469712
Nombre     =&gt; CAMANEI SA DE CV
RFC Rep.   =&gt; CAJU641218Q96
CURP       =&gt; CAJU641218HDFMLR54
sucursal   =&gt; 
Begin date =&gt; Dec  3 17:48:18 2010 GMT
End date   =&gt; Mar  2 17:48:18 2013 GMT
-----------------------------------------------------------------
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCqIIggmHT4qclfBRsIO7fzgDUd
iYcSF46wqFu1cetJU+O/2G/E5o2LBj9dVyBwPxes5QvqcLxZUakXZH14EDAGlHm0
we5fr034OM/Mqj18o2dpSX3HKZyHnTgyaIxWVP9zSPrm2L4lwSdFS29kkQxx+VzE
ewj0b1mJAtghZZLM5QIDAQAC
-----END PUBLIC KEY-----
&nbsp;
-----BEGIN CERTIFICATE-----
MIIENzCAAx+gAwIBAgIUMDAwDDEwMDAwMDAxMDIyOTY0ODIwDQYJKoZIhvcNAQEF
BQAwggE2MTgwNgYDVQQDDC9BLkMuIGRlbCBTZXJ2aWNpbyBkZSBBZG1pbmlzdHJh
Y2nDs24gVHJpYnV0YXJpYTEvMC0GA1UECgwmU2VydmljaW8gZGUgQWRtaW5pc3Ry
YWNpw7NuIFRyaWJ1dGFyaWExHzAdBgkqhkiG9w0BCQEWEGFjb2RzQHNhdC5nb2Iu
bXgxJjAkBgNVBAkMHUF2LiBIaWRhbGdvIDc3LCBDb2wuIEd1ZXJyZXJvMQ4wDAYD
VQQRDAUwNjMwMDELMAkGA1UEBhMCTVgxGTAXBgNVBAgMEERpc3RyaXRvIEZlZGVy
YWwxEzARBgNVBAcMCkN1YXVodGVtb2MxMzAxBgkqhkiG9w0BCQIMJFJlc3BvbnNh
YmxlOiBGZXJuYW5kbyBNYXJ0w61uZXogQ29zczAeFw0xMDEyMDMxNzQ4MThaFw0x
MzAzMDIxNzQ4MThaMIGlMRkwFwYDVQQDExBJTkNVVk9YIFNBIERFIENWMRkwFwYD
VQQpExBJTkNVVk9YIFNBIERFIENWMRkwFwYDVQQKExBJTkNVVk9YIFNBIERFIENW
MQswCQYDVQQGEwJNWDElMCMGA1UELRMcSU5DMTAxMTA5UTM2IC8gUk9BRjY0MTIx
N0s5NDEeMBwGA1UEBRMVIC8gUk9BRjY0MTIxN0hERk1MUjA4MIGfMA0GCSqGSIb3
DQEBAQUAA4GNADCBiQKBgQCqIIgggHT4qclfBRsIO7fzgDUdiYcSF46wqFu1cetJ
U+O/2G/E5o2LBj9dVyBwPxes5QvqcLxZUakXZH14EDAGlHm0we5fr034OM/Mqj18
o2dpSX3HKZyHnTgyaIxWVP9zSPrm2L4lwSdFS29kkQxx+VzEewj0b1mJAtghZuLM
5QIDAQABo08wTTAMBgNVHRMBAf8EAjAAMAsGA1UdDwQEAwID2DARBglghkgBhvhC
AQEEBAMCBaAwHQYDVR0lBBYwFAYIKwYBBQUHAwQGCCsGAQUFBwMCMA0GCSqGSIb3
DQEBBQUAA4IBAQBLcKX2vawNdSjOZoA9lX5+KdBMCuKV74y4gQNnC+xNrN0Srjlr
1T7kwqdQJvQmz29RV9zc0dX7riM1S0xCrSzSrang9B6Actipz8QBFyCYvw1FDEZi
YOf89Z4pA7YlhuNOI7+nDgfJa3DXrW5lB2totGPZ82dfSSaSB5NHJGeUTqESel0G
7GpGowO+tEz8KAky54lAuod8kPlkEpo5rh2K3zFeFLHoG6MYIcFAhirt3b13ABuq
2ZWzcTaht87bCam1H4zMAOZF5xTHCfBNN7NSV+yAeb0Ssp48N6nstsZBIvIKF7JV
jW8PcylnhWsdW/3IQ7ENXE1S7fjKstDfkCdB
-----END CERTIFICATE-----</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://cofradia.org/2013/03/06/es-importante-verificar-la-caducidad-de-los-certificados-del-sat/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>¿Cómo vender software de código abierto en México?</title>
		<link>http://cofradia.org/2013/02/28/como-vender-software-de-codigo-abierto-en-mexico/</link>
		<comments>http://cofradia.org/2013/02/28/como-vender-software-de-codigo-abierto-en-mexico/#comments</comments>
		<pubDate>Fri, 01 Mar 2013 01:22:53 +0000</pubDate>
		<dc:creator>mahomedalid</dc:creator>
				<category><![CDATA[Paranoia Fan Club]]></category>
		<category><![CDATA[Pregúntale al gurú]]></category>
		<category><![CDATA[Programacion]]></category>
		<category><![CDATA[Tecnología]]></category>

		<guid isPermaLink="false">http://cofradia.org/?p=7746</guid>
		<description><![CDATA[Probablemente esta pregunta se ha hecho anteriormente pero no he encontrado las respuestas que requiero sobre todo en el ámbito legal. Mi pregunta es simple ¿cómo vender software de código abierto en México? Tengo actualmente un programita que vamos a vender a otra compañía, es una utilería que realiza ciertas operaciones en una base de [...]]]></description>
				<content:encoded><![CDATA[<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin-left: 10px;"><g:plusone size="tall" count="1" href="http://cofradia.org/2013/02/28/como-vender-software-de-codigo-abierto-en-mexico/"></g:plusone></div><p>Probablemente esta pregunta se ha hecho anteriormente pero no he encontrado las respuestas que requiero sobre todo en el ámbito legal. Mi pregunta es simple ¿cómo vender software de código abierto en México?</p>
<p>Tengo actualmente un programita que vamos a vender a otra compañía, es una utilería que realiza ciertas operaciones en una base de datos de un programa más grande. Queremos vender a esta compañía el programa acompañado de su código fuente, pero no queremos que está al final nos meta alguna demanda o algo para prohibirnos vender este software. Mis preguntas específicas:</p>
<p>- ¿Tengo que registrarlo en Indautor?</p>
<p>- ¿Cómo puedo demostrar que el software lo hice yo?</p>
<p>- ¿Qué tipo de contrato se tiene que realizar?</p>
<p>La idea sería liberarlo en una licencia simple no restrictiva como MIT.</p>
]]></content:encoded>
			<wfw:commentRss>http://cofradia.org/2013/02/28/como-vender-software-de-codigo-abierto-en-mexico/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Convocatoria para desarrollar plataforma de participación ciudadana</title>
		<link>http://cofradia.org/2013/02/16/convocatoria-para-desarrollar-plataforma-de-participacion-ciudadana/</link>
		<comments>http://cofradia.org/2013/02/16/convocatoria-para-desarrollar-plataforma-de-participacion-ciudadana/#comments</comments>
		<pubDate>Sat, 16 Feb 2013 20:22:01 +0000</pubDate>
		<dc:creator>miguelbo</dc:creator>
				<category><![CDATA[Convocatorias]]></category>
		<category><![CDATA[Cultura Libre]]></category>
		<category><![CDATA[Política]]></category>
		<category><![CDATA[Redes sociales]]></category>
		<category><![CDATA[software libre]]></category>

		<guid isPermaLink="false">http://cofradia.org/?p=7725</guid>
		<description><![CDATA[Estimados cofrades, Los invitamos a que se sumen a un esfuerzo que estamos arrancando para tratar de cambiar la situación política del país, denominado Democracia 2.0. La idea es desarrollar una plataforma web, obviamente liberada como software libre, en la que cualquier ciudadano pueda participar para trabajar colaborativamente en el desarrollo de iniciativas de ley [...]]]></description>
				<content:encoded><![CDATA[<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin-left: 10px;"><g:plusone size="tall" count="1" href="http://cofradia.org/2013/02/16/convocatoria-para-desarrollar-plataforma-de-participacion-ciudadana/"></g:plusone></div><p>Estimados cofrades,</p>
<p>Los invitamos a que se sumen a un esfuerzo que estamos arrancando para tratar de cambiar la situación política del país, denominado Democracia 2.0. La idea es desarrollar una plataforma web, obviamente liberada como software libre, en la que cualquier ciudadano pueda participar para trabajar colaborativamente en el desarrollo de iniciativas de ley y otras propuestas para mejorar su comunidad. Para poder tener incidencia política, hemos iniciado el proceso de registro como partido político ante el IFE, pero no pretendemos ser un simple partido político más, sino que buscamos cambiar de fondo la forma en que se hace la política en México: queremos extrapolar la metodología de desarrollo del software libre a la política&#8230;<br />
<span id="more-7725"></span><br />
Imaginen una especie de GitHub pero que en lugar de alojar proyectos de software aloje proyectos de cualquier índole que puedan ser desde iniciativas de ley hasta proyectos sociales. Cada proyecto tendrá a su disposición herramientas de trabajo colaborativo tipo wiki con control de versiones, foros de discusión de nueva generación (algo tipo Discourse.org) y un chat. Además esta plataforma contará con una red social interna con la que se pretende que los usuarios puedan difundir viralmente los proyectos de su interés. Cuando un proyecto o iniciativa de ley haya madurado lo suficiente, el sistema permitirá que sea sometido a votación general entre todos los usuarios para su aprobación. De ser aprobado, los diputados y senadores que tenga Democracia 2.0 tendrán la obligación de presentarlo y defenderlo en el Congreso de la Unión. Este sistema también permitirá que los usuarios puedan nominar y votar por los ciudadanos de su predilección para que se les otorguen las candidaturas de Democracia 2.0. Sin embargo, los candidatos elegidos no tendrán voz ni voto propio, sino que serán simples voceros encargados de llevar al Congreso las decisiones que se tomen en la plataforma web, por lo que en caso de ganar tendrán que devolver la mayor parte del sueldo que reciban, excepto lo que los usuarios de la plataforma consideren que sea una justa retribución por los dos días a la semana que tendrán que asistir a las sesiones del Congreso.</p>
<p>Por otro lado, la plataforma que desarrollemos tendrá un sistema de contabilidad y auditoría que publique en tiempo real toda la información contable de Democracia 2.0 (incluyendo saldos y transferencias de sus cuentas bancarias) para que pueda ser revisada por cualquier persona. Pretendemos que sea un sistema de contabilidad colectiva que funcione de forma similar al desarrollo de software libre, solo que en lugar de buscar bugs, los usuarios buscarán irregularidades en las cuentas y también podrán decidir a dónde se van a destinar los recursos que el IFE otorgue a Democracia 2.0 en caso de alcanzar el registro como partido. Los usuarios podrán decidir si este dinero se debe devolver, si se debe utilizar para financiar alguno de los proyectos que se propongan en la plataforma (algo tipo Kickstarter pero con dinero público), o si se deben utilizar en cualquier otra cosa.</p>
<p>Este es un experimento que si se consolida y se logran los suficientes lugares en el Congreso, a mediano plazo se podría transformar la forma en que funciona el Poder Legislativo, para que en lugar de tener diputados y senadores que en teoría se supone que nos representan pero que en la práctica obedecen a intereses ajenos a la ciudadanía; cada ciudadano se pueda representar a sí mismo y pueda elaborar y votar las iniciativas y reformas de su interés.</p>
<p>Posteriormente, a largo plazo y si los ciudadanos así lo deciden mediante la plataforma, también se podría derogar el sistema de partidos políticos para que sea a través de esta plataforma web donde los ciudadanos se agrupen con otros ciudadanos afines a su ideología para proponer y votar por los candidatos a alcalde, gobernador y presidente de su elección (los diputados y senadores ya no deberían existir llegados a este punto).</p>
<p>Como pueden ver, es un proyecto bastante ambicioso, por lo que convocamos a todos los programadores amantes del software libre que estén interesados en rescatar al país de la partidocracia que lo tiene secuestrado.</p>
<p>Los invitamos a que visiten nuestra página web:</p>
<p>http://www.d20.org.mx</p>
<p>Y que nos sigan en Twitter: @d20mx</p>
<p>Si están interesados en participar en el desarrollo de esta plataforma, pónganse en contacto conmigo. Saludos cordiales,</p>
<p>&nbsp;</p>
<p>Atentamente,</p>
<p>Miguel Barousse Ordóñez<br />
miguel (en) d20 (punto) org (punto) mx</p>
]]></content:encoded>
			<wfw:commentRss>http://cofradia.org/2013/02/16/convocatoria-para-desarrollar-plataforma-de-participacion-ciudadana/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Este es el cerebro que toma las decisiones más importantes del pais.</title>
		<link>http://cofradia.org/2013/02/08/este-es-el-cerebro-que-toma-las-decisiones-mas-importantes-del-pais/</link>
		<comments>http://cofradia.org/2013/02/08/este-es-el-cerebro-que-toma-las-decisiones-mas-importantes-del-pais/#comments</comments>
		<pubDate>Fri, 08 Feb 2013 20:01:12 +0000</pubDate>
		<dc:creator>propositivo</dc:creator>
				<category><![CDATA[Opinión]]></category>
		<category><![CDATA[Política]]></category>

		<guid isPermaLink="false">http://cofradia.org/?p=7709</guid>
		<description><![CDATA[Factor decisivo para tomar las decisiones más importantes que nos afectan a todos los mexicanos. http://mx.noticias.yahoo.com/blogs/corte-de-caja/crystal-tovar&#8211;la-diputada-con-la-minifalda-m%C3%A1s-corta-141146540.html]]></description>
				<content:encoded><![CDATA[<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin-left: 10px;"><g:plusone size="tall" count="1" href="http://cofradia.org/2013/02/08/este-es-el-cerebro-que-toma-las-decisiones-mas-importantes-del-pais/"></g:plusone></div><p>Factor decisivo para tomar las decisiones más importantes que nos afectan a todos los mexicanos.</p>
<p>http://mx.noticias.yahoo.com/blogs/corte-de-caja/crystal-tovar&#8211;la-diputada-con-la-minifalda-m%C3%A1s-corta-141146540.html</p>
]]></content:encoded>
			<wfw:commentRss>http://cofradia.org/2013/02/08/este-es-el-cerebro-que-toma-las-decisiones-mas-importantes-del-pais/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
