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

July 25th, 2011 § 10 comments § permalink

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

July 15th, 2011 § 0 comments § permalink

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 § 0 comments § 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

March 16th, 2010 § 1 comment § permalink

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.

Taiwan Trip: Day 2

March 14th, 2010 § 0 comments § permalink

Despite waking up for a short while at 4:30AM, we managed to sleep until about 7:00, when we got up, had some coffee and toast, and went out to visit the nearby market, which Alex has called ‘The Stinky Market’ since she was very tiny. The Stinky Market is a traditional Taiwanese market, with vendors that rotate daily and who sell more or less anything you could ever need: meat, fish, vegetables, live chickens, seafood, clothing, furnishings and everything between.
Also, being traditionally Taiwanese, the ceilings and signage hang about 18 inches lower than anything in the US, so I had to duck down to avoid obstacles every few yards. This, it turns out, is an ongoing issue for me everywhere I go; mostly, it means I have to avoid the odd overhead beam or cardboard advertisement, but I live in fear of bashing into a sprinkler head sticking out of the ceiling and flooding the place.
After the market, we walked along one of the main roads through the local business district, down to the Eslite Bookstore, where we found a Taipei guidebook (which are oddly hard to come by in the US), and had a look around the stationery and gift department, where I found a product that one could never, ever sell in the US:
By midday we were hungry so we set off back to the Far Eastern Tower to have a bite to eat in the basement food court, which outdoes any of its US equivalents; there are no Burger Kings or grim mall food here; the cuisine was top-notch. Alex and I made our way through a fair number of dumplings and a large bowl of wonton soup. Alex’s aunt took up upstairs to the 40th floor of the Far Eastern Tower, where she works, and showed us the view of Taipei from there, where we could see her apartment complex across the street, and Taipei 101 on the east side of the building.
It’s remarkable not only how enormous Taipei 101 is, but how enormous it is compared to pretty much anything else around it. The vast majority of residential buildings in Taipei are four or five stories high at most, and even most of the newest office towers are twenty or thirty stories tall. Taipei 101 is a behimoth that towers over everything else by at least a factor of two. Even living in New York where I’m used to seeing the Empire State Building, Taipei 101 just seems so much taller by virtue of its being so much bigger than everything else around it.
and then we headed off to Xindian, where most of the rest of Alex’s family lives, to pay them a visit. We were variously shown around each of their condos, starting with Alex’s eldest aunt for some tea and fruit, then her uncle, and finally her cousin and her husband’s house. By the end I was showing obvious signs of jetlag so we were driven home for a rest.
Dinner was at 6:00, at a local–and famous–Peking Duck house, where, somehow, the crowd for dinner was even bigger than last night, coming to some 18 people this time with the addition of some old family friends and more in-laws as well. Big group dinners are an elaborate affair, and there are some critical customs to explain. First, all the dishes are served family-style, and put on a Lazy Susan for easy access and to keep spillage down to a minimum. The dinner starts off slowly with small bowls of pickles and appetizers, and then the floodgates seem to open and dishes come thick and fast, with the main dish beingPeking Duck served three ways: roasted, served with wrappers and sauce; in a soup; and finally with beansprouts.
The other main custom to introduce here is the toasting ritual, which is taken very seriously. Dinner is usually served with liquor–often whisky–which you drink from a very small shot glass, perhaps an ounce of liquid at a time. One is not supposed to drink alone; you summon the attention of a companion and look them in the eye to toast them before drinking.
Now, at our table, the game of the evening was “Make Guy Eat and Drink Strange Chinese Things”. Luckily, I have an iron stomach and English drinking genes, so I was ready for this. I’d also been prepped beforehand about Kaoliang jiu, the infamous spirit made from sorghum, notorious for knocking unsuspecting foreigners on their unsuspecting arses. A bottle was brought to the table and shared out. Perhaps it’s because I’ve been eating for two days straight, or because I’m just a heavy drinker in general, but I’m pleased to report that 120-proof booze presented little challenge. Nor did it for Alex, either. Perhaps this isn’t actually something to be proud of. The toasting continued throughout the meal, with people walking between tables to toast each other. Alcohol is definitely a social lubricant regardless of language barriers.
So, with that established, the next step was naturally to try me with some local cuisine, including pig’s blood soup with intestines, and duck brains. I was too full to try the duck brains, but I must say that pig’s intestine soup was most excellent, if perhaps a little chewy.