I am Liang Hong. A student in CSE department of UB. This blog is mainly used as a record of my study.
2012年1月24日星期二
vim: two file copy&paste diff
vim execlp.c
:sp/:vsp
:e fork1.c
Ctrl+w w
v
yy
Ctrl+w w
p
----------------------------
:vert diffsplit ~/src/kern/vm/kmalloc.c
:diffthis
vim -d file1 file2/vimdiff file1 file2
2012年1月18日星期三
gnuradio code for USRP2 TX/RX
#packet_utils.py(make packet, build a packet, given access code, payload, and whitener offset)
#packet will have access code at the beginning, followed by length, payload and finally CRC32
self.connect(self._pkt_input, self._modulator, self)
self.connect(self, self._demodulator, self.correlator, self.framer_sink)
-----------------------------------------------------------------------------
dbpsk.py
"differential BPSK modulation and demodulation"
"input is a byte stream (unsigned char) and the output is the complex modulated signal at baseband"
#function bits_per_symbol will return 1, so arity is 2
arity = powe(2, self.bits_per_symbol())
self.symbol_mapper = gr.map_bb(psk.binary_to_ungray[arity])
--------------------------------------------
psk.py
# identity mapping, range(2) is start from 0(default), the end is 2, so it means [0, 1, 2]
binary_to_ungray = {
2 : range(2),
4 : range(4),
8 : range(8)
}
-----------------------------------------
//how the actual symbol mapping to constellations is done
gr_map_bb.cc
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include
#include
gr_map_bb_sptr
gr_make_map_bb (const std::vector &map)
{
return gnuradio::get_initial_sptr(new gr_map_bb (map));
}
gr_map_bb::gr_map_bb (const std::vector &map)
: gr_sync_block ("map_bb",
gr_make_io_signature (1, 1, sizeof (unsigned char)),
gr_make_io_signature (1, 1, sizeof (unsigned char)))
{
for (int i = 0; i < 0x100; i++)
d_map[i] = i;
unsigned int size = std::min((size_t) 0x100, map.size());
for (unsigned int i = 0; i < size; i++)
d_map[i] = map[i];
}
int
gr_map_bb::work (int noutput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items)
{
const unsigned char *in = (const unsigned char *) input_items[0];
unsigned char *out = (unsigned char *) output_items[0];
for (int i = 0; i < noutput_items; i++)
out[i] = d_map[in[i]];
return noutput_items;
}
-------------------------------------------
dbpsk.py
#symbol clock recovery
self.receiver=gr.mpsk_receiver_cc(arity, 0,
self._costas_alpha, self._costas_beta,
fmin, fmax,
self._mm_mu, self._mm_gain_mu,
self._mm_omega, self._mm_gain_omega,
self._mm_omega_relative_limit)
-----------------------------------
//Basically M-PSK modulations in GNU Radio utilize the function
gr_mpsk_receiver_cc.cc
------------------------------------------------------
use gr.file_sink() to dump all kinds of data in GNU Radio
The dumped data can be read from Matlab using some conversion codes
---------------------------------------------------------
you need to make and make install when debugging, otherwise you don't add your new modifications to the library and install the library for the python code to access.
eg:
change gr_mpsk_receiver_cc.cc in gnuradio-core/src/lib/general/
change pkt.py in gnuradio-core/src/python/gnuradio/blks2impl
---------------------------------------------------------
benchmark_tx.py
benchmark_rx.py
usrp_transmit_path.py
usrp_receive_path.py
transmit_path.py
receive_path.py
pkt.py
packet_utils.py
dbpsk.py
dqpsk.py
gr_map_bb.cc
-------------------------------
tmr
1 trace dbpsk.py for connection with pkt.py
2 try code below
#!/usr/bin/env python
from gnuradio import gr, eng_notation, gru, window, blks2
from gnuradio import audio
from gnuradio import usrp
from gnuradio.eng_option import eng_option
from optparse import OptionParser
from gnuradio import gr_unittest
class my_top_block(gr.top_block):
def __init__(self):
gr.top_block.__init__(self)
self.data = (1+2j, 3+4j, 5+6j)
self.src = gr.vector_source_c (self.data)
self.converte = gr.complex_to_float()
self.re_sink = gr.vector_sink_f ()
self.im_sink = gr.vector_sink_f ()
self.connect (self.src, (self.converte,0))
self.connect ((self.converte,0), self.re_sink)
self.connect((self.converte,1), self.im_sink)
if __name__ == '__main__' :
tb = my_top_block()
try:
tb.run()
except KeyboardInterrupt:
pass
print "src data: ", tb.data
print "real: ", tb.re_sink.data()
print "imag: ", tb.im_sink.data()
3 use --log of benchmark to see what .dat file can get
4 Q: if I have made one DQPSK transmission for image transfer and now I want to check the transmission and reception of the image at different SNR values. I am unable to find any signal block where i can change the SNR value .
A:
You will want to add a Gaussian noise source and a add block to add------------------------------------------------------------------
AWGN, or you can use the channel_model block. To set the SNR, you will
first have to calculate the signal power in your simulation and from
their, determine the noise power for your desired SNR. The convert the
noise power to an amplitude, which is what the noise source block
takes. Look in gnuradio-examples/python/digital/benchmark_loopback.py
to see an example of these calculations.
discussion is from here
2011年10月25日星期二
10.25
/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 );
}
------------------------------------
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
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
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
//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. :(