mobilemodule.cpp
来自「wince中 我自己的流驱动实现 注册表和bib文件 修改在QZSerialS」· C++ 代码 · 共 1,978 行 · 第 1/4 页
CPP
1,978 行
returntimes++ ;
tmp_Right = tmp.Right(tmp.GetLength() - Find_Int - 4) ;
Find_Int = tmp_Right.Find(_T("000A")) ;
while(Find_Int != -1)
{
tmp_Left += tmp_Right.Left(Find_Int) + "000D000A" ;
returntimes++ ;
tmp_Right = tmp_Right.Right(tmp_Right.GetLength() - Find_Int - 4) ;
Find_Int = tmp_Right.Find(_T("000A")) ;
}
CString str_Number = tmp_Left.Left(60) ;
str_Number = str_Number.Right(2) ;
int char_num = HexToInteger(str_Number) ;
char_num += 2*returntimes ;
str_Number = IntegerToHex(char_num) ;
CString temp_left = tmp_Left.Left(58) ;
CString temp_right = tmp_Left.Right(tmp_Left.GetLength()-60) ;
tmp_Left = temp_left + str_Number + temp_right ;
tmp = tmp_Left + tmp_Right ;
}
LPWSTR ptemp = tmp.GetBuffer(tmp.GetLength()) ;
int len = WideCharToMultiByte(CP_ACP,NULL,ptemp,wcslen(ptemp),char_tmp,wcslen(ptemp),NULL,NULL) ;
char_tmp[len] = '\0' ;
gsmDecodePdu(char_tmp,csca,SendNum,SendTime,SmsContent) ;
}
int CMobileModule::HexToInteger(CString str)
{
int n = 0 , result = 0 ;
LPTSTR pHex = str.GetBuffer(str.GetLength()) ;
int len = wcslen(pHex) ;
char *HexValue = new char[len+1] ;
wcstombs(HexValue,pHex,len) ;
HexValue[len+1] = '\0' ;
for(int i = 0 ; HexValue[i] != '\0' ;i++)
{
if(HexValue[i] >= '0' && HexValue[i] <= '9')
{
n = HexValue[i] - '0' ;
}
if(HexValue[i] >= 'a' && HexValue[i] <= 'f')
{
n = HexValue[i] - 'a' + 10 ;
}
if(HexValue[i] >= 'A' && HexValue[i] <= 'F')
{
n = HexValue[i] - 'A' + 10 ;
}
n <<= ((len - i - 1)<<2) ;
result |= n ;
}
delete [] HexValue ;
return result ;
}
CString CMobileModule::IntegerToHex(int Ivalue)
{
CString ReturnVal("") ;
int value_mode = 0, value_vid = 0 ,times = 0 ;
char Hex_value[5] ;
memset(Hex_value ,0,5) ;
const char tab[]="0123456789ABCDEF"; // 0x0-0xf的字符查找表
value_vid = Ivalue ;
do{
value_mode = value_vid % 16 ;//取余数
value_vid = value_vid / 16 ;//取结果
Hex_value[times++] = tab[value_mode] ;
}while(value_vid > 0) ;
for(int first = 0 ; first < times/2 ; first++)
{
char ch ;
ch = Hex_value[first] ;
Hex_value[first] = Hex_value[--times] ;
Hex_value[times] = ch ;
}
ReturnVal = Hex_value ;
return ReturnVal ;
}
void CMobileModule::CSCSCommand(CString chse)
{//Select TE Character Set
//“GSM” GSM default alphabet.
//"HEX" character strings consist only of hexadecimal numbers from 00 to FF;
//"IRA" international reference alphabet
//"PCCP" PC character set Code
//"PCDN" PC Danish/Norwegian character set
//“UCS2” UCS2 alphabet
//"8859-1" ISO 8859 Latin 1 character set
CString ATCommand("AT+CSCS=") ;
ATCommand += "\"" ;
ATCommand += chse ;
ATCommand += "\"\r" ;
OpeSerial.WriteSerial(ATCommand);
}
void CMobileModule::CHLDCommand(int Index)
{//Call hold and multiparty
//0 Terminate all held calls or UDUB (User Determined User Busy) for a waiting call
//1 Terminate all active calls (if any) and accept the other call (waiting call or held call)
//1X Terminate the specific call number X (X= 1-7)( active, waiting or held)
//2 Place all active calls on hold (if any) and accept the other call (waiting call or held call) as the active call
//2X Place all active calls except call X (X= 1-7) on hold
//3 Add the held call to the active calls
CString ATCommand("AT+CHLD=") ;
char tmp[2];
memset(tmp,0,2);
sprintf(tmp, "%d", Index);
ATCommand += tmp ;
ATCommand += "\r" ;
OpeSerial.WriteSerial(ATCommand);
}
void CMobileModule::CLCCCommand()
{//List current calls of ME
CString ATCommand("AT+CLCC\r") ;
OpeSerial.WriteSerial(ATCommand);
}
void CMobileModule::CLCKCommand(CString fac, int mode, CString password, int class_mode)
{//Facility lock
//<fac> "PS" PH-SIM (lock Phone to SIM card) (ME asks password when other than current SIM card inserted; ME may remember certain amount of previously used cards thus not requiring password when they are inserted)
//"SC" SIM (lock SIM card) (SIM asks password in ME power-up and when this lock command issued)
//"AO" BAOC (Barr All Outgoing Calls) (refer GSM02.88[6] clause 1) "OI" BOIC (Barr Outgoing International Calls) (refer GSM02.88[6] clause 1)
//"OX" BOIC-exHC (Barr Outgoing International Calls except to Home Country) (refer GSM02.88[6] clause 1)
//"AI" BAIC (Barr All Incoming Calls) (refer GSM02.88[6] clause 2)
//"IR" BIC-Roam (Barr Incoming Calls when Roaming outside the home country) (refer GSM02.88 [6] clause 2)
//"AB" All Barring services (refer GSM02.30[19]) (applicable only for <mode>=0)
//"AG" All out Going barring services (refer GSM02.30[19]) (applicable only for <mode>=0)
//"AC" All in Coming barring services (refer GSM02.30[19]) (applicable only for <mode>=0)
//"PN" Network Personalization (refer GSM 02.22[33])
//"PU" network subset Personalization (refer GSM 02.22[33])
//"PP" service Provider Personalization (refer GSM 02.22[33])
//"PC" Corporate Personalization (refer GSM 02.22[33])
//<mode> 0 unlock 1 lock 2 query status
//<passwd> password
//<class> 1 voice 2 data 4 fax 7 all classes (default)
CString ATCommand("AT+CLCK=") ;
ATCommand += fac ;
char tmp[2] ;
memset(tmp,2,0);
sprintf(tmp,"%d",mode) ;
ATCommand += tmp ;
if(password.Compare(L"") != 0)
{
ATCommand += "," ;
ATCommand += password ;
char temp[2] ;
memset(temp,0,2) ;
ATCommand += temp ;
}
ATCommand += "\r" ;
OpeSerial.WriteSerial(ATCommand);
}
void CMobileModule::CLIPCommand(int Value)
{//Calling line identification presentation
//0 suppress unsolicited result codes
//1 display unsolicited result codes
CString ATCommand("AT+CLIP=") ;
char tmp[2] ;
sprintf(tmp,"%d",Value) ;
ATCommand += tmp ;
ATCommand += "\r" ;
OpeSerial.WriteSerial(ATCommand);
}
void CMobileModule::COLPCommand(int value)
{//Connected Line Identification Presentation
/*atd15818718810; //at+colp=1
+COLP: "15818718810",129
OK
*/
CString ATCommand("AT+COLP=") ;
char tmp[2] ;
memset(tmp,0,2) ;
sprintf(tmp,"%d",value) ;
ATCommand += tmp ;
ATCommand += "\r" ;
OpeSerial.WriteSerial(ATCommand);
}
void CMobileModule::COPSCommand()
{//Operator selection
CString ATCommand("AT+COPS?\r") ;
OpeSerial.WriteSerial(ATCommand);
}
void CMobileModule::CPASCommand()
{//Mobile equipment activity status
//0 ready 2 unknown (ME is not guaranteed to respond to instructions)
//3 incoming call (ringing) 4 call in progress or call hold
CString ATCommand("AT+CPAS\r") ;
OpeSerial.WriteSerial(ATCommand);
}
void CMobileModule::CACMCommand(CString acmmax ,CString password)
{//Accumulated call meter maximum(ACM max) reset or query
//<acmmax> string type; three bytes of the max. ACM value in hexa-decimal
//format (e.g. "00001E" indicates decimal value 30) 000000 disable
//ACMmax feature 000001-FFFFFF
//<passwd> string type SIM PIN2
CString ATCommand("AT+CACM=") ;
ATCommand += acmmax ;
ATCommand += "," ;
ATCommand += password ;
ATCommand += "\r" ;
OpeSerial.WriteSerial(ATCommand);
}
void CMobileModule::CPINGetCommand()
{//Get Pin mode
CString ATCommand("AT+CPIN?\r") ;
OpeSerial.WriteSerial(ATCommand);
}
void CMobileModule::CPINSetCommand(CString pin, CString newpin)
{//If the PIN required is SIM PUK or SIM PUK2, the second pin is required.
//This second pin, <new pin>, is used to replace the old pin in the SIM.
CString ATCommand("AT+CPIN=") ;
ATCommand += pin ;
if(newpin.Compare(L"") != 0)
{
ATCommand += "," ;
ATCommand += newpin ;
}
ATCommand += "\r" ;
OpeSerial.WriteSerial(ATCommand);
}
void CMobileModule::CPWDCommand(CString fac, CString newpw)
{//TA sets a new password for the facility lock function.
CString ATCommand("AT+CPWD=") ;
ATCommand += fac ;
ATCommand += "," ;
ATCommand += newpw ;
ATCommand += "\r" ;
OpeSerial.WriteSerial(ATCommand);
}
void CMobileModule::CPWDCommand(CString fac, CString oldpw, CString newpw)
{//TA sets a new password for the facility lock function.
CString ATCommand("AT+CPWD=") ;
ATCommand += fac ;
ATCommand += "," ;
ATCommand += oldpw ;
ATCommand += "," ;
ATCommand += newpw ;
ATCommand += "\r" ;
OpeSerial.WriteSerial(ATCommand);
}
void CMobileModule::CRCCommand(int mode)
{//Set Cellular Result Codes for incoming call indication
/*
+CRING: VOICE
+CLIP: "15818718810",129,"",,"",0
*/
CString ATCommand("AT+CRC=") ;
char tmp[2] ;
memset(tmp,0,2) ;
sprintf(tmp,"%d",mode) ;
ATCommand += tmp ;
ATCommand += "\r" ;
OpeSerial.WriteSerial(ATCommand);
}
void CMobileModule::CSQCommand()
{//Signal Quality Report l
CString ATCommand("AT+CSQ\r") ;
OpeSerial.WriteSerial(ATCommand);
}
void CMobileModule::CFUNCommand()
{//Set phone functionality.
CString ATCommand("AT+CFUN\r") ;
OpeSerial.WriteSerial(ATCommand);
}
void CMobileModule::CFUNCommand(int value)
{//Set phone functionality.
CString ATCommand("AT+CFUN=") ;
char tmp[2] ;
memset(tmp,0,2) ;
sprintf(tmp,"%d",value) ;
ATCommand += tmp ;
ATCommand += "\r" ;
OpeSerial.WriteSerial(ATCommand);
}
void CMobileModule::CCLKCommand()
{//Get module time
CString ATCommand("AT+CCLK?\r") ;
OpeSerial.WriteSerial(ATCommand);
}
void CMobileModule::CCLKCommand(CString time_str)
{//Set module time
CString ATCommand("AT+CCLK=\"") ;
ATCommand += time_str ;
ATCommand += "\"\r" ;
OpeSerial.WriteSerial(ATCommand);
}
void CMobileModule::CALMCommand(int Value)
{//Alert Sound Mode
CString ATCommand("AT+CALM=") ;
char tmp[2] ;
memset(tmp,0,2) ;
sprintf(tmp,"%d",Value) ;
ATCommand += tmp ;
ATCommand += "\r" ;
OpeSerial.WriteSerial(ATCommand);
}
void CMobileModule::CRSLCommand(int level)
{//Ringer Sound Level 0<level<100
CString ATCommand("AT+CRSL=") ;
char tmp[2] ;
memset(tmp,0,2) ;
sprintf(tmp,"%d",level) ;
ATCommand += tmp ;
ATCommand += "\r" ;
OpeSerial.WriteSerial(ATCommand);
}
void CMobileModule::CLVLCommand(int Value)
{//Loud speaker volume level
CString ATCommand("AT+CLVL=") ;
char tmp[2] ;
memset(tmp,0,2) ;
sprintf(tmp,"%d",Value) ;
ATCommand += tmp ;
ATCommand += "\r" ;
OpeSerial.WriteSerial(ATCommand);
}
void CMobileModule::MUTCommand(int Value)
{//Mut control
CString ATCommand("AT+CMUT=") ;
char tmp[2] ;
memset(tmp,0,2) ;
sprintf(tmp,"%d",Value) ;
ATCommand += tmp ;
ATCommand += "\r" ;
OpeSerial.WriteSerial(ATCommand);
}
void CMobileModule::CCWECommand(int Value)
{//Call Meter Maximum Event
//0 Disable call meter warning event
//1 Enable call meter warning event
//note:Shortly before the ACM (Accumulated Call Meter) maximumvalue is reached,
//an unsolicited result code +CCWV will be sent, if enabled by this command
CString ATCommand("AT+CCWE=") ;
char tmp[2] ;
memset(tmp,0,2) ;
sprintf(tmp,"%d",Value) ;
ATCommand += tmp ;
ATCommand += "\r" ;
OpeSerial.WriteSerial(ATCommand);
}
void CMobileModule::CBCCommand()
{//Battery Charge
//Support for this command will be hardware dependant and
//only be used when battery is set to vibrator
CString ATCommand("AT+CBC\r") ;
OpeSerial.WriteSerial(ATCommand);
}
void CMobileModule::CSSNCommand(int Value1,int Value2)
{//SUPPLEMENTARY SERVICES NOTIFICATION
//a numeric parameter which indicates whether to show the +CSSI result code
//presentation status after a mobile originated call setup
CString ATCommand("AT+CSSN=") ;
char tmp[2] ;
memset(tmp,0,2) ;
sprintf(tmp,"%d",Value1) ;
ATCommand += tmp ;
ATCommand += "," ;
memset(tmp,0,2) ;
sprintf(tmp,"%d",Value2) ;
ATCommand += tmp ;
ATCommand += "\r" ;
OpeSerial.WriteSerial(ATCommand);
}
void CMobileModule::CPOWDCommand()
{//Power Off
CString ATCommand("AT+CPOWD=1\r") ;
OpeSerial.WriteSerial(ATCommand);
}
void CMobileModule::CMICCommand(int channel, int gainlevel)
{//Change the microphone gain level
//<channel> 0 – Main Microphone 1 – Aux Microphone
//< gainlevel > int: 0 – 15 0 0dB 1 +1.5dB 2 +3.0 dB(default value)
//3 +4.5 dB 4 +6.0 dB 5 +7.5 dB 6 +9.0 dB 7 +10.5 dB 8 +12.0 dB 9 +13.5 dB
//10 +15.0 dB 11 +16.5 dB 12 +18.0 dB 13 +19.5 dB 14 +21.0 dB 15 +22.5 dB
CString ATCommand("AT+CMIC=") ;
char tmp[2] ;
memset(tmp,0,2) ;
sprintf(tmp,"%d",channel) ;
ATCommand += tmp ;
ATCommand += "," ;
memset(tmp,0,2) ;
sprintf(tmp,"%d",gainlevel) ;
ATCommand += tmp ;
ATCommand += "\r" ;
OpeSerial.WriteSerial(ATCommand);
}
void CMobileModule::AlarmCommand(int state, CString time, int repeat, int power)
{//Set\Clear Alarm Clock
CString ATCommand("AT+CALARM=") ;
char tmp[2] ;
memset(tmp,0,2) ;
sprintf(tmp,"%d",state) ;
ATCommand += tmp ;
ATCommand += "," ;
ATCommand += time ;
ATCommand += "," ;
memset(tmp,0,2) ;
sprintf(tmp,"%d",repeat) ;
ATCommand += tmp ;
ATCommand += "," ;
memset(tmp,0,2) ;
sprintf(tmp,0,power) ;
ATCommand += tmp ;
ATCommand += "\r" ;
OpeSerial.WriteSerial(ATCommand);
}
void CMobileModule::CEXTHSCommand(int mode)
{//External headset jack control
//a numeric parameter which indicates whether an unsolicited event code
//(indicating whether the headset has been attached/detached) should be
//sent to the terminal.
CString ATCommand("AT+CEXTHS=") ;
char tmp[2] ;
memset(tmp,0,2) ;
sprintf(tmp,"%d",mode) ;
ATCommand += tmp ;
ATCommand += "\r" ;
OpeSerial.WriteSerial(ATCommand);
}
void CMobileModule::CEXTBUTCommand(int mode)
{//Headset button status reporting
//a numeric parameter which indicates whether an unsolicited event code
//(indicating whether the headset button has been pressed) should be
//sent to the terminal.
CString ATCommand("AT+CEXTBUT=") ;
char tmp[2] ;
memset(tmp,0,2) ;
sprintf(tmp,"%d",mode) ;
ATCommand += tmp ;
ATCommand += "\r" ;
OpeSerial.WriteSerial(ATCommand);
}
void CMobileModule::CSMINSCommand(int value)
{//SIM inserted status reporting
CString ATCommand("AT+CSMINS=") ;
char tmp[2] ;
memset(tmp,0,2) ;
sprintf(tmp,"%d",value) ;
ATCommand += tmp ;
ATCommand += "\r" ;
OpeSerial.WriteSerial(ATCommand);
}
void CMobileModule::CHFACommand(int Value)
{//Swap the audio channels
//0 – Normal audio channel(default) 1 – Aux audio channel
CString ATCommand("AT+CHFA=") ;
char tmp[2] ;
memset(tmp,0,2) ;
sprintf(tmp,"%d",Value) ;
ATCommand += tmp ;
ATCommand += "\r" ;
OpeSerial.WriteSerial(ATCommand);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?