<?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>Jkx@home</title>
	<atom:link href="http://www.larsen-b.com/feed" rel="self" type="application/rss+xml" />
	<link>http://www.larsen-b.com</link>
	<description>Titanium Exposé</description>
	<lastBuildDate>Sat, 11 May 2013 00:28:17 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5</generator>
		<item>
		<title>Howto : Change Spotify font size (for 42&#8243; TV display)</title>
		<link>http://www.larsen-b.com/Article/446.html</link>
		<comments>http://www.larsen-b.com/Article/446.html#comments</comments>
		<pubDate>Wed, 16 Jan 2013 13:48:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Hifi]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[spotify]]></category>

		<guid isPermaLink="false">http://www.larsen-b.com/?p=446</guid>
		<description><![CDATA[I use Spotify for my every day listening, and I decided to use it on a big screen : My 42&#8243; LCD TV. Simply launch Spotify in a one-line .xinitrc script. It fit perfectly in full screen mode without any tweak. But &#8230; <a href="http://www.larsen-b.com/Article/446.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>I use <a title="spotify.com" href="http://www.spotify.com">Spotify</a> for my every day listening, and I decided to use it on a big screen : My 42&#8243; LCD TV. Simply launch Spotify in a one-line .xinitrc script. It fit perfectly in full screen mode without any tweak. But of course nothing is perfect,  we have to live with a very small font on a such big screen. Spotify use a skin for the client app, so changing QT4 fonts doesn&#8217;t change anything, we have to fix the skin directly.</p>
<p>So, first step : search the file <em>resources.zip</em> (in <em>/opt/spotify/spotify-client/Data/</em> on Debian). Extract the file <strong>skin.xml</strong>. In this file, search for line like this.</p>
<pre>&lt;font ci="FriendsListFont" color="#dddddd" shadow="#333333" size="11" /&gt;</pre>
<p>So change all font sizes, save the file, re-pack the ressources file .. and Voila. You can fix this manually (or with a special XML editor), but the file contain 245 font definitions. I decided to fix with a <a href="http://www.python.org">Python</a> script.</p>
<pre>
<strong>import</strong> <font color="#2040a0">xml</font>.<font color="#2040a0">etree</font>.<font color="#2040a0">ElementTree</font> <font color="#2040a0">as</font> <font color="#2040a0">xml</font>

<font color="#2040a0">tree</font> <font color="4444FF">=</font> <font color="#2040a0">xml</font>.<font color="#2040a0">parse</font><font color="4444FF">(</font><font color="#008000">&quot;./skin.xml&quot;</font><font color="4444FF">)</font>
<font color="#2040a0">root</font> <font color="4444FF">=</font> <font color="#2040a0">tree</font>.<font color="#2040a0">getroot</font><font color="4444FF">(</font><font color="4444FF">)</font>

<strong>for</strong> <font color="#2040a0">f</font> <strong>in</strong> <font color="#2040a0">root</font>.<font color="#2040a0">findall</font><font color="4444FF">(</font><font color="#008000">'font'</font><font color="4444FF">)</font><font color="4444FF">:</font>
	<font color="#2040a0">taille</font> <font color="4444FF">=</font> <font color="#2040a0">f</font>.<font color="#2040a0">get</font><font color="4444FF">(</font><font color="#008000">'size'</font><font color="4444FF">)</font>
	<strong>if</strong> <font color="#2040a0">taille</font><font color="4444FF">:</font>
		<font color="#2040a0">taille</font> <font color="4444FF">=</font> <font color="#2040a0">int</font><font color="4444FF">(</font><font color="#2040a0">taille</font><font color="4444FF">)</font> <font color="4444FF">+</font> <font color="#FF0000">4</font>
		<font color="#2040a0">f</font>.<font color="#2040a0">set</font><font color="4444FF">(</font><font color="#008000">'size'</font>,<font color="#2040a0">str</font><font color="4444FF">(</font><font color="#2040a0">taille</font><font color="4444FF">)</font><font color="4444FF">)</font>


<font color="#2040a0">file</font> <font color="4444FF">=</font> <font color="#2040a0">open</font><font color="4444FF">(</font><font color="#008000">&quot;new_skin.xml&quot;</font>, <font color="#008000">'w'</font><font color="4444FF">)</font>

<font color="#2040a0">xml</font>.<font color="#2040a0">ElementTree</font><font color="4444FF">(</font><font color="#2040a0">root</font><font color="4444FF">)</font>.<font color="#2040a0">write</font><font color="4444FF">(</font><font color="#2040a0">file</font><font color="4444FF">)</font>

</pre>
<p>Let&#8217;s try this new skin :  <a style="font-style: normal; line-height: 24px; text-decoration: underline;" href="http://jkx.larsen-b.com/gallery/blog/big_spotify?full=1"><img class="alignnone" alt="" src="http://jkx.larsen-b.com/photos/blog/big_spotify.sized.jpg" width="640" height="433" /></a></p>
<p>This should be a easier for the big screen :)</p>
<p><strong>/Enjoy music</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.larsen-b.com/Article/446.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress update</title>
		<link>http://www.larsen-b.com/Article/441.html</link>
		<comments>http://www.larsen-b.com/Article/441.html#comments</comments>
		<pubDate>Sun, 30 Dec 2012 22:45:27 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Blog]]></category>

		<guid isPermaLink="false">http://www.larsen-b.com/?p=441</guid>
		<description><![CDATA[Just installed the new wordpress 3.5 version. Everything seems to be fine right now. Feel free to post a comment if you see something wrong. Switching to a new theme is a pure nightmare, I hate this stuff (editing PHP file, &#8230; <a href="http://www.larsen-b.com/Article/441.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Just installed the new <a href="http://www.wordpress.org">wordpress</a> 3.5 version. Everything seems to be fine right now. Feel free to post a comment if you see something wrong. Switching to a new theme is a pure nightmare, I hate this stuff (editing PHP file, testing, adding google adsense &#8230;) grr</p>
<p>That&#8217;s enough !</p>
]]></content:encoded>
			<wfw:commentRss>http://www.larsen-b.com/Article/441.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Change the default sound card in Spotify : Alsa + Monkey Patching</title>
		<link>http://www.larsen-b.com/Article/425.html</link>
		<comments>http://www.larsen-b.com/Article/425.html#comments</comments>
		<pubDate>Sat, 08 Dec 2012 13:12:27 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Unix]]></category>
		<category><![CDATA[alsa]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[spotify]]></category>

		<guid isPermaLink="false">http://www.larsen-b.com/?p=425</guid>
		<description><![CDATA[I&#8217;m a long time Spotify user right now. I decided to opt for a unlimited account due to the price. The main issue : Spotify for Linux is a closed source software, doesn&#8217;t allow the user to change the sound &#8230; <a href="http://www.larsen-b.com/Article/425.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>I&#8217;m a long time <a href="http://www.spotify.com">Spotify</a> user right now. I decided to opt for a unlimited account due to the price. The main issue : Spotify for Linux is a closed source software, doesn&#8217;t allow the user to change the sound card and I want to use my <a href="http://www.larsen-b.com/Article/414.html">almost finished USB DAC</a>.</p>
<p>In fact, if you use <a href="http://jackaudio.org/">Jackd</a> (and perhaps Pulse) you can change the sound card used by Spotify, but this is overkill for my needs (mainly cause, I use Spotify on a litte old netbook and Jackd is a nightmare to configure)</p>
<p>After some strace dump, Alsa (libasound2) source reading, I decided to fix it by myself. Let&#8217;s go for some <a href="http://en.wikipedia.org/wiki/Monkey_patch">Monkey Patching</a>. Monkey patching on closed source binary isn&#8217;t that easy, the hard step : find the right function to hack. Here the<a href="http://equalarea.com/paul/alsa-audio.html"> Alsa tutorial</a> come to rescue (ldd of course too). So we need to modify the <em>snd_pcm_open</em> call.</p>
<p>Let&#8217;s give it a try : First we need to dynamically re-route this call to a wrapper. The easier way to do this, is to build a special library and to force Spotify to use the wrapper with an <a href="http://en.wikipedia.org/wiki/Dynamic_linker">LD_PRELOAD</a> hack. (see code below). In fact, Spotify call the <em>snd_pcm_open</em> with <em>name=&#8221;default&#8221;</em> which is the default sound card, so we can change this to &#8220;usb&#8221; for example, and fix the .asoundrc to point &#8220;usb&#8221; sound card to the right hardware card.</p>
<p>That&#8217;s enough, let&#8217;s code :</p>
<pre>
<font color="0000ff"><strong>#define _GNU_SOURCE</strong></font>

<font color="0000ff"><strong>#include <font color="#008000">&lt;dlfcn.h&gt;</font></strong></font>
<font color="0000ff"><strong>#include <font color="#008000">&lt;stdio.h&gt;</font></strong></font>
<font color="0000ff"><strong>#include <font color="#008000">&lt;alsa/asoundlib.h&gt;</font></strong></font>

<strong>static</strong> <strong>int</strong> <font color="4444FF">(</font><font color="4444FF">*</font><font color="#2040a0">wrap_snd_pcm_open</font><font color="4444FF">)</font><font color="4444FF">(</font><font color="#2040a0">snd_pcm_t</font> <font color="4444FF">*</font><font color="4444FF">*</font><font color="#2040a0">pcm</font>, <strong>const</strong> <strong>char</strong> <font color="4444FF">*</font><font color="#2040a0">name</font>, <font color="#2040a0">snd_pcm_stream_t</font> <font color="#2040a0">stream</font>, <strong>int</strong> <font color="#2040a0">mode</font><font color="4444FF">)</font> <font color="4444FF">=</font> <font color="#2040a0">NULL</font><font color="4444FF">;</font>

<strong>void</strong> <font color="4444FF">*</font> <font color="#2040a0">wrap</font><font color="4444FF">(</font><strong>void</strong> <font color="4444FF">*</font> <font color="#2040a0">func</font>,<strong>char</strong> <font color="4444FF">*</font><font color="#2040a0">name</font><font color="4444FF">)</font>
<font color="4444FF"><strong>{</strong></font>
    <strong>char</strong> <font color="4444FF">*</font><font color="#2040a0">msg</font><font color="4444FF">;</font>
    <strong>if</strong> <font color="4444FF">(</font><font color="#2040a0">func</font> <font color="4444FF">=</font><font color="4444FF">=</font> <font color="#2040a0">NULL</font><font color="4444FF">)</font> <font color="4444FF"><strong>{</strong></font>
        <font color="#2040a0">func</font> <font color="4444FF">=</font> <font color="#2040a0">dlsym</font><font color="4444FF">(</font><font color="#2040a0">RTLD_NEXT</font>, <font color="#2040a0">name</font><font color="4444FF">)</font><font color="4444FF">;</font>
        <font color="#2040a0">fprintf</font><font color="4444FF">(</font><font color="#2040a0">stderr</font>, <font color="#008000">&quot;** wrapping %s =&gt;  %p<font color="#77dd77">\n</font>&quot;</font>, <font color="#2040a0">name</font>,<font color="#2040a0">func</font><font color="4444FF">)</font><font color="4444FF">;</font>
        <strong>if</strong> <font color="4444FF">(</font><font color="4444FF">(</font><font color="#2040a0">msg</font> <font color="4444FF">=</font> <font color="#2040a0">dlerror</font><font color="4444FF">(</font><font color="4444FF">)</font><font color="4444FF">)</font> <font color="4444FF">!</font><font color="4444FF">=</font> <font color="#2040a0">NULL</font><font color="4444FF">)</font> <font color="4444FF"><strong>{</strong></font>
            <font color="#2040a0">fprintf</font><font color="4444FF">(</font><font color="#2040a0">stderr</font>, <font color="#008000">&quot;** %s: dlopen failed : %s<font color="#77dd77">\n</font>&quot;</font>, <font color="#2040a0">name</font>,<font color="#2040a0">msg</font><font color="4444FF">)</font><font color="4444FF">;</font>
            <font color="#2040a0">exit</font><font color="4444FF">(</font><font color="#FF0000">1</font><font color="4444FF">)</font><font color="4444FF">;</font>
        <font color="4444FF"><strong>}</strong></font> <strong>else</strong> <font color="4444FF"><strong>{</strong></font>
            <font color="#2040a0">fprintf</font><font color="4444FF">(</font><font color="#2040a0">stderr</font>, <font color="#008000">&quot;** %s: wrapping done<font color="#77dd77">\n</font>&quot;</font>,<font color="#2040a0">name</font><font color="4444FF">)</font><font color="4444FF">;</font>
        <font color="4444FF"><strong>}</strong></font>
    <font color="4444FF"><strong>}</strong></font>
    <strong>return</strong> <font color="#2040a0">func</font><font color="4444FF">;</font>
<font color="4444FF"><strong>}</strong></font>

<strong>int</strong> <font color="#2040a0">snd_pcm_open</font><font color="4444FF">(</font><font color="#2040a0">snd_pcm_t</font> <font color="4444FF">*</font><font color="4444FF">*</font><font color="#2040a0">pcm</font>, <strong>const</strong> <strong>char</strong> <font color="4444FF">*</font><font color="#2040a0">name</font>, <font color="#2040a0">snd_pcm_stream_t</font> <font color="#2040a0">stream</font>, <strong>int</strong> <font color="#2040a0">mode</font><font color="4444FF">)</font>
<font color="4444FF"><strong>{</strong></font>
    <strong>int</strong> <font color="#2040a0">temp</font><font color="4444FF">;</font>

    <font color="#2040a0">sprintf</font><font color="4444FF">(</font><font color="#2040a0">name</font>,<font color="#008000">&quot;usb&quot;</font><font color="4444FF">)</font><font color="4444FF">;</font>

    <font color="#2040a0">wrap_snd_pcm_open</font> <font color="4444FF">=</font> <font color="#2040a0">wrap</font><font color="4444FF">(</font><font color="#2040a0">wrap_snd_pcm_open</font>,<font color="#008000">&quot;snd_pcm_open&quot;</font><font color="4444FF">)</font><font color="4444FF">;</font>
    <font color="#2040a0">temp</font> <font color="4444FF">=</font> <font color="#2040a0">wrap_snd_pcm_open</font><font color="4444FF">(</font><font color="#2040a0">pcm</font>,<font color="#2040a0">name</font>,<font color="#2040a0">stream</font>,<font color="#2040a0">mode</font><font color="4444FF">)</font><font color="4444FF">;</font>
    <font color="#2040a0">fprintf</font><font color="4444FF">(</font><font color="#2040a0">stderr</font>, <font color="#008000">&quot;** Calling snd_pcm_open for path:[%s] =&gt; fd:[%d]<font color="#77dd77">\n</font>&quot;</font>,<font color="#2040a0">name</font>,<font color="#2040a0">temp</font><font color="4444FF">)</font><font color="4444FF">;</font>
    <font color="#2040a0">fflush</font><font color="4444FF">(</font><font color="#2040a0">stderr</font><font color="4444FF">)</font><font color="4444FF">;</font>
    <strong>return</strong> <font color="#2040a0">temp</font><font color="4444FF">;</font>

<font color="4444FF"><strong>}</strong></font>
</pre>
<p>As you can see in the code, I use a generic wrapper function because during my code session, I used this function to re-route some other functions. To build the library :</p>
<pre>gcc -g -fPIC -shared -Wl,-soname,preload.so -ldl -o preload.so  main.c</pre>
<p>Load the lib, with export LD_PRELOAD=./preload.so before running Spotify. Spotify (and all other software using Alsa) will use &#8220;usb&#8221; as default sound card.</p>
<p>Note: C reader will note that name is a const char pointer, and so we can&#8217;t change it, but even if gcc raise a big warning, the code do trick fine.</p>
<p><strong>Enjoy good quality sound even w/ closed source </strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.larsen-b.com/Article/425.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Cheap DIY USB Tube DAC</title>
		<link>http://www.larsen-b.com/Article/414.html</link>
		<comments>http://www.larsen-b.com/Article/414.html#comments</comments>
		<pubDate>Fri, 20 Apr 2012 17:30:16 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[dac]]></category>
		<category><![CDATA[tube]]></category>
		<category><![CDATA[usb]]></category>

		<guid isPermaLink="false">http://www.larsen-b.com/?p=414</guid>
		<description><![CDATA[Due to lot of homework, I haven&#8217;t found a lot of time to have fun electronic for some times. I decided to change this by building an cheap USB DAC with tube output. There is a bunch of USB DAC &#8230; <a href="http://www.larsen-b.com/Article/414.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Due to lot of homework, I haven&#8217;t found a lot of time to have fun electronic for some times. I decided to change this by building an cheap USB DAC with tube output.</p>
<p>There is a bunch of USB DAC on the market right now, but most of them aren&#8217;t really top quality. As I don&#8217;t want to loose some time to build the USB part, I decided to buy a USB DAC Kit. After a little search on Ebay I found this one :</p>
<p><img class="alignnone" title="Ebay USB DAC" src="http://jkx.larsen-b.com/photos/blog/ebay_usb_dac.sized.jpg" alt="" width="640" height="541" /></p>
<p>This kit sports an CS8416+CS4398 combot plus an NE5532 output buffer, but as I want it to be a little audiophile, I will drop the NE5532 in favor of an simple tube preamp.</p>
<p>For the tube part, I think I will go for an 12AX7 or something similar. I really think 6SN7 are better, but this tube are overkill for an preamp I think.</p>
<p>Update, some links for the tube output :</p>
<ul>
<li><a href="http://www.shine7.com/audio/12ax7_pre.htm">http://www.shine7.com/audio/12ax7_pre.htm</a></li>
<li><a href="http://diyaudioprojects.com/Tubes/12AX7_Preamp/">http://diyaudioprojects.com/Tubes/12AX7_Preamp/</a></li>
</ul>
<p><strong>/Enjoy tube sound</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.larsen-b.com/Article/414.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automatic FTP backup for servers</title>
		<link>http://www.larsen-b.com/Article/409.html</link>
		<comments>http://www.larsen-b.com/Article/409.html#comments</comments>
		<pubDate>Sat, 28 Jan 2012 17:07:48 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Utils]]></category>
		<category><![CDATA[duplicity]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://www.larsen-b.com/?p=409</guid>
		<description><![CDATA[Today I need to find a way to do some backup on an FTP server. Of course there is a lot of way to do that, but I need something automatic that does some full (monthly) and incremental (daily) backup. &#8230; <a href="http://www.larsen-b.com/Article/409.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Today I need to find a way to do some backup on an FTP server. Of course there is a lot of way to do that, but I need something automatic that does some full (monthly) and incremental (daily) backup. I decided to use <a href="http://duplicity.nongnu.org/">duplicity</a> because it&#8217;s a really simple and effective software. The main issue, is that duplicity command line is a bit hard to remember for me. So why not simply write a simple python script that does the job for me.</p>
<p>So here, we are :</p>
<pre><span style="color: #444444;">#!/usr/bin/python </span>
# Edit DATA and DEST
<span style="color: #2040a0;">DATA</span><span style="color: #4444ff;">=</span><span style="color: #008000;">'/var/www'</span>
<span style="color: #2040a0;">DEST</span><span style="color: #4444ff;">=</span><span style="color: #008000;">'ftp://username:password@ftp.server/backup'</span>

<strong>import</strong> <span style="color: #2040a0;">os</span>
<strong>import</strong> <span style="color: #2040a0;">sys</span>

<span style="color: #2040a0;">def</span> <span style="color: #2040a0;">backup</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">b_type</span><span style="color: #4444ff;">=</span><span style="color: #008000;">'incr'</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">:</span>
    <span style="color: #2040a0;">dup_cmd</span> <span style="color: #4444ff;">=</span><span style="color: #008000;">'nice -n 19 duplicity %s  --volsize 512 --no-encryption --asynchronous-upload '</span> <span style="color: #4444ff;">%</span> <span style="color: #4444ff;">(</span><span style="color: #2040a0;">b_type</span>,<span style="color: #4444ff;">)</span>
    <span style="color: #2040a0;">temp</span> <span style="color: #4444ff;">=</span> <span style="color: #008000;">'%s %s %s'</span> <span style="color: #4444ff;">%</span> <span style="color: #4444ff;">(</span><span style="color: #2040a0;">dup_cmd</span>,<span style="color: #2040a0;">DATA</span>,<span style="color: #2040a0;">DEST</span><span style="color: #4444ff;">)</span>
    <span style="color: #2040a0;">os</span>.<span style="color: #2040a0;">system</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">temp</span><span style="color: #4444ff;">)</span>

<span style="color: #2040a0;">def</span> <span style="color: #2040a0;">info</span><span style="color: #4444ff;">(</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">:</span>
    <span style="color: #2040a0;">dup_cmd</span><span style="color: #4444ff;">=</span><span style="color: #008000;">'duplicity collection-status  %s'</span> <span style="color: #4444ff;">%</span> <span style="color: #4444ff;">(</span><span style="color: #2040a0;">DEST</span><span style="color: #4444ff;">)</span>
    <span style="color: #2040a0;">os</span>.<span style="color: #2040a0;">system</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">dup_cmd</span><span style="color: #4444ff;">)</span>

<span style="color: #2040a0;">def</span> <span style="color: #2040a0;">list_files</span><span style="color: #4444ff;">(</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">:</span>
    <span style="color: #2040a0;">dup_cmd</span><span style="color: #4444ff;">=</span><span style="color: #008000;">'duplicity list-current-files  %s'</span> <span style="color: #4444ff;">%</span> <span style="color: #4444ff;">(</span><span style="color: #2040a0;">DEST</span><span style="color: #4444ff;">)</span>
    <span style="color: #2040a0;">os</span>.<span style="color: #2040a0;">system</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">dup_cmd</span><span style="color: #4444ff;">)</span>

<span style="color: #2040a0;">def</span> <span style="color: #2040a0;">clean</span><span style="color: #4444ff;">(</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">:</span>
    <span style="color: #2040a0;">dup_cmd</span><span style="color: #4444ff;">=</span><span style="color: #008000;">'duplicity remove-all-but-n-full 1 --force %s'</span> <span style="color: #4444ff;">%</span> <span style="color: #4444ff;">(</span><span style="color: #2040a0;">DEST</span><span style="color: #4444ff;">)</span>
    <span style="color: #2040a0;">os</span>.<span style="color: #2040a0;">system</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">dup_cmd</span><span style="color: #4444ff;">)</span>

<span style="color: #2040a0;">def</span> <span style="color: #2040a0;">usage</span><span style="color: #4444ff;">(</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">:</span>
    <strong>print</strong> <span style="color: #008000;">"%s [-incr|-full|-list|-info|-clean]"</span> <span style="color: #4444ff;">%</span> <span style="color: #2040a0;">sys</span>.<span style="color: #2040a0;">argv</span><span style="color: #4444ff;">[</span><span style="color: #ff0000;">0</span><span style="color: #4444ff;">]</span>

<strong>if</strong> <span style="color: #2040a0;">__name__</span><span style="color: #4444ff;">=</span><span style="color: #4444ff;">=</span><span style="color: #008000;">'__main__'</span><span style="color: #4444ff;">:</span>
    <strong>if</strong> <span style="color: #2040a0;">len</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">sys</span>.<span style="color: #2040a0;">argv</span><span style="color: #4444ff;">)</span> <span style="color: #4444ff;">&gt;</span> <span style="color: #ff0000;">1</span><span style="color: #4444ff;">:</span>
        <strong>if</strong> <span style="color: #2040a0;">sys</span>.<span style="color: #2040a0;">argv</span><span style="color: #4444ff;">[</span><span style="color: #ff0000;">1</span><span style="color: #4444ff;">]</span> <span style="color: #4444ff;">=</span><span style="color: #4444ff;">=</span> <span style="color: #008000;">'-incr'</span><span style="color: #4444ff;">:</span>
            <span style="color: #2040a0;">backup</span><span style="color: #4444ff;">(</span><span style="color: #008000;">'inc'</span><span style="color: #4444ff;">)</span>
        <strong>elif</strong> <span style="color: #2040a0;">sys</span>.<span style="color: #2040a0;">argv</span><span style="color: #4444ff;">[</span><span style="color: #ff0000;">1</span><span style="color: #4444ff;">]</span> <span style="color: #4444ff;">=</span><span style="color: #4444ff;">=</span> <span style="color: #008000;">'-full'</span><span style="color: #4444ff;">:</span>
            <span style="color: #2040a0;">backup</span><span style="color: #4444ff;">(</span><span style="color: #008000;">'full'</span><span style="color: #4444ff;">)</span>
        <strong>elif</strong> <span style="color: #2040a0;">sys</span>.<span style="color: #2040a0;">argv</span><span style="color: #4444ff;">[</span><span style="color: #ff0000;">1</span><span style="color: #4444ff;">]</span> <span style="color: #4444ff;">=</span><span style="color: #4444ff;">=</span> <span style="color: #008000;">'-info'</span><span style="color: #4444ff;">:</span>
            <span style="color: #2040a0;">info</span><span style="color: #4444ff;">(</span><span style="color: #4444ff;">)</span>
        <strong>elif</strong> <span style="color: #2040a0;">sys</span>.<span style="color: #2040a0;">argv</span><span style="color: #4444ff;">[</span><span style="color: #ff0000;">1</span><span style="color: #4444ff;">]</span> <span style="color: #4444ff;">=</span><span style="color: #4444ff;">=</span> <span style="color: #008000;">'-list'</span><span style="color: #4444ff;">:</span>
            <span style="color: #2040a0;">list_files</span><span style="color: #4444ff;">(</span><span style="color: #4444ff;">)</span>
        <strong>elif</strong> <span style="color: #2040a0;">sys</span>.<span style="color: #2040a0;">argv</span><span style="color: #4444ff;">[</span><span style="color: #ff0000;">1</span><span style="color: #4444ff;">]</span> <span style="color: #4444ff;">=</span><span style="color: #4444ff;">=</span> <span style="color: #008000;">'-clean'</span><span style="color: #4444ff;">:</span>
            <span style="color: #2040a0;">clean</span><span style="color: #4444ff;">(</span><span style="color: #4444ff;">)</span>
        <strong>else</strong><span style="color: #4444ff;">:</span>
            <span style="color: #2040a0;">usage</span><span style="color: #4444ff;">(</span><span style="color: #4444ff;">)</span>
    <strong>else</strong><span style="color: #4444ff;">:</span>
        <span style="color: #2040a0;">usage</span><span style="color: #4444ff;">(</span><span style="color: #4444ff;">)</span></pre>
<p>Please note that I disabled the PGP encryption for this backup. Mainly because, I don&#8217;t want to deal w/ lost keys when I will need to restore the backup. But this can be done easily. I will post a complete guide if someone ask.</p>
<p>The next step call the script in cron.d for example with something like this : <em>30  3   *  *  * </em></p>
<p><strong>Feel happy no more stress with backup ;)</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.larsen-b.com/Article/409.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Connect NGW100 Linux (AVR32) to Arduino with I2C</title>
		<link>http://www.larsen-b.com/Article/398.html</link>
		<comments>http://www.larsen-b.com/Article/398.html#comments</comments>
		<pubDate>Sun, 08 Jan 2012 01:39:27 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[arduino]]></category>
		<category><![CDATA[I2C]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[openwrt]]></category>

		<guid isPermaLink="false">http://www.larsen-b.com/?p=398</guid>
		<description><![CDATA[For a Linux embedded training, I need to find something fun to plug on an AVR32 board. The board used for the training is a NGW100 board. I decided to try to use the I2C bus. I have several I2C &#8230; <a href="http://www.larsen-b.com/Article/398.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>For a Linux embedded training, I need to find something fun to plug on an AVR32 board. The board used for the training is a <a href="http://www.atmel.com/dyn/products/tools_card.asp?tool_id=4102">NGW100</a> board. I decided to try to use the <a href="http://en.wikipedia.org/wiki/I%C2%B2C">I2C</a> bus. I have several I2C stuff on the desk, but nothing really fun and I don&#8217;t want to solder a lot of stuff, and spend a lot of time on this. I decided to use a Arduino board as a I2C slave device and plug this to the NGW100 board.</p>
<p><strong>First step: S</strong>imply use the Arduino IDE and the <a href="http://arduino.cc/en/Reference/Wire">Wire lib</a>. I use an <a href="http://www.seeedstudio.com/blog/tag/seeeduino/">Seeeduino</a> because I need an Arduino that works at 3.3v level. Here the code :</p>
<pre><span style="color: #0000ff;"><strong>#include <span style="color: #008000;">&lt;Wire.h&gt;</span></strong></span>
<strong>void</strong> <span style="color: #2040a0;">setup</span><span style="color: #4444ff;">(</span><span style="color: #4444ff;">)</span>
<span style="color: #4444ff;"><strong>{</strong></span>
  <span style="color: #2040a0;">Wire</span>.<span style="color: #2040a0;">begin</span><span style="color: #4444ff;">(</span><span style="color: #ff0000;">4</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>                <span style="color: #444444;">// join i2c bus with address #4</span>
  <span style="color: #2040a0;">Wire</span>.<span style="color: #2040a0;">onReceive</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">receiveEvent</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span> <span style="color: #444444;">// register event</span>
  <span style="color: #2040a0;">Wire</span>.<span style="color: #2040a0;">onRequest</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">requestEvent</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span> <span style="color: #444444;">// register event</span>
  <span style="color: #2040a0;">Serial</span>.<span style="color: #2040a0;">begin</span><span style="color: #4444ff;">(</span><span style="color: #ff0000;">38400</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>           <span style="color: #444444;">// start serial for output</span>
  <span style="color: #2040a0;">Serial</span>.<span style="color: #2040a0;">println</span><span style="color: #4444ff;">(</span><span style="color: #008000;">"Boot Ok"</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
<span style="color: #4444ff;"><strong>}</strong></span>

<strong>void</strong> <span style="color: #2040a0;">loop</span><span style="color: #4444ff;">(</span><span style="color: #4444ff;">)</span>
<span style="color: #4444ff;"><strong>{ </strong></span><span style="color: #2040a0;">delay</span><span style="color: #4444ff;">(</span><span style="color: #ff0000;">100</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span><span style="color: #4444ff;"> </span><span style="color: #4444ff;"><strong>}</strong></span>

<strong>void</strong> <span style="color: #2040a0;">receiveEvent</span><span style="color: #4444ff;">(</span><strong>int</strong> <span style="color: #2040a0;">howMany</span><span style="color: #4444ff;">)</span>
<span style="color: #4444ff;"><strong>{</strong></span>
  <strong>char</strong> <span style="color: #2040a0;">c</span> <span style="color: #4444ff;">=</span> <span style="color: #2040a0;">NULL</span><span style="color: #4444ff;">;</span>
  <strong>while</strong><span style="color: #4444ff;">(</span><span style="color: #2040a0;">Wire</span>.<span style="color: #2040a0;">available</span><span style="color: #4444ff;">(</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">)</span> <span style="color: #444444;">// loop through all</span>
  <span style="color: #4444ff;"><strong>{</strong></span>
    <span style="color: #2040a0;">c</span> <span style="color: #4444ff;">=</span> <span style="color: #2040a0;">Wire</span>.<span style="color: #2040a0;">receive</span><span style="color: #4444ff;">(</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span> <span style="color: #444444;">// receive byte as a character</span>
    <span style="color: #2040a0;">Serial</span>.<span style="color: #2040a0;">print</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">c</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>         <span style="color: #444444;">// print the character</span>
  <span style="color: #4444ff;"><strong>}</strong></span>
  <span style="color: #2040a0;">Serial</span>.<span style="color: #2040a0;">println</span><span style="color: #4444ff;">(</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
  <span style="color: #2040a0;">Serial</span>.<span style="color: #2040a0;">println</span><span style="color: #4444ff;">(</span><span style="color: #008000;">"==="</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
<span style="color: #4444ff;"><strong>}</strong></span>

<strong>void</strong> <span style="color: #2040a0;">requestEvent</span><span style="color: #4444ff;">(</span><span style="color: #4444ff;">)</span>
<span style="color: #4444ff;"><strong>{</strong></span>
  <span style="color: #2040a0;">Serial</span>.<span style="color: #2040a0;">println</span><span style="color: #4444ff;">(</span><span style="color: #008000;">"read"</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
  <span style="color: #2040a0;">Wire</span>.<span style="color: #2040a0;">send</span><span style="color: #4444ff;">(</span><span style="color: #008000;">"Hello world from Arduino"</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
<span style="color: #4444ff;"><strong>}</strong></span></pre>
<p>To test the Arduino I used a <a href="http://dangerousprototypes.com/docs/Bus_Pirate">Bus Pirate</a>, this is quite simple and fun, here a little snipset of my initial test with the BP (note the string are different). The I2C slave is at the 0&#215;4 address (check the setup()).</p>
<pre>Searching I2C address space. Found devices at:
0x08(0x04 W) 0x09(0x04 R) 

Read content from the device, 'ABCD'
I2C&gt;[0x09 rrrrrr]
I2C START BIT
WRITE: 0x09 ACK
READ: 0x41
READ:  ACK 0x42
READ:  ACK 0x43
READ:  ACK 0x44
READ:  ACK 0xFF
READ:  ACK 0xFF
NACK
I2C STOP BIT
I2C&gt;

send content to the device 'ABC'
I2C&gt;[0x08 0x41 0x42 0x43]
I2C START BIT
WRITE: 0x08 ACK
WRITE: 0x41 ACK
WRITE: 0x42 ACK
WRITE: 0x43 ACK
I2C STOP BIT</pre>
<p><strong>Second step: </strong> Plug the Arduino to the NGW100. I used the wrapping technique. Simply connect SDA, SCL, and GND. (NGW100 pinouts : SDA=&gt;9, SCL=&gt;10, GND=&gt;2)</p>
<p><img style="border: 0px initial initial;" title="NGW100-AVR32 to Arduino" src="http://jkx.larsen-b.com/photos/blog/2012_01_05_13_57_32_001.sized.jpg" alt="" width="640" height="480" /></p>
<p>On Linux, load the I2C-GPIO kernel module. On <a href="http://openwrt.org">OpenWRT</a> (used on the NGW100), simply load the <strong>kmod</strong>-<strong>i2c-gpio</strong> package.</p>
<p><strong>Final step:</strong> If everything is Ok, we can now test the communication. I used a small piece of C code to deal with I2C on Linux.</p>
<pre><span style="color: #0000ff;"><strong>#include <span style="color: #008000;">&lt;string.h&gt;</span></strong></span>
<span style="color: #0000ff;"><strong>#include <span style="color: #008000;">&lt;stdio.h&gt;</span></strong></span>
<span style="color: #0000ff;"><strong>#include <span style="color: #008000;">&lt;stdlib.h&gt;</span></strong></span>
<span style="color: #0000ff;"><strong>#include <span style="color: #008000;">&lt;linux/i2c-dev.h&gt;</span></strong></span>
<span style="color: #0000ff;"><strong>#include <span style="color: #008000;">&lt;sys/ioctl.h&gt;</span></strong></span>
<span style="color: #0000ff;"><strong>#include <span style="color: #008000;">&lt;fcntl.h&gt;</span></strong></span>

<strong>void</strong> <span style="color: #2040a0;">i2c_run</span><span style="color: #4444ff;">(</span><strong>void</strong><span style="color: #4444ff;">)</span> <span style="color: #4444ff;"><strong>{</strong></span>
    <strong>int</strong> <span style="color: #2040a0;">file</span><span style="color: #4444ff;">;</span>
    <strong>char</strong> <span style="color: #2040a0;">filename</span><span style="color: #4444ff;">[</span><span style="color: #ff0000;">40</span><span style="color: #4444ff;">]</span><span style="color: #4444ff;">;</span>
    <strong>int</strong> <span style="color: #2040a0;">addr</span> <span style="color: #4444ff;">=</span> <span style="color: #ff0000;">0x4</span><span style="color: #4444ff;">;</span>
    <strong>char</strong> <span style="color: #2040a0;">buf</span><span style="color: #4444ff;">[</span><span style="color: #ff0000;">32</span><span style="color: #4444ff;">]</span> <span style="color: #4444ff;">=</span> <span style="color: #4444ff;"><strong>{</strong></span><span style="color: #ff0000;">0</span><span style="color: #4444ff;"><strong>}</strong></span><span style="color: #4444ff;">;</span>
    <strong>int</strong> <span style="color: #2040a0;">i</span><span style="color: #4444ff;">;</span>

    <span style="color: #2040a0;">sprintf</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">filename</span>,<span style="color: #008000;">"/dev/i2c-0"</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
    <strong>if</strong> <span style="color: #4444ff;">(</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">file</span> <span style="color: #4444ff;">=</span> <span style="color: #2040a0;">open</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">filename</span>,<span style="color: #2040a0;">O_RDWR</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">)</span> <span style="color: #4444ff;">&lt;</span> <span style="color: #ff0000;">0</span><span style="color: #4444ff;">)</span> <span style="color: #4444ff;"><strong>{</strong></span>
        <span style="color: #2040a0;">printf</span><span style="color: #4444ff;">(</span><span style="color: #008000;">"Failed to open the bus."</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
        <span style="color: #2040a0;">exit</span><span style="color: #4444ff;">(</span><span style="color: #ff0000;">1</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
    <span style="color: #4444ff;"><strong>}</strong></span>

    <strong>if</strong> <span style="color: #4444ff;">(</span><span style="color: #2040a0;">ioctl</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">file</span>,<span style="color: #2040a0;">I2C_SLAVE</span>,<span style="color: #2040a0;">addr</span><span style="color: #4444ff;">)</span> <span style="color: #4444ff;">&lt;</span> <span style="color: #ff0000;">0</span><span style="color: #4444ff;">)</span> <span style="color: #4444ff;"><strong>{</strong></span>
        <span style="color: #2040a0;">printf</span><span style="color: #4444ff;">(</span><span style="color: #008000;">"Failed to acquire bus access and/or talk to slave.<span style="color: #77dd77;">\n</span>"</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
        <span style="color: #2040a0;">exit</span><span style="color: #4444ff;">(</span><span style="color: #ff0000;">1</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
    <span style="color: #4444ff;"><strong>}</strong></span>

    <span style="color: #2040a0;">i</span> <span style="color: #4444ff;">=</span> <span style="color: #ff0000;">24</span><span style="color: #4444ff;">;</span>
    // <span style="color: #2040a0;">read</span> <span style="color: #2040a0;">I2C</span>
    <strong>if</strong> <span style="color: #4444ff;">(</span><span style="color: #2040a0;">read</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">file</span>,<span style="color: #2040a0;">buf</span>,<span style="color: #2040a0;">i</span><span style="color: #4444ff;">)</span> <span style="color: #4444ff;">!</span><span style="color: #4444ff;">=</span> <span style="color: #2040a0;">i</span><span style="color: #4444ff;">)</span> <span style="color: #4444ff;"><strong>{</strong></span>
      <span style="color: #2040a0;">printf</span><span style="color: #4444ff;">(</span><span style="color: #008000;">"Failed to read from the i2c bus.<span style="color: #77dd77;">\n</span>"</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
    <span style="color: #4444ff;"><strong>}</strong></span> <strong>else</strong> <span style="color: #4444ff;"><strong>{</strong></span>
      <span style="color: #2040a0;">printf</span><span style="color: #4444ff;">(</span><span style="color: #008000;">"Read %d bytes from I2C: [%s]<span style="color: #77dd77;">\n</span>"</span>,<span style="color: #2040a0;">i</span>,<span style="color: #2040a0;">buf</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
    <span style="color: #4444ff;"><strong>}</strong></span>

    <span style="color: #2040a0;">sprintf</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">buf</span>,<span style="color: #008000;">"IC2 from Linux to Arduino"</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
    <span style="color: #2040a0;">i</span> <span style="color: #4444ff;">=</span> <span style="color: #2040a0;">strlen</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">buf</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
    <strong>if</strong> <span style="color: #4444ff;">(</span><span style="color: #2040a0;">write</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">file</span>,<span style="color: #2040a0;">buf</span>,<span style="color: #2040a0;">i</span><span style="color: #4444ff;">)</span> <span style="color: #4444ff;">!</span><span style="color: #4444ff;">=</span> <span style="color: #2040a0;">i</span><span style="color: #4444ff;">)</span> <span style="color: #4444ff;"><strong>{</strong></span>
        <span style="color: #2040a0;">printf</span><span style="color: #4444ff;">(</span><span style="color: #008000;">"Failed to write to the i2c bus.<span style="color: #77dd77;">\n</span>"</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
    <span style="color: #4444ff;"><strong>}</strong></span> <strong>else</strong> <span style="color: #4444ff;"><strong>{</strong></span>
      <span style="color: #2040a0;">printf</span><span style="color: #4444ff;">(</span><span style="color: #008000;">"Sent %d bytes to I2C: [%s]<span style="color: #77dd77;">\n</span>"</span>,<span style="color: #2040a0;">i</span>,<span style="color: #2040a0;">buf</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
    <span style="color: #4444ff;"><strong>}</strong></span>
<span style="color: #4444ff;"><strong>}</strong></span>

<strong>int</strong> <span style="color: #2040a0;">main</span><span style="color: #4444ff;">(</span><span style="color: #4444ff;">)</span>
<span style="color: #4444ff;"><strong>{</strong></span>
  <span style="color: #2040a0;">i2c_run</span><span style="color: #4444ff;">(</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
  <strong>return</strong> <span style="color: #ff0000;">0</span><span style="color: #4444ff;">;</span>
<span style="color: #4444ff;"><strong>}</strong></span></pre>
<p>As you can see this code is a bit rude, but works really well : Read the I2C bus, and send a sample string, a proof ? :)</p>
<p><img style="border: 0px initial initial;" title="openWRT I2C" src="http://jkx.larsen-b.com/photos/blog/openWRT_I2C_001.jpg" alt="" width="690" height="440" /></p>
<p>Of course, I used string values but in real life a small protocol shoud be used. Another important thing: I used a NGW100 but you can use the same idea on all Linux embedded board like the Fonera, or anything else.</p>
<p><strong>Update:</strong> Of course you can use the <a href="http://lm-sensors.org/wiki/I2CTools">i2c-tools</a> on Linux to detect your own device. To do that : Grab the i2c-tools source, and cross compile it for the AVR32. (You only have to change the CC path in the Makefile).</p>
<p><strong>/Enjoy small Linux</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.larsen-b.com/Article/398.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Calling GDB (Gnu debugger) within your code.</title>
		<link>http://www.larsen-b.com/Article/393.html</link>
		<comments>http://www.larsen-b.com/Article/393.html#comments</comments>
		<pubDate>Sat, 20 Aug 2011 12:19:32 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Unix]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[gcc]]></category>
		<category><![CDATA[gdb]]></category>

		<guid isPermaLink="false">http://www.larsen-b.com/?p=393</guid>
		<description><![CDATA[I spent a lot of time finding the right way to do this, so here is a quick note. For work, I need to debug a small piece of code I wrote. But the main software (closed source) load my &#8230; <a href="http://www.larsen-b.com/Article/393.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>I spent a lot of time finding the right way to do this, so here is a quick note. For work, I need to debug a small piece of code I wrote. But the main software (closed source) load my library (via dlopen) and run it in a single thread.</p>
<p>That&#8217;s fine, but I&#8217;m unable to debug this part of the code because I&#8217;m unable to place a breakpoint. So I want to place a &#8220;break&#8221; in my code that&#8217;s return back to GDB. (exactly like you can launch the debugger within Python w/ a simple pdb.set_trace().</p>
<p>This is quite easy to do, and really useful but not really popular. The main trick is to call the interrupt number 3. This will rise a SIGTRAP signal in the Linux kernel that GDB can intercept .. so in your code simply add a macro :</p>
<pre>#define GDB()  asm("int $0x3")
int main()
{
 int a = 12;
 GDB();
 printf("A ==&gt; %u \n",a);
 return 0;   
}</pre>
<p><br/><br />
Call the GDB(); macro in your code, compile it with gcc -g, simply run your program in GDB, and wait for the macro to be called :)</p>
<p><strong><em>/Enjoy gdb</em></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.larsen-b.com/Article/393.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Mbed Ethernet connection</title>
		<link>http://www.larsen-b.com/Article/385.html</link>
		<comments>http://www.larsen-b.com/Article/385.html#comments</comments>
		<pubDate>Sun, 07 Nov 2010 14:19:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[arm]]></category>
		<category><![CDATA[mbed]]></category>
		<category><![CDATA[rj45]]></category>

		<guid isPermaLink="false">http://www.larsen-b.com/?p=385</guid>
		<description><![CDATA[I just received my mbed module. This little ARM device is pretty cool, and the associated tools works quite nice. Of course they cost a lot of money, I received mine for free for the mbed contest. Really kool no &#8230; <a href="http://www.larsen-b.com/Article/385.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>I just received my <a href="http://mbed.org">mbed</a> module. This little ARM device is pretty cool, and the associated tools works quite nice. Of course they cost a lot of money, I received mine for free for the mbed contest. Really kool no ? ;)</p>
<p>After the classic blink test, I decided to go for a network test. But I don&#8217;t have any magnetic Ethernet module right now (In fact, I should have one, but I&#8217;m unable to find it). So let&#8217;s go for a magnetic less ! <a href="http://mbed.org/cookbook/Ethernet-RJ45">The doc on the mbed dedicated page</a> say that should be fine. I decided to pull the RJ45 socket from an old broken WRT54.</p>
<p>The main issue is to figure out how to solder this RJ45 on a veroboard. Here comes the fun part, I remembered that radio-amateur use a technique called &#8220;dead bug soldering&#8221;. Check this <a href="http://workmanship.nasa.gov/lib/insp/2%20books/links/sections/303_deadbugs.html">guidelines from the NASA</a> for examples.</p>
<p>I decided to give it a try :</p>
<p><img class="alignnone" title="RJ45 dead bug" src="http://jkx.larsen-b.com/photos/blog/PA245231_resized.sized.jpg" alt="" width="640" height="489" /></p>
<p>Just glue the RJ45 on the veroboard and use a common wrapping technique : Not so bad ;)</p>
<p>The next step is to flash a <a href="http://mbed.org/users/donatien/programs/">network example</a> to test.</p>
<p>That&#8217;s really fun, the mbed works pretty well. I secretly hopes that somebody will come with a mbed like with opensource hardware and software.</p>
<p><strong>Enjoy wired networks ;)</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.larsen-b.com/Article/385.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Really cheap USB to TTL on Atmega : 1.70$</title>
		<link>http://www.larsen-b.com/Article/370.html</link>
		<comments>http://www.larsen-b.com/Article/370.html#comments</comments>
		<pubDate>Sat, 11 Sep 2010 16:58:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[atmega]]></category>
		<category><![CDATA[avr]]></category>
		<category><![CDATA[rs232]]></category>
		<category><![CDATA[usb]]></category>

		<guid isPermaLink="false">http://www.larsen-b.com/?p=370</guid>
		<description><![CDATA[One of the most common way to interface a microcontroler to a computer used to be serial port. But right now, serial port have been replaced with USB on most computers. A common way to fix this issue is to &#8230; <a href="http://www.larsen-b.com/Article/370.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>One of the most common way to interface a microcontroler to a computer used to be serial port. But right now, serial port have been replaced with USB on most computers. A common way to fix this issue is to use a USB to TTL converter or a USB to RS232 converter + MAX232. That&#8217;s fine but :</p>
<ul>
<li>USB to TTL PCB cost a bit of money : you can find some on Ebay around 7€ (shipped) and 15$ on Sparfun !!!  That&#8217;s about 2 or 5 times the cost of the microcontoler !</li>
<li>USB to RS232 cost 1.70$ (shipped) but need some extra level shifting and doesn&#8217;t really feet on a PCB (need a DB9 connector &#8230;)</li>
</ul>
<p style="text-align: left;">In fact, USB to RS232 is a mass product, and the cost is really low. I decided to order a couple of this, just to look if I can use this stuff on a PCB. So I bought a 1.70$ USB to RS232 on Ebay.</p>
<p style="text-align: left;">
<p style="text-align: center;"><img class="aligncenter" title="USB to RS232" src="http://jkx.larsen-b.com/photos/blog/USB_to_RS_232_Cable.jpg" alt="" width="324" height="282" /></p>
<p>I decided to rip the plastic off the DB9 and discovered a really tiny PCB. I removed the DB9, and decided to pass this little PCB to a scope session. How the hell do they manage to do a USB to RS232 with only a couple of external components ? They is no big capacitor for level shifter  (remember  RS232 is a +12/-12v ) ? The answer is simple, they don&#8217;t !!</p>
<p>This device isn&#8217;t RS232 compliant at all, the signals on the DB9 are TTL compliant, but not RS232. The ouput is between 0/5V and the input can handle -12/+12V but works great with a 0/5V too. I simply removed used pads on one side and added a couple on pins.</p>
<p style="text-align: center;">
<p style="text-align: center;"><img class="aligncenter" title="USB to TTL cheap" src="http://jkx.larsen-b.com/photos/blog/usb_ttl_1.sized.jpg" alt="" width="460" height="640" /></p>
<p style="text-align: left;">
<p style="text-align: left;">Please note that RX pin is missing on this pix but needed of course. The next step : How can I use this with an AVR Atmega (I used a Atmega8 but any will do the trick). Serial connection on a micro is TTL like this board, but the TTL signal is just inverted. A &#8220;1&#8243; on the RS232 side is a -12V and +5V on a TTL, and a 0 on the RS232 side is a + 12V and a 0v on the TTL. You can find all the information <a href="http://www.arcelect.com/rs232.htm">here</a>.</p>
<p style="text-align: left;">In fact MAX232 do both level shitting and inverting, but as I&#8217;m to lazy to wire a MAX232 (and will destroy the cheap aspect of this hack), I decided to handle this by software. This mean, I won&#8217;t be able to use the Atmega serial builtin port but need to write some additional code, to do the RS232 encoding/decoding by hand. Let&#8217;s give it a try :</p>
<p style="text-align: left;">
<p style="text-align: left;"><img class="aligncenter" title="USB to RS232 Atmega" src="http://jkx.larsen-b.com/photos/blog/P9115024.sized.jpg" alt="" width="640" height="609" /></p>
<p style="text-align: left;">
<p style="text-align: left;">
<p style="text-align: left;">I simply put this on a verroboard, connect VCC to USB Vcc, GND, RX and TX  to random pins on the AVR and let&#8217;s go to RS232 software serial. This can be done easily in fact, and I managed to handle 19200bauds with the internal 8Mhz clock of the Atmega. Above you will find the popular uart_putc() and uart_getc() ..</p>
<pre><a name="line1"> 1</a> <span style="color: #0000ff;"><strong>#define UART_TX	D,1</strong></span>
<a name="line2"> 2</a> <span style="color: #0000ff;"><strong>#define UART_RX	D,2</strong></span>
<a name="line3"> 3</a> <span style="color: #0000ff;"><strong>#define UART_DELAY	52 // 1/9600 = 104uS : 1/19200 = 52uS</strong></span>
<a name="line4"> 4</a>
<a name="line5"> 5</a>
<a name="line6"> 6</a> <strong>void</strong> <span style="color: #2040a0;">uart_putc</span><span style="color: #4444ff;">(</span><strong>char</strong> <span style="color: #2040a0;">c</span><span style="color: #4444ff;">)</span>
<a name="line7"> 7</a> <span style="color: #4444ff;"><strong>{</strong></span>
<a name="line8"> 8</a>   <span style="color: #2040a0;">uchar</span> <span style="color: #2040a0;">i</span><span style="color: #4444ff;">;</span>
<a name="line9"> 9</a>   <span style="color: #2040a0;">uchar</span> <span style="color: #2040a0;">temp</span><span style="color: #4444ff;">;</span>
<a name="line10">10</a>
<a name="line11">11</a>   // <span style="color: #2040a0;">start</span>
<a name="line12">12</a>   <span style="color: #2040a0;">set_output</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">UART_TX</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
<a name="line13">13</a>   <span style="color: #2040a0;">_delay_us</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">UART_DELAY</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
<a name="line14">14</a>   <span style="color: #2040a0;">clr_output</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">UART_TX</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
<a name="line15">15</a>
<a name="line16">16</a>   <strong>for</strong><span style="color: #4444ff;">(</span><span style="color: #2040a0;">i</span><span style="color: #4444ff;">=</span><span style="color: #ff0000;">0</span><span style="color: #4444ff;">;</span><span style="color: #2040a0;">i</span><span style="color: #4444ff;">&lt;</span><span style="color: #ff0000;">8</span><span style="color: #4444ff;">;</span><span style="color: #2040a0;">i</span><span style="color: #4444ff;">+</span><span style="color: #4444ff;">+</span><span style="color: #4444ff;">)</span>
<a name="line17">17</a>   <span style="color: #4444ff;"><strong>{</strong></span>
<a name="line18">18</a>     <span style="color: #2040a0;">temp</span> <span style="color: #4444ff;">=</span> <span style="color: #2040a0;">c</span><span style="color: #4444ff;">&amp;</span><span style="color: #ff0000;">1</span><span style="color: #4444ff;">;</span>
<a name="line19">19</a>     <strong>if</strong> <span style="color: #4444ff;">(</span><span style="color: #2040a0;">temp</span><span style="color: #4444ff;">=</span><span style="color: #4444ff;">=</span><span style="color: #ff0000;">0</span><span style="color: #4444ff;">)</span>
<a name="line20">20</a>       <span style="color: #2040a0;">set_output</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">UART_TX</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
<a name="line21">21</a>     <strong>else</strong>
<a name="line22">22</a>       <span style="color: #2040a0;">clr_output</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">UART_TX</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
<a name="line23">23</a>     <span style="color: #2040a0;">_delay_us</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">UART_DELAY</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
<a name="line24">24</a>
<a name="line25">25</a>      <span style="color: #2040a0;">c</span> <span style="color: #4444ff;">=</span> <span style="color: #2040a0;">c</span> <span style="color: #4444ff;">&gt;</span><span style="color: #4444ff;">&gt;</span><span style="color: #ff0000;">1</span><span style="color: #4444ff;">;</span>
<a name="line26">26</a>   <span style="color: #4444ff;"><strong>}</strong></span>
<a name="line27">27</a>
<a name="line28">28</a>   // <span style="color: #2040a0;">stop</span>
<a name="line29">29</a>   <span style="color: #2040a0;">set_output</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">UART_TX</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
<a name="line30">30</a>   <span style="color: #2040a0;">_delay_us</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">UART_DELAY</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
<a name="line31">31</a>   <span style="color: #2040a0;">clr_output</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">UART_TX</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
<a name="line32">32</a>
<a name="line33">33</a>   <span style="color: #2040a0;">_delay_us</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">UART_DELAY</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
<a name="line34">34</a> <span style="color: #4444ff;"><strong>}</strong></span>
<a name="line35">35</a>
<a name="line36">36</a> <span style="color: #2040a0;">uchar</span> <span style="color: #2040a0;">uart_getc</span><span style="color: #4444ff;">(</span><span style="color: #4444ff;">)</span>
<a name="line37">37</a> <span style="color: #4444ff;"><strong>{</strong></span>
<a name="line38">38</a>   <span style="color: #2040a0;">uchar</span> <span style="color: #2040a0;">i</span><span style="color: #4444ff;">;</span>
<a name="line39">39</a>   <span style="color: #2040a0;">uchar</span> <span style="color: #2040a0;">ib</span> <span style="color: #4444ff;">=</span> <span style="color: #ff0000;">0</span><span style="color: #4444ff;">;</span>
<a name="line40">40</a>   <span style="color: #2040a0;">uchar</span> <span style="color: #2040a0;">currentChar</span><span style="color: #4444ff;">=</span><span style="color: #ff0000;">0</span><span style="color: #4444ff;">;</span>
<a name="line41">41</a>
<a name="line42">42</a>   <strong>while</strong> <span style="color: #4444ff;">(</span><span style="color: #2040a0;">ib</span> <span style="color: #4444ff;">!</span><span style="color: #4444ff;">=</span> <span style="color: #ff0000;">1</span><span style="color: #4444ff;">)</span>
<a name="line43">43</a>     <span style="color: #2040a0;">ib</span> <span style="color: #4444ff;">=</span> <span style="color: #2040a0;">get_input</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">UART_RX</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
<a name="line44">44</a>
<a name="line45">45</a>   <span style="color: #2040a0;">_delay_us</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">UART_DELAY</span>/<span style="color: #ff0000;">2</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span> // <span style="color: #2040a0;">middle</span> <span style="color: #2040a0;">of</span> <span style="color: #2040a0;">the</span> <span style="color: #2040a0;">start</span> <span style="color: #2040a0;">bit</span>
<a name="line46">46</a>   <strong>for</strong><span style="color: #4444ff;">(</span><span style="color: #2040a0;">i</span><span style="color: #4444ff;">=</span><span style="color: #ff0000;">0</span><span style="color: #4444ff;">;</span><span style="color: #2040a0;">i</span><span style="color: #4444ff;">&lt;</span><span style="color: #ff0000;">8</span><span style="color: #4444ff;">;</span><span style="color: #2040a0;">i</span><span style="color: #4444ff;">+</span><span style="color: #4444ff;">+</span><span style="color: #4444ff;">)</span>
<a name="line47">47</a>     <span style="color: #4444ff;"><strong>{</strong></span>
<a name="line48">48</a>       <span style="color: #2040a0;">_delay_us</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">UART_DELAY</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
<a name="line49">49</a>       <span style="color: #2040a0;">ib</span> <span style="color: #4444ff;">=</span> <span style="color: #2040a0;">get_input</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">UART_RX</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">;</span>
<a name="line50">50</a>
<a name="line51">51</a>       <strong>if</strong> <span style="color: #4444ff;">(</span><span style="color: #2040a0;">ib</span> <span style="color: #4444ff;">=</span><span style="color: #4444ff;">=</span><span style="color: #ff0000;">0</span><span style="color: #4444ff;">)</span>
<a name="line52">52</a> 	<span style="color: #2040a0;">currentChar</span> <span style="color: #4444ff;">|</span><span style="color: #4444ff;">=</span> <span style="color: #ff0000;">1</span><span style="color: #4444ff;">&lt;</span><span style="color: #4444ff;">&lt;</span><span style="color: #2040a0;">i</span><span style="color: #4444ff;">;</span> // <span style="color: #2040a0;">this</span> <span style="color: #2040a0;">is</span> <span style="color: #2040a0;">a</span> <span style="color: #ff0000;">1</span>
<a name="line53">53</a>     <span style="color: #4444ff;"><strong>}</strong></span>
<a name="line54">54</a>   <strong>return</strong> <span style="color: #2040a0;">currentChar</span><span style="color: #4444ff;">;</span>
<a name="line55">55</a> <span style="color: #4444ff;"><strong>}</strong></span></pre>
<p style="text-align: left;">
<p style="text-align: left;">Nothing more to say, this hack works really great, and I can now build a bunch of USB board without paying so much. The only drawback of this approach is that you can&#8217;t use an interrupt for the uart_getc() so you have deal with that in your code. Another approach would use a single transistor for the RX pin to make the RX compliant w/ the AVR serial builtin routine.</p>
<p style="text-align: left;">
<p style="text-align: left;">You can find the whole project C files + Makefile in a zip <a href="http://www.larsen-b.com/wp-content/uploads/avr-soft-serial.zip">here</a>. I think this little hack is really useful, so please send it to all to your DIYer friends, this can save them money, time &#8230;</p>
<p style="text-align: left;">
<p style="text-align: left;"><strong>// Enjoy cheap USB ? :)</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.larsen-b.com/Article/370.html/feed</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Boosting IR remote video sender (Thomson VS360U)</title>
		<link>http://www.larsen-b.com/Article/364.html</link>
		<comments>http://www.larsen-b.com/Article/364.html#comments</comments>
		<pubDate>Sat, 21 Aug 2010 14:21:21 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[diy]]></category>
		<category><![CDATA[infrared]]></category>
		<category><![CDATA[transistor]]></category>
		<category><![CDATA[video sender]]></category>

		<guid isPermaLink="false">http://www.larsen-b.com/?p=364</guid>
		<description><![CDATA[In my home, I have a bad TV antenna, so we use only the cable receiver to watch TV. But I have two TV sets. I decided to buy a video sender a couple of months ago, but never managed &#8230; <a href="http://www.larsen-b.com/Article/364.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>In my home, I have a bad TV antenna, so we use only the cable receiver to watch TV. But I have two TV sets. I decided to buy a video sender a couple of months ago, but never managed to get it working nicely. I bought a Thomson VS360U video sender. This one is really cheap, 24 €, works on the 2.4Ghz for the audio/video and 433Mhz for remote.</p>
<p><img class="alignnone" title="Thomson video sender" src="http://jkx.larsen-b.com/photos/blog/L2210.jpg" alt="" width="250" height="150" /></p>
<p>At the first test, I discovered that the transceiver come with a couple of IR leds. I have to glue each IR led in front of each part of your equipment I want to drive. For me, the cable receiver, the DVD, the Dvico, and the AV amp .. I tried this, but that&#8217;s a mess, each led is soldered on a single string, and tend to move. Not really a nice experience. This is simple to crappy to be use.</p>
<p>I decided to mod it to be able to use a single IR led, with a better gain. The first step is to find the right place to place my mod. Just open the transceiver, locate the power supply (Vcc/Gnd) and the IR transistor. I was quite easy, the only trick is to solder the wire for the IR transistor just before the base resistor. Here is the result.</p>
<p><img class="alignnone" title="Thomson video sender hack-1" src="http://jkx.larsen-b.com/photos/blog/P6113410_contrast.sized.jpg" alt="" width="640" height="575" /></p>
<p>You can find a better pix, in the <a href="http://jkx.larsen-b.com/gallery/blog/P6113410_contrast">gallery.</a> I used a scope to find the IR transistor, but this can be done without.</p>
<p>Let&#8217;s build a simple IR booster, that&#8217;s connect to this pins, and everything will be fine. I used an common BC547 but any common transistor will do the job.</p>
<p><img class="alignnone" title="IR booster schematic" src="http://jkx.larsen-b.com/photos/blog/vs_schem.png" alt="" width="285" height="335" /></p>
<p>The result :</p>
<p><img class="alignnone" title="video sender final" src="http://jkx.larsen-b.com/photos/blog/vs_final.sized.jpg" alt="" width="506" height="640" /></p>
<p>As you can see, this is small. I placed this near my cable receiver and every is working nicely. I can now control every equipment (cable, DVD, Dvico) for my room without any lag, or IR lost signal.</p>
<p>I managed to fix this cheap video sender without to much effort, I&#8217;m happy. This kind of hack can be used in a couple video sender device. The hardest part is to find the IR transistor, the rest is simply the same.</p>
<p><em><strong>Enjoy TV from bed ;) </strong></em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.larsen-b.com/Article/364.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
