//=================================================================
// GSM.h for VC
//-----------------------
// support GTM-201-3GWA, GTM-201 serial
//=================================================================

#ifndef SMS_H_
#define SMS_H_


#define GM_API extern "C" __declspec (dllexport)


//--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 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: GTM-201
}SYSProfile;

//======================
//==== API for user ====
//======================

//== Get lib. version
//return:
//	version format = A.BC
GM_API int GM_SYS_GetLibVersion(void);

//== return lib. date
//parameter:
//	libDate:	date, format="Jul 21 2010"
GM_API 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
GM_API 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 MiniOS7)
//return:
//		GM_NOERROR:		no error
//		GM_CMDERROR:	command error
GM_API 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
GM_API 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 GSM.h
GM_API 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
GM_API 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
GM_API int GM_SYS_CheckReg(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
GM_API 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
GM_API int GM_SMS_GetNewMsg(strEncode_Msg* msg);

#endif //SMS_H_