Hecl Command line app for J2ME mobile phones

xet7.org In English > Hecl Command line app for J2ME mobile phones
 

Latest Updates

2008-05-07:

  • Updates to Commanline.hcl code:
    • Now Exit button works.
    • Removed ; from end of textlines, because it works without them too! :)
  • Found how to remove opened projects from mobile phone emulator, it is told at the bottom of this webpage.

2008-05-06:

  • Created  this webpage.

 

About Hecl mobile scripting language

Hecl is made with Java. It works in J2ME mobile phones, like my Nokia 9500 Communicator, and others like in Googles Android phones:
http://www.hecl.org

Hecl has syntax that looks a little like tcl, but is different.

 

Screenshot in mobile phone emulator

What you can do with it

Type Hecl commands, and get results below. For example:

1) Get webpage source:

hget [http.geturl http://www.google.com] data

2) Calculate 33 + 44:

+ 33 44

You can also write more complex apps. You can look at source code that's in hecl source directory, after installing it with instructions below (How to compile...) :

gedit /home/username/hecl/midp20/script.hcl

More info about commands (using midp2.0) is at:

http://www.hecl.org/docs/


Download

Files for mobile phone:

Commandline.jad  (0.2k)
Commandline.jar   (140k)

Source code textfile of Commandline app:

commanline.hcl  (2k)


License

My Commandline app code is free to use for any purpose - Public Domain.

Hecl is under the liberal Apache 2.0 open source license, and there is more said in docs page at the bottom:
http://www.hecl.org/docs/


Installing to mobile phone

1) Transfer Commandline.jad and Commandline.jar to your mobile phone, for example this way:

  • Connect your mobile phone with cable or bluetooth
  • Put mobile phone memory card to (USB) cardreader and connect to computer
  • Put files to web and download them with mobile phone webbrowser

2) Navigate with mobile phone file manager to directory where files are, and click Commandline.jad to install it, and during install create shortcut to desktop.

3) Navigate to desktop and click Commandline app.


How to compile source and test in emulator

I'm using Parsix GNU/Linux 1.5r0-TEST-1 for developing this app:
http://www.parsix.org

1) To install development environment, type in Root Terminal:

apt-get update

apt-get install sun-java6-fonts sun-java6-jdk sun-java6-jre sun-java6-plugin subversion ant

update-java-alternatives -s java-6-sun

apt-get dist-upgrade

2) Download Sun Wireless Toolkit .bin file from:
http://java.sun.com/products/sjwtoolkit/download.html

3) Type in Root Terminal to install it (there may be later newer versions of WTK too):

./sun_java_wireless_toolkit-2_5_2-linux.bin

Install it to directory   /opt/WTK2.5.2

4) Then as normal user get newest Hecl from Subversion:

svn co https://hecl.svn.sourceforge.net/svnroot/hecl hecl

So now you should have hecl in this directory, change the username:

/home/username/hecl/

5) You may need to rebuild JarHack, that is used to compile Hecl app:

cd /home/username/hecl/
ant packageJarHack

(The following rebuild isn't needed, it's only if someone would use HeclBuilder instead of JarHack:)

cd /home/username/hecl/
ant HeclBuilderJar

6) Download my code textfile (or copy-paste from below):

commandine.hcl (2k)

Put that file in following directory, changing username:

/home/username/hecltest/

Here's the Hecl Command line app code (same as in file commandline.hcl above):

#################################################
# Command form application
#################################################

# You can try this with commands like these in the input field.
# 1) Get webpage source:
#      hget [http.geturl http://www.google.com] data
# 2) Calculate 33 + 44:
#      + 33 44

#################################################
# Create some lcdui.commands
#################################################
set backcmd [lcdui.command -label Back -longlabel Back -type back -priority 1]
set exitcmd [lcdui.command -label Exit -longlabel Exit -type exit -priority 1]
set nocmd [lcdui.command -type screen -label "No" -longlabel "No" -priority 2]
set okcmd [lcdui.command -label Ok -longlabel Ok -type ok -priority 1]
set selectcmd [lcdui.command -label Select -longlabel Select -type item -priority 1]
set yescmd [lcdui.command -type screen -label "Yes" -longlabel "Yes" -priority 1]
set runcmd [lcdui.command -label Run -longlabel Run -type ok -priority 1]

#################################################
# lcdui elements
#################################################

# Command form

set tf [lcdui.textfield -label "Reply" -text "" -type any]

set cmdform [lcdui.form -title "Command form" -commandaction runCommand]
$cmdform append [lcdui.textfield -label "Cmd:" -text "" -type any]
$cmdform append [lcdui.spacer -label spacer1 -minwidth 200 -minheight 2]
$cmdform append $tf
$cmdform append [lcdui.spacer -label spacer2 -minwidth 200 -minheight 4]
$cmdform addcommand $runcmd
$cmdform addcommand $exitcmd

proc main {} {
    global cmdform
    $cmdform setcurrent
}

proc runCommand {cmd d} {
    global reply tf exitcmd

    if {eq $cmd $exitcmd} {
           midlet.exit
    }

    set cmdName [[$d item 0] cget -text]
    set tmp [eval $cmdName]

    $tf configure -text $tmp
}

### Local Variables:
### mode:tcl
### coding:utf-8
### End:

main

7) Now compile the app:

cd /home/username/hecl/

java -jar jars/JarHack.jar jars/cldc1.1-midp2.0/Hecl.jar /home/username/hecltest/ Commanline /home/username/hecltest/commandline.hcl

In that command after Hecl.jar is

  • target directory      /home/username/hecltest/
  • name of the app    Commandline
  • source of the app   /home/username/hecltest/commandline.hcl

Now you have 2 new files in directory /home/username/hecltest/ :

Commandline.jad
Commandline.jar

8) Let's open mobile emulator, type as normal user:

/opt/WTK2.5.2/bin/ktoolbar

It should look like this:

Click from top menu: File / Create Project from JAR/JAD file ...

From folder list open file:    /home/username/hecltest/Commandline.jad

Click Run.

Click mobile phone round button below text "Launch", then Commandline app is started.

Here I have typed command and got result from Internet:

9) You need to delete projects from directory before you can use File / Create Project from JAR/JAD file again.

On Linux it is:

/home/username/j2mewtk/2.5.2/apps/

On Windows it is:

C:\Documents and Settings\Username\j2mewtk\2.5.2\apps\

I found this in documentation:
/opt/WTK2.5.2/docs/UserGuide-html/introduction.html#50626611_pgfId-43310