2012年10月28日 星期日

無線網路連線記錄


  • iwconfig 維護更新基本的無線參數。
  • iwlist 許可用初始掃描與列出頻率,bit-rate與加密鑰…。
  • iwspy 許可用來取個每個結點的連線品質。
  • iwpriv 許可維護更新無線延申指定的驅動程式(私人)。
  • ifrename 許可命名在多重靜態認証的界面。

自己測試連線
#iwconfig wlan0 essid "wingingAP" mode managed key xxxxxxxxxxxxxxxxxx

#ifconfig wlan0 192.168.1.2
#ping 192.168.1.1
OK



使用ubuntu編android 4.0.1問題解決



我下載了三明治冰淇淋android中

$ repo init -u https://android.googlesource.com/platform/manifest -b android-4.0.1_r1 

在編譯過程中需要修改這一些東西。才能完整編完。所以
但是實在要編太久了!大約用了5-6個小時才編完。

本文出處
https://groups.google.com/forum/?fromgroups=#!topic/android-building/AgeruY7XIwQ



Not saying any of this is right, just that it finished my build. 
Using the cm9 repo (ics branch), ubuntu oneiric ocelot.  Take it for 
what it's worth, which may be nothin'. 

--fattire 


ERROR:  :0:0: error: "_FORTIFY_SOURCE" redefined [-Werror] 

FIX: 

in build/core/comboHOST_linux-x86.mk : 
-HOST_GLOBAL_CFLAGS += -D_FORTIFY_SOURCE=0 
+HOST_GLOBAL_CFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0 

------- 

ERROR:  external/gtest/src/../include/gtest/internal/gtest-param- 
util.h:122:11: error: ‘ptrdiff_t’ does not name a type 

FIX: 

in external/gtest/internal/gtest-param-util.h 
 #include  
+#include  
 #include  

------- 

ERROR:  external/oprofile/libpp/format_output.h:94:22: error: 
reference ‘counts’ cannot be declared ‘mutable’ [-fpermissive] 

FIX: 

in external/libpp/format_output.h b/libpp/format_output.h 
 -               mutable counts_t & counts; 
 +               counts_t & counts; 

------- 

ERROR:  frameworks/compile/slang/slang_rs_export_foreach.cpp:247:23: 
error: variable ‘ParamName’ set but not used [-Werror=unused-but-set- 
variable] 

FIX: 

in android/ics/frameworks/compile/slang/Android.mk 
-local_cflags_for_slang := -Wno-sign-promo -Wall -Wno-unused-parameter 
-Werror 
+local_cflags_for_slang := -Wno-sign-promo -Wall -Wno-unused-parameter 

------- 

ERROR:  Numerous pthread errors w/llvm: 
      Example:   external/llvm/lib/Support/Threading.cpp:96: undefined 
reference to `pthread_create' 

FIX:  This is a really dumb fix.  But it got me to the end of the 
build.  In external/llvm... 

diff --git a/lib/Support/Mutex.cpp b/lib/Support/Mutex.cpp 
index b408973..3a13adf 100644 
--- a/lib/Support/Mutex.cpp 
+++ b/lib/Support/Mutex.cpp 
@@ -13,6 +13,8 @@ 

 #include "llvm/Config/config.h" 
 #include "llvm/Support/Mutex.h" 
+#undef ENABLE_THREADS 
+#undef HAVE_PTHREAD_H 
// 
===---------------------------------------------------------------------- 
===// 
 //=== WARNING: Implementation here must contain only TRULY operating 
system 
diff --git a/lib/Support/Signals.cpp b/lib/Support/Signals.cpp 
index a117893..68fa5e7 100644 
--- a/lib/Support/Signals.cpp 
+++ b/lib/Support/Signals.cpp 
@@ -25,6 +25,8 @@ using namespace sys; 

 } 

+#undef HAVE_DLFCN_H 

 // Include the platform-specific parts of this class. 
 #ifdef LLVM_ON_UNIX 
 #include "Unix/Signals.inc" 
diff --git a/lib/Support/Threading.cpp b/lib/Support/Threading.cpp 
index 2957956..f1339a3 100644 
--- a/lib/Support/Threading.cpp 
+++ b/lib/Support/Threading.cpp 
@@ -16,6 +16,7 @@ 
 #include "llvm/Support/Mutex.h" 
 #include "llvm/Config/config.h" 
 #include  
+#undef LLVM_MULTITHREADED 

 using namespace llvm;

建立無線網路

這個週未,拿到了一片usb的無線網卡,在桌面電腦ubuntu上看起來一切都是正常的,
但是我把這片網路放到 arm 的新平台上,使用linux-3.0.8,使用這個無線網卡。

首先要選驅動程式
Device Drivers --->
[*] Network device support --->
[*] Wireless LAN --->
<*> Ralink driver support --->
<*> Ralink rt27xx/rt28xx/rt30xx (USB) support

選了無線網卡的驅動程式後,再重新的編譯kernel後再燒入主片中。
現在就要開始使用無線網路了!

開機後要再開始使用無線網卡了!

先看usb有沒有抓到
#lsusb

Bus 001 Device 001: ID 1d6b:0002
Bus 002 Device 001: ID 1d6b:0001
Bus 001 Device 002: ID 148f:3070 <--這一張就是無線網卡


#cat /proc/net/dev
face |bytes packets errs drop fifo frame compressed multicast|bytes packd
lo: 0 0 0 0 0 0 0 0 0 0
wlan0: 0 0 0 0 0 0 0 0 0 0 <-無線
eth0: 28192 205 0 0 0 0 0 0 3662 0

啟動無線網卡
#ifconfig wlan0 up
phy0 -> rt2x00lib_request_firmware: Error

看來是有問題的查看到要的是什麼firmware
在kernel中 drivers/net/wireless/rt2x00/rt2x00firmware.c
修改

fw_name = rt2x00dev->ops->lib->get_firmware_name(rt2x00dev);
if (!fw_name) {
ERROR(rt2x00dev,
"Invalid firmware filename.\n"
"Please file bug report to %s.\n", DRV_PROJECT);
return -EINVAL;
}

-INFO(rt2x00dev, "Loading firmware file '%s'.\n", fw_name);
+ERROR(rt2x00dev, "Loading firmware file '%s'.\n", fw_name);

重燒kernel之後就看到的firmware的名字了。
phy0 -> rt2x00lib_request_firmware: Error - Loading firmware file 'rt2870.bin'.
原來找需要的firmware是rt2870.bin,我的電腦可以用那我的電腦應該有吧!我就找了一下,果然
在/lib/firmware資料夾下有rt2870.bin拿過來用果然就可一了!

2012年9月20日 星期四

How to mount jffs2 on linux

出處:http://martin-yang.blogspot.tw/2007/04/pcjffs2-imagemount-jffs2loop-back.html 1.製作jffs2 image 請確認有mkfs.jffs2指令或事先安裝mtd-tools套件 假設 /jffs2 目錄製作成 jffs2.img 如下 #mkfs.jffs2 -d /jffs2 -o /jffs2.img -l iVU 2.mount jffs2.img在loopback上 請載入以下modules modprobe mtdcore modprobe jffs2 modprobe mtdram modprobe mtdchar modprobe mtdblock 確認以上modules會產生/dev/mtd0 及/mtd/mtdblock0檔案 dd if=/jffs2.img of=/dev/mtd0 mount /dev/mtdblock0 /mnt 需要更大的請自行指定 modprobe mtdram total_size=32768 erase_size=256

2011年10月4日 星期二

Linux 底下好用的文字編輯器-Geany

在linux上,有很多編輯器像vi,vim,emacs,nano,gedit,gvim,有很多,如果是拿來寫code我看很多人都推vi或emacs,但是我也實在是不太會用,最多就是拿來改改小地方,完整用這些軟體來寫code我就敬而遠之,由於中windows的習慣,中毒實在太深了!所以不用圖型化的軟體實在是受不了!所以常用就用UltraEdit和Source Insight來寫code和看code,但是這兩個軟體在linux實在沒有什麼比較好的軟體可以用。在這之前我有用過gedit來編或是vim使用設定功能變成比較像ultraEdit但是用起來就是沒有那麼順手。kscope也沒有Source Insignt那麼習慣!
最近因為寫QT的,所以發現QtCreater也不錯用,引導功能也不錯!又有人推Geany裝了一下覺得不錯用更像UltraEdit功能不錯!

在ubuntu下安裝udo apt-get install geany
在windows也發現一套不用錯,又不比UltraEdit差的軟體"PSPad" - 功能超強的免費編輯器
http://www.pspad.com/en/download.php可以下載到,也是要推一下!


所以整理兩套文字編輯器
1.linux 下geany網址https://launchpad.net/%7Egeany-dev/+archive/ppa

2.在windows下PSPadEdit網址在http://www.pspad.com/en/download.php
可以提供作為使用上的參考。

2011年1月23日 星期日

移植IPv6

轉文自http://uw714doc.sco.com/en/SDK_netapi/sockD.PortIPv6examples.html

看來IPv4與IPv6在Socket軟體的寫作上有些不太一樣的地方。

1. gethostbyname(argv[1]);是在IPv4上使用。
gethostbyname2(argv[1], AF_INET6);是在IPv6上使用。

2. struct sockaddr_in server; 是在IPv4上使用的結構
struct sockaddr_in6 server;是在IPv6上使用的結構
s = socket(AF_INET6, SOCK_STREAM, 0);是在IPv6上建立socket使用。

3.細部分的不同就參考下面的程式吧!
4.如果軟體在寫作上有明顯的不同參數設定,即表示協構上相同,但是指令上應該是不相容吧!


Porting IPv6 -- examples


Consider the following IPv4 code examples:

IPv4 client code


   #include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdio.h>
#include <netdb.h>
...
main(argc, argv) /* client side */
int argc;
char *argv[];
{
struct sockaddr_in server;
struct servent *sp;
struct hostent *hp;
int s;
...
sp = getservbyname("login", "tcp");
if (sp == NULL) {
fprintf(stderr, "rlogin: tcp/login: unknown service\n");
exit(1);
}
hp = gethostbyname(argv[1]);
if (hp == NULL) {
fprintf(stderr, "rlogin: %s: unknown host\n", argv[1]);
exit(2);
}
memset((char *)&server, 0, sizeof(server));
memcpy((char *)&server.sin_addr, hp->h_addr, hp->h_length);
server.sin_len = sizeof(server);
server.sin_family = hp->h_addrtype;
server.sin_port = sp->s_port;
s = socket(AF_INET, SOCK_STREAM, 0);
if (s < 0) {
perror("rlogin: socket");
exit(3);
}
...
/* Connect does the bind for us */
if (connect(s, (struct sockaddr *)&server, sizeof(server)) < 0) {
perror("rlogin: connect");
exit(5);
}
...
exit(0);
}

IPv4 server code


   #include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdio.h>
#include <netdb.h>
...
main(argc, argv) /* server side */
int argc;
char *argv[];
{
int f;
struct sockaddr_in from;
struct sockaddr_in sin;
struct servent *sp;


sp = getservbyname("login", "tcp");
if (sp == NULL) {
fprintf(stderr,
"rlogind: tcp/login: unknown service\n");
exit(1);
}
...
#ifndef DEBUG
/* Disassociate server from controlling terminal. */
...
#endif


memset((char *)&sin, 0, sizeof(sin));
sin.sin_len = sizeof(sockaddr_in);
sin.sin_port = sp->s_port; /* Restricted port */
sin.sin_addr.s_addr = INADDR_ANY;
...
f = socket(AF_INET, SOCK_STREAM, 0);
...
if (bind(f, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
...
}
...
listen(f, 5);
for (;;) {
int g, len = sizeof(from);


g = accept(f, (struct sockaddr *) &from, &len);
if (g < 0) {
if (errno != EINTR)
syslog(LOG_ERR, "rlogind: accept: %m");
continue;
}
if (fork() == 0) {
close(f);
doit(g, &from);
}
close(g);
}
exit(0);
}

This code can be ported to IPv6 with only a small number of changes.
These changes are highlighted in the examples below by comments in the code.

IPv4 client code ported to IPv6


   #include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdio.h>
#include <netdb.h>
...
main(argc, argv) /* client side */
int argc;
char *argv[];
{
/* */
/* OLD code: struct sockaddr_in server; */
/* */
/* Change structure to sockaddr_in6 from sockaddr_in. */
/* */
struct sockaddr_in6 server;
struct servent *sp;
struct hostent *hp;
int s;
...
sp = getservbyname("login", "tcp");
if (sp == NULL) {
fprintf(stderr, "rlogin: tcp/login: unknown service\n");
exit(1);
}


/* */
/* OLD code: hp = gethostbyname(argv[1]); */
/* */
/* Use gethostbyname2 instead of gethostbyname. */
/* */
hp = gethostbyname2(argv[1], AF_INET6);
if (hp == NULL) {
fprintf(stderr, "rlogin: %s: unknown host\n", argv[1]);
exit(2);
}
memset((char *)&server, 0, sizeof(server));


/* */
/* OLD code: Not applicable. */
/* */
/* If the len member was not in the original IPv4 code*/
/* add it now and make sure it is sin6_len for IPv6. */
/* */
server.sin6_len = sizeof(server);


/* */
/* OLD code: memcpy((char *)&server.sin_addr, ... */
/* OLD code: server.sin_family = hp->h_addrtype; */
/* OLD code: server.sin_port = sp->s_port; */
/* */
/* Make sure you are using sockaddr_in6 members. */
/* */
memcpy((char *)&server.sin6_addr, hp->h_addr, hp->h_length);
server.sin6_family = hp->h_addrtype;
server.sin6_port = sp->s_port;


/* */
/* OLD code: s = socket(AF_INET, SOCK_STREAM, 0); */
/* */
/* Use the correct address family for IPv6. */
/* */
s = socket(AF_INET6, SOCK_STREAM, 0);
if (s < 0) {
perror("rlogin: socket");
exit(3);
}
...
/* Connect does the bind for us */
if (connect(s, (struct sockaddr *)&server, sizeof(server)) < 0) {
perror("rlogin: connect");
exit(5);
}
...
exit(0);
}





NOTE: In the assignments to server.sin6_addr and
server.sin6_family hp->h_length will always be
equal to sizeof(struct in6addr) and hp->h_addrtype will
always be equal to AF_INET6.




IPv4 server code ported to IPv6


   #include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdio.h>
#include <netdb.h>
...
main(argc, argv) /* server side */
int argc;
char *argv[];
{
int f;


/* */
/* OLD code: struct sockaddr_in from; */
/* OLD code: struct sockaddr_in sin; */
/* */
/* Change structure to sockaddr_in6 from sockaddr_in. */
/* */
struct sockaddr_in6 from;
struct sockaddr_in6 sin;
struct servent *sp;


sp = getservbyname("login", "tcp");
if (sp == NULL) {
fprintf(stderr,
"rlogind: tcp/login: unknown service\n");
exit(1);
}
...
#ifndef DEBUG
/* Disassociate server from controlling terminal. */
...
#endif


memset((char *)&sin, 0, sizeof(sin));


/* */
/* OLD code: Not applicable. */
/* */
/* If the len member was not in the original IPv4 code*/
/* add it now and make sure it is sin6_len for IPv6. */
/* */
sin.sin6_len = sizeof(sin);


/* */
/* OLD code: sin.sin_port = sp->s_port; */
/* */
/* Make sure you are using sockaddr_in6 members. */
/* */
sin.sin6_port = sp->s_port; /* Restricted port */


/* */
/* OLD code: sin.sin_addr.s_addr = INADDR_ANY; */
/* */
/* Make the modifications for assigning in6addr_any to*/
/* sin6_addr. */
/* */
sin.sin6_addr = in6addr_any;
...


/* */
/* OLD code: f = socket(AF_INET, SOCK_STREAM, 0); */
/* */
/* Use the correct address family for IPv6. */
/* */
f = socket(AF_INET6, SOCK_STREAM, 0);
...
if (bind(f, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
...
}
...
listen(f, 5);
for (;;) {
int g, len = sizeof(from);


g = accept(f, (struct sockaddr *) &from, &len);
if (g < 0) {
if (errno != EINTR)
syslog(LOG_ERR, "rlogind: accept: %m");
continue;
}
if (fork() == 0) {
close(f);
doit(g, &from);
}
close(g);
}
exit(0);
}

As can be seen in the two IPv6 ported examples, there are only a few
changes required to port IPv4 applications to IPv6. You may want to go one step
further and use the new getaddrinfo(3N)
and getnameinfo(3N)
functions to make your IPv6 application more portable. The following examples
show how you could modify the client and server examples to use getaddrinfo(3N).

IPv6 client code using getaddrinfo


   #include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdio.h>
#include <netdb.h>


main(argc, argv) /* client side */
int argc;
char *argv[];
{
struct addrinfo req, *ans;
int code, s;


req.ai_flags = 0;


req.ai_family = PF_INET6; /* Same as AF_INET6. */
req.ai_socktype = SOCK_STREAM;


/* */
/* Use default protocol (in this case tcp) */
/* */
req.ai_protocol = 0;
if ((code = getaddrinfo(argv[1], "login", &req, &ans)) != 0) {
fprintf(stderr, "rlogin: getaddrinfo failed code %d\n",
code);
exit(1);
}


/* */
/* ans must contain at least one addrinfo, use */
/* the first. */
/* */
s = socket(ans->ai_family, ans->ai_socktype, ans->ai_protocol);
if (s < 0) {
perror("rlogin: socket");
exit(3);
}


...


/* Connect does the bind for us */
if (connect (s, ans->ai_addr, ans->ai_addrlen) < 0) {
perror("rlogin: connect");
exit(5);
}


...

/* */
/* Free answers after use */
/* */
freeaddrinfo(ans);


/* ... */


exit(0);
}


IPv6 server code using getaddrinfo


   #include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdio.h>
#include <netdb.h>


main(argc, argv) /* server side */
int argc;
char *argv[];
{
struct sockaddr_in6 from;
struct addrinfo req, *ans;
int code, f, len;


/* */
/* Set ai_flags to AI_PASSIVE to indicate that return */
/* address is suitable for bind() */
/* */
req.ai_flags = AI_PASSIVE;


req.ai_family = PF_INET6; /* Same as AF_INET6. */


req.ai_socktype = SOCK_STREAM;
req.ai_protocol = 0;


if ((code = getaddrinfo(NULL, "login", &req, &ans)) != 0) {
fprintf(stderr, "rlogind: getaddrinfo failed code %d\n",
code);
exit(1);
}


...


#ifndef DEBUG
/* Disassociate server from controlling terminal. */
...
#endif


/* */
/* ans must contain at least one addrinfo, use */
/* the first. */
/* */
f = socket(ans->ai_family, ans->ai_socktype, ans->ai_protocol);
...


if (bind(f, ans->ai_addr, ans->ai_addrlen) < 0) {
...
}


listen(f, 5);
for (;;) {
int g, len = sizeof(from);


g = accept(f, (struct sockaddr *) &from, &len);
if (g < 0) {
if (errno != EINTR)
syslog(LOG_ERR, "rlogind: accept: %m");
continue;
}
if (fork() == 0) {
close(f);
doit(g, &from);
}
close(g);
}


/* */
/* Free answers after use */
/* */
freeaddrinfo(ans);
exit(0);
}

2011年1月12日 星期三

玩玩Android的Sensor

1自重Wii與iphone問世後,手機上的操作已經不限於傳統的手機的,目前使用android+HTC Desire HD來作開發!
其實可以用的sensor還不少

TYPE_ACCELEROMETER :加速感測器
TYPE_ALL :使用所有的感測器
TYPE_GRAVITY :重力感測器
TYPE_GYROSCOPE :陀螺儀傳感器
TYPE_LIGHT :亮度感測器
TYPE_LINEAR_ACCELERATION:線性加速感測器
TYPE_MAGNETIC_FIELD 磁場感測器
TYPE_ORIENTATION : 方向傳感器
TYPE_PRESSURE:壓力感測器
TYPE_PROXIMITY:接近感測器

TYPE_ROTATION_VECTOR 旋轉向量傳感器
TYPE_TEMPERATURE:溫度感測器

不過在的我HTC上溫度感測器跟壓力感測器這兩個東西好像沒有什麼作用!
下次寫的時候把所有的參數直接顯示在畫面上,看看每一個感測器反應出來的意思有什麼不一樣!