/* smsDemo.c: send and receive sms message demo Compiler: VC6 Hardware: GTM-201, GTM-201-3GWA serial notice: [Apr 12, 2011] Create by Malo */ #include #include #include #include #include #include "GSM.h" //== Unicode format to MBCS (default formate of VC6's string) //parameter: // pSrc: Unicode string, and MBCS string will be put here later // nSrcLength: pSrc's length (byte) //return: // Length of MBCS string (unit:byte) int UCS2toMBCS(unsigned char* pSrc, int nSrcLength) { int nDstLength; // UNICODE length WCHAR wchar[128]; // UNICODE buffer char* pDst = (char*)pSrc; // change high/low byte, and fit into unicode string for(int i=0; i MBCS nDstLength = WideCharToMultiByte(CP_ACP, 0, wchar, nSrcLength/2, pDst, 160, NULL, NULL); // end char pDst[nDstLength] = 0x00; return nDstLength; } //== MBCS format to Unicode format //parameter: // pSrc: MBCS string, and Unicode string will be put here later // nSrcLength: pSrc's length //return: // Length of Unicode string (unit:byte) int MBCStoUCS2(char* pSrc, int nSrcLength) { int nDstLength; // UNICODE length WCHAR wchar[128]; // UNICODE buffer unsigned char* pDst = (unsigned char*)pSrc; // MBCS --> UNICODE nDstLength = MultiByteToWideChar(CP_ACP, 0, pSrc, nSrcLength, wchar, 128); // change high/low byte, and fit into result string for(int i=0; i> 8; // high byte *pDst++ = wchar[i] & 0xff; // low byte } return nDstLength * 2; } void printfMsg(strEncode_Msg RecMsg) { printf("\n---- new SMS message come in ----\n"); printf("phone number = %s\n", RecMsg.phoneNumber); printf("receive time = %s\n", RecMsg.time); printf("mode = %d\n", RecMsg.mode); printf("message length = %d\n", RecMsg.dataLen); printf("message = %s\n", RecMsg.msg); printf("\n---------------------------------\n"); } int main(void) { int iAction=1, quit=1; int i; int tmp; int libVer; char libDate[20]; int Result=0; strEncode_Msg RecMsg, SendMsg; char sendNumber[20]; int send_n; int sendStatus = 0; SYSProfile sysProfile; //-- print HSDPA lib. version GM_SYS_GetLibDate(libDate); libVer = GM_SYS_GetLibVersion(); printf("GSM LIB vesion %X.%02X, Date:%s\n", libVer>>8, libVer&0xff, libDate); //-- init modem strcpy(sysProfile.PINCode, "0000"); //The pin code of SIM card, ex: "0000" sysProfile.modemPort = 2; sysProfile.hardware = 0; //0: GTM-201 if( (Result = GM_SYS_InitModem(sysProfile)) == GM_NOERROR) printf("init_modem success!!\n"); else{ printf("init_modem fail!! return value is %d\n", Result); return 1; } //--check Could the modem service? while(GM_SYS_CheckModemStatus() != GM_NOERROR) { printf("wait modem register...\n"); Sleep(1000); } printf("modem registered!!\n"); while(iAction!=0) { iAction=0; quit=0; printf("\n"); printf("1) Send ASCII messages\n"); printf("2) check signal quality\n"); printf("3) check registered?\n"); printf("\n"); printf("0) Quits demo program\n\n"); printf("Choose an option and press [Enter]: "); scanf("%d", &iAction); printf("\n"); switch(iAction) { case 1://Send ASCII messages printf("Send ASCII messages\n"); printf("Please Input Phone Number ="); scanf("%s", sendNumber); printf("How many message do you want to send?\n"); scanf("%d", &send_n); i = 0; printf("== start to send sms, please press to exit ==\n"); while(1) { // press "ESC" to exit if(kbhit()) { tmp = getch(); if( tmp == 27 || tmp == 'q') break; } //--(1) check that could the modem service, if it can't, skip operating the modem below if(GM_SYS_CheckModemStatus() != GM_NOERROR) continue; //--(2) send messages, when the modem can service if(i