📄 smsserialport.h
字号:
// SmsSerialPort.h: interface for the CSmsSerialPort class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_SMSSERIALPORT_H__4C00B45C_1F42_4D50_A67D_BA3BDF94C7A6__INCLUDED_)
#define AFX_SMSSERIALPORT_H__4C00B45C_1F42_4D50_A67D_BA3BDF94C7A6__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "SerialPort.h"
//#include "SmsDataTranslate.h"
#include <list>
// 用户信息编码方式
#define GSM_7BIT 0
#define GSM_8BIT 4
#define GSM_UCS2 8
// 应答状态
#define GSM_WAIT 0 // 等待,不确定
#define GSM_OK 1 // OK
#define GSM_ERR -1 // ERROR
// 短消息参数结构,编码/解码共用
// 其中,字符串以'\0'结尾
typedef struct
{
char SCA[16]; // 短消息服务中心号码(SMSC地址)
char TPA[16]; // 目标号码或回复号码(TP-DA或TP-RA)
char TP_PID; // 用户信息协议标识(TP-PID)
char TP_DCS; // 用户信息编码方式(TP-DCS)
char TP_SCTS[16]; // 服务时间戳字符串(TP_SCTS), 接收时用到
char TP_UD[160]; // 原始用户信息(编码前或解码后的TP-UD)
short index; // 短消息序号,在读取时用到
} SM_PARAM;
// 读取应答的缓冲区
typedef struct
{
int len;
char data[16384];
} SM_BUFF;
#ifndef NOTE_MESSAGE_LIST_LENGTH
#define NOTE_MESSAGE_LIST_LENGTH
#define MAX_SM_SEND 128 // 发送队列长度
#define MAX_SM_RECV 128 // 接收队列长度
#define WM_SHOWNOTEMESSAGE WM_USER + 100//显示短消息信息
#endif
#ifndef CUR_NOTE_MESSAGE
#define CUR_NOTE_MESSAGE
typedef struct NoteMessageInfo
{
CString time;
CString phoneNumber;
CString action;
CString state;
CString content;
} NoteMsgInfo;
#endif
class CSmsSerialPort : public CSerialPort
{
public:
CSmsSerialPort();
virtual ~CSmsSerialPort();
public:
//////////////////////////////////////////////////////////////////////////
int gsmBytes2String(const unsigned char* pSrc, char* pDst, int nSrcLength);
int gsmString2Bytes(const char* pSrc, unsigned char* pDst, int nSrcLength);
int gsmEncode7bit(const char* pSrc, unsigned char* pDst, int nSrcLength);
int gsmDecode7bit(const unsigned char* pSrc, char* pDst, int nSrcLength);
int gsmEncode8bit(const char* pSrc, unsigned char* pDst, int nSrcLength);
int gsmDecode8bit(const unsigned char* pSrc, char* pDst, int nSrcLength);
int gsmEncodeUcs2(const char* pSrc, unsigned char* pDst, int nSrcLength);
int gsmDecodeUcs2(const unsigned char* pSrc, char* pDst, int nSrcLength);
int gsmInvertNumbers(const char* pSrc, char* pDst, int nSrcLength);
int gsmSerializeNumbers(const char* pSrc, char* pDst, int nSrcLength);
int gsmEncodePdu(const SM_PARAM* pSrc, char* pDst);
int gsmDecodePdu(const char* pSrc, SM_PARAM* pDst);
///////////////////////////////////////////////////////////////////////////
int gsmSendMessage(SM_PARAM& Src);
// 读取短消息,仅发送命令,不读取应答
// 用+CMGL代替+CMGR,可一次性读出全部短消息
int gsmReadMessageList();
// 删除短消息,仅发送命令,不读取应答
// 输入: index - 短消息序号,1-255
int gsmDeleteMessage(int index);
int gsmGetResponse(SM_BUFF& Buff);
//////////////////////////////////////////////////////////////////////////
BOOL IsExistModen();//短信设备是否连接
BOOL IsRunning();//判断串口是否连接
//将字符内容转成SM_PARAM结构体
SM_PARAM NoteMessage(CString ServiceCenter,CString Combined_Set_No,CString Message,int orderID);
//将短消息放入发送缓冲区
BOOL PutToSendMessageList(SM_PARAM & sm_Parama);
//从发送缓冲区取出短消息
BOOL GetNoteMessageFromSendMessagelist(SM_PARAM& smParam);
//从显示消息队列中取出一条记录并删掉
BOOL GetNoteMessageInfoFromShowMessageList(NoteMsgInfo & noteMsgInfo);
//放到显示消息队列中去
BOOL PutToShowNoteMessageList(CString time,CString phoneNumber,CString action,CString state,CString content);
BOOL SendNoteMessage(SM_PARAM & sm_Param);
void ReceiveNoteMessage(SM_PARAM & sm_Param);
static ULONG _stdcall NoteMessageThread(LPVOID lpParam);
BOOL StartThread();
BOOL StopThread();
//////////////////////////////////////////////////////////////////////////
BOOL IsRecvNoteMessageDate();
void GetMessageIndex(char *str);
void SaveToReceivedLog(SM_PARAM sm_Param);
void SaveToSendLog(SM_PARAM sm_Param,CString sendTime,int state);
////////////////////////////////////////////////////////////////////////
std::list<SM_PARAM> m_SendNoteMessageList;//发送短信消息队列
std::list<NoteMsgInfo> m_ShowNoteMessageList;//接收队列
BOOL m_isConnectDevice;//是否已连接短信猫
public:
CRITICAL_SECTION m_SendNoteMessageListCritical; //发送消息列表临界区
CRITICAL_SECTION m_RecvNoteMessageListCritical; //接收消息列表临界区
CRITICAL_SECTION m_ShowNoteMessageListCritical; //显示消息列表临界区
HANDLE m_hThread;
DWORD m_dwThreadID;
BOOL m_isRunning;
HANDLE m_event;
//////////////////////////////////////////////////////////////////////////
//用到
public:
int m_MessagIndex;
BOOL m_IsRecvNoteMessageDate;
};
#endif // !defined(AFX_SMSSERIALPORT_H__4C00B45C_1F42_4D50_A67D_BA3BDF94C7A6__INCLUDED_)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -