2007/12/17

NS2 快速入門: DV-distance 模擬 (5)

存取實體層

Reference: http://www.baisi.net/viewthread.php?tid=13936

節錄片段程式碼:
dv-distance/dv-distance.cc
[cpp]
int DV_DistanceAgent::command(int argc, const char*const* argv) {
Node* self_ = Node::get_node_by_address(addr());
printf("S: self->nodeid(): %d\n", self_->nodeid());
}

void DV_DistanceAgent::recv(Packet* pkt, Handler*) {
printf("Recv OK\n");

printf("R: pkt->txinfo_.getNode()->nodeid(): %d\n", pkt->txinfo_.getNode()->nodeid());
printf("R: txinfo_.getTxPr(): %.20lf\n", pkt->txinfo_.getTxPr());
printf("R: txinfo_.getLambda(): %.20lf\n", pkt->txinfo_.getLambda());
printf("R: txinfo_.RxPr: %.20lf\n", pkt->txinfo_.RxPr);
printf("R: distance: %.20lf\n", this->getDist(pkt));
}

double DV_DistanceAgent::getDist(Packet* pkt) const {
Antenna* ant = pkt->txinfo_.getAntenna();
WirelessPhy* phy = (WirelessPhy*)(pkt->txinfo_.getNode()->ifhead().lh_first);

double lambda = pkt->txinfo_.getLambda();
double Pr = pkt->txinfo_.RxPr;
double Pt = pkt->txinfo_.getTxPr();
double Gt = ant->getTxGain(ant->getX(), ant->getY(), ant->getZ(), lambda);
double Gr = ant->getRxGain(ant->getX(), ant->getY(), ant->getZ(), lambda);
double ht = ant->getZ();
double hr = ant->getZ();
double L = phy->getL();

return phy->getDist(Pr, Pt, Gt, Gr, ht, hr, L, lambda);
}
[/cpp]

2007/12/15

NS2 快速入門: DV-distance 模擬 (4)

先新增一個自訂的 Agent

之後在修改執行演算法的部份來跑自訂的 protocol

新增 Agent 的方法如下:

(附註: 這裡的 ns2 目錄是指 ns2 所在的目錄,每個人不一定一樣,
ex: ~/ns-allinone-2.33/ns-2.33)

ns2/dv-distance/dv-distance.h
[cpp]
#ifndef ns_dv_distance_h
#define ns_dv_distance_h

#include "agent.h"
#include "tclcl.h"
#include "packet.h"
#include "address.h"
#include "ip.h"

struct hdr_dv_distance {

// Header access method
static int offset_; // required by PacketHeaderManager
inline static int& offset() { return offset_; }
inline static hdr_dv_distance* access(const Packet* p) {
return (hdr_dv_distance*) p->access(offset_);
}
};

class DV_DistanceAgent : public Agent {
public:
DV_DistanceAgent();
virtual int command(int argc, const char*const* argv);
virtual void recv(Packet*, Handler*);
};

#endif // ns_dv_distance_h
[/cpp]

ns2/dv-distance/dv-distance.cc
[cpp]
#include "dv-distance.h"

int hdr_dv_distance::offset_;
static class DV_DistanceHeaderClass : public PacketHeaderClass {
public:
DV_DistanceHeaderClass() : PacketHeaderClass("PacketHeader/DV_Distance",
sizeof(hdr_dv_distance)) {
bind_offset(&hdr_dv_distance::offset_);
}
} class_dv_distancehdr;

static class DV_DistanceClass : public TclClass {
public:
DV_DistanceClass() : TclClass("Agent/DV_Distance") {}
TclObject* create(int, const char*const*) {
return (new DV_DistanceAgent());
}
} class_dv_distance;

DV_DistanceAgent::DV_DistanceAgent() : Agent(PT_DV_DISTANCE) {
//bind("packetSize_", &size_);
}

int DV_DistanceAgent::command(int argc, const char*const* argv) {
if(argc == 2) {
if(strcmp(argv[1], "start") == 0) {
// Create a new packet
Packet* pkt = allocpkt();

// Access the DV_Distance header for the new packet
hdr_dv_distance* hdr = hdr_dv_distance::access(pkt);

// Send the packet
send(pkt, 0);

// return TCL_OK, so the calling function knows that
// the command has been processed
return (TCL_OK);
}
}
return (Agent::command(argc, argv));
}

void DV_DistanceAgent::recv(Packet* pkt, Handler*) {
// Access the IP header for the received packet
hdr_ip* hdrip = hdr_ip::access(pkt);

// Access the DV_distance header for the received packet
hdr_dv_distance* hdr = hdr_dv_distance::access(pkt);

printf("Recv OK");
Packet::free(pkt);
}
[/cpp]

接著要把自訂的 Agent 加到 NS2 中

才能在 NS2 中使用

1. 修改 ns2/Makefile.in
在 OBJ_CC = 的地方加上 dv-distance/dv-distance.o
(注意:修改 Makefile 無效,Makefile 會在每次 configure 後依據 Makefile.in 產生)


2. 修改 ns2/common/packet.h 加上新的 packet type

ns 2.32 以前:
在 enum packet_t 加上 PT_DV_DISTANCE
(不能加在最後一個,PT_NTYPE 必須最後)

在 class p_info 的 public: p_info() { } 內
加上 name_[PT_DV_DISTANCE]="DV_Distance";

ns 2.33 以後:
在 static packet_t PT_NTYPE 前加上
static const packet_t PT_DV_DISTANCE = XX;
XX 為其他 packet type 沒用過的數字 (ex: 62)
(注意:一定要加在 PT_NTYPE 之前,且 PT_NTYPE 的 value 一定要最大,
否則發送 packet 時,會出現 Segmentation fault (core dumped) 無法正常運作)


在 class p_info 的 public: static void initName() { } 內
name_[PT_NTYPE]= "undefined"; 附近加上
name_[PT_DV_DISTANCE]="DV_Distance";
建議和加 PT_DV_DISTANCE 一樣
加在 name_[PT_NTYPE]= "undefined"; 之前


3. 修改 trace/cmu-trace.cc (非必要)

在 void CMUTrace::format(Packet* p, const char *why) {} 加上 case PT_DV_DISTANCE:

4. 修改 tcl/lib/ns-packet.tcl (非必要)
在 foreach prot { } 加上 DV_Distance
加這個是為了方便在模擬時
可以用下列方式寫在 tcl 內
只顯示想要觀察的 packet type

[code]remove-packet-header AODV ARP DV_Distance

# ...

set ns [new Simulator][/code]
[code]remove-all-packet-headers
add-packet-header AODV ARP DV_Distance

# ...

set ns [new Simulator][/code]

大功告成

開始編譯

1. 有改 Makefile.in 或 XXX.h 檔時
在 ns2 目錄下執行 ./configure; make clean; make depend; make

2. 只改 source code (XXX.cc 檔) 時
在 ns2 目錄下直接執行 make 就可以了

3. 只改 XXX.h 檔
如果不想等太久,可以 touch XXX.cc 後再 make
ex: touch dv-distance/dv-distance.cc; make
但不保證能正常運作

附註:若編譯時出現關於 proxytrace2any.cc 的錯誤,請參考這篇文章,以我的經驗如果是第一次編譯,2.32和2.33都會出現這個問題,可以先修改後再編譯,才不用花很久的時間重新編譯

2007/12/14

NS2 2.32 core dump when "make"

Problem:

Core dump message as follows:

NS2 2.32 make error with "proxytrace2any.cc"

Problem: NS2 2.32 make error with "proxytrace2any.cc"


proxytrace2any.cc: In function `int main(int, char**)':
proxytrace2any.cc:112: error: `IsLittleEndian' undeclared (first use this function)
proxytrace2any.cc:112: error: (Each undeclared identifier is reported only once for each function it appears in.)
proxytrace2any.cc:120: error: `ToOtherEndian' undeclared (first use this function)
make[1]: *** [proxytrace2any.o] Error 1
make[1]: Leaving directory `/home/sokoyo/ns-allinone-2.32/ns-2.32/indep-utils/webtrace-conv/dec'
make[1]: Entering directory `/home/sokoyo/ns-allinone-2.32/ns-2.32/indep-utils/webtrace-conv/epa'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/home/sokoyo/ns-allinone-2.32/ns-2.32/indep-utils/webtrace-conv/epa'
make[1]: Entering directory `/home/sokoyo/ns-allinone-2.32/ns-2.32/indep-utils/webtrace-conv/nlanr'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/home/sokoyo/ns-allinone-2.32/ns-2.32/indep-utils/webtrace-conv/nlanr'
make[1]: Entering directory `/home/sokoyo/ns-allinone-2.32/ns-2.32/indep-utils/webtrace-conv/ucb'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/home/sokoyo/ns-allinone-2.32/ns-2.32/indep-utils/webtrace-conv/ucb'



Solution: Modify file "ns-allinone-2.32/ns-2.32/indep-utils/webtrace-conv/dec/my-endian.h"

-#ifndef _ENDIAN_H_
-#define _ENDIAN_H_
+#ifndef _MY_ENDIAN_H_
+#define _MY_ENDIAN_H_


...

2007/12/13

NS2 快速入門: DV-distance 模擬 (3)

節錄使用 Hierarchical Addressing 片段

參考
ns-2/tcl/test/test-suite-WLtutorial.tcl
ns-2/tcl/test/test-suite-wireless-lan-aodv.tcl
ns-2/tcl/test/test-suite-wireless-lan-tora.tcl

case 1
[code]
$ns node-config -wiredRouting OFF

$ns node-config -addressType hierarchical
AddrParams set domain_num_ 2
lappend cluster_num 1 2
AddrParams set cluster_num_ $cluster_num
lappend eilastlevel 1 2 2
AddrParams set nodes_num_ $eilastlevel

set n0 [$ns node 0.0.0]
$n0 random-motion 0
$n0 set X_ 301
$n0 set Y_ 399
$n0 set Z_ 0.0
$ns initial_node_pos $n0 20
set n1 [$ns node 1.0.0]
$n1 random-motion 0
$n1 base-station [AddrParams addr2id [$n0 node-addr]]
$n1 set X_ 480
$n1 set Y_ 544
$n1 set Z_ 0.0
$ns initial_node_pos $n1 20
[/code]

case 2
[code]
puts "Hierarchical Routing..."
set naddr {0.0.0 \
0.0.1 \
0.0.2 \
0.0.3 \
0.0.4 \
0.0.5 \
0.0.6 \
0.0.7 \
0.0.8 \
0.0.9 \
0.0.10 \
0.0.11 \
0.0.12 \
0.0.13 \
0.0.14 \
0.0.15 \
0.0.16 \
0.0.17 \
0.0.18 \
0.0.19}

# Create 20 nodes
for {set i 0} {$i < $opt(nn)} {incr i} {
set node($i) [$ns node [lindex $naddr $i]]
$node($i) random-motion 0
$node($i) base-station [AddrParams addr2id [$node(0) node-addr]]
}
[/code]

2007/12/11

NS2 快速入門: DV-distance 模擬 (2)

第一個可正常使用 DSR, DSDV, AODV Routing 的 Wireless Simulation

參考 ns-2/tcl/test/test-suite-WLtutorial.tcl
參考網址 http://www.net.c.dendai.ac.jp/~yuuki/

如果要使用 DSDV

記得 Application 啟動的時間要比較晚

因為 DSDV 要建立好 routing table

花的時間比較久

routing-test.tcl
[code]
#===================================
# Simulation parameters setup
#===================================
set opt(chan) Channel/WirelessChannel ;# channel type
set opt(prop) Propagation/TwoRayGround ;# radio-propagation model
set opt(netif) Phy/WirelessPhy ;# network interface type
set opt(mac) Mac/802_11 ;# MAC type
set opt(ifq) Queue/DropTail/PriQueue ;# interface queue type
set opt(ll) LL ;# link layer type
set opt(ant) Antenna/OmniAntenna ;# antenna model
set opt(ifqlen) 50 ;# max packet in ifq
set opt(nn) 20 ;# number of mobilenodes
set opt(rp) DSDV ;# routing protocol
set opt(x) 700 ;# X dimension of topography
set opt(y) 550 ;# Y dimension of topography
set opt(stop) 150.0 ;# time of simulation end
set opt(cp) "cbr-test.tcl"
set opt(sc) "scen-test.tcl"

#===================================
# Initialization
#===================================

# Create a ns simulator
set ns [new Simulator]

# Setup topography object
set topo [new Topography]
$topo load_flatgrid $opt(x) $opt(y)
set god [create-god $opt(nn)]

# Open the NS trace file
$ns use-newtrace
set tracefile [open out.tr w]
$ns trace-all $tracefile

# Open the NAM trace file
set namfile [open out.nam w]
$ns namtrace-all $namfile
$ns namtrace-all-wireless $namfile $opt(x) $opt(y)

#===================================
# Mobile node parameter setup
#===================================
if {$opt(rp) == "DSR"} {
set opt(ifq) CMUPriQueue
} else {
set opt(ifq) Queue/DropTail/PriQueue
}

$ns node-config -adhocRouting $opt(rp) \
-llType $opt(ll) \
-macType $opt(mac) \
-ifqType $opt(ifq) \
-ifqLen $opt(ifqlen) \
-antType $opt(ant) \
-propType $opt(prop) \
-phyType $opt(netif) \
-channel [new $opt(chan)] \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \
-movementTrace ON

#===================================
# Nodes Definition
#===================================

# Create 20 nodes
for {set i 0} {$i < $opt(nn)} {incr i} {
set node($i) [$ns node]
$node($i) random-motion 0
}

puts "Loading scenario file..."
source $opt(sc)

for {set i 0} {$i < $opt(nn)} {incr i} {
$ns initial_node_pos $node($i) 20
}

#===================================
# Agents & Applications Definition
#===================================

puts "Loading connection pattern..."
source $opt(cp)

#===================================
# Termination
#===================================

# Define a 'finish' procedure
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile

puts "running nam..."
exec nam out.nam &
exit 0
}
for {set i 0} {$i < $opt(nn)} {incr i} {
$ns at $opt(stop) "$node($i) reset"
}
$ns at $opt(stop) "$ns nam-end-wireless $opt(stop)"
$ns at $opt(stop) "finish"
$ns at $opt(stop) "puts \"done\" ; $ns halt"

puts "Starting Simulation..."
$ns run
[/code]

cbr-test.tcl
[code]
#===================================
# Agents Definition
#===================================

# Setup a TCP connection
set tcp [new Agent/TCP]
$ns attach-agent $node(15) $tcp
set sink [new Agent/TCPSink]
$ns attach-agent $node(4) $sink
$ns connect $tcp $sink

#===================================
# Applications Definition
#===================================

set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ns at 120.0 "$ftp start"
[/code]

scen-test.tcl
[code]
#===================================
# Nodes Definition
#===================================
set god [God instance]
#$god set-dist 15 16 1 ;# node 15 <--> node 16 : 2 hop
#$god set-dist 16 17 1 ;# node 15 <--> node 17 : 2 hop
#$god set-dist 17 18 1 ;# node 15 <--> node 16 : 2 hop


$node(0) set X_ 0
$node(0) set Y_ 600
$node(0) set Z_ 0.0

$node(1) set X_ 200
$node(1) set Y_ 600
$node(1) set Z_ 0.0

$node(2) set X_ 400
$node(2) set Y_ 600
$node(2) set Z_ 0.0

$node(3) set X_ 600
$node(3) set Y_ 600
$node(3) set Z_ 0.0

$node(4) set X_ 800
$node(4) set Y_ 600
$node(4) set Z_ 0.0

$node(5) set X_ 0
$node(5) set Y_ 400
$node(5) set Z_ 0.0

$node(6) set X_ 200
$node(6) set Y_ 400
$node(6) set Z_ 0.0

$node(7) set X_ 400
$node(7) set Y_ 400
$node(7) set Z_ 0.0

$node(8) set X_ 600
$node(8) set Y_ 400
$node(8) set Z_ 0.0

$node(9) set X_ 800
$node(9) set Y_ 400
$node(9) set Z_ 0.0

$node(10) set X_ 0
$node(10) set Y_ 200
$node(10) set Z_ 0.0

$node(11) set X_ 200
$node(11) set Y_ 200
$node(11) set Z_ 0.0

$node(12) set X_ 400
$node(12) set Y_ 200
$node(12) set Z_ 0.0

$node(13) set X_ 600
$node(13) set Y_ 200
$node(13) set Z_ 0.0

$node(14) set X_ 800
$node(14) set Y_ 200
$node(14) set Z_ 0.0

$node(15) set X_ 0
$node(15) set Y_ 0
$node(15) set Z_ 0.0

$node(16) set X_ 200
$node(16) set Y_ 0
$node(16) set Z_ 0.0

$node(17) set X_ 400
$node(17) set Y_ 0
$node(17) set Z_ 0.0

$node(18) set X_ 600
$node(18) set Y_ 0
$node(18) set Z_ 0.0

$node(19) set X_ 800
$node(19) set Y_ 0
$node(19) set Z_ 0.0
[/code]

2007/12/06

Proxy.pac example

最近常常連不到某些網站

不知道是哪裡擋掉

或是能 login 的連線有限

所以利用跳板就很重要啦 XD

紀錄一下 proxy.pac 的寫法如下:

[code]
function FindProxyForURL(url, host)
{
if (dnsDomainIs(host, "study-area.org"))
return "PROXY proxy.teatime.com.tw:8080";
else if(dnsDomainIs(host, "ieee.org"))
return "PROXY b.com:8080";
else
return "DIRECT";
}
[/code]

2007/12/05

Windows XP 安全性設定

Windows XP 在 "資料夾選項" 取消 "使用簡易檔案共用 (建議使用)" 後

會多出安全性的設定

然而 Windows XP 的安全性控制非常的爛

啟用後常常會出現不能存取某些檔案的怪問題

這裡紀錄最基本的安全性設定

如果安全性跑掉了

就重新照下面的方法設定吧

目前試過暫時還沒遇到問題

ps: 請使用進階設定

C:\ (系統碟) 設定:

[權限]
取消 "從父項繼承套用到子物件的權限項目,包括明確定義於此的項目"

權限項目:
Administrators
- 套用在 "這個資料夾,子資料夾及檔案"
- "完全控制"
- 取消 "套用這些權限到此容器中的物件及(或)容器"
CREATOR OWNER
- 套用在 "只有子資料夾及檔案"
- "完全控制"
- 取消 "套用這些權限到此容器中的物件及(或)容器"
Everyone
- 套用在 "只有這個資料夾"
- "周遊資料夾/執行檔案", "列出資料夾/讀取資料", "讀取屬性", "讀取擴充屬性", "讀取使用權限"
- 取消 "套用這些權限到此容器中的物件及(或)容器"
SYSTEM
- 套用在 "這個資料夾,子資料夾及檔案"
- "完全控制"
- 取消 "套用這些權限到此容器中的物件及(或)容器"
Users
- 套用在 "這個資料夾,子資料夾及檔案"
- "周遊資料夾/執行檔案", "列出資料夾/讀取資料", "讀取屬性", "讀取擴充屬性", "讀取使用權限"
- 取消 "套用這些權限到此容器中的物件及(或)容器"
Users
- 套用在 "這個資料夾及子資料夾"
- "建立資料夾/附加資料"
- 取消 "套用這些權限到此容器中的物件及(或)容器"
Users
- 套用在 "只有子資料夾"
- '建立檔案/寫入資料"
- 取消 "套用這些權限到此容器中的物件及(或)容器"
[擁有者]
Administrators

C:\WINDOWS (Windows 系統檔案目錄,注意若設定出錯,重開機後會無法進入 Windows) 設定:

[權限]
取消 "從父項繼承套用到子物件的權限項目,包括明確定義於此的項目"

權限項目:
Administrators
- 套用在 "這個資料夾,子資料夾及檔案"
- "完全控制"
- 取消 "套用這些權限到此容器中的物件及(或)容器"
CREATOR OWNER
- 套用在 "只有子資料夾及檔案"
- "完全控制"
- 取消 "套用這些權限到此容器中的物件及(或)容器"
Power Users
- 套用在 "這個資料夾,子資料夾及檔案"
- 先選取"完全控制"後,取消"完全控制", "刪除子資料夾及檔案", "變更使用權限", "取得擁有權"
- 取消 "套用這些權限到此容器中的物件及(或)容器"
SYSTEM
- 套用在 "這個資料夾,子資料夾及檔案"
- "完全控制"
- 取消 "套用這些權限到此容器中的物件及(或)容器"
Users
- 套用在 "這個資料夾,子資料夾及檔案"
- "周遊資料夾/執行檔案", "列出資料夾/讀取資料", "讀取屬性", "讀取擴充屬性", "讀取使用權限"
- 取消 "套用這些權限到此容器中的物件及(或)容器"
[擁有者]
Administrators

其他硬碟 (ex: D:\) 設定:

[權限]
取消 "從父項繼承套用到子物件的權限項目,包括明確定義於此的項目"

[權限]
取消 "從父項繼承套用到子物件的權限項目,包括明確定義於此的項目"

權限項目:
Administrators
- 套用在 "這個資料夾,子資料夾及檔案"
- "完全控制"
- 取消 "套用這些權限到此容器中的物件及(或)容器"
CREATOR OWNER
- 套用在 "只有子資料夾及檔案"
- "完全控制"
- 取消 "套用這些權限到此容器中的物件及(或)容器"
Everyone
- 套用在 "這個資料夾,子資料夾及檔案"
- "周遊資料夾/執行檔案", "列出資料夾/讀取資料", "讀取屬性", "讀取擴充屬性", "讀取使用權限"
- 取消 "套用這些權限到此容器中的物件及(或)容器"
SYSTEM
- 套用在 "這個資料夾,子資料夾及檔案"
- "完全控制"
- 取消 "套用這些權限到此容器中的物件及(或)容器"
Users
- 套用在 "這個資料夾,子資料夾及檔案"
- "周遊資料夾/執行檔案", "列出資料夾/讀取資料", "讀取屬性", "讀取擴充屬性", "讀取使用權限"
- 取消 "套用這些權限到此容器中的物件及(或)容器"
Users
- 套用在 "這個資料夾及子資料夾"
- "建立資料夾/附加資料"
- 取消 "套用這些權限到此容器中的物件及(或)容器"
Users
- 套用在 "只有子資料夾"
- '建立檔案/寫入資料"
- 取消 "套用這些權限到此容器中的物件及(或)容器"
[擁有者]
Administrators

Present 的論文內容

明顯有類似 protocol 這類的 paper

不要選實驗、理論推導

看看有沒有類似第一步、第二步 ... 的結構

主要是要融會貫通講精髓

讓大家知道一個流程

如果是用數學 model 來推導

難懂又不好講

著重找到該文主要突破點, 並找出該突迫所以能達成的 smart ideas, key techniques。

結論:
1. What are the important considerations in the special topic of research (與以前從相關論文所得心得相互驗証, 校正, 並總結)?
2. What are the existing approaches for the special topic of research?
3. What are their relative merits (優點) and disadvantages?
4. If this paper has any relative merits, how are they achieved?
5. If the paper has any disadvantages, what are the causes for them?
6. How to avoid such shortages in your proposed approach?
7. If they are unavoidable, what are the reasons for?

2007/12/04

NS2 快速入門: DV-distance 模擬 (1)

寫 Tcl 檔產生節點、座標和設定環境

NS2 快速入門: DV-distance 模擬 (0)

0. 先了解 DV-distance

論文:D. Niculescu and B. Nath. Ad Hoc Positioning System (APS). In Proceedings of IEEE GlobeCom, San Antonio, AZ, November 2001.

定位 protocol,屬於 Application Layer

DV-hop
1. 先使用 distance vector 交換到網路所有 node,以取得到 landmark 的 hop 距離
2. 每個 node 維護一個 table 包含 (X, Y, h) 只從 neighbor 更新,(X, Y) 為 landmark 的位置, h 為 hop count
3. 只要 landmark 收到到其他 landmark 的距離,就估計平均一個 one hop 的距離,接著廣播發佈一個 correction 通知到整個網路
4. 接收到 correction 的節點,會在可以用三角測量時,估計到 landmark 的距離
5. 接收到 correction 的節點,以第一個收到的 correction 為準

每個 landmark 計算 The correction a landmark (Xi, Yi) ci, 一個 hop 的平均距離,以公尺為單位

每個 landmark 知道與其他 landmark 間的 hop count 與 euclidean distance

flooding 時,forward 一個 correction 後,會 drop 隨後的同一個 correction,
以確保每個 node 只會收到一個 correction,從最近的 landmark

可以用封包 TTL 限制一個 node 收到的 landmark 數

DV-distance

和 DV-hop 相同只是與鄰居 node 間的距離用訊號強度而不是 hop count,以公尺為單位
distance vector algorithm 使用訊號強度來累計旅行的距離


1. 要撰寫 NS2 模擬需要了解的步驟


TCL 相關
- 如何產生節點和座標
- 如何使用 protocol

C++ 相關
- 如何產生自訂的 protocol
- C++ 和 TCL 間的關係
- 如何在 NS2 內用個 table (structure)
- 如何從點 A 傳資料到點 B
- 如何從點 A flooding 資料出去
- 如何用 RSSI 估計兩點間的距離
- 如何改封包 TTL 的位置

2007/11/30

[C++] Finding Square Root without using sqrt()

不用 sqrt 函式自己寫開根號的 code

http://www.dreamincode.net/code/snippet244.htm

[cpp]
/* Code written by Sanchit Karve
A.K.A born2c0de
Contact Me at born2c0de AT hotmail.com

20 August, 2005

*/




#include
#include

using namespace std;


float sqroot(float m)
{
float i=0;
float x1,x2;
while( (i*i) <= m )
i+=0.1;
x1=i;
for(int j=0;j<10;j++)
{
x2=m;
x2/=x1;
x2+=x1;
x2/=2;
x1=x2;
}
return x2;
}

int main()
{
cout << "Enter a Number:";
int no;
cin >> no;
cout << "Square Root using sqroot()= " << sqroot(no) < << "Square Root using sqrt() = " << sqrt(no);

return 0;
}

[/cpp]

2007/11/23

Visual Studio 2005 更換 Project 位置後問題

移動 VS 2005 Project 檔案位置後

無法正常執行可能原因是因為檔案位置改變

導致中斷點失敗

說明在這裡 http://msdn2.microsoft.com/zh-tw/library/h6aesyw2(VS.80).aspx

可能解決方法有三種

1.
工具 -> 選項 -> 偵錯 -> 一般 -> 取消[原始程式檔必須完全符合原始版本]

2.
偵錯 -> 刪除所有中斷點

3.
在中斷點上按右鍵選位置

或是

打開中斷點視窗(偵錯 -> 視窗 -> 中斷點),同樣在中斷點按右鍵選位置

一個一個修改[檔案]位置



選取[允許原始程式碼與原始版本不同]

2007/11/22

2007/11/11

上班族新修練3:迎戰外在環境劇變之敏銳力(Power of Agility)

http://news.yam.com/view/mkmnews.php/384975

上班族新修練2:創造十倍的溝通熱力之上台說話技巧

http://news.yam.com/view/mkmnews.php/384974

上班族新修練:先處理心情,再處理事情(顧客抱怨管理)

http://blog.career.com.tw/managing/communication_content.aspx?na_id=274&na_toolid=405

11件事人生中必做的事,張忠謀線上告訴你

http://news.yam.com/view/mkmnews.php/544445

開拓社交圈的行動方案

http://news.yam.com/view/mkmnews.php/460169

新手上路必修5堂課 別當老闆的眼中釘

http://tw.news.yahoo.com/marticle/url/d/a/071003/25/lpeg.html?type=old

夜貓上班族,精力衝衝衝 (想睡怎麼辦?)

http://tw.news.yahoo.com/marticle/url/d/a/071003/25/lped.html?type=old

精準管理,資訊吸收超效率

http://tw.news.yahoo.com/marticle/url/d/a/071003/25/lpec.html?type=old

2007/11/06

Note of controlling SVN(Subversion)

1. Create repository:

Subversion provides two options for the type of underlying data store that each repository uses.
See the comparison in here or http://svnbook.org/


shell> mkdir /home/svn/repos
shell> svnadmin create --fs-type fsfs /home/svn/repos



The Subversion Repository, Defined in here


conf

A directory containing repository configuration files.

dav

A directory provided to mod_dav_svn for its private housekeeping data.

db

The data store for all of your versioned data.

format

A file that contains a single integer that indicates the version number of the repository layout.

hooks

A directory full of hook script templates (and hook scripts themselves, once you've installed some).

locks

A directory for Subversion's repository lock files, used for tracking accessors to the repository.

README.txt

A file whose contents merely inform its readers that they are looking at a Subversion repository.



2. Import data:

See the "Planning Your Repository Organization" to decide how to organize your projects with respect to repositories.
Your first decision is whether to use a single repository for multiple projects, or to give each project its own repository, or some compromise of these two.


shell> svn import /home/svn/tmp/ file:///home/svn/repos/ -m "Initial Import"



3. Show repository:


shell> svn list -v file:///home/svn/repos/
shell> svnlook info --revision 1 /home/svn/repos/
shell> svnlook tree /home/svn/repos/ --show-ids



4. Invoking server

shell> svnserve -d --listen-port 3690 -r /home/svn




Reference:
http://www-128.ibm.com/developerworks/cn/java/j-lo-apache-subversion/index.html
http://svnbook.red-bean.com/en/1.4/index.html

Using GATOS on My "ATI Technologies Inc Rage 128 RF/SG AGP" card

Using GATOS on My "ATI Technologies Inc Rage 128 RF/SG AGP" card

gatos-conf

RAM on Card: 32Mb
Gatos will Probe RAM
864kb for PAL/SECAM
Gatos autodection
NTSC North/South American Cable (CATV)

舊 BIOS 使用 Ubuntu 無法關機 (無法開啟APM, ACPI)

舊 BIOS 使用 Ubuntu 無法關機 (無法開啟APM, ACPI)

開啟 ACPI:
在 grub/menu.lst 的 kernel 加上 acpi=force

開啟 APM:
在 /etc/modules 加上 apm power_off=1

擇一即可。

2007/11/05

Tor (anonymity network)

http://www.torproject.org/
http://en.wikipedia.org/wiki/Tor_%28anonymity_network%29

Tor (The Onion Router) is a free software implementation of second-generation onion routing – a system enabling its users to communicate anonymously on the Internet.

2007/11/04

上班就是這樣?

1.never do job at non-duty time

上班的時候 就是做事
下班的時候 完全不會去想碰上班在做的事

2.quiet listening

你跟我說的這些我都知道 可是我還是會安靜地聽完
因為這樣可以消耗上班的時間

3.non-last status

當你發現你不是最菜的時候 你所受的壓力會大幅減少
而且會覺得相當的輕鬆 尤其是最菜的傢伙快到30歲的時候

4.future mirror

跟資深人員共事過後 你會希望(或害怕)未來像這位員工一樣的好...(或壞)

5.long-used devices

希望公司願意花錢買一套新的鍵盤跟滑鼠發給我用
也希望當試用期結束後把桌上的CRT換成LCD

6.discounting sales

感謝公司讓我喝便宜的可口可樂 我不會奢望有提供免費的
但是可以順便提供一下公仔和日文雜誌的折扣販賣服務嗎?

7. early-waked freak

當我說我晚上11點半睡覺 早上7點半起床的時候
請不要用很驚訝的表情問說我家是不是種田的...

想加薪升遷 四大撇步

http://pro.udnjob.com/mag2/hr/storypage.jsp?f_ART_ID=31430

應徵的最好時機

6 7 8月因為學生的畢業潮 工作會比較難找 價錢會比較普通

到了9 10月後談價錢對應徵方是較好的 因為公司會急著找人補需要有人來做的職位

11月之後公司真的就是用挑的再挑應徵者

隔年的過年前又會有一波離職潮 大家都想要換份好的工作

12月到隔年的2月 又是一個找工作的高峰期 價錢是看應徵方的資歷而定 各談各的

沒有普遍的行情

2007/10/05

Ajax不只是炫技

http://www.ithome.com.tw/itadm/article.php?c=44009

[WebSite] C/C++ Reference

C/C++ Reference

File Control in C

File Open

FILE *fp;
fp = fopen("FileName" , "Mode");
/* 失敗 return NULL */

Mode
w ... 只可寫入,覆寫
r ... 只可讀取
a ... 只可附加資料在此檔之後
b ... 只可讀取 binary 類型 file
r+ ... 可讀取與寫入
w+ ... 可讀取、覆寫
a+ ... 可讀取、附加資料在此檔之後


/* 以下成功 return 0 ,失敗 return EOF 即 -1 */

File Close

fclose(fp);


fgetc、fputc

File *fp2 = fopen("FileName2.txt","w");
int c;
while ( (c = fgetc(fp /* stdin */)) != EOF) /* 讀取一個字元並傳回 */
fputc(c, fp2 /* stdout */); /* 將字元 c 寫入檔案 */


fscanf、fprintf

fscanf(FILE *stream, const char *format, ...);
/* 用法同 scanf(),但讀取的資料改成來自 stream */
fprintf(FILE *stream, const char *format, ...);
/* 用法同 printf(),但寫入的資料改成寫到 stream */

ex:
fscanf(stdin,"%d",fp); /* 讀 stdin 寫 fp */
fprintf(fp,"%d",stdout); /* 讀 stdout 寫 fp */


/* 以下傳回所讀資料的筆數,若失敗傳回值為 0 */

fread、fwrite

char buf[128];
while ( (size = fread(buf, sizeof(char), sizeof(buf), fp_in) ))
fwrite(buf, sizeof(char), size , fp_out) ;

/* 從檔案 fp_in 讀取資料,一次讀取資料大小為 sizeof(char) 的物件
sizeof(buf) 個,並且將讀到的資料存放到 buf 這個暫存區,將 buf
所存的資料大小為 sizeof(char) 的物件 size 個,寫入檔案 fp_out */



fgets、fputs

char s[128]

fgets(s, n, fp);
/* 由 fp 讀入 n-1 個字元, 儲存到 s 的位址,正
確 return *s , 錯誤或檔案結束 return NULL */


fputs(s, fp);
/* fputs() 將字串輸出至 fp 成功 return
最後一個輸出的字元, 否則 return EOF */

2007/09/21

[TeX/LaTeX] NS2 Documentation's page number problem

Edit "ns-daily-2.31/ns-2/doc/basic.tex" as follows for correct page number



-\chapter{Introduction}
+\chapter{Introduction}\setcounter{page}{12}



The number 12 is the correct page number for the manual on September 20, 2007

2007/09/11

Using Sluice on Tmote Sky

Sluice: Secure Dissemination of Code Updates in Sensor Networks
Source code
Author's research website

0. Install Moteiv’s Tmote Tools from http://www.moteiv.com/

1. Extract file "sluice-tinyos.tgz" and move sub-directory "contrib" to "C:\cygwin\opt\tinyos-1.x\contrib"

2. Change file "/opt/tinyos-1.x/contrib/cmu/tools/java/jars/bcprov-jdk15-130.jar" to latest version if you need from here. (I use "bcprov-jdk16-137.jar" for this note.)

3. Set up environment variables as follows:
[code]export LD_LIBRARY_PATH=".:$LD_LIBRARY_PATH"
export TOSROOT="/opt/tinyos-1.x"
export TOSDIR="$TOSROOT/tos"
export MAKERULES="$TOSROOT/tools/make/Makerules"
export CLASSPATH="`$TOSROOT/tools/java/javapath`;C:\\\\cygwin\\\\opt\\\\tinyos-1.x\\\\contrib\\\\cmu\\\\tools\\\\java;C:\\\\cygwin\\\\opt\\\\tinyos-1.x\\\\contrib\\\\cmu\\\\tools\\\\java\\\\jars\\\\bcprov-jdk16-137.jar"
export SLUICE_PRIV_KEYFILE="c:\\\\cygwin\\\\opt\\\\tinyos-1.x\\\\contrib\\\\cmu\\\\tools\\\\java\\\\eccPrivate.key"[/code]

4. Modify files "/opt/tinyos-1.x/contrib/cmu/tos/lib/Sluice/DelugePageTransferC.nc" and "/opt/tinyos-1.x/contrib/cmu/tos/lib/Sluice/DelugePageTransferM.nc" about token "SharedMsgBufTX" and "SharedMsgBufRX" by refer to files " /opt/moteiv/tos/lib/Deluge/DelugePageTransferC.nc" and "/opt/moteiv/tos/lib/Deluge/DelugePageTransferM.nc"

5. Modify files "/opt/tinyos-1.x/contrib/cmu/tos/lib/Sluice/VerifierM.nc" as follows:




...

command uint8_t Verifier.verify(uint8_t *msg_ptr, uint16_t msg_len, NN_DIGIT *r_ptr, NN_DIGIT *s_ptr) {

...

if (post VerifyTask()) {
-#if 1
+#if PLATFORM_PC
dbg(DBG_USR2, "[Verifier.verify] info: posted VerifyTask\n");
dbg_clear(DBG_USR2, "\tr: 0x");
print_nn(r, DBG_USR2);
dbg_clear(DBG_USR2, "\n\ts: 0x");
print_nn(s, DBG_USR2);
dbg_clear(DBG_USR2, "\n");
#endif
return SUCCESS;
} else {

...

}
}

...




6. Change to directory "/opt/tinyos-1.x/contrib/cmu/apps/Sluice" and make as follows:
[code]make tmote install[/code]

7. Change to directory "/opt/tinyos-1.x/contrib/cmu/tools/java/net/tinyos/sluice" and "/opt/tinyos-1.x/contrib/cmu/tools/java/net/tinyos/tools" and complie all java files

8. Set up environment variables of "MOTECOM" for the Tmote Sky. for example:
[code]export MOTECOM=serial@COM6:tmote[/code]

9. Now, you can run "java net.tinyos.tools.Sluice" for testing.

Note: the source seems only implement function "inject".

for a example:

10. Change to directory "/opt/moteiv/apps/Count/CountLed" and Modify
file "/opt/moteiv/apps/Count/CountLed/Makefile" as follows:



COMPONENT ?= CountLedsC
CFLAGS += -I..

+PFLAGS += -DVERIFY_TIME=25 -I$(TOSROOT)/contrib/cmu/tos/lib/Sluice -I$(TOSROOT)/contrib/cmu/tos/lib/SHA1 -I$(TOSROOT)/contrib/ncsu/tos/lib/TinyECC
+TINYOS_NP ?= BNP

include $(MAKERULES)




11. And then make as follows:
[code]make tmote[/code]

12. Change to directory "/opt/moteiv/apps/Count/CountLeds/build/tmote" and "inject to image 1" as follows:
[code]java net.tinyos.tools.Sluice -i -in=1 -ti=tos_image.xml[/code]

2007/09/10

BackTrack: Penetration Testing

BackTrack is the most Top rated linux live distribution focused on penetration testing. With no installation whatsoever, the analysis platform is started directly from the CD-Rom and is fully accessible within minutes

BackTrack Wiki.
remote-exploit.org

2007/09/01

研究觀念

在實驗室最重要的事情是你自己要分配自己的時間,什麼時候念
paper什麼時候寫程式時麼時候打球運動,每天早上起床其實早點起來可以做很多事情
早上就可以先想一下今天要做哪些事情,做完了就可以去爽了

沒事多待在實驗室大家的感情其實也會比較好,不然就是多多聚餐

重點就是paper一開始一定要看的多,或是直接看老板上課有一本wireless sensor的書,
他有很多層的介紹與paper的整理,你看看你對哪的方面有興趣的就可以翻後面的目錄自己
去看看,然後有興趣了以後大概就專心的抓差不多20篇左右的paper但是這中間大概會有
垃圾或是奇怪的paper重點就是你看完了以後想一個方法很爛沒有關係但是你要讓老闆知
道你有看了很多這類的paper,可能一開使老闆會一直打你槍,但是一定要堅持到最後如
果那個是你的興趣的話,老闆就會妥協了

每次跟老闆的 meeting很重要,千萬不要有那種得過且過的想法
因為老闆已經去清大了,所以以後你們能跟他meeting的時間要是錯過了可能就要自己去
清大找老師,因為每次的討論時間就是一個對你的方法再更近一步的探討

寫模擬的大概要再12月以前搞懂NS2再衝三小,然後自己可以先針對自己的想法先偷寫,然
後多看google,而且你們除了要寫自己的方法,也要
寫人家的方法要跟人家比較,所以NS2工具的使用特別的重要,另外如果你到超熟的話可以
去PTT去接寫NS2模擬的case很賺,另外NS2可以問問看張育嘉學長,不知是誰嗎? 就是天
天在後面張嘴打電動的那個,他NS2 星海 還有魔獸都蠻厲害的

如果你是實作的請多多加強自己的心臟能力還有程式解bug的能力,我是實作
的常常實驗的結果會不是你想像的,因為變數太多了,所以有的時候方法想完實做了還要常
常修正你的方法,記得要多多跟同學討論,才會有多一些想法,常常我有很多不是我預期
的實驗錯誤或是不明的原因我都會找伯權或是rocky討論,這個很重要它可以幫助你有更
多的想法,在這個過程中你也會發現很多問題以及對應的解決方法,這次的口試教授問的
問題其實再我平常實作的時候就有發生過,還回答的蠻順利的,所以記得在口試前要對自
己的論文極度清楚,還有衍生的問題這些都是可以先在跟老師 meeting 與 實作中發現,如果
到了口試的時候才被委員問出來,那個場面會很難看而且老闆能幫你檔一時,沒有辦法檔全
部,當然如果你們還有其他作研究的問題可以多問問看博班或是我們學長,我們會很樂意
跟你們說的

另外老師的話不用聽的太認真,有的時候它只是講爽的而已,只要對得起
自己問心無愧就可以了

2007/08/29

Change radio transmit power and frequency on Tmote

http://www.moteiv.com/community/Change_radio_transmit_power_and_frequency

---Backup the article

Change frequency at compile time

One way to set the CC2420 radio channel is to do it at compile time by assigning the environment variable CC2420_CHANNEL perhaps like this

export CC2420_CHANNEL=12

The valid channels for the CC2420 are 11 to 26, and the default is channel 11. You can put that export command in your login script such as ~/.bashrc to make it persistent across login sessions. If you want a radio channel specific to an application, you can put a similar command in that application's Makefile, like this

CC2420_CHANNEL=12

The next time you build your application, the changes will take effect. Do not forget to also recompile and reinstall TOSBase with the new channel, as well, if applicable.

Change transmit power at compile time

To change the transmit power at compile time, you will need to predefine a preprocessor directive called CC2420_DEF_RFPOWER. To do this, define your compile flags "CFLAGS" before compiling your application. You must specify a power index from 1 to 31. The valid values are 1 through 31 with power of 1 equal to -25dBm and 31 equal to max power (0dBm)

CFLAGS=-DCC2420_DEF_RFPOWER=x make tmote

Change transmit power or frequency at run time

Another way to set the CC2420 radio channel or transmit power is to use the CC2420Control interface provided by the CC2420RadioC component. The two applicable commands are

command result_t TunePreset( uint8_t rh, uint8_t channel );
command result_t SetRFPower( uint8_t rh, uint8_t power );

rh
Either RESOURCE_NONE for automatic resource scheduling or a resource handle acquired by the CC2420ResourceC component. Note, this parameter is not present in any of the commands in the TinyOS 1.x CC2420Control interface

channel
One of the valid 802.15.4 present channels. Valid channel values are 11 through 26. The channel frequencies are calculated by

Freq = 2405 + 5(k-11) MHz for k = 11,12,...,26

power
A power index from 1 to 31. The input value is simply an arbitrary index that is programmed into the CC2420 registers. The output power is set by programming the power amplifier. The valid values are 1 through 31 with power of 1 equal to -25dBm and 31 equal to max power (0dBm)

2007/08/28

The Big Ol' Ubuntu Security Resource

http://www.itsecurity.com/features/ubuntu-secure-install-resource


Watch video in Ubuntu

1. Add new repository following http://medibuntu.sos-sts.com/repository.php

2. Install codecs


sudo apt-get update
sudo apt-get install gstreamer0.10-alsa \
gstreamer0.10-esd \
gstreamer0.10-ffmpeg \
gstreamer0.10-fluendo-mpegdemux \
gstreamer0.10-gnomevfs \
gstreamer0.10-plugins-base \
gstreamer0.10-plugins-base-apps \
gstreamer0.10-plugins-good \
gstreamer0.10-plugins-ugly gstreamer0.10-x
sudo apt-get install w32codecs \
libdvdcss2 \
libxine-extracodecs \
totem-xine \
ffmpeg \
lame \
faad \
sox \
mjpegtools \
libxine-main1



3. Upgrade



sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade



2. Set preferences
Select video driver to xv (X11/Xv)

Reference:
http://tw.myblog.yahoo.com/jw!Z3YOJZSGER5taqtYmemK3uSU/article?mid=368&prev=-1&next=366
http://54061.blogspot.com/2007/03/ubuntu-704-codec-rmvb.html
http://www.ubuntu.org.tw/modules/newbb/viewtopic.php?topic_id=4041&viewmode=flat&order=ASC&type=&mode=0&start=30
http://www.ubuntu.org.tw/modules/newbb/viewtopic.php?topic_id=42&viewmode=flat&order=ASC&type=&mode=0&start=0

2007/08/27

Server list

YZU

bbs.cse.yzu.edu.tw 2200 FreeBSD 4.11-STABLE *
freebsd.netlab.cse.yzu.edu.tw 22 Ubuntu
OSs.CNA.CCu.Edu.Tw 23
bbs.yzu.edu.tw 22 FreeBSD 4.11-STABLE *
linux.netlab.cse.yzu.edu.tw 22 Linux version 2.6.10-1.771_FC2
moon.cse.yzu.edu.tw 9999 FreeBSD 6.2-STABLE
webbbs.yzu.edu.tw 22 FreeBSD 6.2-STABLE *

NCU

sokoyo.csit.tw 2222 Ubuntu 7.10 *
axp1.csie.ncu.edu.tw 5330 Linux version 2.6.19-1.2911.fc6PAE
sparc12.cc.ncu.edu.tw 22 Solaris
sparc13.cc.ncu.edu.tw 22 Solaris
sparc14.cc.ncu.edu.tw 22 Solaris
sparc15.cc.ncu.edu.tw 22 Solaris
sparc19.cc.ncu.edu.tw 22 Linux version 2.6.17-1.2142_FC4
sparc20.cc.ncu.edu.tw 22 Linux version 2.6.17-1.2142_FC4

2007/08/18

Build Octopus develop environment

What is Octopus?

1. Install Moteiv's Tmote Tools from http://www.moteiv.com/

If already installed Cygwin, I recommend uninstall Cygwin firstly. Secondly,
to run setup.msi from tmote-tools-2_0_5.zip. Finally, to upgrade or install
other Cygwin packages.

2. Copy and Modify target file


shell> cd /opt/moteiv/tools/make/
shell:/opt/moteiv/tools/make/> cp tmote.target octopus.target



octopus.target




...

-PLATFORM ?= tmote
+PLATFORM ?= octopus

...

-CFLAGS += \
--I$(MOTEIV_DIR)/tos/platform/tmote \
--I$(MOTEIV_DIR)/tos/platform/tmote/util/uartdetect \
+CFLAGS += \
+-I$(MOTEIV_DIR)/tos/platform/octopus \
+-I$(MOTEIV_DIR)/tos/platform/octopus/util/uartdetect \

...

- BOOTLOADER ?= $(MOTEIV_DIR)/tos/lib/Deluge/TOSBoot/build/tmote/main.ihex
+ BOOTLOADER ?= $(MOTEIV_DIR)/tos/lib/Deluge/TOSBoot/build/octopus/main.ihex

...

-tmote: $(BUILD_DEPS)
+octopus: $(BUILD_DEPS)

...




3. Create octopus directory


shell> cp -r /opt/moteiv/tos/platform/tmote /opt/moteiv/tos/platform/octopus



4. Modify hardware.h file

/opt/moteiv/tos/platform/octopus/hardware.h




...

// LEDs
TOSH_ASSIGN_PIN(RED_LED, 5, 4);
TOSH_ASSIGN_PIN(GREEN_LED, 5, 5);
-TOSH_ASSIGN_PIN(YELLOW_LED, 5, 6);
+TOSH_ASSIGN_PIN(YELLOW_LED, 5, 3);
+TOSH_ASSIGN_PIN(BLUE_LED, 5, 6);

...

TOSH_ASSIGN_PIN(STE1, 5, 0);
+TOSH_ASSIGN_PIN(BUFFER_CS, 4, 3);

// ADC
TOSH_ASSIGN_PIN(ADC0, 6, 0);

...

// FLASH
-TOSH_ASSIGN_PIN(FLASH_PWR, 4, 3);
+TOSH_ASSIGN_PIN(FLASH_W, 4, 0);
TOSH_ASSIGN_PIN(FLASH_CS, 4, 4);

...




5. Copy and Modify HPLUSART1M.nc file


shell> cp /opt/moteiv/tos/platform/msp430/HPLUSART1M.nc /opt/moteiv/tos/platform/octopus/



/opt/moteiv/tos/platform/octopus/HPLUSART1M.nc




...

async command result_t USARTControl.tx(uint8_t data){
atomic {
+ TOSH_CLR_BUFFER_CS_PIN();
U1TXBUF = data;
}
return SUCCESS;
}

...




6. Copy and Modify Leds.nc file


shell> cp /opt/tinyos-1.x/tos/interfaces/Leds.nc /opt/moteiv/tos/platform/octopus/



/opt/moteiv/tos/platform/octopus/Leds.nc




interface Leds {

...

/**
* Toggle the yellow LED. If it was on, turn it off. If it was off,
* turn it on.
*
* @return SUCCESS always.
*
*/
async command result_t yellowToggle();

+ async command result_t blueOn();
+ async command result_t blueOff();
+ async command result_t blueToggle();

/**
* Get current Leds information
*
* @return A uint8_t typed value representing Leds status
*
*/
async command uint8_t get();

...
}



7. Copy and Modify LedsC.nc file


shell> cp /opt/tinyos-1.x/tos/system/LedsC.nc /opt/moteiv/tos/platform/octopus/



/opt/moteiv/tos/platform/octopus/LedsC.nc




...

enum {
- RED_BIT = 1,
- GREEN_BIT = 2,
- YELLOW_BIT = 4
+ BLUE_BIT = 1,
+ GREEN_BIT = 2,
+ RED_BIT = 4,
+ YELLOW_BIT = 8
};

async command result_t Leds.init() {
atomic {
ledsOn = 0;
dbg(DBG_BOOT, "LEDS: initialized.\n");
TOSH_MAKE_RED_LED_OUTPUT();
TOSH_MAKE_YELLOW_LED_OUTPUT();
TOSH_MAKE_GREEN_LED_OUTPUT();
+ TOSH_MAKE_BLUE_LED_OUTPUT();
TOSH_SET_RED_LED_PIN();
TOSH_SET_YELLOW_LED_PIN();
TOSH_SET_GREEN_LED_PIN();
+ TOSH_SET_BLUE_LED_PIN();
}
return SUCCESS;
}

...

async command result_t Leds.yellowToggle() {
result_t rval;
atomic {
if (ledsOn & YELLOW_BIT)
rval = call Leds.yellowOff();
else
rval = call Leds.yellowOn();
}
return rval;
}

+ async command result_t Leds.blueOn() {
+ dbg(DBG_LED, "LEDS: Blue on.\n");
+ atomic {
+ TOSH_CLR_BLUE_LED_PIN();
+ ledsOn |= BLUE_BIT;
+ }
+ return SUCCESS;
+ }

+ async command result_t Leds.blueOff() {
+ dbg(DBG_LED, "LEDS: Blue off.\n");
+ atomic {
+ TOSH_SET_BLUE_LED_PIN();
+ ledsOn &= ~BLUE_BIT;
+ }
+ return SUCCESS;
+ }

+ async command result_t Leds.blueToggle() {
+ result_t rval;
+ atomic {
+ if (ledsOn & BLUE_BIT)
+ rval = call Leds.blueOff();
+ else
+ rval = call Leds.blueOn();
+ }
+ return rval;
+ }

async command uint8_t Leds.get() {
uint8_t rval;
atomic {
rval = ledsOn;
}
return rval;
}

async command result_t Leds.set(uint8_t ledsNum) {
atomic {
- ledsOn = (ledsNum & 0x7);
+ ledsOn = (ledsNum & 0xF);
if (ledsOn & GREEN_BIT)
TOSH_CLR_GREEN_LED_PIN();
else
TOSH_SET_GREEN_LED_PIN();
if (ledsOn & YELLOW_BIT )
TOSH_CLR_YELLOW_LED_PIN();
else
TOSH_SET_YELLOW_LED_PIN();
if (ledsOn & RED_BIT)
TOSH_CLR_RED_LED_PIN();
else
TOSH_SET_RED_LED_PIN();
+ if (ledsOn & BLUE_BIT)
+ TOSH_CLR_BLUE_LED_PIN();
+ else
+ TOSH_SET_BLUE_LED_PIN();
}
return SUCCESS;
}

...




8. Copy MSP430ClockM.nc file


shell> cp /opt/moteiv/tos/platform/msp430/timer/MSP430ClockM.nc /opt/moteiv/tos/platform/octopus/



9. Copy and Modify MSP430GeneralIOM.nc file


shell> cp /opt/tinyos-1.x/tos/platform/msp430/MSP430GeneralIOM.nc /opt/moteiv/tos/platform/octopus/



/opt/moteiv/tos/platform/octopus/MSP430GeneralIOM.nc




...

- async command uint8_t Port12.getRaw() { return TOSH_READ_PORT12_PIN(); }
- async command bool Port12.get() { return TOSH_READ_PORT12_PIN() != 0; }
+ async command uint8_t Port12.getRaw() { TOSH_READ_PORT12_PIN(); return 1;}
+ async command bool Port12.get() { TOSH_READ_PORT12_PIN(); return 1;}

...




10. Copy and Modify NoLeds.nc file


shell> cp /opt/moteiv/tinyos-1.x/tos/system/NoLeds.nc /opt/moteiv/tos/platform/octopus/



/opt/moteiv/tos/platform/octopus/NoLeds.nc




...

async command result_t Leds.yellowToggle() {
return SUCCESS;
}

+ async command result_t Leds.blueOn() {
+ return SUCCESS;
+ }

+ async command result_t Leds.blueOff() {
+ return SUCCESS;
+ }

+ async command result_t Leds.blueToggle() {
+ return SUCCESS;
+ }

async command uint8_t Leds.get() {
return 0;
}

...




11. Modify and Compile SerialByteSource.java file

/opt/tinyos-1.x/tools/java/net/tinyos/packet/SerialByteSource.java




...

public void openStreams() throws IOException {

...

try {
serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);
serialPort.setSerialPortParams(baudRate,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);

+ // elva set COM port pin(DTR) to LOW
+ serialPort.setDTR(false);
+ // elva end of modify

serialPort.addEventListener(this);
serialPort.notifyOnDataAvailable(true);
}

...

is = serialPort.getInputStream();
os = serialPort.getOutputStream();

+ // elva delay for mote reboot
+ try {
+ Thread.sleep(1300);
+ }
+ catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ }
+ // elva end of modify
}

...



Complie SerialByteSource.java file


shell> cd /opt/tinyos-1.x/tools/java/net/tinyos/packet
shell:/opt/tinyos-1.x/tools/java/net/tinyos/packet> javac SerialByteSource.java



appendix 1. Make an example application


shell> cd /opt/moteiv/apps/Count/CountLeds
shell:/opt/moteiv/apps/Count/CountLeds> make octopus



appendix 2. Run an example application


shell> export MOTECOM=serial@COM6:tmote
shell> cd /opt/tinyos-1.x/tools/java/net/tinyos/tools
shell:/opt/tinyos-1.x/tools/java/net/tinyos/tools> java net.tinyos.tools.Listen



appendix 3. Set Node ID: 5

shell:/opt/moteiv/apps/Count/CountLeds> /opt/tinyos-1.x/tools/make/msp/set-mote-id --objcopy msp430-objcopy --objdump msp430-objdump --target ihex build/octopus/main.ihex build/octopus/main.ihex.out-5 5

.vimrc file

The backup of .vimrc file

2007/08/17

NS2 Installation on UNIX based system (Daily Snapshot)

1. Download Tcl/Tk from http://www.tcl.tk/software/tcltk/


shell> wget http://prdownloads.sourceforge.net/tcl/tcl8.4.15-src.tar.gz
shell> wget http://prdownloads.sourceforge.net/tcl/tk8.4.15-src.tar.gz



2. Download daily NS2 from http://www.isi.edu/nsnam/dist/daily/


shell> wget http://www.isi.edu/nsnam/dist/daily/nam-1-XXXXXXXX.tar.gz
shell> wget http://www.isi.edu/nsnam/dist/daily/ns-2-XXXXXXXX.tar.gz
shell> wget http://www.isi.edu/nsnam/dist/daily/otcl-XXXXXXXX.tar.gz
shell> wget http://www.isi.edu/nsnam/dist/daily/tclcl-XXXXXXXX.tar.gz



3. De-compress all file in custom directory (ex: ~/ns-daily-2.31/)

4. Recommand touch a file for the version of ns2


shell:~/ns-daily-2.31/> touch 20070815



5. Using following shell script to configure and make files

install.sh
[code]
#!/bin/bash

# tcl
cd tcl8.4.15/unix
./configure --enable-shared
make
cd ../..

# tk
cd tk8.4.15/unix
./configure --enable-shared
make
cd ../..

# otcl
cd otcl
./configure --disable-static --with-tcl-ver=8.4.15 --with-tk-ver=8.4.15
make
cd ..

# tclcl
cd tclcl
./configure --disable-static --with-tcl-ver=8.4.15 --with-tk-ver=8.4.15
make
cd ..

# ns-2
cd ns-2
./configure --disable-static --with-tcl-ver=8.4.15 --with-tk-ver=8.4.15 \
--with-otcl=../otcl --with-tclcl=../tclcl
make
cd ..

# nam-1
cd nam-1
./configure --disable-static --with-tcl-ver=8.4.15 --with-tk-ver=8.4.15 \
--with-otcl=../otcl --with-tclcl=../tclcl
make
cd ..

echo "Installation complete"
[/code]

If this fail, try Distribution Specific instructions

If this error for file pcap.h not existed, install libpcapX.X-dev

If this success, only needing to upgrade OTcl, TclCL, ns-2 and nam-1 in the future

6. Create soft link for needing files


shell:~/ns-daily-2.31/> mkdir bin
shell:~/ns-daily-2.31/> mkdir lib
shell:~/ns-daily-2.31/> cd bin
shell:~/ns-daily-2.31/bin/> ln -s ../ns-2/ns .
shell:~/ns-daily-2.31/bin/> ln -s ../nam-1/nam .
shell:~/ns-daily-2.31/bin/> cd ../lib/
shell:~/ns-daily-2.31/lib/> ln -s ../tcl8.4.15/unix/libtcl8.4.so .
shell:~/ns-daily-2.31/lib/> ln -s ../tk8.4.15/unix/libtk8.4.so .



7. Add following setting to set NS2 environment

.bashrc
[code]
# NS2 environment
PATH=/home/USER/ns-daily-2.31/bin:$PATH
LD_LIBRARY_PATH=/home/USER/ns-daily-2.31/bin:/home/USER/ns-daily-2.31/lib
TCL_LIBRARY=/home/USER/ns/ns-daily-2.31/tcl8.4.15/library
export PATH LD_LIBRARY_PATH TCL_LIBRARY
[/code]

8. Make Documentation


shell:~/ns-daily-2.31/ns-2/doc> make



If you want to create html documentation, install latex2html firstly

2007/08/16

Problems with installation ns-2.31 under Cygwin

Reference:
[ 1393985 ] validation fails under Cygwin
http://mailman.isi.edu/pipermail/ns-users/2006-December/058117.html

Error Message:


validate overall report: some tests failed:
./test-all-smac-multihop ./test-all-simultaneous ./test-all-wireless-tdma
to re-run a specific test, cd tcl/test; ./test-all-TEST-NAME
Notice that some tests in webcache will fail on freebsd when -O is turned on.
This is due to some event reordering, which will disappear when -g is turned on.

Cygwin >= 1.3.19 detected (1.5.24), all tests should have passed.
Please see <http://www.isi.edu/nsnam/ns/ns-problems.html>
for potential solutions.



Solution:

Those tests currently fail on Cygwin.

2007/08/11

懷舊

整理了以前蒐集的美女相簿

看到一些推文

回想起當初

好懷念從前

不想長大

長大才發現人心的險惡

長大才發現自己的不足

長大才發現我真討人厭

2007/08/09

MySQL Backup

http://dev.mysql.com/doc/refman/5.0/en/backup-strategy-example.html

main command:

shell> mysqldump -uroot -p --single-transaction --flush-logs --master-data=2\
--all-databases > db.sql



backup script
[code]
#!/bin/sh

BACKUP_DIR="/backup"

ROOT_PASSWORD="password"

DATE=`date +%y%m%d`

SQL_FILE=db$DATE.sql
TGZ_FILE=db$DATE.tgz

cd $BACKUP_DIR

mysqldump -uroot -p$ROOT_PASSWORD --single-transaction --flush-logs --master-data=2 --all-databases > $SQL_FILE

tar zcvf $TGZ_FILE $SQL_FILE

rm $SQL_FILE
[/code]

2007/08/05

安裝兩張以上網卡備忘

/etc/network/interfaces 內只能設一個 gateway

否則 routing table 會出現一個以上的 default route

可能造成從非期望的網卡 route 出封包

2007/08/03

Install GloMoSim

GloMoSim in ubuntu http://axp1.csie.ncu.edu.tw/~rick/blog/?p=4
GloMoSim in Windows http://axp1.csie.ncu.edu.tw/~rick/blog/?p=5

---

Backup the archives


0. Windows: Install VC6
Others: Install gcc
1. Download from http://pcl.cs.ucla.edu/projects/glomosim/academic/topsecret_download.html
2. De-compress
3. Set 『PCC_DIRECTORY』 environment variable = 『glomosim-2.03/parsec/The OS
4. Add 『Path』 environment variable = 『glomosim-2.03/parsec/The OS/bin』
5. Windows: change directory to 『glomosim-2.03/glomosim/main/』 & run 『makent.bat』
Others: change directory to 『glomosim-2.03/glomosim/main/』 & run 『make』
6. Windows: To find 『glomosim2.03/glomosim/bin/glomosim.exe』
Others: To find 『glomosim2.03/glomosim/bin/glomosim』

2007/07/30

[轉載] 追求女友的祕方

http://blog.outian.net/archives/296

---

到了大學的時期,對異性的幻想和追求的慾望總是存在,然而在交大這個女少男多的奇怪環境下,卻十分難以如願,所以特別提供追求女友的祕方以饗諸網友們,還請大家多多指教。

1.心理建設:   

  許多人看到了合意的女孩,總有追求的慾望,到了最後又總是會追不成。
  也許那些人會說自己膽子小,也有的人說再等一下,過幾天再追。
  事實上這些〞再等一下〞,或是〞不敢〞的想法正是追求女友的大敵,
  要知道,在這個年頭,想要等女孩子自己送上門來,幾乎是不可能的,
  除非你人帥或是有錢,否則這種從天而降的好事,最好是想都別想。
  那麼照這麼說,女友要怎麼追?其實也不會十分的困難,
  要知道,其實大部分的女性都十分的可憐,她們在社會道德的約束下,
  多半只能等男人來追,今天她要是放棄了你的追求,
  她們也會擔心下次還有人來追還要等多久?
  當然,這一點在交大不十分的適用,
  但是對於外界的女性而言,可是一件十分殘酷的事實。
  在另一個角度來說,有的人怕會失敗,會被他人恥笑,這也不是問題。
  想一想,要是說你自己不去大嘴巴,她還敢到處說她被某某人追,
  但是自己不喜歡等等的話,無異於自絕生路。
  
  今天她到處亂說,他日還有誰敢去追她?
  誰都怕成為她口中的白痴,我以前就有認識一個女的,
  班上有人來追她竟然四面招搖,結果沒有人恥笑那個男的,
  反而那個女的到了大四時還沒有人要追,人老了才知道自己的無知,又那來的及呢?
  所以大家也不要怕會成為人家的笑柄,
  只要你不說,又有誰會知道你的追求失敗呢?
  而且,失敗不可恥,膽小怕事才真的永遠無法追到自己所喜歡的女孩!
  
  而且,你怎麼知道她不是在等著你呢?
  也有的人嫌自己長的不好看,這也不像是個問題,不好看的人只是追不到小女生而已;
  有些長不大的女生總是把男人的好看與否當成最主要的選擇條件,
  我想,對於這種女性,她遲早會出問題的。
  想想看,
  大帥哥當然是人見人愛,到了她老的時後,年老色衰時,
  她那留的住看她美貌而追求她的男人呢?
  我也被個女的嘲笑過人醜,嗯,可能還不只一個..
  上次我坐火車回台北時還被莒光號的小姐說是兔寶寶(兩顆超大的門牙),
  不過這也不是問題,我總也是找的到女友的,
  要是自己都嫌自己的話,我看連其他的女生都會嫌你了,
  又不是沒看過漂亮的女生旁邊跟著奇醜無比的男友的?
  不去試一下,怎麼知道她不會喜歡你?
  反正當成死定了,試試無妨的心理去看一下,說不定還會成功也不一定,
  總是比中發票的機會大吧!   
  
  所以說,也不要怕失敗,反正就算是失敗了,
  也沒人知道,去試看看總是好的。但是可千萬不要整天東追一個西追一個,
  那麼我就罪過大了哦。  
  
  不過,也千萬不要老是成天想著要去追大美女,那種人天天有人追,不是一般人追的到的。
  當然也不是沒有例外,有的大美女要的只是一個可以信賴的好男人,
  不管他長的好看與否,自然是有可能會喜歡上平凡的男仕,
  也許你就是她所期待的類型,但是呢,不去試看看怎麼知道?  
  
  說了這麼多,只是要大家先拋開心理的障礙,
  但是若是說自己一無所長,又憑什麼人家要喜歡你?
  就算是一時追到也無法長久保有,所以說自己要適當的充實自己是必要的。
  充實自己不是要你去學東學西,主要的是要讓自己能適當的發揮自己的長處,
  行有餘力再去學些別的也不遲,何況,又不是為了要追女生才去學些東西?
  不過,人要活的有價值,總是要有些長處的吧!

2.前置作業:

  首先,大家要有個体認,那就是要如何選定對象。
  
  選定對象應要有誠意,不要抱定玩玩就走的心態,
  同樣的,也要事先考慮個性的匹配問題,以避免他日還要有分手的困擾,
  然而這是見人見智的,只要雙方覺得滿意,再多的困難也是可以克服的。   
  
  當自己已選好目標了之後,再來要面對的就是要如何先獲取她的注意力了,
  下面提供數點參考意見:
  
  a.無論是多麼細微的小事,只要是與她相關的,都必需強調:
    與女性交談時,首先可以發覺到,如果自己與她有共同點,
    那這位女性便會立即對你表示好感,此時她會緩和拘束的表情,
    且談話時也會表現出親蜜感。
    發現有共同點時會產生親切感並不是只有女性才會有這種表現,
    男性也同樣會有,只是在女性身上特別顯著而己。
    女性對於形成命運的事物十分敏感,在芸芸眾生之中,
    僅你和她有相同點的話,她會覺得神秘,會聞到命運的氣息,
    是以會對你有特殊的好感。所以你必需強調自己與她的相同和相似點。
  
  b.女性欣賞的是男性談話的風采,而不是談話的內容:  
    通常女生對一個男性的評價,多是建立在模糊、大概的印象判斷上,
    而不是作客觀、詳盡的分析。
    譬如,女性難得說的出:這個人眼睛大、頭額寬..等等的事,
    卻容易作「好人」「溫柔親切的人」一類的批評;
    對態度的評價也是如此,「熱忱」「開朗」「老實」..等等,
    將重點擺在說話異性的音調或是動作上,這也是女性的特徵。
    所以,有人總認為自己的口才遲鈍、無話可說,
    而煩惱於不能吸引女性的注意力。
    實則與其消極的目卑自嘆,不如積極地談些自己的工作或拿手的專長,
    並且比手劃腳一番,那麼女性儘管不甚明瞭你的談話內容,
    也會瞪大眼睛欣賞你的談話風采,繼而接納你的言語,
    甚至重新評估你的確「不同凡響」,而立即表現出親切的態度呢!
    我有一個學妹就是如此,雖然在我上台報告時聽不懂一些艱澀的理論,
    卻老是說我在台上時好迷人等等的話,所以要是你認為自己不會說話,
    也不要灰心,女生看的是你的風采,而少注意你的內容。
  
  c.擁有共同的目標與目的,是打開她心房的第一步:
    讓兩個人有共同的目標與目的,十分容易讓她有兩人是命運共同体的假象,
    這也是許多花花公子常用的招數。此種現象在大公司裡十分常見,
    像老闆和祕書由於兩個人要共同面對外界的事件,所以也特別容易發生感情。
    其實,自己也可以想一下,現在你和你同學,要是一起為同一件工作而努力時,
    是不是會比較親近呢?同樣的,要是能有機會能和她共同解決問題,
    或是在想法上能站在她那一邊的話,必然能立刻拉近與她之間的距離!
    同理,在說話上也是一樣,與其說〞我和妳〞就不如說〞我們〞來的好了。
    再引伸下去,有的時後,
    自己要是犯了什麼錯或是一些讓人知道也無傷的小祕密也可以讓她知道,
    當然,要說的好像你只對她一個人說似的,那麼由於兩人享有共同的祕密,
    也十分容易拉近雙方的距離;或是說兩個人一起犯了些小錯而不讓人知道的話,
    也有異曲同工之妙哦。
  
  d.交談時,要避免問〞是/否〞來回答的問題:  
    有的人,在剛見面時,總是談沒有幾句就沒話講了。
    仔細想一下,許多人都是犯了同一個錯誤,
    就是老問一些〞是〞或〞不是〞就可以回答的問題..
    嗯,像是說,你問她:「妳看不看電影呢?」
    就不如問她:「妳平常有那些休閒活動呢?」來的好。
    因為每一回她只要說〞是〞或〞不是〞就可回答的話,
    那麼兩人的談話不是一下子就結束了嗎?
  
  e.與女生交談時,必須注意一些不可重覆提出的忌諱語句:
    女生容易受到暗示的程度比男性強,對於男性覺得不在乎的重覆語句,
    在無意識中,還是會左右女性的想法。
    譬如說,某位女性要是自己覺得自己皮膚黑,
    那麼你要是老是在講別人的皮膚怎樣不好的話,會讓她誤以為你在嫌她,
    這是剛開始交往時一定要注意的。
  
  d.稱讚女性的技巧:
    我想,大家也知道,要想去追一個女孩子,總免不了要稱讚她幾句,
    然而就是有人稱讚的讓女性受用,有的人卻馬屁會拍到馬腳上。
    要稱讚女性,一定要提出〞具体的〞所在,
    怎麼說呢,像是你要讚美一個女性有多漂亮,不能說〞妳好漂亮呀〞,
    而是要明白的指出:〞妳的皮膚好好喲!〞或是〞妳的眼睛好有靈性啊!〞等的,
    要言之有〞物〞,要明白的表示她好的地方,
    否則容易讓人產生在拍馬屁的錯覺,那麼稱讚她所應有的效益就不好了。
    或是也可以換一個方式說:〞大家都覺得妳好漂亮哦..〞一類的,
    利用別人的言語〞大家都說..〞來稱讚,那麼女性容易覺得這不是恭維,
    而是真實的。
  
  e.身体的無意碰觸,是增進彼此感情的好方法:
    在剛認識的時後,我想大家都有經驗,就是人與人的身体距離比較遠,
    一方面是不熟,在另一方面也是人類行為的特性,
    對不熟的人會保持距離以策安全。
    不僅是心理上如此,在外在的表現也是如此。
    所以說,當兩個人談話談的十分愉快,而在肢体上有〞不經意〞的碰觸時,
    能在潛意識裡增進彼此的距離。
    當然,這個要用的有技巧,否則易讓人有〞侵犯〞的感覺,但是反過來說,
    這也是十分有效的方法。
    所以說,為何在交女友之初,大家老想到要如何牽到她的手是一樣的道理,
    能有身体上的接觸,則更能增進彼此感情。
    所以了,要是有女孩子老是不經意的碰碰你怎樣的,
    雖然不表示她一定是喜歡你怎樣的,
    至少可以表示她把你當自己人才會有這樣的表現。

生涯希望工程

生涯希望工程學院 http://hp.e-yang.org.tw/

中華民國大專生涯發展協會 http://www.e-yang.org.tw/

2007/07/19

心慌慌

等實驗室沒人的這段時間

逛了逛好久沒去的幾個 BBS

找了找需要的資料

意外發現了 OuTian 大大曾經開過課的紀錄

http://blog.outian.net/archives/category/myself/otclass/

不禁感嘆

我浪費了好多時間

有一大堆等著我去學

我還差得遠勒

---

話說還真想跟 OuTian 大大要開課的教材

可惜不認識阿 Orz

2007/07/13

Apache Block TRACE/TRACK XSS

Secure Apache TRACE Vulnerabilities

Set follows in Apache configuration

# Block TRACE/TRACK XSS vector
RewriteEngine On
RewriteCond %{REQUEST_METHOD} ^TRAC(E|K)
RewriteRule .* - [F]

2007/06/22

在 Ubuntu 下管理與設置 UTF-8 環境的 MySQL

在 Ubuntu 下管理與設置 UTF-8 環境的 MySQL

1. 修改 my.cnf

[client]
default-character-set = utf8

[mysqld]
datadir = /home/mysql
character-set-server= utf8
collation_server = utf8_general_ci
init-connect = 'SET NAMES utf8'



2. 產生新的 MySQL Database 存放位置

shell> mysql_install_db --user=mysql



3. 執行 MySQL

shell> /etc/init.d/mysql start



出現下面錯誤訊息先不用管


/usr/bin/mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'debian-sys-maint'@'localhost' (using password: YES)'
sokoyo@sokoyo-server:~/mysql$ /usr/bin/mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'debian-sys-maint'@'localhost' (using password: YES)'



4. 以 root 登入


shell> mysql -u root



5. 列出所有 host 和 user

mysql> SELECT Host, User FROM mysql.user;
+---------------+------+
| host | user |
+---------------+------+
| 127.0.0.1 | root |
| localhost | root |
| hostname | root |
+---------------+------+
3 rows in set (0.00 sec)



6. 設定 root 密碼

mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpwd');
mysql> SET PASSWORD FOR 'root'@'127.0.0.1' = PASSWORD('newpwd');
mysql> SET PASSWORD FOR 'root'@'hostname' = PASSWORD('newpwd');



7. 新增使用者 debian-sys-maint,密碼參閱 /etc/mysql/debian.cnf 內的 password

mysql> GRANT ALL PRIVILEGES ON *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;



8. 檢視環境變數

mysql> show variables;



結果如下代表成功設置 UTF-8 環境


| character_set_client            | utf8                        |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
| collation_connection | utf8_general_ci |
| collation_database | utf8_general_ci |
| collation_server | utf8_general_ci |



9. 重新啟動 MySQL

shell> /etc/init.d/mysql restart



出現如下代表正常啟動


 * Stopping MySQL database server mysqld	[ OK ]
* Starting MySQL database server mysqld [ OK ]
* Checking for corrupt, not cleanly closed and upgrade needing tables.




接下來靠 phpMyAdmin 就可以了

一些開發需要的 apt package

開發時需要的環境和 apt package

2007/06/02

近畢業有感

大學快畢業了

心理覺得挺煩、挺無奈

雖說要畢業

一堆事情卻都還沒處理完

再加上要搬家

整個煩躁

---

回首大學生涯

大一上算是快樂的一學期

成就感十足

在功課壓力與娛樂中快樂的度過

---

大一下是悲劇的開始

莫名奇妙被推上當班代

莫名奇妙出了個資訊週

因為個人責任認知的不同

人際關係瞬間盪到谷底

不過這個時候還不自知

---

大二期間因為沒有與同學外宿

相處時間變少

隔閡漸深

誤會愈大

同樣我也不自知

只是有些感覺

---

大三上想找教授做專題時

問題更明顯

我不知道如何解決

只好在自己的 B 版大吐苦水

誰知這樣更加重了裂痕

---

大三下作專題

參加比賽

自己的問題加上遇人不淑

埋藏許久的火山逐漸爆發

要升大四上時

從 BBS 上的匿名版爆了出來

起因很單純

只是我在個人版吐了類似孤單的發言

開始有人用力捅

欲制人與死地

好奇心與求好心切的作祟

讓我想知道誰對我不滿

試圖力挽狂瀾

然而就如蝴蝶效應一般愈滾愈大、愈來愈嚴重

---

人心是很有趣、很難測的

一旦有了主觀的意見

要改變的機會是微乎其微

因為發現在個人版澄清的文章無效

一度限制進版的人

到最後演變成轉為密版

然而這些只是掩耳盜鈴

最終對一切失去希望

同學情誼正式宣告瓦解

個人版關閉

讓自己從同學的眼中消失不見

---

接下來的大四生活

一開始是灰色的

雖然連指導教授都試圖挽救

但是已無力回天

心中只要有了疙瘩

是無法輕易消除的

---

所幸

認識了老王學長

重新快樂起來找到心靈的依靠

感謝老王、磊哥、鴻哥、耗子、silk、toad、小翁學長們

雖然斷絕了同學之間的關係

但我在實驗室生活中找到了歡樂、友誼和人生

---

實驗室中是多采多姿的

充滿歡笑、一起討論、互相開玩笑、一起玩、一起臭幹譙、一起吃飯

最值得回憶的就是大四這段實驗室生活

用有歡笑有淚水來形容真是再貼切不過了

---

轉眼間要畢業了

沒有 netlab 就不會有現在的我

想到未來要與學長們各分東西真的很捨不得

想到未來要到新的環境更加憂心

如果時光可以停止或是倒回那該有多好

---

人總是會長大、年老

對於未來不確定的我真是感到憂心

鴻哥、老王說有夢想、有目標是最好最幸福的

我沒有明確的夢想與目標

常讓我不知所措

只能以走一步算一步的方式闖蕩我的人生

---

我討厭自己的個性與無能

願我能快快成長

不要虛度一生

2007/05/27

iptables setting

PC1 in NAT
eth0: 192.168.1.1
run HTTP server on 80 port

PC2 in NAT and Public Domain
eth0: 140.138.243.124
eth1: 192.168.1.2

If you want to use PC2 as Firewall and to provide HTTP service,
set iptables in PC2 as follows:

Clear old setting:


sudo iptables -F
sudo iptables -X
sudo iptables -Z
sudo iptables -F -t nat
sudo iptables -X -t nat
sudo iptables -Z -t nat



Set POSTROUTING for NAT -> Public Domain connection:


sudo iptables -t nat -A POSTROUTING -s 0.0.0.0/0 -j SNAT \\
--to 140.138.243.124



Set PREROUTING for Public Domain -> NAT connection:


sudo iptables -t nat -A PREROUTING -p tcp -d 140.138.243.124 \\
--dport 80 -j DNAT --to 192.168.1.1:80



※ For the setting, PC2 can't use HTTP service through Public IP of PC2.
:$

2007/05/26

前天 5/24

前天要換防毒軟體

手賤忘了要先移除舊的

裝到一半才想起來

趕快停止 and 移除後重灌

結果不能灌了 = =

乾 防毒軟體根本跟病毒沒兩樣

刪了資料夾和 register tree 一樣不給灌

不知道在電腦偷塞了什麼檔案

想起來就杜爛

說完成結果資料夾內是空的

為了怕中毒只好暫時 shutdown

現在只好用 Firestarter 作個臨時的防火牆 + NAT Server

只讓 HTTP 和 DNS 能進我的主機

不過 Firestarter 畢竟是新手用的東西

功能沒有 iptables 強大

外面資料可以 forward 到 NAT 內的機器

在 NAT 內的機器封包竟然沒辦法 forward 到 NAT 內的機器



看來還是找一天快點把 iptables 設好 + 重灌

---

話說今天夢到 我 + 忘記是哪兩位美女 + 老王學長

大概是昨天聽了一場"辯論會" + 看了 PTT 的羅莉照

夢裡我變得好強勢 + 遇到小羅莉 (我不是羅莉控!!)

為了便利商店拖很久沒給我微波好的東西

竟然大發雷霆 @@

我在現實社會可是逆來順受的 囧

完全不一樣滴

2007/05/22

Apache log 中出現 PHP Notice: Undefined index 的解決方式

在使用外部傳遞變數 $_POST 或 $_GET

Apache log 中有可能出現 PHP Notice: Undefined index

解決方式一種是直接在 php configuration file 內

錯誤紀錄的階級修改為

error_reporting = E_ALL & ~E_NOTICE


另一種則是保持好習慣

用到可能沒傳遞的變數做好判斷

範例如下:

[php] if( isset($_POST['p']) ) {
$post_p = $_POST['p'];
echo "get variable {$post_p} by POST method";
}
?>[/php]

2007/05/11

WP 頁首頁尾出現不明、奇怪數字

WordPress 頁首頁尾出現不明、奇怪數字的解法

wp-includes/functions.php

- @header("HTTP/1.1 $header $text", true, $header);
+ @header($_SERVER["SERVER_PROTOCOL"]." ".$header." ".$text, true, $header);



原因是在

http://trac.wordpress.org/ticket/3886

相關的討論串

http://www.robbin.cc/vb/showthread.php?t=649
http://wordpress.org/support/topic/105807

2007/05/11 凌晨

人生總是瞬息萬變

輾轉得知同學車禍過世了

雖然人家不當我是朋友

但知道的當下還是有點感傷

兩個星期前我爺爺也是過世了

不禁覺得死神似乎無所不在

做任何事都要小心



看到那麼多同學為他哀悼、難過

忍不住問問自己

如果是我

會有人為我難過嗎?

我在這世上留下了些什麼

有什麼值得留在他人的心中



知道自己做人挺失敗的

只能時時警惕自己

什麼該做

什麼該說

沉默會讓人誤會

然而說錯話同樣會讓人誤會

人生就是這樣充滿學問



人心難測

你永遠無法知道你的表現在別人心中會是什麼模樣

活在世上充滿悲歡離合

重要的是在臨走之前

能留下什麼

懷念、難過

亦或是

毫不在乎、竊喜?



能夠讓人永遠掛在心上的一定是擁有深刻的記憶

思考該怎樣才能讓別人的心中有我

倒不如思考怎麼做好自己

"己所不欲勿施於人"是句老話

但我何嘗不是在施於人的當下卻不自知呢?

戒之 戒之



最後願他能安息

一路好走

2007/04/26

Java SWT 增加 KeyBoard, Mouse Listener

在 SWT 處理 KeyBoard 和 Mouse 的 Event

Example Code:

1. KeyBoard:

[java]public class KeyBoard {
private Shell shell;

public KeyBoard(Shell _shell) {
this.shell = _shell;

this.shell.addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent e) {
// ignored
}
public void keyReleased(KeyEvent e) {
if(e.stateMask == SWT.CTRL && e.keyCode == 'c') {
System.out.println("ctrl + c");
}
}
});
}
}[/java]

2. Mouse:

[java]public class Mouse {
private Shell shell;

public Mouse(Shell _shell) {
this.shell = _shell;

this.shell.addMouseListener(new MouseListener() {
public void mouseUp(MouseEvent e) {
// mouse up
}
public void mouseDown(MouseEvent e) {
// mouse down
}
public void mouseDoubleClick(MouseEvent e) {
// mouse double click
}
});
}
}[/java]

3. KeyBoard and Mouse

[java]public class Both {
private Shell shell;

public Both(Shell _shell) {
this.shell = _shell;

Listener l = new Listener() {
Point origin;
public void handleEvent(Event e) {
switch (e.type) {
case SWT.MouseDown:
origin = new Point(e.x, e.y);
break;

case SWT.MouseUp:
origin = null;

if(e.button == 1) {
// left button
}
break;

case SWT.MouseMove:
if (origin != null) {
Point p = display.map(shell, null, e.x, e.y);
shell.moveTo(p.x - origin.x, p.y - origin.y);
}
break;

case SWT.MouseDoubleClick:
break;


case SWT.KeyDown:
break;
}
}
};
this.shell.addListener(SWT.MouseDown, l);
this.shell.addListener(SWT.MouseUp, l);
this.shell.addListener(SWT.MouseMove, l);
this.shell.addListener(SWT.MouseDoubleClick, l);
this.shell.addListener(SWT.KeyDown, l);
}
}[/java]

如果 1, 2 和 3 一起使用

都會有效果

以使用的順序為執行的順序

2007/04/25

Java SortedProperties

原始的 java.util.Properties 是以 java.util.Hashtable 來儲存資料

因此輸出的結果會以亂數排列

如果想使用 sort 過的 Properties

需要重新 override keys

程式碼如下:

SortedProperties.java

[java]import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
import java.util.Properties;
import java.util.Set;

public class SortedProperties extends Properties {

@ Override
public Enumeration keys() {
List sortedList = new ArrayList();
sortedList.addAll((Set) this.keySet());
Collections.sort(sortedList);
return (Enumeration) Collections.enumeration(sortedList);
}
}[/java]