#!/usr/bin/python
import serial,sys,os,xmpp
timeout=250
reading=True
print "\n\n\n\n\n\n\n\n\n\n\n\n"
zerocount=0
codes=["._", "_...", "_._.", "_..", ".", ".._.", "__.", "....", "..",
".___", "_._", "._..", "__", "_.", "___", ".__.", "__._", "._.",
"...", "_", ".._", "..._", ".__", "_.._", "_.__", "__.."]
keys=["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
"N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
#must make port open for business; with su chmod 666 /dev/ttyUSB0
ser = serial.Serial('/dev/ttyUSB0', 9600)
#sender id/password
jid="mac@jabber.laptop.org" #had to register this account with the server
pwd="test" #don't know what the password is for the xos
#receiving xo
#c9dcdd473a2817adf24ff26430f657c981857134@jabber.laptop.org plaz
#182f647d0a622b2fbc0a7bfbb35aba6f927b1b53@jabber.laptop.org kbaum
recipient="c9dcdd473a2817adf24ff26430f657c981857134@jabber.laptop.org"
#connect xo
jid=xmpp.protocol.JID(jid)
cl=xmpp.Client(jid.getDomain(),debug=[])
if cl.connect() == "":
print "xmpp not connected"
sys.exit(0)
if cl.auth(jid.getNode(),pwd) == None:
print "xmpp authentication failed"
sys.exit(0)
def analyze(s):
s=s[s.find("1"):]
s=s.replace("10", "1 0")
s=s.replace("01", "0 1")
s=s.replace("010", "000")
s=s.replace("101", "111")
s=s.replace("0110", "0000")
while (s.find("00")!=-1):
s=s.replace("00", "0")
s=s.replace("0", " ")
#print s
blocks=s.split()
#print blocks
total=0
count=0
min=100000000000
for i in range(0, len(blocks)):
if(len(blocks[i])<min):
min=len(blocks[i])
mess=""
for i in range(0, len(blocks)):
if(len(blocks[i])>=2*min):
mess+="_"
else:
mess+="."
if(mess!=""):
if(mess.find("_")==-1):
if(min>=75):
mess=mess.replace(".", "_")
print mess
for i in range(0, len(codes)):
if(mess==codes[i]):
#print min
print keys[i]+"\n"
cl.send(xmpp.protocol.Message(recipient,msg))
s=""
temp=0
count=0
while 1:
rl=ser.readline()
try:
rl = int((rl.strip()).replace("?", ""))
except:
#print "whoops"
1
if(rl>800):
rl="1"
else:
rl="0"
s+=rl
if(rl=="0"):
zerocount+=1
if(zerocount>=timeout):
analyze(s)
s=""
zerocount=0
else:
zerocount=0