?? hgsmsenddlg.cpp
字號:
// hgsmsendDlg.cpp : implementation file
//
#include "stdafx.h"
#include "hgsmsend.h"
#include "hgsmsendDlg.h"
#include "smpp3.h"
#include "share.h"
#include "io.h"
#include "stdio.h"
#include "inihead.h"
#include "functopt.h"
#define STX 0x01
#define ETX 0x02
#define ACK 0x03
#define NAK 0x04
#define PARITYERROR 1
#define IDCALL 0x0C
#define ORDERRING 0x70
#define FOOTBALL 0x71
#define GROUPCALL 0x72
#define AUTOMO 0x73
#define ORDERSTRU 0x50
#define ORDERCONT 0x51
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//===========<B add by 肖桂云 2003/08/28 監控>================//
char watchstr[200]="Active";
static int count=0;
//===========<E add by 肖桂云 2003/08/28 監控>================//
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
CHgsmsendDlg *sgd;
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()
/////////////////////////////////////////////////////////////////////////////
// CHgsmsendDlg dialog
CHgsmsendDlg::CHgsmsendDlg(CWnd* pParent /*=NULL*/)
: CDialog(CHgsmsendDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CHgsmsendDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDI_ICON3);
}
void CHgsmsendDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CHgsmsendDlg)
DDX_Control(pDX, IDC_LIST1, m_Result_List);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CHgsmsendDlg, CDialog)
//{{AFX_MSG_MAP(CHgsmsendDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_TIMER()
ON_WM_DESTROY()
ON_COMMAND(ID_TEST, OnTest)
ON_COMMAND(ID_STATUS, OnStatus)
ON_COMMAND(ID_BIND, OnBind)
ON_COMMAND(ID_RESET, OnReset)
ON_COMMAND(ID_SYSCONFIG, OnSysconfig)
ON_COMMAND(ID_OK, OnOk)
ON_WM_CANCELMODE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CHgsmsendDlg message handlers
BOOL CHgsmsendDlg::OnInitDialog()
{
UINT time=1000;
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon,TRUE); // Set big icon
//SetIcon(m_hIcon, TRUE); // Set small icon
// TODO: Add extra initialization here
memset(&m_save,0,sizeof(m_save));
m_connect=0;
m_type=1;
m_unicode=0;
LineTest=0;
SetWindowText(" 上 海 海 港 SGIP (8690) 短 信 網 關 VERSION 1.0 ");
Message.Empty();
Phone.Empty();
SetSystemPara();
sgd=this;
InitBoxList();
InitSockClient();
InitSock();
WantReset=0;
time=1000/SENDTIMES;
SetTimer(1,time,NULL);
SetTimer(2,120000,NULL);
SetTimer(3,600000,NULL);
SetTimer(4,1000,NULL);
return TRUE; // return TRUE unless you set the focus to a control
}
void CHgsmsendDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CHgsmsendDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CHgsmsendDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CHgsmsendDlg::InitBoxList()
{
LV_COLUMN columninfo;
CRect r;
m_Result_List.GetClientRect(&r);
columninfo.mask = LVCF_FMT | LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH;
columninfo.fmt = LVCFMT_LEFT;
columninfo.iSubItem = 0;
columninfo.pszText ="狀態欄";
columninfo.cx = r.Width()/7 ;
m_Result_List.InsertColumn(0, &columninfo);
columninfo.mask = LVCF_FMT | LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH;
columninfo.fmt = LVCFMT_LEFT;
columninfo.iSubItem = 1;
columninfo.pszText =" 信息欄";
columninfo.cx = 6*r.Width()/7;
m_Result_List.InsertColumn(0, &columninfo);
}
void CHgsmsendDlg::xprintf(char * buffer,char *buffer1)
{
LV_ITEM insitem;
if (m_Result_List.GetItemCount()>=26) m_Result_List.DeleteItem(0);
insitem.mask=LVIF_TEXT;
insitem.iItem=m_Result_List.GetItemCount();
insitem.iSubItem=0;
insitem.pszText=buffer;
m_Result_List.InsertItem(&insitem);
insitem.iSubItem=1;
insitem.pszText=buffer1;
m_Result_List.SetItem(&insitem);
}
void CHgsmsendDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
if(nIDEvent==1) {
CheckSubmitSmBuffer();
}
if(nIDEvent==2)
{
if(!m_connect) TcpReset();
}
if(nIDEvent==3) RemoveOldFile();
writelog();
//===========<B add by 肖桂云 2003/08/28 監控>================//
if(nIDEvent==4)
{
sprintf(watchstr,"Squ=%ld",sequence_number);
if(m_connect) {
count++;
if (count<5) SendActive();
else {
m_connect=0;
if (count>200) PostMessage(WM_CLOSE, 0, 0L);
}
}
}
//===========<E add by 肖桂云 2003/08/28 監控>================//
CDialog::OnTimer(nIDEvent);
}
void CHgsmsendDlg::InitSock()
{
memset(&Client,0,sizeof(Client));
if (TcpSock.m_hSocket==INVALID_SOCKET)
{
BOOL bFlag=TcpSock.Create(TCP_PORT,SOCK_STREAM);
if (!bFlag) {
AfxMessageBox("Socket Failed!");
TcpSock.Close();
::PostQuitMessage(0);
return;
}
}
if (!TcpSock.Listen(3)) {
int nErrno=TcpSock.GetLastError();
if (nErrno!=WSAEWOULDBLOCK)
{
AfxMessageBox("Socket Failed!");
TcpSock.Close();
::PostQuitMessage(0);
return;
}
}
if (UdpSockUser.m_hSocket==INVALID_SOCKET) {
BOOL bFlag=UdpSockUser.Create(UDP_PORT_USER,SOCK_DGRAM);
if (!bFlag)
{
AfxMessageBox("Socket Failed!");
TcpSock.Close();
UdpSockUser.Close();
::PostQuitMessage(0);
return;
}
}
//UdpSockUser.AsyncSelect(FD_READ);
if (UdpSockRead.m_hSocket==INVALID_SOCKET) {
BOOL bFlag=UdpSockRead.Create(UDP_PORT_READ,SOCK_DGRAM);
if (!bFlag)
{
AfxMessageBox("Socket Failed!");
TcpSock.Close();
UdpSockUser.Close();
UdpSockRead.Close();
::PostQuitMessage(0);
return;
}
}
if (UdpSockSend.m_hSocket==INVALID_SOCKET) {
BOOL bFlag=UdpSockSend.Create(UDP_PORT_SEND,SOCK_DGRAM);
if (!bFlag)
{
AfxMessageBox("Socket Failed!");
TcpSock.Close();
UdpSockUser.Close();
UdpSockRead.Close();
UdpSockSend.Close();
::PostQuitMessage(0);
return;
}
}
}
void CHgsmsendDlg::UdpRead(char *buf, int length, CString ip)
{
int i,nLength,mlong=0,len;
char id[51],buffer[1024],temp[300],tempring[300];
int data_coding=0,esm_class=0;
char FeeValue[100];
char ChargeID[100];
BYTE FeeType=0;
DEF_SENDPOCKET m_sendpocket;
memset(ChargeID,0,sizeof(ChargeID));
memset(FeeValue,0,sizeof(FeeType));
memset(temp,0,sizeof(temp));
memset(id,0,sizeof(id));
switch(buf[0]) {
case 0x01:
memcpy(buffer,buf,80);buffer[80]=0;
xprintf(buffer,"OK");
if(buf[1]==ORDERRING)
{
memset(id,0,sizeof(id));
FeeType=buf[2]-'0';
memcpy(FeeValue,buf+3,6);
memcpy(id,buf+9,11);
memcpy(ChargeID,buf+20,11);
memset(buffer,0,sizeof(buffer));
memcpy(buffer,buf+31,3);
data_coding=atoi(buffer);
if(buf[34]=='1')
{
esm_class=64;
}
else
{
esm_class=0;
}
memset(buffer,0,sizeof(buffer));
memcpy(buffer,buf+35,3);
nLength=atoi(buffer);
if (nLength>140||nLength<1)
{
sprintf(buffer,"READ FROM %s MESSAGE LENGTH ERROR!",ip);
xprintf(buffer,"OK");
SendNak(PARITYERROR,ip);
sprintf(buffer,"SEND NAK TO %s",ip);
xprintf(buffer,"OK");
return ;
}
memset(buffer,0,sizeof(buffer));
memcpy(buffer,buf+38,nLength);
buffer[nLength]=0;
memset(tempring,0,sizeof(tempring));
sprintf(tempring,"READ:鈴聲From UDP:%s",ip);
xprintf(tempring,"OK");
SendACK(ip);
Submit_Sm_Ring(id,nLength,buffer,(BYTE)buf[1],data_coding,esm_class,FeeValue,FeeType,ChargeID);
break;
}else
if(buf[1]==ORDERSTRU)
{
memset(id,0,sizeof(id));
FeeType=buf[2]-'0';
memcpy(FeeValue,buf+3,6);
memcpy(id,buf+9,11);
memcpy(ChargeID,buf+20,11);
memset(buffer,0,sizeof(buffer));
memcpy(buffer,buf+31,3);
data_coding=atoi(buffer);
if(buf[34]=='1')
{
esm_class=64;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -