/**************************************************************************************/ /* GPRS.h */ /* */ /* Modification History: */ /* v2.01[Oct/04/2010] by Yide */ /* Modify: GPRS_TCPClient, GPRS_UDPClient */ /* v2.00[Sep/17/2010] by Yide */ /* New: GPRS_CheckModuleName */ /* v1.32[Aug/25/2010] by Yide */ /* Modify: GPRS_TCPClient, GPRS_UDPClient, GPRS_Receive_Data */ /* v1.31[Aug/02/2010] by Yide */ /* Modify: GPRS_TCPClient, GPRS_UDPClient */ /* v1.30[Jul/25/2010] by Yide */ /* Modify: Could_Send_Data, GPRS_TCPClient, GPRS_UDPClient */ /* v1.29[Jul/13/2010] by Yide */ /* New: iCSQ_Status, ulGPRS_Ask_CSQ_time */ /* Modify: Could_Send_Data, GPRS_TCPClient, GPRS_UDPClient */ /* v1.28[Jun/09/2010] by Yide */ /* Modify: SMS_Recv_Msg_Loop2 */ /* v1.27[May/18/2010] by Yide */ /* Modify: SMS_Recv_Msg_Loop2 */ /* v1.26[May/17/2010] by Yide */ /* New: SMS_Recv_Msg_Loop2, SMS_Check_Recv_Msg2, SMS_Encode_Msg2 */ /* Modify: SMS_Init */ /* v1.25[Apr/07/2010] by Yide */ /* New: extern unsigned char ucFailedToConnectServer */ /* _GPRS_TCP_Close, _GPRS_TCP_RECONN */ /* ulASk_time,iSMS_Recv_Msg_Loop_CREG,iSMS_Recv_Msg_Loop_CSQ */ /* Modify: SMS_Recv_Msg_Loop */ /* v1.24[Feb/10/2010] by Yide */ /* New: extern unsigned char ucReConTCPServer */ /* v1.23[Sep/25/2009] by Yide */ /* Modify: GPRS_TCPClient, SMS_PDUMode_Send, SMS_PDUMode_Send_Loop */ /* v1.22[Aug/17/2009] by Yide */ /* New: extern unsigned int Connect_Server_TimeOut */ /* Modify: GPRS_Check_CSQ, GPRS_Check_Reg */ /* v1.21[Jul/07/2009] by Yide */ /* Modify: GPRS_TCPClient, GPRS_UDPClient */ /* v1.20[Jul/01/2009] by Yide */ /* Modify: GPRS_TCPClient, GPRS_UDPClient */ /* v1.19[Jun/25/2009] by Yide */ /* Modify: struct str_GPRS_setting, Could_Send_Data, GPRS_TCP_Close */ /* v1.18[Jun/17/2009] by Yide */ /* Modify: GPRS_TCPClient, GPRS_UDPClient */ /* v1.17[Jun/16/2009] by Yide */ /* Modify: SMS_Encode_Msg */ /* v1.16[Jun/08/2009] by Yide */ /* New: SMS_Send_Flag, SMS_Init, SMS_PDUMode_Send_Loop */ /* GPRS_Recv_From_Remote_IP, GPRS_Recv_From_Remote_port */ /* Modify: SMS_Recv_Msg_Loop, GPRS_TCPClient, GPRS_UDPClient */ /* GPRS_UDPClient_Send_Data, GPRS_UDPClient_Send_Data_Num */ /* v1.15[Apr/14/2009] by Yide */ /* New: struct strEncode_Msg, SMS_Recv_Msg_Loop, SMS_Encode_Msg */ /* Fix: SMS_PDUMode_Send */ /* Modify: GPRS_UDPClient_Send_Data, GPRS_UDPClient_Send_Data_Num */ /* v1.14[Mar/03/2009] by Yide */ /* New: GPRS_Send_Data_Num */ /* v1.13[Feb/17/2009] by Yide */ /* Fix: GPRS_Send_Data */ /* v1.12[Feb/02/2009] by Yide */ /* Fix: GPRS_Get_Operating_Band */ /* v1.11[Jan/22/2009] by Yide */ /* New: GPRS_Get_Operating_Band, GPRS_Set_Operating_Band */ /* and GPRS_GetLibDate */ /* Modify: GPRS_Check_CSQ */ /* v1.10[Jan/13/2009] by Yide */ /* New: DNSCFG, DNS_Server, GPRS_UDPClient_Send_Data_Num */ /* Modify: struct str_GPRS_setting GPRS_server1 and GPRS_server2 */ /* modify 32 chars,struct GPRS_UDP_setting Remote_IP modify */ /* 32 chars. Modify GPRS_TCPClient and GPRS_UDPClient step */ /* v1.09[Jan/07/2009] by Yide */ /* Modify: struct str_GPRS_setting user_name and password modify 32 chars*/ /* v1.08[Dec/30/2008] by Yide */ /* Fix: SMS_PDUMode_Send */ /* v1.07[Dec/26/2008] by Yide */ /* New: struct GPRS_UDP_setting,GPRS_UDPClient,GPRS_UDPClient_Send_Data */ /* Modify: AutoRedial */ /* v1.06[Dec/15/2008] by Yide */ /* New: GPRS_Modem_Reset_Loop,GPRS_GetLibVersion */ /* Modify: GPRS_Check_MODEM */ /* V1.05[Oct/27/2008] by Yide */ /* New: SMS_TextMode_Send,SMS_PDUMode_Send,SMS_Del_Msg,SMS_Select_Mode */ /* and SMS_Message_Read */ /* V1.04[Sep/09/2008] Create by Yide */ /**************************************************************************************/ #define NoError 0 struct str_GPRS_setting { char phone[20]; // ex. "4121234" char user_name[32]; // GPRS's username. This parameter must be provided by users's Telcomm. Co., Ltd. char password[32]; // GPRS's password. This parameter must be provided by users's Telcomm. Co., Ltd. char ExtraStr[50]; //GPRS'APN (access point name). This parameter must be provided by users's Telcomm. Co., Ltd. unsigned long modem_baud; unsigned long debug_baud; char GPRS_server1[32]; // Remote Server's IP or Remote Server's domain name.If users want to use domain name mode, users must set "DNSCFG" as "1" int RemotePort; // Remote Server's port int modem_com; //Modem port number int debug_port; //Debug port number int Enable_debug; //When users set the Enable_debug as 1, this library will show debug information. int AutoRedial; //When users set the AutoRedial as 1 and connection failed, this library will automatic re-dial. int LocalPort; //The GPRS module port. When users use the TCP Client or UDP Client function to /* OS7_COM *pModem_com; OS7_COM *pDebug_port; */ /* int iModem_Slot; int iDebug_Slot; */ /* [2009/01/12] when remote TCP Server or UDP Server is a domain name. */ int DNSCFG; //If users set "DNSCFG" as "1", their GPRS_server1 must be domain name char DNS_Server[32]; //When users set "DNSCFG" as "1", DNS_Server parameter is needed. /* When remote TCP Server or UDP Server is a domain name. struct str_GPRS_setting rGPRS; ... rGPRS.modem_baud = 115200L; rGPRS.debug_baud = 115200L; rGPRS.DNSCFG = 1; sprintf(rGPRS.DNS_Server, "168.95.1.1"); // for example: Chunghwa Telecom Co.,Ltd's DNS Server in Taiwan When remote TCP Server or UDP Server is a IP. struct str_GPRS_setting rGPRS; ... rGPRS.modem_baud = 115200L; rGPRS.debug_baud = 115200L; rGPRS.DNSCFG = 0; // here choose zero. //sprintf(rGPRS.DNS_Server, "168.95.1.1"); //can be blank. } */ }; extern unsigned char ucReConTCPServer; /* extern BYTE bReConTCPServer; When recvive "TCP Close" from remote TCP Server, whether try to re-connect to remote server again. bReConTCPServer value: 0: Don't try to re-connect , it will try to connect to remote TCP server until the user call GPRS_TCP_RECONN function. 1: connect to remote TCP Server again when G-4500 recvives "TCP Close" */ extern unsigned int Connect_Server_TimeOut; /* extern unsigned int Connect_Server_TimeOut; describe: Set the connect to remote timeout. Default is 5000 ms. Unit is ms. */ //SMS Data Format #define GSM_7BIT 0 //ASCII format, max. 160 characters #define GSM_UCS2 8 //Unicode format, max. 70 characters typedef struct { char phone[20]; // ex. "4121234" char content[200]; char cMode; // 0: SMS_7BIT. 8: GSM_UCS2. } SMS_Setting; typedef struct { // new add [2009/04/14] ver 1.15 char cPhone_number[30]; //receive phone number char cTime[20]; //receive Date and Time char cMsg[512]; //receive message int nMsg_len; //receive length of message char cMode; // 0: SMS_7BIT. 4: SMS_8BIT. 8: GSM_UCS2. }strEncode_Msg; extern int SMS_Send_Flag; // new add [2009/06/08] ver 1.16 /* extern int SMS_Send_Flag; describe: Send SMS state 0: Ready to send a message 1: Sending a message 2: Sent a successful message 3: Receiving a message -1: Sent a wrong message -5: Time Out */ extern char GPRS_Recv_From_Remote_IP[20]; extern int GPRS_Recv_From_Remote_port; int GPRS_Check_MODEM(void); /* int GPRS_Check_MODEM(void); describe: Check the modem whether is normal. Return: 0 -> OK Others -> The modem does not response. Check the modem and the baud rate. */ int GPRS_Para_Set(const struct str_GPRS_setting GPRS_setting); /* int GPRS_Para_Set(struct str_GPRS_setting GPRS_setting); describe: The function is for setting GPRS parameters to system. example: rGPRS.phone = "*99***1#"; // *** use your own *** rGPRS.user_name = ""; // *** use your own *** rGPRS.password = ""; // *** use your own *** rGPRS.GPRS_server1 = "218.164.78.164"; // *** choose mail server 1 near you *** rGPRS.modem_com=1; rGPRS.RemotePort=10000; ret=GPRS_Para_Set(rGPRS); Return: 0 -> success -1 -> setting parameter fault */ void GPRS_CONN_Start(void); /* void GPRS_CONN_Start(void); describe: Start to dial to modem and connection IPS. */ int GPRS_Check_Status(void); /* int GPRS_Chack_Status(void); describe: Check connection state. Return: 0 -> IP INITIAL 1 -> IP START 2 -> IP CONFIG 3 -> IP IND 4 -> IP GPRSACT 5 -> IP STATUS 6 -> TCP CONNECTING 7 -> IP CLOSE 8 -> CONNECT OK 9 -> PDP DEACT */ extern unsigned char ucFailedToConnectServer; //[2010/04/07] Ver1.25 add int GPRS_TCPClient(void); /* int GPRS_TCPClient(void); describe: Connect Remote TCP Server and must be loop. Return: 1-49 ¡X> GPRS dialing 80 ¡X> Connect OK -1 ¡X> TIMEOUT -2 ¡X> System no ready -3 ¡X> Send Data TimeOut -4 ¡X> Send Data ERROR */ extern int iCSQ_Status; //[2010/07/13] V1.29 add /* extern int iCSQ_Status; describe: The iCSQ_Status is valid when users call the GPRS_TCPClient function. Value: 0 -> -113 dBm or less 1 -> -111 dBm 2 to 30 -> -109 to -53 dBm 31 -> -51 dBm or greater 99 -> not known or not detectable -5 -> TimeOut -6 -> Command Error */ extern unsigned long ulGPRS_Ask_CSQ_time; //[2010/07/13] V1.29 add /* extern unsigned long ulGPRS_Ask_CSQ_time; describe: The ulGPRS_Ask_CSQ_time is valid when users call the GPRS_TCPClient function. The ulGPRS_Ask_CSQ_time is how long to check the signal strength of GSM module.(Uint: ms)(Default: 1000 ms) Value: 0 -> Disable this function other -> Enable this function.(Uint: ms)(Default: 1000 ms) */ int GPRS_Send_Data(char *sData); /* int GPRS_Send_Data(char *sData); describe: When Could_Send_Data is equal 1, the data can be sent to the server. Send data isn¡¦t more than 1024 bytes. Return: 0 -> The data can be send to the server. -1 -> The data more than 1024 bytes.(ERROR) -2 -> The Could_Send_Data state isn't equal "1".(ERROR) */ int GPRS_Send_Data_Num(char *sData, int cData_Length); /* int GPRS_Send_Data(char *sData); describe: When Could_Send_Data is equal 1, the data can be sent to the server. Send data isn¡¦t more than 1024 bytes. Argument: cData_Length is the length of sData. Return: 0 -> The data can be send to the server. -1 -> The data more than 1024 bytes.(ERROR) -2 -> The Could_Send_Data state isn't equal "1".(ERROR) */ int GPRS_Check_Data_Length(void); /* int GPRS_Check_Data_Length(void); describe: Check the length of data from the Remote Server in the Internet. Return: Receive data length from the remote server. */ int GPRS_Receive_Data(char *data); /* int GPRS_Receive_Data(char *data); describe: Receive data from the Remote Server in the Internet. Return: 0 -> The data can be received succes -1 -> No receive any data */ int GPRS_PPP_Close(void); /* int GPRS_PPP_Close(void); describe: Terminate the PPP connection. Return: 0 -> Success Others -> The modem does not response. */ int GPRS_TCP_Close(void); /* int GPRS_TCP_Close(void); describe: Terminate the TCP/IP connection. Return: 0 -> Success Others -> The modem does not response. */ int _GPRS_TCP_Close(int iMode); //[2010/04/07]new add /* int GPRS_TCP_Close(void); describe: Terminate the TCP/IP connection. Argument: iMode 0 -> TCP Client function Return: 0 -> Success Others -> The modem does not response. */ int GPRS_PPP_RECONN(void); /* int GPRS_PPP_RECONN(void); describe: Reconnect the PPP connection. Return: 0 -> Success Others -> The modem does not response. */ int GPRS_TCP_RECONN(void); /* int GPRS_TCP_RECONN(void); describe: Reconnect the TCP/IP connection. Return: 0 -> Success Others -> The modem does not response. */ int _GPRS_TCP_RECONN(int iMode); //[2010/04/07]new add /* int GPRS_TCP_RECONN(void); describe: Reconnect the TCP/IP connection. Argument: iMode 0 -> TCP Client function Return: 0 -> Success Others -> The modem does not response. */ int GPRS_Modem_Reset(void); /* int GPRS_Modem_Reset(void); describe: Reset the modem. Return: 0 -> Success Others -> The modem does not response. */ int GPRS_Check_CSQ(void); /* int GPRS_Check_CSQ(void); describe: Check GSM CSQ(Signal Quality Report). Return: 0 -> -113 dBm or less 1 -> -111 dBm 2 to 30 -> -109 to -53 dBm 31 -> -51 dBm or greater 99 -> not known or not detectable -5 -> TimeOut */ int GPRS_CheckModuleName(void); /* int GPRS_CheckModuleName(void); describe: Check GSM module Return: 0 -> SIM300/SIM340 1 -> SIM900 -5 -> TimeOut */ int RTC_GPRS_Time(unsigned char *GMT); /* int RTC_GPRS_Time(unsigned char *GMT); describe: Set time of MiniOS7 to GPRS modem. Return: 0 -> The modem reset success. -1 -> The modem reset failed and must be re-call the function. */ extern int Could_Send_Data; /* extern int Could_Send_Data; describe: Check whether users can send data or not. Value: 0 -> don't connect to remote server 1 -> Users can send data. 2 -> Users sent data successfully. 3 -> Users are sending data 4 -> Library checks CSQ. */ extern char GPRS_Local_IP[20]; /* extern char GPRS_Local_IP[20]; describe: GPRS Local IP. */ int SMS_Init(int iMode); // new add [2009/06/08] ver 1.16 // Modefiy [2010/05/17] ver 1.26 /* void SMS_Init(void); describe: SMS function initial Argument: iMOde 0 Normal mode 2 SMS_Recv_Msg_Loop2 mode 3 SMS_Recv_Msg_Loop2 mode(Debug) Return: 0: success -1: failed */ int SMS_Select_Mode(int mode); /* int SMS_Select_Mode(int mode); describe: Select the SMS mode Argument: mode 0 PDU mode(UCS2) 1 Text mode Return: 0 -> Setting success. -5 -> TimeOut,Error. */ int SMS_TextMode_Send(SMS_Setting str_SMS); /* int SMS_TextMode_Send(SMS_Setting str_SMS); describe: Send a message to assign phone number by TextMode. Return: 0 -> Send success. -1 -> Content of message too long(Max. 160 character),Error. -2 -> An error occurred in transmission. -5 -> TimeOut,Error. */ int SMS_PDUMode_Send(SMS_Setting str_SMS, int data_length); /* int SMS_PDUMode_Send(SMS_Setting str_SMS, int data_length); describe: Send a message to assign phone number by PDU mode. Return: 0 -> Send success. -1 -> Content of message too long(max. 70 UCS2, max. 160 Ascii),Error. -2 -> An error occurred in transmission. -5 -> TimeOut,Error. PDU mode -------- Ascii format, max. 160 characters. | ---- Unicode format, max. 70 characters. */ int SMS_PDUMode_Send_Loop(SMS_Setting str_SMS, int data_length, unsigned long ulTimeout); // new add [2009/06/08] ver 1.16 /* int SMS_PDUMode_Send_Loop(SMS_Setting str_SMS, int data_length, int Timeout) describe: Send a message to assign phone number by PDU mode. Argument: Timeout is whether send a message success or not Return: 0 -> Send success. -1 -> Content of message too long(Max. 70 UCS2, max. 160 Ascii),Error. -2 -> The status of SMS_Send_Flag variable isn't equal to 0,Error. PDU mode -------- Ascii format, max. 160 characters. | ---- Unicode format, max. 70 characters. */ int SMS_Del_Msg(int index); /* int SMS_Del_Msg(int index); describe: Delete assign index message. Return: 0 -> Delete success. -5 -> TimeOut,Error. */ int SMS_Message_Read(int index, char *szResult); /* int SMS_Message_Read(int index,char *szResult); describe: Read assign index message. Return: 0 -> Read success. -5 -> TimeOut,Error. */ extern unsigned long ulASk_time; // new add [2010/04/07] ver 1.25 extern int iSMS_Recv_Msg_Loop_CREG; // new add [2010/04/07] ver 1.25 extern int iSMS_Recv_Msg_Loop_CSQ; // new add [2010/04/07] ver 1.25 int SMS_Recv_Msg_Loop(void); // new add [2009/04/14] ver 1.15 /* int SMS_Recv_Msg_Loop(void); describe: when receive a message, return the index of message. Return: 0 -> Read success. 1 ~ 15 -> SMS index. */ int SMS_Recv_Msg_Loop2(void); //new add [2010/05/17] ver 1.26 /* int SMS_Recv_Msg_Loop2(void); describe: Must be called each loop. Return: 0: sueecss */ void SMS_ResetLoop2Param(void);//new add [2010/08/07] int SMS_Check_Recv_Msg2(void); //new add [2010/05/17] ver 1.26 /* int SMS_Check_Recv_Msg2(void); describe: Check whether receive a message or not. Return: 0: Don't recvive a message >0: Receive a message(SMS) */ int SMS_Encode_Msg2(strEncode_Msg* strMsg); //new add [2010/05/17] ver 1.26 /* int SMS_Encode_Msg2(strEncode_Msg* strMsg); describe: When the SMS_Check_Recv_Msg2 is more than zero, read the content of message. Return: 0: sueecss Note: Don't need to call SMS_Del_Msg function, the library will automatic to delete the message that . */ int SMS_Encode_Msg(int index, strEncode_Msg* strMsg); // new add [2009/04/14] ver 1.15 /* int SMS_Encode_Msg(int index, strEncode_Msg* strMsg); describe: Read assign index message. Return: 0 -> Read success. -5 -> TimeOut,Error. */ /* How to use the SMS_Recv_Msg_Loop and SMS_Encode_Msg functions to receive a short message? Example: int iRet; strEncode_Msg RecMsg; ... SMS_Select_Mode(0); //Select SMS PDU mode while(1){ if(Kbhit()) break; iRet = SMS_Recv_Msg_Loop(); if(iRet > 0){ Print("Msg index=>%d\r\n", iRet); SMS_Encode_Msg(iRet, &RecMsg); Print("Phone Num=%s\r\n", RecMsg.cPhone_number); Print("") } */ /* [2008/12/08] add function for GSM/GPRS. */ int GPRS_Check_Reg(void); /* int GPRS_Check_Reg(void); describe: Check GSM/GPRS network registration. Return: 0 -> not registered, ME is not currently searching for a new operator. 1 -> registered, home network. 2 -> not registered, ME currently searching for a new operator. 3 -> registration denied. 4 -> unknown. 5 -> registered, roaming. -5 -> TimeOut,Error. */ /* [2008/12/15] add function for GSM/GPRS Modem Reset. */ #define GPRS_Chack_Status GPRS_Check_Status void GPRS_Modem_Reset_Loop(void); /* void GPRS_Modem_Reset_Loop(void); describe: Reset the modem. Use another method that have better perform, but must be loop GPRS_TCPClient() after call this function. int iRet; ... while(1){ iRet = GPRS_TCPClient(); if(iRet==-2){ GPRS_Modem_Reset_Loop(); printCom_1("System no ready\r\n"); } } */ int GPRS_UDPClient(void); /* int GPRS_UDPClient(void); describe: Connect Remote UDP Server and must be loop. Return: 1-79 ¡X> GPRS dialing 80 ¡X> Get IP -1 ¡X> TIMEOUT -2 ¡X> System no ready */ int GPRS_UDPClient_Send_Data(char *cData); /* int GPRS_UDPClient_Send_Data(char *cData); describe: Send data to the server, and the data isn¡¦t more than 1024 bytes. cData : You want to send to Remote UDP Server data. Return: 0 -> The data can be send to the server. -1 -> The data more than 1024 bytes.(ERROR) -2 -> The Could_Send_Data state isn't equal "1".(ERROR) */ /* [2009/01/13] add function for UDP Client via GPRS. */ int GPRS_UDPClient_Send_Data_Num(char *cData, int cData_Length); /* int GPRS_UDPClient_Send_Data(char *cData); describe: Send data to the server, and the data isn¡¦t more than 1024 bytes. cData : You want to send to Remote UDP Server data. Return: 0 -> The data can be send to the server. -1 -> The data more than 1024 bytes.(ERROR) -2 -> The Could_Send_Data state isn't equal "1".(ERROR) When your data have '0x00' byte problem, please use this function. */ /* [2009/01/22] add function for set and get operating band (ex: 1800MHz). */ int GPRS_Get_Operating_Band(void); /* int GPRS_Get_Operating_Band(void); describe: Get GSM/GPRS Operating Band. Return: 1 -> PGSM_MODE(900MHz) 2 -> DCS_MODE(1800MHz) 3 -> PCS_MODE(1900MHz) 4 -> EGSM_DCS_MODE(900/1800MHz) 5 -> GSM850_PCS_MODE(850/1900MHz) -5 -> TimeOut,Error. */ int GPRS_Set_Operating_Band(int iMode); /* int GPRS_Set_Operating_Band(int iMode); describe: Set GSM/GPRS Operating Band. Argument: iMode: 1 -> PGSM_MODE(900MHz) 2 -> DCS_MODE(1800MHz) 3 -> PCS_MODE(1900MHz) 4 -> EGSM_DCS_MODE(900/1800MHz) 5 -> GSM850_PCS_MODE(850/1900MHz) Return: 0 -> Set up success. -5 -> TimeOut,Error. */ int GPRS_TCPServer(void); /* int GPRS_TCPClient(void); describe: Connect Remote TCP Server and must be loop. Return: 1-49 ¡X> GPRS dialing 80 ¡X> Connect OK -1 ¡X> TIMEOUT -2 ¡X> System no ready -3 ¡X> Send Data TimeOut -4 ¡X> Send Data ERROR */ extern char GPRS_Remote_TCP_Client_IP[20]; extern int iIsRemoteTcpClient; //0:no, 1:yes void GPRS_GetLibDate(char *cDate); /* void GPRS_GetLibDate(char *cDate); describe: Current date is Jan 22 2009 (*cData: Jan 22 2009) */ unsigned GPRS_GetLibVersion(void); /* unsigned GPRS_GetLibVersion(void); describe: Current version is 2.01 (return 0x0201) */