2011年10月25日星期二

10.25

tinyos normal communication interface:

/opt/tinyos-2.1.1/tos/interfaces/Packet.nc

#include

interface Packet{
command void clear(message_t* msg);
command uint8_t payloadLength(message_t* msg);
command void setPayloadLength(message_t* msg, uint8_t len);
command uint8_t maxPayloadLength();
command void* getPayload(message_t* msg, uint8_t len);
}


---------------------------
/opt/tinyos-2.1.1/tos/types/message.h

#include "platform_message.h"

typedef nx_struct message_t {
nx_uint8_t header[sizeof(message_header_t)];
nx_uint8_t data[TOSH_DATA_LENGTH];
nx_uint8_t footer[sizeof(message_footer_t)];
nx_uint8_t metadata[sizeof(message_metadata_t)];
} message_t;


Send:no address interface for sending data

#include
#include

interface Send {


command error_t send(message_t* msg, uint8_t len);

command error_t cancel(message_t* msg);

event void sendDone(message_t* msg, error_t error);

command uint8_t maxPayloadLength();

command void* getPayload(message_t* msg, uint8_t len);
}

Receive:receive interface for message

#include
#include

interface Receive {


event message_t* receive(message_t* msg, void* payload, uint8_t len);

}

PacketAcknowledgements:

interface PacketAcknowledgements {


async command error_t requestAck( message_t* msg );

async command error_t noAck( message_t* msg );

async command bool wasAcked(message_t* msg);

}

async:

RadioTimeStamping:
interface RadioTimeStamping
{

async event void transmittedSFD( uint16_t time, message_t* p_msg );

async event void receivedSFD( uint16_t time );
}

------------------------------------
TestSerial.java do the work of serial communication.

But in android platform, there is no software environment to control telosb.
I need to learn how android get the data from serial port. It should be NDK and JNI development and produce a lib for the upper app to call it.

I bought IOIO today and hope it work well for my project.


2011年10月20日星期四

Telosb serial port test-tinyos2.1.1

Telosb has two serial port: UART 0 and UART 1. The default setting is UART1.
When doing the write or read operation, data will go through FT232BM chip, which is a USB-serial converter chip, and then upload to PC.

First, I will introduce the 'make' command

1)make [platform]: this command will compile nesc code that could run on certain platform such as telosb or mica. You need to cd to the code directory.

eg: make telosb; make mica

2)make [platform] reinstall: this command will download the code into the platform

3)make [platform] install: this command is equal to first run 'make [platform]' then 'make [platform] reinstall'. Of course, if there is any error when doing the 'make [platform]', it will not go to 'make [platform] reinstall'.

4)make clean: clean the file or directory the above compile command generate.

Then you can run 'java net.tinyos.tools.Listen -comm serial@/dev/ttyUSB0:telosb'
ttyUSBx could change, you can check the port with 'motelist'

If the java env and PATH is right, you will get
serial@/dev/ttyUSB0:115200: resynchronising

this means java is ok, and it is waiting the data. But it could receive anything.
We need to go to /apps/tests/TestSerial
'make telosb install'
Then try the serial listen again, it will say
:-) java net.tinyos.tools.Listen -comm serial@/dev/ttyUSB0:telosb
serial@/dev/ttyUSB0:115200: resynchronising
00 FF FF 00 00 02 00 89 00 64
00 FF FF 00 00 02 00 89 00 65
00 FF FF 00 00 02 00 89 00 66
00 FF FF 00 00 02 00 89 00 67
00 FF FF 00 00 02 00 89 00 68
00 FF FF 00 00 02 00 89 00 69
00 FF FF 00 00 02 00 89 00 6A
00 FF FF 00 00 02 00 89 00 6B
00 FF FF 00 00 02 00 89 00 6C
00 FF FF 00 00 02 00 89 00 6D
00 FF FF 00 00 02 00 89 00 6E
00 FF FF 00 00 02 00 89 00 6F
00 FF FF 00 00 02 00 89 00 70
00 FF FF 00 00 02 00 89 00 71
00 FF FF 00 00 02 00 89 00 72
00 FF FF 00 00 02 00 89 00 73
00 FF FF 00 00 02 00 89 00 74

:-) java TestSerial -comm serial@/dev/ttyUSB1:telosb
Sending packet 0
serial@/dev/ttyUSB1:115200: resynchronising
Received packet sequence number 287
Received packet sequence number 288
Received packet sequence number 289
Received packet sequence number 290
serial@/dev/ttyUSB1:115200: bad packet
Received packet sequence number 292
Received packet sequence number 293
Received packet sequence number 294
serial@/dev/ttyUSB1:115200: bad packet
Received packet sequence number 296
Received packet sequence number 297
Received packet sequence number 298
serial@/dev/ttyUSB1:115200: bad packet
serial@/dev/ttyUSB1:115200: bad packet
Received packet sequence number 301
Received packet sequence number 302
Received packet sequence number 303


Congrats!


Telosb communicate with PC through support/sdk/java and support/sdk/c, we could use java or c to do the communication. Also, we could use python.

java net.tinyos.tools.Listen -comm serial@/dev/ttyUSB0:telosb

This command use java to implement the listen of serial port. The baud rate of telosb is 115200.

Tomorrow I will study the serial port of telosb both in hardware and software.

The cable that connect microUSB port to USB male port is still on delivery...
I will debug telosb serial port and android port separately before I get the cable.

2011年10月7日星期五

tinyos2.1.1-ubuntu11.04 msp430 error solution

I have been blocked by this issue for a long time.... Today it is finally been solved

Based on the ubuntu11.04 environment. There is java installed. You can check the version with 'java -version', it should be java version "1.6.0_22".

I use the 'deb http://tinyos.stanford.edu/tinyos/dists/ubuntu lucid main' for the repository. Add it to the /etc/apt/sources.list.

sudo apt-get update

sudo apt-get install tinyos-2.1.1

It will automatically install all the related toolchains and compiles, including MSP430 toolchain, AVR toolchain, nesc compliers etc.

I use 'dpkg -l |grep tinyos*' and similar commands to see the installed packages. Also, I use 'nescc -v' to check the nesc version.

Use tos-check-env to check the env. There will be two warnings about java version and graphviz, I skipped them.

Then test is coming! Run 'make telosb' in /opt/tinyos-2.1.1/apps/Blink, you will see a lot of errors about msp430 related nc file, said can not find port....

The problem is discussed in here. The keypoint of this problem is msp430 packages.

There are 6 msp430 packages after your original installation: (dpkg -l |grep msp430*)

msp430-binutils-tinyos
msp430-gcc-tinyos
msp430-libc-tinyos
msp430-tinyos
msp430mcu-tinyos
tinyos-required-msp430

What I did is remove all these packages and install the old version, here are the instructions:

1 remove msp430 packages

sudo apt-get autoremove --purge msp430-tinyos
sudo apt-get autoremove --purge msp430-gcc-tinyos

2 download the old version from here

3 install the old msp430 packages, because of the dependency, the steps is important, of course, you can try one by one...

sudo dpkg -i msp430-gcc-tinyos_3.2.3-20080806_i386.deb
sudo dpkg -i msp430-tinyos-base_2.1-20080806_all.deb
sudo dpkg -i msp430-binutils-tinyos_2.17-20080806_i386.deb
sudo dpkg -i msp430-gcc-tinyos_3.2.3-20080806_i386.deb
sudo dpkg -i msp430-libc-tinyos_20060801cvs-20080806_i386.deb
sudo dpkg -i msp430-tinyos_2.1-20080806_all.deb
sudo dpkg -i msp430-optional-tinyos_2.1-20090326_all.deb

Then try Blink again, you will see the blue LED is flashing. Congrats!

2011年10月1日星期六

gnuradio installation

for  Natty Narwhal (11.04)

sudo apt-get -y install git-core autoconf automake  libtool g++ python-dev swig \ pkg-config libboost-all-dev libfftw3-dev libcppunit-dev libgsl0-dev \ libusb-dev sdcc libsdl1.2-dev python-wxgtk2.8 python-numpy \ python-cheetah python-lxml doxygen python-qt4 python-qwt5-qt4 libxi-dev \ libqt4-opengl-dev libqwt5-qt4-dev libfontconfig1-dev libxrender-dev

//
Download GNU Radio from the git master tree:
git clone http://gnuradio.org/git/gnuradio.git
cd gnuradio ./bootstrap ./configure make
make check

sudo make install

//installation done, try to execute the dial_tone.py example (/usr/local/share/gnuradio/examples/audio/dial_tone.py)

error

//solution:
$ cp /etc/ld.so.conf /tmp/ld.so.conf $ echo /usr/local/lib >> /tmp/ld.so.conf $ sudo mv /tmp/ld.so.conf /etc/ld.so.conf $ sudo ldconfig

pass

installation & env of tinyos2

Tinyos sw has two versions, the newest one is tinyos-2.1.1. I tried to install both on my os, but the toolchain which support the tinyos would totally mess up the environment and can not proceed to compile. So I tried to uninstall the tinyos-2.1.1. However, the apt-get autoremove failed to remove the packet and also can not install the tinyos again. Finally, I reinstall ubuntu and use the initial environment to run the program.


When doing apt-get from the server, it will install the toolchain include avr-binutil, avr-gcc, avr-libc, tinyos-tools,msp430 tools and nesc. After finishing doing the installation, I used gcc-v, python -v, java-verion, and nescc -v to check the environment. At last, I used tos-check-env to check the whole env. There are two warning which is jdk version should be 1.4 or 1.5 and the graphviz version is not right. I skipped it to do the test.

Some operation record:

//bug wit apt-get install, "decode error, etc"use this to remove the list
sudo rm /var/lib/apt/lists/* -vf

apt-get update

//still have the bug,find some bug with /etc/apt.conf, since use proxy server before, change it to
APT
{
//Options for apt-get
Get
{
Download-Only "false";
Show-UPgraded "true";
};
};

//still can not install the tinyos-2.1.1, reinstall the system. Tried a lot other method, not recorded here.

add the repository in /etc/apt/source.list
# deb http://tinyos.stanford.edu/tinyos/dists/ubuntu lucid main

apt-get update

sudo apt-get install tinyos-2.1.1

//change the env of tinyos.sh

CLASSPATH=$CLASSPATH:$TOSROOT/support/sdk/java/tinyos.jar:.


//test the env
/* */
configuration SkelAppC {
}
implementation
{
components MainC, SkelC;

SkelC -> MainC.Boot;
}
Save as SkelAppC.nc
Take new file in gedit. Type follwing code
/*
The SKEL application */
module SkelC

{
uses interface Boot;

}
implementation
{

event void Boot.booted()
{
1;
}
}
Save the file as SkelC.nc
Take new file in gedit
Type following

COMPONENT=SkelAppC
include $(MAKERULES)

Save as Makefile

make telosb

//wrong, error: no Makerule
echo $MAKERULES
/opt/tinyos-2.1.1/support/make/Makerules

//the env setting is right, problem is the chmod of the file,
chmod 777 -R tinyos-2.1.1

make telosb

/usr/bin/../lib/gcc/msp430/4.5.3/../../../../msp430/include/signal.h:43:2: warning: #warning msp430-libc deprecated, using


//pass, then test Blink
error : /opt/tinyos-2.1.1/tos/chips/msp430/pins/HplMsp430GeneralIOC.nc:227: syntax error before `;'


//It should be the problem of the version of msp430, I will use old version to try this model tomorrow.

The android env was deleted because of the reinstall of os. :(