2010年12月12日 星期日

Population Count of a Uint32

When studying Android audio system, I saw a interest function code in google’s AndioSystem class:

uint32_t AudioSystem::popCount(uint32_t u)

{

    u = ((u&0x55555555) + ((u>>1)&0x55555555));

    u = ((u&0x33333333) + ((u>>2)&0x33333333));

    u = ((u&0x0f0f0f0f) + ((u>>4)&0x0f0f0f0f));

    u = ((u&0x00ff00ff) + ((u>>8)&0x00ff00ff));

    u = ( u&0x0000ffff) + (u>>16);

    return u;

}

Honestly, I cannot understand how this code come from. Fortunately, the code leave a reference link for us: http://www.df/lth/se/~john_e/gems/gem002d.html.

And telling the trust again, for me, it’s still hard to understand after reading the reference algorithm. So, I decide to make a node, and just copy the code when I need it ~ 吐舌頭.

2010年12月5日 星期日

會無好會

今天在參與了一個案子的 Kick-Off Meeting,會議過程亂七八糟,會議內容五花八門,會議目標模糊不清。真的是讓我上了一堂震撼教育,原來公司大頭們開會是這樣子開的喔!?

2010年11月28日 星期日

姓名學雜記

小孩快滿月了,最近正為了取名字傷透腦筋。雖說自己並不是很信那些算命、命理類的東西,但是基於旁人的要求與未了小孩好,還是不免要找找老師、做做功課。

本來想說做做功課比較不會被唬來唬去,沒想到一看下去,沒完沒了!一個姓名學五花八門、各行各派都有,你說我不準、我說你找碴。難怪最後大家都樂於花錢了事…

這邊是我的小小筆記:

五行相生:木生火、火生土、土生金、金生水、水生木

五行相剋:木剋土、土剋水、水剋火、火剋金、金剋木

五格:以名字三個字為例,姓的比畫加一為「天格」,姓與名的第一個字的比畫相加為「人格」,名字兩個字的比劃相加為「地格」,姓與名的第二個字的筆劃相加為「外格」,三個字的總比劃為「總格」。

五格與五行(熊崎):取五格的個位數,1與2 為木、3與4為火、5與6為土、7與8為金、9與0為水。其中基數為「陽」,偶數為「陰」。例如15劃為「陽土」。

五格與五行(河洛):從河洛的九宮圖而來,一樣取五格的個位數,1與6為水、2與7為火、3與8為木、4與9為金、0與5為土。可以看到一樣是五行,它與熊崎的數理五行定義不同,所以…

生肖姓名學:很多地方可以找到,不同的生肖有不同的適宜的、或是不好的字。例如虎落平陽,所以屬虎的不宜有「田」的字型;因為畫蛇添足,所以屬蛇的最好不要用有腳的形狀的字。目前主流去給老師算名字都可以聽到這一套,我想可能是最容易找到你名字的破綻吧。難怪它在網路上被姓稱為「找碴姓名學」。

字的五行:除了五格求出的五行外,每一個字也有它所對應的五行,有些是看形狀、有些看讀音、有些我壓根看不出來邏輯在哪(Orz)。我也不知道有甚麼書可以查到每個字的五行對應,有些算命書則會列出一些。

寫到這其實我已經頭昏眼花了,光一個五格的五行就有不一樣的解釋,在加上被戲稱為「找碴姓名學」的生肖姓名學,難怪每個老師都可以輕易推翻另外一個老師的命名來建議你改名。

我想,還是找個老師,錢花下去,他說啥就是啥吧~XD

2010年11月19日 星期五

台北慈濟婦產科

一個多禮拜前,老二順利的在台北慈濟醫院生下來了。家裡的兩個小孩都是在台北慈濟出生的,倒不是因為醫院有多好,而純粹只是對這個醫生還蠻滿意的,而且離家又比較近。

不過,第二次住進慈濟醫院的婦產科病房,之前第一胎時遇到的問題,果然也幾乎再次浮現,甚至,遇到更多。我不清楚這到底是不是通例,畢竟我只有兩個小孩…

2010年11月15日 星期一

Wi-fi 干擾與 AP Channel 設定

最近為了一些原因看了一些有關 WiFi 的文章,赫然發現原來 WiFi 這麼容易遇到干擾啊。也順便了解了之前設定 Wireless AP 時,一直不知道那是幹啥用的 channel 是啥。

原來 Wifi 把 2.4GHz (~2.483GHz) 的頻段切割成 11 (依照國家不同,有些切到 15)個頻段,每一個頻段就是一個 channel。因為相同頻率的信號波會互相干擾,所以當同一個地點有兩個無線訊號使用相同 channel 時,802.11 設計了一套避免干擾的方法,那就是:等別人用完了再用!

簡單的說,就是發射訊號前先檢查 channel 裡有沒有訊號正在傳送,有的話,就「等」。等到 channel 安靜下來,它才開始傳送自己的資料。顯而易見的,這個方法會影響到傳輸的速率。所以當同一個地點有很多 wifi 使用相同 channel 的話,看起來訊號很強,其實連線的問題很大!

所以,要避免這種干擾。最好讓環境裡的無線訊好號越少越好(我知道,這可能不是自己能控制的事);再不然,至少不要讓這些無線網路使用相同的(或鄰近的)channel 來減少訊號干擾的機會。

以切成 11 個 channel 來說,有三個 channel 是幾乎不會互相覆蓋到的:1、6、11。所以理論上把自己的 AP 設成這三個 channel 應該是最好的。

而根據像我這種不懂,把 AP 買回家用預設值換個密碼、設個 WEP 就上線的人應該不少。所以,我想把 channel 改到 6 或 11 應該可以避免不少干擾才是。

今天回家就試試看吧~

參考:IEEE 802.11 (wiki)
參考:避免2.4GHz ISM頻段各種類型無線設備干擾的技術

2010年11月14日 星期日

Print enumeration name in C, C++

Print out enumeration name as string is useful for debugging, but I does not how to do it until I read a sample code from MSDN on last week. That’s really shame for being an engineer (害羞).

2010年11月4日 星期四

輕鬆讓你的 Windows7 變無線 AP

Windows7 有一個新的功能叫做 Soft-AP,顧名思義就是軟體模擬的無線 AP。有了這東西,你可以輕易的用你的電腦或筆電模擬成一台無線 AP,讓家裡面其它的裝置,例如 iPad、手機、遊戲機等都透過它來上網。而不用另外花錢買一台頻寬分享器。

以下是設定的步驟:

2010年11月3日 星期三

帶種的才來

Nikon 的新機 D7000 自從有消息傳出後,由於功能強大,頗有在 N 家機種中有以下犯上的感覺,網路上好多人都在等它正式發表。連我自己同事都有人苦苦等著它上市要來升級一番。

結果,幾個月過去後,昨天終於正式公布台灣的售價。結果價格高不可攀,Mobile01 上罵聲不斷。同時,PCHOME 的購物中心也正式上架了。

不過,它的標題卻是:「帶種」新機預購 目瞪口呆

mobile01-8b80f484c00d8ba0f6efb162bb3a1858

究竟是在說國祥(代理商)定這個價格很帶種呢?還是敢用價種價格買的人很帶種?開懷大笑

不管怎樣,至少買方跟賣方其中有一邊很帶種就是了~ 吐舌頭

2010年11月2日 星期二

E220 HSDPA Study

There are three devices will appear in system when E220 USB device plug-in (with driver installed).

  1. Mass storage device (include driver, application and manual)
  2. 3G modem device (COM)
  3. Mobile Connect PC UI Interface device (COM)

There is a application called “Mobile Connect” will be installed with 3G modem driver. Which will use the 3th device in above list to communicate with 3G chip. (cause the 3G modem device has been locked by windows connection manager when connected, the application need another interface to get statistic from 3G chip)

MSMQ Auto Installation

There are several ways to install (enable) MSMQ automatically.

The major issues are:

  1. The way to install MSMQ in different OS version are different.
  2. The supported components of MSMQ are different in different OS.

In below detail procedure for install MSMQ, you will see I enable different MSMQ components for different OS version. Those components are tested for me to use. If you need more components, you need to add them in command line, or un-attend file to enable them.

2010年11月1日 星期一

Sign your application for HKLM/Init

I had made a test application in [HKLM\Init and database status] for trying to figure out the database status in boot up sequence. And as I said in that post, the application run fail when I try to put it earlier than services.exe (launch60).

And I found a solution about the issue: signature.

I still cannot find any document mention about this limitation, but after I sign my test application with my develop certificate, the application can be run at anywhere I wanted.

2010年10月31日 星期日

Using certification in VS2008 project property

I already describe the way to create, install and sign application use test certification in [Create and use test certificate]. And I found that VS2008 already provides the ability in project property.

You still need to create your test certificate using makecert.exe first. You can follow the steps to create it. If you follow the sample, the certificate should be installed in user store already, and it’s name is “Tim’s Dev Authority”.

Research on locked resources

I am keep looking at how to stop service, drivers and applications to release resources (file, database) to make backup & restore process more smoothly.

This post is a note of the testing result, it will keep updating when anything was found.

2010年10月29日 星期五

Mobile Service Development

Notes of study “Implement a Network Service on Windows CE”. I think this article is a good start point of learning mobile service development.

憑證管理員

之前在作一些憑證相關的測試與研究時,由於還不是懂,結果建立與安裝了一大堆測試的憑證,搞得亂七八糟。之後,在 Windows 7 的系統下,我找不到憑證管理員在哪,連要怎麼清除那些測試憑證都不知道…

還好,Google 萬能,有拜有保佑~

  1. Start / Run / MMC.exe
  2. File / Add-Remove Snap-In (新增移除嵌入式管理單元)
  3. Select Certificates (憑證) and click Add
  4. Select Current User (目前的使用者) and click Ok
  5. Select Computer Account (電腦帳戶) and click Next
  6. Select Local Computer (本機電腦)
  7. Click close
  8. Click Ok

之後離開這個程式時,可以把它的設定儲存成 [憑證管理員] (名字隨你),之後就可以用這個設定直接打開管理憑證而不需要在作上面那一堆動作了~

Create and use test certificate

When develop a service on window mobile, the service dll file need to be signed for services.exe to run it normally. Otherwise, your service cannot be run be services.exe when system start up. So, here is the topic of this post.

How to create a certificate for testing and development use?

Before I list the procedure, I need to declare first: There are still lot of things I don’t know in windows certification, this procedure it’s just a way I found I can finish my target only.

Ok, here we go…

2010年10月26日 星期二

Cemail.vol backup / restore

The original post is on MSDN develop forums, cause the post there sometimes get lost, and the coding style is totally crash by HTML. So, I made one copy here for backup and clear the coding style for easy read.

Below link it the original post:

http://social.msdn.microsoft.com/Forums/en-US/vssmartdevicesnative/thread/d1d8c95a-9366-4acf-8bac-b6862bfc2f79

This post share source code of two functions: BackupMain() and RestoreMain() to backup and restore cemail.vol, The idea is very simple.

Mobile (CE) hive-base registry diagram

Again, I made a diagram for hive-base registry.

擷取

Key points of this diagram:

  1. Three kinds of HIVE in mobile system
  2. Filesys,dll will mount Boot.hv from ROM first
  3. Boot.hv used to pre-load root partition (storage driver, marked as bootable) and locate system hive position (HKLM\Init\SystemHive)
  4. Default.hv is the ROM portion of system hive
  5. System.hv stores the changes of default.hv
  6. Again, current users user.hv will be located by system hive
  7. User.hv in root file system stores the changes of user.hv in ROM image
  8. Whatever system hive or user hive, system will store ROM portion’s MD5 checksum as signature
  9. When filesys.dll load system hive and user hive from root file system, the signature will be checked. If signature not match, the system.hv and user.hv in file system will be delete
  10. The signature mechanism cannot be disabled
  11. There are OEM I/O controls can force system to delete system.hv and user.hv in root file system

突然想到,解釋這麼落落長,那不就代表這張圖沒有用…目瞪口呆

Mobile (CE) File System Diagram

I made a diagram for my study report.

擷取

Key points of this diagram:

  1. When clean boot, filesys.dll will use initobj.dat (in ROM image) to create root file system.
  2. ROM image content ‘flat’ file system, no directory, only files
  3. ROM image will be mounted at “\windows” folder
  4. Folder “\windows” actually contents files in ROM and files in root file system, object store will handle the integration.
  5. External storage like SD card will be mounted at “\Storage Card” folder; Driver can define the mount point name as they want.
  6. If multi external storage exists, device management add sequence ID on the end of mount point name, like “\Storage Card 2”

日文漢字對照表

玩實況或是 KOEI 的遊戲常要用的漢字對照表。

實況野球 2010 買來福彼女功略

不知道是打棒球還是追女人的實況野球功略 開懷大笑

轉貼自: http://home.gamer.com.tw/blogDetail.php?owner=NBA2009&sn=5808

其實在好多網站跟討論區都有看到,我也搞不懂到底誰是真正的 source 了。不過我是從上面的那個 blog 轉貼的,這邊只是幫我自己做個備份(我玩超慢的)。

前面的應該是跟實況 4 一模一樣的通用彼女,後面的則是實況 4 的特殊彼女們。還要玩小遊戲,看起來就好麻煩… 傷心

2010年10月25日 星期一

Schema of CEDB

Except the strange terminology on Windows CE database, I finally got another key point that why I am struggle on study CEDB document. That is:

There is no schema on CEDB database.

What a key point of CEDB feature, but I did not notice that! Cause I already used to other database engines on the world. Without this realization, it’s hard to understand the CEDB APIs.

Each record in CEDB refers to a set of data. Each data has a unique property ID and data type. CEDB allow records in same database has different properties (but I really don’t know who need this).

With this cognition, everything is clear. Why CeCreateDatabaseEx() API does not have parameter for properties, why CEDB using CeWriteRecordPropertiresEX() API to create properties, …, etc.

I think, I really waste a lot of time on study CEDB with wrong assumption… 傷心

2010年10月24日 星期日

Something about EDB and CEDB

Although MSDN mentions that EDB is designed to replace CEDB, but I did not find documents descript about how to detect the database in my device is EDB or CEDB. And more important is, I do not how to use EDB APIs in my develop machine (When using VS2008 with SDK 6.0, it using CEDB APIs by default, and I don’t know how to switch it).

Finally, I got some post that really help me to solve my problem.

2010年10月22日 星期五

Backup & restore case study: XCamera

This post is a case study of backup and restore one application called XCamera which is a camera application with it’s own driver included.

After analysis, I found the components I think it should be backup for restoring.

Files in \Program Files\XCamera The application install folder. There are lot of exe, dll and ini files in this folder.
Two driver files in \Windows folder File camera.dll and backlight.dll. There are drivers run by device.exe.
A link file in \Windows\開始功能表\程式集 The shortcut LNK file.
Files in \Windows\AppMgr\[XCamera ….] Looks like some files created by AppMgr. I am not sure what they are, but they should be backup.
Registry XCamera does not user hive, we only need to backup system hive.

So, here is the procedure to backup system for XCamera.

  1. Backup registry using RegSaveKey()
  2. Backup all files listed in above table

I don’t get any problem on backup process (很棒). So, let’s clean boot the device and start our restore procedure.

  1. Find devices use camera.dll and backlight.dll, de-active them. (procedure in [Driver file replacement])
  2. Using CopyFile() API to replace camera.dll and backlight.dll (original files are INROM file, after this copy, they becomes NORMAL files)
  3. Create \windows\AppMgr\[XCamera …] folder and copy backup files into that folder
  4. Create \Program Files\XCamera folder and copy backup files into that folder
  5. Copy backup system hive file to “My Documents” folder and using RegReplaceKey() function to restore it.
  6. Reboot device

There are two things cause you need to reboot the device: First, the de-actived devices will be active again after reboot (Of course, you can active them by yourself). Second, the RegReplaceKey() API will un-mount system hive, you need to reboot the device and OS will use your hive to replace system hive.

After reboot, I can see XCamera in 程式集, and it can be run normally.

But, I found another problem on this procedure. After restore, I cannot find the application XCamera in application manager, that means I cannot uninstall and upgrade the application. 嚎啕大哭

Looks like application manager using other resource on disk. Maybe database??? I think I found my next topic…

2010年10月21日 星期四

Driver file replacement

In my case study, the target application will replace some drivers under \Windows folder. Those drivers are run by device.exe when boot up.

In my backup and restore study, although I can copy the driver file into backup image, but I cannot simply write it back to device.

My first plan is develop a program run before device.exe and replace those files. The program only needs file system APIs, and the APIs are ready in early of filesys.exe, so I guess it should work.

But as my test result on [HKLM\init and database status], I go problem to run any application before device.exe, even service.exe. And I cannot find solution for it until now.

So, here is the second solution I got:

First, find the sub-key(s) in “HKLM\Drivers\Active” which using the driver file. In my case: camera.dll, I found it at “HKLM\Drivers\Active\38”. Here is the entries in that registry key:

Hnd 3490960
Name CAM1:
Key Drivers\BuiltIn\CameraDriver
BusParent 206896
InterfaceType 0
BusName BuiltIn_0_13_0
ClientInfo 0

Three keys you need to pay attention:

Hnd HANDLE of running device. You will need it to deactive the device for release driver file.
Key The registry location which store the driver settings for device.exe. You need it for device active API.
ClientInfo Driver’s init parameter. If device.exe active driver with parameter, it will put it in this registry. You will need it when you want to active the device again.
If the registry key not exists, ignore it.

After found that registry, all information needs for my testing application to replace driver are ready. Here is the procedure of camera.dll:

  1. Deactive camera device by “DeactiveDevice(3490960)” to release camera.dll. (In my case, only one device using camera.dll)
  2. Copy camera.dll from backup image to \Windows folder
  3. Active camera device by “ActiveDevice(_T(“Drivers\BuiltIn\CameraDriver”), 0)”. The second parameter is ClientInfo, if your driver does not use it, pass 0 for it

I think most of drivers can use this procedure to replace, but I still think it’s too complex.

Cause that means after I scan all files does not in ROM image ([Windows Mobile File system Study]), I need to differentiate which files are used by device.exe and using different way to perform backup & restore function for them.

And here is anther issue about this solution: When I de-active the device, something device will popup “device.exe failure” error screen. Although that does not cause any problem for our backup & restore operation, but the user experience is bad for user to see that screen.

2010年10月20日 星期三

HKLM\Init and database status

On the post Enumerate Database Volumes, we saw a lot of database volumes has been mounted and locked by some applications or services. I am trying to find a position in boot up sequence to get less database locked as I can.

This is the volumes mounted when boot up finished:

\Documents and Settings\Default.vol
\ReplStrorVol
\mxip_notifi.vol
\mxip_swmgmt.vol
\cemail.vol
\mxip_system.vol
\mxip_lang.vol

I modified my enumeration application to output the enumeration to a file. Cause this application should only use database and file system API, I hope it can be executed very early in boot sequence.

And I find the first place to try: HKLM\Init. The applications registered in this registry will be run in the lastest step of filesys.exe. At that moment, the database and file system APIs should be ready. So I start my testing.

I put my execution file in \Windows folder, and add a registry in HKLM\ini as “LunchXX” with my application file name as value.

First, let me list my KHLM\Init:

Launch4 sdpready.exe
Launch19 initvmmap.exe
Launch20 device.exe
Launch30 gwes,exe
Launch50 shell32.exe
Launch60 services.exe
Launch70 connmgr.exe
Launch82 ShellNotification.exe

This is not a full list, but enough for my description.

First try, I think device.exe loads drivers, the system state should be ready to execute my application. So I made “Lunch35” as my key name, and them, the application run fail, I don’t know why, but just cannot see the output file.

Second try, I want to make sure my application can be run in HKLM\init. So I modify the key name to “Launch135”. And great, it can be run, and the output is:

\Documents and Settings\Default.vol
\ReplStrorVol
\mxip_notifi.vol
\mxip_swmgmt.vol
\cemail.vol

Another great news, some volumes missed. Then I try to put my test application on “Launch65”, and the cmail.vol missed, too.

\Documents and Settings\Default.vol
\ReplStrorVol
\mxip_notifi.vol
\mxip_swmgmt.vol

And then when I try to run it earlier at “Launch55”, it fail to run again.

According my HKLM\init list, the item between 55 and 65 is “Launch60: services.exe”. Seems my application need to wait for all service ready. I am depressed about that. Cause I think my application only use database and file system APIs, I hope it can be run earlier then that.

So, until now, I have four database volumes need to study about how to release them for backup and restore operation.

2010年10月19日 星期二

顳顎關節炎

其實要紀錄的是還算蠻不愉快的就醫經驗…

從三、四個月前左右,我就常有起床後嘴巴打不開、臉部左邊的關節會疼痛的情況。本來不以為意,結果後來越來愈嚴重,這個關節疼痛與張口障礙變成了常態問題。

兩個月前,我受不了終於去找醫生,問題是我不知道這是啥病,所以就找了家醫科詢問。醫生只跟我說應該是關節發炎,開了止痛消炎藥叫我試試看(沒錯!就是試試看)。然後跟我說吃完沒用的話到牙醫去掛號看看…

我一向是很聽醫生的話的,所以我就乖乖的試試看,然後理所當然的沒有用。所以,該去掛牙醫科了,這下問題又來了!我打開醫院的牙科門診列表,才發現原來牙醫分這麼多種喔?我以前都只知道蛀牙去牙醫診所看就好了,這麼多奇奇怪怪的牙醫是要怎麼掛?

後來我找了個有「齒顎」這個關鍵字的門診,好熱門啊,要一個禮拜後才掛得到耶!我還是乖乖的掛號了,也乖乖的等了,也乖乖的去看了。然後,我得到一句:「你掛錯門診囉~」(暈…)。

還好,雖然掛錯門診,但是總算是牙醫沒差太遠,醫生很快的告訴我,這個病叫做顳顎關節疼痛,然後給了我一張衛教單,叫我照著上面的「消極性治療」去做,一個月後還沒好的話,去掛另一個門診。

沒了,沒有 X 光,沒有問診,只拿到一張衛教單跟一個醫生的名子;然後我換拿著肌肉鬆弛劑與止痛藥回家了。我也只能安慰自己總算有點進展,至少有病名了,還有衛教單呢。

看著衛教單,顯然又是個原因不明的文明病。林林總總列了十幾種可能的病因,列太多說實在的跟沒寫差不多,然後告訴我要作消極性治療;消極?簡單的說是盡量不要讓它痛,看它會不會自己好…

(印象中不知在哪看過,「樂觀面對、積極治療」才是面對病痛的最佳方式,怎麼會是消極呢?)

很快的,一個半月又過去了,消極顯然不是個很好的詞,感覺上醫的好的套上這個詞後都會覺得醫不好。昨天,我又去看醫生了,這次,總算沒有人跟我說掛錯診了(YA~我要放鞭炮)。

有掛對診還是有點幫助,照了 X 光片檢查,醫生也比較詳細的跟我說明了這個病的物理成因,還做了一些小實驗可以讓我嘴巴張開了(好神奇,雖然只有一下下)。只不過,得到的結論仍然是要先繼續作休養性的治療(終於不用消極了~),繼續觀察。醫生要我不要急,這個病沒辦法一時根治,要有耐心。

(我想,沒耐心的話我就不會跟你們耗四個月了…)

最後,這次拿了肌肉鬆弛劑與安眠藥回家,再加一張兩面的衛教單(多一面喔!)。醫生要我乖乖的吃藥,下禮拜再回診一次看看有沒有變化。

老實說,我不知道這次的就診結果會不會比之前的好;心態上我都快要跟這個病和平共處了。我只是有時候會想,還好這不是個嚴重的有生病危險的病,要不然這樣拖啊拖的,難道不會有危險嗎?或者,就是因為沒有危險,所以醫生就很放心的讓我拖拖拖?

2010年10月15日 星期五

蘭陽博物館 & 金車咖啡城堡

上個星期五晚上,老婆突然提到這個地方。其實我知道這地方已經好久了,只不過一直覺得假日宜蘭觀光客暴多,有點懶得去;但是既然老婆都知道了,那就閃不過啦。只好提醒她早點起床出門囉~

隔天老婆還真的很乖的早早起床、安撫不喜歡早起的小阿呆,就準備出門了;連早餐都是在車上吃的。

其實說早也沒有很早,出門時其實已經快十點了,不過還是比平常她們 ready 時間(十二點!)早很多啦;所以,免不了台五線還是要給它塞一下的。

去到那邊赫然發現,原來還沒開始正式營業喔?結果就已經一大堆的遊覽車出團到那邊去了!跟當初的民俗藝術中心一樣,沒開業先賺錢。不過這邊跟民俗比起來交通糟多了,停車場小不拉嘰的,根本就沒有考慮到會有這麼多遊客嘛。

到的時候其實人來不算多,入館內二樓參觀已經要排隊了。我跟老婆懶得排,想說先在一樓的伯朗咖啡吃個午餐再說。沒想到吃完午餐後,排隊的人潮已經完全超乎想像。

上面照片的旁邊擺著一個「此處排隊約兩小時」,可以看到我拍照時都還沒人。吃完飯,已經真的排到兩小時這來了…

吃飯時看著金車的廣告傳單,才發現它們在宜蘭的觀光真的已經深耕很久了;水產中心、金車酒廠、咖啡城堡,看來來宜蘭玩的人很難不被它們敲點竹槓。

因為看到排隊人潮太可怕,我跟老婆決定不上二樓參觀了,於是決定離開這邊,到咖啡城堡去讓金車再賺一筆(目瞪口呆)。

沒想到上城堡要走不算短的山路,而且路還很小很窄。還好上去時看起來車還沒有很多,順利停好車後就在城堡走走逛逛、拍拍照。

因為也不趕時間,我們在城堡上上下下晃來晃去,後來又點了飲料在那慢慢喝,一晃眼兩個小時過去了。就當我們要下山時,看到了相當可怕的景象…

整條山路從山腳一路塞到山上,甚至莫名其妙的還有遊覽車跑到山上了,結果那小不拉嘰的山路停滿了車,遊覽車根本下不去(目瞪口呆)。這時我跟老婆真得慶幸我們決定在博物館不上二樓的決定,不然塞在那山路上的就是我們了~

雖然今天的天氣不好,拍出來的照片也都陰陰的,完全看不到藍天白雲。不過倒是也樂得不用曬太陽,蠻舒服的。晚上我們又固定去羅東給它光顧了一下,吃吃那離婚的包心粉圓(開懷大笑)。

Enumerate database in volume

As I said in [Windows Mobile (CE) Database Study], the terminology of CEDB and EDB is almost killing me. The topic is enumerate  tables in database, if using all other common database engines.

I cannot find any document descripts CEDB and EDB which one used in Windows Mobile 6.1 (my test device). But I cannot use EDB only APIs on my develop environment (VS2008 + WM 6.1 SDK) , so the sample code here is using CEDB.

Here is the code piece, follow the sample code in [Enumerate DB Volumes], we got the DB volume’s CEGUID (in variable ‘guid’) and then try to enumerate all database (tables) in that volume.

HANDLE hFind = CeFindFirstDatabaseEX(&guid, 0);
CEOID oid = 0;
while ((oid = CeFindNextDatabaseEx(hFind, NULL)) != 0) 
{
        CEOIDINFOEX oidinfo;
        memset(&oidinfo, 0, sizeof(CEOIDINFOEX));
        oidinfo.wVersion = CEOIDINFO_VERSION;

        if ((CeOidGetInfoEx2(&guid, oid, &oidinfo))
        {
                /// TODO: print out oidinfo.infDatabase.szDbaseName
        }
}
CloseHandle(hFind);

Back to enumeration, you can use CREATE_INVALIDGUID to initialize variable 'guid’, then the code will enumerate all database (tables) in all mounted volume (I am not sure the order)..

And you can specified a PCEGUID in the second parameter of CeFindNextDatabaseEx() function to get the volume’s GUID which the database belongs to.

Below is the enumeration of my device, just for reference.

VOL: \Documents and Settings\default.vol
        ScheduleU
        ScheduleS
        ScheduleGroupU
        ScheduleGroupS
VOL: \ReplStorVol
        ReplStor
VOL: \mxip_notify.vol
        DB_notify_queue
        DB_notify_events
VOL: \mxip_swmgmt.vol
        SwMgmtMetadataStore
VOL: \cemail.vol
        fldr3100001d
        pmailVolumes
        pmailNamedProps
        pmailMsgClasses
        pmailOldTables
        pmailMsgs
        pmailFolders
VOL: \mxip_system.vol
        \ConfigMetabase
VOL: \mxip_lang.vol
        \MetabaseOptions
        \MetabaseLabels

2010年10月14日 星期四

Hive-base registry initialization

Original document:
http://msdn.microsoft.com/en-us/library/ee489764.aspx

Sequence

I only list items I may needed

1. Mount boot hive (Boot.hv) from ROM
2. Loads and initializes Storage Manager (HKLM\System\StorageManager)
3. Boot phase zero
4. Initialize system locale
5. Boot phase one
6. Device.exe (if needed ??)
7. Wait for file system contains system hive ready (MountAsBoot?)
8. Mounts ROM portion of system registry (\Windows\Default.hv)
9. Check IOCTL_HAL_GET_HIVE_CLEAN_FLAG for clean system hive
10. Check HIVECLEANFLAGS_SYSTEM for clean system hive
11. Load system.hv from file system
12. Check system hive signature for clean system hive
13. Swap out boot registry hive
14. Check IOCTL_HAL_GET_HIVE_CLEAN_FLAG for delete user.hv
15. Check HIVECLEANFLAGS_USERS for delete user.hv
16. Mounts ROM portion of user hive (\Windows\User.hv)
17. Load user.hv from file system
18. Check user hive signature for clean user hive

Boot phase

Phase 0: system locale not ready
Phase 1: system locale ready, but total registry no loaded
Phase 2: system locale ready and total registry has been loaded

Enumerate EDB volumes

I wrote a test application to enumerates all EDB volumes on my WM6.1 devices. Here is the code piece:

CEGUID guid;
DWORD  dwErr;
WCHAR  wszMsg[255];
WCHAR  wszName[255];

CREATE_INVALIDGUID(&guid);

while (CeEnumDBVolumes(&guid, wszName, 255))
{
        StringCchPrintfW(
                wszMsg, 255, L"VOL: %s\n", wszName);
        OutputDebugStringW(wszMsg);
}

if (GetLastError != ERROR_NO_MORE_ITEMS)
{
        OutputDebugString(L”Unexpected stop\n”);       
}   

According the MSDN, the size of wszName should be enough to CEDB_MAXDBASENAMELEN. But actually I got ERROR_INSUFFICIENT_BUFFER error when using that size.

After increase the size to 255, the enumeration finish normally, and here is the output in my device.

VOL: \Documents and Settings\default.vol
VOL: \ReplStorVol
VOL: \mxip_notify.vol
VOL: \mxip_swmgmt.vol
VOL: \cemail.vol
VOL: \mxip_system.vol
VOL: \mxip_lang.vol

It’s more than I expected….嚎啕大哭

And notice the first one, the length is absolutely larger then CEDB_MAXDBASENAMELEN (32), that means the reference guide of CeEnumDBVolumes() was wrong.

Back to the list I got, there are more than that when I searching the *.vol files on root file system. Cause CeEnumDBVolumes() only list the mounted database volumes.

And of course, the volumes listed has been locked after my mobile device boot up, there is a long road for me to understand how to release them for backup/restore purpose.

2010年10月13日 星期三

老兵

昨天老婆拿到台北縣政府發的「10年資深優良教師」獎狀了,來跟我年初拿到的 5 年資深員工講座合照一下。

這兩個東西說真的,一點也不重要,不過它代表的,都是歲月的痕跡啊。

另外,搞教育就是不一樣,一個獎狀也要寫的文謅謅的…

Windows Mobile (CE) Database Study

Notes about study CEDB and EDB on Windows Mobile (CE).

Terminology

When study MSDN about CEDB and EDB, some wording keep confusing me. Cause CEDE and EDB using different terminology with other common database engine.

EDB and CEDB term SQL Server Compact term
Sort order Index
Data type Data type
Property Column
Record Row
Database Table
Volume Database

Especially the Database mapping to Table one keep confusing me on reading the document…

Database Volume

We can see CEDB and EDB as a file-base database like Sqlite. A volume is a file including multi database (table, you see why I am confusing).

Before using the database, you need to mount (‘open’ in normal terminology) the volume. If the volume is not exists, you need to create (create a new file using CEDB API) first. When you don’t need the database anymore, you need to un-mount (‘close’) the volume.

There is a default database volume in CE (Mobile) system used by object store. It will be mounted when system start up and released when system shutdown (that means the file will be locked in whole running cycle).

And applications can create volume in any location they wanted, including external storage (like SD card).

The EDB and CEDB APIs using CEGUID as identity to access a volume, database or even a record. For the detail usage, need to refer to each method’s document for detail.

Database Backup / Restore

Obviously, we need different procedures to handle the default volume (object store) and others.

For extra created database volume, we just need to stop all process which using these database volume. And then we can just follow the root file system backup & restore procedure. It should be a easy one.

For object store database volume….

If I can find the way to un-mount the object store, it should be easier to handle it like other database volume. But seems it’s not so easy to find the way.

Otherwise, we can enumerate all object store database and dump them into our format. And then push them back when restore. I am not sure if there is some database has write-protect, but I think it should be not….

2010年10月12日 星期二

火力展示

雖名為火力展示,但其實是沒有火力的證明,跟許多玩相機的人比起來,我有的只是小小的木刀而已吧(微笑)。

2308
D40 + Sigma 30mm F1.4

女兒出生前,在作了好幾個月的功課後,我買了人生的第一台單眼相機。D40 當初是 N 家最低階(也就是最便宜)的入門單眼,沒有機身馬達、沒有雙螢幕、沒有雙轉盤、只有三點對焦,以現在的規格來看,簡直是空殼…

不過配上 S 家的 30mm F1.4,體積小、大光圈與適合室內拍攝的短焦,就成了我紀錄小孩成長最大的幫手。


家裡的拍攝,背景一點也不重要,就讓它糊掉吧~XD

在小孩漸漸長大,可以帶著四處玩後,也開始感覺到定焦鏡的不足;剛好適逢小舅子要結婚了,希望我幫忙隨便拍一下;於是,敗家的路又啟動了~

2310
SB400 + Nikon 16-85 F3.5~F5.6

這兩個[雞絲頭]加起來就跟我之前的鏡頭加機身一樣貴;小閃燈當然不夠力,不過配 D40 比較合身,而且再大我應該就懶得帶出門了。N1685 其實是個被評價為 CP 值不高的選擇,不過有小廣角加上不會太長太大(我又不拍鳥),我還是趁新光周年慶時拜下去了…


變焦鏡 + 閃燈在使用上真的比定焦靈活很多

從 N1685 開始,我發現兩萬塊上下的東西似乎是我拜 3C 產品的 Magic Number;往上的,我嫌太貴買不下手,往下的,我會嫌它不夠好。

雖然變焦與定焦鏡我都有了,不過俗話說得好:「生命會自己找到出路,敗家會自己找到理由」,我的下一個理由比我想像的還快出現…

那就是「好累」

帶者單眼出門有時確實需要熱情,尤其包包裡已經被一堆的小孩用品塞滿時。於是,我開始尋覓的我的隨身機,被單眼畫質與使用方式教育過的我,對那些太聰明以至於顯得自己太傻瓜的 DC 開始變得很挑(說真的,其實那真的沒有甚麼意義)。

2304
GRD3

最終,又是一台評價上 CP 值不高的選擇。跟 N1685 一樣,CP 值不高並不是它不好,而是它賣很貴(傷心)。這台小 DC 又落在我的 Magic Number 附近,你說貴不貴~


同事幫我入手 GRD 後就先跑去試拍了

雖然我一直說它們貴,不過說真的,我自己是都覺得花的蠻值得的(好啦,閃燈真的很少用,因為不想閃小孩啊)。

就鏡頭與隨身機來說,我其實真的已無所求了,兩個都很好用;不過機身隨著這兩三年的進步,真的差異已經很大了。不過現在也找不到當初 D40 那麼便宜的的機身(才 12000 左右)就是了。

偏偏最近剛上市的 D3100 就是繼承(當然,已經好幾代去了)當初 D40 定位的入門機身,功能完全的 level up,而且很該死的:價位正在那個 Magic Number 以下一點點…

小朋友,你準備好了嗎?

2010年10月11日 星期一

Windows Mobile (CE) File System Study

The same reason as the previous one for Windows mobile registry. This post is the notes of Windows mobile file system study.

FILE ATTRIBUTE

Theoretically, we can scan all files and folders in root system, and then using GetFileAttributes to get the attribute. And of course we can use the attribute to differentiate the file is stored in ROM image, writable root file system or external media storage (like SD card).

FILE_ATTRIBUTE_INROM Indicate the file store in ROM image. It’s read-only and cannot be modified. And we don’t need to worry about it on backup function.
FILE_ATTRIBUTE_SYSTEM The file is used by the OS.
FILE_ATTRIBUTE_HIDDEN The file or directory is hidden. I am not sure if we can find hidden file using  FindFirstFile API.
FILE_ATTRIBUTE_ARCHIVE MSDN says application use this attribute to mark files for backup or removal. I am not really understand what he means. I need more study on this, maybe that relative with backup and restore function we wanted.
FILE_ATTRIBUTE_TEMPORARY Temp files, we can ignore them for backup function.

There are more attributes list in MSDN, I don’t know if I miss anything important for backup application. I need more testing on real device for detail.

SCAN STORAGE

I had write a testing code to scan all storages on my mobile device follow the sample here.

And I get output like this:

Store: SMFLASH
    Part: Name(Part00) Vol() FS(BOOT) ATT(0)
    Part: Name(Part01) Vol() FS(RAWFS) ATT(0)
    Part: Name(Part02) Vol() FS(imgfs.dll) ATT(16)
    Part: Name(Part03) Vol() FS(fatfsd.dll) ATT(16)
Store: DSK1:
    Part: Name(Part00) Vol(\Storage Card) FS(fatfsd.dll) ATT(16)

I can see I have one SD card using FAT file system and mounted on “\Storage Card”. And the internal storage is SMFLASH with 4 partitions.

I can understand that we don’t need to care about partition 0 and 1, but I still cannot know which is the root file system we are using. (The partition attribute 16 means READONLY, AUTOFORMAT and MOUNTED.)

Ps. The sample code using library storeapi.lib, this library does not exists in Windows Mobile SDK. I got it from WM616 adapter kit.

FILE SYSTEM BACKUP PLAN

Theoretically, if we can list all files which are not store in ROM image, then we can create the file backup image for later restore.

I had wrote a test application which scan all files in root file system to find out the files and directories does not store in ROM image using API FindFirstFile and FindNextFile.

But we still have issues need to be solve:

1. When mobile OS running, lot of files were been locked for read (for example: driver dll in windows folder). I cannot copy those files for creating backup image.

2. Like previous issue, of course the running (locked) files cannot be write for restoring.

Android Doc, 加油, 好嗎?

最近工作需求正在狂啃 MSDN,然想起了一個月前開始玩 android 的經驗。有時候,documentation 真的比你想像的重要~

一切的故事就從 Install the SDK 開始:Step 1, Preparing you development computer。很好,它給了我 link 去安裝 JDK 與 Eclipse;當時的最新版是 JDK 6 Update 21 與 Eclipse 3.6。

安裝完 JDK 後,突然看到 Eclipse 上說 JDK 6 Update 21 有問題(…);還好,後來找到說現在下載的最新版 JDK 應該修好了(虛驚一場,汗)。

裝完 Eclipse 後照著 Install the SDK 繼續往下,該裝 ADT plugin 了(疑?還要跳到其他文件繼續喔)。然後就看到

Caution: There are known issues with the ADT plugin running with Eclipse 3.6. Please stay on 3.5 until further notice.

(啊你是不會早點講喔~~~!X!)

到這邊為止,我有種被耍的感覺。雖然不是甚麼解決不了的問題,但是搞成這樣真的是很讓人不愉快。安裝文件不就該是 step by step 就好的嗎?哪有人這樣限制放在後面說的啊!於是,我只好移掉裝好的 Eclipse,然後決定把網站裡所有跟安裝有關的文件都看完後,再繼續安裝我可愛的 Android SDK。

現在,對比 MSDN Library 的文件與 developer.android 的 SDK Reference,仍可以明確的感覺到 android 這邊文件的缺乏。大多數 Windows API 都可以在 MSDN 找到真正的使用法,而 android 這邊,總是需要靠著 google 大神四處挖其他開發者的經驗談。

我只能說,也許 Android 的開發者都是高手吧,有些人還去 download SDK 的原始碼來研究要怎麼用,真是見鬼了…。

天氣先決

對我這種業餘的相機玩家來說,不管光圈先決還是快門先決,說真的,都沒有天氣先決來得重要。

5065953939_0461fd787a_z

前天去了趟宜蘭的金車咖啡城堡,去過的就知道,從那邊看烏石港其實很漂亮。偏偏那天一整個烏雲密佈,連空氣都有種濛濛的感覺,結果我的 D40 + N1685 拍起來就變成這樣,整個慘(我還稍微後制過…)。

C360_2010-10-12 07-50-46

看看這個在上班路上用手機拍的,不用後制,不用調整,天空就一整個藍到爆。

我想以後出去拍照,與其買一大堆器材,不如多做幾個晴天娃娃比較實在…

敗家

嚴格來說,我其實是個會敗家的人。


結婚以前,我是個物質欲望很低的人,每個月花的錢其實很有限。在不逛街的習慣下,我沒有甚麼機會看到那些花花綠綠的各式商品,沒花的錢存下來沒有甚麼特別的感覺,也不會懊惱。

然而結婚後,因為要常陪老婆逛街,再加上每次看到她買的那麼開心,再回頭想想自己每個月存下來的錢,有時真的會有種我存錢幹嘛的想法,好想就像理智斷掉一樣的大買特買。雖然,大部分的時候我是控制住了,但是,其實也真的花了不少了。

女兒出生時,我狠下心來買下手中的單眼相機,雖然只是入門機種,也花了快三萬;在加上之後其它拉哩啦咂的配件與鏡頭,也已經花了六萬多有了吧。不過最近單眼吹起的錄影風,讓許多新機的功能不停調整,價格也相當吸引人,我又開始想敗家了….

希望,這次能夠忍得住啊~

API initializes sequence by filesys.dll

According to MSDN, here are the APIs initialized by filesys.dll in sequence:

  1. Database APIs
  2. File system APIs
  3. Point-to-Point message queue APIs
  4. Event log APIs
  5. Registry APIs

I had not read the detail yet, but I am surprising the database API initialed before file system. The database does not need to refer to file system??

Fstream read performance issue on WinCE

I meet this issue when develop a window mobile application which needs huge file IO operations on our company's handheld device. Until now, I still don't know this issue cause by official windows mobile STD library or our company's OS image only.

The target application randomly read binary files like a RO-database. I using STD ofstream API to read data from file and found the performance was badly. I try to debug this performance issue on that application and found that the root cause is fstream API.

I made a 100MB dummy file and one simple application to read the file sequentially (a for-loop), the total ready time using fstream is almost ten times of another one using fopen/fread interface.

I am lazy to test the same behavior on other company's device (actually, I don't have other device….), so I just re-write the code to use fread() API and the problem solved.

PS. I got the same behavior on two models of our company's handheld device, and they are use Window Mobile 6.1 system.

Windows Mobile (CE) Registry Study

I got a job from my leader about backup and restore system state of our company's handheld products which are using Windows Mobile 6.1. So, I start to study the Windows Mobile system architecture for the knowledge to backup the system.

This post is a study notes about the registry system in Windows Mobile.

Registry Type: RAM-base and HIVE-base

There are two types registry provides by Window CE: RAM-base and HIVE base.

RAM-base Registry means the registry keeps in Object-Stored. Of course when system shutting down, the data in RAM will lost. So OEM need to implement the architecture to save and restore the registry to/from storage when system shutdown and start up.

HIVE-base Registry means the registries are saved in file system in HIVE file (like other Windows systems). There are three HIVE files in mobile system: boot hive, system hive and user hive.

Important: Windows Mobile 6.X only support HIVE-base registry.

Boot Hive, System Hive and User Hive

Boot hive stored in ROM and will be loaded when system startup (by filesys.dll). It contents the registry roots: HKEY_CLASS_ROOT, HKEY_LOCAL_MACHINE and HKEY_USERS. Once the boot.hv has been loaded, the filesys.dll will locate and load the system hive from registry [HKLM]\init\SystemHive. Once the system hive has been loaded, the boot.hv is discarded (OEM can define the system hive location and file name in his OS design).

System hive provides the same registry roots as boot hive. Any modification about those registry roots will stored in system hive (boot hive in ROM will not change unless perform ROM upgrade).

User hive contents the registry for logon user (HKEY_CURRENT_USER). The location of the user hive can be specified in [HKLM]\init\ProfileDir, and the file name is "user.hv".

Signature link Hive in ROM and Hive in File System

When system created the hive on file system on clean boot, it keeps a signature (MD5 of hive in ROM) in the hive. When filesys.dll loads the hive file in file system, it will check if the signature is match. If not, filesys.dll will force to clean the hive in file system and create a new one for it.

Cause the hive in file system normally presents the changes of the hive in ROM, this mechanism used to ensure the hive is valid for current ROM image.

This mechanism fixed in filesys,dll and cannot be disabled.

Backup and restore system hive

To backup the system hive, you can use "RegSaveKey" API. Although the API parameter supports to input registry ROOT key for saving, but actually it save whole system hive when you input the HKLM, HKCR or their sub keys.

To restore the system hive, you can use "RegReplaceKey" API. Providing the file you got from "RegSaveKey" to this API, and the system will un-mount the system hive and replace it by your file. And then you need to reboot the system to re-mount the new system hive.

The procedure here is used only for HIVE-base registry, for RAM-base registry, you need to refer MSDN by youself.

Backup and restore user hive

Like backup system hive, you can use "RegSaveKey" API with HKCU or his sub-key to save whole user hive.

To restore the user hive, you need to logoff the current user by using "SetCurrentUser(NULL)" API, the logoff will close and release the user hive file. And then you can use "CopyFile" API to replace the "user.hv" as yours.

And then we can use "SetCurrentUser" again to login the user (re-mount user hive), or need to reboot the system? I don't know….

HIVE format

The book "Windows Internals" has chapter to descript the HIVE detail, I have not read it yet.

According the MSDN and the book, there are two types HIVE format has been used: Standard format (1.3) or lastest format (1.5), I don't know what's the format be used in Window Mobile "RegSaveKey" API. Need more study.

2010年9月20日 星期一

ACTION_UP missing?

I am try to implement a custom VIEW for practice, and I got a strange issue: I want to handle the ACTION_UP event in onTouchEvent() method, but I cannot see the ACTION_UP event.

After some testing, I found the root course of this issue: ACTION_DOWN event must be handled before you received the ACTION_UP event.

Cause my view does not need to care about ACTION_DOWN, so I just put ACTION_UP check and return TRUE for it, otherwise return super.onTouchEvent() instead.

Seems Android makes a assumption that if you don’t care about ACTION_DOWN, you will not need ACTION_UP. And that’s why I cannot get the ACTION_UP event.

After I add a ACTION_DOWN checking and return TRUE, I can receive ACTION_UP as normal.

I don’t know if my guess is correct, I cannot find any document mention this assumption. But that’s the behavior I can see in my test code, and that really solve my issue.

Layout 元件的大小單位轉換

Android 上有幾個在 layout 上可用的單位:

px

Pixels - 對應到螢幕的幾個像素(pixel)

in

Inches - 對應到實際的距離為幾呎

pt

Points - 通常用在 font size,一個 point 為 1/72 inch

換算公式:pt = px * dpi /72

dp (dip)

Density-Independent Pixels - 對應到在 160 dpi 的螢幕上的幾個像素,為 android 用來處理支援不同大小的螢幕的 layout 單位,詳細定義可以參考 android SDK 的文件。在 android 的 layout 中,應該都使用 dp 來給定元件大小,而不應使用 px。

換算公式:dp = px * dpi / 160

sp

Scale-Independent Pixels - 跟 dip 一樣,加上 pt 的觀念。簡單的說,就是對應在 160 dpi 的螢幕上的幾個 pt。在 android 中,文字大小應使用 sp 而非 pt。

換算公式:sp = pt * dpi / 160

換算公式:sp = dp * dpi / 72


舉個例子說明:你有一個 49 dp 的按鈕,在 120 dpi 的螢幕上,裡面的文字大小最大應為: 49 * 120 / 160 = 36.75 sp。