Tuesday, December 23, 2008

CSR C3 F.W. And Trim With Agilent N4010A, 2008/12/24

C3 F.W. And Trim 總算 Released 了, 紀錄如下 :

1. 原 Query Frequency Offset Command : "DIAG:HW:DAP:READ:BT:FOFF?" 原廠 FAE LEI_YANG 釋疑如下 :

The command "DIAG:HW:DAP:READ:BT:FOFF?" is a diagnostic command for debug only. We strongly recommend to use "FETCh:FOFF?" to replace it.
Yang Lei
WiNet Application Engineer
Mobile Broadband Division
China Communications Operation
Agilent Technologies
Tel : +86(10)64396940
Fax: +86(10)64397666
TN: 658-6940
Email: lei_yang@agilent.com

? 不能用 "DIAG:HW:DAP:READ:BT:FOFF?" Get Frequency Offset, 但用 "FETCh:FOFF?" 卻 Always Get Last Test Result, N4010A 並沒有再 "Run/Resume" 一次, 向原廠 FAE LEI_YANG 求助 Ans : 以 "INIT" Command 讓 N4010A "Run/Resume" 一次, 而 Command And Command 間可用分號串聯 :
Old Command : "DIAG:HW:DAP:READ:BT:FOFF?"
New Command : "INIT;FETCH:FOFF?"

PS : DIAG 並非 SCPI Standard Command, 而且 Agilent 方面也沒有 Document, 更不建議用.

至此對 Agilent N4010A Command 方面已可讓 Test Func Work Fine. 但有些不足的是, 在丟 "INIT;FETCH:FOFF?" N4010A Panel 並沒有自動跳到 "Result" Page, 向原廠 FAE LEI_YANG 求助 Ans : Command "DIAG:KEY 72" Is Equal Panel "Result" Button. 所以用 Agilent N4010A Test BT Trim Result Frequency Offset 部份 OK.


2. CSR BC3 Trim : BC3, BC4 有 Host Based 之差異, BC3 Cold / Warm Reset 須 Wait (Sleep) 1~2 Sec For Core Boot, 剛開始一直用 Debug Mode Step By Step Run, 此類 Timing Issue 不會浮現, Release 時卻一直卡住, BC3 Cold /Warm Reset 需 Sleep (Wait For Boot), BC4 不用.


3. nFore Said, BT ColdBoot OK 後會從 UART 吐版本, 但在 F.W. Download And MAC Write 後做(Use API, Help Notes Equal ColdBoot) ColdBoot 後卻是 "Sometimes" 才吐版本(Use Serial Monitor), 所以需要自行 Query (Use "(b)" Command).


4. BC3 在 BootMode 非 1 And F.W. Download And Coldboot OK 之時不可 Open PC Side COM Port, 於此時間 Open PC Side COM Port 自己所遇到的情況是 Sometimes Open OK and Sometimes Fail, 但如果是 Fail, COM Port 會被 "暫時" Lock, 和 小 P 所遇到的 Uart 亂丟東西雖徵狀有異, 但可能是相同原因所導致.


5. 原 Code 在 F.W. Download 後 SetTimer 後即 close spi handle And Coldboot Module, 這樣會造成 UART Data 尚未 Read(Send 也未知...), PC Side UART 未 Closehandle, BT Module 即 Coldboot. 移除該段 Code 後解決 PC UART Read / Send But BT Module Be Coldboot 問題.


6. SCPI Command 修正如下 :
SCPI Init Command :
"*CLS",
"INST:SEL 'RFA'",
"SENS:BAND 1300000",
"SENS:POW:RANG 5",
"SENS:FREQ:CENT 2441",
"SENS:SWE:TIME .00300",
"INIT" -->> "DIAG:KEY 72" 於此時做 Frequency Offset Test ("INIT") 並無意義, 改成將 Panel LCD 切換至 Result ("DIAG:KEY 72")

SCPI Get Frequency Offset Command :
"DIAG:HW:DAP:READ:BT:FOFF?" -->> "INIT;FETCH:FOFF?" 先做 Test And Then Get Frequency Offset Value.


7. 以 "FETCH:APOW" Command 可 Get DB Value. 先前試遍了 "DIAG..." 開頭的 Command 均 Fail.


8. Debug 過程 UART 一直陸續有問題, 除 Open UART Timing 外, Agilent IO Control 也是元兇之一, 在開啟 Agilent IO Control AP 同時用 Layer 0 的 UART Monitor Tool 可以看到 Agilent IO Control AP 開的時候對每個 UART 都做了 Open / Close (Send?) 動作, 如果是剛好(機率極高) 在不可 Open UART 時 Open UART...., BT F.W. & Trim AP 就會受影響 (Uart 已被 Agilent IO Control Open UART 時搞死), 無法 Open / Read Version BT F.W. Version, 整個程式結果也就不正確了.


9. Search Algorithm : 一開始用 Binary Search 似乎 OK, 但若加進從 Agilent N4010A 的 Frequency Offset Value 再配合 Frequency Offset Table, Worst Case 應在 5 times 可得知 Trim Fail, 4 times 即可 Trim OK.


10. 今日版本已將 Log (S.F. Format) 產生出, 後續修改 :
(1) Trim Value Search Algorithm
(2) Hard Coding -> Variable & There Are Default(Use "define") Value And Can Get From XML
(3) BT MAC & S.F. Issue.

Trim Value Search Algorithm 應該比較簡單, 但要長時間量測.
Hard Coding 則要配合 BT MAC & S.F. 一起改.

Saturday, December 20, 2008

Agilent N4010A Trim BT, 2008/12/20

每好的週末來上工, 要有些突破才行. 今天將 Trim 部份搞定了.
一 : PC <- Line-> Agilent N4010 :
1. 可不用 NI API (但仍須裝 GPIB Cable Driver) 來下 Command.
2. 透過 Agilent 的 Agilent IO Control 可達成 General Purpose Programming.
<1> H.W. Interface : 可使用 (1) USB, (2)GPIB, (3) Ethernet, (4) UART[沒有 Try, 因 PC Com Port 只有一個, 拿去接 BT 了] 等 4 種 Interface Connect To Agilent N4010A.
<2> S.W. Interface : 可只用一組相同的 API 經由 Agilent IO Control Manager 和不同 Connection Cable 對 Agilent N4010 下相同的 SCPI Command.
<3> 針對不同 H.W. Interface, 只須在 Agilent IO Control Manager UI 中設定(Sometimes 要自行 Create Instrument & VISA Alias, Ex : Ethernet, GPIB 等), Configuration VISA Alias OK 後即可在 iopen API 中使用.


二 : PC <- Line-> BT:
1. PC 可透過 CSR 的 API 以 USB, SPI, UART 和 CSR BT Module Connection, 這部份因為 BT Module H.W. 只有拉出 SPI, 所以也只 Try 了 SPI, But 從 Other Project 接手時是使用 UART 的, So UART & SPI 應該都沒問題.
2. 透過如 CSR 所提供之 API 如 initTestEngine(param...)[UART], initTestEngineSpi(param)[SPI] 會 Return 一個類似 Win Handle 的東東, 之後所有對 BT Module 的 Control 都用此 Handle.
Ex :
psWrite
bccmdSetWarmReset
bccmdSetAnaXtalFtrim
radiotestTxstart
bccmdSetAnaXtalFtrim
bccmdSetWarmReset
closeTestEngine
psReadXtalFtrim

三. SCPI Command.
原本這部份最模擬, 因
原 Structure : PC<->NI API<->NI Driver<->NI USB2GPIB Cable<->Agilent N4010A,
但嘗試了 PC<->Agilent API<->Agilent I/O Control Manager<->Agilent Driver<-USB/Ethernet/USB2GPIB->Agilent N4010A 後, 使用相同 SCPI Command 所得結果相同, 驗證了 NI API 只不過是 Bypass 而已.

四. SCPI Command.
原本這部份也很模擬, 因 Command 下了之後根本不知道 N4010A 有沒有 Work, Trace Code 後再至 N4010A Panel 驗證, Parameter 的確有被設定到 N4010A, PC Side 由 Agilent Interactive I/O Tools 設定後再透過直接操作 N4010A 驗證 Value 即可了解.
SCPI Verify Command :
*RST;*OPC?
>> Must Return +1

SCPI Init Command :
"*CLS",
"INST:SEL 'RFA'",
"SENS:BAND 1300000",
"SENS:POW:RANG 5",
"SENS:FREQ:CENT 2441",
"SENS:SWE:TIME .00300",
"INIT"

SCPI Get Frequency Offset Command :
"DIAG:HW:DAP:READ:BT:FOFF?"

So 原 Code Get 後用 Flot 接, exp part 並沒掉, 後續除 1000 再限定 Value 於 -2~+2 間為儀器誤差值 2K.


頻譜分析儀操作 :
1. 先設 Central Frequency (BT : 2.441GHz)
2. 再設定 Span (For Test, 100KHz, 100KHz 指的是 Left ~ Right Side)
3. 再設定 Mark (BT : 2.441GHz)
4. BT Module bootmode -> 2
5. BT Enter Test Mode(2441,50,255,0) => BT Module 發出自己認定的 2.441G
6. 接探針 View & Verify.

Tuesday, December 02, 2008

Windows Standard Modem Driver, 2008/12/02

一直有疑問, Why Desktop 上的 "標準 56000 bps" Modem 不能用 Simcom 的 GPRS Module 上網(Telit & Wavecom 似乎都 OK), NB 卻可以用, 今天將 Driver Backup / Restore To Another 後赫然發現, 其實 NB 上的 56000 bps Modem 其實也不能 Run, 先前可以 Work 是因為有 19200 bps standard modem 之故, 用 56000 bps modem 時實際上是用到了 19200 bps 的 Driver, 難怪可以 Work. 本想改改 Modem Driver (inf file only) Try 看看, 可是除了之前發現的 s95=47 外還有其他 Command Simcom SIM 340 也不支援….., so, 結論是 sim 340z 不支援 Windows Standard 5600 bps, 但 Support 33600 bps, 19200 bps (除 5600 bps Try 過不行外, 其他的沒 Try 過, 不知道). 另一家更…!@#% 的 xnfora 似乎也有這個問題.

Thursday, October 23, 2008

M$ VS2008 下的 Device Application

在 V$ 2008 下建 Device 程式共有下列地方要修改

1. Library Issue : Use MFC in a Shared DLL.

Configuration Properties -> General -> Use of MFC

2. Unicode Issue :

(1) Treat wchar_t as Built-in Type : No

Configuration Properties -> C/C++ -> Language -> Treat wchar_t as Build-in Type

(2) Entry Point : wWinMainCRTStartup

Configuration Properties -> Linker -> Advanced -> Entry Point

3. Message MAP Macro.

Remove Class Name In Message MAP Macro

4. Deployment : Remote Directory.

Configuration Properties -> Deployment -> Remote Directory

5. Debugging, Remote Executable

Configuration Properties -> Debugging -> Remote Executable

6. For "warning C4812...", Modify Relation Template Function.

Compiler Warning (level 1) C4812

Error Message

obsolete declaration style: please use 'new_syntax' instead

In the current release of Visual C++, the explicit constructor specialization is still supported, but it may not be supported in a future release.

The following sample generates C4812:

// C4812.cpp
// compile with: /W1 /c
template
class MyClass;

template
class MyClass {
MyClass();
};

template
MyClass::MyClass() {} // C4812
// try the following line instead
// MyClass::MyClass() {}

7. Run App, …. Can Not Execute! If Use MFC / ATL!

Solution : Copy

(1) mfcce400(d).dll,

D:\Microsoft\WindowsCETools\wce500\Royaltek RC7B\Mfc\Lib\ARMV4I

(2) olece400(d).dll,

D:\Microsoft\WindowsCETools\wce500\Royaltek RC7B\Mfc\Lib\ARMV4I

(3) msvcr90(d).dll [At Least]

D:\Microsoft\Microsoft Visual Studio 9.0\VC\ce\dll\armv4i

To Device Exe Folder!

Tuesday, October 21, 2008

WaveCOM Q2686/Q2687 PC GPRS 上網 Error 692 Or 777

Issue :
用 WaveCOM Q2686 一直無法以 GPRS 上網,

Point :
Trace Modem 的 Log [註 1.],

Reason : Baud Issue
Trace Log 後, 發現 Based On 該 Modem 的 Dial Up Network 會以該 "Default Perferences" [註 2.] Speed 和 Modem 作 Communication, 但 WaveCOM 的 "Autobauding" 似乎沒 Work (Or 自己還不會設定, Telit Default 就 Enable, So 很容易就上網了)

Solution :
因還不會調 XP 的 "Default Perferences" [註 2.], So 就調整 WaveCOM 的 Baud Rate, 以 WaveCOM 的
AT+IPR?
先 Check 目前 Baud Rate, 再以 :
AT+IPR=38400
將 Q2686 Module Baud Rate 設定為 38400, Disconnect Terminal 後再以 38400 Connect Module 後同樣以
AT+IPR?
檢查一次. 確定無誤後 WaveCOM Q2686 的 Dial Number 記得要設成
*99***1#
而不是
*99#
Dial Up Network 的 Max Baud Rate [註 3.] 也要跟著調成 38400(否則一樣無法撥接成功)

[註 1.] : => Select Modem / Properties / Diagnostics / View Log
[註 2.] : => Select Modem / Properties / Advanced / Change Default Perferences.../ General / Port Speed
[註 3.] : => Select Dial Up Network / General / Configure... / Maximum speed(bps)


WinCE 要 Check 一下看有沒有那該屎的 "Default Perferences" [註 2.], 若有的話....又有的玩了...

Friday, October 17, 2008

RasSetEntryProperties, 2008/10/17

達成 RAS Entry Properties Set 功能已經四天了, 再不紀錄就快忘了. 先提幾個 Key Point, (1) Binary Data Structure 似乎找不到正式文件, 得笨笨的一個一個猜, (2) Device Name 和 Entry Name 不要混淆, 上週一就是這部份混淆了, 否則上週一就完成了, 之後還是靠比對 寫入 & Dialog 產生 的 Binary Data 才知道問提出在這.
RASRegSet 是以 Export Entire Class 的 DLL 方式 Implement, 主要的檔案有 3 個, Macro.h, CRASRegSet.h CRASRegSet.cpp, 分別 List 如下 (For WinCE 5.0) :
Macro.h (For Export Entire Class PreDefine)

#ifndef __RAS_MACRO__
#define __RAS_MACRO__

#ifndef AFX_EXT_DATA
#ifdef _AFXEXT
#define AFX_EXT_CLASS AFX_CLASS_EXPORT
#define AFX_EXT_API AFX_API_EXPORT
#define AFX_EXT_DATA AFX_DATA_EXPORT
#define AFX_EXT_DATADEF
#else
#define AFX_EXT_CLASS AFX_CLASS_IMPORT
#define AFX_EXT_API AFX_API_IMPORT
#define AFX_EXT_DATA AFX_DATA_IMPORT
#define AFX_EXT_DATADEF
#endif
#endif

#endif

CRASRegSet.h

// CRASRegSet.h: interface for the CRASRegSet class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_CRASREGSET_H__96AA9E65_FEE2_441F_A7E2_57CEF87FA627__INCLUDED_)
#define AFX_CRASREGSET_H__96AA9E65_FEE2_441F_A7E2_57CEF87FA627__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "Macro.h"
#include
#include

#define __REG_NAME__ _T("BT Connection")
#define __DEVICE_NAME__ _T("Bluetooth DUN on COM2") // Modem Friendly Name, [PS1]
#define __PHONE_NUMBER__ _T("\*99\#")
#define __COUNTRY_CODE__ 0×376
#define __AREA_CODE__ _T("03")
#define __AT_CMD_LEN__ 331

// Following Data Struct Is Reversing From HKEY_CURRENT_USER\Comm\RasBook\Xxxx, (Xxxx Is Modem Device Name)
// Use For API RasSetEntryProperties Parameter, For Set Modem & Extra Command Like "+cgdcont=1,"ip","internet"
// 2008/10/03, Tony.Jou

typedef struct {

WORD wHeader; // 0×00(L:2), Val = 0×30, Unknown

WORD wWaitForCreditCardSec; // 0×02(L:2), Val = 0×0, Wait For Credit Card Tone Seconds,

WORD wCancelTimeOut; // 0×04(L:2), Val = 78 00 -> 0×78

WORD wReserved1; // 0×06(L:2), Val = 0×0,

BYTE bFlowControl; // 0×08(L:1), Val = 0×0,
// F.C. = None, Val = 0×0,
// F.C. = H.W., Val = 0×10,
// F.C. = S.W., Val = 0×20,

BYTE bWaitForDialTone; // 0×09(L:1), Val = 0×1, Wait For Dial Tone Before Dialing
// Enable Wait For Dial Tone Before Dialing, Val = 0×1
// Disable Wait For Dial Tone Before Dialing, Val = 0×3

WORD wReserved2; // 0×0A(L:2), Val = 0×0,

UINT uBaudRate; // 0×0C(L:4), Val = 00 c2 01 00, 0×0001c200 = 115200

WORD wTerminal; // 0×10(L:2), Val = 00(L^) 00(H) -> 0×0, digital (d2)(d1)(d0),
// d2:Manual Dial,
// d1:Use terminal window before dialing,
// d0:Use terminal window after dialing,

BYTE bDataBits; // 0×12(L:1), Val = 0×8,

BYTE bStopBits; // 0×13(L:1), Val = 0×0,
// StopBits = 1, Val = 0×0
// StopBits = 1.5,Val = 0×1
// StopBits = 2, Val = 0×2

WORD wParity; // 0×14(L:2), Val = 00(^L) 00(H) -> 0×0
// Parity = None, Val = 0×0
// Parity = Odd, Val = 0×1
// Parity = Even, Val = 0×2
// Parity = Mark, Val = 0×3
// Parity = Space,Val = 0×4

WCHAR wszAtCmd[__AT_CMD_LEN__]; // 0×16(L:662),
// __AT_CMD_LEN__ ->331, Why "331" -> Reg DevCfg TotalLen : 684(0~0×2AB)
// 684(0~0×2AB) - 22(0×0~0×15->0×16) = 662(0×16~0×2AB->0×296)
// 662(0×16~0×2AB->0×296) / sizeof(WCHAR)
} sDevConfig;

class AFX_EXT_CLASS CRASRegSet
{
public:
CRASRegSet();
virtual ~CRASRegSet();
bool UpdateRASReg();

private:
sDevConfig m_DevConfig;
RASENTRY m_RASEntry;
bool InitVar();
bool GetRASEntries();
bool GetDeficeID(TCHAR *btname, int *iDeviceID);
};

#endif // !defined(AFX_CRASREGSET_H__96AA9E65_FEE2_441F_A7E2_57CEF87FA627__INCLUDED_)

CRASRegSet.cpp

// CRASRegSet.cpp: implementation of the CRASRegSet class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "CRASRegSet.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CRASRegSet::CRASRegSet()
{
memset(m_DevConfig.wszAtCmd,0,__AT_CMD_LEN__*sizeof(WCHAR));
}

CRASRegSet::~CRASRegSet()
{

}

bool CRASRegSet::UpdateRASReg()
{
DWORD dwRet = 0;
bool bRet = false;
DWORD dwBufferSize = 0;
DWORD dwSize = 0;

int iLineID = 0;
int iDeviceID = 0;

LONG lRet = -1;

// This is important! Find the buffer size (different from sizeof(RASENTRY)).
RasGetEntryProperties(NULL, L"", NULL, &dwBufferSize, NULL, NULL);
dwSize = sizeof(m_DevConfig);

bRet = InitVar();
//bRet = true;

if (bRet) {

dwRet = RasSetEntryProperties(
NULL,
__REG_NAME__,
&m_RASEntry,
dwBufferSize,
(LPBYTE)&m_DevConfig,
dwSize
);

switch (dwRet) {
case ERROR_BUFFER_INVALID:
MessageBox(NULL,_T("ERROR_BUFFER_INVALID"),NULL,MB_OK);
break;
case ERROR_CANNOT_OPEN_PHONEBOOK:
MessageBox(NULL,_T("ERROR_CANNOT_OPEN_PHONEBOOK"),NULL,MB_OK);
break;
default:
break;
}

bRet = (dwRet?false:true);

dwBufferSize = 0;

m_RASEntry.dwSize = sizeof(RASENTRY);

RasGetEntryProperties(NULL, __REG_NAME__, NULL, &dwBufferSize, NULL, NULL);

dwRet = RasGetEntryProperties(
NULL,
__REG_NAME__,
&m_RASEntry,
&dwBufferSize,
(LPBYTE)&m_DevConfig,
&dwSize
);
bRet = (dwRet?false:true);
}

if (bRet) {
bRet = GetRASEntries();
}

if (bRet) {
bRet = GetDeficeID(L"Bluetooth", &iDeviceID);
}

return bRet;

if (bRet) {

//lRet = lineSetDevConfig((DWORD)iDeviceID, &m_DevConfig, dwSize, L"Comm");
//lRet = lineSetDevConfig((DWORD)iDeviceID, &m_DevConfig, dwSize, L"tapi/line");
// lRet = lineSetDevConfig((DWORD)iDeviceID, &m_DevConfig, dwSize, L"comm/datamodem/portname/Bluetooth DUN on COM2\0");
//lRet = lineSetDevConfig((DWORD)iDeviceID, &m_DevConfig, dwSize, L"Comm/datamodem");

bRet = (lRet?false:true);
}

return bRet;
}

bool CRASRegSet::InitVar()
{
// Read Config …

// m_RASEntry Variable
DWORD dwFlagOptions = 0;
DWORD dwChannel = 0;
bool bSpecificDNS = false;
bool bSpecificIpAddr = false;
int iDeviceType = 0;

// Set Variable

m_RASEntry.dwSize = sizeof(RASENTRY);

memset((void*)&m_RASEntry, 0, m_RASEntry.dwSize);

m_RASEntry.dwfOptions = RASEO_ProhibitEAP;

dwFlagOptions = RASEO_RemoteDefaultGateway;

if (bSpecificDNS) {
dwFlagOptions |= RASEO_SpecificNameServers;
// example : 168.95.1.1 -> 0xA8, 0×5F, 0×1, 0×1
m_RASEntry.ipaddrDns.a = 0×1;
m_RASEntry.ipaddrDns.b = 0×1;
m_RASEntry.ipaddrDns.c = 0×5F;
m_RASEntry.ipaddrDns.d = 0xA8;

// example : 168.95.1.2 -> 0xA8, 0×5F, 0×1, 0×2
m_RASEntry.ipaddrDnsAlt.a = 0×2;
m_RASEntry.ipaddrDnsAlt.b = 0×1;
m_RASEntry.ipaddrDnsAlt.c = 0×5F;
m_RASEntry.ipaddrDnsAlt.d = 0xA8;

// example : 168.95.1.3 -> 0xA8, 0×5F, 0×1, 0×3
m_RASEntry.ipaddrWins.a = 0×3;
m_RASEntry.ipaddrWins.b = 0×1;
m_RASEntry.ipaddrWins.c = 0×5F;
m_RASEntry.ipaddrWins.d = 0xA8;

// example : 168.95.1.4 -> 0xA8, 0×5F, 0×1, 0×4
m_RASEntry.ipaddrWinsAlt.a = 0×4;
m_RASEntry.ipaddrWinsAlt.b = 0×1;
m_RASEntry.ipaddrWinsAlt.c = 0×5F;
m_RASEntry.ipaddrWinsAlt.d = 0xA8;
}

if (bSpecificIpAddr) {
dwFlagOptions |= RASEO_SpecificIpAddr;
// example : 203.22.95.42 -> 0xCB, 0×16, 0×5F, 0×2A
m_RASEntry.ipaddr.a = 0×2A;
m_RASEntry.ipaddr.b = 0×5F;
m_RASEntry.ipaddr.c = 0×16;
m_RASEntry.ipaddr.d = 0xCB;
}

m_RASEntry.dwfOptions = dwFlagOptions;

m_RASEntry.dwCountryCode = __COUNTRY_CODE__; //

_tcscpy(m_RASEntry.szAreaCode, __AREA_CODE__);

_tcscpy(m_RASEntry.szLocalPhoneNumber, __PHONE_NUMBER__);

_tcscpy(m_RASEntry.szDeviceName, __DEVICE_NAME__);

_tcscpy(m_RASEntry.szX25PadType, _T(""));
_tcscpy(m_RASEntry.szX25Address, _T(""));
_tcscpy(m_RASEntry.szX25Facilities, _T(""));
_tcscpy(m_RASEntry.szX25UserData, _T(""));

m_RASEntry.dwfNetProtocols = RASNP_Ip;
m_RASEntry.dwFramingProtocol = RASFP_Ppp;

switch (iDeviceType) {
case 0:
_tcscpy (m_RASEntry.szDeviceType, RASDT_Modem);
break;
case 1:
_tcscpy (m_RASEntry.szDeviceType, RASDT_Direct);
break;
case 2:
_tcscpy (m_RASEntry.szDeviceType, RASDT_Modem);
break;
default:
_tcscpy (m_RASEntry.szDeviceType, RASDT_Vpn);
break;
}

// Number specifying the number of channels supported by the device,
// where 1 is mono, 2 is stereo, and so on.
m_RASEntry.dwChannels = dwChannel;
m_RASEntry.dwReserved1 = 0;
m_RASEntry.dwReserved2 = 0;
m_RASEntry.dwCustomAuthKey = 0;

// Init DevConfig
/*
WORD wHeader; // 0×00(L:2), Val = 0×30, Unknown

WORD wWaitForCreditCardSec; // 0×02(L:2), Val = 0×0, Wait For Credit Card Tone Seconds,

WORD wCancelTimeOut; // 0×04(L:2), Val = 78 00 -> 0×78

WORD wReserved1; // 0×06(L:2), Val = 0×0,

BYTE bFlowControl; // 0×08(L:1), Val = 0×0,
// F.C. = None, Val = 0×0,
// F.C. = H.W., Val = 0×10,
// F.C. = S.W., Val = 0×20,

BYTE bWaitForDialTone; // 0×09(L:1), Val = 0×1, Wait For Dial Tone Before Dialing
// Enable Wait For Dial Tone Before Dialing, Val = 0×1
// Disable Wait For Dial Tone Before Dialing, Val = 0×3

WORD wReserved2; // 0×0A(L:2), Val = 0×0,

UINT uBaudRate; // 0×0C(L:4), Val = 00 c2 01 00, 0×0001c200 = 115200

WORD wTerminal; // 0×10(L:2), Val = 00(L^) 00(H) -> 0×0, digital (d2)(d1)(d0),
// d2:Manual Dial,
// d1:Use terminal window before dialing,
// d0:Use terminal window after dialing,

BYTE bDataBits; // 0×12(L:1), Val = 0×8,

BYTE bStopBits; // 0×13(L:1), Val = 0×0,
// StopBits = 1, Val = 0×0
// StopBits = 1.5,Val = 0×1
// StopBits = 2, Val = 0×2

WORD wParity; // 0×14(L:2), Val = 00(^L) 00(H) -> 0×0
// Parity = None, Val = 0×0
// Parity = Odd, Val = 0×1
// Parity = Even, Val = 0×2
// Parity = Mark, Val = 0×3
// Parity = Space,Val = 0×4

WCHAR wszAtCmd[331]; // 0×16(L:662),
// Why "331" -> Reg DevCfg TotalLen : 684(0~0×2AB)
// 684(0~0×2AB) - 22(0×0~0×15->0×16) = 662(0×16~0×2AB->0×296)
// 662(0×16~0×2AB->0×296) / sizeof(WCHAR)
*/
m_DevConfig.wHeader = 0×30; // 0×00(L:2)
m_DevConfig.wWaitForCreditCardSec = 0×0;// 0×02(L:2),
m_DevConfig.wCancelTimeOut = 0×78; // 0×04(L:2),
m_DevConfig.wReserved1 = 0×0; // 0×06(L:2),
m_DevConfig.bFlowControl = 0×0; // 0×08(L:1),
m_DevConfig.bWaitForDialTone = 0×1; // 0×09(L:1),
m_DevConfig.wReserved2 = 0×0; // 0×0A(L:2),
m_DevConfig.uBaudRate = 0×0001c200; // 0×0C(L:4),
m_DevConfig.wTerminal = 0×0; // 0×10(L:2),
m_DevConfig.bDataBits = 0×8; // 0×12(L:1),
m_DevConfig.bStopBits = 0×0; // 0×13(L:1),
m_DevConfig.wParity = 0×0; // 0×14(L:2),
_tcscpy(m_DevConfig.wszAtCmd, _T("+cops=1,2,\"46692\";+cgdcont=1,\"ip\",\"internet\""));
return true;
}

bool CRASRegSet::GetRASEntries()
{
DWORD dwRet = -1;
DWORD cb;
DWORD cEntries;
bool bRet = false;
LPRASENTRYNAME lpRASEntryName;
int i = 0;

lpRASEntryName = (LPRASENTRYNAME)LocalAlloc(LPTR, sizeof(RASENTRYNAME));
lpRASEntryName->dwSize = sizeof(RASENTRYNAME);
if ((dwRet = RasEnumEntries(NULL, NULL, lpRASEntryName, &cb, &cEntries))
== ERROR_BUFFER_TOO_SMALL)
{
lpRASEntryName = (LPRASENTRYNAME)LocalAlloc(LPTR, cb);
lpRASEntryName->dwSize = sizeof(RASENTRYNAME);
}

// Calling RasEnumEntries to enumerate the phonebook entries
dwRet = RasEnumEntries(NULL, NULL, lpRASEntryName, &cb, &cEntries);

if (dwRet != ERROR_SUCCESS)
{
TRACE(_T("RasEnumEntries failed: Error %d\n"), dwRet);
}
else
{
TRACE(_T("Phone book entries in the default phonebook:\n\n"));
for(i=0;i <>szEntryName);
if(_tcsncmp((lpRASEntryName + i)->szEntryName, __DEVICE_NAME__, _tcslen(__DEVICE_NAME__)) == 0)
{
lpRASEntryName = (LPRASENTRYNAME)LocalAlloc(LPTR, cb);
lpRASEntryName->dwSize = sizeof(RASENTRYNAME);
return TRUE;
}
}
}

bRet = (dwRet?false:true);

return bRet;
}

bool CRASRegSet::GetDeficeID(TCHAR *btname, int *iDeviceID)
{
LPRASDEVINFO lpRasDevInfo = NULL;
DWORD dwBufSize = 0;
DWORD dwNumDevices = 0;
DWORD dwDeviceID = 0;
DWORD dwErr;

// find the buffer size needed
dwErr = RasEnumDevices(NULL, &dwBufSize, &dwNumDevices);
if (!dwBufSize) return false;

lpRasDevInfo = (LPRASDEVINFO)LocalAlloc(LPTR, dwBufSize);

if (!lpRasDevInfo) return false;

lpRasDevInfo->dwSize = sizeof(RASDEVINFO);

if (RasEnumDevices(lpRasDevInfo, &dwBufSize, &dwNumDevices))
{
LocalFree(lpRasDevInfo);
return false;
}

dwDeviceID = 0;
//
// Find the correct device ID for this connection type
//
while (dwDeviceID <>szDeviceType, RASDT_Modem, wcslen(RASDT_Modem)) == 0)
{
if(wcsncmp((lpRasDevInfo + dwDeviceID)->szDeviceName, btname, wcslen(btname)) == 0)
{
LocalFree(lpRasDevInfo);
*iDeviceID = dwDeviceID;
return true;
}
}
dwDeviceID++;
}
LocalFree(lpRasDevInfo);
return false;
}


[PS1]

Modem Reg Sample (這段 Reg 一定要加在 Platform.reg 中, 因 Modem Reg 是 Boot 時 Load 的, 即便用 Hive-based 的 reg 也要 Reboot 會才會 Work):

[HKEY_LOCAL_MACHINE\ExtModems\bluetooth_dun]
"port"="COM2:"
"DeviceType"=dword:1
"Order"=dword:0
"FriendlyName"="Bluetooth DUN on COM2"


"bluetooth_dun" 這個 key 值可自訂, 如 GPSxxx... 等.

"FriendlyName"="Bluetooth DUN on COM2" 的 "Bluetooth DUN on COM2" 就要特別注意, 在 RasSetEntryProperties API 的第5個 Param : LPBYTE lpb 的 szDeviceName要和這個值("Bluetooth DUN on COM2") 一致, 若不一致, 會造成 RasSetEntryProperties 雖 Return Zero(Successful), 但在實際查看新增的撥號網路設定參數值均為 Default (如 Baud Rate : 19200)

若要使用 WinCE Default 的 Diaup AP 並配合自動撥號, 所要添加的 Reg 如下

[HKEY_LOCAL_MACHINE\ExtModems\bluetooth_dun]
"port"="COM2:"
"DeviceType"=dword:1
"Order"=dword:0
"FriendlyName"="Bluetooth DUN on COM2"
[HKEY_LOCAL_MACHINE\ExtModems\bluetooth_dun\Init]

[HKEY_LOCAL_MACHINE\ExtModems\bluetooth_dun\Settings]

[HKEY_LOCAL_MACHINE\Comm\Autoras]
"Dialer"="Rnaapp.exe"
"NoPromptOpt"="-p"
"RasEntryOpt"="-e"
"RasEntry"="BT Connection"

[HKEY_LOCAL_MACHINE\Comm\AutoDial]
"Enabled"="1"

接著添加 exe And dll :

1. 從 P.B. 中添加 AutoDial : AutoDial(Catalog/Core OS/Communication Services and Networking/Networking - Wide Area Network [WAN]/Dial Up Networking [RAS/PPP]/AutoDial), 並將 Rnaapp.exe 放入 Files 中再 Rebuild OS.

2. 在 platform.bib 中添加

autoras.dll $(_FLATRELEASEDIR)\autoras.dll NK U

rnaapp.exe $(_FLATRELEASEDIR)\rnaapp.exe NK U
rnaapp.lnk $(_FLATRELEASEDIR)\rnaapp.lnk NK U

rapisrv.exe $(_FLATRELEASEDIR)\rapisrv.exe NK U
rapisrv.lnk $(_FLATRELEASEDIR)\rapisrv.lnk NK U

autoras.exe $(_FLATRELEASEDIR)\autoras.exe NK U
autoras.lnk $(_FLATRELEASEDIR)\autoras.lnk NK U

3. Check 在 .bib 中 List 的 File 在 Files Folder 中是否都存在.

4. 建立 .lnk 檔

Example : rnaapp.lnk 檔內容(最前面的數字代表 String Len, "#" 不計):

19#\windows\rnaapp.exe


Example autoras.lnk 檔內容(最前面的數字代表 String Len, "#" 不計):

20#\windows\autoras.exe


Example rapisrv.lnk 檔內容(最前面的數字代表 String Len, "#" 不計):

20#\windows\rapisrv.exe

都 OK 後再 Rebuil OS 即可

d

Friday, October 03, 2008

The Data Structure For RasSetEntryProperties - lineGetDevConfig (WinCE 5.0)

Following Data Structure Is For RasSetEntryProperties - Parameter " LPTYPE lpb"

typedef struct {
WORD wHeader; // 0x00(L:2), Val = 0x30, ???
WORD wWaitForCreditCardSec; // 0x02(L:2), Val = 0x0, Wait For Credit Card Tone Seconds,
WORD wCancelTimeOut; // 0x04(L:2), Val = 78 00 -> 0x78
WORD wReserved1; // 0x06(L:2), Val = 0x0,
BYTE bFlowControl; // 0x08(L:1), Val = 0x0,
// F.C. = None, Val = 0x0,
// F.C. = H.W., Val = 0x10,
// F.C. = S.W., Val = 0x20,
BYTE bWaitForDialTone; // 0x09(L:1), Val = 0x1, Wait For Dial Tone Before Dialing
// Enable Wait For Dial Tone Before Dialing, Val = 0x1
// Disable Wait For Dial Tone Before Dialing, Val = 0x3
WORD wReserved2; // 0x0A(L:2), Val = 0x0,
UINT uBaudRate; // 0x0C(L:4), Val = 00 c2 01 00, 0x0001c200 = 115200
WORD wTerminal; // 0x10(L:2), Val = 00(L^) 00(H) -> 0x0, digital (d2)(d1)(d0),
// d2:Manual Dial,
// d1:Use terminal window before dialing,
// d0:Use terminal window after dialing,
BYTE bDataBits; // 0x12(L:1), Val = 0x8,
BYTE bStopBits; // 0x13(L:1), Val = 0x0,
// StopBits = 1, Val = 0x0
// StopBits = 1.5,Val = 0x1
// StopBits = 2, Val = 0x2
WORD wParity; // 0x14(L:2), Val = 00(^L) 00(H) -> 0x0
// Parity = None, Val = 0x0
// Parity = Odd, Val = 0x1
// Parity = Even, Val = 0x2
// Parity = Mark, Val = 0x3
// Parity = Space,Val = 0x4
WCHAR wszAtCmd[331]; // 0x16(L:662),
// Why "331" -> Reg DevCfg TotalLen : 684(0~0x2AB)
// 684(0~0x2AB) - 22(0x0~0x15->0x16) = 662(0x16~0x2AB->0x296)
// 662(0x16~0x2AB->0x296) / sizeof(WCHAR)
} sDevConfig;

我負責

 ... + ...........  政策 我負責. 負責推卸責任. (阿不然你以為哩...) 聽說 記錯了 請見諒 深感抱歉.... 抗(國外)疫(苗)中...