Archive for the ‘Software’ Category

pscanf: a sscanf replacement for C

Wednesday, August 6th, 2008

In general, I like C. Pointers don’t generally bother me all that much, and its really nice to use for a lot of different things. However, its string handling SUCKS (though, printf is nice). It seems like a lot of the string routines in the standard C library are designed to screw you in the most unexpected ways possible.

So recently I’ve been struggling with processing input from a user on the command line, and I was using sscanf to attempt to do really simple string processing, and it simply wasn’t matching the correct things. After much struggling and coming to the realization that I needed to do something similar to regular expressions… I sat down and wrote the following function, and it works quite well for what I want to do.

What it does do:

  • Match arbitrary strings using a perl regex, and return the matches to you

What it doesn’t do:

  • This is not a drop-in replacement for sscanf: you need to change the format string around and (possibly) your parameters.
  • It will not return anything but a string. Thats all you get. Of course, if you format your regex correctly then you can pretty much be guaranteed that strtol/strtod/etc will work…
  • Give you any kind of comprehensive error reporting. If you want that, then just use the pcre functions directly
  • Cook your meals or do your laundry

This is released under the license contained on, enjoy!


Dynamic Options/Preferences Dialog Library for wxWidgets

Tuesday, April 29th, 2008

So I’ve been doing a lot of work related to my carputer lately, and one of my big focuses is getting Roadnav to be more touchscreen friendly so that I can use it as my primary GPS application. One of the biggest problems I’ve found with most applications (and Roadnav is no exception, unfortunately) is that most of the dialogs are simply too big for my screen. The preferences screen has especially stuck out as an offender here.

To solve this, over the last week I’ve created a set of generic classes that you can use in wxWidgets to create options/preferences dialogs that have a consistent feel to them, and can be easily created at runtime. Its setup in a hierarchical manner, and each layer of the menu is dynamically generated at runtime. Here’s a nice screen shot of the top level menu for your viewing pleasure.

Now, since I’m designing this for a touchscreen, right now the visual design is definitely touchscreen focused. However, its generic enough (thanks to wxWidgets sizers) that you can change the logic in the dialog to whatever you want it to be, without having to change the definition of your menus. In fact, if you do it right you can even switch the look at runtime because of all controls are created at runtime, so each one of the option classes is designed so that you can destroy its controls and then bring it back again.

Another cool option that could be implemented is loading the definitions for the options from an XML file or something similar — I’ve actually created something like that before in C# for the pGina project (see their SVN) — since everything is dynamic, it would be pretty trivial to do that.

Anyways, here’s an overview of how it works:

C# Oscilloscope and Analog Meter Controls

Thursday, April 3rd, 2008

I updated my C# analog meter control awhile ago (it had some bugs), but never got around to posting it online. Well, here are those updates, PLUS I integrated a C# Oscilloscope control as well! I’d put up some screenshots, but I don’t currently have a compiler installed for C# (been redoing my machine) so I can’t take any. But, it works pretty nicely except for a few non-serious bugs….

This is an ongoing set of postings documenting some of the software I developed for my senior project this fall.

Go download it.

Analog Meter (Ammeter/Voltmeter/etc) Control for C# and .NET

Friday, January 18th, 2008

UPDATE: See my newest update, which includes a C# Oscilloscope and Analog Meter control!

This is another open source C# control that was developed for my Senior Design project. Its pretty obvious what it does from the following screenshot.


This is definitely a useful control for some projects, and is released under an open source license. This control implements a simple to use Analog Meter control, similar to old school analog meters used for all sorts of things. Obviously theres a lot more things that could be added to this, but this does what I need it to do at the moment. And, it looks quite nice if I do say so myself. πŸ˜‰ Its very adjustable as well, with integrated designer support.


Add the control to your form, and adjust the Value parameter of the control to move the needle. Pretty easy to use. There are a bunch of other options, such as adjusting the frequency of the tick marks, but they should be mostly self evident as to what they do.

Enjoy! As always, let me know if you either use this or find a bug.

Download: Link

Visual Studio styled Dockable Windows Component Library for .NET

Wednesday, January 2nd, 2008

Well, isn’t THAT a mouthful of a title.

This is another open source project created as a result of my Senior Design project. See, we had this nice GUI, but it seemed like it needed to be a lot more flexible than it was, since using it was really quite annoying. So, I got the idea to copy the interface from Visual Studio… since, in my opinion, the way the dockable windows work in VS is quite intuitive and useful. Some of you may cry out that there are other programs that do the same behavior… well, I copied it from VS.

So, thats what this component library implements. See a screenshot:


As you can see, its capable of fairly complex layouts, with each element completely resizable and movable and such.Β  It is not quite as polished as the interface for Visual Studio, but its still quite intuitive for the user to use, and a pretty decent approximation for most projects. More importantly, its open source!

A sample executable and source code/project files are included in the download package.

Please note that you can NOT drag new panes into the form designer, as implementing the appropriate designer support seemed to be more trouble than its worth. Refer to the PaneTest project for detailed implementation, and the source code for detailed documentation.

If you find any bugs or have any comments or questions, feel free to drop me an email!

Download: Link

PSoC USB SuiteUSB .NET (CyUSB) Asynchronous Wrapper

Saturday, December 8th, 2007

This is the first of a few pieces of software I’ve written for my Senior Design project here at WMU. We created a device using a Cypress PSoC, and I wrote the user interface for the project in C#. I will be releasing a number of components from this project as open source.

If you’ve used the Cypress SuiteUSB .NET library, you’ll notice that they say asynchronously sending and receiving data to and from the device is the difficult way to access the device. Of course, one thing that contributes to the difficulty of using their interface is that its nothing like any other .NET asynchronous operations. If you have used .NET asynchronous sockets or file writing… well, you probably realize that the way Cypress decided to implement their library is definitely NOT .NET oriented, and in general is rather annoying for .NET programmers to use.

Well, it annoyed the heck out of me too, so I wrote a nice wrapper for it. Now, asynchronous sending and receiving is trivial. πŸ™‚

This will allow you to wrap the EndPoints exposed by any CyUSBDevice, so that you can call .NET-style Begin/End asynchronous calls that use IO completion ports to work nicely and quickly. I do not have any benchmarks for it at this time, but I’d bet that it works faster than Cypress’s library.. of course, I could be wrong.

Does NOT support Isochronous transfers. Probably does not support ControlEndPoints either.

A set of demo code is provided.


It’s pretty trivial to use this class. Create an instance of it, then use it like any other BeginXXX/EndXXX pair in .NET. For example:

CyUSBAsyncWrapper usbComm;

// create the wrapper
private void Init(CyUSBDevice usbDevice){
	usbComm = new CyUSBAsyncWrapper(usbDevice.BulkOutEndPt);

// call this to begin transferring the data
private void SendData(byte [] data) {
	usbComm.BeginTransfer(data, data.Length, new AsyncCallback(EndTransfer), data);

// called on another thread when the transfer is complete
void EndTransfer(IAsyncResult result) {

Licensed under a BSD-style license. Let me know if you find any bugs.

Download: Link

Make BitTorrent/P2P less annoying at home using Linux, Iptables, and QoS

Saturday, November 17th, 2007

At home, I’ve been using a Linux router for as long as I can remember… since, a rather long time ago, I didn’t have money for a router but I happened to have an extra computer that I had been playing with Linux on it. So, I developed an ipchains script (which I eventually converted to iptables) to do NAT on it, and its worked pretty well ever since then. I honestly don’t remember where I derived the script from, however.

When I was in the dorms and afterwards in an apartment with others, we had used my Linux router, since it was pretty simple and theres a ton of things you can do with a Linux server. However, something we noticed (which wasn’t specific to this router) is that whenever someone was using BitTorrent or some other P2P app (you know, to download Linux distros and CC-licensed stuff), it would totally kill our internet access unless the person made their upload rate ridiculously low.. which is fine, unless a visitor stops by, plugs in, and forgets to turn their torrents down.

So, sometime last year I decided that there was probably a good way to filter different types of traffic so they don’t get excessive. Turns out, you can combine iptables and the QoS functionality of the kernel to do just that.


MBR Love Note Responses

Tuesday, November 13th, 2007

I have to say, I didn’t quite expect the wide variety of responses to my “MBR Love Note“. And… it was on the front page of Digg and BoingBoing, among other places. Which, has driven a ton of random traffic to the site. πŸ™‚ πŸ™‚ πŸ™‚

I’m not going to bother posting the Digg comments, a lot of them were so far off base and yet wildly amusing.

Cory Dotorow classified it as a “Scary MBR-nuking program.. “.. I don’t know if I would go that far, thats a bit of an exaggeration.

Brandon said “it was a [real, non-script kiddie] hack”.. thanks. πŸ™‚
Gameboy genius filmed installation and booting of the love note and put it on YouTube… you can see it at his blog.

CustomPC wrote that “an expert assembly code programmer writes an app to make your computer greet you with a note when you switch it on”. Expert, eh? Really, its not all that hard…

As an aside, it really is quite trivial to uninstall the program. Look at the comments section for a hint if you really don’t have any idea. Though, you probably shouldn’t install it if you don’t have an idea. I don’t feel like dealing with thousands of people screwing their computer up. It probably (most likely) won’t destroy your computer by any stretch of the imagination..

My roommate Jon provided the text, which I believe he did get from ThinkGeek.

Oh, and yes, I did know the answers to the quiz when I made it. The only one I wasn’t 100% sure about on #3, but I was right when I looked it up. And the quiz is mostly for fun, but anyone who has messed with MBR’s and such should be able to get them right. And I would say a great deal of people *should* be able to get #1 right.

Inspired by XKCD: MBR Love Note

Sunday, November 11th, 2007

I am a huge fan of the webcomic, XKCD, which is a very geeky and amusing comic for those of you who haven’t read it. On Friday, the following comic was posted:

And this of course reminded me of when I first started programming — I started with assembly language in 2000 with an 80286 I got out of the trash. I quickly became interested in low-level system programming, and created a number of MBR-based programs and other random programs in assembly. I haven’t programmed in assembly in a couple years, but this was pretty simple once I started going. πŸ™‚

In any case, the comic has inspired me to write a Windows-based program that can write a “love note” to the MBR and display it when the computer starts. And of course, just for fun it shows the “Missing operating system” message as well. Shown is a screenshot:

Roses are red… missing operating system.