[Tinyos-help] Help writing to telosb over UART in Python
Darren Bishop
D.Bishop at cs.ucl.ac.uk
Tue Jul 25 10:42:03 PDT 2006
I am writing a Pyhton software to manage our mote testbed; I must use Python
to integrate into the 'larger' system and I must use TinyOS-1.x.
I am having trouble writing to the motes over UART. I can read from them
perfectly i.e. I have implemented the HDLC-like framing and CRC calculation
and all is well. For example, I read the following from a telosb mote running
the Oscilloscope image:
rxpkt: 7e 42 0e 00 00 00 00 00 7d 5e 00 1b 7d 5d 00 00 8d 00 00 0d 9c dc 43 01
00 f6 00 08 66 3f 7e
[As an aisde, can anyone explain why the payload length is moved to rxpkt[2],
and where bytes rxpkt[3-7] come from?]
My goal here is to implement a 'command interpreter' on the mote, where
commands are sent from the PC.
The content of CommandMsg.h is as follows:
enum {
COMMAND = 1 << 15,
STATUS = 0 << 15,
INTERNAL = 1 << 14,
EXTERNAL = 0 << 14
};
struct CommandMsg
{
uint16_t cmd;
uint16_t mask;
uint16_t arg;
};
enum {
AM_COMMANDMSG = 20
};
The byte array (Python: array.array('B')) of data I want to send goes through
the following transformations:
Data: 0b 00 00 00 a3 08 (11, 0, 2211)
Message: 7e 00 1b 7d 0b 00 00 00 a3 08
Packet: 7e 42 06 00 00 00 00 00 7d 5e 00 14 7d 5d 0b 00 00 00 a3 08 f9 f0 7e
The final packet format reflects what I read of the wire i.e. Packet[2] is the
data length followed by 5 pad bytes.
I open the port with the following Python code (assume necessary modules are
imported):
def open(self):
self.__fd = os.open(self.__port, os.O_RDWR|os.O_NOCTTY)
iflag, oflag, cflag, lflag, ispeed, ospeed, cc = \
termios.tcgetattr(self.__fd)
cflag = termios.CS8 | termios.CLOCAL | termios.CREAD
iflag = termios.IGNPAR | termios.IGNBRK
oflag = 0 # saw this in serialsource.c
ispeed = termios.__dict__['B'+str(self.__baudrate)]
ospeed = termios.__dict__['B'+str(self.__baudrate)]
termios.tcflush(self.__fd, termios.TCIFLUSH);
termios.tcsetattr(self.__fd, termios.TCSANOW, \
[iflag, oflag, cflag, lflag, ispeed, ospeed, cc]);
When I write the packet, the little green LED by the mote-USB connector (not
the main 3-LEDS) flashes, but I do not get the desired result i.e. the main
red-LED does not switch on (as it is 'commanded' to).
Has anyone achieved writing to a (telosb?) mote in C or Python? Have I set the
wrong output flags (oflag) on the serial port maybe? Have I got the frame
format wrong?
Your help is appreciated.
--
Warm regards,
Darren Bishop, MSc, BSc (Hons), MBCS
More information about the Tinyos-help
mailing list