📄 simuphone.cpp
字号:
// SimuPhone.cpp : implementation file
//
#include "stdafx.h"
#include "pansrmtc.h"
#include "SimuPhone.h"
#include "ServiceDataQueue.h"
#include "VSInterpreter.h" //为了CVSInterpreter::AbstractData
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define WM_USER_DIALIN WM_USER + 2000
#define WM_USER_ONHOOK WM_USER + 2001
#define WM_USER_KEY WM_USER + 2002
#define WM_USER_GETKEYTIMEOUT WM_USER + 2003
extern CServiceDataQueue m_requestQueue_Voice;
extern CServiceDataQueue m_replyQueue;
UINT SimuDialogicThread(LPVOID lpvoid);
DWORD dwSimuDialogicThreadID;
/////////////////////////////////////////////////////////////////////////////
// CSimuPhone dialog
CSimuPhone::CSimuPhone(CWnd* pParent /*=NULL*/)
: CDialog(CSimuPhone::IDD, pParent)
{
//{{AFX_DATA_INIT(CSimuPhone)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CSimuPhone::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSimuPhone)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSimuPhone, CDialog)
//{{AFX_MSG_MAP(CSimuPhone)
ON_BN_CLICKED(IDC_BUTTON_KEY1, OnButtonKey1)
ON_BN_CLICKED(IDC_BUTTON_KEY10, OnButtonKey10)
ON_BN_CLICKED(IDC_BUTTON_KEY8, OnButtonKey8)
ON_BN_CLICKED(IDC_BUTTON_KEY2, OnButtonKey2)
ON_BN_CLICKED(IDC_BUTTON_KEY3, OnButtonKey3)
ON_BN_CLICKED(IDC_BUTTON_KEY4, OnButtonKey4)
ON_BN_CLICKED(IDC_BUTTON_KEY5, OnButtonKey5)
ON_BN_CLICKED(IDC_BUTTON_KEY6, OnButtonKey6)
ON_BN_CLICKED(IDC_BUTTON_KEY7, OnButtonKey7)
ON_BN_CLICKED(IDC_BUTTON_KEY9, OnButtonKey9)
ON_BN_CLICKED(IDC_BUTTON_KEY11, OnButtonKey11)
ON_BN_CLICKED(IDC_BUTTON_KEY12, OnButtonKey12)
ON_BN_CLICKED(IDC_BITMAP_HOOKSTATE, OnBitmapHookstate)
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSimuPhone message handlers
void CSimuPhone::OnButtonKey1()
{
PostThreadMessage(dwSimuDialogicThreadID, WM_USER_KEY, m_iChannelNo, (LPARAM)'1');
}
void CSimuPhone::OnButtonKey2()
{
PostThreadMessage(dwSimuDialogicThreadID, WM_USER_KEY, m_iChannelNo, (LPARAM)'2');
}
void CSimuPhone::OnButtonKey3()
{
PostThreadMessage(dwSimuDialogicThreadID, WM_USER_KEY, m_iChannelNo, (LPARAM)'3');
}
void CSimuPhone::OnButtonKey4()
{
PostThreadMessage(dwSimuDialogicThreadID, WM_USER_KEY, m_iChannelNo, (LPARAM)'4');
}
void CSimuPhone::OnButtonKey5()
{
PostThreadMessage(dwSimuDialogicThreadID, WM_USER_KEY, m_iChannelNo, (LPARAM)'5');
}
void CSimuPhone::OnButtonKey6()
{
PostThreadMessage(dwSimuDialogicThreadID, WM_USER_KEY, m_iChannelNo, (LPARAM)'6');
}
void CSimuPhone::OnButtonKey7()
{
PostThreadMessage(dwSimuDialogicThreadID, WM_USER_KEY, m_iChannelNo, (LPARAM)'7');
}
void CSimuPhone::OnButtonKey8()
{
PostThreadMessage(dwSimuDialogicThreadID, WM_USER_KEY, m_iChannelNo, (LPARAM)'8');
}
void CSimuPhone::OnButtonKey9()
{
PostThreadMessage(dwSimuDialogicThreadID, WM_USER_KEY, m_iChannelNo, (LPARAM)'9');
}
void CSimuPhone::OnButtonKey10()
{
PostThreadMessage(dwSimuDialogicThreadID, WM_USER_KEY, m_iChannelNo, (LPARAM)'0');
}
void CSimuPhone::OnButtonKey11()
{
PostThreadMessage(dwSimuDialogicThreadID, WM_USER_KEY, m_iChannelNo, (LPARAM)'*');
}
void CSimuPhone::OnButtonKey12()
{
PostThreadMessage(dwSimuDialogicThreadID, WM_USER_KEY, m_iChannelNo, (LPARAM)'#');
}
BOOL CSimuPhone::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
HWND hwndListChannelInfo = ::GetDlgItem(this->m_hWnd, IDC_LIST_CHANNELINFO);
::SendMessage(hwndListChannelInfo, LB_SETHORIZONTALEXTENT, 1000, 0);
m_bOnHook = TRUE;
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
struct SimuDialogicThreadParam
{
int iChannelCount;
};
CSimuPhone *psimuPhone;
UINT RunSimuDialogic(int iChannelCount)
{
struct SimuDialogicThreadParam *pthreadParam = (struct SimuDialogicThreadParam *)malloc(sizeof(struct SimuDialogicThreadParam));
pthreadParam->iChannelCount = iChannelCount;
psimuPhone = new CSimuPhone[iChannelCount];
for(int i = 0; i < iChannelCount; i ++)
{
psimuPhone[i].Create(i + 1);
}
CWinThread *pwinThread = AfxBeginThread(SimuDialogicThread, pthreadParam, 0, 0, 0, NULL);
if(pwinThread != NULL)
{
dwSimuDialogicThreadID = pwinThread->m_nThreadID;
return -1;
}
else
dwSimuDialogicThreadID = 0;
return 0;
}
struct KeyParam
{
int iKeyCount;
char aszTermKey[16];
int iWaitTime;
};
struct ChannelStatus
{
int iChannelNo;
int iServiceNo;
int iISN;
char *szKeyBuf; //本通道的按键缓冲
struct KeyParam keyParam;
char aszVoiceFilePath[100]; //语音文件的路径(以'\'结尾)
char aszTempPath[100]; //临时文件的路径(以'\'结尾)
int iLangType; //语种 0:未定 1:普通话 2:粤语 3:英语
BOOL bOffHook; //摘机状态
};
int ClearChannelStatus(struct ChannelStatus *pchannelStatus)
{
int iChannelNo = pchannelStatus->iChannelNo;
int iISN = pchannelStatus->iISN;
if(pchannelStatus->szKeyBuf != NULL)
{
free(pchannelStatus->szKeyBuf);
pchannelStatus->szKeyBuf = NULL;
}
memset(pchannelStatus, 0, sizeof(struct ChannelStatus));
pchannelStatus->iChannelNo = iChannelNo;
pchannelStatus->iISN = iISN;
return 0;
}
int DisplayChannelMsg(int iChannelNo, char *szDisplayMsg)
{
if(IsWindow((psimuPhone[iChannelNo - 1]).m_hWnd) == FALSE)
return -1;
HWND hwndListChannelInfo = ::GetDlgItem((psimuPhone[iChannelNo - 1]).m_hWnd, IDC_LIST_CHANNELINFO);
SendMessage(hwndListChannelInfo, LB_ADDSTRING, 0, (LPARAM)szDisplayMsg);
int iCount = SendMessage(hwndListChannelInfo, LB_GETCOUNT, 0, 0);
SendMessage(hwndListChannelInfo, LB_SETCURSEL, iCount - 1, 0);
return 0;
}
UINT SimuDialogicThread(LPVOID lpvoid)
{
struct SimuDialogicThreadParam *pthreadParam = (struct SimuDialogicThreadParam *)lpvoid;
struct ParamList *prequestParamList;
struct ParamList *preplyParamList;
struct ChannelStatus *pchannelStatus;
int i;
//初始化语音通道
int iChannelCount = pthreadParam->iChannelCount;
pchannelStatus = (struct ChannelStatus *)malloc(iChannelCount * sizeof(struct ChannelStatus));
memset(pchannelStatus, 0, iChannelCount * sizeof(struct ChannelStatus));
char aszTempPath[100] = "\0";
char aszVoiceFilePath[100] = "\0";
if(GetPrivateProfileString("PATH", "USRPATH", "\0", aszTempPath, sizeof(aszTempPath), ".\\Setup.ini") == 0)
{
AfxMessageBox("USRPATH not found");
return -1;
}
if(GetPrivateProfileString("PATH", "SYSPATH", "\0", aszVoiceFilePath, sizeof(aszVoiceFilePath), ".\\Setup.ini") == 0)
{
AfxMessageBox("SYSPATH not found");
return -1;
}
for(i = 0; i < iChannelCount; i ++)
{
pchannelStatus[i].iChannelNo = i + 1;
strcpy(pchannelStatus[i].aszTempPath, aszTempPath);
strcpy(pchannelStatus[i].aszVoiceFilePath, aszVoiceFilePath);
}
//检查WINDOW消息循环,接着检查RequestQueue_Voice
int iChannelNo; //发生事件的通道号
struct ChannelStatus *pcurrentChannelStatus;
char aszTemp[1000];
char *szDisplayMsg;
while(1)
{
//线程消息循环
MSG msg;
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{//有消息
if(msg.hwnd != NULL)
{
TranslateMessage(&msg); // Translates virtual key codes
DispatchMessage(&msg); // Dispatches message to window
}
else
{
iChannelNo = (int)msg.wParam;
pcurrentChannelStatus = &(pchannelStatus[iChannelNo - 1]);
if(pcurrentChannelStatus->bOffHook == FALSE && msg.message != WM_USER_DIALIN)
{//如果当前通道是挂机,就不接收除DIALIN以外的任何事件
continue;
}
switch(msg.message)
{
case WM_USER_DIALIN: //用户打入
pcurrentChannelStatus->bOffHook = TRUE;
CServiceDataQueue::CreateParamList(&preplyParamList, 1, pcurrentChannelStatus->iServiceNo, iChannelNo, pcurrentChannelStatus->iISN);
CServiceDataQueue::AddParamListMember_Integer(preplyParamList, 0);
m_replyQueue.AddParamList(preplyParamList);
break;
case WM_USER_GETKEYTIMEOUT: //用户超时仍未按键
//如果当前不在执行GETKEY,就忽略
if(pcurrentChannelStatus->iServiceNo != SERVICE_GETKEY)
break;
CServiceDataQueue::CreateParamList(&preplyParamList, 1, pcurrentChannelStatus->iServiceNo, iChannelNo, pcurrentChannelStatus->iISN);
CServiceDataQueue::AddParamListMember_Integer(preplyParamList, -2);
m_replyQueue.AddParamList(preplyParamList);
break;
case WM_USER_ONHOOK: //用户挂机
pcurrentChannelStatus->bOffHook = FALSE;
CServiceDataQueue::CreateParamList(&preplyParamList, 1, 9001, iChannelNo, pcurrentChannelStatus->iISN);
m_replyQueue.AddParamList(preplyParamList);
break;
case WM_USER_KEY: //用户按键
//如果当前不在执行GETKEY,就忽略
if(pcurrentChannelStatus->iServiceNo != SERVICE_GETKEY)
break;
char *szKeyBuf;
int iKeyLen;
char cNewKey;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -