2010年11月21日 星期日

framework

在完成Android系統上函式庫層的D2MCE原生碼實作之後,我們將於框架層將設計出方便應用程式開發所用的Java元件。該元件對上提供方便使用的類別與介面及方法,對下則透過JNI與函式庫層的原生碼整合。以下是預計提供的介面類別的宣告與使用方式。


Android D2MCE Java 套件:

import com.eps.d2mce;

說明:Android應用程式引入此套件方可使用D2MCE服務與元件

Android D2MCE執行時期服務取得:

D2MCEManager mD2Mgr = D2MCE.getService("group_name");

說明:若應用程式需使用D2MCE的服務,則透過D2MCE的靜態方法getService()將可加入一名為"group_name"的運算群組。該方法將傳回一D2MCE管理者物件。

Android D2MCE 共享物件宣告與配置

D2MCESharedData mSharedData =

new D2MCESharedData(mD2Mgr, "data_name");

說明:D2MCE將提供一泛形(generic)共享物件類別,在配置共享物件時指定所共享的資料形態(SomeType),建構子中指定D2MCE管理者(代表D2MCE運算群組)與共享資料名稱即可完成配置。(資料大小由SomeType型別決定。)

Android D2MCE 共享物件內容存取

SomeType value = mySharedData.getValue();

mySharedData.setValue(value);

說明:D2MCESharedData類別將提供getValue與setValue方法,用來存取實際型態為SomeType的共享資料內容值。

Android D2MCE 共享物件存取同步方法

mySharedData.lock();

mySharedData.unlock();

說明:D2MCESharedData類別將提供lock與unlock方法,用來實現分散式共享資料存取所需的同步與臨界區間(critical section)運作。(這部分無法使用Java的Synchronized方法與程式區塊的方式實現,而須另行提供,因為我們所面對的環境是分散式的環境,而非單一機器的多執行緒環境。)

以上為Android D2MCE實作應該提供的基本的元件類別。除此之外,我們也應該允許程式開發者透過繼承D2MCESharedData類別的方式來定義自己的共享物件類別;而在資料存取的同步問題,亦可在子類別中定義專用的存取方法,將lock與unlock的同步機制包含於實作中,方便使用。

2010年9月12日 星期日

d2mce_mutex_rw



d2mce_mutex_rw(&mutex, 4, A, "rw", B, "rw", initialized, "rw", schedule_index, "rw");

這是幹嘛用的


其實就是
d2mce_mutex_lock( &mutex);
d2mce_load ( A );
d2mce_load ( initialized);
d2mce_load ( schedule_index );
的合起來


再問一個d2mce_mutex_rw(&mutex, 1,initialized,"r");
這個是什麼組合?

d2mce_mutex_rw(&mutex, 1,initialized,"r");
                   
裡面的 &mutex  是指 mutex_lock 的變數
1 是指 後面有一個 共享變數
那個共享變數叫 initialized

然後 只可以 "r"  = load
rw 就是 可以 load 也可以 store

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>