안드로이드 소스





* intent 사용예제

// 1. 어떤 이름인지 모를 때. (클래스 이름을 모를때)
// 필터를 줄 수 있다. 서버의 manifest.xml의 service -> intent-filter -> action에 넣어야 한다. 
Intent i = new Intent("com.google.p.server.REMOTE_SERVICE");

// 2. 클래스 이름을 알고 있을 때.
//             Intent i = new Intent(IMyService.class.getName());



* bind


생명주기













  이미지 출처 
     http://shadowxx.egloos.com/10726222
    http://blog.naver.com/mirnae/100101468187




* aidl

http://developer.android.com/guide/developing/tools/aidl.html

aidl 매니저가  aidl 파일을 일고 stub 코드를 알아서 생성
client가 쓸 수 있는 proxy 코드와 server가 쓸 수 있는  stub 코드를 생성한다.


package com.google.p.server;

interface IMyService {
 int getStatus();
}




=> gen 디렉토리 밑에 자동으로 파일을 생성되어 있다.


/*
 * This file is auto-generated.  DO NOT MODIFY.
 * Original file: C:\\AndroidP\\eclipse\\workspaces\\RemoteServerClient\\src\\com\\google\\p\\server\\IMyService.aidl
 */
package com.google.p.server;
public interface IMyService extends android.os.IInterface
{
/** Local-side IPC implementation stub class. */
public static abstract class Stub extends android.os.Binder implements com.google.p.server.IMyService
{
private static final java.lang.String DESCRIPTOR = "com.google.p.server.IMyService";
/** Construct the stub at attach it to the interface. */
public Stub()
{
this.attachInterface(this, DESCRIPTOR);
}
/**
 * Cast an IBinder object into an com.google.p.server.IMyService interface,
 * generating a proxy if needed.
 */

public static com.google.p.server.IMyService asInterface(android.os.IBinder obj)
{
if ((obj==null)) {
return null;
}
android.os.IInterface iin = (android.os.IInterface)obj.queryLocalInterface(DESCRIPTOR);
if (((iin!=null)&&(iin instanceof com.google.p.server.IMyService))) {
return ((com.google.p.server.IMyService)iin);
}
return new com.google.p.server.IMyService.Stub.Proxy(obj);
}
public android.os.IBinder asBinder()
{
return this;
}
@Override public boolean onTransact(int code, android.os.Parcel data, android.os.Parcel reply, int flags) throws android.os.RemoteException
{
switch (code)
{
case INTERFACE_TRANSACTION:
{
reply.writeString(DESCRIPTOR);
return true;
}
case TRANSACTION_getStatus:
{
data.enforceInterface(DESCRIPTOR);
int _result = this.getStatus();
reply.writeNoException();
reply.writeInt(_result);
return true;
}
}
return super.onTransact(code, data, reply, flags);
}
private static class Proxy implements com.google.p.server.IMyService
{
private android.os.IBinder mRemote;
Proxy(android.os.IBinder remote)
{
mRemote = remote;
}
public android.os.IBinder asBinder()
{
return mRemote;
}
public java.lang.String getInterfaceDescriptor()
{
return DESCRIPTOR;
}
public int getStatus() throws android.os.RemoteException
{
android.os.Parcel _data = android.os.Parcel.obtain();
android.os.Parcel _reply = android.os.Parcel.obtain();
int _result;
try {
_data.writeInterfaceToken(DESCRIPTOR);
mRemote.transact(Stub.TRANSACTION_getStatus, _data, _reply, 0);
_reply.readException();
_result = _reply.readInt();
}
finally {
_reply.recycle();
_data.recycle();
}
return _result;
}
}
static final int TRANSACTION_getStatus = (android.os.IBinder.FIRST_CALL_TRANSACTION + 0);
}
public int getStatus() throws android.os.RemoteException;
}





* manifest.xml 

 service에 remote 설정하고 프로세스 단위의 통신이 된다.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.google.p.client"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="8" />

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".AIDLClient"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <service android:name="com.google.p.server.MyService" android:process=":remote" >
            <intent-filter>
                <action android:name="com.google.p.server.REMOTE_SERVICE"></action>
            </intent-filter>
        </service>

    </application>
</manifest>




어플을 올리고, bind 가 되게 한 후(start binding),
 DDMS로 확인하니. 아래와 같이 remote 프로세스가 뜨는지 확인


adb shell로 들어가서, proc 정보를 본다.



어느 파일들을 읽고 있나 본다.
app_process 프로세스와 binder , dalvk 관련 내용들이  보인다.



결국 이런 개념이 됨
 remoteservice.jpg


(이미지 출처 : http://liveeasily.dothome.co.kr/wiki/doku.php?id=android_service)



---------------------------------

인사이드 안드로이드 의 8장 안드로이드 서비스 프레임워크
(네이티브) 샘플 소스를 보드에 넣어보고 테스트해 보기


HelloWorld 시스템 소스



1. 복사를 먼저 한다. 
1)  include 파일은 소스디렉토리\frameworks\base\include 에 include에  복사
2) libs 파일은 소스디렉토리\\frameworks\base\libs 에 libs 에 복사
3) helloworld client 소스는 소스디렉토리\\frameworks\base\helloworld 에 복사

2. 다음은 전체 컴파일을 한다.  

소스디렉토리 # ./build_android.sh 

3. output이 정상적으로 나왔는지 확인
소스디렉토리\out\target\product\sv210\system\lib 밑에 보면,libhelloworld.so 파일이 들어가 있다.


서비스와 클라이언트 파일이 정상적으로 만들어졌는지 본다.

 

4. 이미지 복사
소스빌드디렉토리에서 (out\target\product\sv210)  root.img, system.img 파일을 복사하여 이미지를 다운받기 좋은 곳으로 보낸다.
기존에 있던 bootloader  zImage 파일도 복사해 둔다.


5. 이미지 다운로드
Hybus 보드에 그 이미지를 넣는다.  odin 같은거 없고, 벤더에서 준 ndw.exe 라는 파일을 이용한다.
드라이버 설치하고 나서, 내 컴의 ndw.exe 를 실행한다.

1) nand init
nand scrub
nand erase 80000 FF80000

2) kernel write
nand erase 600000 500000
dnw c0008000
[내 컴의 ndw.exe] Select USB Port -> Transmit -> Transmit -> Select zImage
nand write c0008000 600000 500000

3) root.img write
nand erase b00000 500000
dnw 40000000
[내 컴의 ndw.exe]  Select USB Port -> Transmit -> Transmit -> Select root.img
nand write.yaffs 40000000 b00000 <byte size of system.img>

4) system.img write
nand erase 1000000 5a00000
dnw 40000000
[내 컴의 ndw.exe]  Select USB Port -> Transmit -> Transmit -> Select system.img
nand write.yaffs 40000000 1000000  <byte size of system.img>

5) reset
(Hybus를 재시작한다.)


6. adb shell로 명령어를 통해 디바이스로 접근하고 실행해 본다.

# cd /system/bin
# ./helloworldservide &
# ./helloworldclient
hello, world




--------------------------------------------------

안드로이스 시스템 서비스 예제

vender 디렉토리에 넣고, 그 부분만 컴파일 하기

소스



zip을 풀고, 소스 디렉토리\external 아래로 복사하고 빌드한다.
hybus의 기계이름은 HyBus_sv210이다.

# .  build/envsetup.sh
# chooseproduct  HyBus_sv210
# mmm  external/ExService3

make 파일처럼 out\target\product\sv210\system\lib 디렉토리에 libSQRS03.so이 나왔다.

(vender depedent)
4. Hybus 에서는 yaffs로 system  이미지를 바꿔야 한다. system.img를 yaffs 파일시스템 형식으로 변환

소스디렉토리/vendor# ./mkyaffs2image  /work/android_froyo_sv210/out/target/product/sv210/system system.img
system 디렉토리를 yaffs 파일시스템형식으로 img 파일을 복사한다.

(원형    # vendor/mkyaffs2image  system  system.img )


4. 빌드 결과 이미지를 타깃 시스템에 올린다.

1) nand init
nand scrub
nand erase 80000 FF80000

2) kernel write
nand erase 600000 500000
dnw c0008000
[내 컴의 ndw.exe] Select USB Port -> Transmit -> Transmit -> Select zImage
nand write c0008000 600000 500000

3) root.img write
nand erase b00000 500000
dnw 40000000
[내 컴의 ndw.exe]  Select USB Port -> Transmit -> Transmit -> Select root.img
nand write.yaffs 40000000 b00000 <byte size of system.img>

4) system.img write
nand erase 1000000 5a00000
dnw 40000000
[내 컴의 ndw.exe]  Select USB Port -> Transmit -> Transmit -> Select system.img
nand write.yaffs 40000000 1000000  <byte size of system.img>

5) reset
(Hybus를 재시작한다.)


5. 결과 확인
#adb shell로 접근한다.

 


6. server 실행하기

  # logcat &

  # addserver03 &

7. client 실행하기

  # sqrtest3





Posted by '김용환'
,

역시 안드로이드가 아이폰보다 자유도가 좋았다. 안드로이드 쓰는 이유가 있다. !!
마인드스톰 NXT를 콘트롤 할 수 있는 안드로이드 App으로 로 다양하게 테스트해보았다.
관련된 어플 소개.

이 중에 가장 마음에 든 것은 중력센서를 이용한 것과 두개의 폰을 이용해서 마인드스톰을 가지고 통제하는 것이다. 



* nxt remote control  
심플
 어플 다운받기 : http://www.appbrain.com/app/nxt-remote-control/org.jfedor.nxtremotecontrol
 소스 : http://code.google.com/p/nxt-remote-control/

Screenshot of NXT Remote Control



* lego nxt build controller 
모터나 센서에 연결해서 마이크로틱하게 움직일 수 있게 하나, 불편하다. 
(App Inventor 구글 코드 소스였군)
어플 다운받기 : http://www.appbrain.com/app/build-controller-for-nxt/appinventor.ai_norfeldt.LEGO_NXT_Build_Controller
소스 : http://appinventor.googlelabs.com/learn/tutorials/ (정확한것은 아님)
 Screenshot of Build Controller for NXT


* nxt gsensor remote (마음에 듦)
안드로이드 중력 센서를 이용해서 콘트롤 
어플 다운받기 http://www.appbrain.com/app/nxt-gsensor-remote/NXT.GSensor
Screenshot of NXT GSensor Remote


* nxt simple remote
심플
어플 다운받기 : http://www.appbrain.com/app/nxt-simple-remote/NXT.Simple
 Screenshot of NXT Simple Remote
 

* NXT Numeric Remote 
심플 (메일박스로 통신하는 것 같은데..^^;;; )
어플 다운받기 :  http://www.appbrain.com/app/nxt-numeric-remote/NXT.BTNumeric
Screenshot of NXT Numeric Remote


* NXT Mailbox Remote 
어플 다운받기 : http://www.appbrain.com/app/nxt-mailbox-remote/NXT.BTMailbox
 Screenshot of NXT Mailbox Remote

 
* MINDdroid (마음에 듦)
중력 센서 이용, 
어플 다운 :  http://www.appbrain.com/app/minddroid/com.lego.minddroid
 Screenshot of MINDdroid


* NXT Bluetooth Remote Control 
동작은 되는데, A 모터만 돔. 버그 있는듯..
http://www.appbrain.com/app/nxt-bluetooth-remote-control/src.nabr
 Screenshot of NXT Bluetooth Remote Control


* NXT Free
mailbox로 메시지 전달하는데, 따로 어플이 있어야 하나..


* NXT Shake It
통신 연결은 되는데, 작동은 안됨...
어플 다운 : http://www.appbrain.com/app/nxt-shake-it/appinventor.ai_sebastian_trella.NXT_Shake_it


* NXT Speech Control
좋은 기능같은데, 내 발음이 문제가 있는지. 작동이 안되네.. 휴..
어플 다운 : 
http://www.appbrain.com/app/nxt-speech-control/appinventor.ai_sebastian_trella.NXT_Sprachsteuerung_free
Screenshot of NXT Speech Control


* Robobot
작동 안됨
http://www.appbrain.com/app/robobot/org.embox.robobot


*  Stream-O-bot  (마음에 듦)
두개의 안드로이드 폰을 이용해서 nxt를 콘트롤 함.  굿!
하나는 controller, 하나는 카메라로 사용. 카메라를 보면서 운전할 수 있도록 함
어플 다운 : http://www.appbrain.com/app/stream-o-bot/edu.snc.android.mindstorm
Screenshot of Stream-O-Bot

동영상 
http://www.youtube.com/watch?feature=player_embedded&v=C5MSQ-LV40I
 

* SenseBot Lego Mindstorm NXT 
 다운을 받고 싶은데, App 마켓에 없어서 실패.
어플 다운 : http://www.appbrain.com/app/sensebot-lego-mindstorm-nxt/com.msi.manning.ua2esensebot
Screenshot of SenseBot  Lego Mindstorm NXTScreenshot of SenseBot  Lego Mindstorm NXT

안드로이드 인 액션에 들어가는 책에 들어가는 어플이란다. 
http://manning.com/ableson2


*cellbot
여러 로봇을 합쳐서 한번에 동작시키는 툴 (그냥 폰하나와 마인드스톰만 있으면 평범..하지만, 동영상 보면 쿨~~)
어플 다운 : http://www.appbrain.com/app/cellbots/com.cellbots
Screenshot of Cellbots

http://www.youtube.com/watch?v=_x_5WDCpvtA&feature=player_embedded


* NxtRemote
동영상을 보면 괜찮은 것 같음. 
Screenshot of NxtRemote
$3.17. 
어플 다운 : http://www.appbrain.com/app/nxtremote/com.smartphoneremote.nxtremote
 http://www.youtube.com/watch?v=bCBzSsjoSqc&feature=player_embedded



Posted by '김용환'
,