Multithreading, Python and passed arguments

Recently I\’ve had a project that required precompiling the firmware for a device so that the end user could program the device, but not have the source code. We\’re not talking about a few versions of the code, but almost 1000. This is something that no person would want to do, especially since it would have to be redone every time the source code changes. Python to the rescue. It was simple enough to write a program that would copy the source code, change a bit of information in a header file, compile it and save the binary to the appropriate location. Controlling other programs is pretty easy with the subprocess module. That\’s great and all, but doing it single-threaded, that\’s so 90s. Python makes multithreading pretty simple using its multiprocessing library. The trick is not stepping on any toes when you do it.

Continue reading

Of embedded black boxes

Over the last few months I\’ve been working on projects using PIC microcontrollers. At first I had a rather negative view of the PIC processors. Since I started coding on them, I have come to realize that it is the compiler that I have issues with much more than the hardware. The compiler we\’ve been using by CCS is designed to get projects up and running quickly by abstracting the hardware from the coder. So, instead of directly writing to the registers, you call one of their functions. We\’ve found this works well when it is a mature processor and when we\’re not trying to do too many things at once. Where we ran into lots of frustration was with new processors. We thought we had the code written correctly, yet it wasn\’t working. Now instead of just having our code and hardware errata to look at, I also had to figure out what the CCS code was doing… which means slogging through the disassembled code and looking up the mnemonics for the different assembly operations.

Now, you need to understand where I come from. I\’m a Professional Engineer. When I vouch for something, I\’m saying that it works. When I have the black box of a intrinsic compiler functions, it makes me a little less sure about what is occurring. That\’s one of the reasons why I like the MSP430. TI does a very good job of letting me know what\’s going on with the chip. There\’s not much left to the imagination when using it. The analog functions are well documented and there are good code examples. The Stellaris line of ARM Cortex-M3 chips tries to make both camps happy. It has good documentation of things, but it also comes with a large driver library that encapsulates many of the functions for an engineer to rapidly program on it.

My beef with embedded processor abstraction through libraries or intrinsic functions is that it usually doesn\’t keep up with the latest processors and that it is too easy to do something that modifies something else and then you don\’t know where the problem is being generated because the functions work separately or in a different order. Oh, and they take more memory, on memory constrained processors. What\’s your experience?

Cleaning up filenames for transfer to windows

For those of you run multiple operating systems, you may have run across the problem where the filenames on one are not valid on the other. Specifically I\’ve had that problem when using NTFS filesystems between Linux and Windows. The NTFS3G drivers on Linux will allow characters in the file names that windows doesn\’t like. To solve this, I wrote a quick python script that will make the filenames windows acceptable. Enjoy.

windows_rename.py

#! /usr/bin/env python
#Copyright 2012 Chad Kidder
#Released under GPL v3.0


import os, sys, re, shutil


def SafeNames(location):
    for root, dirs, files in os.walk(location):
        for tfile in files:
            NewFile = InvalidCharacters.sub("_",tfile)
            if NewFile <> tfile:
                shutil.move(os.path.join(root, tfile), os.path.join(root, NewFile))
                print "%s -> %s" % (os.path.join(root, tfile), os.path.join(root, NewFile))
        for tdir in dirs:
            NewDir = InvalidCharacters.sub("_",tdir)
            if NewDir <> tdir:
                print "%s -> %s" % (os.path.join(root, tdir), os.path.join(root, NewDir))
                shutil.move(os.path.join(root, tdir), os.path.join(root, NewDir))

if __name__ == "__main__":
    if len(sys.argv) < 2:
        print "Please enter a directory to fix the file names on"
    else:
        InvalidCharacters = re.compile(r"[\\/?:*|\'\\"]")
        for location in sys.argv[1:]:
            SafeNames(location)

Automating Dreamhost backups

We here at Curious System Solutions use dreamhost as our hosting provider.  One of the nice things they give us is a nice, tidy, backup every month, if we ask for it.  It may take a few days if you ask at the beginning of the month, and it is easy to forget to download.  So, we have a handy python script that will check an imap4 email server to see if the backup is ready, and if so, download it.  The script is designed to be a cron job that can be ran every night so you don\’t have to worry about remembering to download things.

Continue reading

Capacitive Touch Sensing on the MSP430

One of the projects I\’m working on involves using capacitive touch sensing (CTS) on the TI MSP430.  TI has been pushing their touch sensing capabilities recently and has even released a library that helps in implementing touch sensing on the MSP430.  I decided to give it a try.  The short story is that there is a lot on TI\’s site and it is easy to get confused as to what you need.  See below for some of my journey getting it going.Continue reading

A quick note on \”ATX\” Power Supplies

After our recent activity making the emergency ATX power supplies, I got a call one evening from one of the hams who couldn\’t get their salvaged 24-pin power supplies to work.  It turns out that many of the larger computer manufacturers use their own proprietary pinouts.  In this case, he got bit by a Compaq power supply.  A good place to check to see if you can make a proprietary power supply work is pinouts.ru (yes, I know it is in Russia, but to my best knowledge it is not crawling with malicious software).

Directions for Soldering of Compact Emergency ATX 12V Output Board

Last Friday night one of the local amateur radio groups that I\’m affiliated with had a get together with good food, friends and activity. We soldered together the Compact ATX 12V board that we wrote up a little while back. There were a few people who were unable to stay and put it together.  For them (and for anyone else trying this), I have put together some instructions on how to put it together.Continue reading