/* smsDemo.c: send and receive sms message demo Compiler: BC++ 3.1 Compile mode: large Project: smsDemo.c G4500.lib GSM_U2.lib OS7_COM.lib MCU2LIB.lib Hardware: G-4513 series [Aug 28, 2014] Modified by William */ #include #include #include #include #include #include "../lib/G4500.h" #include "../lib/GSM_U2.h" #include "../lib/OS7_COM.h" #include "../lib/MCU2LIB.h" //== this function controls the power of GSM module void powerFunction(int lv) { if(lv==0) { MCU2_EnableGSM(0); //GSM Power OFF }else { MCU2_EnableGSM(1); //GSM Power ON } } void printMsg(strEncode_Msg RecMsg) { int i; if(RecMsg.mode == 0) { Print("\r\n------------------\r\n"); Print("phone number = %s\r\n", RecMsg.phoneNumber); Print("receive time = %s\r\n", RecMsg.time); Print("mode = %d\r\n", RecMsg.mode); Print("message length = %d\r\n", RecMsg.dataLen); Print("message = %s\r\n", RecMsg.msg); Print("\r\n------------------\r\n"); }else { Print("\r\n------------------\r\n"); Print("phone number = %s\r\n", RecMsg.phoneNumber); Print("receive time = %s\r\n", RecMsg.time); Print("mode = %d\r\n", RecMsg.mode); Print("message length = %d\r\n", RecMsg.dataLen); Print("message = \r\n"); for(i=0; i>8, libVer&0xff, libDate); //-- print GSM lib. version GM_SYS_GetLibDate(libDate); libVer = GM_SYS_GetLibVersion(); Print("GSM LIB vesion %X.%02X, Date:%s\r\n", libVer>>8, libVer&0xff, libDate); //-- print MCU2 lib. version MCU2_getLibVer(libDate); Print("MCU2 LIB vesion : %s\r\n", libDate); //-- initial MCU2 Result = MCU2_init(); if(Result!=0) { Print("MCU2 initial fail\r\n"); return 1; }else { MCU2_getFWVer(libDate); Print("MCU2 FW version: %s\r\n", libDate); } //-- Enable Battery Protecting function: // 11.1V->close system power, 12.6V->system power recovered MCU2_BatteryProtect(1); //---- init modem strcpy(sysProfile.PINCode, "0000"); //The pin code of SIM card, ex: "0000" sysProfile.modemPort = 4; //modem port number. G-4500 = 4, uP-5000 = 11 sysProfile.hardware = 0; //hardware type. 1: G-4500, 2: uPAC-5000, 3: iP-8000, 0: Other GM_SYS_SetPowerFunction(powerFunction);//set power-control function if( (Result = GM_SYS_InitModem(sysProfile)) == GM_NOERROR) Print("init_modem success!!\r\n"); else{ Print("init_modem fail!! return value is %d\r\n", Result); return 1; } //--check Could the modem service? while(GM_SYS_CheckModemStatus() != GM_NOERROR) { Print("wait modem register...\r\n"); DelayMs(1000); } Print("modem registered!!\r\n"); while(iAction!=0) { iAction=0; quit=0; Print("\r\n"); Print("1) Send ASCII messages\r\n"); Print("2) check signal quality\r\n"); Print("3) check registered?\r\n"); Print("\r\n"); Print("0) Quits demo program\r\n"); Print("Choose an option and press [Enter]: "); Scanf("%d", &iAction); Print("\r\n"); switch(iAction) { case 1://Send ASCII messages Print("Send ASCII messages\r\n"); Print("Please Input Phone Number ="); Scanf("%s", sendNumber); Print("How many message do you want to send?\r\n"); Scanf("%d", &send_n); i = 0; Print("== start to send sms, please press to exit ==\r\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