2010年6月4日 星期五

debug USB - use usbmon, usbfs


dump urb data

  1. 編kernel時,在driver/usb/下選擇usb monitor
  2. mount -t debugfs debugfs /sys/kernel/debug
  3. 之後在此目錄下就會看到usbmon目錄
  4. 可以在此dump出urb的資料(ascii)

  • 可以使用/dev/usbmon[XX]來dump出raw data,之後自己寫程式去parse
  • 詳細文件參考Documentation/usb/usbmon.txt

查看linux上所有USB裝置的詳細資訊



  1. mount -t usbfs usbfs /proc/bus/usb/
  2. cat /proc/bus/usb/devices
  3. 各攔位介紹
    1. http://www.linux-usb.org/USB-guide/c607.html
  4. 詳細文件: Documentation/usb/proc_usb_info.txt

/proc/bus/usb/devices各欄位資料

  • T開頭(topology)
    • Bus: which bus the device is on
    • Lev: the level of the device
      • level 00 for the root hub
      • level 01 for any device attached to the root hub
      • level 02 for devices attached to hubs at level 01, and so on.
    • Prnt: the parent device for this device
      • always 00 for the root hub
      • 01 for the devices attached to the root hub
    • Port: the port on the parent device
      • starting at 00 for the first port on each device.
      • Prnt/Port is unique per bus.
    • Cnt: what number device this is, based on the enumeration order within that level of the topology, starting at 01 for the first device.
    • Dev#: what number device this is, irrespective of level, based on the bus enumeration order. This is unique per bus
    • Spd: what speed this device is running at, in Mbps (either 1.5 or 12 with the current version of USB).
    • MxCh: how many devices can be connected to this device
      • 00 for anything except a hub.
    • Driver: which device driver is being used for this device
      • an entry of (none) indicates that no driver is being used.
  • D開頭(device descriptor)
    • Ver: which USB specification version the device claims to meet.
    • Cls: which device class the device is claiming to meet, in both hexadecimal and as a string.
      • A Cls entry of 00(>ifc) indicates that the device class specification compliance is interface dependent, and the interface descriptor should be read for device class information.
    • Sub: which sub-class (within the Cls entry), the device meets.
    • Prot: which protocol within a class or sub-class the device claims to meet.
    • MxPS: how big the packets from Endpoint 0 are.
    • #Cfgs: how many configurations this device has.
  • P開頭(pid/vid)
    • Vendor: the Vendor Identification code for the device
    • ProdID: the Product Identification code for the device.
    • Rev: the product revision number.
  • S開頭: vendor and product strings that the device returned.
  • C開頭(configuration descriptor)

    • the number of C:lines per device is given by #Cfgs, and the entry followed by an asterisk is the current configuration.

    • #If: how many interfaces the device has.

    • Cfg#: which configuration is being described.

    • Atr: hexadecimal indication of the device attributes

      • 0x80 for bus-powered

      • 0x40 for self-powered

      • 0x20 for remote wake-up capable

    • MxPwr: maximum power draw for this device configuration, in milliamps(mA).

  • I開頭(interface descriptor)

    • If#: which interface is being described within a given device configuration.

    • Alt: which alternate setting of this interface is being described.

    • #EPs: how many endpoints there are within the alternate setting for this endpoint.

    • Cls: which class the alternate setting of the interface corresponds to, in both hexadecimal and as a character string.

    • Sub: which sub-class the alternate setting of the interface belongs to.

    • Prot: which interface protocol (within a class and sub-class tuple) the alternate setting of the interface conforms to.

    • Driver: which of the various USB drivers has claimed this interface.

  • E開頭(endpoint descriptor)

    • Endpoint 0 is not displayed.

    • Ad: endpoint address, with a letter to indicate whether the endpoint is an In or Out endpoint.

    • Atr: the attribute (transfer type) associated with the endpoint, followed by a string translating the transfer type.

    • MxPS: maximum packet size this endpoint is capable of sending or receiving, as appropriate.

    • Ivl: the interval, in milliseconds, between polling of interrupt endpoints.

      • ignored for bulk and control transfers, and is set to 1 for isochronous transfers.







=================================================

example

root@ocgod-ubuntu9:/proc/bus/usb# cat devices

T: Bus=05 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#= 1 Spd=12 MxCh= 2
B: Alloc= 0/900 us ( 0%), #Int= 0, #Iso= 0
D: Ver= 1.10 Cls=09(hub ) Sub=00 Prot=00 MxPS=64 #Cfgs= 1
P: Vendor=1d6b ProdID=0001 Rev= 2.06
S: Manufacturer=Linux 2.6.28-18-generic uhci_hcd
S: Product=UHCI Host Controller
S: SerialNumber=0000:00:10.3
C:* #Ifs= 1 Cfg#= 1 Atr=e0 MxPwr= 0mA
I:* If#= 0 Alt= 0 #EPs= 1 Cls=09(hub ) Sub=00 Prot=00 Driver=hub
E: Ad=81(I) Atr=03(Int.) MxPS= 2 Ivl=255ms

T: Bus=04 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#= 1 Spd=12 MxCh= 2
B: Alloc= 0/900 us ( 0%), #Int= 0, #Iso= 0
D: Ver= 1.10 Cls=09(hub ) Sub=00 Prot=00 MxPS=64 #Cfgs= 1
P: Vendor=1d6b ProdID=0001 Rev= 2.06
S: Manufacturer=Linux 2.6.28-18-generic uhci_hcd
S: Product=UHCI Host Controller
S: SerialNumber=0000:00:10.2
C:* #Ifs= 1 Cfg#= 1 Atr=e0 MxPwr= 0mA
I:* If#= 0 Alt= 0 #EPs= 1 Cls=09(hub ) Sub=00 Prot=00 Driver=hub
E: Ad=81(I) Atr=03(Int.) MxPS= 2 Ivl=255ms

T: Bus=03 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#= 1 Spd=12 MxCh= 2
B: Alloc= 0/900 us ( 0%), #Int= 0, #Iso= 0
D: Ver= 1.10 Cls=09(hub ) Sub=00 Prot=00 MxPS=64 #Cfgs= 1
P: Vendor=1d6b ProdID=0001 Rev= 2.06
S: Manufacturer=Linux 2.6.28-18-generic uhci_hcd
S: Product=UHCI Host Controller
S: SerialNumber=0000:00:10.1
C:* #Ifs= 1 Cfg#= 1 Atr=e0 MxPwr= 0mA
I:* If#= 0 Alt= 0 #EPs= 1 Cls=09(hub ) Sub=00 Prot=00 Driver=hub
E: Ad=81(I) Atr=03(Int.) MxPS= 2 Ivl=255ms

T: Bus=02 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#= 1 Spd=12 MxCh= 2
B: Alloc= 34/900 us ( 4%), #Int= 3, #Iso= 0
D: Ver= 1.10 Cls=09(hub ) Sub=00 Prot=00 MxPS=64 #Cfgs= 1
P: Vendor=1d6b ProdID=0001 Rev= 2.06
S: Manufacturer=Linux 2.6.28-18-generic uhci_hcd
S: Product=UHCI Host Controller
S: SerialNumber=0000:00:10.0
C:* #Ifs= 1 Cfg#= 1 Atr=e0 MxPwr= 0mA
I:* If#= 0 Alt= 0 #EPs= 1 Cls=09(hub ) Sub=00 Prot=00 Driver=hub
E: Ad=81(I) Atr=03(Int.) MxPS= 2 Ivl=255ms

T: Bus=02 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#= 2 Spd=1.5 MxCh= 0
D: Ver= 1.10 Cls=00(>ifc ) Sub=00 Prot=00 MxPS= 8 #Cfgs= 1
P: Vendor=13ba ProdID=0017 Rev= 0.01
S: Product=Generic USB K/B
C:* #Ifs= 2 Cfg#= 1 Atr=a0 MxPwr=100mA
I:* If#= 0 Alt= 0 #EPs= 1 Cls=03(HID ) Sub=01 Prot=01 Driver=usbhid
E: Ad=81(I) Atr=03(Int.) MxPS= 8 Ivl=24ms
I:* If#= 1 Alt= 0 #EPs= 1 Cls=03(HID ) Sub=01 Prot=02 Driver=usbhid
E: Ad=82(I) Atr=03(Int.) MxPS= 5 Ivl=10ms

T: Bus=02 Lev=01 Prnt=01 Port=01 Cnt=02 Dev#= 3 Spd=1.5 MxCh= 0
D: Ver= 1.10 Cls=00(>ifc ) Sub=00 Prot=00 MxPS= 8 #Cfgs= 1
P: Vendor=04d9 ProdID=0499 Rev= 2.90
C:* #Ifs= 1 Cfg#= 1 Atr=a0 MxPwr=100mA
I:* If#= 0 Alt= 0 #EPs= 1 Cls=03(HID ) Sub=01 Prot=02 Driver=usbhid
E: Ad=81(I) Atr=03(Int.) MxPS= 8 Ivl=10ms

T: Bus=01 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#= 1 Spd=480 MxCh= 8
B: Alloc= 0/800 us ( 0%), #Int= 0, #Iso= 0
D: Ver= 2.00 Cls=09(hub ) Sub=00 Prot=00 MxPS=64 #Cfgs= 1
P: Vendor=1d6b ProdID=0002 Rev= 2.06
S: Manufacturer=Linux 2.6.28-18-generic ehci_hcd
S: Product=EHCI Host Controller
S: SerialNumber=0000:00:10.4
C:* #Ifs= 1 Cfg#= 1 Atr=e0 MxPwr= 0mA
I:* If#= 0 Alt= 0 #EPs= 1 Cls=09(hub ) Sub=00 Prot=00 Driver=hub
E: Ad=81(I) Atr=03(Int.) MxPS= 4 Ivl=256ms

2010年6月3日 星期四

在linux 下使用rdesktop連線windows 遠端桌面

在ubuntu中可以使用內建的圖形化介面:tsclient
不過他預設的解析度只有固定幾個,無法改變
(就直接修改tsclient存下來的設定檔,也只會跳到最接近的選項)

所以可以使用rdesktop指令:
rdesktop -u cyl -p passwd -g 1280x1000 -a 24 192.168.0.XXX -x nr



rdesktop: A Remote Desktop Protocol client.
Version 1.6.0. Copyright (C) 1999-2008 Matthew Chapman.
See http://www.rdesktop.org/ for more information.

Usage: rdesktop [options] server[:port]
-u: user name
-d: domain
-s: shell
-c: working directory
-p: password (- to prompt)
-n: client hostname
-k: keyboard layout on server (en-us, de, sv, etc.)
-g: desktop geometry (WxH)
-f: full-screen mode
-b: force bitmap updates
-L: local codepage
-A: enable SeamlessRDP mode
-B: use BackingStore of X-server (if available)
-e: disable encryption (French TS)
-E: disable encryption from client to server
-m: do not send motion events
-C: use private colour map
-D: hide window manager decorations
-K: keep window manager key bindings
-S: caption button size (single application mode)
-T: window title
-N: enable numlock syncronization
-X: embed into another window with a given id.
-a: connection colour depth
-z: enable rdp compression
-x: RDP5 experience (m[odem 28.8], b[roadband], l[an] or hex nr.)
-P: use persistent bitmap caching
-r: enable specified device redirection (this flag can be repeated)
'-r comport:COM1=/dev/ttyS0': enable serial redirection of /dev/ttyS0 to COM1
or COM1=/dev/ttyS0,COM2=/dev/ttyS1
'-r disk:floppy=/mnt/floppy': enable redirection of /mnt/floppy to 'floppy' share
or 'floppy=/mnt/floppy,cdrom=/mnt/cdrom'
'-r clientname=': Set the client name displayed
for redirected disks
'-r lptport:LPT1=/dev/lp0': enable parallel redirection of /dev/lp0 to LPT1
or LPT1=/dev/lp0,LPT2=/dev/lp1
'-r printer:mydeskjet': enable printer redirection
or mydeskjet="HP LaserJet IIIP" to enter server driver as well
'-r sound:[local[:driver[:device]]|off|remote]': enable sound redirection
remote would leave sound on server
available drivers for 'local':
alsa: ALSA output driver, default device: default
oss: OSS output driver, default device: /dev/dsp or $AUDIODEV
'-r clipboard:[off|PRIMARYCLIPBOARD|CLIPBOARD]': enable clipboard
redirection.
'PRIMARYCLIPBOARD' looks at both PRIMARY and CLIPBOARD
when sending data to server.
'CLIPBOARD' looks at only CLIPBOARD.
-0: attach to console
-4: use RDP version 4
-5: use RDP version 5 (default)
-y: use raw keyboard (default no)

2010年6月2日 星期三

簡易連線uart的程式

本來是想要把minicom搬到android上,不過他的source code很多,也蠻複雜的,
後來在網路上找到tick_minicom,只有幾個檔案,應該很容易讓他編進android

tick_minicom:簡單的uart程式
http://linuxocarina.blogspot.com/2007/09/minicom.html

不過我的連線設定跟他不一樣,所以參考以下網站對程式做了一些修改之後就可以使用了
http://book.51cto.com/art/200711/59758.htm



int
set_baud (int fd, int rate)
{
int i, rt;

u_int32_t bd = 0;

struct termios ti;

//select baudrate
for (i = 0; i < ARRAY_SIZE (bdrts); i++) {
if (bdrts[i].bps == rate) {
bd = bdrts[i].b;
debug("select baudrate: %d\n",rate);
break;
}
}
if (bd == 0) {
error ("Cannot set Baud Rate!!\n");
return -1;
}

//set baudrate
rt = tcgetattr (fd, &ti);
if (rt < 0) {
error ("Cannot get attr i=%d\n", rt);
return rt;
}

debug ("Open uart input with speed %d\n", bdrts[i].bps);
//rt = cfsetispeed (&ti, B0);
rt = cfsetispeed (&ti, bd);
if (rt < 0) {
//error ("Cannot set input baud to B0!!\n");
error ("Cannot set input baud to bd!!\n");
return rt;
}

debug ("Open uart output with speed %d\n", bdrts[i].bps);
rt = cfsetospeed (&ti, bd);
if (rt < 0) {
error ("Cannot set baud rate %d\n", bdrts[i].bps);
return rt;
}

rt=tcsetattr (fd, 0, &ti);
if(rt<0){
return rt;
}

//set no hareware conrtol
rt = tcgetattr (fd, &ti);
//ti.c_cflag |= CRTSCTS; // hardware control
ti.c_cflag &= ~CRTSCTS; // no hardware control
rt=tcsetattr (fd, 0, &ti);
if(rt<0){
return rt;
}


//set databit:8
rt = tcgetattr (fd, &ti);
ti.c_cflag&=~CSIZE;
ti.c_cflag |=CS8;
rt=tcsetattr (fd, 0, &ti);
if(rt<0){
return rt;
}


//set no parity bit
rt = tcgetattr (fd, &ti);
ti.c_cflag &= ~PARENB;
rt=tcsetattr (fd, 0, &ti);
if(rt<0){
return rt;
}


return rt;
}

解決ubuntu 10.04 中minicom放大到全螢幕會閃爍的問題

參考 http://blog.xuite.net/yctseng/notes/26134176

使用:
alias minicom='TERM=linux /usr/bin/minicom'



2010年5月31日 星期一

使用shell script計算CPU使用率

PROGRAM_NAME --程式名稱
DELAY ---------每隔多久看一次CPU usage
NUMBER --------總共看幾次


取得系統CPU使用率:
top -b -n NUMBER -d DELAY | tee top.log
cat top.log | grep CPU: | awk '{print $8}' | sed s/%//g

若要查看某程式的cpu使用率
cat top.log | grep -v grep | grep PROGRAM_NAME | awk '{print $7}'| sed s/%//g







example:
假設要看hello程式, 一分鐘內每隔一秒的CPU使用率:

top -b -n 60 -d 1 | grep -v grep | grep hello | awk '{print $7}'| sed s/%//g
輸出結果:
0
9
5
2
1
2
2
2
4
2
2
3
3
1
2
3
2
3
2
0
.....

2010年5月30日 星期日

腳踏車變速器/剎車調整

我是用:
SHIMANO TY-22中變速器
SHIMANO TOURNEY TX-31 FOR 21SPEED 後變速器
SHIMANO EF50上下按鍵式變把
SHIMANO MFTZ21 7速飛輪

中變:
1.在把手上有微調旋鈕,先調整至在中間那一檔能夠順利
往上下檔位切換
2.調整high/low螺絲限制最高與最低檔位的位置
至適當距離


後變:
1.微調旋鈕在後變上,調整至後變中間幾個檔位切換順暢
2.調整high/low螺絲限制後變最高與最低檔位的
位置至適當距離


剎車:
1.調整變速器上的微調旋鈕使剎車按壓的距離至適當位置
2.調整V型剎車組的彈簧微調螺絲使得兩邊彈力差不多,
剎車皮與輪圈之間距離相同

在linux下使用LFTP多點下載

參考 http://yurinfore.blogspot.com/2009/10/linux.html

改成可以控制下載thread數量
function pget()
{
thread=5

case $# in
1)
addr=$1
;;
2)
thread=$1
addr=$2
;;
*)
echo "usage:"
echo "pget [URL] (default thread:5)"
echo "or"
echo "pget [thread] [URL]"
exit 1
;;
esac


echo thread : $thread
echo address : $addr
cmd="pget -n $thread $addr; exit"
lftp -e "$cmd"
}