Posted on September 26, 2007 in Computers by seadog11 Comments »

Using a howto from this site I managed to cross-compile python 2.5.1 for my embedded linux board . Although AXIS provides python 2.4 with their SDK and configures it with no threads and stuff, I compiled the the original python 2.5.1 with only this patch applied to prevent tests from running while cross compiling and to byte-compile python scripts using host’s python compiler.

The patch is heavily based on Chris’, which is heavily based on K’s :) I modified only what was need to successfully patch 2.5.1 (Chris’ patch is for 2.5.0)

Here is a small howto to get you going:

Get python

wget http://python.org/ftp/python/2.5.1/Python-2.5.1.tgz
wget http://www.sealabs.net/seadog/files/python-2.5.1-cris.patch
tar zxf Python-2.5.1.tgz

Apply Patch

cd Python-2.5.1
patch < ../python-2.5.1-cris.patch

Now we compile python for our host architecture to get python and Parser/pgen executables. These are needed to byte-compile python during our cross compile procedure.

./configure
make

Save native python and pgen

mv python hostpython
mv Parser/pgen Parser/hostpgen

Clean everything up

make clean

Now we are ready to cross-compile!

If you have downloaded Acme criss-gcc debian package, don’t forget to add /usr/local/cris/bin to PATH

export PATH="/usr/local/cris/bin:$PATH"

Set enviroment variables

export HOST="cris-axis-linux-gnu"
export CC=" gcc-cris -mlinux -mno-mul-bug-workaround"
export CXX=$(CC)

export LN=” ln”
export RM=” rm -f”

export AR=” ar-cris”
export INSTALL=” install_elinux -p”
export LD=” ld-cris -mcrislinux”
export OBJCOPY=” objcopy-cris”
export RANLIB=” ranlib-cris”
export STRIP=” strip-cris”

export OPT=”-Os”
export CFLAGS=”-Wall -Wshadow -g”
export LDFLAGS=”-fPIC”
export HOSTPYTHON=./hostpython
export HOSTPGEN=./Parser/hostpgen
export CROSS_COMPILE=yes

Configure

./configure --host=$HOST --prefix=/tmp/cris-python --build=`uname -m`-pc-linux-gnu

Make and install respecting enviroment variables

make -e
make -e install

Now check if you can run your cross compiled binary /tmp/cris-python/bin/python. (You shouldn’t!)

seadog@plu:~/Projects/fox/cris-binary/python/bin$ ./python
bash: ./python: cannot execute binary file

Dada! You have a cross-compiled binary!

I also cross compiled twisted python 2.5.0 and pyxml 0.8.

You just untar and execute (python is native binary)

python -E setup.py install --prefix=../cris-python --install-scripts=/tmp/cris-python/bin

I have a bazaar repository with binary python here http://www.sealabs.net/cris/cris-binary which you can checkout using

bzr checkout http://www.sealabs.net/cris/cris-binary

And now my jabber bots can run on my fox board! :)

Posted on September 25, 2007 in Computers by seadogNo Comments »

Πέρασα μία ολόκληρη μέρα προσπαθώντας να εγκαταστήσησω το scratchbox και το build toolchain για την αρχιτεκτονική cris του fox board. ΔΕΝ ΠΑΙΖΕΙ! Για την ακρίβεια -τουλάχιστον το cris κομμάτι- είναι γεμάτο bugs και τελικά παρόλο που κατάφερα να προσπεράσω μερικά δεν τα κατάφερα όλα. Τα debian packages του scratchbox δεν είναι και πολύ προσεγμένα (setup scripts δεν παίζουν!) και λίστα φαίνεται ανενεργή, αφού ακόμη περιμένω το confirmation mail :(
Κρίμα γιατί το project φαίνεται αρκετα ενδιαφέρον και είναι πολύ καλό να έχεις ένα προστατευμένο περιβάλλον για cross-compile.

Θα περάσω μερικές ώρες δοκιμάζοντας και το scratchbox 2, ελπίζοντας μέχρι το βράδυ να έχω μία full python distribuction για την αρχιτεκτονική cris.

Posted on September 25, 2007 in Uncategorized by seadog1 Comment »

Το practical python που είχα παραγγείλει πριν από 27 μέρες τελικά έφτασε! Πήρε μια εβδομάδα παραπάνω από ότι είχα υπολογίσει στο πρώτο post, αλλά δεν είχα υπολογίσει τον χρόνο που χρειάζεται το βιβλίο να πάει από τον πραγματικό πωλητή στην alibris. Όπως και να έχει, το βιβλίο είναι όντως καινούριο, ατσαλάκωτο και άγραφο και μου κόστισε μόλις 18,5 ευρώ με τα μεταφορικά.

Το καλύτερο νέο όμως ότι η alibris άνοιξε και κατάστημα στην αγγλία, με μεταφορικά μόλις 5,8 ευρώ (+2,5 για κάθε άλλο βιβλίο) και χρόνο παραλαβής 3-14 (!) μέρες.

+1 από μένα για την alibris ;)

Posted on September 22, 2007 in Computers by seadogNo Comments »


Yesterday my fox board arrived! A complete linux system in just 66×72mm based on Axis Etrax 100LX with 32Mib RAM and 8Mib flash memory.

Features:

  • Axis ETRAX 100LX 32 bit, RISC, 100MHz (100MIPS)
  • 8MB FLASH 32MB RAM
  • 1 Ethernet (10/100 Mb/s)
  • 2 USB 1.1
  • 1 serial console port
  • 2 extension sockets with IDE, SCSI, serial lines, parallel ports, I/O lines, I2C bus interface

Yet I haven’t tested the device perfomance comprehensively but I ran some (a bit dissapointing) network tests. I get aroung 150Kib / sec using secure copy which means I will have to wait for a stronger Fox to build my embedded torrent download server :)

Acmesystems, the company which builds fox, besides the great name (see Acme Corp) is linux friendly and offers good (but not complete) documentation on various usage scenarios (e.g. lcd connections, wifi modules). The tools provided have some glitches as I haven’t managed yet to recompile successfully the flash image using Axis SDK, even if I use the provided config file.

Anyway this board seems to be the best choise for starters on embedded systems considering both price and capabilities. If only Atmel’s NGW100 had build in USB support…

Posted on September 18, 2007 in Uncategorized by seadogNo Comments »

Ένα μικρό jabber client module που έγραψα, βασισμένο στο twisted python framework. To client παρέχει όλες τις βασικές συναρτήσεις για login στο jabber server, για επικοινωνία με άλλα jabber accounts και εγκρίνει αυτόματα τις αιτήσεις για “αναγνώριση” (presence notifications)

Στο συγκεκριμένο client έχουν βασιστεί και τα echo, fortune και marx bots (σχετικό post).

#!/usr/bin/env python

from twisted.words.protocols.jabber import jid,xmlstream,client
from twisted.words.xish import domish
from twisted.internet import reactor

from string import join, letters
from random import sample

class Jclient:

def __init__(self, server, username, password, resource="Jclient", port=5222, observers=None):
self.username = username
self.password = password
self.resource = resource
self.server = server
self.port = port
self.observers = observers

def connect(self):
self.myJid = jid.JID('%s/%s' % (self.username, self.resource))
factory = client.basicClientFactory(self.myJid, self.password)
factory.addBootstrap('//event/stream/authd', self.authd)

reactor.connectTCP(self.server, self.port, factory)
reactor.run()

def authd(self, xmlstream):
#save xmlstream
self.xmlstream = xmlstream

# send presence
presence = domish.Element(('jabber:client', 'presence'))
xmlstream.send(presence)

self.watchdog()

def watchdog(self):

if not self.observers:
self.observers = {}
#self.observers['/*'] = self.logger
self.observers['/message'] = self.messageHandler
self.observers['/presence'] = self.presenceHandler

for trigger, function in self.observers.items():
self.xmlstream.addObserver(trigger, function)

def logger(self, xmlstream):
print xmlstream.toXml()

def messageHandler(self, xmlstream):
“”"
Returns sender’s jid, receiver’s jid and message
“”"

sender = xmlstream['from']
receiver = xmlstream['to']
message = xmlstream.body.children[0]
id = xmlstream['id']

return sender, receiver, id, message

def send(self, msg):

self.xmlstream.send(msg)

def newMsg(self, to, message, id=None, type=”chat”):

if not id:
# generate id
id = ‘jc’ + join(sample(letters, 5), ”)

msg = domish.Element((’jabber:client’, ‘message’), attribs={’to’:to, ‘from’:self.myJid.full(), ‘type’: type, ‘id’: id})
msg.addElement(’body’, content=message)

return msg

def replyMsg(self, xmlstream, message, type=None):
“”"
Creates reply AND sends it
“”"
msg = self.newMsg(xmlstream['from'], message, None, type or xmlstream['type'])
self.send(msg)

def presenceHandler(self, xmlstream):
“”"
Should implement auto add and auto delete from
presence lists
“”"

if ‘type’ in xmlstream.attributes:
if xmlstream['type'] == ‘error’:
pass
elif xmlstream['type'] == ‘probe’:
msg = domish.Element((’jabber:client’, ‘presence’), attribs = {’to’: xmlstream['from'], ‘from’:xmlstream['to']})
# always free to chat
msg.addElement(’show’, content=”chat”)
else:
msg = domish.Element((’jabber:client’, ‘presence’), attribs = {’type’:xmlstream['type'], ‘to’:xmlstream['from'], ‘from’:xmlstream['to']})

if msg:
self.xmlstream.send(msg)

def __del__(self):
reactor.stop()

Φτιάχνοντας ένα echo bot σε 22 γραμμές με χρήση του Jclient


#!/usr/bin/env python

from jclient import Jclient
from twisted.words.xish import domish
from twisted.internet import reactor

class Jecho(Jclient):
def __init__(self, server, username, password, resource="Jecho", port=5222):
Jclient.__init__(self,server, username, password, resource, port)
self.connect()

def messageHandler(self, xmlstream):
"""
echoes the same message to sender
"""

(sender, receiver, id, message) = Jclient.messageHandler(self,xmlstream)
self.replyMsg(xmlstream,message)

jecho = Jecho("localhost", "server@localhost", "1")

Posted on September 12, 2007 in Computers by seadog3 Comments »


Έπαιξα τις τελευταίες δύο εβδομάδες με το xmpp το πρωτόκολλο πίσω από το δίκτυο jabber το μεγαλύτερο free as in speech instant messaging δίκτυο. Το jabber πήρε τα πάνω του από τότε που το gmail αποφάσισε να υποστήριξει instant messaging τεχνολογίες με το jabber μέσα από το webmail client .

Το ίδιο το jabber είναι αποκεντρωποιημένο δίκτυο -στην λογική που λειτουργεί και το email- οπότε ο καθένας μπορεί να στήσει έναν jabber server και όλοι οι servers επικοινωνούν μεταξύ τους για να ανταλλάξουν τα μηνύματά τους οι χρήστες.

Επίσης αξίζει να σημειωθεί ότι το xmpp είναι ουσιαστικά ανταλλαγή xml μηνυμάτων κάτι που το κάνει φοβερά extensible. Μπορείς για παράδειγμα να το χρησιμοποιήσεις για application2application messaging για να δημιουργήσεις ένα message queue σε κατανεμημένα συστήματα κτλ.

Στο ψητό τώρα, χρησιμοποιήσα την twisted python, έναν ενδιαφέρον programming framework για network (και όχι μόνο) programming σε python.

Έγραψά ένα jabber client class βασισμένο στο twisted python jabber protocol και βάση αυτού έφτιαξα τρία services.

  • To echo service (echo@jabber.sealabs.net): που κάνει απλά echo ότι του λες
  • Το fortune service (fortune@jabber.sealabs.net): που σου στέλνει ένα fortune cookie (από το πρόγραμμα fortune του linux) κάθε φορά που γίνεσαι available
  • και… το καλύτερο τον Karl Marx (marx@jabber.sealabs.net) ένα chatbot βασισμένο στο megahal και εκπαιδευμένο με το Κομμουνιστικό Μανιφέστο

Μπορείτε να κάνετε add buddy τα παραπάνω και θα κάνουν άμεσα authorise. Οι συζητήσεις σας με τα παραπάνω bot και κυρίως με τον Marx μπορεί να καταγράφονται για όλους ψυχαγωγίας ;)
Θα ανεβάσω και τους σχετικούς κώδικές γιατί αυτό το ριμάδι το twisted python δεν έχει ολοκληρωμένο documentation

Posted on September 2, 2007 in Uncategorized by seadogNo Comments »

Super Mushroom
Μου έκαναν δώρο ένα pixelized μανιτάρι από το super mario, φτιαγμένο με υλικά ενός παιχνιδιού χειροτεχνίας. Κάνεις ένα σχέδιο με χάντρες - pixels μετά τα σιδερώνεις και το πλαστικό λιώνοντας κολλά τις χάντρες μεταξύ τους, δίνοντας ένα ενιαίο αποτέλεσμα. Εύκολο, αισθητικά ωραίο και σίγουρα geeky ;) Το μόνο πρόβλημα είναι ότι δεν ξέρω πως ονομάζεται το παιχνίδι!

btw ποιός είπε ότι τα μανιτάρια του super mario δεν έχουν καταχώρηση στην wikipedia? http://en.wikipedia.org/wiki/Mushroom_(Mario)