The following describes how to send a Chinese text message using the AT command below wince.
1. Set csca
Int _ stdcall setcsca () {int isok =-1; DWORD dwwritensize = 0; DWORD dwreadsize; If (m_serial = invalid_handle_value) {retailmsg (1, (Text ("m_serial = invalid_handle_value \ r"); Return isok;} cstring m_quest ("at + csca = \" + 8613010200500 \ "\ r "); // cstring m_quest ("at + CSQ \ r"); Int J = m_quest.getlength (); unsigned char * rel = new unsigned char [50]; memset (Rel, 0, sizeof (rel); unsigned char * Buf = new unsi Gned char [J]; for (INT I = 0; I <j; I ++) BUF [I] = (unsigned char) m_quest.getat (I ); /* convert to single-byte characters */writefile (m_serial, Buf, J, & dwwritensize, null); sleep (200); If (readfile (m_serial, Rel, 50, & dwreadsize, null) {cstring TMP; // TMP. format (_ T ("% s"), Rel); DWORD dwnum = multibytetowidechar (cp_acp, 0, (lpcstr), Rel,-1, null, 0); wchar_t * pwtext; pwtext = new wchar_t [dwnum]; multibytetowidechar (cp_acp, 0, (lpcstr) Re L,-1, pwtext, dwnum); // start to convert TMP = pwtext; If (TMP. Find (L "OK ")! =-1) isok = 0; // retailmsg (1, (text ("isok % d"), isok); Delete [] pwtext;} Delete [] Buf; delete [] rel; return isok ;}
2. Set cmgf
Int _ stdcall setcmgf () {// return 0; int isok =-1; DWORD dwwritensize = 0; DWORD dwreadsize; If (m_serial = invalid_handle_value) {retailmsg (1, (Text ("m_serial = invalid_handle_value \ r"); Return isok;} cstring m_quest = l "at + cmgf = 0 \ r "; // cstring m_quest ("at + CSQ \ r"); Int J = m_quest.getlength (); unsigned char * rel = new unsigned char [50]; memset (Rel, 0, sizeof (rel); unsigned char * Buf = new unsigned char [J]; for (int I = 0; I <j; I ++) BUF [I] = (unsigned char) m_quest.getat (I);/* convert to single-byte characters */writefile (m_serial, buf, J, & dwwritensize, null); sleep (200); If (readfile (m_serial, Rel, 50, & dwreadsize, null) {cstring TMP; DWORD dwnum = multibytetowidechar (cp_acp, 0, (lpcstr) REL,-1, null, 0); wchar_t * pwtext; pwtext = new wchar_t [dwnum]; multibytetowidechar (cp_acp, 0, (lpcstr) REL,-1, pwtext, dwnum); // start to convert TMP = pwtext; If (TMP. f Ind (L "OK ")! =-1) isok = 0; Delete [] pwtext;} Delete [] Buf; Delete [] rel; return isok ;}
3. send text messages
Int _ stdcall sendmessage (const char * strnumber, const char * strcontent) {sm_param smparam; Int J; j = strlen (strnumber); If (j <11) {return 2; // incorrect mobile phone number} cstring strunicode; wchar [1024]; cstring strsmsc = l "8613010200500"; int nconut = strlen (strcontent); // retailmsg (1, (Text ("content: % d"), strlen (strcontent); If (nconut <= 1) {return 3;} else if (nconut> 140) {return 4;} Char phonenum [100]; memset (phonenum, 0, sizeof (Phonenum); If (strnumber [0]! = '8' & strnumber [0]! = '6') {phonenum [0] = '8'; phonenum [1] = '6'; strcpy (phonenum + 2, strnumber);} else {strcpy (phonenum, strnumber) ;}for (INT I = 0; I <strsmsc. getlength (); I ++) {smparam. SCA [I] = strsmsc. getat (I);} strcpy (smparam. TPA, phonenum); strcpy (smparam. tp_ud, strcontent); // retailmsg (1, (text ("\ r \ ntp_ud lenght: % d"), strlen (smparam. tp_ud); smparam. tp_pid = 0; smparam. tp_dcs = 8; // use ucs2 encoding if (setsms (& smparam) = 0) {return 0;} return-1 ;}
4. Set up a text message center
Int _ stdcall sendmessage1 (const char * strsmsc, const char * strnumber, const char * strcontent)
{Sm_param smparam; Int J, M; j = strlen (strnumber); M = strlen (strsmsc); If (j <11 | M <11) {return 2; // incorrect mobile phone number} cstring strunicode; wchar [1024]; // cstring strsmsc = l "8613010200500"; int nconut = strlen (strcontent); // retailmsg (1, (Text ("content: % d"), strlen (strcontent); If (nconut <= 1) {return 3;} else if (nconut> 140) {return 4 ;}char phonenum [100]; memset (phonenum, 0, sizeof (phonenum); If (strnumber [0]! = '8' & strnumber [0]! = '6') {phonenum [0] = '8'; phonenum [1] = '6'; strcpy (phonenum + 2, strnumber);} else {strcpy (phonenum, strnumber);} Char SMCs [100]; memset (SMCs, 0, sizeof (SMCs); If (strsmsc [0]! = '8' & strsmsc [0]! = '6') {SMCs [0] = '8'; SMCs [1] = '6'; strcpy (SMCs + 2, strsmsc);} else {strcpy (SMCs, strsmsc);} strcpy (smparam. SCA, SMCs); strcpy (smparam. TPA, phonenum); strcpy (smparam. tp_ud, strcontent); // retailmsg (1, (text ("\ r \ nsmparam. SCA "); smparam. tp_pid = 0; smparam. tp_dcs = 8; // use ucs2 encoding if (setsms (& smparam) = 0) {return 0;} return-1 ;}
5. Other functions and struct used
Int _ stdcall setsms (sm_param * psrc) {int npdulength; // The length of the PDU string unsigned char nsmsclength; // The length of the SMSC string int nlength; // The Data Length received by the serial port: Char cmd [16]; // command string: Char PDU [512]; // PDU string: Char ans [128]; // response string int isok =-1; DWORD dwwritensize = 0; DWORD dwreadsize; // retailmsg (1, (text ("setmessage \ r "))); if (m_serial = invalid_handle_value) {// retailmsg (1, (text ("m_serial = invalid_handle_value \ r"); Return isok;} npdulength = gsmenc Odepdu (psrc, PDU); // encode the PDU string strcat (PDU, "\ x001a") based on the PDU parameters; // end the gsmstring2bytes (PDU, & nsmsclength, 2); // get the length of SMSC information in the PDU string nsmsclength ++; // Add the length of the byte itself // The length in the command, excluding the length of SMSC information, sprintf (CMD, "At + cmgs = % d \ r", npdulength/2-nsmsclength) in data bytes; // generate command // For (int I; I <strlen (CMD); I ++) // retailmsg (1, (text ("% C"), CMD [I]); // retailmsg (1, (Text ("\ r \ n"); // For (Int J; j <strlen (PDU); j ++) // retailmsg (1, (Text ("% C"), PDU [J]); writefile (m_serial, CMD, strlen (CMD), & dwwritensize, null); // retailmsg (1, (text ("% s "), tmp3); sleep (200); unsigned char * rel = new unsigned char [1, 1024]; // int Len; memset (Rel, 0, sizeof (rel )); if (readfile (m_serial, Rel, 50, & dwreadsize, null) {cstring TMP; // TMP. format (_ T ("% s"), Rel); DWORD dwnum = multibytetowidechar (cp_acp, 0, (lpcstr), Rel,-1, null, 0); wchar_t * pwtext; pwtext = new wchar_t [dwnum]; multibytet Owidechar (cp_acp, 0, (lpcstr) REL,-1, pwtext, dwnum); // start to convert TMP = pwtext; If (TMP. Find (L "> ")! =-1) {writefile (m_serial, PDU, strlen (PDU), & dwwritensize, null); int counter = 0; unsigned char * rel1 = new unsigned char [1024]; while (counter <10) {sleep (300); If (readfile (m_serial, rel1, 200, & dwreadsize, null) {// retailmsg (1, (Text ("readfile \ r \ n"); DWORD dwnum3 = multibytetowidechar (cp_acp, 0, (lpcstr) rel1,-1, null, 0); wchar_t * pwtext3; cstring tmp3; pwtext3 = new wchar_t [dwnum3]; multibytetowidechar (cp_acp, 0, (lpcstr) rel1,-1, pwtext3, dwnum3); // start to convert tmp3 = pwtext3; // retailmsg (1, (text ("% s "), tmp3); If (tmp3.find (L "OK ")! =-1) {isok = 0;} Delete [] pwtext3; If (isok = 0) {break ;}} counter ++;} Delete [] rel1 ;} delete [] pwtext;} Delete [] rel; return isok ;}