2017年11月26日 星期日

[ Windows | MFC ] get full path of application's exe file

CString ClassName::getAppExePath()
{
     CString path;
     GetModuleFileName(NULL, path.GetBufferSetLength(MAX_PATH + 1), MAX_PATH);
     path.ReleaseBuffer();
     int nPos = path.ReverseFind('\\');
     return path.Left(nPos + 1);
}


[ Windows | MFC ] get application name

CString ClassName::getAppName()
{
     return   AfxGetApp()->m_pszExeName;
}


[ Windows | MFC ] get appliation version

CString ClassName::getAppVersion()
{
     int major, minor, build, revision;
     DWORD verBufferSize;
     char verBuffer[2048];
     CString version;

     TCHAR AppName[MAX_PATH];
     GetModuleFileName(NULL, AppName, MAX_PATH);

     //  Get the size of the version info block in the file
     verBufferSize = GetFileVersionInfoSize(AppName, NULL);
     if (verBufferSize > 0 && verBufferSize <= sizeof(verBuffer))
     {
         //  get the version block from the file
         if (TRUE == GetFileVersionInfo(AppName, NULL, verBufferSize, verBuffer))
         {
              UINT length;
              VS_FIXEDFILEINFO *verInfo = NULL;

              //  Query the version information for neutral language
              if (TRUE == VerQueryValue(
                  verBuffer,
                  _T("\\"),
                  reinterpret_cast<LPVOID*>(&verInfo),
                  &length))
              {
                  //  Pull the version values.
                  major = HIWORD(verInfo->dwProductVersionMS);
                  minor = LOWORD(verInfo->dwProductVersionMS);
                  build = HIWORD(verInfo->dwProductVersionLS);
                  revision = LOWORD(verInfo->dwProductVersionLS);
              }
         }
     }

     version.Format(_T("V %d.%d.%d.%d"), major, minor, build, revision);
     return version;
}


[ Windows / MFC ] Is File or Dir exist

bool ClassName::isFileExist(CString fullFilePath)
{
     return PathFileExists(fullFilePath) ? true : false;

     //CFileFind finder;
     //return finder.FindFile(fullFilePath);
}


bool ClassName::isDirExist(CString dirPath)
{
     return PathFileExists(dirPath) ? true : false;
}


2014年10月7日 星期二

[ Android ] Add device driver to kernel

take a note!

===================================================

To cross compile your own driver in the arm architecture you have to follow some steps as mentioned below.
  1. Create a directory like my_drvr inside drivers(which is in the Linux source code) for your driver and put your driver (my_driver.c) file inside this directory. It will looks like /linux_source_code/drivers/my_drvr/my_driver.c
  2. Create one Makefile inside your driver directory (using vi any editor) and inside this put obj-$((CONFIG_MY_DRIVER) += my_driver.o and save this file. This will appears like /linux_source_code/drivers/my_drvr/Makefile
  3. Create one Kconfig file inside your driver directory (using vi any editor) and inside this put
    config MY_DRIVER
    tristate "my driver" //gives your driver description like vendor name etc.
    depends on ARM
    default y if ARM
    help
      my driver module.
  4. Save this file, this will appears like /linux_source_code/drivers/my_drvr/Kconfig
  5. Add both Makefile and Kconfig file in the Linux source drivers Makefile and Kconfig file which are at /linux_source_code/drivers/Makefile and /linux_source_code/drivers/Kconfig
  6. In the Makefile add below in last line
     obj-y    += my_drvr/ 
    or
     obj-$((CONFIG_MY_DRIVER)  += my_drvr/
  7. In Kconfig file add below in last line
    source "drivers/my_drvr/Kconfig"
  8. Finally have to add Kconfig file into architecture specific config file which will be at kernel_source/arch/arm/configs/--defconfig in this add below line in the last
    CONFIG_MY_DRIVER=y
Note:- Last step will differ according to your architecture, so that you have take care. Now you can compile your driver by using make command.

===================================================

2014年8月11日 星期一

[ 投資理財 ] 筆記 : 杜金龍教室 20 堂投資必修課


1. 認識公司基本面 :

    a. 認識老闆、經營團隊、經營業務
    b. 由研究報告、相關新聞快速了解公司

2. 檢視公司財務結構 :

    a. 負債比 : ( 總負債 / 總資產 ) * 100%
        衡量公司長期償債能力的指標,< 50% 較安全
    b. 利息保障倍數 : ( 稅前淨利 + 利息費用 ) / 利息費用
        代表公司支付借貸利息的能力,x > 5 佳; x < 2 不佳
    c. 長期資金佔固定資產比率 ( 長期資產 / 固定資產淨額 ) * 100%
        長期資產 = 長期負債 + 股東權益
        代表公司投資相關設備的資金,是來自長期資金居多,還是短期負債來支應長投,> 200% 佳; < 100 % 不佳。
    d. 衍生性商品佔資產比率
    e. 公司發行的公司債

3. 了解公司償債能力 :

    a. 流動比率 : ( 流動資產 / 流動負債 ) * 100%
        衡量公司一年之內的短期償債能力,> 200% 安全;< 200% 不安全
    b. 速動比率 : ( 速動資產 / 流動負債 ) * 100%
        速動資產 = 流動資產 - 存貨 - 預付費用
        表示公司緊急償債能力,> 100% 0 安全;< 100% 不安全
    c. 利息保障倍數 ( 同前 )

4. 了解公司經營績效 :
 
    a. 存貨周轉率
    b. 應收帳蒯周轉率
    c. 總資產周轉率

5. 從獲利指標看公司賺錢能力 :

    a. 營業毛利率 :
        ( 營業毛利 / 營業收入 ) *100%
        營業毛利 = 營業收入 - 營業成本
    b. 營業利益率 :
        ( 營業利益 / 營業收入 ) *100%
        又稱 "營業淨利率", 營業利益率愈高代表公司經營本業的賺錢能力越好
    c. 純益率 :
        ( 稅後收入 / 營業收入 ) *100%
        純益率至少要高於定存利率
    d.  股東權益報酬率 :
        ( 稅後淨利 / 平均股東權益 ) *100%
       平均股東權益 = ( 年初股東權益 + 年底股東權益 ) / 2
       股東權益報酬率 > 15% 較好
 e. 資產報酬率 :
        [ 稅前淨利 + 利息 * ( 1 - 稅率 ) / 平均總資產 ] *100%
       資產報酬率愈高越好

6. 從現金流量看公司財務風險 :

    a

7. 選擇配息穩健的企業賺錢 :

    現金殖利率 = 每股股利 ( 現金股利 + 盈餘配股 ) / 每股市價
    現金殖利率愈高表示越具投資價值

8. 從本益比判斷合理股價 :

    本益比 = 股價 / 每股稅後純益 ( PER = P / EPS )











2014年8月3日 星期日

[ Android ] : bluetooth HCI log ( >= android 4.3)


After android 4.2, the bluetooth stack was changed from bluez to bluedroid;
so... the log tool ( hci tools ) was abandoned.

But you can still get BT log by thess 3 steps :

1. enable BT HCI logger at "settings > developer" :

2. modify the log level you want trace :

a. the location of configure file at /etc/bluetooth/bt_stack.conf

b. then modify the file content:
============================================================
# Enable BtSnoop logging function
# valid value : true, false
BtSnoopLogOutput=false

# BtSnoop log output file
BtSnoopFileName=/sdcard/btsnoop_hci.log

# Enable trace level reconfiguration function
# Must be present before any TRC_ trace level settings
TraceConf=true

# Trace level configuration
#   BT_TRACE_LEVEL_NONE    0    ( No trace messages to be generated )
#   BT_TRACE_LEVEL_ERROR   1    ( Error condition trace messages )
#   BT_TRACE_LEVEL_WARNING 2    ( Warning condition trace messages )
#   BT_TRACE_LEVEL_API     3    ( API traces )
#   BT_TRACE_LEVEL_EVENT   4    ( Debug messages for events )
#   BT_TRACE_LEVEL_DEBUG   5    ( Full debug messages )
#   BT_TRACE_LEVEL_VERBOSE 6    ( Verbose messages ) - Currently supported for TRC_BTAPP only.
TRC_BTM=2
TRC_HCI=2
TRC_L2CAP=2
TRC_RFCOMM=2
TRC_OBEX=2
TRC_AVCT=2
TRC_AVDT=2
TRC_AVRC=2
TRC_AVDT_SCB=2
TRC_AVDT_CCB=2
TRC_A2D=2
TRC_SDP=2
TRC_GATT=2
============================================================
you should change BtSnoopLogOutput=false >> BtSnoopLogOutput=true
and change the log level you interest, like : TRC_L2CAP=2 >> TRC_L2CAP=5
notice that the output log file at /sdcard/btsnoop_hci.log

3. read your output log file by wireshark :