//================================================================= // GSM_U2.h for miniOS //------------------ // support G-4511ĦBG-4513 series //------------------ //Version 1.00 2014/09 // 1.First release version //================================================================= #ifndef SMS_H_ #define SMS_H_ #ifdef __cplusplus extern "C" { #endif //--Error codes #define GM_NOERROR 0 //NO ERROR, success #define GM_COMERROR -1 //COM PORT ERROR #define GM_TIMEOUT -2 //time out #define GM_CMDERROR -3 //command error #define GM_NOSMS -4 //no sms #define GM_NOREG -5 //no register, or modem can't service #define GM_INITERROR -6 //init. Error #define GM_BUSY -7 //modem is busy #define GM_READY -8 //modem is ready to accept next command #define GM_LINKERROR -21 //Link to Server ERROR #define GM_NETERROR -22 //Network not opened ERROR // encode style for SMS #define GSM_7BIT 0 #define GSM_UCS2 8 //-- structure for sending/reading SMS typedef struct STRENCODE_MSG{ char phoneNumber[30]; //phone number char time[20]; //sms_time_stamp char msg[161]; //message's content unsigned char dataLen; //Message's length, Max length: 7-bit=160 words, UCS2=70 words(140 bytes) char mode; //encode style: 0=GSM_7BIT, 8=GSM_UCS2(uni-code) } strEncode_Msg; //-- structure for reading GPRS sockets typedef struct GPRSDATA{ char data[1500]; //data int dataLen; //data length char fromIP[16]; //IP of the serverĦA000.000.000.000 and '0x00', total 16 byte unsigned int port; //TCP/UDP port of the server int link; //data of link[n] } GPRSData; //-- structure for setting network typedef struct NET_PROFILE { char APN[60]; //APN for network provided by your cellular provider char user[32]; //username for network provided by your cellular provider char pw[32]; //password for network provided by your cellular provider char DnsServerIP[16]; //The most basic task of DNS is to translate hostnames such as www.icpdas.com to IP address such as 96.9.41.131. } NetProfile; //-- structure for setting system parameters typedef struct SYS_PROFILE { char PINCode[5]; //The pin code of SIM card, ex: "0000" int modemPort; //modem port number. int hardware; //hardware type. 0: G-4511ĦBG-4513 series, 1: G-4500 }SYSProfile; //====================== //==== API for user ==== //====================== //== Get lib. version //return: // version format = A.BC int GM_SYS_GetLibVersion(void); //== return lib. date //parameter: // libDate: a string of lib. date, format="Apr 15 2014" void GM_SYS_GetLibDate(char* libDate); //== initialize Modem // must use GM_SYS_CheckModemStatus() to check modem status later //parameter: // sysProfile: set system profile //return: // GM_NOERROR: success // GM_COMERROR: comport error // GM_INITERROR: init fail error int GM_SYS_InitModem(SYSProfile sysProfile); //== Close the modem // Please call GM_SYS_InitModem() to wake up modem // after using GM_SYS_CloseModem(1) to shut down the modem. //parameter: // mode: 0: close modem, but maintain it power on // 1: close modem and set it power off (only for G-4500) //return: // GM_NOERROR: no error // GM_CMDERROR: command error int GM_SYS_CloseModem(int mode); //== check modem status, suggest you check it in your loop every time //return: // GM_NOERROR: modem register success, can service // GM_NOREG: modem not registered, can't service int GM_SYS_CheckModemStatus(void); //== get the status of the command you sent //return: // GM_BUSY: modem busy, you can't send other command // GM_NOERROR: success // GM_TIMEOUT: time out // GM_CMDERROR: command error // other: please refer to error codes of HSDPA.h int GM_SYS_CheckCmdStatus(void); //== check signal quality //return: // signal: signal quality // 0 -113 dBm or less // 1 -111 dBm // 2...30 -109... -53 dBm // 31 -51 dBm or greater int GM_SYS_CheckSignal(void); //== check register //return: // register flag // 0: not registered // 1: registered, home network // 2: not registered, and searching... // 3: registration denied // 4: unknown // 5: registered, roaming int GM_SYS_CheckReg(void); //== Set Power-control function // * if you use GSM library with GTM-201 serial production, // this function will reset GTM-201 if necessary //parameter: // userPowerFunc power-control function // *notice: setPowerFunc(1) is Power-ON, setPowerFunc(0) is OFF void GM_SYS_SetPowerFunction(void (*userPowerFunc)(int)); //== Enable NITZ function // the NITZ function can auto-adjust RTC of the system at the moment of the modem registering to GSM system // Please call "GM_SYS_NITZUpdateRTC" to update RTC after GM_SYS_EnableNITZ(1). //parameter: // nitz: 0=disable, 1=enable void GM_SYS_EnableNITZ(int nitz); //== Update the RTC of the System by NITZ // Notice: this function will disable all 3G/GSM function about 1~2 minutes. // Please use this function after you stop all 3G/GSM function void GM_SYS_NITZUpdateRTC(void); //== check the status of NITZ //return: // 0:fail, 1:success, 2 updating int GM_SYS_CheckNITZ(void); //====================== //==== SMS function ==== //====================== //== Send a message // must use "GM_SYS_CheckCmdStatus()" to check status later //parameter: // strMsg: the message //return: // GM_NOERROR no error // GM_NOREG: not registered, or can't service // GM_BUSY: modem busy int GM_SMS_SendMsg(strEncode_Msg strMsg); //== Get a new sms message //parameter: // msg: new sms message //return: // 0: no new message // 1: new message coming int GM_SMS_GetNewMsg(strEncode_Msg* msg); //============================================== //==== 3G / GPRS data Transmission Function ==== //============================================== //== Set Net profile data //parameter: // netProfile: Net profile data //return: // GM_NOERROR no error // GM_CMDERROR command error int GM_NET_SetNet(NetProfile netProfile); //== Built TCP/UDP link //parameter: // n link number (0~6), 3G:0~6, 2G:0 // tcp client type, tcp=1 for TCP client ; tcp=0 for UDP client // serverIP IP or Domain name of the server, Max length=63, ex: "61.111.222.333", "test.com.tw" // serverPort TCP/UDP Port of the server (1~65535), ex: 1234 //return: // GM_NOERROR correct parameter to install TCP/UDP link // GM_CMDERROR command error int GM_NET_InstallLink(int n, int tcp, char* serverIP, unsigned int serverPort); //== Close NetWork //return: // GM_NOERROR no error // GM_CMDERROR command error // GM_BUSY: modem busy int GM_NET_CloseNet(void); //== get local IP //parameter: // ipaddr: IP string, format: char ipaddr[16]; void GM_NET_GetIP(char* ipaddr); //== Close client link[n] //parameter: // n: client link[n], 3G:0~6, 2G:0 //return: // GM_NOERROR no error // GM_CMDERROR command error // GM_BUSY: modem busy int GM_NET_CloseLink(int n); //== get status of Link[n] //parameter: // n: link[n], 3G:0~6, 2G:0 //return: // status: 0=not link, 1=linked, 2=Network closed int GM_NET_GetLinkStatus(int n); //== Send a packet // must use "GM_SYS_CheckCmdStatus()" to check status later //parameter: // link: link number, 3G:0~6, 2G:0 // data: data // dataLen: data length, Max.=1000 //return: // GM_NOERROR no error // GM_CMDERROR command error // GM_BUSY: modem busy int GM_NET_Send(char link, char* data, int dataLen); //== Get the new packet //parameter: // gprsData: new data packet //return: // 0: no new packet // 1: new packet coming int GM_NET_GetNewPacket(GPRSData* gprsData); #ifdef __cplusplus } #endif #endif //SMS_H_