This is exactly what i was looking for....

For those following, the \x00 added at the end of the
packet is just imaginary and represents

in the meantime, I made the following that just
'decobs' a series of packets (only 8-10 bytes) that
are coming in over the com port. (my incoming packets
also begin with x00 for some reason)

It accurately decodes that data stream (same result as
when I esc out and connect with the dev kit program)
I need to use what you have given me to make it
scalable for size 


#!/usr/bin/env python

#MJC 20051004
baudrate = 115200
port = 'com4'
echo = 1
convert_outgoing_cr = 1

import sys, serial, threading

s = serial.Serial(port,baudrate)

def reader():
    """loop forever and copy serial->console"""
    cobspacket = [0,0,0,0,0,0,0,0,0,0]
    while 1:
        i = 0
        cobschar = s.read()
        cobspacket[i] = ord(cobschar)
        if cobschar == '\x00':
            cobschar = s.read()
            cobspacket[i] = ord(cobschar)
            codebyte = int(cobspacket[i])
            while cobschar != '\x00':
                if i == codebyte:
                    d = 0
                    codebyte = codebyte +
cobspacket[i] 
                else:
                    d = cobspacket[i]
                    
                if i>0:
                    sys.stdout.write('%02X' % (d))

                i+=1
                cobschar = s.read()
                cobspacket[i] = ord(cobschar)

        sys.stdout.write('\n')

def writer():
    """loop forever and copy console->serial"""
    while 1:
        c = getkey()
        if c == '\x1b': break   #exit on esc
        s.write(c)              #send character
        if convert_outgoing_cr and c == '\r':
            s.write('\n')
            if echo: sys.stdout.write('\n')


print "--- Mikey's interface --- type ESC to quit"
#start serial->console thread
r = threading.Thread(target=reader)
r.setDaemon(1)
r.start()
#enter console->serial loop
writer()

print "\n--- exit ---"



--- Alan Gauld <[EMAIL PROTECTED]> wrote:

> > I am a noob to converting pointers in C++ to
> arrays in
> > python, although the first time I see it done, I
> will
> > have no problem. Can you help converting the below
> > (what I think is the 'decoder' section) to python?
> 
> It won't be working code but I think this is whats
> happening...
> 
> > UINT CCobsPackets::UnStuffData(unsigned char *src,
> > unsigned char *dst, UINT length)
> 
> def UnStuffData(src,dst,len):
-snip-


        
                
______________________________________________________ 
Yahoo! for Good 
Donate to the Hurricane Katrina relief effort. 
http://store.yahoo.com/redcross-donate3/ 

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to