2010年10月12日 星期二

[Qt] string/byte converting

轉換Qt編程時候用得甚多,可是老記不住,每次都要找,很麻煩,就先記下來吧~

11、各種資料類型的相互轉換
char * 與 const char *的轉換
char *ch1="hello11";
const char *ch2="hello22";
ch2 = ch1;//不報錯,但有警告
ch1 = (char *)ch2;

char 轉換為 QString
其實方法有很多中,我用的是:
char a='b';
QString str;
str=QString(a);

QString 轉換為 char
方法也用很多中
QString str="abc";
char *ch;
ch = str.toLatin1.data();

QByteArray 轉換為 char *
char *ch;//不要定義成ch[n];
QByteArray byte;
ch = byte.data();

char * 轉換為 QByteArray
char *ch;
QByteArray byte;
byte = QByteArray(ch);

QString 轉換為 QByteArray
QByteArray byte;
QString string;
byte = string.toAscii();


QByteArray 轉換為 QString
QByteArray byte;
QString string;
string = QString(byte);
這裏再對這倆中類型的輸出總結一下:
qDebug()<<"print";
qDebug()<qDebug()<qDebug()<qDebug()<qDebug()<qDebug()<但是qDebug()<qDebug()<
int 轉 QString
int a=10;
QString b;
b=QString::number(a)

QString 轉int
QString a="120"
int b;
b=a.toInt()

(updated by 2010/10/14)

2010年10月8日 星期五

Programming C, [volatile]

參考來源: 阿~~-y朙的不小格, C語言-volatile用法

C語言-volatile用法

volatile的本意為"易變的"的意思

由於存取暫存器的速度要快過RAM,所以編譯器一般都會作減少存取外部RAM的最佳化。
例如:

static int i=0;

int main(void)
{
...
while (1)
{
if (i) dosomething();
}
}

/* Interrupt service routine. */
void ISR_2(void)
{
i=1;
}

此程式的本意是希望ISR_2中斷產生時,在main當中調用dosomething函式是,
但由於編譯器判斷在main函式裡面沒有修改過i,
因此可能只執行一次對從i到每暫存器的Read操作,
然後每次if判斷都只使用這個暫存器裡面的“i副本”,
導致dosomething永遠不會被引用。如果將變數加上volatile來修飾,
則編譯器保證對此變數的Read/Write操作都不會被最佳化(肯定會被執行)。
此例子中i也應該如此說明。

一般來說,volatile用在以下幾個地方:

1、中斷伺服程式中修改的供其它程式檢測的變量需要加volatile。

2、多任務環境下各任務間共享的標誌應該加volatile。

3、記憶位址對應的硬體暫存器通常也要加volatile,因為每次對它的Read/Write都有可能有不同的意義。

另外,以上幾種情況經常還要同時考慮數據的完整性
(相互關聯的幾個標誌Read一半被打斷了而重新Write),
第1項目中可以通過關中斷方式來實現,
第2項目中可以禁止任務調度,
第3項目中則只能依靠硬體的良好設計。

2010年9月29日 星期三

[pic18net] original_web_change_appconfig_procedures

(Based on Microchip TCPIP Stack 5.25v)

http2.C -> case SM_HTTP_PROCESS_POST: -> c = HTTPExecutePost(); -> HTTPExecutePost() -> if(!memcmppgm2ram(filename, "protect/config.htm", 18)) return HTTPPostConfig(); -> HTTPPostConfig() -> //Read all browser POST data from "config.htm" web-page

[pic18net] flag check DHCP disabled or not

(Based on Microchip TCPIP Stack 5.25v)
Key point is this flag check DHCP disabled or not: "AppConfig.Flags.bIsDHCPEnabled"


for DHCP-Client disabled/Off (static IP):
main() function -> InitAppConfig() -> StackInit() -> check if(!AppConfig.Flags.bIsDHCPEnabled).. -> DHCPDisabled(0) -> in the main-Loop -> if(dwLastIP != AppConfig.MyIPAddr.Val) -> finalized the network configuration with static IP.


for DHCP-Client enabled/On (DHCP IP):
main() function -> InitAppConfig() -> StackTask() -> if(AppConfig.Flags.bIsDHCPEnabled).. -> if(DHCPIsBound(0)).. -> get the latest DHCP IP-address configuration -> AppConfig.Flags.bInConfigMode = FALSE; -> in the main-Loop -> if(dwLastIP != AppConfig.MyIPAddr.Val) -> finalized the network configuration with DHCP-Client IP -> in the main-Loop -> if(dwLastIP != AppConfig.MyIPAddr.Val) -> finalized the network configuration with DHCP-Client IP.


note 1 for "AppConfig.Flags.bInConfigMode".

Based on Microchip tcpip stack v5.25, the global flag, "AppConfig.Flags.bInConfigMode" can be considered the network-configuration running or not. While network-configuration running(if (AppConfig.Flags.bInConfigMode == TRUE)), all of the s/w network tcpip stack must not running. After the network-configuration done/finished (if (AppConfig.Flags.bInConfigMode == FALSE)), all the s/w network tcpip stack can run afterwards.


note 2 for "AppConfig.Flags.bInConfigMode".

Based on Microchip tcpip stack v5.25, when DHCP-Client disabled/Off state, there is no setting to have "AppConfig.Flags.bInConfigMode = FALSE;". But when DHCP-Client disabled/On state, "AppConfig.Flags.bInConfigMode = FALSE;" can be found in the function, "StackTask()"..; if(DHCPIsBound(0)) -> AppConfig.Flags.bInConfigMode = FALSE;

2010年8月23日 星期一

[pic18net] Tcpip Demo App project picking

Base on TCPIP v5.20 application structure..



By following up with the above NECESSARY structure SDK, then the whole projector for "TCPIP Demo APP" is enought!!

2010年4月13日 星期二

[pic18net] string-buffer 宣告, 大有文章..

"固定字串"作宣告時 (ex, BYTE RdyPrompt[]="Program ready now.";); 會耗用哪一區/哪一部份(ex, Program/Data memory)的記憶體.. 在pic 系列中確實大有文章, 值得細細規劃/注意!!


1.
(Global declaration..)

2.
(Inner function declaration..)

3.
("ROM" decoration added..)

2010年4月3日 星期六

[pic18net] uart-communication by ISR

UART-Process by ISR

(1) taking advance of [Maestro] application module, Application Maestro
for PIC18 series
.
I'd been trying that UART2TCPBridge sample for reference of my apps, but fail..~_~


(2) make sure that pic18 system-clock rate
2a. PIC18net.2 board based

2b. In the "HardwareProfile.h", we found that..
(line156)

..
#ifdefine (PICDEMNET2) ||..
#define GetSystemClock() (41666667ul) //HZ
..

The system clock is "41.67MHZ".

2c. Maestro utility for USART interrupt by C, instead of Assembly

By default installation, the installed folder is "C:\Program Files\Microchip\MpAM".


2d. baudrate: 19200 bps


2e. have the 3 files putting into "the whole project"..
(1) UARTIntC.c
(2) UARTIntC.h
(3) UARTIntC.def


2f. In the main function of initialized state
call this function, "UARTIntInit()" calling.


2g. using the below pressure-testing code for Receiving and Sending..

...
//pressure testing for UART-communication by -----.---, 2010/04/03
if(!vUARTIntStatus.UARTIntRxBufferEmpty)
{
UARTIntGetChar(&chData);
if(!vUARTIntStatus.UARTIntTxBufferFull)
UARTIntPutChar(chData);
}//end of UART RCV-buffer not EMPTY
...


(3) pressure-testing, (N/G).. how come?!

2010年3月28日 星期日

[pic18net] data-type and keyword

(1) keyword: "static"

MPLAB C18 supports parameters and local variables allocated either on the software stack or directly from global memory. The static keyword places a local variable or a function parameter in global memory instead of on the software stack.[3] In general, stack-based local variables and function parameters require more code to access than static local variables and function parameters (see static Function Arguments). Functions that use stack-based variables are more flexible in that they can be re-entrant and/or recursive.

[3] static parameters are valid only when the compiler is operating in Non-Extended mode.
(see Selecting the Mode).


(2) data-type, BOOL for pic18
allocated 1-byte space


(3) data-type, WORD for pic18
allocated 2-type space

2010年3月25日 星期四

[pic18net] add file in MPLAB-IDE


In case of portable concerned for the whole project, supposed to choose the below setting while one additional file added into the MPLAB-IDE project.

2010年3月14日 星期日

[pic18net] software-reset with RAM not initialized

如果呼叫 function, pic18net的 Reset(), 預設此 function為 software-reset機制。
pic18 的 software-reset 預設機制, 是不清除 RAM內的宣告變數 (ex, array/variable/pointer..)。

如果所宣告的變數已在上次有先前的處理資料/數值.. 有可能因為沒被清除而導致程式邏輯誤判而百思不得其解, 到底錯誤在何處..

2010年3月13日 星期六

[pic18net] how to debug, instead of "UART" way

(1)
By original sample, the AJAX sample can refresh the corresponding variable and state by the interval 500 m-seconds.

New added one debugging-MSG with the HTTP web-server for SSI output in the AJAX sample.

(2)
slower down the debug-MSG output by time-interval skill

2010年3月8日 星期一

[pic18net] http2 keeping, but no smtp-client

想保留 web-server, 但不需用到 smtp-client..
(tcpipconfig.H)
have the following defined disabled:
//#define STACK_USE_HTTP_EMAIL_DEMO

(That's it!!)

[pic18net] Definition of PIE1bits and PIR1bits

After the whole project of pic18 searching, not found the definition, "PIE1bits" and "PIR1bits"..

In the "[root-DIR]\mcc18\h" path, both of the 2 defiitions can be found by each dedicated IC-header description.

2010年1月29日 星期五

[pic18net] TCPIP_DEMO_APP for PIC18F67J60

The 'Hardwarprofile.H', between PIC18F67J60 and PIC18F97J60 , has different by default.

By default, PIC18F67J60 is based on [Ethernet RADIO], no EEPROM involved, for [TCPIP DEMO APP] project.

And By default, PIC18F97J60 is based on [PICDEMnet2], with EEPROM involved, for [TCPIP DEMO APP] project.

To be mentioned, some of Hardware-configuration are supposed to be modified for EEPROM and diverse PIC18 micon pin-definition.

If no modification for [TCPIP DEMO APP] project in "PIC18F67J60" based, then there will be Linking-Error while building the [TCPIP DEMO APP] project.

[Microchip PIC] diverse versions for C-Compilers

From this [MPLAB C Compilers] link, we can find out the diverse-versions introduction:
MPLAB C Compilers - Installing and Upgrading

Time-Limited Standard Evaluation Edition.
時效過後, 就不再能夠作"最佳化"..
and~
Lite Edition.
Lite版本, 不能夠作"最佳化"..

2010年1月20日 星期三

Telnet tutorial

使用Telnet指令來測試SMTP是否正常運作?
依下列步驟確認主機和 IMC 之間的通訊是否正常進行(附註:每行指令輸入完成後,請按下 鍵):
使用下列指令啟動 TELNET 工作階段:
Telnet 125.125.0.4 25 (置換上述 IP 位址)

如果正常運作,即可看到下列來自 IMC 的回覆:
220 site.company.com Microsoft ESMTP Internet Mail Service ,Version:5.0.xxxx.xxxx ready.

鍵入以下指令並開始進行通訊:
HELO test.company.com

您會看到下列回應:
250 OK

鍵入以下指令來通知 SMTP郵件訊息源自何處:
MAIL FROM:

您會得到下列回應:
250 OK - MAIL FROM

鍵入下列指令來通知 SMTP郵件訊息的目的地位址(使用有效的收件者 SMTP 位址)。
RCPT TO:

您會看到下列回應:
250 OK - Recipient

鍵入下列指令以通知SMTP已準備好傳送資料:
DATA

您會看到下列回應:
354 Send data. End with CRLF.CRLF

鍵入下列指令以加入主題:
Subject: test message

然後連按兩次 Enter 鍵。

該指令沒有任何回應。

附註:兩個 Enter 指令符合 RFC 822 規則,即表示 822 指令必須在一列空白後。
鍵入下列指令以加入郵件本文:
This is a test message

您無法看到本指令的回應。
在下一空白列輸入英文句點,然後按下 ENTER 鍵。

您會看到下列回應:
250 OK

鍵入下列指令以切斷連結:
QUIT

您會看到下列回應:
221 closing connection

在執行上述任一指令後,若收到「500 Command not recognized」錯誤訊息,則表示由於語法錯誤或指令無效,導致 SMTP 無法識別您鍵入的內容。
登入您在上述步驟 4 中,郵件收件者的用戶端信箱。如果信箱內有您的測試郵件訊息,則表示傳入SMTP 通訊運作正常。

2010年1月18日 星期一

ipv6 reference

Just surfing in the web, found that good article for IPv6..

ipv6資料整理.

[digested some of prefix..]
本來認為不會這麼快用到ipv6的功能,但在windows 7的homegroup及ipv6使用心得,以及建立方法這篇文章中,發現可以透過ipv6解決windows 7 的電腦之間,ipv4不同網段的資料共用問題,然後有網友問到可否同樣在windows xp與windows 7中,利用ipv6來解決ipv4不同網段的檔案分享問題。在windows 7很簡單,啟用ipv6就可以分享檔案了,完全不必多做設定,但在windows xp與windows 7之間,經過我努力的查找資料,相關的資料實在很貧乏,很可惜沒有找到建立共用檔案的方法。

不過雖然失敗,卻也吸收了不少ipv6的相關知識,在此記錄下來,ipv4的ip快耗盡了,以後總是會用到ipv6,先整理一些ipv6的基本知識。...

2010年1月7日 星期四

[pic18net] UART processing

============================================================
(2010/01/07 updated)


1. befor receiving in by UART (ex, ReadUART() function call)..
MUST do the below process:
while(!DataRdyUART());


(Receiving UART-msg by one-byte, "c")

//Receive a byte
while(!DataRdyUART());
c = ReadUART();



2. befor sending out by UART (ex, WriteUART() function call)..
MUST do the below process:
while(BusyUART());


(Send-out UART-msg by one-byte, "c")

//Transmit a byte
while(BusyUSART());
putcUART(*data);




By following up the above 2 must-procedures, that's the complete RECEIVE-In/Send-Out by UART procedure.

============================================================
(2010/01/22 updated)

in [TCPIP Demo APP] project for PIC18xxx series, the UART initialization is located in the below section (Line0491 ~ Line0509) of "InitializeBoard()" function.


============================================================
(2010/01/27 updated)
For the intro by 2010/01/07, that's NOT good way to receiving and/or sending UART messages, while multi tcpip stack tasks running simultaneously.

The better way comes from (UART <-> TCP Bridge Example), [UART2TCPBridge.C].
The ISR function (UART2TCPBridgeISR( )) for UART receiving and/or sending message is the CLASSIC example.