Jan 15

FTDI Drivers

So I figured that I’d talk about FTDI’s Linux D2XX drivers for a little bit, and about some odd things that they do.

First of all, FTDI makes really nice chips.  We use them at work.  The problem came about as follows: we tried to have both an SPI device and a normal serial port on an FTDI 4232H, since it has 4 possible serial ports.  So, we figured that using the FTDI D2XX drivers would work, in conjunction with their MPSSE drivers to communicate with the SPI device.

Wrong.

As it turns out, FTDI tries to be clever with their drivers.  That, or they have no idea how Linux works(I don’t know if this affects Windows as well.)

You see, what FTDI does is to dynamically load the methods that they are going to call.

That is not the right way to do it.

You know why?

Because that’s the job OF THE LINKER.

This is why when linking with D2XX drivers, you need to pass -ldl to the linker.

Also, this is done in the initializer of the drivers, which happens to be name my_init, presumably because they simply copied whatever example they found on the internet in order to do this.  There are very few occasions where it is appropriate to use an initializer in a library.  This is not one of them.  You know why?  Because their library is built on top of libusb.  So there isn’t even anything special going on.

Now, FTDI’s MPSSE library also has an initializer named my_init.  So you can’t statically link the libraries in.  Dynamic linking links cleanly, but the program doesn’t work.  And as it turns out, you just send MPSSE commands to the serial port once you put it into MPSSE mode.  So libraries are being duplicated now.

So what can be done to fix this problem?

Well, it’s very simple.

You can link shared libraries to each other.

So, when creating libFTD2XX, FTDI should remove the initializer, and pass in -lusb to the linker.  Sure, those of us who link to the library may also have to link to libusb, but it’s a small price to pay to be able to use the software properly.  It also has the nice side effect of having a linking error when compiling, instead of a runtime segfault in the initializer which would happen with earlier versions of the library.

Dec 04

Linux & Simplicity

A while ago, I posted some thoughts on Linux installing.  Just today, I came across this blog post, which covers kindof the same things.  The problem that seems to exist now is that there are multiple ways to do things.  Not that it’s a bad thing; but there’s no real standard way to do it.  Everybody wants to come up with their own way of doing things, as commented on in this article.  New tools are fine, but what should be happening is have these new tools simply provide new ways of accessing/modifying information, not as replacements.  Why is there a separate service that runs for adding users?  That utility has existed ever since UNIX came around.  It’s impossible to actually figure out what file is actually being used at any point in time.

This lack of standardization is really killing me here.  Just today, I was trying to install gnome-common for some development work, and it put it in /usr/local/share/aclocal.  Which is fine, except that the way aclocal is configured on Ubuntu 12.04 it should actually be /usr/share/aclocal.  WHY IS THIS DIFFERENT?!

This is, again, where Windows is better.  Each program has its own, special folder, typically in Program Files.  All the .exes, dlls, images, etc. go in there.  It’s essentially a self-contained unit.  You have the system registry to tell you information about programs, some variables needed, and where they are.  Granted, the system registry is abused quite often.

So, here’s basically what I think needs to happen:

  • Programs should have their own folder that they store all of their .so, executables, images, etc in.
  • Paths need to be better defined, i.e. where to put something, does it go in /usr, /etc, /local, what?  Currently, programs are scattered all over the place, and shared libs also
  • The only shared libraries that should go in the shared library folder(i.e. /usr/local/lib ) are actually shared libraries,  stuff that is used by more than one program.  If you use it only for your program, that goes in your program folder
  • There should be some kind of registry.  This would probably hold information like where to find something, and would essentially be an extension of environment variables, but for all users.  For example, let’s say that you have two different daemons that provide some service.  This registry would point at the daemon that you want to use – as long as their APIs are standardized, it shouldn’t matter which one you’re using.
  • APIs need to be standardized.  There doesn’t seem to be one “true” way to do anything.  As we can see, you can use one of several interfaces to do the same task, which all do something slightly different.

Maybe this would be a good time to split off something new from Linux.  In addition to doing the above standardization, this is also what I would like to see:

  • Get rid of X.  Sure, X is fine and all, but maybe Wayland would be better?  X is annoying to use, and it was designed for something else than what it is being used for now.  Something simpler, with built-in support for modern APIs(such as OpenGL) would be great.
  • Get rid of the SysV init interface.  Use Upstart instead, completely deprecate it.
  • Any new programs and APIs should not replace old programs, such as useradd or usermod.  They should simply provide a new way of doing it.

Well, that’s a mostly disorganized post.  Braindump complete.

Dec 02

DBus Tutorial Updated

I’ve updated the DBus tutorial. When I moved to WordPress, some of the escaped sequences were not quit rite. So, I’ve fixed all of those, and updated the text a little bit to reflect changes in dbus-cxx. If anything is still not right, please post – or any questions, please post those too! I can’t fix problems if I don’t know that they exist.

Oct 28

TV on PC

So a few weeks ago, I got a Hauppauge 950q to watch TV on my computer.  I finally got it working today, because of all the stuff that I’ve had to go through.  First, I got a new cable box from Comcast.  Once I had the box though, there is no Coax out from the box.  So I had to use the composite input.  That’s fine, so I try to fire up Windows Media Center to play it.  Well, it turns out that Media Center refuses to work properly unless there is an IR blaster remote to control the box.  I don’t care about that, because I can just use the standard remote.  So, I tried using the standard WinTV7.  Unfortunately, this seems to lock up my computer with alarming regularity.  So, I’ve now moved on to MediaPortal.  Fortunately, it does not lock up on me.  The only problem that I had was a syncing issue between the sound and the video.  Here’s what I did to fix the problem, which may or may not work for other people:

1. Change your codecs  to be Microsoft.  Do do this, open up the MediaPortal configuration in expert mode, and go to ‘Codecs and Renderer’.  This did not fix it for me, but at least one other person said that it fixed it for them.

2.   Under the Media Portal TV Server configuration, go to ‘TV Channels’ and pick the decoder that you are using.  Mine is ‘CVBS#1 on 3’.  In the ‘Channels’ section, click ‘Edit’, and make sure the tuning details are right.  For some reason, mine was on ‘The Netherlands’ for country.  I also selected ‘VCR signal’.  I’m not sure which of these actually fixed the problem, but once I did that my sound is properly synced with my picture.

Oct 17

A Wish for Opera

So I’ve used the Opera web browser for years now.  I’m used to it, I like it.  Not that I particularly have anything against Firefox, but hey.  It’s what I do.

Anyway, when Opera boots I always like to start clean.  But you know what would be very useful?

A way to close, but on the next start to come up with all the tabs that were open.

Many times, I find myself doing something important, and then I put my computer to sleep so that I don’t loose my place.  I would love if there was an option to close Opera, but load all of my currently open tabs on the next startup.  I don’t want this to happen all the time, which is why it would be great if it was some option, like “Exit and Save Tabs”.

(sometimes I get this to happen by just killing the Opera process forcefully.  The end result is the same, but it’s awkward to do)

Aug 21

Editing a file with no tools

So I came across this interesting question on SuperUser yesterday, and it got me thinking… would it be possible to create a full text editor using only standard terminal commands?  That is, could we create a text editor using only standard tools such as shell scripts, sed, awk, grep, etc.  That way it could be completely portable, and not depend on any binaries on the target system.  The only binaries which would be required would be for the standard tools – which should already be installed.

Anyway, that would be cool.

May 09

SVN Syncing

So I just spent a good half of the day today trying to figure out how to sync two repositories together. We’re moving repositories, and so we had to import data from one repository to the other. However, this process took a while, so once we had imported the data into the new repository it was several revisions out of date. There didn’t seem to be a way to use SVN tools to do this. So, I went and wrote a script which would take all the changes from one repo and commit them to the other one with all the data. This was needed because we didn’t have shell access to the new SVN repo, and because of how that repo has to be set-up it would be somewhat infeasible to do another SVN dump.

There are a few limitations with this; there’s no way to add new files to the repo(though you could probably do an svn add right before you commit). There’s also no way to delete any files. In our case, this is not a problem, as there have been only file modifications.

Before you do this, you must checkout both repositories into different directories.

So, without further ado, here’s the code:

#!/bin/bash

ORIG_DIR=<original directory>
NEW_DIR=<new SVN directory>
START_REV=<start revision of original SVN>
END_REV=<end revision of original SVN>
CURRENT_DIR=`pwd`

while [ $START_REV -ne $END_REV ]
do
cd $CURRENT_DIR
cd $ORIG_DIR
svn update -r "$START_REV" #update to next revision of old directry
let "START_REV += 1"

cd $CURRENT_DIR
echo "About to diff, this may take a while..."
diff -qr --exclude=".svn" $ORIG_DIR $NEW_DIR > /tmp/svn_out_orig #figure out what files changed
cat /tmp/svn_out_orig | grep Only > /tmp/svn_diff_files
cat /tmp/svn_out_orig | grep Files > /tmp/svn_out
LINES=`wc -l /tmp/svn_out | cut -d' ' -f1` #how many files changed?
cat /tmp/svn_out | cut -d' ' -f2 > /tmp/sources
cat /tmp/svn_out | cut -d' ' -f4 > /tmp/dests
echo "LINES = $LINES"
while [ $LINES -gt 0 ]
do
    SOURCE=`sed -n "$LINES"p /tmp/sources`
    DEST=`sed -n "$LINES"p /tmp/dests`
    cp $SOURCE $DEST #copy each file that changed to the new directory
    let "LINES -= 1"
done
cd $ORIG_DIR
LOG=`svn log --xml -l 1 | grep msg | sed 's/<msg>//p' | sed 's/<\/msg>//p'` #get the log message for  that commit
cd $CURRENT_DIR
cd $NEW_DIR
echo "ABOUT TO COMMIT"
svn commit -m "$LOG" #commit with message

done
Jan 19

SOPA and PIPA

By this time, you have probably heard quite a lot about SOPA and PIPA, so I won’t repeat that stuff here. I will however say that these bills must be stopped. And so, until they are stopped, we will continue to fight the good fight. Yes, we may be on the side of pirates. But it’s better to have the freedom that we have today than the totalitarianism of tomorrow.

Fight the good fight!

Jun 12

Linux and Installing

So I’ve been working on a way to have C callback functions call member functions of a C++ class. To do that though, I’m upgrading to gcc 4.6, because there are some new features in c++0x that I think could help me solve this problem easily.

However, upgrading to a new version of gcc is apparently totally fucking impossible. I’m currently installing it from debian-main, because my computer runs Aurora OS, which is based off of an older version of Ubuntu. So, in order to upgrade, I first went to the gcc website and downloaded the source. However, it turns out that the source also has some dependencies. So I went and downloaded and installed those. Then I tried to actually compile the thing, and about an hour later it errored out.

Seriously.

For whatever inane reason, gcc just refuses to compile on my system. I tried reconfiguring, and I even tried going to an Ubuntu PPA, but it just did not like that.

This is one of the reasons that I find Linux so very annoying at times. There’s no easy way to install things. On Windows, you generally just download an installer, it does a few things, and then BAM! you can run the program. Linux is a lot more complicated. Especially because many programs you download and install the source. Seriously, would it be too hard to provide a nice simple way to do this? Moreover, why are there several locations for you to put binaries? You have /usr/local/bin/, /usr/bin, /bin, etc. There’s a bunch of random places that you could hide something. It’s very simple on Windows generally. It would be really nice if we could get something like this for Linux, like a more advanced RPM or something like that. Because I’m in about hour five of trying to upgrade gcc here, and this is just fucking bullshit.

Jan 15

D-Bus tutorial finished

D-Bus tutorial finished. It should cover all major aspects of D-Bus, using both method calls and signals. I’ve tried to make it as clear as possible, but I’m afraid that it may not be quite clear. Hopefully it will be useful to people.

On a related note, this has caused me to greatly increase the features available on the website. BBCode now works(only for pages at the moment though). I do however need to make it more robust. At the moment it’s highly likely to break if bad input is introduced. In order to make something that looks good, I’m going to have to write some sort of tokenizer it seems. That way I can replace only certain instances. i.e. I want to make it so that each paragraph is enclosed by a <p> tag, but I don’t want that tag inside of code or quote blocks. Well, maybe inside of quote blocks, but definitely not code blocks. It makes it look weird.