<?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>veys.com</title>
	<atom:link href="http://veys.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://veys.com</link>
	<description>if I only had a tagline.</description>
	<lastBuildDate>Sun, 25 Jul 2010 00:11:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Migrating multi-project Subversion repositories to Git</title>
		<link>http://veys.com/2010/07/24/migrating-multi-project-subversion-repositories-to-git/</link>
		<comments>http://veys.com/2010/07/24/migrating-multi-project-subversion-repositories-to-git/#comments</comments>
		<pubDate>Sun, 25 Jul 2010 00:11:04 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[howtos]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[subversion]]></category>
		<category><![CDATA[svn2git]]></category>
		<category><![CDATA[svnadmin]]></category>
		<category><![CDATA[svndumpfilter]]></category>
		<category><![CDATA[version control]]></category>

		<guid isPermaLink="false">http://veys.com/?p=375</guid>
		<description><![CDATA[So I finally gave in and submitted to the version control Gods, Git is the way to go.  Of course it would happen that Git repositories are typically a single-project-per-repo situation, and I have a couple globbed together Subversion repositories with many projects in them.  How do I separate out my histories from the individual [...]]]></description>
			<content:encoded><![CDATA[<p>So I finally gave in and submitted to the version control Gods, Git is the way to go.  Of course it would happen that Git repositories are typically a single-project-per-repo situation, and I have a couple globbed together Subversion repositories with many projects in them.  How do I separate out my histories from the individual projects, maintain tags and branches, and not lose that precious history that nobody really ever looks at anyway?</p>
<p>Well, luckily there is a nifty script called <a title="svn2git" href="http://github.com/nirvdrum/svn2git">svn2git</a> that gets us the bulk work of migrating history of a single Subversion repo to a new Git repo.  Coupled with a few admin tools that come with Subversion, we got it covered.</p>
<h2>The current situation</h2>
<p>I have a couple repositories, looking like the following:</p>
<pre>/var/lib/svn/repo1
  /project1
    /trunk
    /tags
    /branches
  /project2
    /trunk
    /tags
    /branches
/var/lib/svn/repo2
  /project3
    /trunk
    /tags
    /branches
  /project4
    /trunk
    /tags
    /branches</pre>
<h2>The desired situation</h2>
<p>I&#8217;d like them all separated, with all history!!!  Resulting in the following structure:</p>
<pre>/var/lib/git/project1.git
/var/lib/git/project2.git
/var/lib/git/project3.git
/var/lib/git/project4.git</pre>
<h2>Step 1 &#8211; Dump your projects from the Subversion repository</h2>
<p>Subversion ships with a tool, svnadmin, that will help dump a repository.  It must operate on the local filesystem of the Subversion repository, not a working copy.  As a result, it only dumps full repositories, hence the problem in general.</p>
<p>Be not afraid though!  Subversion also ships with svndumpfilter, the key to our salvation.</p>
<p>For my example above, to dump project1, project2, project3 and project4 into separated Subversion repositories, I would:</p>
<pre>mkdir svn-convert &amp;&amp; cd svn-convert
svnadmin create project1.svn
svnadmin create project2.svn
svnadmin create project3.svn
svnadmin create project4.svn
svnadmin dump /var/lib/svn/repo1 | svndumpfilter include project1 | svnadmin load project1.svn
svnadmin dump /var/lib/svn/repo1 | svndumpfilter include project2 | svnadmin load project2.svn
svnadmin dump /var/lib/svn/repo2 | svndumpfilter include project3 | svnadmin load project3.svn
svnadmin dump /var/lib/svn/repo2 | svndumpfilter include project4 | svnadmin load project4.svn</pre>
<p>And viola, separated Subversion repositories.</p>
<h2>Step 2 &#8211; Convert via svn2git</h2>
<p>First, download and install <a href="http://github.com/nirvdrum/svn2git">svn2git</a>, it&#8217;s a Ruby script, the instructions are good, it&#8217;ll work for you.</p>
<p>Next, create a text file, &#8216;authors.txt&#8217; with contents like the following:</p>
<pre>name1 = Full Name &lt;email@example.com&gt;
name2 = Another Name &lt;email2@example.com&gt;</pre>
<p>Substituting the names of users who have committed to the Subversion repositories of course.  This will map the Subversion users to Git authors.</p>
<p>Next, we make a place for the new repository and run the conversion utility.  It will init the Git repository and create the necessary history.</p>
<pre>mkdir project1.git &amp;&amp; cd project1.git
svn2git file:///home/nick/svn-convert/project1.svn \
    --trunk project1/trunk --branches project1/branches \
    --tags project1/tags --authors ../authors.txt</pre>
<p>Repeated for each repository with appropriate substitutions, and you&#8217;ve got yourself some Git repositories.</p>
<p>Quick verification should show you you&#8217;re in business:</p>
<pre>$ git tag
v1.0
v1.0.1
v1.0.2
v1.0.3</pre>
<pre>$ git branch
* master
  ticket102
  ticket87</pre>
<p>All that is left is to put them in a safe place and start cloning!</p>
]]></content:encoded>
			<wfw:commentRss>http://veys.com/2010/07/24/migrating-multi-project-subversion-repositories-to-git/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Restoring from a Samba-based Time Machine backup (kinda)</title>
		<link>http://veys.com/2009/08/16/restoring-from-a-samba-based-time-machine-backup-kinda/</link>
		<comments>http://veys.com/2009/08/16/restoring-from-a-samba-based-time-machine-backup-kinda/#comments</comments>
		<pubDate>Sun, 16 Aug 2009 23:36:31 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[howtos]]></category>
		<category><![CDATA[afp]]></category>
		<category><![CDATA[leopard]]></category>
		<category><![CDATA[restore]]></category>
		<category><![CDATA[samba]]></category>
		<category><![CDATA[smbfs]]></category>
		<category><![CDATA[snow leopard]]></category>
		<category><![CDATA[time machine]]></category>

		<guid isPermaLink="false">http://veys.com/?p=354</guid>
		<description><![CDATA[Panicking about not being about to find or mount your Samba share you&#8217;ve been blissfully backing up to over your network?  Trying to restore to a new hard drive using the Leopard boot DVD? I recently had the pleasure of a hard disk crash on my MacBook, and only a month earlier had started backing [...]]]></description>
			<content:encoded><![CDATA[<p>Panicking about not being about to find or mount your Samba share you&#8217;ve been blissfully backing up to over your network?  Trying to restore to a new hard drive using the Leopard boot DVD?</p>
<p>I recently had the pleasure of a hard disk crash on my MacBook, and only a month earlier had started backing up to a Samba-share via Time Machine.  I had the &#8220;how to restore&#8221; question nagging in the back of my head when I set it all up but I figured someone had it figured out, otherwise why would <a href="http://www.oak-tree.us/blog/index.php/2009/06/09/backup-part4">so</a> <a href="http://hupio.wordpress.com/2008/04/27/osx-timemachine-and-sambawindows-share/">many</a> <a href="http://freakymousemats.com/blog/posts/2007/11/01/time-machine-over-smb/">articles</a> exist to show you how to set it up?</p>
<p>I&#8217;ve been trying to find out how people using the <tt>TMShowUnsupportedNetworkVolumes</tt> hack to use Time Machine on smbfs shares have been restoring and it would seem that the answer is &#8220;they aren&#8217;t&#8221;.  That, or they&#8217;re simply using it as an &#8220;oops&#8221; fixer, restoring a file here and there.</p>
<p>When booting from the Leopard DVD, firing up the terminal and attempting to mount the share, the following delightful message shows up:</p>
<p><code> mount_smbfs --&gt; mount_smbfs: failed to load the smb library: Unknown error: 1102<br />
</code></p>
<p>Searching for that was even more disappointing.  Other people running into the issue, no solutions.  It seems smb support is just not available on the boot DVD.</p>
<p>I ran into a possible solution, copy the Time Machine sparse bundle onto a removable hard disk, and hook it up to the laptop.  Unfortunately all my external storage is formatted ReisferFS or ext3, neither are supported filesystems, and I didn&#8217;t feel like changing one just to fix this.</p>
<p>So in comes the hack.  Luckily the Samba share is on an Ubuntu 9.04 (Jaunty) server, so adding support for something Apple <em>does </em>support on the boot DVD is tragically easy.  This is a fairly specific solution, but variations on it will work for many different servers.</p>
<h3>Enter AFP</h3>
<p>Looking through the other available mount applications, we also have <tt>mount_afp</tt> available.  This mounts <a href="http://en.wikipedia.org/wiki/Apple_Filing_Protocol">Apple Filing Protocol</a>-based shares, and it works too, bonus!</p>
<p>So it boils down to enabling AFP on the server and sharing the same volume via AFP.  AFP on Linux (BSD, etc) is supplied by <a href="http://netatalk.sourceforge.net/">netatalk</a>, and here&#8217;s a step-by-step of how I wrapped it all up.</p>
<p>On the server:</p>
<ul>
<li><tt>sudo aptitude install netatalk</tt></li>
<li>Edit <tt>/etc/netatalk/AppleVolumes.default</tt></li>
<li>Add entry for the volume, such as:
<ul>
<li><tt>/mnt/time_machine "tmachine"</tt></li>
</ul>
</li>
<li>Save the file</li>
<li><tt>sudo /etc/init.d/netatalk restart</tt></li>
</ul>
<p>On the Mac:</p>
<ul>
<li>Boot from the Leopard install DVD</li>
<li>Enable Airport (if on WiFi), join your network</li>
<li>From the menu bar, select <strong>Utilities -&gt; Terminal</strong></li>
<li>Navigate to <tt>/Volumes</tt></li>
<li>Create a new mount point for the Time Machine volume
<ul>
<li><tt>mkdir /Volumes/tmachine</tt></li>
</ul>
</li>
<li>Mount the AFP share on the new point (<a href="http://www.macosxhints.com/article.php?story=2001120201020569">details</a>)
<ul>
<li><tt>mount -t afp afp://username:password@server.hostname/tmachine /Volumes/tmachine</tt></li>
</ul>
</li>
<li>Quit Terminal</li>
<li>Back at the main menu bar, select <strong>Utilities -&gt; Restore System From Backup&#8230;</strong></li>
<li>You should see your Time Machine backup volume listed</li>
<li>Select it, and select the date from which you wish to restore</li>
<li>Wait a <em>considerable</em> amount of time for it to determine the space needed</li>
<li>Enjoy the hours and hours of restore time!</li>
</ul>
<h3>Aftermath</h3>
<p>The basic AFP installation added to the server is likely pretty insecure, I purged it as soon as the restore completed.  <a href="http://www.kremalicious.com/2008/06/ubuntu-as-mac-file-server-and-time-machine-volume/">Read this for a more formal treatment on setting up an AFP server on Linux</a>.  It is likely that the real solution is to stop suggesting people use Samba as a file server for Time Machine backups, instead switching to AFP altogether.</p>
<h3>Update</h3>
<p>Just recently came back to this for a Snow Leopard restore, the directions are unchanged.  The nice bonus is there have apparently been some optimizations during the restore, and an initial space calculation was practically instant.  Nice.</p>
]]></content:encoded>
			<wfw:commentRss>http://veys.com/2009/08/16/restoring-from-a-samba-based-time-machine-backup-kinda/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Time to broadcast, iPhone style</title>
		<link>http://veys.com/2009/06/27/time-to-broadcast-iphone-style/</link>
		<comments>http://veys.com/2009/06/27/time-to-broadcast-iphone-style/#comments</comments>
		<pubDate>Sat, 27 Jun 2009 22:40:56 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[broadcast]]></category>
		<category><![CDATA[bsd]]></category>
		<category><![CDATA[cocoa]]></category>
		<category><![CDATA[cocoa touch]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[networking]]></category>
		<category><![CDATA[objective c]]></category>
		<category><![CDATA[sockets]]></category>
		<category><![CDATA[udp]]></category>

		<guid isPermaLink="false">http://veys.com/?p=346</guid>
		<description><![CDATA[Ran into a need to dynamically determine the current UDP broadcast address for the WiFi interface on the ole&#8217; iPhone. Since NSHost appears to be a private API even w/the 3.0 software, it seems one must go lower. I wrapped it up in a neat little bundle that seems fairly usable if not verbose and [...]]]></description>
			<content:encoded><![CDATA[<p>Ran into a need to dynamically determine the current UDP broadcast address for the WiFi interface on the ole&#8217; iPhone.  Since NSHost appears to be a private API even w/the 3.0 software, it seems one must go lower.  I wrapped it up in a neat little bundle that seems fairly usable if not verbose and full of magic (but understandable) numbers.</p>
<p>A few things of note. en0 is the WiFi interface.  There are others.  Instrument the following code w/some debug to get them all out.  The ip/netmask methods return nil when the WiFi interface is not active.  I would also be shocked if there were no corner cases I am ignoring&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#include &lt;arpa/inet.h&gt;</span>
<span style="color: #6e371a;">#include &lt;net/if.h&gt;</span>
<span style="color: #6e371a;">#include &lt;sys/ioctl.h&gt;</span>
<span style="color: #6e371a;">#include &lt;sys/socket.h&gt;</span>
<span style="color: #6e371a;">#include &lt;errno.h&gt;</span>
<span style="color: #6e371a;">#include &lt;ifaddrs.h&gt;</span>
<span style="color: #6e371a;">#include &lt;stdio.h&gt;</span>
&nbsp;
<span style="color: #a61390;">static</span> <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>kWifiInterface <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;en0&quot;</span>;
&nbsp;
<span style="color: #a61390;">@implementation</span> NetUtil
&nbsp;
<span style="color: #002200;">+</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>broadcastAddressForAddress<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>ipAddress withMask<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>netmask <span style="color: #002200;">&#123;</span>
    NSAssert<span style="color: #002200;">&#40;</span><span style="color: #a61390;">nil</span> <span style="color: #002200;">!=</span> ipAddress, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;IP address cannot be nil&quot;</span><span style="color: #002200;">&#41;</span>;
    NSAssert<span style="color: #002200;">&#40;</span><span style="color: #a61390;">nil</span> <span style="color: #002200;">!=</span> netmask, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Netmask cannot be nil&quot;</span><span style="color: #002200;">&#41;</span>;
    <span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span>ipChunks <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>ipAddress componentsSeparatedByString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;.&quot;</span><span style="color: #002200;">&#93;</span>;
    NSAssert<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>ipChunks count<span style="color: #002200;">&#93;</span> <span style="color: #002200;">==</span> <span style="color: #2400d9;">4</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;IP does not have 4 octets!&quot;</span><span style="color: #002200;">&#41;</span>;
    <span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span>nmChunks <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>netmask componentsSeparatedByString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;.&quot;</span><span style="color: #002200;">&#93;</span>;
    NSAssert<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>nmChunks count<span style="color: #002200;">&#93;</span> <span style="color: #002200;">==</span> <span style="color: #2400d9;">4</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Netmask does not have 4 octets!&quot;</span><span style="color: #002200;">&#41;</span>;
&nbsp;
    NSUInteger ipRaw <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>;
    NSUInteger nmRaw <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>;
    NSUInteger shift <span style="color: #002200;">=</span> <span style="color: #2400d9;">24</span>;
    <span style="color: #a61390;">for</span> <span style="color: #002200;">&#40;</span>NSUInteger i <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>; i &lt; <span style="color: #2400d9;">4</span>; <span style="color: #002200;">++</span>i, shift <span style="color: #002200;">-=</span> <span style="color: #2400d9;">8</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        ipRaw |<span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>ipChunks objectAtIndex<span style="color: #002200;">:</span>i<span style="color: #002200;">&#93;</span> intValue<span style="color: #002200;">&#93;</span> &lt;&lt; shift;
        nmRaw |<span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>nmChunks objectAtIndex<span style="color: #002200;">:</span>i<span style="color: #002200;">&#93;</span> intValue<span style="color: #002200;">&#93;</span> &lt;&lt; shift;
    <span style="color: #002200;">&#125;</span>
&nbsp;
    NSUInteger bcRaw <span style="color: #002200;">=</span> ~nmRaw | ipRaw;
    <span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> stringWithFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;%d.%d.%d.%d&quot;</span>, <span style="color: #002200;">&#40;</span>bcRaw <span style="color: #002200;">&amp;</span> 0xFF000000<span style="color: #002200;">&#41;</span> &gt;&gt; <span style="color: #2400d9;">24</span>,
            <span style="color: #002200;">&#40;</span>bcRaw <span style="color: #002200;">&amp;</span> 0x00FF0000<span style="color: #002200;">&#41;</span> &gt;&gt; <span style="color: #2400d9;">16</span>, <span style="color: #002200;">&#40;</span>bcRaw <span style="color: #002200;">&amp;</span> 0x0000FF00<span style="color: #002200;">&#41;</span> &gt;&gt; <span style="color: #2400d9;">8</span>, bcRaw <span style="color: #002200;">&amp;</span> 0x000000FF<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">+</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>ipAddressForInterface<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>ifName <span style="color: #002200;">&#123;</span>
    NSAssert<span style="color: #002200;">&#40;</span><span style="color: #a61390;">nil</span> <span style="color: #002200;">!=</span> ifName, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Interface name cannot be nil&quot;</span><span style="color: #002200;">&#41;</span>;
&nbsp;
    <span style="color: #a61390;">struct</span> ifaddrs <span style="color: #002200;">*</span>addrs <span style="color: #002200;">=</span> <span style="color: #a61390;">NULL</span>;
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>getifaddrs<span style="color: #002200;">&#40;</span><span style="color: #002200;">&amp;</span>addrs<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Failed to enumerate interfaces: %@&quot;</span>, <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> stringWithCString<span style="color: #002200;">:</span><span style="color: #a61390;">strerror</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">errno</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>;
        <span style="color: #a61390;">return</span> <span style="color: #a61390;">nil</span>;
    <span style="color: #002200;">&#125;</span>
&nbsp;
    <span style="color: #11740a; font-style: italic;">/* walk the linked-list of interfaces until we find the desired one */</span>
    <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>addr <span style="color: #002200;">=</span> <span style="color: #a61390;">nil</span>;
    <span style="color: #a61390;">struct</span> ifaddrs <span style="color: #002200;">*</span>curAddr <span style="color: #002200;">=</span> addrs;
    <span style="color: #a61390;">while</span> <span style="color: #002200;">&#40;</span>curAddr <span style="color: #002200;">!=</span> <span style="color: #a61390;">NULL</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>AF_INET <span style="color: #002200;">==</span> curAddr<span style="color: #002200;">-</span>&gt;ifa_addr<span style="color: #002200;">-</span>&gt;sa_family<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
            <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>curName <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> stringWithCString<span style="color: #002200;">:</span>curAddr<span style="color: #002200;">-</span>&gt;ifa_name<span style="color: #002200;">&#93;</span>;
            <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>ifName isEqualToString<span style="color: #002200;">:</span>curName<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
                <span style="color: #a61390;">char</span><span style="color: #002200;">*</span> cstring <span style="color: #002200;">=</span> inet_ntoa<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#40;</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">struct</span> sockaddr_in <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>curAddr<span style="color: #002200;">-</span>&gt;ifa_addr<span style="color: #002200;">&#41;</span><span style="color: #002200;">-</span>&gt;sin_addr<span style="color: #002200;">&#41;</span>;
                addr <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> stringWithCString<span style="color: #002200;">:</span>cstring<span style="color: #002200;">&#93;</span>;
                <span style="color: #a61390;">break</span>;
            <span style="color: #002200;">&#125;</span>
        <span style="color: #002200;">&#125;</span>
        curAddr <span style="color: #002200;">=</span> curAddr<span style="color: #002200;">-</span>&gt;ifa_next;
    <span style="color: #002200;">&#125;</span>
&nbsp;
    <span style="color: #11740a; font-style: italic;">/* clean up, return what we found */</span>
    freeifaddrs<span style="color: #002200;">&#40;</span>addrs<span style="color: #002200;">&#41;</span>;
    <span style="color: #a61390;">return</span> addr;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">+</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>ipAddressForWifi <span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span>NetUtil ipAddressForInterface<span style="color: #002200;">:</span>kWifiInterface<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">+</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>netmaskForInterface<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>ifName <span style="color: #002200;">&#123;</span>
    NSAssert<span style="color: #002200;">&#40;</span><span style="color: #a61390;">nil</span> <span style="color: #002200;">!=</span> ifName, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Interface name cannot be nil&quot;</span><span style="color: #002200;">&#41;</span>;
&nbsp;
    <span style="color: #a61390;">struct</span> ifreq ifr;
    <span style="color: #a61390;">strncpy</span><span style="color: #002200;">&#40;</span>ifr.ifr_name, <span style="color: #002200;">&#91;</span>ifName UTF8String<span style="color: #002200;">&#93;</span>, IFNAMSIZ<span style="color: #002200;">-</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#41;</span>;
    <span style="color: #a61390;">int</span> fd <span style="color: #002200;">=</span> socket<span style="color: #002200;">&#40;</span>AF_INET, SOCK_DGRAM, <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span>;
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">-</span><span style="color: #2400d9;">1</span> <span style="color: #002200;">==</span> fd<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Failed to open socket to get netmask&quot;</span><span style="color: #002200;">&#41;</span>;
        <span style="color: #a61390;">return</span> <span style="color: #a61390;">nil</span>;
    <span style="color: #002200;">&#125;</span>
&nbsp;
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">-</span><span style="color: #2400d9;">1</span> <span style="color: #002200;">==</span> ioctl<span style="color: #002200;">&#40;</span>fd, SIOCGIFNETMASK, <span style="color: #002200;">&amp;</span>ifr<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Failed to read netmask: %@&quot;</span>, <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> stringWithCString<span style="color: #002200;">:</span><span style="color: #a61390;">strerror</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">errno</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>;
        close<span style="color: #002200;">&#40;</span>fd<span style="color: #002200;">&#41;</span>;
        <span style="color: #a61390;">return</span> <span style="color: #a61390;">nil</span>;
    <span style="color: #002200;">&#125;</span>
&nbsp;
    close<span style="color: #002200;">&#40;</span>fd<span style="color: #002200;">&#41;</span>;
    <span style="color: #a61390;">char</span> <span style="color: #002200;">*</span>cstring <span style="color: #002200;">=</span> inet_ntoa<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#40;</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">struct</span> sockaddr_in <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&amp;</span>ifr.ifr_addr<span style="color: #002200;">&#41;</span><span style="color: #002200;">-</span>&gt;sin_addr<span style="color: #002200;">&#41;</span>;
    <span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> stringWithCString<span style="color: #002200;">:</span>cstring<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">+</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>netmaskForWifi <span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span>NetUtil netmaskForInterface<span style="color: #002200;">:</span>kWifiInterface<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://veys.com/2009/06/27/time-to-broadcast-iphone-style/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>NSURLConnection + startImmediately:NO == boom?</title>
		<link>http://veys.com/2008/08/17/nsurlconnection-startimmediatelyno-boom/</link>
		<comments>http://veys.com/2008/08/17/nsurlconnection-startimmediatelyno-boom/#comments</comments>
		<pubDate>Mon, 18 Aug 2008 00:59:47 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[cocoa]]></category>
		<category><![CDATA[nsurlconnection]]></category>
		<category><![CDATA[objective c]]></category>

		<guid isPermaLink="false">http://www.veys.com/?p=320</guid>
		<description><![CDATA[Having issues creating NSURLConnections using initWithRequest:delegate:startImmediately? NSURLConnection *c = &#91;&#91;NSURLConnection alloc&#93; initWithRequest:&#91;NSURLRequest requestWithURL:url&#93; delegate:self startImmediately:NO&#93;; Apparently when not using the simpler initWithRequest:delegate:, or even startImmediately:YES, the connection does not get scheduled in the current run loop. And again apparently, this causes unhappiness to occur when you eventually get around to calling start. Simple fix, just [...]]]></description>
			<content:encoded><![CDATA[<p>Having issues creating NSURLConnections using initWithRequest:delegate:startImmediately?</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #400080;">NSURLConnection</span> <span style="color: #002200;">*</span>c <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSURLConnection</span> alloc<span style="color: #002200;">&#93;</span> initWithRequest<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSURLRequest</span> requestWithURL<span style="color: #002200;">:</span>url<span style="color: #002200;">&#93;</span>
                                                     delegate<span style="color: #002200;">:</span>self
                                             startImmediately<span style="color: #002200;">:</span><span style="color: #a61390;">NO</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>Apparently when not using the simpler initWithRequest:delegate:, or even startImmediately:YES, the connection does not get scheduled in the current run loop.  And again apparently, this causes unhappiness to occur when you eventually get around to calling start.</p>
<p>Simple fix, just stuff it in the current run loop before calling start and everyone gets along just fine.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">&#91;</span>c scheduleInRunLoop<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSRunLoop</span> currentRunLoop<span style="color: #002200;">&#93;</span> forMode<span style="color: #002200;">:</span>NSDefaultRunLoopMode<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>c start<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>If there is something I am doing wrong or something I can do to prevent this, I&#8217;d like to know.  Alas, the API is fairly brief on NSURLConnection, I don&#8217;t think I&#8217;m missing anything.  This seems consistent with Cocoa, Cocoa Touch.</p>
]]></content:encoded>
			<wfw:commentRss>http://veys.com/2008/08/17/nsurlconnection-startimmediatelyno-boom/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Some Airsoft Turret play</title>
		<link>http://veys.com/2008/02/22/some-airsoft-turret-play/</link>
		<comments>http://veys.com/2008/02/22/some-airsoft-turret-play/#comments</comments>
		<pubDate>Sat, 23 Feb 2008 06:45:59 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[projects]]></category>
		<category><![CDATA[airsoft turret]]></category>
		<category><![CDATA[avr]]></category>
		<category><![CDATA[libwiimote]]></category>
		<category><![CDATA[wiimote]]></category>

		<guid isPermaLink="false">http://www.veys.com/blog/?p=57</guid>
		<description><![CDATA[Been toying with the idea of making an Airsoft Gun controller wirelessly via Wii Remote.  Inspired by a previous DefconBots challenge.  Just managed to get control of 2 servos via a ATMega8, serial link to a PC and a Wii Remote talking to said PC via BlueTooth.  Pretty hacky but it works, and it&#8217;s way [...]]]></description>
			<content:encoded><![CDATA[<p>Been toying with the idea of making an Airsoft Gun controller wirelessly via Wii Remote.  Inspired by a previous DefconBots challenge.  Just managed to get control of 2 servos via a ATMega8, serial link to a PC and a Wii Remote talking to said PC via BlueTooth.  Pretty hacky but it works, and it&#8217;s way easier than grokking BlueTooth on the MCU for now.</p>
<p>First video is of 1 servo working with really jittery input.</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="344" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="http://www.youtube.com/v/4P2k3uha0OI&amp;hl=en&amp;fs=1" /><embed type="application/x-shockwave-flash" width="425" height="344" src="http://www.youtube.com/v/4P2k3uha0OI&amp;hl=en&amp;fs=1"></embed></object></p>
<p>Second video is 2 servos on X and Y axis with smoothed input.  Much nicer.</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="344" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="src" value="http://www.youtube.com/v/jMppGliIu0I&amp;hl=en&amp;fs=1" /><embed type="application/x-shockwave-flash" width="425" height="344" src="http://www.youtube.com/v/jMppGliIu0I&amp;hl=en&amp;fs=1" allowfullscreen="true"></embed></object></p>
<p>Using <a href="http://libwiimote.sourceforge.net/">libwiimote</a> on the host side for Wii Remote interfacing.</p>
]]></content:encoded>
			<wfw:commentRss>http://veys.com/2008/02/22/some-airsoft-turret-play/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Python SubWCRev</title>
		<link>http://veys.com/2007/10/26/python-subwcrev/</link>
		<comments>http://veys.com/2007/10/26/python-subwcrev/#comments</comments>
		<pubDate>Sat, 27 Oct 2007 06:52:19 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[svn]]></category>
		<category><![CDATA[windows sucks]]></category>

		<guid isPermaLink="false">http://www.veys.com/blog/?p=64</guid>
		<description><![CDATA[Fired out a little Python script for exercise&#8230; pysubwcrev is a Python version of TortoiseSVN&#8217;s SubWCRev app. SubWCRev is a windows-only console app, pysubwcrev is a command-line argument compatible replacement that is Python-based, and therefore runs on any platform with an available Python interpreter and pysvn. Currently only Linux is tested. The code is hosted @ Google Code. Currently [...]]]></description>
			<content:encoded><![CDATA[<p>Fired out a little Python script for exercise&#8230;</p>
<p>pysubwcrev is a Python version of <a class="external text" title="http://tortoisesvn.net" rel="nofollow" href="http://tortoisesvn.net/">TortoiseSVN&#8217;s</a> <a class="external text" title="http://tortoisesvn.net/docs/release/TortoiseSVN_en/tsvn-subwcrev.html" rel="nofollow" href="http://tortoisesvn.net/docs/release/TortoiseSVN_en/tsvn-subwcrev.html">SubWCRev</a> app. SubWCRev is a windows-only console app, pysubwcrev is a command-line argument compatible replacement that is Python-based, and therefore runs on any platform with an available Python interpreter and pysvn. Currently only Linux is tested.</p>
<p>The code is hosted @ <a class="external text" title="http://code.google.com/p/pysubwcrev/" rel="nofollow" href="http://code.google.com/p/pysubwcrev/">Google Code</a>. Currently no packaged release exists but it is (should be?) feature complete in svn.</p>
<p>Note: This is just a hack at playing w/Python, jabs and criticism w/the style can come in the form of patches.</p>
]]></content:encoded>
			<wfw:commentRss>http://veys.com/2007/10/26/python-subwcrev/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mr. Baybus 3 Preview</title>
		<link>http://veys.com/2005/07/24/mr-baybus-3-preview/</link>
		<comments>http://veys.com/2005/07/24/mr-baybus-3-preview/#comments</comments>
		<pubDate>Mon, 25 Jul 2005 03:06:54 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[projects]]></category>
		<category><![CDATA[digital baybus]]></category>
		<category><![CDATA[mr baybus]]></category>

		<guid isPermaLink="false">http://www.veys.com/blog/?p=209</guid>
		<description><![CDATA[Yet another digital baybus.  The original Mr. Baybus, then Mr. Baybus 2, and now this one with PC control and a graphical LCD! Currently only a few shots of some basic functionality, nothing concrete to announce or deliver unfortunately. Screen Images Application Screenshots]]></description>
			<content:encoded><![CDATA[<p>Yet another digital baybus.  The original <a href="http://veys.com/2002/08/20/mr-baybus/" title="Mr. Baybus">Mr. Baybus</a>, then <a href="http://veys.com/2002/08/24/mr-baybus-2/" title="Mr. Baybus 2">Mr. Baybus 2</a>, and now this one with PC control and a graphical LCD!</p>
<p>Currently only a few shots of some basic functionality, nothing concrete to announce or deliver unfortunately.</p>
<h3>Screen Images</h3>
<table border="0">
<tbody>
<tr>
<td>
<p><div id="attachment_216" class="wp-caption aligncenter" style="width: 160px"><a href="http://www.veys.com/wp-content/uploads/2008/07/mbb3_lcd_splash.jpg" rel="lightbox[209]"><img class="size-thumbnail wp-image-216 " title="Splash screen" src="http://www.veys.com/wp-content/uploads/2008/07/mbb3_lcd_splash-150x150.jpg" alt="Splash screen" width="150" height="150" /></a><p class="wp-caption-text">Splash screen</p></div></td>
<td>
<p><div id="attachment_214" class="wp-caption aligncenter" style="width: 160px"><a href="http://www.veys.com/wp-content/uploads/2008/07/mbb3_lcd_fans.jpg" rel="lightbox[209]"><img class="size-thumbnail wp-image-214 " title="Fans" src="http://www.veys.com/wp-content/uploads/2008/07/mbb3_lcd_fans-150x150.jpg" alt="Fans" width="150" height="150" /></a><p class="wp-caption-text">Fans</p></div></td>
</tr>
<tr>
<td>
<p><div id="attachment_215" class="wp-caption aligncenter" style="width: 160px"><a href="http://www.veys.com/wp-content/uploads/2008/07/mbb3_lcd_lights.jpg" rel="lightbox[209]"><img class="size-thumbnail wp-image-215 " title="Lights" src="http://www.veys.com/wp-content/uploads/2008/07/mbb3_lcd_lights-150x150.jpg" alt="Lights" width="150" height="150" /></a><p class="wp-caption-text">Lights</p></div></td>
<td>
<p><div id="attachment_217" class="wp-caption aligncenter" style="width: 160px"><a href="http://www.veys.com/wp-content/uploads/2008/07/mbb3_lcd_temps.jpg" rel="lightbox[209]"><img class="size-thumbnail wp-image-217 " title="Temperatures" src="http://www.veys.com/wp-content/uploads/2008/07/mbb3_lcd_temps-150x150.jpg" alt="Temperatures" width="150" height="150" /></a><p class="wp-caption-text">Temperatures</p></div></td>
</tr>
</tbody>
</table>
<h3>Application Screenshots</h3>
<table border="0">
<tbody>
<tr>
<td>
<p><div id="attachment_212" class="wp-caption aligncenter" style="width: 160px"><a href="http://www.veys.com/wp-content/uploads/2008/07/mbb3_app_menu.gif" rel="lightbox[209]"><img class="size-thumbnail wp-image-212" title="Menu" src="http://www.veys.com/wp-content/uploads/2008/07/mbb3_app_menu-150x150.gif" alt="" width="150" height="150" /></a><p class="wp-caption-text">Main Menu</p></div></td>
<td>
<p><div id="attachment_210" class="wp-caption aligncenter" style="width: 160px"><a href="http://www.veys.com/wp-content/uploads/2008/07/mbb3_app_fans.gif" rel="lightbox[209]"><img class="size-thumbnail wp-image-210" title="Fans" src="http://www.veys.com/wp-content/uploads/2008/07/mbb3_app_fans-150x150.gif" alt="" width="150" height="150" /></a><p class="wp-caption-text">Fan Controls</p></div></td>
</tr>
<tr>
<td>
<p><div id="attachment_211" class="wp-caption aligncenter" style="width: 160px"><a href="http://www.veys.com/wp-content/uploads/2008/07/mbb3_app_lighting.gif" rel="lightbox[209]"><img class="size-thumbnail wp-image-211" title="Lighting" src="http://www.veys.com/wp-content/uploads/2008/07/mbb3_app_lighting-150x150.gif" alt="" width="150" height="150" /></a><p class="wp-caption-text">Lighting Controls</p></div></td>
<td>
<p><div id="attachment_213" class="wp-caption aligncenter" style="width: 160px"><a href="http://www.veys.com/wp-content/uploads/2008/07/mbb3_app_temps.gif" rel="lightbox[209]"><img class="size-thumbnail wp-image-213" title="Temperatures" src="http://www.veys.com/wp-content/uploads/2008/07/mbb3_app_temps-150x150.gif" alt="" width="150" height="150" /></a><p class="wp-caption-text">Temperatures</p></div></td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://veys.com/2005/07/24/mr-baybus-3-preview/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Conditional Jumping in PIC16 Assembly</title>
		<link>http://veys.com/2003/02/27/conditional-jumping-in-pic16-asm/</link>
		<comments>http://veys.com/2003/02/27/conditional-jumping-in-pic16-asm/#comments</comments>
		<pubDate>Fri, 28 Feb 2003 03:51:09 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[howtos]]></category>
		<category><![CDATA[assembly]]></category>
		<category><![CDATA[pic16]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.veys.com/blog/?p=237</guid>
		<description><![CDATA[PIC Microcontrollers have a funky way of handling conditionals. I&#8217;d like to present a set of macros I&#8217;ve made to make this easier to use, as well as explain the basics behind the technique in general. Most MCU&#8217;s I&#8217;ve worked with before PICs had nice simple conditional statements&#8230; The mnemonic was usually to the effect [...]]]></description>
			<content:encoded><![CDATA[<p>PIC Microcontrollers have a funky way of handling conditionals. I&#8217;d like to present a set of macros I&#8217;ve made to make this easier to use, as well as explain the basics behind the technique in general.</p>
<p>Most MCU&#8217;s I&#8217;ve worked with before PICs had nice simple conditional statements&#8230; The mnemonic was usually to the effect of &#8220;branch if x to destination&#8221;. Not so on the PICs.</p>
<p>On a PIC, we have to do an operation between the data to test, then either skip the next instruction or not, based on the results of this test.</p>
<p>Take the instruction &#8220;BTFSS&#8221; meaning &#8220;Bit-test F, Skip if Set&#8221;. This instruction takes a register and a bit number, and will jump over the next instruction if that bit number in the register is set. For example:</p>
<p>We have 2 registers, REG1 and REG2. We want to know if the value in REG1 equals the value in REG2. A quick, simple way to do this is first to load one into W, then subtract the other from it, with the result going in to W as not to destroy one of the variables. This sets the &#8220;ZERO&#8221; bit in the STATUS register to either 1 if the operation resulted in a 0, or 0 otherwise. We know if the operation resulted in 0 the two values are equal, so we can code like so:</p>

<div class="wp_syntax"><div class="code"><pre class="asm" style="font-family:monospace;">TESTIFZERO
  movf REG1<span style="color: #339933;">,</span> w
  subwf REG2<span style="color: #339933;">,</span> w
  btfss STATUS<span style="color: #339933;">,</span> Z
    <span style="color: #000000; font-weight: bold;">goto</span> NOTEQUAL
EQUAL
  <span style="color: #666666; font-style: italic;">; they were equal</span>
  <span style="color: #000000; font-weight: bold;">goto</span> DONETESTING
NOTEQUAL
  <span style="color: #666666; font-style: italic;">; they weren't equal</span></pre></div></div>

<p>So we can test for equality.</p>
<p>We can also macro-ize it for ease of use&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="asm" style="font-family:monospace;">BEQ <span style="color: #000000; font-weight: bold;">macro</span> REG1<span style="color: #339933;">,</span> REG2<span style="color: #339933;">,</span> DEST	<span style="color: #666666; font-style: italic;">; branch if REG1 == REG2</span>
  movf REG2<span style="color: #339933;">,</span> W			<span style="color: #666666; font-style: italic;">; W &amp;lt;- REG2</span>
  subwf REG1<span style="color: #339933;">,</span> W			<span style="color: #666666; font-style: italic;">; W &amp;lt;- REG1 - REG2</span>
  btfsc STATUS<span style="color: #339933;">,</span> Z		<span style="color: #666666; font-style: italic;">; if result was nonzero: skip out</span>
    <span style="color: #000000; font-weight: bold;">goto</span> DEST			<span style="color: #666666; font-style: italic;">; otherwise jump</span>
  <span style="color: #000000; font-weight: bold;">endm</span></pre></div></div>

<p>This gives us a macro we can call with 2 registers and a destination, and have it jump there if the condition ends up being true, and just pass on through if it&#8217;s not true. Much, much easier to use.</p>
<p>The other tests: inequality, less than, greater than, less than or equal to, greater than or equal to and so on follow a similar pattern. They are all covered in the &#8220;conditionals.inc&#8221; file I use quite often. I have both register-register comparisons and register-literal comparisons in there. Feel free to grab a copy and use it in your next project.</p>
<h3>Downloads</h3>
<ul>
<li><a href="http://www.veys.com/wp-content/uploads/2008/07/conditionals.zip">conditionals</a> (zip)</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://veys.com/2003/02/27/conditional-jumping-in-pic16-asm/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mr. Baybus 2</title>
		<link>http://veys.com/2002/08/24/mr-baybus-2/</link>
		<comments>http://veys.com/2002/08/24/mr-baybus-2/#comments</comments>
		<pubDate>Sun, 25 Aug 2002 05:23:46 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[projects]]></category>
		<category><![CDATA[electronics]]></category>
		<category><![CDATA[legacy articles]]></category>
		<category><![CDATA[microcontroller]]></category>
		<category><![CDATA[mr baybus]]></category>
		<category><![CDATA[pic]]></category>

		<guid isPermaLink="false">http://www.veys.com/blog/?p=126</guid>
		<description><![CDATA[After such a good response to Mr. Baybus, I decided to up the ante. I wanted temperature sensing and light control, as well as a more refined interface. I also wanted a chance to write much, much better code as Mr. Baybus was most definitely a kludge. This led to the design of Mr. Baybus [...]]]></description>
			<content:encoded><![CDATA[<p>After such a good response to <a href="http://veys.com/2002/08/20/mr-baybus/" title="Mr. Baybus">Mr. Baybus</a>, I decided to up the ante. I wanted temperature sensing and light control, as well as a more refined interface. I also wanted a chance to write much, much better code as Mr. Baybus was most definitely a kludge. This led to the design of Mr. Baybus 2.</p>
<p>Mr. Baybus had a few problems I wanted to take care of. One being price, it cost way too much compared to its utililty value, which is normal for projects like this, but still&#8230;</p>
<p>Mr. Baybus 2 uses a much more sophisticated microcontroller, a PIC 16F870. This is a 28-pin SDIP style chip, lots more I/O pins, an onboard UART, and even an ADC. This little guy also has twice the instruction memory, so I had more freedom to make the interface somewhat more sleek, and add more features. The benefit of more pins is CHEAPER LCD. The previous serial LCD ran about $42 shipped, which is semi-high for a serial LCD in general, but it was a CrystalFontz so at least it was high quality. Anyways, now I can move to a simple <a href='http://en.wikipedia.org/wiki/HD44780_Character_LCD' target='_blank'>HD44780</a> based parallel LCD (by <a href="http://www.crystalfontz.com">CrystalFontz</a>, of course). These run around $20 shipped, and even less from other places selling generics.</p>
<h3>Features</h3>
<ul>
<li>Three On/Off Fan controls</li>
<li>One 12V Light control (Neons, etc)</li>
<li>Two centrigrade temperature sensors</li>
<li>20&#215;2 screen (any HD44780 compatible will work)</li>
<li>Simple, menu-driven style interface</li>
<li>Stores fan status in non-volatile memory</li>
</ul>
<h3>Display Images</h3>
<table border="0">
<tbody>
<tr>
<td>
<p><div id="attachment_194" class="wp-caption aligncenter" style="width: 160px"><a href="http://www.veys.com/wp-content/uploads/2008/07/mbb2_splash.jpg" rel="lightbox[126]"><img class="size-thumbnail wp-image-194" title="Splash screen" src="http://www.veys.com/wp-content/uploads/2008/07/mbb2_splash-150x127.jpg" alt="" width="150" height="127" /></a><p class="wp-caption-text">Splash screen</p></div></td>
<td>
<p><div id="attachment_195" class="wp-caption aligncenter" style="width: 160px"><a href="http://www.veys.com/wp-content/uploads/2008/07/mbb2_status.jpg" rel="lightbox[126]"><img class="size-thumbnail wp-image-195" title="Fan status" src="http://www.veys.com/wp-content/uploads/2008/07/mbb2_status-150x136.jpg" alt="Fan status" width="150" height="136" /></a><p class="wp-caption-text">Fan status</p></div></td>
<td>
<p><div id="attachment_196" class="wp-caption aligncenter" style="width: 160px"><a href="http://www.veys.com/wp-content/uploads/2008/07/mbb2_status2.jpg" rel="lightbox[126]"><img class="size-thumbnail wp-image-196" title="Fan status w/selection" src="http://www.veys.com/wp-content/uploads/2008/07/mbb2_status2-150x129.jpg" alt="Fan status w/selection" width="150" height="129" /></a><p class="wp-caption-text">Fan status w/selection</p></div></td>
</tr>
<tr>
<td>
<p><div id="attachment_193" class="wp-caption aligncenter" style="width: 160px"><a href="http://www.veys.com/wp-content/uploads/2008/07/mbb2_lighting.jpg" rel="lightbox[126]"><img class="size-thumbnail wp-image-193" title="Lighting status" src="http://www.veys.com/wp-content/uploads/2008/07/mbb2_lighting-150x133.jpg" alt="Lighting status" width="150" height="133" /></a><p class="wp-caption-text">Lighting status</p></div></td>
<td>
<p><div id="attachment_197" class="wp-caption aligncenter" style="width: 160px"><a href="http://www.veys.com/wp-content/uploads/2008/07/mbb2_temperature.jpg" rel="lightbox[126]"><img class="size-thumbnail wp-image-197" title="Temperatures" src="http://www.veys.com/wp-content/uploads/2008/07/mbb2_temperature-150x127.jpg" alt="Temperatures" width="150" height="127" /></a><p class="wp-caption-text">Temperatures</p></div></td>
</tr>
</tbody>
</table>
<h3>Unit Images</h3>
<table border="0">
<tbody>
<tr>
<td>
<p><div id="attachment_200" class="wp-caption aligncenter" style="width: 160px"><a href="http://www.veys.com/wp-content/uploads/2008/07/mbb2_front_up.jpg" rel="lightbox[126]"><img class="size-thumbnail wp-image-200" title="High view of the front" src="http://www.veys.com/wp-content/uploads/2008/07/mbb2_front_up-150x150.jpg" alt="High view of the front" width="150" height="150" /></a><p class="wp-caption-text">High view of the front</p></div></td>
<td>
<p><div id="attachment_198" class="wp-caption aligncenter" style="width: 160px"><a href="http://www.veys.com/wp-content/uploads/2008/07/mbb2_back_up.jpg" rel="lightbox[126]"><img class="size-thumbnail wp-image-198" title="High view of the back" src="http://www.veys.com/wp-content/uploads/2008/07/mbb2_back_up-150x150.jpg" alt="High view of the back" width="150" height="150" /></a><p class="wp-caption-text">High view of the back</p></div></td>
</tr>
<tr>
<td>
<p><div id="attachment_199" class="wp-caption aligncenter" style="width: 160px"><a href="http://www.veys.com/wp-content/uploads/2008/07/mbb2_backpanel.jpg" rel="lightbox[126]"><img class="size-thumbnail wp-image-199" title="Back view" src="http://www.veys.com/wp-content/uploads/2008/07/mbb2_backpanel-150x150.jpg" alt="Back view" width="150" height="150" /></a><p class="wp-caption-text">Back view</p></div></td>
<td>
<p><div id="attachment_201" class="wp-caption aligncenter" style="width: 160px"><a href="http://www.veys.com/wp-content/uploads/2008/07/mbb2_underneath.jpg" rel="lightbox[126]"><img class="size-thumbnail wp-image-201" title="Underneath" src="http://www.veys.com/wp-content/uploads/2008/07/mbb2_underneath-150x150.jpg" alt="Underneath" width="150" height="150" /></a><p class="wp-caption-text">Underneath</p></div></td>
</tr>
</tbody>
</table>
<h3>Version 2.1</h3>
<p>A slight update to the original. I decided I wanted to re-write it in C as an exercise.  While I was at it, I figured I&#8217;d add a feature or two.</p>
<p>Pretty basic, a complete re-write in C, Hi-Tech PICC to be exact. It&#8217;s a great compiler for the PICs and gave me opportunities to re-write the LCD, ADC and DELAY libraries in C.</p>
<h3>New Features</h3>
<ul>
<li>New program-loop idea, worked well</li>
<li>Strobe mode for Light output</li>
<li>Temperatures in Celcius or Fahrenheit</li>
</ul>
<h3>Downloads</h3>
<p>All files for Mr. Baybus 2 are distributed under a <a href="http://www.opensource.org/licenses/bsd-license.php">BSD</a>-style license.</p>
<ul>
<li>Original
<ul>
<li><a href="http://www.veys.com/wp-content/uploads/2008/07/mbb2-src.zip">Assembly source code, and assembled HEX file (built for 16F870)</a> (zip)</li>
<li><a href="http://www.veys.com/wp-content/uploads/2008/07/mbb2_parts.sxc">Parts list</a> (<a href="http://www.openoffice.or">OOo</a> spreadsheet)</li>
<li><a href="http://www.veys.com/wp-content/uploads/2008/07/mbb2_screens.sxc">Screen prototypes</a> (OOo spreadsheet)</li>
</ul>
</li>
<li>v2.1
<ul>
<li><a href="http://www.veys.com/wp-content/uploads/2008/07/mbb21-src.zip">C source code, and compiled HEX file (built for 16F870)</a> (zip)</li>
<li><a href="http://www.veys.com/wp-content/uploads/2008/07/mbb21_screens.sxc">Screen prototypes</a> (OOo spreadsheet)</li>
</ul>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://veys.com/2002/08/24/mr-baybus-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PIC buttons (interrupt-based)</title>
		<link>http://veys.com/2002/08/23/pic-buttons-interrupt-based/</link>
		<comments>http://veys.com/2002/08/23/pic-buttons-interrupt-based/#comments</comments>
		<pubDate>Sat, 24 Aug 2002 05:08:56 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[howtos]]></category>
		<category><![CDATA[electronics]]></category>
		<category><![CDATA[interrupts]]></category>
		<category><![CDATA[legacy articles]]></category>
		<category><![CDATA[microcontroller]]></category>
		<category><![CDATA[pic]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.veys.com/blog/?p=124</guid>
		<description><![CDATA[Previously, in PIC buttons (polling) we saw how to poll for the state of a line connect to a button, that is all fine and good but really that is not the best way to do them. The &#8220;real&#8221; way to interface with external components like that is through interrupts, a slick feature. Interrupts provide [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_250" class="wp-caption alignright" style="width: 160px"><a href="http://www.veys.com/wp-content/uploads/2008/07/interrupt_schematic.gif" rel="lightbox[124]"><img class="size-thumbnail wp-image-250" title="Schematic" src="http://www.veys.com/wp-content/uploads/2008/07/interrupt_schematic-150x150.gif" alt="Schematic" width="150" height="150" /></a><p class="wp-caption-text">Schematic</p></div>
<p>Previously, in <a href="http://veys.com/2002/08/22/pic-buttons-polling/" title="PIC buttons (polling)">PIC buttons (polling)</a> we saw how to poll for the state of a line connect to a button, that is all fine and good but really that is not the best way to do them. The &#8220;real&#8221; way to interface with external components like that is through interrupts, a slick feature.</p>
<p>Interrupts provide you with lots of freedom in your code. They allow you to sit back, relax, and be told when an event occurs, and not be forced to sit and wait for it to happen.</p>
<p>For this program, the schematic and circuit are practically the same, the only thing that changed location is the button.</p>
<p>Instead of looping over and over again, we simply wait, using a goto $ we are essentially goto&#8217;ing the same address over and over, &#8220;goto here, goto here, goto here&#8230;&#8221; ad nauseum. A common technique is also to use a SLEEP command, which puts the PIC in a low power mode and halts the program counter. Same effect to the user though. You of course could do &#8216;real&#8217; work too instead of just burn cycles.</p>
<p>Once the button is pressed and released, the PIC will generate an interrupt, forcing the program to goto memory location 4. This is labeled in the code as ISR (Interrupt Service Routine).</p>
<p>For this program we are using the RB0/INT Interrupt. This interrupt occurs when there is a low-high change in PORTB,0. It can also be configured for high-low as well.</p>
<p>To enable this, we set INTCON,INTE. This bit says we want to know if a change occurs. To enable interrupts in general, we must then set INTCON,GIE. This lets all enabled interrupts occur.</p>
<p>We then wait for the interrupt. Once it occurs, GIE is automatically cleared so we can&#8217;t have them inside each other, and blink the LED a couple times. We then clear the interrupt flag, saying we&#8217;ve handled the interrupt (INTCON,INTF). We then re-enable interrupts and return from the interrupt: retfie.</p>
<p>It should be noted that if we were using more than one interrupt type, we would have needed to check the flag bits to find out which one interrupted us. We then handle it, and clear its flag. The PIC is somewhat crippled in this manner. Any and all interrupts generated and thrown into address 4 and &#8220;we&#8221; have to figure out which one occured. Many higher end MCU&#8217;s will have a table of addresses to jump to for each particular interrupt type, we then code in each location the correct routine and the processor knows which to call based on what happens.</p>
<h3>Downloads</h3>
<ul>
<li><a href="http://www.veys.com/wp-content/uploads/2008/07/interrupts.zip">Source Code</a> (zip)</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://veys.com/2002/08/23/pic-buttons-interrupt-based/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
