Friday, December 30, 2011

Setting the Serial Port of a OSEPP Uno On Mac OS X Lion

I am new to Arduino hacking and as such I installed the latest Arduino software that comes without the need to install separate USB drivers, ie. the FTDIUSBSerialDriver_10_4_10_5_10_6.mpkg file with older Arduino software installs for Mac.

I am on Mac OS X 10.7 (Lion) as well.

So, when I hooked up a second Arduino board I bought yesterday, an OSEPP Uno Rev 1.1, I could not load sketches onto it.

I went to the getting started website for the OSEPP Uno, which suggested setting the board to an “Arduino Duemilanove or Nano w/ ATmega328″ to get it to work. Still nothing.

I looked at the Serial Ports but there were no usbserial ports listed. So, start debugging. I opened the Console and tried unplugging/plugging in the board, sure enough there was an error:

kernel: 0 0 AppleUSBCDC: start - initDevice failed


So, rereading the getting started site, I released that since this board was a little older I might just need to the older drivers.

I downloaded the Arduino 0023 drivers from the Arduino Software page for Mac OS X. I installed just the FTDIUSBSerialDriver_10_4_10_5_10_6.mpkg file.

Restart the Arduino IDE and voila, there should not be a /dev/tty.usbserial-* device that will be the OSEPP Uno board. You can then load your programs.

Hope that helps.

Friday, November 18, 2011

Configuring the liboauth C Library for PlayBook

Overview



You've decided to write a PlayBook App with the NDK (Native Development Kit). That's awesome, let's learn how to port an OSS library you want to use in your new app.

For those of you who are ./configure experts, please point out anything I have wrong or maybe could do differently which might make this easier.

Ok so first off, I am not a ./configure expert but I am perfectly willing to beat my head against the compiling and linking wall until I get something that works.

Some prerequisites:
  • I am on a Mac, switching between a Snow Leopard and a Lion box. So this should work for either. If you are on Windows, please feel free to fork my post and write up how you did this on Windows. If you do, then please refer back here for the Mac Devs who find your site.
  • I expect that you have installed the BlackBerry Tablet OS NDK in the default locations.
  • I am using 2 PlayBooks for testing. One running 1.0.7 and one running 2.0. You can expect this to work for either, if not let me know and I will verify that it is working no the latest OS.
  • You know what the Terminal.app is and aren't afraid to use it.
Let's get started.

Porting liboauth (http://liboauth.sourceforge.net/)

I choose liboauth since it involved the least amount of work for the library's I have been working with. I built liboath-0.9.4 for PlayBook. I only built the device (arm) version since I am not using the simulator; I like to test on the metal; but with some minor variations to the options it should not be hard to get a simulator compatible version built.

First: Set the environment for building

To do this source the NDK included environment script:
source /Developer/SDKs/bbndk-1.0/bbndk-env.sh
This should setup your environment for the QNX compiler so we can build for the PlayBook. Here is what that looks like (at time of writing):
QNX_TARGET="/Developer/SDKs/bbndk-1.0/target/qnx6"
QNX_HOST="/Developer/SDKs/bbndk-1.0/host/macosx/x86"
QNX_CONFIGURATION="/Users/YOUR_USERNAME_HERE/Applications/Library/Research In Motion/BlackBerry Native SDK"
MAKEFLAGS="-I$QNX_TARGET/usr/include"
DYLD_LIBRARY_PATH="/Developer/SDKs/bbndk-1.0/host/macosx/x86/usr/lib:$DYLD_LIBRARY_PATH"
PATH="$QNX_HOST/usr/bin:$QNX_HOST/usr/qde/eclipse/jre/bin:$PATH"
export QNX_TARGET QNX_HOST QNX_CONFIGURATION MAKEFLAGS DYLD_LIBRARY_PATH PATH

Second: Modify the config.sub to include the CPU instruction set for ARMv7

When we set the target and host in the ./configure command we will be using the PlayBook CPU type of armv7, we will need to add that to the config.sub since it is missing from liboauth's config.sub. I did this by searching for armv, where you will find and switch out the line shown in the following diff, notice I just added 7 into the armv[2345] statement:
diff --git a/config.sub b/config.sub
index c2d1257..dd4ef08 100755
--- a/config.sub
+++ b/config.sub
@@ -249,7 +249,7 @@ case $basic_machine in
| alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \
| alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \
| am33_2.0 \
-       | arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr | avr32 \
+       | arc | arm | arm[bl]e | arme[lb] | armv[23457] | armv[345][lb] | avr | avr32 \
| bfin \
| c4x | clipper \
| d10v | d30v | dlx | dsp16xx \
Sidetrack: If you want to look at some more details on the CPU, check out http://en.wikipedia.org/wiki/Texas_Instruments_OMAP

Third: Run ./configure with some options

Here is the ./configure I used. I included the OpenSSL and the Curl libraries.
./configure CXX="QCC -V4.4.2,gcc_ntoarmv7le_cpp" CC="qcc -V4.4.2,gcc_ntoarmv7le" --prefix=$PWD/playbook NM=ntoarmv7-nm RANLIB=ntoarmv7-ranlib STRIP=ntoarmv7-strip AR=ntoarmv7-ar LD=ntoarmv7-ld LDFLAGS="-L/Developer/SDKs/bbndk-1.0/target/qnx6/armle-v7/usr/lib/" CURL_CFLAGS="-DFD_SETSIZE=64 -g -O2" CURL_LIBS="-Wl,-s -Wl,-Bsymbolic -Wl,--gc-sections" --build=i386-apple-darwin11.2.0 INCLUDES="/Developer/SDKs/bbndk-1.0/target/qnx6/armle-v7/usr/include" --target=armv7-nto --host=armv7-nto
If the above worked then great, you can now run make, else, you will need to try to debug the problem with your environment/configuration.

Fourth: Run make

Run make and then make install to install into the path we chose in our configure statement which was set with the --prefix=$PWD/playbook. What is $PWD, it is the environment variable for the directory you are building the library within. Basically, the make install will make a new directory called playbook and place all the built artifacts into that directory.

Lastly: Pull liboauth into your project

I'll leave that for the user to work out but here is a sample liboauth on BlackBerry PlayBook qde project on github that has the built library and the test/selftest_wiki.c file renamed to main.c included to verify that the library is working.

Finishing



With a little tweaking of the ./configure, porting an OSS project to the PlayBook is not to hard. When you run into compiler issues the story can be a little different (read, lots of hair pulling) but is not insurmountable.

Good luck with your app!

Friday, August 19, 2011

OCMock observerMock and unrecognized selector


I've been writing lots of unit tests for some new classes that use process wide NSNotifications.  I wanted to test these since I have not written NSNotification code often and this is a base class that a lot of future code is going to be built upon.

A handy way to test these are to use OCUnit with OCMock to create mock observers to verify that your notifications are being called.  Many others have talked about how to setup OCUnit, OCMock, and do Unit Testing in Xcode so I won't go there.

One article that did help me out with the OCMock observerMock usage was Alex Vollmer's Making Fun of Things with OCMock.  I used his example to build upon to write my mock observer tests.

I did run into a problem though while testing.  A test for a notification, let's call it MyCoolNotification, would pass and then a second test that tested this notification would fail.  The weird thing if I would see failures like:
  • [NSCFString handleNotification:]: unrecognized selector ...
  • [NSCFNumber handleNotification:]: unrecognized selector ...
These failures would be for the same call, same line of the test, but on different runs I would get different classes throwing exceptions due to the unrecognized selector.  What to do?

I put it together when I noticed the pattern, that the first test of usage of MyCoolNotification would pass but the second and remaining would fail.

The examples of the usage of [OCMockObject observerMock] left out one important NSNotification item.  Once you finish your test, don't forget to remove your mock from observing the notification.

Here is a more complete example of that I am talking about:
- (void)test_MyCoolNotification {
  id mock = [OCMockObject observerMock];
  [[NSNotificationCenter defaultCenter] addMockObserver:mock
                                                   name:MyCoolNotification
                                                 object:nil];
                                               
  [[mock expect] notificationWithName:MyCoolNotification object:[OCMArg any] userInfo:[OCMArg any]];

  MyCoolClass *coolio = [MyCoolClass create];
  [coolio someMethodThatFiresMyCoolNotification];

  [[NSNotificationCenter defaultCenter] removeObserver:mock];
  [mock verify];
}

By adding the removal of the object from the NSNotificationCenter you can now test the notification multiple times in multiple tests.

Saturday, March 5, 2011

TextMate

Holy Preview Update Batman!!

I have new respect for TextMate. I had the web preview open and I made a change to some javascript (switching the username from a sample user to my username) and the preview updated immediately to show me the changes.

Slick and very handy for editing this web app.

Thursday, March 3, 2011

PlayBook App

Well, my first PlayBook app is in development. I am going to write it using the BlackBerry WebWorks SDK which boils down to; I am writing a web app. I don't know the latest web technologies to save my life so this should be a good experiment to see how easy it is to develop something.

I've found two Javascript libraries to help me along the way and handle a large portion of the work I need for this app. Now I just need to do the gluing and get to work on getting something running in two weeks.

I will be doing a PlayBook Hackathon in 2 weeks and I want to be able to demo the app at the end of the event so I am taking my experience from my last Hackathon and going into this one with the basics of the app laid out. Then at the Hackathon I can get some advice on any areas that are giving me trouble.

Expect some further posts as I progress and once I get the demo completed.

Sunday, February 20, 2011

Preparing For Sale

Been a crazy weekend. In the last 24hrs I have been violently ill with food poisoning, picked up paint supplies for our painter that start yesterday, and filled one side of my garage with stuff to give away or throw out.

Just another fun filled day getting ready to leave my frozen homeland for milder climes in Washington state.

The house prep work is going well. Selling a house is probably easier in a sense when you are also moving to a new city, country, job (for my wife), and need to down size what you are taking with you.

Part of our big move is that we must inventory everything we own and assign a replacement value to it. This is for insurance purposes. Hence, you can tell that we are motivated to count less and throw out more. I mean really, if I have not used some of this stuff since we moved in here 6 years ago, is there really a chance I am going to be needing it when we settle in our new home? Nope, thought not.

Our first house showing to a prospective buyer is tomorrow. This came about due to word of mouth which is cool. Let's hope the fact our house is in a shambles since half of it is in a state of being painted, just painted, or about to be painted.

At least the house is clean and less cluttered by the minute.

Friday, January 21, 2011

HackOTT: A BlackBerry PlayBook App

What is HackOTT?


Hack Ottawa = HackOTT is part of the HackDays across Canada. Here's how it works:


  • Gather developers
  • Provide food, space to work, and APIs (Application Programming Interfaces, the building blocks for applications that programmers use to like you know, build stuff)
  • Let them code for 8 hours.
  • Judge the results

Read more here: http://hackdays.ca/2011/01/hack-ottawa-is-here/


Register Here: http://guestlistapp.com/events/42672


I've signed up for the event here in Ottawa and am starting to prep for the event. So, let's get down to the title tagline of this post: A BlackBerry PlayBook App.


If you don't know, I work for Research In Motion, better known as RIM. The RIM tablet offering is the PlayBook and it's coming soon. Being a geek, lover of new tech, and always in pursuit of a challenge; I've decided I'll design my app to run on the PlayBook.


Dude a PlayBook, Like Let Me See It


"Cool, Mark, you've got a PlayBook to use already? They aren't even for sale yet," you say. Well, the truth is I don't have a PlayBook and if I did I would not be bringing it out to play. So, don't expect me to be toting one around to show you and demo. I have to wait for them to be available for sale like everyone else.


Well then how am I going to develop for the PlayBook? With the dev tools including the BlackBerry Tablet SDK and the BlackBerry Tablet Simulator for VMware Fusion; on my Mac Book Pro of course. All further discussion is specific to programming on the Mac. If you are a Windows dev, sorry, this might be of little use to you.


Setting Up A New Project


Let's jump in and get started.

BlackBerry PlayBook Resources


Ok, got that done? Good. Let's drop a couple links to resources to help you along the way of coding up your BlackBerry PlayBook App.

Ok, that's all for tonight. Next, I'll be reading up on the WebWorks SDK and the Adobe AIR SDK to see which one I'd like to use for the project.