2010年8月9日 星期一

D2MCE 簡易實作步驟

https://pms.eps.csie.ntut.edu.tw/trac/d2mce/wiki/Reference
https://pms.eps.csie.ntut.edu.tw/svn/d2mce/


d2mce在64bit機器上會壞掉
只能在32bit上執行


首先利用svn下載至電腦上
#apt-get install subversion
#svn co https://pms.eps.csie.ntut.edu.tw/svn/d2mce/


編譯D2MCE
#cd /d2mce/trunk
#./configure --prefix=/opt/d2mce
#make
#make install


要先在home目錄底下mkdir一個.d2mce_conf且裡面要有d2mce.conf
#~/.d2mce_conf/d2mce.conf
這個檔案用來設定用哪一個port哪一個網卡
若沒有這個檔案執行檔案時會出現

root@nisun:/d2mce/trunk/examples/matrix-d2mce-dynamic# ./matrix 
can't not open /root/.d2mce_conf/d2mce.conf
Error: read_config() failed.
d2mce init failured

所以要先做
#cd ~
#mkdir .d2mce_conf
#cd .d2mce_conf

#vim d2mce.conf
編輯內容

network_device eth0
port 55660
然後:wq
port最好大於1024

接下來還要再開一個程式
在/opt/d2mce/bin內的d2mced
這是一個daemon用來控制整個group
所以必須先開daemon
#/opt/d2mce/bin/d2mced

接下來就可以執行程式了
我們執行一個example
#cd /d2mce/trunk/examples/matrix-d2mce-dynamic
#make
#./matrix
可以看到結果

Vector Size:512
Matrix size:262144
Processing time:1.956712
msg count:184
msg byte :5474
daemon exit ok!!


若有error while loading shared libraries: libd2mce.so.0: cannot open shared object file: No such file or directory
需要先在/sbin裡
打ldconfig /opt/d2mce/lib/


2010年2月9日 星期二

Android Activity Life Cycle Demo



public class LifeCycleTest extends Activity {
    private static final String TAG = "ActivityLifeTest";

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Log.v(TAG, "onCreate");
        
        Uri uri = Uri.parse("http://maps.google.com/maps?f=d&saddr=startLat%20startLng&daddr=endLat%20endLng&hl=en");  
        Intent it = new Intent(Intent.ACTION_VIEW, uri);  
        startActivity(it);  
    }

    public void onStart() {
        super.onStart();
        Log.v(TAG, "onStart");
    }

    public void onResume() {
        super.onResume();
        Log.v(TAG, "onResume");
    }

    public void onPause() {
        super.onPause();
        Log.v(TAG, "onPause");
    }

    public void onStop() {
        super.onStop();
        Log.v(TAG, "onStop");
    }

    public void onRestart() {
        super.onRestart();
        Log.v(TAG, "onReStart");
    }

    public void onDestroy() {
        super.onDestroy();
        Log.v(TAG, "onDestroy");
    }
}








First, new a project with Google APIs.
Then, Run it.



We can see that Log:ActivityLifeTest is onPause now. It means the Intent start another Activity.
If we press “BACK”, Activity:LifeCycleTest will resume again.


Now, restart the Activity, and press “Maps”.



We can find out that Activity:LifeCycleTest  is stopped. It means Activity:LifeCycleTest  is no longer visible.

Finally, press “BACK” to the Activity:LifeCycleTest, and Activity:LifeCycleTest will restart.





If we leave the Activity:LifeCycleTest, Activity:LifeCycleTest will be destroyed.





Reference:
http://stenlyho.blogspot.com/search/label/Android
http://code.google.com/p/androidbmi/wiki/LifeCycle
http://developer.android.com/intl/zh-TW/guide/topics/fundamentals.html
üW





üWe

2010年2月4日 星期四

Run linux kernel on PXA270



After the connection between host and hardware devices, we install the driver so that we can use host's COM to connect the device.
go http://www.squarechair.net/arkmicro/ first,
then go to http://www.cpu.com.tw/kh/comp/usb/usb4.html download drivers.
Install both, and you can see one more COM at 裝置管理員 




We need shared folders between Windows and VirtualBox.

Fisrt,
    Turn on the Virtual Box.








Right click at the red block of following picture.





Logout and login
Then type sudo mount.vboxsf "windows shared folder name" "linux shared folder path"




Copy file to the shared folders.
    \critical\research_Embedded\Creator PXA270 v107\Linux\bin\arm-linux-toolchain-bin.4.0.2.tar.gz
    \critical\research_Embedded\Creator PXA270 v107\Linux\src\linux-2.6.15.3-creator-pxa270.patch
    \critical\research_Embedded\Creator PXA270 v107\Linux\src\mt-linux-2.6.15.3.tar.gz


look at linux..






Then we need install tool chain first.
PDF at \critical\research_Embedded\Creator PXA270 v107\Linux\Doc
                       \Linux for Creator-XScale-PXA270 User Guide.pdf
see chapter 2-1-3
Turn on the Linux Terminal
Type:
    $cp /arm-linux-toolchain-bin.4.0.2.tar.gz /
    $cd /
    $tar -zxvf arm-linux-toolchain-bin.4.0.2.tar.gz


    $vim /etc/bash.bashrc


Add the following text at the end of bash.bashrc
    PATH=/opt/microtime/pro/devkit/arm/pxa270/gcc-4.0.2-glibc-2.3.3/arm-unknown-linux-gnu/bin:$PATH
    export PATH

Turn off the terminal, and restart it.
Test by typing arm- [tab] [tab]
you will see 


Now, install Creator-XSale-PXA270 kernel source and file patch
see the Linux for Creator-XScale-PXA270 User Guide.pdf chapter 3
We can ignore 3-2-2: set root filesystem.

Turn on 超級終端機 on windows.








Turn on the PXA270.











set pxa270 ip and server(windows) ip.(at 超級終端機)
    $setenv ipaddr xxx.xxx.xxx.www
    $setenv serverip yyy.yyy.yyy.zzz
note: xxx.xxx.xxx must be the same as yyy.yyy.yyy
    $saveenv

We need tftp to push uImage in pxa270.
So, download tftp server at http://tftpd32.jounin.net/
and we put uImage at tftp shared folder.
note: uImage at linux /usr/src/microtime/build-linux/output/flash_boot/uImage








Type command at 超級終端機:
    $tftp 0xa1000000 uImage
    $bootm 0xa1000000


Done!
Result:






Reference:

2010年2月3日 星期三

JBox2D Demo on Eclipse



  • In Eclipse: 
  • Open New->Java project->create project from existing source
  • Type project name and browse the file which is extracted from Pendulum_src.zip => finish
  • Create a folder /lib/ at project
  • Right Click on /lib, select Import 
  • Select General / File System 
  • Choose the directory of 
  • Import the file jbox2d.jar 
  • Right click on the project and select "Properties" 
  • Click on "Java Build Path" and select the "Libraries" tab 
  • Click on "Add JARs..." and pick the file



After some sets.
result:


2010年1月31日 星期日

Mp3Player With Service

Activity:

public class Mp3PlayerWithService extends Activity implements OnClickListener {
private static final String TAG = "Mp3Interface";
private static Mp3PlayerWithService appRef = null;

private ImageButton btn, btn2, btn3;
public TextView tv;
private IBinder ib;

public static Mp3PlayerWithService getApp() {
return appRef;
}

public void btEvent(String data) {
setTitle(data);
}

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
appRef = this;

btn = (ImageButton) findViewById(R.id.PlayMP3);
btn2 = (ImageButton) findViewById(R.id.Stop);
btn3 = (ImageButton) findViewById(R.id.exit);
btn.setId(101);
btn2.setId(102);
btn3.setId(103);

btn.setOnClickListener(this);
btn2.setOnClickListener(this);
btn3.setOnClickListener(this);

tv = (TextView) findViewById(R.id.TextView01);
tv.setText("Ready");

bindService(new Intent(Mp3PlayerWithService.this, mp3Service.class),
mContection, Context.BIND_AUTO_CREATE);
}

private ServiceConnection mContection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName className, IBinder ibinder) {
ib = ibinder;
tv.setText(className.toString());
}

@Override
public void onServiceDisconnected(ComponentName className) {
}
};

public void onClick(View v) {
switch (v.getId()) {
case 101:
try {
ib.transact(1, null, null, 0);
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
break;
case 102:
try {
ib.transact(2, null, null, 0);
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
break;
case 103:
finish();
break;
}
}
}

Binder:


public class mp3PlayerBinder extends Binder{
private MediaPlayer mPlayer = null;
private Context ctx;

public mp3PlayerBinder(Context cx){
ctx = cx; }
@Override
public boolean onTransact(int code, Parcel data, Parcel reply, int flags){
if(code == 1)
this.play();
else if(code == 2)
this.stop();
return true;
}
public void play(){
if(mPlayer != null)
return;
mPlayer = MediaPlayer.create(ctx, R.raw.test);
mPlayer.start();
}
public void stop(){
if(mPlayer != null){
mPlayer.stop();
mPlayer.release();
mPlayer = null;
}
}
}

Service:


public class mp3Service extends Service{
private IBinder mBinder = null;
@Override
public void onCreate(){
mBinder = new mp3PlayerBinder(getApplicationContext());
}
@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return mBinder;
}
}

layout:



?xml version="1.0" encoding="utf-8"?>
LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
TextView android:text="@+id/TextView01" android:id="@+id/TextView01"
android:layout_width="wrap_content" android:layout_height="wrap_content">
LinearLayout android:orientation="horizontal"
android:layout_height="wrap_content" android:layout_width="fill_parent">
ImageButton android:id="@+id/PlayMP3"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:src="@drawable/play" />
ImageButton android:id="@+id/Stop" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:src="@drawable/stop" />
ImageButton android:id="@+id/exit" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:src="@drawable/exit" />
      /LinearLayout>
/LinearLayout>