Recent Computer Related Events

The last few months have been crazy.

I’ve had a couple of job interviews with tech companies in California, attended a BB10Jam, released a couple of playbook apps, started on some side research projects at school. So this post is all about talking a bit about each of those things.

Job Interviews in Grad School
If you are like me and don’t like to say no to anything, you’ll probably go along with the whole interview process – just to see where it takes you. Also if you are like me and a busy grad student – you probably will not have time to prepare properly for the interviews. This is probably a big mistake (or maybe not). From my perspective, the technical questions in the interviews went pretty well when they were directly in my areas of expertise. As soon as they meandered to peripheral areas, things got a little ugly. Worse still was the coding questions. While I do try to keep up my skills in this area, grad students (particularly PhD) students in comp sci aren’t always well known for being code monkeys. We spend most of our time reading papers, proposing algorithms and mechanisms for solving problems. We then either 1) Hire an undergraduate student for the programming or 2) Make use of as many open source tools as possible and “macgyver” them into suiting our needs. In the extreme case we may code some specialized tool for what we need as well. So as you can guess, my coding skills were rusty. If I were to prepare in the future, I’d focus on this for as much time as I could before starting the interview processes. But since these interviews all contacted me first, that wasn’t an option.

BB10Jam
Despite all the doom and gloom in Waterloo these days about RIM, I still like to develop apps for the Playbook for a few reasons. 1) RIM lives where I live. 2) I got a free Playbook at a conference. 3) The AppWorld is not saturated with a million of the same type of app yet.

 

So after developing a couple of apps I noticed they were having a BB10Jam here in Waterloo and went. The event was really good. The people were friendly and nice, and it was much less stuffy than some of the previous RIM events I have attended. Maybe it is a sign things are starting to reverse. Beyond just that though, the platform looks pretty good. I also got a developer device and am working on some apps for it now. The biggest selling point in developing for them right now for BB10 is the $10,000 reward for any app that can make $1,000 in the first year. Also at the event there were many stats showing increasing numbers of developers and apps in the store which all sounds good. Another interesting bit of info was that BB users are more likely to pay for their apps compared to other platforms. All of this makes it increasingly attractive to develop for the platform. So at the end of the BB10Jam I came away pretty excited to get at it. Just need to find the time now!

BB Playbook Apps
If you have read this blog previously, you may noticed something about one of my apps. The first one I made was a telnet application. I had the intention to also include ssh, but have not had the time to include this bit of code yet. The biggest challenge with that app was developing a console library for displaying the text. At the time Cascades was not available yet, and this type of thing was a bit tricky. There’s more info on it here: http://www.jasonernst.com/2012/01/24/opengl-console-library-for-blackberry-native-sdk-playbook/. The app is available here for free on the appworld: http://appworld.blackberry.com/webstore/content/77778/?lang=en

The second app I created is a web server. The inspiration for this was that I wanted to be able to serve images from the camera onto a website hosted on the playbook. This way you can leave your playbook setup as a sort of security camera. So the first step was creating the web-server to serve the content. Right now it just supports serving static content – no php, perl, python etc, but maybe in the future. The next step will be to hook into the camera and serve up a continuously changing image that is polled from the camera regularly. The app is available here: http://appworld.blackberry.com/webstore/content/124979/?lang=en

Side Research Projects
The last thing is the side research projects I have taken on in the past couple of months. I have been collaborating with researchers in the math department on two projects. First is a cognitive agent project. In this project we are interested in the intelligence required for a creature to cross a busy street. The first creatures are oblivious to the conditions in which danger may exist so they cross the road. As some of them are hit, the creatures which follow can observe the conditions and avoid crossing. Eventually they start to learn when it is safe to cross. The focus of the work is the underlying learning mechanisms for this problem.

The second project I am involved in is a vehicular traffic simulation tool. An existing tool was developed several years ago, however there were some shortcomings in the model. The model is based on the Nagel-Schreckenberg traffic model, however the ramps on the highway were only one cell. Because of this limitation, it becomes difficult to properly simulate certain highway configurations such as clover-leaf ramps. My recent work on this project has extended the model to address this limitation.

OpenGL Console Library for Blackberry Native SDK (Playbook)

Over the break, I decided to try my hand at some Blackberry native SDK programming since I recently got a playbook. I looked around the App World and noticed there weren’t any telnet/ssh tools available for free (that worked the way I wanted) so I thought this would be a good starter project.

However, for the look I wanted, I wanted to maximize the screen space for the console application to show as much text as possible and worked off the hello world example on the SDK webpage. Essentially, the simple “library” (note: library is used very loosely here) initializes the display, shows the keyboard and supports some simple output using putch and puts functions that I implemented. It can also show a blinking cursor and user input at a prompt. In case someone else can use the code I have made it available. Check back soon to see the source for the telnet portion of the app I made as well or look for it on the App World.

Simple Telnet - Example Application
Simple Telnet – Example Application using the conosole library

In order to use the library, you need to make use of the bbutil.c and bbutil.h files that are included in many of the examples provided by RIM. I have provided them here alongside my own code so that it is easier to follow along. I also provide two more files: glconsole.c and glconsole.h. You just need to #include “glconsole.h” in your source in order to use the library. All of the functions available to you are listed in the “glconsole.h” file as well. I will go over the important ones in this article.

First is gl_init(). This function initializes the library, the screen, font etc. This function should be called before using anything else in the library. Similarly, gl_cleanup() is used to free memory and should be called before your app is terminated.

After initialization, you may now use the puts and putch functions to display characters to the screen. gl_putch(char c) takes a single character and displays it onto the screen. It can handle newlines which are represented as ‘\n’ and tabs which are represented as ‘\t’. Backspaces by user input is handled as a ‘\b’ character. This is similar to how people on The osdev.rg website often handle character output in their custom operating systems. I’m not sure how it relates with normal c standards, but I imagine it is similar. Eventually I hope to implement a printf() type of function, but at the moment the putch() and puts() functions serve what I am doing well enough. Note: puts() is the same as putch() but instead takes a (char *) ie) a string. The string should also be null-terminated, or it will just continue until it hits a null character. The characters are automatically scrolled when the bottom of the screen is reached.

The only other really important function is gl_render(). This function is what should be called everytime the screen needs to be refreshed. This is usually in a for loop within your main() function in your app.

It is also possible to resize the screen using the gl_resize() function. By default the screen starts at 80X29 which is the maximum size with no virtualkeyboard showing, at the font size I selected. When the keyboard shows up, it fits 80×14. In some sample code I’ll also show how keyboard input can be handled, how to blink the cursor and how to detect when the keyboard is shown or hidden.

For the rest of this guide, I’ll assume you are using the QNX Momentix IDE available from RIM’s developer website. To start, create a new project by going to File->New Blackberry Tablet OS C/C++ Project. Name it whatever you like, click next. Then choose the C language, and empty Application Project. You can now drag the gl_console.c, glconsole.h, bbutil.c and bbutil.h files into the src folder within the IDE to include them. You will probably want to copy the files and not link them when it asks. Before compiling, there are several libaries which must be linked to the project. You can do this by right clicking your project, going to properties. Then go to C/C++ General->Paths and Symbols->Libraries. Here you can add libraries. Each time you add one, be sure to check “add to all Configurations” so that you don’t need to do this again if you change from a device-debug to device-release build. The following libraries should be included:

  • bps
  • EGL
  • GLESv1_CM
  • freetype
  • png

Now that all this is setup, it is possible to start you main() function and use the library. If you like you can right click on your src folder and click “new file” and create a main.c file or whatever you like to name it. While this isn’t the typical way you would include a library into a project, this way lets you edit the library source to your liking in case you want to further extend it.

The following example shows a skeleton of what is required to get the code to display some text:

#include /* EXIT_FAILURE */
#include /* NULL */
#include /* BPS_SUCCESS */
#include /* screen_event_get_event() */
#include /* NAVIGATOR_EXIT */
#include "glconsole.h"

void handleScreenEvent(bps_event_t *event);

int main(int argc, char * argv[])
{
int exit_application = 0;

if(EXIT_SUCCESS != gl_init())
{
fprintf(stderr, "error init\n");
return 0;
}

gl_puts("Hello gl console world!\n");

for(;;)
{
bps_event_t *event = NULL;
if (bps_get_event(&event, 0) != BPS_SUCCESS)
return EXIT_FAILURE;

if (event)
{
int domain = bps_event_get_domain(event);

if (domain == screen_get_domain())
handleScreenEvent(event);
else if ((domain == navigator_get_domain()) && (NAVIGATOR_EXIT == bps_event_get_code(event)))
exit_application = 1;

if (exit_application)
break;
}
gl_render();
}

gl_cleanup();
return 0;
}

void handleScreenEvent(bps_event_t *event)
{
/* do normal event handling here, see other bb examples */
}

The key parts are calling gl_init() which initializes the library. Then within the main loop, the gl_render() function should be called which will actually render the text. Finally gl_cleanup() should be called before termination to properly free memory.

In the near future I plan to add some support to handle ansi encoded text (specifically for my telnet application) so that it can display colours and move the cursor around the screen using this standard.

Here are the files:
glconsole.h
glconsole.c