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

📄 gsmsmsdlg.cpp

📁 一个可以实现与SCADA系统实现数据访问,并且通过手机短消息的方式发送到指定手机用户的实现.
💻 CPP
📖 第 1 页 / 共 3 页
字号:
		}
		
		for(int count = 0;count<m_person_max;count++)
		{
		    code = m_person_info[count].number;
		    type = m_person_info[count].type;
			name = m_person_info[count].name;
			rtu  = m_person_info[count].rtu;
		    
			if(type&SEND_TYPE_ALL)
			{ 
			    FjLibMsgTrans(Msg,sendstring,FALSE);
			    WriteOut(name,code,sendstring);
			} 
		    else if((type&SEND_TYPE_YX)&&(Msg.MsgType==FJD_MSG_TYPE_SIFT_YX))
			{
			    FjLibMsgTrans(Msg,sendstring,FALSE);
				if(SearchMap(rtu,type&SEND_TYPE_YX,Msg))
			        WriteOut(name,code,sendstring);
			} 
		    else if((type&SEND_TYPE_LMT)&&(Msg.MsgType==FJD_MSG_TYPE_LMT))
			{
			    FjLibMsgTrans(Msg,sendstring,FALSE);
				if(SearchMap(rtu,type&SEND_TYPE_LMT,Msg))
			        WriteOut(name,code,sendstring);
			} 
		    else if((type&SEND_TYPE_DEV)&&(Msg.MsgType==FJD_MSG_TYPE_DEV))
			{
			    FjLibMsgTrans(Msg,sendstring,FALSE);
				if(SearchMap(rtu,type&SEND_TYPE_DEV,Msg))
			        WriteOut(name,code,sendstring);
			} 
		    else if((type&SEND_TYPE_BH)&&(Msg.MsgType==FJD_MSG_TYPE_SIFT_BH))
			{
			    FjLibMsgTrans(Msg,sendstring,FALSE);
			    WriteOut(name,code,sendstring);
			} 
		    else if((type&SEND_TYPE_BHWJ)&&(Msg.MsgType==FJD_MSG_TYPE_SIFT_BHWJ))
			{ 
			    FjLibMsgTrans(Msg,sendstring,FALSE);
				if(SearchMap(rtu,type&SEND_TYPE_BHWJ,Msg))
			        WriteOut(name,code,sendstring);
			} 
		} 
	}
	ThreadBusy = FALSE;
	return 1;
}

BOOL CGsmSmsDlg::PutMsg(FJS_MSG_STRUCT & Msg)
{
	WORD type = Msg.MsgType;
    if (type==FJD_MSG_TYPE_NONE||type==FJD_MSG_TYPE_SIFT_YK
		||type==FJD_MSG_TYPE_PL||type==FJD_MSG_TYPE_YT||type==FJD_MSG_TYPE_CTRL_BH
		||type==FJD_MSG_TYPE_SOE||type==FJD_MSG_TYPE_CTRL_BHA||type==FJD_MSG_TYPE_YKSIFT) {
		return FALSE;
	}
	short	d;
	d = MsgPutPtr + 1;
	if (d>=FJD_MSG_BUF_MAX) d=0;
	if (d == MsgGetPtr) return FALSE;
	if (Msg.MsgType==FJD_MSG_TYPE_ASCII) {
		if (Msg.MsgDate.Asc.Time==0) {
			long xtime;
		    time(&xtime);
			xtime+=28800;
			Msg.MsgDate.Asc.Time=xtime;
		}
	}
	MsgBuf[d]=Msg;
    MsgPutPtr=d;
	return TRUE;
}

//from rlib message
LRESULT CGsmSmsDlg::FromRlibGetMsg(WPARAM wParam, LPARAM lParam)
{
	DWORD rec = wParam;
	CString s;
	FjLibGetLastMsg(Msg,rec);
	if(PutMsg(Msg)){
		if(!ThreadBusy&&hCom){
		    AfxBeginThread((AFX_THREADPROC)SendMsgThread,(LPVOID)NULL,THREAD_PRIORITY_NORMAL);
			ThreadBusy = TRUE;
		}
	}
	return 1;
}

/////////////////////////////////////////////////////////////////////
class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGsmSmsDlg dialog

CGsmSmsDlg::CGsmSmsDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CGsmSmsDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CGsmSmsDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	FjSysPath = _T("");
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);


	DWORD len1,len2;
    GetFjPath();
	if (!FjLibInit3(&FjSysPath,len1,len2,BaseNum)) {
			AfxMessageBox("实时库失败");
			return;
	}
	HWND pScadaWnd = ::FindWindow(NULL,"FJ95NT");
	if(!pScadaWnd)
	{
		AfxMessageBox("警告:SCADA模块未运行,系统不能正常工作!",MB_OK|MB_ICONERROR);
	}
    
	int Port;
    int Bate;

    Port = GetPrivateProfileInt("INIT","port",2,InitFile);
	Bate = GetPrivateProfileInt("INIT","bate",9600,InitFile);
    if(!Port) Port = 2;

	InitPort(Port-1,Bate);
    LoadPersonMessage();
	InitAllMap();
	ClrList();
}

void CGsmSmsDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CGsmSmsDlg)
	DDX_Control(pDX, IDC_LIST_SMS, m_list_sms);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CGsmSmsDlg, CDialog)
	//{{AFX_MSG_MAP(CGsmSmsDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_SET_COM, OnSetCom)
	ON_BN_CLICKED(IDC_TEL_NUM, OnTelNum)
	ON_BN_CLICKED(IDC_B_TEST, OnBTest)
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_B_HIS, OnBHis)
	ON_WM_SIZE()
	ON_WM_CREATE()
    ON_MESSAGE ( WM_TRAYNOTIFY, OnTrayNotify )
	ON_COMMAND(IDC_SHOWMAIN, OnShowmain)
	ON_COMMAND(IDEXIT, OnExit)
	ON_MESSAGE(FJD_MSG_GSM_SMS, FromRlibGetMsg) 
	ON_WM_SHOWWINDOW()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGsmSmsDlg message handlers
void CGsmSmsDlg::LoadPersonMessage()
{
	int count = 0;
	char asc[32];
	char temp[32];

	while(TRUE){
		sprintf(asc,"person%d",count);
	    m_person_info[count].rtu = GetPrivateProfileInt("RTU",asc,-1,InitFile);
        if(m_person_info[count].rtu == -1)
	       break;

	    sprintf(asc,"type%d",count);
	    m_person_info[count].type = GetPrivateProfileInt("SENDTYPE",asc,-1,InitFile);
	    if(m_person_info[count].type == -1) 
	       break;

		sprintf(asc,"name%d",count);
        GetPrivateProfileString("TELNAME",asc,"not found",temp,32,InitFile);
        if(!strcmp(m_person_info[count].name,"not found"))
	       break;
        m_person_info[count].name = temp;

		sprintf(asc,"code%d",count);
        GetPrivateProfileString("TELCODE",asc,"not found",temp,32,InitFile);
        if(!strcmp(m_person_info[count].number,"not found"))
	       break;
        m_person_info[count].number = temp;
	    count++;
	}
	m_person_max = count;
}

void CGsmSmsDlg::InitList()
{
	LV_COLUMN lvCol;

	lvCol.mask = LVCF_FMT|LVCF_SUBITEM|LVCF_TEXT|LVCF_WIDTH;
	lvCol.fmt = LVCFMT_LEFT;

	lvCol.cx = 40;
	lvCol.pszText="序号";
	lvCol.cchTextMax=4;
	lvCol.iSubItem = 0;
	m_list_sms.InsertColumn(lvCol.iSubItem, &lvCol);

	lvCol.cx = 60;
	lvCol.pszText="姓名";
	lvCol.cchTextMax=4;
	lvCol.iSubItem = 1;
	m_list_sms.InsertColumn(lvCol.iSubItem, &lvCol);

	lvCol.cx = 80;
	lvCol.pszText="电话号码";
	lvCol.cchTextMax=8;
	lvCol.iSubItem = 2;
	m_list_sms.InsertColumn(lvCol.iSubItem, &lvCol);

	lvCol.cx = 80;
	lvCol.pszText="发送日期";
	lvCol.cchTextMax=8;
	lvCol.iSubItem = 3;
	m_list_sms.InsertColumn(lvCol.iSubItem, &lvCol);
	
	lvCol.cx = 60;
	lvCol.pszText="发送时间";
	lvCol.cchTextMax=8;
	lvCol.iSubItem = 4;
	m_list_sms.InsertColumn(lvCol.iSubItem, &lvCol);

	lvCol.cx = 240;
	lvCol.pszText="短消息内容";
	lvCol.cchTextMax=10;
	lvCol.iSubItem = 5;
	m_list_sms.InsertColumn(lvCol.iSubItem, &lvCol);
}

void CGsmSmsDlg::InitAllMap()
{
	char asc[64];
	int count = 0;
	CString csTmp = _T("");
	DWORD value;
	DWORD rtu,dot,act;

    count = 0;
	while(TRUE){
        sprintf(asc,"lmt%d",count);
	    value=GetPrivateProfileInt("LMT", asc, -1, InitFile);
        if(value==-1) break;
        m_LmtSendMap.SetAt(value,value);
		count++;
	}
	count = 0;
	while(TRUE){
        sprintf(asc,"yx%d",count);
		GetPrivateProfileString("YX", asc, "not found", csTmp.GetBuffer(100),100,InitFile);
		csTmp.ReleaseBuffer();
		if (csTmp.CompareNoCase("not found")==0)
			break;
		sscanf(csTmp.LockBuffer(), "%d,%d", &rtu, &dot);
		csTmp.UnlockBuffer();
        m_yxSendMap.SetAt(dot,rtu);
		count++;
	}
	count = 0;
	while(TRUE){
        sprintf(asc,"dev%d",count);
		GetPrivateProfileString("DEV", asc, "not found", csTmp.GetBuffer(100),100,InitFile);
		csTmp.ReleaseBuffer();
		if (csTmp.CompareNoCase("not found")==0)
			break;
		sscanf(csTmp.LockBuffer(), "%d,%d", &rtu, &dot);
		csTmp.UnlockBuffer();
        m_DevSendMap.SetAt(dot,rtu);
		count++;
	}
	count = 0;
	while(TRUE){
        sprintf(asc,"bh%d",count);
		GetPrivateProfileString("BHWJ", asc, "not found", csTmp.GetBuffer(100),100,InitFile);
		csTmp.ReleaseBuffer();
		if (csTmp.CompareNoCase("not found")==0)
			break;
		sscanf(csTmp.LockBuffer(), "%d,%x", &rtu, &act);
		csTmp.UnlockBuffer();
        m_BhSendMap.SetAt(act,rtu);
		count++;
	}
}

BOOL CGsmSmsDlg::InitPort(int com,DWORD bate)
{
	DCB CommDCB;   
    COMMTIMEOUTS TimeOut;
    DWORD dwError,InQue = 2048,OutQue = 2048;
    char szText[40];
    BOOL fSuccess;
 
	if (hCom) CloseHandle(hCom);

    hCom = CreateFile(Port_Com[com], 
                      GENERIC_READ|GENERIC_WRITE,
                      0,    /* comm devices must be opened w/exclusive-access */  
                      NULL, /* no security attrs */   
                      OPEN_EXISTING, /* comm devices must use OPEN_EXISTING */  
                      0,//FILE_FLAG_OVERLAPPED    /* not overlapped I/O */   
                      NULL  /* hTemplate must be NULL for comm devices */ 
                     );

    if (hCom == INVALID_HANDLE_VALUE)
    {
	   dwError = GetLastError();  
       sprintf(szText,"不能初始化串口%s,请选择其它串口!",Port_Com[com]);
 	   AfxMessageBox(szText,MB_OK|MB_ICONINFORMATION);/* handle error */
	   return FALSE;
     }

    //设置输入/输出缓冲区.
    SetupComm(hCom, InQue, OutQue);

    fSuccess = GetCommState(hCom,&CommDCB);
	if (!fSuccess) 
	{
		sprintf(szText,"不能打开%s,请选择其它串口!",Port_Com[com]);
        AfxMessageBox(szText,MB_OK|MB_ICONERROR);
	    return FALSE;
    }

    CommDCB.BaudRate = bate;
	CommDCB.ByteSize = 8;
	CommDCB.Parity   = 0;
	CommDCB.StopBits = 0;
	CommDCB.fParity  = FALSE;     
	CommDCB.fOutX    = FALSE;    
	CommDCB.fInX     = FALSE;   
    CommDCB.fOutxCtsFlow = FALSE; 
    CommDCB.fOutxDsrFlow = FALSE; 
    CommDCB.fDtrControl  = DTR_CONTROL_ENABLE;//DTR_CONTROL_DISABLE;
    CommDCB.fRtsControl  = RTS_CONTROL_ENABLE;//RTS_CONTROL_DISABLE; 
    CommDCB.XonLim       = 1024;
    CommDCB.XoffLim      = 1024;
    CommDCB.fDsrSensitivity = FALSE;
    CommDCB.fTXContinueOnXoff = FALSE;
    CommDCB.fErrorChar = FALSE;
    //CommDCB.EofChar  = 0x0d;
	CommDCB.fBinary  = true;

    fSuccess = SetCommState(hCom,&CommDCB);
	if (!fSuccess) 
	{
		sprintf(szText,"设置 %s 错误!",Port_Com[com]);
		AfxMessageBox(szText,MB_OK|MB_ICONERROR);
	    return FALSE;
	}
		
	//设置通讯超时时间.
	GetCommTimeouts(hCom, &TimeOut);
	TimeOut.ReadIntervalTimeout=0;

⌨️ 快捷键说明

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