2010年4月28日 星期三
Poison Candy
2010年4月27日 星期二
2010年4月26日 星期一
期交所 K 棒轉檔 4 upload
2010年4月25日 星期日
Linux Mouse Drivers
主要透過 Input Sub System 底下的 Input Core 建立 input_handler, 來處理 mousedev_event.之後在 Register 到 Linux 的 Kernel中.
2010年4月24日 星期六
Linux Driver Hello World
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
#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) cleancommand 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....
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 \">‎([^<.]*)<\/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;
}
2010年4月23日 星期五
Eclipse CDT + OpenOCD + OpenJTAG
OpenJTAG
2010年4月20日 星期二
J2ME Wireless Toolkit GPS (jsr179)
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月19日 星期一
2010年4月18日 星期日
eBlueShare
- obexftp
- Linux(Ubuntu)
- BlueZ
- usblib
- 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,
#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(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){ $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"; } } } } }
2010年4月14日 星期三
Shark System V1 pt3
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
2010年4月13日 星期二
Shark System V1 3~4 profits report
2010年4月12日 星期一
J2ME WirelessToolkit FileConnetion (JSR75)
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(); } }
J2ME + Eclipse + jar implement
2010年4月11日 星期日
J2ME Wireless Toolkit WMA (JSR102)
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
2010年4月7日 星期三
acer 5560 sawed
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=1Bluetooth sample code
- 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
結果: 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
2010年4月2日 星期五
Bluetooth case study
- 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.
2010年4月1日 星期四
Remote Player
download : http://sites.google.com/site/funningboy/java-1/monitor.rar?attredirects=0&d=1