2021年6月14日 星期一

2021年2月22日 星期一

修正Cmder backspace會錯亂的問題

找到Cmder安裝位置的vendor\clink.lua
例如D:\cmder\vendor\clink.lua

找到{lamb}

要筆者手上的版本191012為例

在第50行
local cmder_prompt = "\x1b[1;32;40m{cwd} {git}{hg}{svn} \n\x1b[1;39;40m{lamb} \x1b[0m"
把{lamb}換成$
local cmder_prompt = "\x1b[1;32;40m{cwd} {git}{hg}{svn} \n\x1b[1;39;40m$ \x1b[0m"

就可以解決了。


2017年2月16日 星期四

Windows7修複圖示壞掉的問題


今天電腦開重機後,有個程式的圖案變成找不到程式的圖案,可是程式實際上還在,點下去也能執行,查了一下是圖示的快取出錯,按下面步驟操作即可修複。




開始->執行->cmd->Enter,叫出命令提示字元後,依序進行下面的操作即可完成。
taskkill /F /IM explorer.exe
cd /d %userprofile%\AppData\Local
attrib -h IconCache.db
del IconCache.db
start explorer

2017年2月3日 星期五

如何使用adb幫你的Ticwatch2台灣限定版安裝apk

前幾天總算拿到預購已久的Ticwatch 2國際版,把玩沒多久就覺得,可用程式少到一個不行……
接著就興起一股想要賣掉它的想法,不過,買都買了,不如來找看看有沒有方法讓它變的像話點的方法吧!
先是找有沒有辦法改成Android Wear相容模式啊(陸版才有,嘖…),後來又看有沒有測試版的韌體可以用啊。
最後,在陸版Ticwatch論壇找到了一些方法能夠自己另外安裝apk,特別整理出來造福一下大家。

  1. 啟用開發者選項
     設置->關於->連擊Ticwear版本,直到出現"您已處於開發者模式,無需進行此操作"。
  1. 開啟ADB調試、通過WIFI調試
     設置->開發者選項->啟用"ADB調試"、啟用"通過WIFI調試"
  1. 於PC上安裝ADB
     安裝ADB的方法稍微Google一下都能找到,就不寫方法跟載點了
     筆者的安裝路徑在D:\ticwatch\adb\

  1. 透過ADB連線到手錶
     因要透過WIFI連線的關係,我們要先知道手錶現在的IP位置,按設置->網路與連接->啟用無線網路->連到自己的AP後,依無線網路->進階選項->IP地址,找到自己的IP並記下來。
     以筆者為例,IP為192.168.8.32

     接著叫出命令提示字元,進入D:\ticwatch\adb,(可以直接在目錄中按住shift後,在空白處點擊滑鼠右鍵,在此處開啟命令視窗)。



     命令視窗開啟後,依剛剛取得的IP輸入
adb connect 192.168.8.32:7272
     
     當出現connected to 192.168.8.32:7272,代表你已經完成前置動作了。

  1. 安裝APK
     完成連線後,我們就可以開始安裝APK啦,獲取APK的方法很多,不知道怎麼拿到的可以透過此網址取得http://apps.evozi.com/apk-downloader/
     將下載好的apk放到D:\ticwatch\adb裡面,接著在命令視窗裡輸入
adb install d:\ticwatch\c.apk
     (假設我的apk檔名為c.apk)
     
     等待一段時間,直到出現Success時,代表已完成安裝。

2016年12月8日 星期四

About AT Attachment (ATA)

Advanced Technology Attachment,簡稱「ATA」
ATA是一個控制器技術,而IDE是一個符合它的磁碟機技術,但是兩個術語經常可以互用。
SATA(Serial ATA)於2002年推出後,原有的ATA改名為PATA(並列高技術配置,Parallel ATA)。
ATAPI (ATA Packet Interface)是一款ATA協定,允許使用ATA連接到硬碟以外的周邊裝置。

從架構面來看,ATA分為以下三層
ATA application Layer:
依照各個Command的不同,做出相對應的Flow。舉例來說,送出讀取SMART資訊的Command後,返回的資料該怎麼從Raw dataParse出對應的資訊。
ATA transport protocol layer:
維持Protocol的基本流程,除了基本Protocol外,上層比較會接觸到的Command Protocol基本上分為Non-data / PIO Data-In / PIO Data-Out  / DMA / DMA Queued / PACKET Command protocol,每一種都有自己的Flow。
ATA interconnect layer:
最接近物理層面的一層,會依據PATA/SATA而有相對應的處理。


所有的Command Set都是建構在Client-Server的觀念去完成的,硬碟是Server /  主機是Client

Command Protocol下的各種類型非常重要,所有的ATA Command後面一定會寫明該Command是哪一種類型,這代表著該Command送出後,Host與Device該採用什麼樣的方式來做溝通。

ATA protocol types are defined
  • Host Power-on protocol
  • Device Power-on protocol
  • Nexus Loss protocol
  • Device Management protocol
  • Command protocol
    • Non-data Command protocol
    • PIO Data-In Command protocol
    • PIO Data-Out Command protocol
    • DMA Command protocol 
    • DMA Queued Command protocol
    • PACKET Command protocol


以Non-data Command protocol來說,流程如下:
1.由Application Client Send Commandhost Transport protocol layer。
2.Device Transport protocol layer收到Command後,發送給Device server,然後Device server開始處理此Command。
3.Devicecommand處理完後,device server發出Send Command Function Complete responsedevice port。
4.Host port收到response後,送出Command Function Complete Received confirmationApplication Client



其它類型的Protocol因為基本上就是看圖說故事,就不在此描述了。下次再來介紹ATA中各種Field的定義及目的。

關於ATA Trim Command

Trim 指令讓OS能夠通知SSD哪個Block的data已經不被需要了,讓SSD內部可以對此Block進行清除。在固態硬碟出現後,Trim即開始被作業系統採用,其原因在於SSD的設計原理與傳統硬碟有極大的不同,如果用傳統操作方法,當作業系統對SSD執行刪除跟格式化操作時,會發生預料之外的效能衰退。 在啟用Trim後,SSD能夠使用更有效率的方法去做garbage collection,來加速未來的寫入操作的時間。

大部份SSD其內部的背景garbage collection機制完全獨立於Trim,就算在作業系統不支援Trim的情況下,SSD依然可以將本身的效能維持在良好的狀態。
Trim指令是不可逆的,沒有回復的可能性。

傳統Trim command定義無法被排入Queue裡,這使得它不容易跟read/write queue command混用,於是SATA 3.1協議針對這點推出了QUEUE TRIM COMMAND來補救。

TRIM is implemented under the DATA SET MANAGEMENT command (opcode 06h)

跟Trim相關支持的Bit如下:
Word 69 bit 14 Deterministic data in trimmed LBA range(s) is supported
Word 69 bit 5 Trimmed LBA range(s) returning zeroed data is supported
Word 169 bit 0 0 the TRIM bit in the DATA SET MANAGEMENT command is supported

TRIM SUPPORTED Bit
Device是否支援Trim command。
DRAT SUPPORTED Bit (Deterministic read after TRIM is supported)
此Bit為1時,每次Trim後Read LBA取得的資料都是固定的。
RZAT SUPPORTED Bit (Trimmed LBA range(s) returning zeroed data is supported)
此Bit為1時,每次Trim後Read LBA取得的資料都是固定的,且拿到的資料都為0。



TRIM SUPPORTEDDRAT SUPPORTEDRZAT SUPPORTEDDescription
0Should be 0Should be 0不支援Trim功能。
10Should be 0Device不保證每次Read Trimmed LBA會回一樣的數據。
110Device保證每次Read Trimmed LBA的到的結果都是固定的,但FW可以選擇要寫什麼值進去。(換句話說,只要你能夠保證資料不變,讓它維持在原先的值也是可以的。)
111Device保證每次Read Trimmed LBA的結果都是固定且為零。


2015年11月23日 星期一

如何Dump usb device插上移除時的Mount Info

1.
Add dump.sh
#!/bin/sh
env >> /Customer/helper.log
echo "CMD:" $@ >> /Customer/helper.log
echo "----------     end     ----------" >> /Customer/helper.log

2.
echo /Customer/dump.sh > /proc/sys/kernel/hotplug

3.
之後重新插拔device 去看 /Customer/helper.log 有沒有印出 變數
cat /Customer/helper.log

2015年3月23日 星期一

Memory互踩注意事項

當確定是誰去踩之後,有幾點可以先確認 1. pointer是否被更改。 2. malloc時的size是否與之後預期使用的值是一致的 3. 在assign value的前一行去做sleep,看看是否會更容易打出來。

2013年5月28日 星期二

Linux Screen 小技巧

在.screenrc加入下面這段指令可以讓你的Screen畫面變的更好用。

caption always "%{=u .G} %-w%<%{=ub .y}%n %t%{=u .G}%+w "
#caption always "%{= wk} %{= KY} [%n]%t %{-} %="
#caption always "%{= wk} %{= KY} [%n]%t @ %H %{-} %= %{= KR} %l %{-} | %{= KG} %Y-%m-%d %{-} "
#caption always "%{=B Bb} %{=B WK}%-w%<%{=B Yk} %n %t /%{=B WK}%+w%-02=%{=B B"
#hardstatus alwayslastline "%{=b bW} {%l}%018= %{=B WK} $HOST %-027=%{YK} %Y-%m"
bindkey ^[z prev
bindkey ^[x next
bindkey ^[, prev
bindkey ^[. next

defscrollback 10000
altscreen
autodetach on
vbell off

termcapinfo xterm|xterms|xs ti@:te=\E[2J

2013年4月11日 星期四

Get GNU screen resurrection after rebooting There are two options that I'm aware of which get close to resurrection. First, you can put some startup screens in your .screenrc, like this:
# ------------------------------------------------------------------------------
# STARTUP SCREENS
# ------------------------------------------------------------------------------

screen bash
screen emacs -nw
chdir /home/me/src
screen -t code


Second, take a look at this project which will
Re-create the screen windows
Populate them with the session history you once had before the reboot
Log you into your previously logged in host via ssh
Place you into the same working directory you were once in.
Most of this data is derived from the prompt. Running any previously ran commands would be extremely dangerous, so this is as far as I can get you.

2013年2月7日 星期四

為你的Terminal Bash Prompt加上顏色

為了在落落長的Terminal畫面中快速看到前先下指令點,在Prompt上加上顏色是個不錯的方法,在.bashrc加入以下指令即可達到這樣的效果
export PS1='\[\033[01;35m\][\A]\[\033[00;32m\][\h \[\033[32m\]\W]\[\033[m\]\$ '

//PS:原先使用這種方式會有游標無法對齊的情況,將replace "\e[" to "\[\033[" 即可解決。
export PS1='\e[\[0;32m[\A][\h \W]$ \e[m'

Reference:how-do-i-fix-my-colour-bash-prompt-wrapping
Reference:http://tldp.org/HOWTO/Bash-Prompt-HOWTO/c327.html

2012年2月9日 星期四

命名習慣

一般變數 全部小寫 名詞
struct 每個單字頭大寫
define,enum 全大寫
函式 第一個單字小寫 動詞
全域 開頭加上g_
const 開頭加上k_

gcc編譯選項

gcc編譯選項

-c 只做預處理(preprocessor)、組譯(Assembler)、還有編譯(Compiler),不做連結
-S 只做組譯(Assembler) 
-e 只做預處理(preprocessor) 
-o file 輸出名稱 
-v 編譯時顯示工具的詳細資訊 
-Wall 警告訊息 
-g debug用(gdb)

DropBear 建立設用者

Linux建立使用者
passwd: unknown uid 0 

echo "root:x:0:0:root:/root:/bin/sh" > /etc/passwd 
echo "root:::0:::::" > /etc/shadow 
echo "root:x:0:" > /etc/group 

echo "root:x:0:0:root:/root:/bin/sh" > passwd 
echo "root:::0:::::" > shadow 
echo "root:x:0:" > group 

第一次使用passwd改密碼 
adduser 

建立/etc/dropbear/ 
再來執行兩個指令 
/etc/dropbear/dropbearkey -t rsa -f /etc/dropbear/dropbear_rsa_host_key 
/etc/dropbear/dropbearkey -t dss -f /etc/dropbear/dropbear_dss_host_key 

./dropbear

2011年12月16日 星期五

Linux指令筆記

samba mount
mount -t cifs //ip/path /localpath -o username=user,password=pass

2011年12月2日 星期五

[轉貼] mkimage使用詳解

uboot源代碼的tools/目錄下有mkimage工具,這個工具可以用來製作不壓縮或者壓縮的多種可啟動映像檔案。

mkimage在製作映像檔案的時候,是在原來的可執行映像檔案的前面加上一個0x40位元組的頭,記錄參數所指定的訊息,這樣uboot才能識別這個映像是針對哪個CPU體系架構的,哪個OS的,哪種類型,加載內存中的哪個位置,入口點在內存的那個位置以及映像名是什麼

root@Glym:/tftpboot# ./mkimage
Usage: ./mkimage -l image
-l ==> list image header information
./mkimage -A arch -O os -T type -C comp -a addr -e ep -n name -d data_file[:data_file...] image
-A ==> set architecture to 'arch'
-O ==> set operating system to 'os'
-T ==> set image type to 'type'
-C ==> set compression type 'comp'
-a ==> set load address to 'addr' (hex)
-e ==> set entry point to 'ep' (hex)
-n ==> set image name to 'name'
-d ==> use image data from 'datafile'
-x ==> set XIP (execute in place)
參數說明︰

-A 指定CPU的體系架構︰

取值 表示的體系架構
alpha Alpha 
arm A RM 
x86 Intel x86
ia64 IA64
mips MIPS
mips64 MIPS 64 Bit
ppc PowerPC
s390 IBM S390
sh SuperH
sparc SPARC
sparc64 SPARC 64 Bit
m68k MC68000

-O 指定作業系統類型,可以取以下值︰
openbsd、netbsd、freebsd、4_4bsd、linux、svr4、esix、solaris、irix、sco、dell、ncr、lynxos、vxworks、psos、qnx、u-boot、rtems、artos

-T 指定映像類型,可以取以下值︰
standalone、kernel、ramdisk、multi、firmware、script、filesystem

-C 指定映像壓縮模式,可以取以下值︰
none 不壓縮
gzip 用gzip的壓縮模式
bzip2 用bzip2的壓縮模式

-a 指定映像在內存中的加載位址,映像下載到內存中時,要按照用mkimage製作映像時,這個參數所指定的位址值來下載

-e 指定映像營運的入口點位址,這個位址就是-a參數指定的值加上0x40(因為前面有個mkimage添加的0x40個位元組的頭)

-n 指定映像名

-d 指定製作映像的源檔案
Reference from http://www.wretch.cc/blog/poemsoul/15441093

2011年11月14日 星期一

const的意義(const pointer, pointer to const, const pointer to a const, const function...)

#include
#include
using namespace std;
class A
{
private:
     int y;
public:
 A(){
  y=0;
 }
 int f1(int x) const // 此const代表此function不可以修改Data Member
 {
  x++;
  // y++; // Error! y為Data Member,因此不可以修改
  return y;
 }
 const int f2(int x) // 回傳值為const
 {
  x++;
  y++;
  return y;
 }
 int f3(int const x) // 參數為const
 {
  // x++; // Error! x為const,不可以修改
  y++;
  return y;
 }
 void f4(int const *x) // x is variable pointer to a constant integer,也可以寫成f4(const int *x)
 {
  // (*x)++; // Error! pointer x所指向的實體為const,因此不可以修改其值
  *x++; // 此行的意思是*(x++),先修改pointer x的值,在指向實體
 }
 void f5(int const &x) // x is variable reference to a constant integer
 {
  // x++; // Error! x就是一個const
 }
 void f6(int *const x) // x constant pointer to a variable integer
 {
  (*x)++;
  // *x++; // Error! Constant pointer x 不可以指向其他實體
 }
 const char * f7() // 回傳一個variable pointer to a constant char
 {
  return "ABC";
 }
 void f8(const int * const x) // x is constant pointer to a const integer
 {
  // (*x)++; // Error! x所指向的實體為const,因此不可以修改其值
  // *x++; // Error! Constant pointer x 不可以指向其他實體
 }
};
int main(){
 A a;
 int x=3;
 a.f1(x);
 a.f2(x);
 a.f3(x); // int x 會自動轉成const int x傳入
 a.f4(&x) ;
 a.f5(x) ;
 const char *s = a.f7(); // 必須使用一個const來接const
 // s[0]='0'; // Error! 無法對const 變數進行改變動作
 return 0;
}

Reference: http://csie-tw.blogspot.com/2010/03/c-constconst-pointer-pointer-to-const.html

2011年11月9日 星期三

How to use cpplint.py

First, you should install python

Second, download cpplint.py

Third, run below script in command line

cpplint.py –output=vs7 helloworld.cpp

Then you can get the result.

2011年11月4日 星期五

Struct for sockaddr,sockaddr_in,sockaddr_in6,addrinfo

struct sockaddr {
      unsigned short sa_family;        /* address family, AF_xxx */
      char sa_data[14];                /* 14 bytes of protocol address */
};

struct sockaddr_in {
      short int sin_family;            /* Address family AF_INET */
      unsigned short int sin_port;     /* Port number */
      struct in_addr sin_addr;         /* Internet address */
      unsigned char sin_zero[8];       /* Same size as struct sockaddr */
};
struct in_addr {
      unsigned long s_addr;            /* Internet address */
};

struct sockaddr_in6 {
      sa_family_t sin6_family;         /* AF_INET6 */
      in_port_t sin6_port;             /* transport layer port # */
      uint32_t sin6_flowinfo;          /* IPv6 traffic class & flow info */
      struct in6_addr sin6_addr;       /* IPv6 address */
      uint32_t sin6_scope_id;          /* set of interfaces for a scope */
};
struct in6_addr {
      uint8_t s6_addr[16];             /* IPv6 address */
};

struct addrinfo{
      int ai_flags;                    /* AI_PASSIVE,AI_CANONNAME,AI_NUMERICHOST */
      int ai_family;                   /* AF_INET,AF_INET6 */
      int ai_socktype;                 /* SOCK_STREAM,SOCK_DGRAM */
      int ai_protocol;                 /* IPPROTO_IP, IPPROTO_IPV4, IPPROTO_IPV6 */
      size_t ai_addrlen;               /* Length */
      char *ai_cannoname;              /* */
      struct sockaddr *ai_addr;        /* struct sockaddr */
      struct addrinfo *ai_next;        /* pNext */
};

2011年10月24日 星期一

Dichotomy Sort 二分排序法

二分法排序(Dichotomy Sort)的精神就是將目標對切,與中間元素相比,較小就把左邊剩餘的陣列再對切,然後重複做一樣的事直到最後
反之亦然,把所有元素都做過這個動作後就是排序好的陣列

int array[100];
for (int i = 0; i < 100; i++)
{
 int start, end, mid;
 start = 0;
 end = i - 1;
 mid = 0;
 int temp = array[i];
 while (start <= end)
 {
  mid = (start + end) / 2;
  if (array[mid] > temp)//目標元素在陣列左邊
  {
   end = mid - 1;
  }
  else
  {
   start = mid + 1;
  }
 }
 for (int j = i - 1; j > end; j--)//找到插入的位置,將其後的元素後移一位
 {
  array[j + 1] = array[j];
 }
 array[end + 1] = temp;

}