2013年6月29日 星期六

PiPO M3 刷機過程


若沒有要備份原有的 img 可跳到第四點…

一、安裝 android adb tools、android usb driver…

二、下載安裝 Moborobo,安裝 adb Driver


三、下載 romdump
http://android.podtwo.com/romdump/

在 dos command 底下執行下列 scripts

adb push romdump /data/local/
adb shell chmod 04755 /data/local/romdump
adb shell /data/local/romdump


會將 android 裝置 dump 到 sd card 上。

四、下載官方升級工具及韌體…
http://www.pipo.cn/index.php?m=Contact&a=index&id=248&type=3
http://www.pipo.cn/index.php?m=About&a=gujian

五、下載 img 解包打包工具…
http://www.mobile01.com/topicdetail.php?f=605&t=3032201&p=1

六、將官方 img 改名後放到打包工具目錄,執行 RK3066.exe,選擇解開 img

七、作需要的修改

八、再打包

七、使用官方升級工具 update img
 

2013年6月27日 星期四

Android 中如何在自己的 APP 應用程序調用另一個 APP 應用程序

列出手機上安裝的 apk,透過 debug 訊息找到 package name…

                PackageManager pm = getPackageManager();  
                for (ApplicationInfo app : pm.getInstalledApplications(0)) {  
                 Log.d("PackageList", "package: " + app.packageName + ", sourceDir: " + app.sourceDir);  
                }  

使用 Intent 啟動 app…

                PackageManager pm = getPackageManager();  
                Intent intent = pm.getLaunchIntentForPackage("com.example.helloworld");  
                startActivity(intent);  

2013年6月17日 星期一

Google Maps Android API v2 APP 開發步驟

網路上很多 Google Maps Android API v2 相關文章,但有各種不同講法,自己試了 1-2 個禮拜都沒有成功,最後結合網路找的資料跟 android sdk 內附的 maps 範例程式,總算成功試出來了,因此作下記錄。

準備工作…
一、建立 keystore 並取出 SHA1 碼。
 到 jre bin 目錄下 C:\Program Files\Java\jre6\bin\
 建立 keysor…
  keytool -genkey -v -keystore yourkeyname.keystore -alias yourkeyname -keyalg RSA -keysize 2048 -validity 10000
 取出 sha1 碼…
  keytool -list -v -keystore yourkeyname.keystore > save_sha1.txt
  打開 save_sha1.txt 找到 sha1 碼
      SHA1:xx:xx:xx…

二、到 Google apis 申請 API key
 到 https://code.google.com/apis/console/
 Create project
 Services 中 google Maps Android API v2 點一下 off 改成 on
 API Access 中「Create new Android key」
  輸入「sha1碼」+「;」+「your_package_name
  產生出 API key…
   Key for Android apps (with certificates)
   API key:AIzaSyB1yoElxxxxxxxx...

三、打開 Android SDK Manager 安裝  Google Play services,在 extra 底下。
 
四、將  google-play-services_lib import 進 Workspace。
 在 SDK 安裝目錄下 \extras\google\google_play_services\libproject\google-play-services_lib

開發專案…
一、建立新專案。

二、將 google-play-services_lib 函式庫加入專案中。
 project > properties >Android Library , Add。

三、順便將 Android Lint Preferences > Correctness:Messages 中 Missing Translation 改為 Ignore。(忽略多國語言未翻譯的錯誤)

四、修改 AndroidManifest.xml,加入權限及 API key。
 application 內加入 api key…
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
                    android:value="AIzaSyB1yoElxxxxxxxx..."/>

 接著 application 底下加入權限設定…
    <permission
        android:name="your_package_name.permission.MAPS_RECEIVE"
        android:protectionLevel="signature"/>
    <uses-permission android:name="your_package_name.permission.MAPS_RECEIVE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-feature android:glEsVersion="0x00020000" android:required="true"/>


五、修改 activIty_main.xml,內容改成底下,最簡易 layout,只用 fragment …
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/map"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  class="com.google.android.gms.maps.SupportMapFragment"/>


 六、MainActivity.java 範例…
public class MainActivity  extends FragmentActivity {

    private GoogleMap mMap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        setUpMapIfNeeded();
    }

    @Override
    protected void onResume() {
        super.onResume();
        setUpMapIfNeeded();
    }

    private void setUpMapIfNeeded() {
        // Do a null check to confirm that we have not already instantiated the map.
        if (mMap == null) {
            // Try to obtain the map from the SupportMapFragment.
            mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
                    .getMap();
            // Check if we were successful in obtaining the map.
            if (mMap != null) {
                setUpMap();
            }
        }
    }
    private void setUpMap() {
        mMap.setMyLocationEnabled(true);
    }

} 

註:API LEVEL 8 以上 Android 2.2 以上才能支援 Google Play services。
註:keystore 可以用自己產生的(release用),也可以用 debug 的。(在 C:\Documents and Settings\USER\.android\debug.keystore)

2013年5月30日 星期四

ENC28J60+UIP1.0 TCI/IP Stack 接收 UDP 廣播封包

要讓 ENC28J60+UIP1.0 TCI/IP Stack 接收 UDP 廣播封包的方式…

一、UIP 修改 configure 檔 uip-conf.h
    #define UIP_CONF_BROADCAST            1

二、ENC28J60 的部份在設定 FILTER 時要禁用 FILTER。

不接收廣播訊息要設定如下,找到設置 FILTER 的程式碼,mark 掉才能聽廣播…

    //接收過濾器
    //UCEN:單播過濾器使能位
    //當ANDOR = 1 時:
    //1 = 目標地址與本地MAC 地址不匹配的數據包將被丟棄
    //0 = 禁止過濾器
    //當ANDOR = 0 時:
    //1 = 目標地址與本地MAC 地址匹配的數據包會被接受
    //0 = 禁止過濾器

    //CRCEN:後過濾器CRC 校驗使能位
    //1 = 所有CRC 無效的數據包都將被丟棄
    //0 = 不考慮CRC 是否有效
   
    //PMEN:格式匹配過濾器使能位
    //當ANDOR = 1 時:
    //1 = 數據包必須符合格式匹配條件,否則將被丟棄
    //0 = 禁止過濾器
    //當ANDOR = 0 時:
    //1 = 符合格式匹配條件的數據包將被接受
    //0 = 禁止過濾器
    enc28j60Write(ERXFCON, ERXFCON_UCEN|ERXFCON_CRCEN|ERXFCON_PMEN);
    enc28j60Write(EPMM0, 0x3f);
    enc28j60Write(EPMM1, 0x30);
    enc28j60Write(EPMCSL, 0xf9);
    enc28j60Write(EPMCSH, 0xf7);


三、UIP 建立 Connection…
    uip_ipaddr_t ipaddr;  
    struct uip_udp_conn * conn;
   
    uip_ipaddr( ipaddr, 0, 0,0, 0 );
    conn = uip_udp_new( &ipaddr, HTONS( 0 ) );
    if( conn != NULL )
            uip_udp_bind( conn, HTONS( MY_UDP_PORT ) );

2013年5月24日 星期五

socket + pthread 資源佔用情形解決

socket + pthread 資源佔用情形解決

在使用 pthread_create 建立 thread 處理 socket 的時候要注意,縱使 socket close 了,資源還是會被 thread 佔用住,此時要採用分離式 thread,才能在 thread 結束時自動釋放資源,最簡單的方式是建立 thread 後設定為 detach。

    while (1)
    {
        newsockfd = accept(sockfd,
                (struct sockaddr *) &cli_addr, &clilen);
        if (newsockfd < 0)
            exit(1);
        pthread_t thread1;
        pthread_create(&thread1, NULL, doSocketThread, &newsockfd );
        pthread_detach(thread1);
    }

2013年5月23日 星期四

Flex Socket Policy

新版的 Flex 支援 socket 通訊,但需要有自己的 Policy Server,好讓 Flex 有連線需求時進行 Policy 認證(透過 port:843)。

一、建立 socketpolicy.pl 檔,內容如下…
############################################################################
#!/usr/bin/perl -wT
#
# Simple Flash Socket Policy Server
# http://www.lightsphere.com/dev/articles/flash_socket_policy.html
#
# Copyright (C) 2008 Jacqueline Kira Hamilton
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see .


use Socket;
use IO::Handle;

my $should_be_logging = 1;  # change to 0 to turn off logging.

my $logfile = 'log';

if ($should_be_logging) {
    open(LOG, ">$logfile") or warn "Can't open $logfile: $!\n";
    LOG->autoflush(1);
}

my $port = 843;
my $proto = getprotobyname('tcp');

# start the server:

      &log("Starting server on port $port");
    socket(Server, PF_INET, SOCK_STREAM, $proto) or die "socket: $!";
setsockopt(Server, SOL_SOCKET, SO_REUSEADDR, 1 ) or die "setsockopt: $!";
      bind(Server,sockaddr_in($port,INADDR_ANY)) or die "bind: $!";
    listen(Server,SOMAXCONN) or die "listen: $!";

    Server->autoflush( 1 );

my $paddr;
&log("Server started. Waiting for connections.");

$/ = "\0";      # reset terminator to null char

# listening loop.

for ( ; $paddr = accept(Client,Server); close Client) {
    Client->autoflush(1);
    my($port,$iaddr) = sockaddr_in($paddr);
    my $ip_address   = inet_ntoa($iaddr);
    my $name         = gethostbyaddr($iaddr,AF_INET) || $ip_address;
    &log( scalar localtime() . ": Connection from $name" );
 
    my $line = ;
    &log("Input: $line");

    if ($line =~ /.*policy\-file.*/i) {
        print Client &xml_policy;
    }
}

sub xml_policy {
    my $str = qq(\0);
    return $str;
}

sub log {
    my($msg) = @_;
    if ($should_be_logging) {
        print LOG $msg,"\n";
    }
}
############################################################################
 
二、在你的 server 上執行…
sudo ./socketpolicy.pl > /dev/null &


2013年5月16日 星期四

Raspberry Pi + Cross Compiler + MySQL

要在 Cross Compiler 上建立 MySQL Connect API 的編譯環境
必須要有 .h include 檔及 mysqlclient lib 檔。

一、先在 Raspberry Pi 下載 MySql connector for C
 wget  http://lgallardo.com/wp-content/uploads/files/programming/mysql-connector-c-6.0.2.tar.gz

二、解壓縮
 tar xvzf mysql-connector-c-6.0.2.tar.gz
 cd mysql-connector-c-6.0.2
 
三、安裝 cmake
 sudo aptitude install cmake
 
四、產出 makefile 檔,其中「install_path」自定義
 cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=/install_path 
 
五、make 需要很久的時間
 
六、make install
 
七、確認是否正確安裝
 file /install_path/lib/libmysql.so.16.0.0 
 

八、將 /install_path 底下所有東西 copy 至 cross compiler host 機上。
 

九、範例程式…
    #include <mysql.h>
    MYSQL      *MySQLConRet;
    MYSQL      *MySQLConnection = NULL;
    MySQLConnection = mysql_init( NULL );

    MySQLConRet = mysql_real_connect( MySQLConnection,
                                          hostName,
                                          userId,
                                          password,
                                          db_name,
                                          0,
                                          "/var/run/mysqld/mysqld.sock",
                                          0 );
 
 注意:socket位置預設是 /tmp/mysql.sock,需按你系統所在位置填入正確值否則會出現…
 runtime error:Can't connect to local MySQL server through socket '/tmp/mysql.sock' 
 socket位置可以在 /etc/mysql/my.cnf 或 /etc/mysql/debian.cnf 查詢到。
九、編譯時引入 mysqlclient 函式庫並增加 include 及 lib patch
 gcc client.c -o client  -I/install_path/include -L/install_path/lib -lmysqlclient
 
 ext. links…
http://lgallardo.com/en/2011/07/14/conector-mysql-para-openwrt-mips/
 
=================================================================================
較簡單的方法…
1.安裝開發工具…
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install libmysqlclient-dev
 
2.從 pi copy header 檔到開發環境,Eclipse 下增加 include path…
/usr/include/mysql

3.從 pi copy lib 檔到開發環境,Eclipse 下增加 lib path
使用指令查出 lib 位置…
mysql_config --libs
 
查出放在「/usr/lib/arm-linux-gnueabihf」底下,並在 linker command 增加 -lmysqlclient
libmysqlclient.a
libmysqlclient.so 

4.若缺少 libz (compress、uncompress) 亦需一併 copy 過去開發環境,並在 linker command 增加 -lz
libz.a
libz.so




VirtualBox 空間減肥

sdelete64 -z c: VBoxManage  modifymedium  disk  "/Users/fellow/VirtualBox VMs/Win10/Win10.vdi"  --compact *.vdi 路徑可以在 VirtualBox 儲...