ejes consulting

Techincal Consulting Design and Automation

Super Small printf for embedded applications

leave a comment »

So I like to write embedded applications – the challenge provided by a low power low memory system is always an enjoyable one. Nevertheless, occasionally one needs to recreate standard functionality and with these constraints in mind it can be quite a task. Anyway, I was stumbling around and found this tiny printf utility that is both elegant and tiny:

http://www.xappsoftware.com/wordpress/2011/01/17/a-tiny-printf-for-embedded-systems/

Advertisements

Written by ejes

February 25, 2011 at 12:09 pm

Posted in Uncategorized

Tagged with ,

Javascript Obfuscation to the MAX!!!

with one comment

I was stumbling around the internet today and found this:

($=[$=[]][(__=!$+$)[_=-~-~-~$]+({}+$)[_/_]+
($$=($_=!''+$)[_/_]+$_[+$])])()[__[_/_]+__
[_+~$]+$_[_]+$$](_/_)

Yep, perfectly legal Javascript, Care to hazzard a guess as it’s function?

http://adamcecc.blogspot.com/2011/01/javascript.html

^ go here to find out more… It’s fantastic :)

Written by ejes

February 1, 2011 at 2:47 pm

Happy New Year

leave a comment »

Happy New Year to all…

Written by ejes

January 1, 2011 at 10:48 pm

Posted in Uncategorized

ubuntu Headless Video Recoding with Handbreak CLI

leave a comment »

I have a lot of movies.  A lot. They are all in a digital format of some sort or another on my NAS server.

I like uniformity, that is, I like all my media in one format.  I have an iPhone (which I also love) so, I’ve been leaning (sadly) toward mp4 for my library.  Also, sadly, my library has already been coded mostly in XviD (the open source DivX.)  So I need to convert my old “.avi” movies to “.mp4”.   This is called “re-coding.”

When I was initially thinking of doing headless recoding I was going to use ffmepg.  ffmpeg is amazing for doing things like this – and what it’s specifically designed for.  I however have been using “HandBrake (http://handbrake.fr/)” on my Mac and I really like the simplicity and it does a very good job.

Why mess with a good thing?

I found out that HandBrake has a command line client (http://handbrake.fr/downloads2.php) which is available in all operating systems except, Linux.  Ubuntu specifically.

Looking around I found that there are nightly “unsupported” development builds for Ubuntu, and since Handbrake is public software and any support you receive for it would be pure fluke; this unsupported version looked better and better.

More importantly there is an option to learn how to use this PPA (personal package archive) system that Ubuntu (https://launchpad.net/ubuntu/+ppas) has been tooting it’s horn over.

The “PPA” archive (available here: https://edge.launchpad.net/~stebbins/+archive/handbrake-snapshots) for Handbrake supports Maverick, Lucid, and Karmic – and since I can’t remember what my system is; I run a little lsb_release.

root@ubuntu:~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 10.04.1 LTS
Release:        10.04
Codename:       lucid
root@ubuntu:~#

Look at that, I run Lucid (Ubuntu 10.04).  It’s “supported.”

To add a PPA it’s actually very easy, you have to use a command called “add-apt-repository.”  I didn’t have it at first:

root@ubuntu:~# add-apt-repository
add-apt-repository: command not found
root@ubuntu:~#

But that’s easily fixed by installing “python-software-properties”

root@ubuntu:~# apt-get install python-software-properties
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
python-software-properties
0 upgraded, 1 newly installed, 0 to remove and 1 not upgraded.
Need to get 0B/30.8kB of archives.
After this operation, 1,126kB of additional disk space will be used.
Selecting previously deselected package python-software-properties.
(Reading database ... 54647 files and directories currently installed.)
Unpacking python-software-properties (from .../python-software-properties_0.75.10.1_all.deb) ...
Processing triggers for man-db ...
Setting up python-software-properties (0.75.10.1) ...
Processing triggers for python-central ...
root@ubuntu:~#

Then you can run, apt-add-repository with the correct repository information (found here: https://edge.launchpad.net/~stebbins/+archive/handbrake-snapshots):

root@ubuntu:~# apt-add-repository ppa:stebbins/handbrake-snapshots
Executing: gpg --ignore-time-conflict --no-options --no-default-keyring --secret-keyring /etc/apt/secring.gpg --trustdb-name /etc/apt/trustdb.gpg --keyring /etc/apt/trusted.gpg --primary-keyring /etc/apt/trusted.gpg --keyserver keyserver.ubuntu.com --recv 43D3A9F60C58A7169778E6FB8771ADB0816950D8
gpg: requesting key 816950D8 from hkp server keyserver.ubuntu.com
gpg: key 816950D8: "Launchpad HandBrake Snapshots" not changed
gpg: Total number processed: 1
gpg:              unchanged: 1
root@ubuntu:~#

(since I already ran it my output above will not match yours)

Once that’s installed, you can quickly use – apt-get install handbrake-cli, to install it:

root@ubuntu:~# apt-get install handbrake-cli
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
handbrake-cli
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 6,119kB of archives.
After this operation, 13.9MB of additional disk space will be used.
Get:1 http://ppa.launchpad.net/stebbins/handbrake-snapshots/ubuntu/ lucid/main handbrake-cli
svn3570ppa1~lucid1 [6,119kB]
Fetched 1,446kB in 7s (199kB/s)
Selecting previously deselected package handbrake-cli.
(Reading database ... 54665 files and directories currently installed.)
Unpacking handbrake-cli (from .../handbrake-cli_svn3570ppa1~lucid1_i386.deb) ...
Setting up handbrake-cli (svn3570ppa1~lucid1) ...
root@ubuntu:~#

Then you can simply use it:

root@ubuntu:~# HandBrakeCLI
Missing input device. Run HandBrakeCLI --help for syntax.
root@ubuntu:~#

Handbrake has a very good tutorial on how to use its command line client, and even has all the normal built in presets: http://trac.handbrake.fr/wiki/CLIGuide

Written by ejes

October 5, 2010 at 10:08 am

Posted in Tutorials

Tagged with , , , , ,

Simple Timesharing for ALL ANSI-C programs

leave a comment »

A client of mine asked that I write a simple co-operative timesharing engine to be used in an embedded project.  Timesharing is quite an easy multitasking system and is frequently used in the embedded space because each process must willingly give up cpu control.  This is good if you have a critical task that must not be interrupted before it completes.  Modern, more powerful cpus have the ability to turn off interrupts during execution (the instructions are sti and cli in the x86 world)  but not all processors support this.

Because I cannot be guaranteed that the microcontroller that i’m using has this, i opted to use a software interrupt that i call “swi”.  Realistically, you can turn this into a preemptive multitasking system by assigning the programmable interrupt to my “swi” function and have it execute at a pre-determined time.

anyway, i also wanted this to be somewhat compliant with normal POSIX programming, so I created a “fork” function.

It uses “setjmp” and “longjmp” to create save points in the “swi” and then call the next call on the process stack.  I was going to include a simple prioritizing system, but really it didn’t require it – i might still.

Anyway, the source is posted in my source code area. 

(terms of use) This software is given to you without warrantee and warning that it worked for me, doesn’t mean it’ll work for you.  Feel free to use and modify it, and send me patches, I will gladly post them and of course give you full credit, as I expect you’d give me credit as well.

Written by ejes

August 5, 2010 at 9:47 am

Posted in Commentary, Hacking

GNU dnsmasq for OpenSolaris SPARC

with 2 comments

I recently have been trying to migrate my FreeNAS server to a SPARC based system runing OpenSolaris.  Mainly for the benefits of ZFS – but also to learn more about OpenSolaris and shellcode on SPARC.

In this light of learning more about OpenSolaris, I’ve been porting some of my lesser power hungry network applications to my little sparc pizzabox as well.  Since the pizzabox server is a little underpowered I wanted to use some pertty trim services to keep it’s availablility up as a NAS.

The first service I thought about was dnsmasq, who on my OpenBSD system works as my DHCP and dynmaically updateable DNS server.  I really like dnsmasq (http://www.thekelleys.org.uk/dnsmasq/doc.html), and have been using it as my primary dns/dhcp server for some time now – it’s fast, feature rich, easy to configure and cheap on resources.  It’s perfect for the home user.

Now just to get in running on my sparc.  After all the searching in the world, I couldn’t find any (trivial) dnsmasq on Solaris documentation. 

This left me no choice:

I’m not afraid of compling source.  Thankfully, DNSmasq 2.52 (http://www.thekelleys.org.uk/dnsmasq/dnsmasq-2.52.tar.gz) compiles cleanly on sparc – so this is the base I used.  In order to compile and run make install properly, I had to change the “Makefile” to use “ginstall” instead of BSD install that is used by default on Solaris systems; the Makefile also uses “cc” instead of “gcc” so I symlinked my “gcc” binary from /usr/bin to /usr/bin/cc.

Once installed I had to deal with the silly Solaris SMF (Service Management Facility).  In order to maintain some continuity across all my services I decded to build a nice smf xml for my dnsmasq as well.  I just copied ssh’s, and modified it to support my newly compiled dnsmasq package.  I also had to write a simple starup script since the SMF facility is just a fancy way of calling /lib/svc/method/ shell scripts who look suspcisouly like “init.d” type scripts.

Compiled, scripted and input into my smf (using svccfg import), my dnsmasq seems to starup great – my netbook got an ip, and it’s pingable by using “ping netbook” .

GREAT!

To save you wonderful internet users some headaches, I built a Solaris “.pkg” file for general consumption.  (http://www.filehosting.org/file/details/143734/GNUdnsmsq.pkg

I followed the instructions here (http://www.ibiblio.org/pub/packages/solaris/sparc/html/creating.solaris.packages.html ) for creaing the Solaris package, then used “pkgtrans -s . GNUdnsmaq.pkg” to translate the package to a “.pkg” file.

Enjoy!

Written by ejes

May 12, 2010 at 12:18 pm

Posted in Hacking, Tutorials

Tagged with , ,

Amazing One Line Script

leave a comment »

I was stumbling around on the internet this morning and I found this awesome site… (http://www.centerkey.com/tree/)

This guy posted an amazing one line script that will graphically show your directory tree with a simple one line command:

ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'

and that’s all!!! It works great!

Written by ejes

March 17, 2010 at 11:42 am