Thursday, June 21, 2012

300 Baud Real Time Software Modem

I did a project during my Computer Science graduate program at Utah State University implementing a 300 baud real time software modem. It was a great project, and given my past as a small town BBS sysop (which deserves a dedicated post, but search  the linked page for Wade Berrier), it brought back some great memories.

I was inspired by this youtube video as well as by some of the projects and people I work with.

A video demonstration is posted here and the full write up is posted here.

Note: in the video I say that it was for Summer 2011, but I really did do it in 2012.

Note2: the write up was done with lout.  Why isn't this more popular?

Anyway, enjoy the video and write up.

Tuesday, April 10, 2012

Source Code Navigation with Vim

I'm a pretty naive user of Vim.  It started while watching a professor of mine do code examples on a projector during class.  I was amazed at the speed of which he was copying and pasting code, editing text, etc... all without using the mouse.

When I asked him how he did that, he talked about how he had been using those techniques for 20 years.  I had watched other people use emacs, but they were still moving their hands away from the home row.  That alone motivated me to pick and learn Vi.  (Yeah yeah, I know, a proficient emacs user could have been just as impressive.  More on that later.)

Learning Vim turned out to be a great investment, as I worked on several unix and embedded systems where it was normal to have some form of Vi installed.  It's even usable in the Dvorak layout! (I'll have to save those details for another post).

Back to the topic at hand: Vim is also great for reading and navigating source code.  I would see people using an IDE that would push a button and it would take them to the declaration of a variable, function, etc... "How did you do that!?"  See, I've never used a "real IDE" on a regular basis, and was unaccustomed to such features (feel free to flog me for this).  I had to figure out how to get those features inside of Vim.  (Another sidenote: I can't use anything besides Vim now.  Even my MS words docs often have rows of jjjjj kkkkk sporadically placed.  Another sidenote #2: One of the eclipse Vim plugins I tried last year made eclipse usable, but I still prefer Vim... I'll have to save that one for another post as well.)

Turns out there were several options to get source code navigation working in Vim.  ctags, cscope, an eclipse ipc method, and one I stumbled on because of a co-worker: gnu global.  Anthony swore by global, and indeed, his source code navigation was impressive... even while using emacs!

In any case, after trying all the above tools, I settled on gnu global, although it took some work to get it working with Vim and my setup.  That's what this post is really about: documenting my usage of Vim and gnu global.

First, some settings for .bashrc:
export MAKEOBJDIRPREFIX=$HOME/wa/globaltags
alias maketags='mkdir -p $MAKEOBJDIRPREFIX/$(pwd -P) && gtags -i $MAKEOBJDIRPREFIX/$(pwd -P)'
alias maketags_cpp='GTAGSFORCECPP=1 $(maketags)'

That will set up the command I use to generate the tags: maketags_cpp

global is great in that you can store the generated tags outside the source tree (in this case $HOME/wa/globaltags/).  Plus, you can be anywhere in your source tree and it correctly finds the tags.  You can also have automatic per project tag databases.  These are some of the main reasons I chose gnu global over the alternatives.  I don't want to jump to spots in an unrelated code base.

Now, for Vim.  First, .vimrc:
let GtagsCscope_Auto_Load = 1
let GtagsCscope_Auto_Map = 1
let GtagsCscope_Quiet = 1
set cscopetag

Apparently Vim doesn't have a plugin architecture for tagging systems.  So, global provides a cscope adapter in order to make Vim think it's using cscope, when it's really using global.

Next, drop gtags-cscope.vim into $HOME/.vim/plugins.  You may need to make sure you have the correct version for the version of global you're using.  global also has "gtags.vim", but like I said, Vim doesn't expose an api to allow different tagging systems, making the tag stack unavailable (which, is one of the best features of this setup).

Another sidenote/tip from Anthony: if you ever google for it, make sure you google "gnu global" and not "global" or "gtags".  I know... "gnu global" is a terrible name marketing wise.

So, after installing global, the basic workflow is like this:

  1. enter source dir root and run "maketags_cpp"
  2. open a file with Vim

Some of the common operations I use:

  • go to function/variable definition of identifier under cursor (pushes onto the tag stack): CTRL-]
  • go back (pops off the tag stack): CTRL-t
  • search for all instances of this identifier: CTRL-\ and then e
    • this brings up a list, and you can enter the number to go to that spot.  You can then do ":tn" and ":tN" from the Vim command line to go forward and backwards through the tag list.
  • global also has a method to find all functions that call the function in question.  I don't remember the shortcut, but honestly, I normally use the above item instead.
  • several other search methods that I can't remember right now
Whenever the tags start getting out of date (because of modified code), you can simply go to the root of source code again and run maketags_cpp.  The updates are fast and incremental, which was another reason for choosing global.

There are some warts that I haven't figured out: sometimes the first "common operation" can't find the definition like it should.  In those cases, I use the 3rd "common operation" as a backup.

There are support for other languages, and some have configured global to work with unsupported languages, but googling for those is left as an exercise for the reader.

That's about it.  Just as my co-worker warned, it's pretty hard to work without this functionality after having enjoyed it.

Tuesday, November 22, 2011

Network Protocols

I've been looking over the supported protocols in IP and noticed the following protocols:

NVP http://www.ietf.org/rfc/rfc741.txt

SCTP

I've used and been interested in VoIP for several years.  It was really neat to see a precursor implemented in the 70's.

I had seen SCTP mentioned here and there but never really looked into it.

Here's a great overview: http://www.isoc.org/briefings/017/

Looks like it will become a widely used protocol at some point.

Learning about this stuff reminds me of when I was learning how to use DOS in the early nineties.  I thought I was sooo cool because I was navigating directories and programming batch files.  I later got into linux and read about it's background and history.  "You mean UNIX has been around for 30 years and I had no idea that my beloved DOS was a disgrace?"

Saturday, February 26, 2011

USU VPN Linux Client

I needed to connect to the Utah State University Virtual Private Network.  They had a page about connecting with linux, but it didn't work for me.  I ended up writing a simple script to configure, start, and stop the vpn.  You can find it here:

https://github.com/wberrier/usu_vpn

It works for me on Ubuntu 10.10, as long as I installed an updated openswan (as noted in the README).

Tuesday, September 1, 2009

Qt and Threads

Multithreaded programming is fun, isn't it?

I'm writing a thin Qt wrapper around OpenAMQ so that we can encapsulate a connection in a separate thread without blocking the event loop in the main application thread.

Some guys at work have developed a few nifty tricks to make threaded programming in Qt easy... well, easier... actually, much easier.  But, I was still having some problems (which were mainly caused by some weirdness and wrong documentation in the OpenAMQ client library, but that's a different story).

Other than better understanding how QCoreApplication and QThread event loops interact, here's a lesson I learned:

Don't call deleteLater() within a class that inherits from QThread.  Reason being is that you need to call quit() before the QThread object is deleted, and once you do that, the event loop in QThread stops.  Since your event loop in the QThread object has stopped, the deleteLater will never get processed.

This all comes down to: using deleteLater in this scenario will never call your destructor.

Lesson learned.  Check.

Wednesday, November 19, 2008

svn and tons of ignores

I never realized what a pain it was to maintain svn:ignore properties until I started using git (which makes it really easy to collect cruft metadata after a build).

After some searching on the web, I found this script:
#!/bin/bash

# svn-ignore - tell Subversion to ignore a file in certain operations.

# See: http://svn-ignore.notlong.com [svnbook.red-bean.com]

test -z "$1" && echo "Usage: $0 FILENAME" && exit -1

for fullname in "$@"

do

dirname=$(dirname "$fullname")

filename=$(basename "$fullname")

(svn propget svn:ignore "$dirname" | egrep -v '^$';

echo "$filename") >/tmp/svn-ignore.$$

svn propset svn:ignore -F /tmp/svn-ignore.$$ "$dirname"

rm /tmp/svn-ignore.$$

done


That coupled with:


for i in `svn status` ; do if [ $i != "?" ]; then echo $i ; svn-ignore $i ; fi ; done



really saved me a lot of work.

Monday, August 4, 2008

A New Adventure

Some may have noticed that I haven't been around the Mono irc channels lately. I recently started working at Applied Signal Technology in Salt Lake City on July 7th.

One project I work on is an embedded board with some Xilinx FPGAs, one of which has an embedded ppc processor. It runs embedded linux and does signal processing in the FPGA. The kernel and embedded linux has been a long time favorite of mine.

The other project is a state-of-health hardware and environment monitoring system written in C++/QT. Having been using Python for monobuild and been in the Gnome/Mono circle for a few years, it has been quite the shift to use C++. I found an interesting white paper comparing C++/qt and Java, but have not formalized any opinions yet. Comments?

I wanted to give an update on my disappearance as well as express my graditude to Novell, my fellow co-workers, and the Mono community. It was a great 3 years and an awesome experience. Thanks especially to Andrew and Marc to taking over the build and release processes. We spent my last week or two at Novell transitioning things over and I've also spent some time since then helping them out. I'm fully confident they will do a superb job with Mono 2.0.

Good luck to everyone with the upcoming release. I wish y'all and the Mono project the best.