Tiliman’s Weblog

October 21, 2011

Sending Unicode SMS via Kannel

Filed under: GSM — Tags: , , , — tiliman @ 3:36 pm

Kannel is always a delight to work with. It is solid piece of software that would win over any commercial SMS GW.

Standard GSM characters are usually enough for English and most European languages but when it comes to sending SMS in other languages you have to rely on UNICODE. Here is character sheet of GSM characterset http://www.csoft.co.uk/sms/character_sets/gsm.htm
It might seem tricky at first to send Unicode SMS via Kannel and usually requires trial and error.

Sending unicode SMS involves following
1– Converting your SMS body string from whatever character set to into UNICODE (UTF-16).
2– URL Encoding (Percent Encoding) the SMS body.

HTTP GET example for sending Unicode SMS

<?php
$in_msg = "你好朋友Michael";
print urlencode(iconv('utf-8', 'ucs-2', $in_msg));
?>

My text here is stored in UTF-8 so I have to first convert it to UNICODE and then convert to URLencoded format.
The result comes out to be something like this
%60O%7DY%0Bg%CBSM%00i%00c%00h%00a%00e%00l%00
Now in Kannel send URL I have to specify that I am sending it UNICODE and for that I used charset=UCS-2
and to tell Kannel to send SMS as UNICODE as well (not as GSM characters)&nbsp;coding=2
I use HTTP GET URL for testing and this is how my final URL looks like
lynx –dump “http://KANNEL_SERVER:13003/cgi-bin/sendsms?username=USERNAME&password=PASSWORD&from=YOURFROMID&to=MOBILE_NUMBER&text=%60O%7DY%0Bg%CBSM%00i%00c%00h%00a%00e%00l%00&coding=2&charset=UCS-2″

HTTP XML POST example for sending Unicode SMS

XML POST is a little different indeed. The charcterset is actually identified in encoding param of xml namespace tag. You need to provide it the body in UNICODE (UTF-16/UTF-16BE) in URLEncoded form.


<?php
$SERVER = 'KANNEL_SERVER';
$PORT = '13003';

$out_msg = "你好朋友Michael怎么了";

# convert from UTF-8 to UTF-16.
$out_msg = mb_convert_encoding($out_msg,"UTF-16","UTF-8");

# Don't forget to URLEncode or else you might get unwanted string termination
$out_msg =  urlencode($out_msg);

print $out_msg."\n";
print "len ". strlen($out_msg)."\n";

$fp = fsockopen ($SERVER, $PORT, $errno, $errstr, 30);
    $res = "";
    $header = "POST /cgi-bin/sendsms HTTP/1.1\r\nHost: $SERVER\r\nContent-Type: text/xml; charset=utf-8\r\nContent-Length: __LENGTH__\r\n\r\n";
    $re1 = "";
    $req = "
<message>
    <submit>
        <da>
            <number>YOUR_NUMBER</number>
        </da>
        <oa>
            <number>FROM_ID</number>
        </oa>
        <ud>$out_msg</ud>
        <udh/>
        <dcs>
            <coding>2</coding>
        </dcs>
        <from>
            <username>USERNAME</username>
            <password>PASSWORD</password>
        </from>
    </submit>
</message>"; 

    $header = str_replace("__LENGTH__",strlen($req),$header);
    if (!$fp) {
            // HTTP ERROR
            print("Error in service.\nPlease try again later..");
            exit;
    } else {
            print "Sending\n$req\n";
            fputs ($fp, $header . $req);
            // read the body data
            $res = '';
            $headerdone = false;
            if (!feof($fp)) {
                $line = fread ($fp, 4096);
                print "Read:\n$line\n";
                fclose($fp);
            }

    }
?>

This is how your XML should look like

<?xml version="1.0" encoding="utf-16"?>
<message>
    <submit>
        <da>
            <number>MOBILE_NUMBER</number>
        </da>
        <oa>
            <number>YOURFROMID</number>
        </oa>
        <ud>O%60Y%7Dg%0BS%CB%00M%00i%00c%00h%00a%00e%00l%60%0ENHN%86</ud>
        <udh/>
        <dcs>
            <coding>2</coding>
        </dcs>
        <from>
            <username>USERNAME</username>
            <password>PASSWORD</password>
        </from>
    </submit>
</message>

This is all. Sending Unicode SMS is not that hard with Kannel after all.

Bringing back Adler32 to SCTP for Kernel 2.6

Filed under: GSM — Tags: , , , , , , , — tiliman @ 9:55 am

I had a situation a few days ago where I wanted to connect to our STP to test MAP applications built on Mobicents. Our STP was configured to only support Adler32 checksum. Adler32 is deprecated and CRC32 is considered a standard checksum to be used for SCTP. Keeping up with standards the Linux 2.6 kernel stopped supporting Adler32 and implemented CRC32 using libcrc32c.

I couldn’t reconfigure STP to use CRC32 and it was not possible to use different checksums for different SCTP peers as it is a Transport Layer Protocol. There was no solution I could find on internet, so I decided to patch my kernel and replace CRC32 with Adler32. I could see that a lot of other have had this problem and they couldn’t find any solution. I hope my solution would work for them as well.

  • Download kernel-headers for your kernel. Command like this would work on Debian apt-get install linux-headers-$(uname -r). Note: you don’t need sources for kernel. Just header files.
  • Take a backup of your original sctp.ko file. It would be somewhere /lib/modules/$(uname -r)/kernel/net/sctp/sctp.ko
  • Download the sctp module code from here to a clean directory somewhere away from usual linux sources. You don’t need it to be in linux sources directory.
  • Do make and make install in the new SCTP code at src/sctp/.
  • Check if new module is installed using modinfo sctp. It should say in description:    Support for the SCTP protocol (RFC2960) – with Adler32.
  • Do rmmod sctp and then modprobe sctp to load this new module. If you can’t do rmmod as module is busy and you can’t free it then you might have to reboot the system.
  • On load the module prints a message in /var/log/messages Initialising Adler32 patched SCTP module for 2.6 kernel

Now you have SCTP using Adler32 instead of CRC32. If you need to ever go back to CRC32, you can replace sctp.ko with your backedup module or you could download kernel sources and remake module.
May be in future I would add a load param to module to tell it to use CRC32 or Adler32 checksum.


Update October 24, 2011
The initial code was able to use checksum for outbound packets but was still using CRC32 for inbound packets. Updated the link to fix that.

September 3, 2011

CIMA UK Professional Experience Requirement for Entrepreneurs

CIMA UK is a great institute (accountancy body) in Management Accountancy fields. I happily opted for it because of its strength even though I had always wanted to be an Entrepreneur and I started my first company in 2006 at age 22.

I passed all my CIMA exams a few months ago. CIMA requires fulfilling of professional experience of about 3 years to be awarded membership as an ACMA. The discussion of this Professional Experience always revolves around about getting a job in industry and going through different roles. We all know that running a company specially starting a company requires you to take on multiple roles which require working on accountancy, legal matters and taxation matters. I have been able to handle most of these roles because of my education.

I was disheartened that I couldn’t fulfill professional experience requirements because I was not an employee of some other big company that could authenticate/verify my experience. So, I emailed CIMA regarding this matter and to my amusement I got a clear response that made my day. It looked like from the tone of email that CIMA has given thought about Entrepreneurs for Professional Experience requirements.

Here is the quoted part from email

—————–

To start I would like to clarify our practical experience requirements to you. Please note you do not need to be working with various jobs or even with reputable corporations. You could work for any size company in any industry,  well known or not, as long as you meet the requirements.

The purpose of the practical experience requirements is to maintain our prestige, and ensure we only qualify the best of the best. To ensure this, we require our members to have experience with common management accounting practices. The types of experience we require can be found via the following link:

http://www.cimaglobal.com/Students/2010-professional-qualification/Test-of-professional-competence-in-management-accounting/Part-A-initial-professional-development–work-based-practical-experience/

If you own your own business you may still gain the experience listed in the above link. However, keep in mind this experience must be verified by parties other than yourself. Generally this would be a line manager/boss, but in the case of an entrepreneur could be a bank manager, external auditor, or company accountant.

So please do not think we limit the opportunity for those employed by smaller firms/self employed, because we recognize all experience in the same light.

I hope this answers your query.

—————–

This should be good information for anyone who is doing CIMA and is worried about Professional Experience part of qualification.

P.S. The accountancy qualification gives a lot of advantage in starting business. The amount of money saved in accountant and lawyer fees and the ability to take advantages of tax exemptions can be used to strengthen business.

June 11, 2010

ImAware – Application for Nokia’s Calling All Innovators

This software was my only entry for Nokia Calling All Innovators competition ended on June 10th, 2010.

Concept

The key idea of this software is to allow users to submit reports about events that occurred around them and let others who visit the area know about it in realtime.

ImAware - Submit Tab

This way users can avoid high crime areas as well as visit close by attractions.

It would not be wrong to say that this is sort of wikipedia for real life events using mobile technology.

How it works

This software allows users to report an event that they have just witnessed via their phone. Each such report gets tagged with location information of the phone. This doesn’t only mean GPS but also includes using Network(CellID).

The software also pulls realtime events surrounding the user, again by taking the users’ location. Events can be of types Crime, News or Attractions like Sports/Concerts.

Threat Level Analysis/Calculation

Most interesting feature of this software  is the Crime threat analysis based on user submitted reports. This is somewhat important for big cities like where crime rate is high. The system uses a simple algorithm by taking crimes that occurred within 5 km of user’s location to calculate an approximate threat level of that area.

The age, severity of crime, time of day, all participate in calculating the threat level.

Threat Levels go between Low, Medium, High and Critical.

What is Event type “Attractions”?

The rest of software is about attractions like Sports, Concerts, Book Sales etc which is shown on users’ map.

Roadmap

ImAware - Status Display

  • A full set of Web API will be provided to allow other websites/softwares to integrate.
  • Integration with facebook to add it as an app.
  • Better analysis of crimes and possible prediction
  • Create a service out of it and a possible business around it.

Technologies/API used

The software makes use of following APIs

  • Nokia Location Services API
  • Qt GUI and Core library
  • Qt Network services for HTTP communication
  • Google Maps
  • Database on remote server using MySQL
  • Python+django based webservice
  • WebKit using QtWebKit wrapper to display map and other html retrieved from server

February 11, 2010

British TV Series Hustle predicted Oil Prices to be 150 dollars in 2006

Filed under: Uncategorized — Tags: , , , , , — tiliman @ 6:22 pm

Hustle is a british TV series where a group of grifters steal money from greedy people by creating brilliant schemes. The 3rd episode of season 3 aired on 24th March 2006 predicted oil prices to reach 150 dollars a barrel in 2 years which would be around 2008 according to airing date of show. Ash and Stacey while presenting their predictions about Oil prices to a banker, convince him that in 2 years time the Oil will hit 150 dollars and all known reserves will be exhausted by 2020. We can’t say about 2020 but the oil prices prediction which were supposedly fake in episode came to be true.

OIL Historical Prices

OIL Historical Prices

February 10, 2010

Android Development with Scala

Filed under: Android, Mobile Software Development — Tags: , , , , , — tiliman @ 4:33 pm

I learned a few weeks back about Scala programming language. I never liked Java and thought to try Scala as I would learn functional language and be able to still use JVMs.
I also wanted to learn Android development as I have done previously Windows Mobile, Symbian and iPhone development. Using Scala with Android was my idea to hit 2 birds with one stone.

Android Decelopment using Eclipse and Scala language

Android Decelopment using Eclipse and Scala language

All the information that I could find about using Scala with Android was for Android 1.6/1.7 but not with Android 2.0.1. Today finally I got Scala-Android development working for me. I am using Eclipse for development on OSX.

The steps involved are documented in detail here which can be followed till Step 4 as after that I will explain the trick to use Scala . If you are an advanced programmer then you should be able to follow my brief guide below.

Increasing memory of Eclipse

Edit eclipse.ini file which can be found in OSX at /Applications/Eclipse/Eclipse.app/Contents/MacOS/eclipse.ini
If you have not made changes to an app contents before in OSX then for your information right-click Show Package Contents displays all the internal directories in .app bundle.
Make sure that these parameters are there in config file as below


256m
-vmargs
-Xms256m
-Xmx1024m
-XX:PermSize=64m

Goto android sdk tools directory at <ANDORID_SDK>/platforms/android-2.0.1/tools/dx.sh and edit it and make sure this param is there


defaultMx="-Xmx512M"

It can be different on windows as windows uses batch file. You can find it as -Xmx<NNN>M where NNN is the memory size.

Note: mine was setup as 1024M so I kept it like that. 512M should work fine as well.

Install Android 2.x.x SDK

Download and install Android SDK and Tools from this link http://developer.android.com/sdk/eclipse-adt.html
I had to use HTTP instead of HTTPS for installing ADT plugin on Eclipse.

Install Scala

Download and install Scala plugin for Eclipse
You can put this URL directly in Install New Software feature of Eclipse
Scala – http://www.scala-lang.org/scala-eclipse-plugin
More details can be found at http://www.scala-lang.org/node/94

Download and install full Scala installer as well to get more control on Scala as well as get sbaz support.
http://www.scala-lang.org/downloads/distrib/files/scala-2.7.6.final-installer.jar or find whatever is the latest version at the time of reading.

Install scala-android library for development

Download and install scala-android.jar (library)


sbaz install scala-android

You can compile it yourself by visiting this link http://robey.lag.net/2009/01/19/scala-on-android.html

Create an Android project

Add Scala Nature by right clicking on project and then Scala->Add Scala Nature

Fix Project settings to use Scala

Scala Eclipse Settings

Scala Eclipse Settings

Goto Properties->Builders tab and make Scala Builder as 2nd last item in list.

Goto Java Build Path->Libraries and Remove Scala Library Version 2.x
In same Java Build Path->Libraries, Add External Jar and locate scala-android.jar in lib directory of Scala SDK.

Extending Scala class from Java

I always had issue compiling Android app written in Scala with class not being found as per manifest file. The issue was somewhere between Java expecting .java file as starting point and not being able to find it. So, I found a solution to leave original .java file as entry point and make a new file for Scala. Now the Java startup/main class extends Scala class which allows me to write rest of application in Scala.
My project was called ScalaTest and the ScalaTest.java was boilerplate code generated by android new project wizard.
The file looks like this after changes made for Scala


package android.ScalaTest;

import android.app.Activity;
import android.os.Bundle;

public class ScalaTest extends MainScala {}

The MainScala.scala looks like this


class MainScala extends Activity {
    override def onCreate(savedInstanceState: Bundle) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.main)
    }
}


First Scala Application

First Scala Application

Thats it. Scala can be used to do rest of Android Development as well as Debugging. Now I am off to learn Scala with Android.

January 7, 2010

Dawn of new 3-D TV Era

Filed under: Gadgets — Tags: , , , , , , , , , — tiliman @ 3:21 am

It seems that suddenly there is increased interest from big electronic appliances manufacturers in 3D TV as well as TV channels.

  • Samsung is releasing a new pencil thin 3D TV that can convert 2D videos into 3D. More interestingly they are integrating their new AppStore withthe system as well.I wonder where is the SDK for building apps for TV? We know Bada for Phone is being launched in April.
  • Toshiba with a set top box has also promised to upconvert 2D videos to 3D as well as upconverting of not-so-high-def videos to highdef.

    Sony Bravia XBR-60LX900 3-D TV

    Sony Bravia XBR-60LX900 3-D TV

  • Sony’s Bravia XBR-60LX900 due this summer will support 3D as well.
  • Discovery partnering with Sony and Imax promises for 24hour 3D TV channel as well as  ESPN promises for 3D TV channel this summer.

The 3D tech is finally arriving in our homes but it is yet to be seen how well the technology delivers. I hope Hollywood is planning on more 3D movies as well to support the initiative of manufacturers.

Update 10 January, 2010

I just saw a test 3D TV channel on Eurobird 9 is available at Freq 11747 tp 51.It seems to be Italian channel called 3DSG. Here is lyngsat link http://www.lyngsat.com/eb9a.html with complete info.

January 2, 2010

Android 1.5 on HTC

Filed under: Android — Tags: , , — tiliman @ 10:09 am

Installing Android on HTC was much easier than I had expected.
I only tried installing Android on HTC Diamond. Kaiser,Vogue and Touch Dual are also possible.

To get started with Android on HTC Diamond download the android build from
http://connect-utb.com/index.php?option=com_rokdownloads&view=file&Itemid=68&id=53:android-1

The steps to install are simple. Just extract the bundle package and copy it to root of your Internal Storage.
Note: Make sure you replace the STARTUP.TXT with diam100.txt from startup-configs directory. The original STARTUP.TXT is for RALPH100
Note: Disable PINCode for your SIM if you have any before using it with Android on HTC.

Disconnect phone from PC and simply run Haret.

Related links

http://glemsom.anapnea.net/android/htc-msm-android/
http://www.androidonhtc.com/

January 1, 2010

AirplaySDK for Cross Mobile OS Game Development

I am totally astonished as to how well AirplaySDK works. The guys at Ideaworks Labs have done it right.

They have made all the right choices when developing an SDK for cross mobile OS game development.

The issue with mobile game development is dealing with all the different Mobile OS plus dealing with different hardware using same OS. Game developers are somewhat lucky if there is OpenGLES implementation available as then they don’t have to worry too much about the rendering part. The sound and file IO and network features still mostly remain as an issue. OpenAL is not supported on most phones for sound. EdgeLib appeared a few years back to solve the problem of IO, Sound and Network features plus to allow software renderer in case OpenGLES is not available. More on EdgeLib in another post.

I tested the kartz sample from AirplaySDK on N82, N80, HTC Diamond, Samsung Omnia.

It is much easier to just list the feature pros and cons of AirplaySDK that I figured out so far by reading and trying out.

PROS

  • Native binary without any VM.
  • Good packaging tools for all OS.
  • Fixed point computation as well as floating point available.
  • Speedy Software rendering engine
  • Auto fallback to software rendering when no hardware accelerator present.
  • Sticking to opensource libraries.
  • One Dynamic Engine (ODE) for rigid body physics.
  • Support for multiple Mobile OS including Symbian, iPhone, Windows Mobile, Android,BREW and Linux). Edgelib doesn’t support Anrdoid and BREW.
  • Highly optimised compression of assets for games. Not just simple zip compression but usage of Derbh which uses shared buffer across files. Claims on site say that Metal Gear Solid came down to 1.5MB.
  • Arm debugger/emulator available that runs on Windows. Debugging is much easier this way.
  • Windows emulator allows testing of software in various different scenerios (tilt/compass/keypad/touch/resolution)
  • VS Studio programmers would love it as they can use VS with this SDK. Very tight integration.
  • UI development possible for softwares other than games. This is interesting feature but as the Core System API is not extensive, it won’t be possible for creating full applications. Only simple apps can be built. There is possibilty of extensions that can do OS dependent API calls but this system is not exposed to developers to create their own extensions. There seems to be discussion of this opening up on AirplaySDK Forum.
  • Extensions available (only for iPhone) for some of iPhone specific API
  • Phone Orientation awareness and auto rotation of GUI.
  • Human Interface limitations/possiblities awareness. Can detect touch screen and keypad and control based on that.
  • Handling of phone events (incoming call/notifications) without extra code.
  • UI code for input is intelligent enough to display touch keypad on touch UI systems without any extra work. MoSync can’t do that. EdgeLib has no support for UI controls/widgets.

CONS

  • No support for OSX/XCode for development yet. It is planned though.
  • Integrates best with visual studio which can be costly. Although express edition is free and should be enough
  • Not very extensive API for core OS like System API.

My Test Results

Omnia Kartz Running in Portrait at 20 fps. Left/Right sides of screen can be used to steer.

OMNIA Kartz Running in Landscape at 18.65 fps. Left/Right sides of screen can be used to steer.

N82 running Kartz sample at 20 fps and steering with keypads. N82 has vfp

HTC Diamond running Kartz sample with 11.4 fps. HTC Diamond has no vfp/hardware acceleration

N80 running Kartz sample at 9.7 fps and steering is with keypad. N80 has no hardware accelration/vfp.

OS Independent Mobile Software Development with MoSync

Introduction

MoSync is truely amazing platform for cross platform development for Mobile Phone Softwares. It comes as a full IDE based on Eclipse. It supports currently Windows Mobile, Symbian, Blackberry (Java),Moblin and J2ME. Support for iPhone,Maemo and Android is planned. MoSync was made opensource a while ago and seems to have very active developers. The best thing is that it creates a binary instead of creating some sort of virtual machine code and thus slowing down the whole application.

In my experience as much as 80% of code needs be ported between platforms. Symbian’s disregard of providing standard C API initially and later requirement to install OpenC on phones with your software, overall confusing the install process for user, made it sub-optimum to use OpenC. The userinterface coding takes a long time on most phones even if there is standard API for core system like IO/Network.

Now MoSync promises that you can make one UI code and use it on other phones, as well as MoSync API translates to Core OS API which means no need to spend time in porting at all.

Test Results on a few phones

This sounded too good to be true so I had to try and spend a night playing with it. The IDE is based on Eclipse. I tried their UI samples on HTC Diamond, Samsung Omnia and N82.

Here are my findings

  • There was no need to install each SDK for Symbian, Windows Mobile or Black berry.
  • The binaries are made per Mobile phone and not per OS.This is a little inconvenience as they are not always compatible on different phones running same OS as I found out with Samsung Omnia.

    HTC Diamond with MAUIEx sample displaying a grid of images

    HTC Diamond MoSync Main interface (Diamond has higher resolution than Omnia)

  • HTC Diamond binary was a native exe and when installed ran fine. Although the selection of items had to be done with keypad.
  • The same HTC Diamond Windows Mobile binary when installed on Samsung didn’t run and crashed. The cab was created by MoSync. This is strange as it is same OS.
  • The simple example which outputs keycodes when keys are pressed was not able to recognise back button on HTC Diamond.
    Omnia MoSync landscape didn't show properly

    Omnia MoSync landscape didn't show properly

    Omnia MoSync Main Screen MAUIEx sample (jar file)

  • When I compiled same code for Samsung Omnia, to my surprise, I got Java (jad/jar) files instead of native binaries. The UI ran fine but as it was not touch UI, I had to reboot phone.
  • The HTC Diamond exe took over whole of screen on Samsung Omnia before crashing and had the taskbar on top hidden. Icouldn’t get that taskbar back and had to reboot phone. This is very scaryif all UI apps built with MoSync do it. This would mean that Windows Mobile Certification test will fail as they require ability to go to “Today Screen”(main screen of phone) using Start menu. More on that later.

    N82 Symbian Native BInary MoSync MAUIEx Clock sample

    N82 Symbian Native binary running MAUIEx created using MoSync

  • The N82 was also a native binary that functioned pretty well as it is not a touch screen and soft-keys (keypad) was mapped perfectly fine.
  • The UI development with MoSync has same limitation where support for both touch UI and keypad UI has to be coded by developer making it less automatic porting.

Final Thoughts

All in all MoSync would reduce development time by reducing the code portability needed but the need to test on each phone is highly increased due to uncertain behavior of same app on different phones. Again stressing here on HTC Diamond Windows Mobile app not able to run on Omnia which almost never happens with traditional development. I will play more with MoSync and create more entries on blog if I find something interesting or contradicting to my these initial findings.

Older Posts »

Theme: Silver is the New Black. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.