⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gprs_smm.h

📁 利用该程序可以通过短信让远程GPRS模块上线
💻 H
字号:
// GPRS_SMM.h : main header file for the GPRS_SMM DLL
// Edited by xie hong sheng , 2002-11 ,CopyRight hongdian

#if !defined(AFX_GPRS_SMM_H__240951A3_FBD4_400A_9024_B3AA1C791AA6__INCLUDED_)
#define AFX_GPRS_SMM_H__240951A3_FBD4_400A_9024_B3AA1C791AA6__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#ifndef __AFXWIN_H__
	#error include 'stdafx.h' before including this file for PCH
#endif

#include "resource.h"		// main symbols

#define  HDCALL        __stdcall 

#define  MAX_RECEIVE_BUF 960 //reserve for translating data
#define  BUFFLEN   2048      //data buf that read from serial com
#define  TIMERINTERVAL 200   //time interval that read data from serial com
#define  WAITCALLTODTU  10   //time to wait for calling DTU
#define  WAITSMTODTU    7    //time to wait for sending sm to DTU
#define  NOTUSECALL     0    //use call mode
#define  USECALL        1    //not use call mode
#define  PROTO_CALLFROMDTU   0x13 

#define  PROTO_SMDTUONLINE   0x13  
#define  PROTO_CONFIGUREDATA 0x32
#define  PROTO_USERDATA      0x33
#define  MAXSMLENGTH         280 

#define  CONFIGUREDATA 0
#define  USERDATA      1
#define  NOPROTOCOL    2
/********************************************/
typedef struct _SMM_information
{
	HANDLE m_hComm;             //handle to the com that opened
	HANDLE m_hCommMutex;        //used to Lock m_hComm

	char   m_szSMMNumber[11];
	char   m_szSMSCNumber[11];
	char   m_szBuf[BUFFLEN];    //store the data that read from com
	int    m_nBeginPosition;    //the first position point to data in the szbuf that has not been processs
	int    m_nEndPosition;      //
	int    m_nBufLen;           //

	int    m_nRunState;         //whether the ProcessDataFromSerialCom is running
	int    m_nOKNOCARRIERNumber;        //count of OK and NOCARRIER

	SOCKET m_sock;              //communicate with DSC
	char   m_DSCIpAddr[16];     //DSC ip addr
	int    m_nDSCSrvPort;       //DSC server port

	UINT   m_unTimerId;         //timer id
	int    m_nWordMode;         //0-not changed,1-changed

	int    m_nCanUse;           //0-can call DTU or send sm to DTU , 1-can not
	
	char   m_szLastPhone[16];   //the last phone number
	int    m_nLastPhoneTTL;     //
}SMM_information;

typedef struct _SM_SUBMIT
{
	char m_AT_CMGF[10];
	char m_AT_CMGS[12];
	char m_zero[2];
	char m_type[2];
	char m_mr[2];
	char m_da[18];
	char m_pid[2];
	char m_dcs[2];
	char m_vp[2];
	char m_udl[2];
	char m_ud[281];  //Length of SM is 280 and length of 0x1A is 1;
}SM_SUBMIT;


//+CMT: "+8613510013635",,"03/01/07,12:37:48+00"
//535A4E07901A4FE1
//10+18+2+18+2+2+14+2=
typedef struct _SM_RECEIVE
{
	char m_smsc[18];
	char m_unknown[2];
	char m_oa[18];
	char m_pid[2];
	char m_dcs[2];
	char m_scts[14];
	char m_udl[2];
	char m_ud[280];
}SM_RECEIVE;

typedef struct _CALLFROMDTU
{
	char m_cFrameHead;              //0x7B
	char m_cProtoType;              //0x13
	unsigned short m_cPackLen;      //total length of packet,0x10
	char m_szDTUNumber[11];         //DTU phone number
	char m_cFrameTail;              //0x7B
}CALLFROMDTU;

typedef struct _SM_RECEIVE_TODSC
{
	CALLFROMDTU m_head;              //DTU that send sm to DSC
	char m_szBuf[MAX_RECEIVE_BUF];   //reserverd for receive and send data,not used now;
}SM_RECEIVE_TODSC;

/********************************************/

/////////////////////////////////////////////////////////////////////////////
// CGPRS_SMMApp
// See GPRS_SMM.cpp for the implementation of this class
//

class CGPRS_SMMApp : public CWinApp
{
public:
	CGPRS_SMMApp();

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CGPRS_SMMApp)
	public:
	virtual BOOL InitInstance();
	//}}AFX_VIRTUAL

	//{{AFX_MSG(CGPRS_SMMApp)
		// NOTE - the ClassWizard will add and remove member functions here.
		//    DO NOT EDIT what you see in these blocks of generated code !
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};
/*************************************************************/
// Interface to DSC

/*
int  SMMInit(char *DSCIpAddr,int DSCSrvPort,
			 char *SerialCom,DCB *dcb,
			 char *SMSCNumber,char *SMMNumber,int WorkMode);
1,DSCIpAddr:DSC ip address;
2,DSCSrvPort:DSC server port;
3,SerialCom:the serial comm than connect gprs modem;
4,dcb:information that config comm,containing baudrate,bytesize,stopbits,pairty;
5,SMSCNumber:SMSC phone number;
6,SMMNumber:the gprs modem phone number;
7,WorkMode:if 0,the dsc ip and port is not changed,1,changed;

result:
0:    success;
-10:  argument error;
-1:   DSCIpAddr or DSCSrvPort error;
-2:   open serial comm error;
-3:   open socket error;
-4:   create mutex error;
-5:   configSMM error;
-6:   SetTimer error;
*/
extern "C" int  HDCALL SMMInit(char *,int,char *,DCB *,char *,char *,int);

/*
    if you call SMMInit,then you must call SMMFree to free 
	the resource that got in the SMMInit;
*/
extern "C" int  HDCALL SMMFree(void);

/*
    int  SMMSetting(char *DSCIpAddr,int DSCSrvPort)
    Set the dsc ip address and dsc server port to smminfo struct;
	DSCIpAddr:dsc ip address;
	DSCSrvPort:dsc server port;
result:
    0:success;
	-1:failed;	
*/
extern "C" int  HDCALL SMMSetting(char *,int);

/*
    int MakeDTUOnLine(int Changed,char *DTUNumber)
    Changed:0-not changed,1-changed;
    DTUNumber:DTU phone number which you want make on line; 
result:
    0-success;
	-1:failed;
*/
extern "C" int HDCALL MakeDTUOnLine(int,char *);

/*
    int  SendDataToDTUBySM(char *DTUNumber,char *szData,int nDataLen,int nProtoType)
	send data to DTU by sm,this mode is used if the gprs service doesn't word;
	DTUNumber:the DTU phone number that you want to send data to;
	szData:the data that you want to send to DTU;
	nDataLen:the length of szData;
	nProtoType:data type,0-configure data,1-user data
result:
    0:success;
	-1:failed;
*/
extern "C" int  HDCALL SendDataToDTUBySM(char *,char *,int,int);

/*****************************************************/
// internal Routine

//Initialize the struct of smminfo, all member are setted to zero;
void Initsmminfo(void);

/*read data from serial com which connect the modem;
result:
  0-success  //the length data read from serial com is bigger than zero;
 -1-failed
*/
int  ReadDataFromSerialCom(void);

/*MakeDTUOnLine by calling DTU
result:
  0-success;
 -1-failed;
*/
int  MakeDTUOnLine_Call(char *);

/*MakeDTUOnLine by Sendding SM to DTU
result:
  0-success;
 -1-failed;
*/
int  MakeDTUOnLine_SM(char *);

/*Write data to serial com which connect the modem;
   szData:the data to be wrote to serial com;
   nDataLen:the length of data;
   nTimeOut:wait for the data to be completly wrote;
result:
  0-success;
 -1-failed;
*/
int  SendDataToSerialCom(char *,int,int);

/*Send data to DSC by socket
   szData:the data to be sent to DSC
   nDataLen:the length of data;
result:
  0-success;
 -1-failed;
*/
int  SendDataToDSC(char *,int);

/*analysis the data that read from serial com;
result:
  0-completely processed;
  1-CLIP data;
  2-CMT  data;
  3-reserve for OK,not used now
  4-reserve for NO CARRIER,not used now
  5-not completely processed , but the length is not enought for any type of data;
*/
int  ProtocolAnalysis(void);

/*reserved ,not used now*/
int  Process_OKNOCARRIER(int);

/*process the CLIP data and CMT data
result:
  0-success;
 -1-failed;
  5-same as ProcessAnalysis
*/
int  Process_CLIP(void);
int  Process_CMT(void);

/*
* int ConfigSMM(char *SMSCNumber)
* send "at+cnmi=2,2,0,0,0" to com
* send "at+clip=1" to com
* send "at+csca=+86"+SMSCNumber to com
* SMSCNumber:SMSC phone number
result: 0:success; -1:failed;
*/
int  ConfigSMM(char *);

void WriteLog(char *,int);

/*used for timer to read and process data
it was called when timeout of timer*/
void ReadAndProcessData(void);

/* 
* ConfigSerialCom(char *SerialCom,DCB *dcb)
* open a COM and then SetCommState and SetupComm;
* SerialCom:the com name,such "COM1";
* dcb:a DCB Struct than contain baudrate,bytesize,stopbits,parity;
result:
  0-success;
 -1-failed;
*/
int  ConfigSerialCom(char *,DCB *);

/*convert the number to SM number
such as "12345678901" to "2143658709F1";
*/
int  ProcessPhoneNumber(char *,char *);

/*convert the SM number to  number
such as "2143658709F1" to "12345678901";
*/
int  ProcessPhoneNumber2(char *,char *);

/*write sm to serial com
int  SendSMToSerialCom(char *,char *,int);  
*/

/*create the sm frame and write it to serial com
  DTUNumber:the dtu which you want to send data to;
  szData:data;
  nDataLen:length of data;
*/
int  SendSMToDTU(char *,char *,int);

/*process the data read from serial com;
  it was called by ReadAndProcessData;
*/
int  ProcessDataFromSerialCom(void);

/*get the position of next 0D0A
result:
  success-the position of next 0D0A;
  failed--1;
*/
int  GetNextEndCharPosition(void);

/*conver the char to int,such as 'A' to 0x41*/
int  CharToInt(char);

/*get host ip address*/
int  GetHostName(char *,int);

/*if the last data is not enouth to any type of data;
  then move the data to the head of buf,and reserved 
  to be processed in next time
result:
  5-success;
*/
int  MoveDataInBuf(void);

/*judge if a packet of CMT is legal
result:
  0-legal;
 -1-illegal;
*/
int  VerifySMCMT(void);

/*calculate the count of "OK" and "NO CARRIER"
  szData:the data to be calculated;
  nDataLen:length of data;
  type:if this is set to 1 then calculate the "NO CARRIER",
       set to  0,calculated "OK" only;
result:
  -1-failed;
  number:success;
*/
int  OKNumber(char *,int,int);

/*reset modem,not used now,reserved for future;
result:
  0-success;
 -1-failed;
*/
int  ResetModem(void);
/*
 *Add by SEA on Oct27,2003
 *Setup Modem type
 *if use CDMA modem,set 1
 *if use GPRS modem,set 0
 *default value 0
 */
extern "C" void  HDCALL SetModemType(int nModemType);
/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_GPRS_SMM_H__240951A3_FBD4_400A_9024_B3AA1C791AA6__INCLUDED_)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -