## Icom CI-V USB/TTL Rig Cable Design Using the FTDI Chipset

I spent some time this weekend with the fine folks over at NYC Resistor hacking on some ham radio related stuff. We took a crack at a USB CI-V interface for an Icom radio. Googling around, we found lots of level converters for RS-232 serial ports, but very little with USB in mind. In addition, most of the circuit designs for homebrew cable assemblies were quite complicated, and generally speaking, published in about 1992.

It turns out that the Icom CI-V interface is TTL-based, with the TX/RX cables bridged together, with a ground reference on the sleeve of the 3.5mm connector. Given the popularity of Arduino and similar chipsets that require a TTL serial interface to program and operate, we figured we could do better with a prefabricated USB-TTL cable like the TTL-232R-5V from FTDI. It turns out the resulting build is stupid-easy.

Here’s a diagram of the resulting assembly, for those who are searching for how to do this:

We turned out to require a stereo Ring-Tip-Sleeve connector rather than a mono two-conductor one, despite much documentation claiming the contrary. Your mileage may vary.

If necessary, one could also use the RTS/CTS contact-closure as a push-to-talk switch setup, which most of the popular ham radio software packages support. The total cost of this assembly is roughly $20, which is how much the cable costs. To cut costs even further (down to about$5), you could hack this together using the bare FT232RQ chip which you can get from Mouser for $4.95 as of this writing. In any case, this is a pretty massive improvement over the$60 that Icom likes to charge for the equivalent.

The drivers are available for all major platforms and are bundled in the Linux kernel already so the additional software needs are minimal for this over a ‘traditional’ RS-232 cable. We tested this on Mac, Linux, and Windows with perfect results.

## Puppet, Mercurial and Syntax-Checking

I am a frequent user of Puppet for system administration, and have given a couple of presentations on how to use Puppet in a security-focused shop. One of the things I’ve found is that revision-control of the puppet configuration via an SCM is a huge win and helps enormously in troubleshooting issues and rolling back errors. Since a large part of Puppet’s configuration is essentially an interpreted language with a real syntax, it makes sense to enforce valid syntax, either at commit-time or push-time, particularly since Puppet’s syntax is quite irritating and prone to error. Searching around, I couldn’t find anyone who had done this with Mercurial, since apparently Git or SVN are the weapons of choice in the Puppet community. Since I work at a Mercurial shop, I adapted this script. Here’s how to make it work:

1. Put this shell script somewhere world-executable:
#!/bin/bash

echo "Starting puppet syntax check"

# Create a tempfile
tempfile=mktemp -t puppet_syntax

# Get a list of all modified files
hg log -r tip --template "{files}\n" | sort | uniq > $tempfile # Walk through our list for line in$(< $tempfile); do # Check that it's actually a puppet file if [ echo$line | grep -E "\.pp$" ] then echo "Found puppet file$line"
hg cat -r tip $line | puppet --parseonly if [$? -ne 0 ]
then
rm -f $tempfile echo "Puppet parse error found" exit -1 fi echo "Puppet file valid:$line"
fi
done
rm -f \$tempfile
exit 0

2. If you use a central repository that you keep your code in, you’ll probably want to use Mercurial’s ‘pretxnchangegroup’ hook. Put this section in the hgrc file for the repo in question; you may need to add the file in /path/to/repo/.hg if it doesn’t exist:
[hooks]
pretxnchangegroup = /usr/local/bin/puppet-syntax-check.sh
3. That should be about it. Next time you push a changeset to your central repository, the script will be invoked. Note that only files that end in .pp will be syntax-checked. Your repository probably contains multiple sorts of configuration files which obviously won’t conform to the Puppet syntax. If the check fails, the central repository will roll back the transaction, and you’ll have to push a changeset which results in the ‘tip’ revision containing valid syntax.

## The Three-Pile Card Trick

December 13th, 2010 § 1 comment § permalink

This year at a holiday party Alex and I were at, a magician was making his way amongst the tables and performing some sleight-of-hand illusions as well as some classic mathematical card tricks. This afternoon, this video popped up in my Twitter feed:

Being almost done with finals for the semester I thought I’d take a few seconds and figure out how the trick works as a short exercise in reasoning.

First, some intuition: the trick works every time provided you follow the algorithm given. Therefore the three ‘chosen’ cards must be in the same place in the deck every time. This suggest the ‘cutting’ routine is for illusion only. The second half of the trick involves sequentially cards in odd ‘positions’ in the deck which suggests some relative primality.

Next, we prove to ourselves that the position of the chosen cards in the deck is deterministic. At the beginning we have four piles with sizes as follows:

$P_1 = 10, P_2 = 15, P_3 = 15, P_4=9$

We then add in the cards and cut the piles accordingly:

$P_1 = 10+C_1+\alpha, P_2=(15-\alpha)+C_2+\beta, P_3 = (15-\beta)+C_3+9$

So, after we combine the four piles, but before we move four cards from the top to the bottom of the pile, we can tell by simplifying that the sequence of cards from bottom to top is:

$10 \cdots C_1 \cdots 15 \cdots C_2 \cdots 15 \cdots C_3 \cdots 9$

If we count from the top to the bottom, after we have moved four cards from top to bottom, the three chosen cards will always be in positions 6, 22, and 38.

Now that we know what happens in the first half of the trick, we move onto the second part. It’s quite clear that the performer starts removing odd-positioned cards from the deck. So we need to show that positions 6, 22 and 38 have some special property that keeps them in the deck to the point where there are only three remaining cards. At first glance this seems unlikely. They are all even, to be sure, so they will pass the first round, but on second round, position 6 will be in position 3, so that card will get eliminated. Looking naïvely, there are of course positions that will survive four rounds of elimination, which are 16, 32, and 48, multiples of 2^4 or 16. These cards don’t occupy those positions.

It took me a moment to figure out what was going on here. Keeping the non-eliminated cards face down has the effect of reversing the deck, so the first card to be ‘kept’ will actually be in position 26 in the next round. When I worked the problem through a couple of times I dealt the cards to myself face-up to try and suss out which positions the chosen cards end up in. Of course, this breaks the trick completely.

Before the first pass, the chosen cards are in the following positions, and there are 52 cards in the deck.

$C_1 = 6 \\ C_2 = 22 \\ C_3 = 38$

After one round of elimination, with 26 cards in the deck

$C_1 = 24 \\ C_2 = 16 \\ C_3 = 8$

After two, with 13

$C_1 = 2 \\ C_2 = 6 \\ C_3 = 10$

After three with 6:

$C_1 = 6 \\ C_2 = 4 \\ C_3 = 2$

Finally after four eliminations and with three cards left:

$C_1 = 1 \\ C_2 = 2 \\ C_2 = 3$

Finally, then, the position p of a card after n rounds is given recursively by:

$\lceil \frac{52}{2n} \rceil - \frac{p_{n-1}}{2} + 1$

So that’s it. No magic, just some arithmetic.

## Taiwan Trip Day 3: Bespoke Shirts, The Queen’s Head, and Naked with the Mafia

We spent today with Alex’s cousin, Ting-Shuen, and her husband Andy, and their friends who happened to be in town from Australia, Carl and Sandy. They very graciously agreed to take us around the northern coastline of Taiwan, and show us around a few things in Taipei as well.

One of the things on my to-do list was to have some custom shirts made (because, honestly, how often do you get the opportunity?), so we stopped by Andy’s tailor in Taipei where I got measured up and ordered three bespoke shirts for the price that you’d pay for one in the US. And that was with fancy fabric. They will be ready later in the week.

Our next stop was in Xindian, where we met up with Carl and Sandy and had some lunch at a neighborhood place where I was, naturally the only white dude in sight, and at least a head taller than everyone else. I don’t think I’ll ever get used to turning heads in restaurants. We had a round of dumplings and noodles, and then set off to the coastline to visit Yeliou, where there’s a park with what the guidebook calls “bizarre rock formations”; along the water’s edge there are about a hundred globes of igneous rock suspended on pillars of sedimentary rock, all hewn away gradually by the tide to create an otherworldly scene on the shore. The most famous of them is the Queen’s Head, so called because in profile it looks like, well, an Egyptian Queen. Supposedly, the Queen’s head will eventually fall over because the base of it will erode away, but apparently that’s been the word for at least a decade, so who knows. There was a line to take a picture in front of it, which we skipped.

On the way out of the rock formations, there’s a small market with snack food. We stopped for some barbecue squid:

Having exhausted all the photo opportunities in Yeliou, we jumped back in the car and drove off to a local town with one of the oldest market streets in the region, which has a shop famous for its duck, which of course we had to try, accompanied by plum juice, which is incredibly sweet, but pretty tasty.

On the way out of town, we stopped at a 200-year old temple. Although the temple is old, it’s been modernized as time has gone on with bright lights, an electronic marquee, and I’m pretty sure I saw some animatronics inside too.

Back in Taipei, we went to the nightmarket, full of stores selling clothing, food, and accessories. It opens at 6PM and apparently goes until at least 2AM. By the time we arrived at 7, it was already packed to the gills with people, deafeningly loud, full of flashing lights, vendors vying for attention and trade, and snack-cart operators selling pretty much every Taiwanese snack in existence:

We stopped regularly at snack vendors, and there was another game of “Make Guy Eat Strange Food”. This is how you play the game:

Host: Hey – try this!
Guy: What is it?
Host: It’s good – try it. I’ll tell you what it is afterwards.
Guy: Okay … <bite> … It’s pretty good; what is it?
Host: It’s duck tongue!
Guy: Hmm… <another bite> chewy, but tasty. <has another one>

Alas, I didn’t get any pictures of the duck tongues, but I have yet to turn down a single thing here.

By the time we left the nightmarket, we’d had some zongzi (meat surrounded by rice cooked in a bamboo leaf), soup, scallion pancakes, tomatoes stuffed with dates (amazing by the way), giant cups of tea, sausages, and of course duck’s tongue. I was pretty well stuffed by the end.

After the nightmarket, we drove to some hot springs back near Xindian. Hot springs are often open twenty four hours and are a particular Taiwanese experience. Most notably, there are no clothes allowed. Supposedly, there are some which require bathing suits, but those are for lame tourists. The baths themselves are outside, and after a shower, you can choose one of three temperature levels. I was only able to manage the middle level, and even then only for a few minutes. All the old Chinese men seemed to be hanging out in the scalding hot bath next door though, happily chatting while clouds of steam billowed around them.

Despite the preponderance of boy parts on view, the hot springs were relaxing and generally terrific. While we were sitting in one of the baths though, Carl pointed out some burly looking guys to me.

“See those guys over there with the big tattoos?”

I replied that I did.

“Mafia,” he said.

The tattoos are quite elaborate, covering a shoulder and uppear arm, and part of the chest, covering the heart. One of the mafiosos was evidently there with his kids, and another was boiling away in the hottest pool. So I can reasoanbly say that I’ve been naked with the Taiwanese mafia.