2010年4月28日 星期三
Poison Candy
2010年4月27日 星期二
2010年4月26日 星期一
期交所 K 棒轉檔 4 upload
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
主要透過 Input Sub System 底下的 Input Core 建立 input_handler, 來處理 mousedev_event.之後在 Register 到 Linux 的 Kernel中.
2010年4月24日 星期六
Linux Driver Hello World
而每個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
#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....
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:
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
透過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 OpenJTAG
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
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(){
$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
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)
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/
2010年4月7日 星期三
acer 5560 sawed
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.Bluetooth 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
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
- 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
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.
download : http://sites.google.com/site/funningboy/java-1/monitor.rar?attredirects=0&d=1





