Mar 27

Inception dreams

I had an interesting dream the other night.  In my dream, I was explaining to a person a dream that I had had two nights before.  Also, for some reason, we were standing on a bed.

It seemed very Inception-like, talking about a dream within a dream.  Once I woke up, I was also a little confused about how I remembered a previous dream in another dream, as generally your dreams don’t stay with you when you wake up.

Anyway, that was kinda interesting.  Just a random thought.

Feb 15

Qt UDP Socket – specify source port

Have you ever had to use a QUdpSocket to send data from a specific port?  I had to do this earlier, and I figured out how to do it(although not using Qt-only APIs).

My problem was as follows: I need to be able to receive on a specific port.  The device that I am talking to listens on this port and then responds back on that same port, no matter what my source port is.  So to keep things clean, I figured that it would be best to use just one single socket to send and receive data packets.

The general consensus that I saw after searching Google was that it is not possible to do this.  It is possible, but it doesn’t seem possible using Qt-only APIs.  I knew that it was possible, as I have done this before.  This is the code that I came up with:

 

    int optval = 1;
    int fd;
    struct sockaddr_in socket_config;

    memset( &socket_config, 0, sizeof( struct sockaddr_in ) );

    fd = socket( AF_INET, SOCK_DGRAM, 0 );
    if( fd < 0 ){
        // error handling goes here
    }

    socket_config.sin_port = htons( port );
    if( bind( fd, (struct sockaddr*)&socket_config, sizeof( struct sockaddr_in ) ) < 0 ){
        // error handling goes here
    }

    if( setsockopt( fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof( optval ) ) < 0 ){ // error handling goes here } 

    udp_socket = new QUdpSocket(); 
    udp_socket->setSocketDescriptor( fd );


This allows us to still re-use the proper port, but use the socket in a Qt-like way.

Jan 22

Java RMI Example

So I just spent the last few hours attempting to get Java RMI working.  This was not easy.  However, the good news is that now you can benefit from it!  Link at the end, but first my story…

Last night, I was wondering how you would connect two Java applications together.  The reason for this is because I want to try and have an embedded Tomcat server inside of an application, but also have the capability of developing the webapp separately, since developing both the embedded server and the webapp in the same project did not seem to work very well.  I figured that I could use something like DBus-Java to do this, however I wanted it easily cross-platform.

As it turns out, Java already has something like that built-in!  In the form of RMI, or Remote Method Invocation.  However, the example that they give in the Java Tutorials is not particularly clear.  It also seems to be out of date, although if it actually is I am not sure.  There are several important parts that the tutorial does not go over.  Other documentation talking about what you need to do does not appear to be up to date either, much if it appears to date from Java 6 and before.

Since this was such a hard thing to figure out, I’ve made a standalone Maven project that goes and sets up an RMI client and server.  Hopefully it will help somebody else in the future.

Check out the code on GitHub!

Dec 01

Weddings & Music

I attended a wedding this past weekend, and of course there was a DJ there who played music.  He was perfectly alright, but it got me thinking a bit about the music that is played at weddings(specifically, the wedding reception).  There are a bunch of songs that seem to be played regularly, although the only one that I can think of right now is Cupid Shuffle.  I have not heard the Macarena at a wedding in quite a few years, I think that it was more popular in the late 90s/early 2000s.

And of course, for whatever reason, the final song always seems to be Don’t Stop Believing.  I’m not sure why.  Has anybody else seen this in their travels?  I’m curious to know if this is a widespread thing or not.

One thing that was cool though, was that when the DJ played Piano Man, we all got in a big circle around the bride and groom and sang it to them.

Nov 21

Gyrocopter Man

In the news this week, gyrocopter man, aka Douglas Hughes, pleaded guilty to the felony charge brought against him.  As you may recall, he piloted his gyrocopter onto the lawn of the Capitol in order to deliver mail protesting campaign finance.

Clearly, campaign finance is a problem.  The solution to which I don’t know and I’m not going to ruminate on it right now.

The amusing part (to me, at least) is at the end of the article:

Hughes’s other charges included operating without an aircraft registration, three misdemeanor counts of violating national defense airspace and one misdemeanor count of operating a vehicle falsely labeled as a postal carrier.

For some reason, this is just hilarious to me.  I can see why that is a misdemeanor, it’s just quite amusing to think of a gyrocopter as a means of delivering mail.  It did have the USPS logo on it though, so I suppose it was technically labeled as a postal carrier.

May 19

Export Board from Altium for OSHPark

Here’s a quick guide on exporting a board from Altium Designer 14 to be made by OSHPark.

1. Go to Design -> Layer Stack Manager
2. Set your stackup to be this:

.LayerStackManager

This information was derived from this FAQ.
3. Go to Project -> Compile PCB Project.  Fix any errors that could cause a problem.
4. Go to File -> Fabrication Outputs -> Gerber Files
5. Under ‘General’, set the units to be ‘Inches’ and the Format to be ‘2:4’
6. Under ‘Layers’, select the following layers:

  • Top Overlay
  • Top Paste
  • Top Solder
  • Top Layer
  • Bottom Layer
  • Bottom Solder
  • Bottom Paste
  • Bottom Overlay
  • Mechanical 15(assuming that you have drawn your board outline on mechanical 15)

Now export, save as <projectname>.cam

7. Go to File -> Fabrication Outputs -> NC Drill.  Use the following settings:

  • Units: Inches
  • Format: 2:4
  • Leading/Trailing Zeros: Suprress trailing zeros
  • Coordinate Positions: Reference to relative origin
  • Other: Optimize change location commands

Save as <projectname>-NCDRILL.cam

8. With the NCDRILL.cam file selected, go to File->Export->SaveDrill.  Set the extension to be .xln

9. Go to your project folder, there should now be a sub-folder called ‘Project Outputs for <Project Name>’.  Grab the following files:

  • *.xln
  • *.GBL
  • *.GBO
  • *.GBP
  • *.GBS
  • *.GKO(re-name the .GM15 file to be .GKO)
  • *.GTL
  • *.GTO
  • *.GTP
  • *.GTS

Put these all into a .zip folder.

10. Upload the .zip folder to OSH Park.

11. Have fun!

Apr 23

WMP54G on Windows 7

So I just upgraded my computer today with an nVidia 970GTX so that I can play Grand Theft Auto V.  However, this caused two problems:

  1. I couldn’t fit the card into my case
  2. The new case had a different configuration, so I had to move my wireless card to a different PCI slot.

When that happened, Windows freaked out.  Completely lost its sense of drivers, so my wireless wasn’t working.  How to get it to work(note: this is from memory, some of this wording is not exact):

  1. Go to Device Manager
  2. Right-click on the network device, go to ‘Update Driver Software’
  3. Go to ‘Browse My computer’
  4. Click ‘Let me pick from already existing drivers’
  5. Go to ‘Network Devices’
  6. Scroll down to Ralink Technology
  7. Select the ‘Wireless LAN a/g PCI card’
  8. Install the drivers
  9. Get on the internet!

Now time for GTA V!