2010年4月28日 星期三

Poison Candy

Poison Candy: Target: 1. 分析券商說的是真的還假的....不要傻傻的被騙摟.... 2. 找出券商跟股票的相關性, 判斷股價漲跌是否有特別的券商在炒作. tool: DDE : http://funningboy.blogspot.com/2010/02/sdde-server-v1.html Indicator : http://funningboy.blogspot.com/2010/03/auto-indicator-4-excel.html Google News: http://funningboy.blogspot.com/2010/04/googlenews.html Parameter Value CoFactorCls2Opn : 券商買賣超對open(開盤價)的影響 CoFactorCls2Hig : 券商買賣超對Close(收盤價)的影響 CoFactorCls2Lw : 券商買賣超對Low(最低價)的影響 Rule: ((open(t-1) - open(t)) > 0 && TraderID_Sell )? CoFactorCls2Opn++: CoFactorCls2Open--; 表示 券商(ID) 如果賣超,且今日開盤價低於昨日開盤價, CoFactorCls2Opn++; 反之 CoFactorCls2Opn--; Case 4 2324(仁寶) sheet : 2324_1440 : 仁寶 對 美林 的相關係數 sheet : 2324_1440 : 仁寶 對 瑞士信貸 的相關係數 sheet : 2324_total : 仁寶對 主力券商 相關係數 ex: (1440:美林) 券商ID 可到底下查詢: http://justdata.yuanta.com.tw/Z/ZG/ZGB/ZGB.asp.htm Rst: 發現 瑞士信貸, 美林, 高盛 對仁寶的 cofactor 影響很大, 且 港商麥格里 在低檔承接. Case 4 2330(台積電) Result : 每家券商都有各自擅長的股票操作方式, 藉由分析方式找到適當的進場位置.

2010年4月27日 星期二

2010年4月26日 星期一

期交所 K 棒轉檔 4 upload

Design Flow : PS: 轉檔器我們是用"Redjoe"所寫的台指期轉檔器在加以改良,加入upload file的功能, 提供下載備份跟回測的Data source. 轉檔器請參考 : Ref: http://redjoetseng.blogspot.com/ upload file : Google DOC api http://code.google.com/intl/zh-TW/apis/documents/docs/developers_guide.html Google DOC upload samle http://funningboy.blogspot.com/2010/03/google-upload-2-google-doc.html file Path: txf : 台指 mxf : 小台 fxf : 金指期 exf : 電指期 code : code location sample code : GoogleDOC.pl 4 upload my $upload_exf = &UpLoadFile($token,'exf','0B6XEwxVW8qCqZjBkYTgzMTQtMjBkMy00YjUwLTliMDAtNzZlODlhMmI5MzU5'); 紅色部分為upload的folder ID, sample code download http://sites.google.com/site/funningboy/perl_code/code.rar?attredirects=0&d=1 PS: 有需要的人我在開Share

2010年4月25日 星期日

Linux Mouse Drivers

Target : 了解 Linux 的Kernel 如何 Driver Hardware Device, 底下用 PS2 的滑鼠當範例. Path : Linux2.6.X/drivers/input 透過Trace mousedev.c 來了解Mouse Driver 4 Linux 是如何操作.

主要透過 Input Sub System 底下的 Input Core 建立 input_handler, 來處理 mousedev_event.之後在 Register 到 Linux 的 Kernel中.

Ref: http://bbs.weeqoo.com/bbsdetail-282613-4.html http://fred-zone.blogspot.com/2010/01/mouse-linux-kernel-driver.html

2010年4月24日 星期六

Linux Driver Hello World

Linux Driver 4 case study Driver 簡單的說就是Software Hardware control. Software 端 Handle application Hardware 端 Handle Device 假設現在要用到USB 來存取 ( "Read", "Write"...) Data, 就必須要有USB 的Driver 來驅動 USB 的硬體裝置,把Data寫入記憶體某個區塊的位置. Ex: 簡單的說 Driver 就是把 Software 轉成 Hardware 看的懂的control Software part: USB->Write(unsigned int address,unsigned int data ); Hardware part: bin 0x00ed001c-o0oocdf1; 00ed001 : address; o0oocdf1 : data 而每個Driver會對 Kernel註冊,藉由Kernel來Handle Program 2 Driver / Driver 2 Program. Kernel 指的是一個提供硬體抽象層, 磁碟及檔案系統控制, 多工等功能的系統軟體,包含了驅動主機各項硬體的偵測程式與驅動模組.

The main features of a driver are:

  • It performs input/output (I/O) management.

  • It provides transparent device management, avoiding low-level programming (ports).

  • It increases I/O speed, because usually it has been optimized.

  • It includes software and hardware error management.

  • It allows concurrent access to the hardware by several processes

Linux Driver Ref: http://www.linuxjournal.com/article/2476?page=0,0 Kernel Ref: http://linux.vbird.org/linux_basic/0540kernel.php#intro_whatiskernel 底下用最簡單的 Hello World 當例子 init : initial 驅動初始化 module : 為我們要對Kernel 註冊的模組,定義value, structure. kernel : 為Linux 的核心中的模型和定義 module_init : 為我們的進入點,有點像 main function. module_exit: 為出場點 Path : \include\linux\Init.h hello.c
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>

static int hello_init(void) {
  printk("<1> Hello world!\n");
  return 0;
}

static void hello_exit(void) {
  printk("<1> Bye, cruel world\n");
}

module_init(hello_init);
module_exit(hello_exit);
Makefile
obj-m += hello.o

all:
 make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
 make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
command line %make %modinfo hello*.ko result filename: hello.ko srcversion: C5BB518CD1B8222581499DF depends: vermagic: 2.6.31-20-generic SMP mod_unload modversions 586 Ref: http://www.tldp.org/LDP/lkmpg/2.6/html/

GoogleNews....

Target : 在股票分析法則下,我們分成三大層面來分析, 分別是"技術", "基本", "新聞",用此來決定這隻股票本質的好壞. Ex: Case 1 Entry Point = 0.5*技術 + 0.3*基本 + 0.2*新聞 Case 2 Entry Point = 0.2*技術 + 0.5*基本+ 0.3*新聞 Case 1 >= 0,5 ? Entry : NOP Case 2 > 0.7 ? Entry : NOP 在Case 1, Case 2下,分別代表我們對這3個影響因子的比重. 在Case 1中表示 技術 > 基本 > 新聞,在技術線型( KD, RSI, WR, OBV...)對我們來說特別重要,只要Case 1的結果 >=0.5 就進場,不然就等待(NOP). 以此類推Case 2 Previous Case: 假設"基本", "技術"都為已知的, 這邊只討論如何處理"新聞面"的資訊 基本, 技術 可參考 http://funningboy.blogspot.com/search/label/stock Ref: http://www.perl.com/pub/a/2006/01/19/analyzing_html.html http://search.cpan.org/~tbone/HTML-Element-Library-4.2.b/lib/HTML/Element/Library.pod PS: Perl regular expression 中文處理 ([^<]*) 中文處理 Big5 -> UTF8 http://www.jeffhung.net/blog/articles/jeffhung/417/ sample code:
sub get_news_for_topic {

    my $topic = $_[0];

    my $url = "http://news.google.com.tw/news?hl=zh-TW&ned=ttw&q=$topic";
    my $ua = LWP::UserAgent->new();
    $ua->agent('Mozilla/5.0');

    my $response = $ua->get($url);
   return unless $response->is_success;

    my $content = $response->decoded_content;
    $content = $response->content if (not defined $content);
   
   #$content = encode('utf-8', decode('big5', $content));
 
   $content =~ s/<font color=\"\#CC0033\">//g;
   $content =~ s/<\/font>//g;
   
  my $tree = HTML::TreeBuilder::XPath->new;
     $tree->parse($content);
     $tree->eof;
     #$tree->dump;
   
     my $items=$tree->findnodes_as_string( '//div[@class[.=~/story/]]');
   
     my @class = split("
\n",$items);
    #  print $class[1];
     my $stu;
     my ($href,$title,$date,$st,$ID);
     my %result;
     $ID =0;

     for( my $i=0; $i <= $#class; $i++){
            if($class[$i] =~ m/href=\"(\S+)\"/                              ){ $href  = $1; $stu=1; }
            if($class[$i] =~ m/target=\"_blank\">([^<.]*)<\/a><\/h2>/       ){ $title = $1; $stu=2; }
            if($class[$i] =~ m/span class=\"date \">&#8206;([^<.]*)<\/span><\/div>/){ $date  = $1; $stu=3; }
            if($class[$i] =~ m/class=\"snippet\">([^<.]*)<b>\.\.\.<\/b>/    ){ $st    = $1; $stu=4; }
           
            if($stu==4){
                 $result{$ID} = {
                   "
href"   => $href,
                   "
title"  => $title,
                   "
date"   => $date,
                   "
st"     => $st,
                 };
                $ID++;
           }
     }
     
    $tree->delete;
   
    return \%result;
}
 
結果 date::2010年4月21日 title::富比世全球2000大企業 台灣39家入榜 鴻海排名最高 st:: 排名最高的是第176 名的電子代工龍頭鴻海(2317-TW),其次分別為台積電(2330-TW)、台塑(1301-TW)、中鋼(2002-TW)、中華電信(2412-TW) 與友達(2409-TW)等。 特別的是,總排名第810 名的宏碁(2353-TW),同時也列名130 家「全球成長表現優異」(Global High Performer) 排行榜 href::http://news.cnyes.com/Content/20100422/KC8Q1MUMP84VU.shtml?c=tw_stock sample code download http://sites.google.com/site/funningboy/perl_code/GoogleNews.pl?attredirects=0&d=1

2010年4月23日 星期五

Eclipse CDT + OpenOCD + OpenJTAG

Eclipse CDT + OpenOCD + OpenJTAG for ARM Debug ENV SoftWare: IDE : Eclipse CDT Debug: OpenOCD GNU/ cross compiler(ARM)... Ref: OpenOCD : http://www.yagarto.de/index.html Eclipse : http://www.eclipse.org/ 安裝下載 YAGARTO GNU ARM toolchain, YAGARTO Tools , Integrated Development Environment 請記得把 bin, include, lib 加入Windows 的path 中 Check all install is ok % openocd -version % arm-elf-gcc --version %make -v HardWare: OpenJTAG http://funningboy.blogspot.com/2010/04/openjtag.html
Design flow:
Hardware
ID(4). openJTG (usb 2 JTAG) Software ID(1). OpenOCD : 為 ID(4)OpenJTAG(FTD2xx) Driver, name xxx.dll ID(2). ARM-ELF-GDB (cross compiler), compile code 2 ARM Based Env ID(3) IDE(Design Env) TCP connect (Remote Debuge) http://funningboy.blogspot.com/2010/02/gdb-debug.html

Detail Flow : 利用 Cross Compiler 做出Arm code 的bin檔, 假設現在我們要存取在記憶體區段 0x2006D4 的Data.利用GDB做斷點分析, 單步, Run...來做 Remote Debug. 透過OpenOCD Lib 轉成USB Protocol 的Series Data . USB control http://funningboy.blogspot.com/2010/03/usb-device.html OpenJTAG 內會把 Series Data Parse 成 Parallel Data, TDI, TDO, TMS.... JTAG methodology http://funningboy.blogspot.com/2010/02/jtag.html All pic ref: Using Open Source Tools for AT91SAM7S Cross Development 除了用usb 2 JTAG 之外, 也可以用 Print Port 2 JTAG 做 Parallel Debug Ref : http://funningboy.blogspot.com/2010/02/print-port-control.html 或者你可以選擇更簡單的模擬環境 UrJTAG http://urjtag.sourceforge.net/ 裡面有需多開發好的套件跟Lib Flow: Detect Cable Device Detect Target Device Shift IR Shift DR .... GDB Debug...interrupt, go ....

OpenJTAG

OpenJTAG and JLink : 1. Env Support: Same: usb 2 JTAG or rs232 2 JTAG
Difference: OpenJTAG : 可以用在Windows,Linux下. JLink : 只能用在Windows下,
2.IDE Env:
OpenJTAG : 能用在所有支持GDB工具上, 比如IAR. Eclipse. winarm. 不能用在支持RDI的工具上.比如ADS。
JLink : 支持多種工具 RDI. GDB, 幾乎所有Windows下的工具都支持, 比如ADS. Keil MDK. IAR
3. Flash burn OpenJTAG. JLink對FLASH的燒入差不多 Ref: http://www.openjtag.net/index.php?title=Main_Page Ref: http://www.study-kit.com/list.asp?ProdId=0181

2010年4月20日 星期二

J2ME Wireless Toolkit GPS (jsr179)

Target: GPS application
Design Flow: 1. 利用 J2ME Wireless Toolkit (JSR179),取得經緯度位置, La = get Latitude(); //取得緯度 Ln = get Longitude(); //取得經度 2.在用Html request的方式透過http://tinygeocoder.com/create-api.php?g=”+lat+”,”+lon,取得我們易懂的位置. La = 33.790348 Ln = 117.226085 example: http://tinygeocoder.com/create-api.php?g=33.790348,-117.226085 3. 最後可以結合 Google Map Display. Flow Chart Sample Code: Get La,Ln
        Coordinates c;
        // Set criteria for selecting a location provider:
        // accurate to 500 meters horizontally
        Criteria cr= new Criteria();
        cr.setHorizontalAccuracy(5000);
        cr.setVerticalAccuracy(5000);
    // Get an instance of the provider
        lp= LocationProvider.getInstance(cr);

        // Request the location, setting a one-minute timeout
        l = lp.getLocation(120);
        c = l.getQualifiedCoordinates();

        if(c != null ) {
          // Use coordinate information
          double La = c.getLatitude();
          double Ln = c.getLongitude();
          string = "\nLatitude : " + La + "\nLongitude : " + Ln;
          new GetData(midlet,La,Ln).start();

        } else {
            string ="Location API failed";
        }

2010年4月18日 星期日

eBlueShare

Propose : the idea is from Windows's Coffee Table, using the wireless communication bridge, that can be a interface from our "Host (PC)" to our "Client 3c Devices" without "line"..... PS: the 3c Device must support wireless communication Target : Blue Tooth Sharing Environments : toool libs
  • obexftp
  • Linux(Ubuntu)
  • BlueZ
  • usblib
obexftp Ref: http://funningboy.blogspot.com/2010/04/obexftp-4-blueftp.html Ubuntu Ref: http://packages.ubuntu.com/dapper/bluez-utils usb Ref: http://funningboy.blogspot.com/2010/03/usb-device.html Devices: Sony Ericsson k530i Acer aspire 5560 PS: this is one way design, only downloaded data from K530i to our local PC, you can adjust it in both ways Design Flow:
  • GetFolderRoot(); Get the Root of our Device, like Phone Disk or SD Card...
  • GetFolderList(); Get the Children of Root folder, like music, photo...
  • GetFileFmDifFolder(); Get each leaf file of Child folder,
Sample Code: GetFileFmDifFolder(); language: Perl
#Step3 get all folder file in different cat
sub GetFileFmDifFolder{

my ($key,$a);
foreach ( sort keys %folderlths){
$key = $_;
foreach $a (@{$folderlths{$key}}){
system "obexftp -b $DeviceID -l \"$key\/$a\"  > catlt.xml";
system "mkdir $a";

open(ifolder,"catlt.xml")  die "open cat.xml error";

my $cont=();
while(){
$cont = $cont.$_;
}

# create a xml object for the response

  my $xml = new XML::Simple(KeyAttr=>[]);

  my $tree = $xml->XMLin($cont);


  my ($e,$j,$k);

  #print Dumper($tree);


  foreach $e ($tree->{"file"}){
    foreach $j (@{$e}){
       $k = $j->{"name"};
       system "obexftp -c \"$key\/$a\" -g $k";
       system "mv $k $a";
   }
 }
}
}

}
sample code download http://sites.google.com/site/funningboy/perl_code/obexftp.pl?attredirects=0&d=1 Execute Result: Ref: http://indiangeek.com/blog/?tag=w810i

2010年4月14日 星期三

Shark System V1 pt3

Support 1. period for super sell 40 2. indicators support KD, RSI, MV, OBV 3. Fast Length, Slow Length K(9), D(9) RSIF(9), RSIS(24) MV(9), MV(24) OBV(9),OBV(24) PS: using MV average line to plot upper and lower band, that can be define our entry point and leave point. 4. Result : OBV*0.3 + MV*0.3 + KD*0.2 + RSI*0.2 sample code 4 KD entry( perl ) , it would get the inf from our "indicator generator 4 Excel", indicator Ref : http://funningboy.blogspot.com/2010/03/auto-indicator-4-excel.html
 sub GetKDEntryRst{
 my ($MyCurK,$MyCurD);
 my ($MyPreK,$MyPreD);
 my ($MyPosK,$MyPosD) =(0,0);
 my ($MyNegK,$MyNegD) =(0,0);
 my $MyKDRst =0;
    
    
  for(my $i= $MyPeriod-2; $i<=$MyPeriod; $i++){  
    $MyPreK = $sheet->Cells($i-1,'L')->{Value}; 
    $MyPreD = $sheet->Cells($i-1,'M')->{Value}; 
 
    $MyCurK = $sheet->Cells($i,'L')->{Value}; 
    $MyCurD = $sheet->Cells($i,'M')->{Value};
    
    #Trend
    # constrain K,D<=35;
    if( $MyCurK<=35 && $MyCurD<=35 ){
     if($MyPreK<=$MyCurK){ $MyPosK++; }
     else{                 $MyNegK++; }
     
     if($MyPreD<=$MyCurD){ $MyPosD++; }
     else{                 $MyNegD++; }
     }
   }
   
    if(($MyPosK+$MyPosD) > ($MyNegK+$MyNegD)){ $MyKDRst=1; }
      
    #print "$MyPosK,$MyPosD,$MyNegK,$MyNegD\n";
    
    return $MyKDRst;
 }

GA Rst 2 Excel

把GA Rst 轉成易讀的 Excel 檔 http://sites.google.com/site/funningboy/perl_code/ParseGaRst2csv.pl?attredirects=0&d=1 Ref : http://funningboy.blogspot.com/2010/03/max-drop-down-test.html PS: 純粹是個人健忘,怕忘記,所以紀錄一下.....

2010年4月13日 星期二

Shark System V1 3~4 profits report

Shark System V1 3~4 profits report Shark V1 Ref: http://funningboy.blogspot.com/2010/03/shark-system-v1-pt1.html http://funningboy.blogspot.com/2010/03/shark-system-v1-pt2.html http://shark4finance.blogspot.com/ 因為是反轉系統,似乎少了點判斷機制,不然在 -7% 不會立刻停損出場. 且在績效上表現普普,雖然沒有大賺,也沒有賠錢.但似乎持股時間有點過長. 可能原因 (1) : 主力賣壓尚未結束,頭部尚未形成. (2): 打底時間過長. (3): 權值股,拉台不易... 解決方式 (1): 加入主力連續買超機制,且是在底部吃貨情況. (2): 底部在 T-10 天內出現跟長紅量, 且現金股價不破前端長紅的當日收盤價. (3): 加入期指判斷, 如果其貨幣險因子過大,就必須等期貨結算之後,再找標地. web ref: http://spreadsheets.google.com/pub?key=tVbSy-YZo3nHjnunhpZlbVQ&single=true&gid=0&output=html

2010年4月12日 星期一

J2ME WirelessToolkit FileConnetion (JSR75)

JSR75 sample code (file connection)
1. file beowser
code from wireless toolkit PDADemo
    void showCurrDir() {
        Enumeration e;
        FileConnection currDir = null;
        List browser;

        try {
            if (MEGA_ROOT.equals(currDirName)) {
                e = FileSystemRegistry.listRoots();
                browser = new List(currDirName, List.IMPLICIT);
            } else {
                currDir = (FileConnection)Connector.open("file://localhost/" + currDirName);
                e = currDir.list();
                browser = new List(currDirName, List.IMPLICIT);
                // not root - draw UP_DIRECTORY
                browser.append(UP_DIRECTORY, dirIcon);
            }

            while (e.hasMoreElements()) {
                String fileName = (String)e.nextElement();

                if (fileName.charAt(fileName.length() - 1) == SEP) {
                    // This is directory
                    browser.append(fileName, dirIcon);
                } else {
                    // this is regular file
                    browser.append(fileName, fileIcon);
                }
            }

            browser.setSelectCommand(view);

            //Do not allow creating files/directories beside root
            if (!MEGA_ROOT.equals(currDirName)) {
                browser.addCommand(prop);
                browser.addCommand(creat);
                browser.addCommand(delete);
            }

            browser.addCommand(exit);

            browser.setCommandListener(this);

            if (currDir != null) {
                currDir.close();
            }

            Display.getDisplay(this).setCurrent(browser);
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
    }
2. connect list

J2ME + Eclipse + jar implement

J2ME + Eclipse 安裝流程可參考. http://changyy.pixnet.net/blog/post/25766488 安裝完成後,可用Hellow World做測試,記得在HelloWorld.jad底下做class link,不然模擬器會找不到確切的位置. 會造成"com.sun.kvem.midletsuite.InvalidJadException: Reason = 22" Error. 用 HelloWorld(project named) -> J2ME -> Create Package 來產生 .jar檔. 最後put .jar到你的Cell Phone上,就可以work了.
how to handle the "com.sun.kvem.midletsuite.InvalidJadException: Reason = 22",
you can reference

2010年4月11日 星期日

J2ME Wireless Toolkit WMA (JSR102)

Wireless Toolkit for JSR J2ME 的Entry point (commandAction),像是 *.java 的main. 其中定義了App start, pause,destroy. 可以在內部填入我們所要的method... public void commandAction(Command cmd, Displayable disp) {} protected void startApp() { } protected void pauseApp() {} protected void destroyApp(boolean bool) {} 在Entry point (commandAction)會check 現在所輸入的command,如Exit , Send Message.... 每個command 會有對應的class, 有點像是Action listen的動作. 底下是 SMS Sender的範例,會定義要傳的Address(Cell Phone Number), Message 內容... SMS Sender.java
public void run() {
        String address = destinationAddress;

        MessageConnection smsconn = null;

        try {
            /** Open the message connection. */
            smsconn = (MessageConnection)Connector.open(address);

            TextMessage txtmessage =
                (TextMessage)smsconn.newMessage(MessageConnection.TEXT_MESSAGE);
            txtmessage.setAddress(address);
            txtmessage.setPayloadText(messageBox.getString());
            smsconn.send(txtmessage);
        } catch (Throwable t) {
            System.out.println("Send caught: ");
            t.printStackTrace();
        }

        if (smsconn != null) {
            try {
                smsconn.close();
            } catch (IOException ioe) {
                System.out.println("Closing connection caught: ");
                ioe.printStackTrace();
            }
        }
    }
code ref: J2ME WMAdemo PS: 請把 port的地方拿掉, 因為我們沒有模擬Receive端透過port來做連接.

2010年4月8日 星期四

OBEXFTP 4 BlueFTP

Pic Ref: http://www.designftp.com/
BeWare:
1. make sure you have installed wiki:OpenObex? and wiki:BluezLib? 2. download obexftp here 3. extract the tarball to a temporary folder 4. execute the following %export OPENOBEX_LIBS="-L/usr/lib -lopenobex" %export OPENOBEX_CFLAGS="-I/usr/include/openobex/ -I/usr/include" %./configure --prefix=/usr %make %make install PS: the OBEXFTP not support java language currently, so we choice the perl language.
Perl
OBEXFTP install
OBEX FTP doc 4 perl
getting start with OBEXFTP

2010年4月7日 星期三

acer 5560 sawed

Pic Ref:
沒想到筆電的CMOS電池會沒電.真是有點扯..... 只好來把它肢解一下.... 好在現在又可以work了... PS: 不知道拿給acer修理要多少錢阿.... 看來自己修理應該是最省的

Bluetooth Player ...

Pic Ref: Bluetooth Player...

Tools

  • tool language : java
  • library : JSR82 (blue tooth lib)
  • : AVIDemo (jpeg 2 avi)
  • external tool : FFmpeg (media converter)

Ref: WebCam http://funningboy.blogspot.com/2010/04/remote-webcam-player.html Ref : image 2 vedio stream http://changyy.pixnet.net/blog/post/25435171 Ref: stream 2 flv/3gp http://www.unix-center.net/bbs/viewthread.phptid=16031 http://apocryph.org/2007/10/27/transcoding_avi_flv_ffmpeg/ http://goinggnu.wordpress.com/2007/02/13/convert-avi-to-3gp-using-ffmpeg/

Ref: Bluetooth http://funningboy.blogspot.com/2010/04/bluetooth-sample-code.html http://funningboy.blogspot.com/2010/04/bluetooth-case-study.html Ref : java call external .exe http://www.javaworld.com.tw/jute/post/view?bid=29&id=31477&sty=3

Target: we use our cell phone to display our media from our Webcam emulator. what's the WebCam emulator? you can ref our previous posted "Remote Player" http://funningboy.blogspot.com/2010/04/remote-web-player-pt1.html PS: "Webcam emulator" is a sample way to emulate the Webcam captured for each frame and stored it in "jpg" format. Design flow : the left hand side is our Webcam emulator and the right hand side is our image converted. both of them are independent, so we use the synchronous queues to our interface, that can commute the multi triggers by each time. Webcam emulator : always captured our frames in 1frame/100ms, and stored in jpg. Converter : always convert from jpgs 2 our media Bluetooth : communucation between our host and client. PS: the java api not support media stream for real time, so you use the media storage for a while time, if it finish and put it to our clint. Result : sample code download : http://sites.google.com/site/funningboy/java-1/jpg2avi_bluetooth.rar?attredirects=0&d=1

Bluetooth sample code

在Bluetooth 的傳輸的Protocl上.包括 RFCOMM 和 Object Exchange (OBEX) 兩種方式.底下就protocl 部分做個簡單的介紹 Ref: http://funningboy.blogspot.com/2010/04/bluetooth-case-study.html 藍芽通訊協定stack
  • HCI 主機控制器介面(Host Controller Interface). 主機(電腦)和控制器(藍芽設備)之間的介面.
  • L2CAP 邏輯連結控制器適配協定(Logical Link Controller Adaptation Protocol),這一層充當其他所有層的資料多工器.
  • BNEP 即藍芽網路封裝協定(Bluetooth Network Encapsulation Protocol) , 可以在藍芽上執行其他網路協定, 例如 IP、TCP 和 UDP.
  • RFCOMM 稱作虛擬串流通訊協定(virtual serial port protocol),因為它允許藍芽設備類比串流的功能
  • OBEX 通訊協定層是在 RFCOMM 層上面實作, 把資料以物件 "檔" (data) 的形式傳輸
  • SDP 是服務發現協定(Service Discovery Protocol)層,用於在遠端藍芽設備上尋找服務
  • AVCTP 和 AVDTP,用於藍芽上音頻和視頻的控制.

底下用 jsr82 來實現 RFCOMM.

Server.java

import java.io.*;
import javax.microedition.io.*;
import javax.bluetooth.*;

public class RFCOMMServer {

    public static void main( String args[] ) {
        try {
            String url = "btspp://localhost:" +
                new UUID( 0x1101 ).toString() +
                ";name=SampleServer";
            StreamConnectionNotifier service =
                (StreamConnectionNotifier) Connector.open( url );

            StreamConnection con =
                (StreamConnection) service.acceptAndOpen();
            OutputStream os = con.openOutputStream();
            InputStream is = con.openInputStream();

            String greeting = "JSR-82 RFCOMM server says hello";
            os.write( greeting.getBytes() );

            byte buffer[] = new byte[80];
            int bytes_read = is.read( buffer );
            String received = new String(buffer, 0, bytes_read);
            System.out.println("received: " + received);
         
            con.close();
        } catch ( IOException e ) {
            System.err.print(e.toString());
        }
    }
}

Client.java

import java.io.*;
import javax.microedition.io.*;
import javax.bluetooth.*;

public class RFCOMMClient {

    public static void main( String args[] ) {
        try {
            String url = "btspp://0123456789AB:3";

            StreamConnection con =
                (StreamConnection) Connector.open(url);

            OutputStream os = con.openOutputStream();
            InputStream is = con.openInputStream();

            String greeting = "JSR-82 RFCOMM client says hello";
            os.write( greeting.getBytes() );

            byte buffer[] = new byte[80];
            int bytes_read = is.read( buffer );
            String received = new String(buffer, 0, bytes_read);
            System.out.println("received: " + received);
         
            con.close();
        } catch ( IOException e ) {
            System.err.print(e.toString());
        }
    }
}

請注意 "url" 要改成你的 address & port.

如不知道,可用jsr 82所提供的 ServiceSearch.java

Ref: http://www.jsr82.com/

結果: BlueCove version 2.1.0 on winsock wait for device inquiry to complete... Device 001D289E7AFE found name K530i Device 2421AB354DC5 found Device 001E45B4779B found name Z610i Device Inquiry completed! 3 device(s) found BlueCove stack shutdown completed

2010年4月3日 星期六

Remote webcam player

this is our Remote WebCam exercise. each references and design methodologies you can find out below. WebCam Reference http://ltu164.ltu.edu/itseng/version.htm Socket && Display Reference http://funningboy.blogspot.com/2010/04/remote-web-player-pt1.html In WebCam part. we use it to capture our images from "Logitech WebCam" based on (1 frame)/100ms , and then put each frame to our communication interface(Socket). In Socket && Display part. we use it to receive our frame from Remote communication and display at the same time. hardware environment CPU : Intel Core 2 T2330(1.66G) RAM: 2G DDR2 simulation environment eclipse + java sdk 1.6 + jmf(java media frame) execution result in left hand side is our locate side and in the right hand side is our remote side. you can see a little delay between it.

2010年4月2日 星期五

Bluetooth case study

Pic Ref: http://en.wikipedia.org/wiki/Bluetooth
usage :
Bluetooth is a standard communications protocol primarily designed for low power consumption, with a short range (power-class-dependent: 100 m, 10 m and 1 m, but ranges vary in practice; see table below) based on low-cost transceiver microchips in each device.[5] Because the devices use a radio (broadcast) communications system, they do not have to be in line of sight of each other.[4]
Ref: http://en.wikipedia.org/wiki/Bluetooth
communication :
  • HCI is the Host Controller Interface. This layer is the interface between the radio and the host computer.
  • L2CAP stands for Logical Link Controller Adaptation Protocol. This layer is the multiplexer of all data passing through the unit. Audio signals, however, have direct access to the HCI.
  • SDP is the Service Discovery Protocol. The SDP layer is used to find services on remote Bluetooth devices.
  • RFCOMM is widely known as the virtual serial port protocol.
  • OBEX is the object exchange protocol.
The Bluetooth protocol is already define, so we only to take our software base on this, like data transfer or bluetooth voice communication ...
Refs:
eclipse + j2me install and path setting
bluez
bluecover
bluetooth api
http://www.jsr82.com/
jeme手機電腦連線程式

2010年4月1日 星期四

Remote Player

Pic Ref: http://www.freesharewaredepot.com/productpages/moyea-web-download-039249.asp Remote Web Player. Language : java Library : java -> socket (one 2 one) no application multi login java -> applet (display layout) Design flow : we separate two major parts for our "Server" and "Client". 1.Server part : we try to emulation the "webcam captured frames". (constrain : frame/2(s) ) if you would to know how to control the webcam in java, you can reference in http://www.javaworld.com.tw/jute/post/view?bid=5&id=266811 http://ltu164.ltu.edu/itseng/version.htm PS: In current case, we define our captured frames are already exist. and we use the "thread delay" function to emulate it - ("webcam captured"). you can use the "YouTube converter" to capture slide frames, that can convert "media stream" into "frames". http://benderconverter.com/ 2.Client part : Display 3.Queue : synchronous, lock ... that can handle multi clock domain and latency.

execution result :

download : http://sites.google.com/site/funningboy/java-1/monitor.rar?attredirects=0&d=1