Friday 26 December 2014

Continuing the Blog

The blog posts have been very scarce lately. There are some reasons for that:

One of the purposes with the blog is to follow my programming projects. They are still active but I am focusing a lot on software development in my new position, still in the telecom industry. I haven't been too active in these projects lately, maybe because I learn a lot in programming at work.

I'm investigating what platform to use for the future of my TrafficControl project. So far, I've been using C++/Qt but JavaScript in combination with OpenLayers seem to provide some advantages.

  • Easier deployment (hosting the application on a web site, or perhaps on the blog) will require no installation/tech support.
  • It will allow me to gain experience in Java Script programming, a good complement to the C++ coding that I've done so far.
I've spent some time to find active and closed railroads in Skåne and add them to Google Earth KML files. I'll post some of them on the blog later, together with their history.

Light blue tracks are not in use or removed. Coloured tracks are in use.

The blog is still active and I'll try to be more frequent on the updates (roughly one update per week).

Thursday 6 November 2014

TrafficControl: Looking into Javascript

The last weeks, I've spent time learning Javascript. It is very similar to C++ and, obviously, Java so the learning gap has been quite small.

I'm investigating if I can use Javascript for trafficControl, using Google Maps/Earth to handle the maps with kml files. Kml files contains the coordinates for the tracks and the stations.

As a first step, I created a Javascript that loaded a kml file to a Google Earth window and displayed that on a web page. This was quite easy with the help from Google Earth API. There, one can find some very helpful examples: https://developers.google.com/earth/


The next step was to make the Javascript analyse the coordinates in the kml file. This gave me some headache as the kml file needs to be loaded into the script itself, and this isn't allowed for web security reasons. I'll discuss that in the next post.

For web programming I can recommend http://www.w3schools.com/ with their excellent tutorials in Javascript, AJAX, JQuery, html and several other technologies. For demonstations of their code, they have a "Try it Yourself" feature, where it is possible to modify their examples and explore the code.




Saturday 18 October 2014

Qt: ...and one way to succeed rebuilding Qt to enable static builds!

Finally, just before giving up, I found this article:
http://qt-project.org/wiki/How-to-build-a-static-Qt-for-Windows-MinGW

After securing that I had Powershell and 7-zip installed, I downloaded the script and started the build process again over the work day. After some reconfigurations, where I specified where Qt creator should look for the compiler, I was finally able to create static executables (16 Mb)!

Saturday 11 October 2014

Qt: Static Linking - Nine ways to fail rebuilding Qt to enable static builds...

The case of static building for Qt is discussed below. With Qt installed, the environment provides the needed DLL-s automatically.

Specifying the DLL-s separately for deployment on a non-Qt environment is very complicated. If I'll deploy my projects in the future, that will most likely be in a single exe file, possibly with some resource files. Therefore, I need to get the static deployment working.

To make this possible, the entire Qt source code needed to be recompiled. This process takes many hours.

Initially, I had Qt installed with the compiler set to Microsoft Visual Studio Express 2013, and having the 64-bit version of Qt installed.

After several hours of compiling all the source code, the compilation process crashed. The first issue was that plugins such as SQL didn't compile during the rebuild of Qt. This is a major issue for deploying applications.

At the next attempt (re-installing Qt and rebuilding it with SQL disabled), I got another crash after five hours, complaining that a LIB file was missing. I even tried to reverse-engineer the LIB file from the dll file, but that wasn't successful either.

Even after following the instructions at
http://doc-snapshot.qt-project.org/qtifw-master/ifw-getting-started.html#configuring-qt
the compilation crashed, this time since a stddev.h file wasn't accepted by the compiler.

I tried with both 64/32-bit versions and MinGW32 (Minimalist GNU for Windows) and Microsoft Visual Studio-based Qt framework, without any luck.

This process took me several days. Why mentioning it on the blog? One central part of software development is all the dead-ends and failures in setting up the development environment. For hobby projects it isn't as critical as in commercial projects, where the developer sometimes need to explain for the stakeholders why he/she has spent several days, barking on the wrong tree.

I'll post the success-story in the next blog post.

Tuesday 7 October 2014

Qt: Static and Dynamic linking for deployment of applications

Almost all software is developed using some pre-existing software, so that the developer doesn't need to invent the wheel again.

These pieces of software are imported in different manners to the final program. This may be:

  • Software that polls the keyboard and sends a corresponding character to the buffer/stdin,
  • Software that keeps track of the mouse pointer
  • Software that manages database connections
  • Software that sets up the user interface, such as the "Open file" window.
  • Software that handles networks
  • Software that handles databases
  • ...

In Windows, that code is compiled to DLL files (Dynamically Linked Library). Other operating systems such as Linux has similar libraries.

Put simply, In order to deploy  software and make it useful for others, there are two options: static and dynamic linking.

Static linking will bring the libraries into the exe file (~10-20 Mb). If many program files on a system will need the same libraries, there will be a lot of redundant code in the different executables.

Dynamic linking will make the program refer to DLL files for the needed external code. This results in a smaller exe files (~100kb), but that will be dependent on external DLL files. I'm sure that my readers has got their fair share of dll errors.

Text in Swedish, but the message is clear: 
spend hours chasing DLLs or consider another program.

The program Dependency Walker can be very helpful when finding what DLL files (and what versions) are needed for a program. Still, a lot of work and frustration lies ahead.

In the next blog post I'll describe what problems I saw when I tried building my program statically. Actually, I needed to recompile the entire Qt installation from its sources, and that's where I got the problems.

Until then, I can recommend VoidRealms/Bryan Cairns Youtube videos about DLL:s







Wednesday 1 October 2014

|| AND &&: Why it is a good idea to quibble

I had to recover my Windows 8 installation one week ago, and in that process, I re-installed Qt. This time, I also included the Microsoft Visual Studio Express compiling option for Qt.

After doing that, I tried to rebuild my programs TrafficControl and StockReader. I got houndreds of strange compiler errors that I didn't expect since the programs compiled without warnings before.

The issue was that I used the keywords "and" and "or" in several if clauses. Those keywords are allowed by gcc/g++ (GNU Compiler Collection), but not by Microsoft Visual Studio 2013: http://msdn.microsoft.com/en-us/library/2e6a4at9.aspx

My personal preference would have been to use AND and OR for logical keywords - that would have kept my source code as similar to human language as possible. But I also want my source code to be portable between different operating systems and compilers. So from now on, I'll continue with using the ||, && and != operators instead of OR, AND and NOT.

I still have some problems making static builds for  my programs. More about that in future blog posts.

Sunday 24 August 2014

Maputo, MZ: The Maputo Railway Station

This station is considered to be one of the world's most beautiful stations, and with its beautiful architecture, I can agree to that.




It was built 1916 but the architect wasn't Gustave Eiffel (Eiffel Tower and Statue of Liberty) as I heard when coming to Maputo. That station has been featured in films such as Blood Diamond




Mocambique has a fragmented railroad system with three lines that are separated from each other: the Nacala railroad (north), the Beira railroad (mid) and the Maputo railroad (south).




CFM stands for Caminhos de Ferro de Mocambique, the iron roads of Mocambique. The URL of CFM is: http://www.cfm.co.mz/ The web page is only in portugese.





Wednesday 16 July 2014

TrafficControl: Thread running after closing window [Solved]

When I introduced threads to the program, I also introduced a problem: the thread didn't terminate when I closed the User Interface. Instead, it carried on after calling the terminate() method and I saw that the thread was still active in the console output, after closing the main program. When closing the console application manually, the console created an error message:

The program has unexpectedly finished.

The problem came, even if I used

    QThread clockThread;
    TrafficClock trafficClock;
    trafficClock.threadSetup(clockThread);
    trafficClock.moveToThread(&clockThread);
    clockThread.start();

ClockThread implementation:
    for(int iii=0;iii<100000;iii++)
    {
        if(continueTick==true)
        {
            emit stepTimeSignal();
        }
        QThread::msleep(333);
    }

When trying to kill the thread, the thread just continued:

    clockThread.terminate();
    while(!clockThread.isFinished()){}
This came even if I used quit() and exit().
After some investigations, I found that the thread wasn't terminated until the work in the thread was done. With this information, I was able to kill the thread by using a local variable isAlive:
    while(isActive==true)
    {
        for(int iii=0;iii<100000;iii++)
        {
            if(continueTick==true)
            {
                emit stepTimeSignal();
            }
        }
        QThread::msleep(333);
    }

Now, I was able to break the loop by setting isAlive to false, and to terminate the thread properly.

Why all the fuss about a thread still running after closing the program? As this program gets more complex, so will the bugs. Small glitches in the code will give me complex problems in the future, and I need to avoid it as soon as possible.

Also:
There are disagreements in the Qt community about how to implement threads. 
  • Subclass the worker klass from Thread, create a object with new for the thread and use the start() method to start the thread. This approach is recommended by the official QT documentation
  • Instead, I create a normal object and I move it to a thread.
You can follow the discussion below




Sunday 13 July 2014

TrafficControl: Data Structures of the program

In future posts, I'll discuss errors and improvements in my program. To make this easier to understand, I'll describe the overall structure of the program.

TrafficControl contains list of all trains, stations and tracks. The TrafficClock is associated with a thread that fires on a periodic interval. When the TrafficClock emits the signal, all train/track/station elements are updated.

The datamodels are used for presenting the current state of the elements of the train network.

Tuesday 1 July 2014

TrafficControl: The First Demonstration of TrafficControl

After implementing a thread model, I can show a screen cap video of the program.



3x normal speed. All units are SI. The stops are very short. A fix is coming...

All numbers are in SI units. The train starts at Hjärup, travels to Lund C and stops there. After that, it travels to Gunnesbo, back to Lund C and to Stångby.

The train network isn't hard coded, instead it is specified in an external file that defines the trains, stations, tracks and travel plans:


The program is still in an early phase, but the functionality is constantly growing. If you have any suggestions, ideas or issues that need to be addressed, please comment.

Adding more trains is easy, and results in three trains moving independently:
Future versions of the program will prevent train collisions and congestion.

I have a list of work packages/incident to deal with:


Hedy Lamarr was a Hollywood actress and inventor of the CDMA technology (leading to Wi-Fi). Her story deserves a blog post of her own, and I will try not to fail her.

Wednesday 18 June 2014

New York, NY: Grand Central Station





Some pictures from Grand Central Station in New York City. This is truly an impressive and beautiful building with the main concourse and the lower parts. It was opened 1871 and rebuilt a hundred years ago, and still a beauty.




I'll add that station and some of the train lines to my program, once it is more mature. Until then, enjoy the pictures.




Tuesday 3 June 2014

Victoria Falls, ZW: More monkey business

We met some more monkeys that were much cuter than baboons, Vervet Monkeys, in St Lucia and later in Pilansberg, Victoria Falls and Great Zimbabwe.



The background music is from Youtube Audio Library.

As I have lots of things to do at work currently, I'll keep the blog in Idle Mode until the middle of June.


Monday 26 May 2014

TrafficControl: Overall Structure of the Program

The program is co-ordinating trains with track segments and stations in order to simulate a train network.

For example, a train is currently at a station. That train asks a track segment if it is allowed to use that segment and leaves the station. After some time on that track, the train slows down and asks for permission to enter the target station.



The program will be designed to simulate any (reasonable) complex track network, for example the TGV network in France or the local trains in Skåne county in Sweden.

I have some objects representing all trains, stations and tracks. They will communicate with each other using a signal-and-slots mechanism in QT (similar to the events in other framesets). Don't worry if you are not familiar with those concepts, I will describe it in more detail later.

To be able to handle several trains, tracks and stations, I have three lists, that contain all objects: trainList, stationList and trackList.

All stations, tracks and trains will have a unique ID number that corresponds to their position in the lists (the first train will have the index zero. This will give a quite easy way of addressing each object.

An object, trafficControl will co-ordinate the objects.

The information will be displayed with the model-view framework. This means that, instead of writing a number to a table directly, that number will be written to a datamodel. When that is done, the view will get the data from the model. This slightly more complicated approach will hopefully make the program easier to adapt in the future.

I will describe the frameworks in more detail in future blog posts, so don't worry if it feels to advanced. Meanwhile, I can recommend the video tutorials that I wrote about in The Qt Part of the Blog.

Thursday 22 May 2014

Boulders Beach, ZA: African Penguins (day 6)

Boulder's Beach is a part of Table Mountain National Park, south of Cape Town. That beach is a protected area for thousands of African Penguins. The population of penguins has risen dramatically since the 1980's, when there were only two spotted penguins in the area. It is listed in the IUCN Red List over endangered species.




The diet of African Penguins is normally sardines, anchovies. As you can see in the movie below, that species is monogamous.





If they are not eaten by sharks, seals, mongooses or cats(!), they can live for ten up to twenty-five years.




I think that the language spoken in the background is Afrikaans. If I'm wrong, you're welcome to comment.

Thursday 15 May 2014

Telecom: The Generations of Mobile Systems

As I work in the telecommunication business, I sometimes get the question about 5G. Strictly, as of today, 5G isn't formally specified even if some actors write about 5G. I've also seen companies marketing "3.9G" and even 3.5G services as "4G", so I'll try to clarify the different generations and the chronology

Talking about different generations is a way to distinguish the radio network technologies from each other. The collaboration forum 3GPP is using release versions to describe the evolution of the networks. 

Year 3GPP release Name Generation Generation in marketing Features
1981 None NMT 1G 1G Pure voice calls
1992 Phase 1/2 GSM 2G 2G Voice calls
1997 Release 96 GSM 2G 2.5G Support for data calls (14.4kbps)
1998 Release 97 GPRS 2G 2.5G Increased speed for data calls
1999 Release 98 EDGE 2G 2.75G Further increases in speed for data calls
2000 Release 99 UMTS 3G 3G Much higher data speed
2001 Release 4 UMTS 3G 3G Changes in the core network
2002 Release 5 HSDPA 3G 3.5G High Speed Downlink Package Access
2004 Release 6 HSPA 3G 3.75G High Speed Downlink/Uplink Package Access
2007 Release 7 HSPA+ 3G 3.75G Improvements on HSPDA/HSUPA
2008 Release 8 LTE 3G 3.9G or 4G New Radio Network Release, SAE
2009 Release 9 LTE 3G 3.9G/4G Improvements on HSPDA/HSUPA
2011 Release 10 LTE-Advanced 4G 4G New Radio Network Release, SAE
2012 Release 11 LTE-Advanced 4G ? Adapting to heterogenous networks
2014? Release 12 LTE-Advanced TBD
2016? Release 13 TBD TBD
Commercial operators have been eager to market their services as "4G", rather than the correct term "LTE" or "3.9G". If all other operators use the term "4G", it would be fatal for an honest operator to market the same services as "3.9G". I will elaborate more on both telecommunications and game theory in later blog posts. More information about telecom standards can be found at. Zahir Ghadialy's blog offers interesting posts about what is going on in the telecom business.

Saturday 10 May 2014

Southern Africa: Monkey Business

Wild animals are hard to spot, as they generally leave the area as soon as they hear humans. This is not the case of wild animals that got used to humans.

At Cape Point, a baboon saw a tourist bus stopping and people leaving the bus. After one minute or two, that baboon approached the bus and tried to open the handles, as you can see in the picture. "Whatever humans can do, baboons can do it better."

The operation was successful and very funny. It was not quite as funny (or yes, later we laughed at it) when another baboon raided our bus with some people inside it. The people inside left the bus quickly and the baboon stole some food and left some "remainings" on the seats.

I've compiled a video of some baboons behaving as monkeys. My first Youtube video ever. I got the audio track from https://www.youtube.com/audiolibrary, that is providing free music for Youtube videos


In a earlier trip in the Philippines, we saw some aggressive monkeys too (Puerto Princesa):


Sunday 4 May 2014

Stellenbosch, ZA: Wine Tasting (day 4)

Some photos from Alto, Tokara and Ernie Els wine estates near Stellenbosh, a South African university town.









Saturday 26 April 2014

StockReader: Motivation and Background

This software has evolved gradually, and from the beginning I had no intention to make this kind of software.

A couple of years ago, I started to invest in stocks. After some painful experiences from the "buy-when-someone-recommends-a-stock"-period, I tried to be more systematic. I wanted to rank the stocks after some key numbers in order to automate the initial screening.

I created a spreadsheet document where I entered some key numbers for stocks, such as dividends, price/earnings, earning marigin, stock price, net asset value and some more parameters. Updating those values by hand was a very time consuming task, even for a very small number of stocks.

The next step was to experiment with linking to external webpages in OpenOffice. I found that task very time consuming too, as the incoming data spanned over different areas each time – sometimes, that data occupied five rows, sometimes seven rows. That brought a lot of work to adjust the spreadsheet. Also, it took OpenOffice some two to tree seconds to fetch the data (with a good internet connection).

The final step was to build a C++/Qt program that downloaded the stock data, analysed it and sent it to a csv file. My stockList spread sheet linked finally to that document. Now, it takes my quite-slow-and-quite-old computer some 80 seconds to download and update the stock information (12 data fields per stock) of some 300 stocks.



Saturday 19 April 2014

Lecture Notes: Financial Markets (Swedish notes)

Here are the lecture notes from my second course in National Economics: Financial Markets.

The notes are unfortunately in Swedish (I had no thoughts about blogging initially) and are meant as an inspiration. I recommend any student to write his/her own lecture notes him/her self.

The PDF file can be found at:
https://dl.dropboxusercontent.com/u/3587964/FinansHansBystrom.pdf

As before, I can guarantee that there are logical and factual mistakes, missing pieces and other flaws. However, I passed the exam with a good grade.

Monday 14 April 2014

Mozambique, MZ: Heavy escort (day 34)

Police stops at an hourly basis has become "business as usual" for our trip. This stop proved to be different.

We were stopped by soldiers with machine guns and rifles. They told us that we had to wait for enough cars, buses and trucks to come so that they could form a convoy.

We spent one hour, drinking beer, eating and looking around in the village. Our trip leader told us not to take photos of any police, military or such vehicles/buildings.

Two armed soldiers were inspecting and counting the souls on the bus. Shortly after leaving the bus, they boarded again, screaming "camera, photo, phone!". They thought we had taken photos of them and they started checking the camera belonging to the suspected. The soldiers checked all (that means, all) pictures, including some high school graduation pictures (he gave a cocky answer when the soldier asked about that picture...). No illegal photos were found and he got the phone back after the soldier had threaten to break the phone.

The 115 km trip lasted for two hours under the protection from armoured combat vehicles and lots of soldiers. We saw one burnt wreck from a bus on the road, some destroyed trucks, a repaired bridge and a military camp.

In the beginning, it felt like an adventure, but I quickly realized that this is for real. There has been attacks on that road before, and people have been killed in those attacks.

For reasons that should be obvious for the reader, I have no photos of the convoy. I'll try to summarize the background of the conflict in a later post.

Saturday 12 April 2014

StockReader: Bringing Hundreds of Stocks to one Spreadsheet

My other project is StockReader. That program scans key numbers from some three hundred Swedish stocks and makes that data accessible from a spread sheet program.

That program analyses stock data from some web pages, extracts the interesting information and arranges it in a comma-separated-value file that is linked to a spreadsheet, where I can rank the stocks after some criteria.

This way, I can assign different points/grades to stocks, depending on how they perform with regard to, for example the price/earnings value. Companies with big losses will get a "bad" grade, and companies with good earnings will get a "good" grade.

The final result of the program: Stock data collected to a Spreadsheet
After summing the grades for each key number, I can easily identify the companies with high dividends, good earnings, good net asset values, ... After having my computer doing all the dull work, I can continue with cherry-picking the best stocks.

Nowadays, I am advocating the efficient market hypothesis, meaning that all public information about assets will be reflected by the price. So stock-picking will be more of a hobby for me with no intentions of beating the market.

I've learnt a lot when creating the program and I want to share it with my readers in future posts.