📄 simuphone.cpp
字号:
if(pcurrentChannelStatus->szKeyBuf == NULL)
{
iKeyLen = 0;
}
else
{
iKeyLen = strlen(pcurrentChannelStatus->szKeyBuf);
}
cNewKey = (char)LOBYTE(LOWORD(msg.lParam));
pcurrentChannelStatus->szKeyBuf = (char *)realloc(pcurrentChannelStatus->szKeyBuf, iKeyLen + 1);
szKeyBuf = pcurrentChannelStatus->szKeyBuf;
szKeyBuf[iKeyLen] = cNewKey;
szKeyBuf[iKeyLen + 1] = 0;
//判断是否结束接收按键
if(pcurrentChannelStatus->keyParam.iKeyCount != 0
&& strlen(szKeyBuf) >= pcurrentChannelStatus->keyParam.iKeyCount)
{//到达按键总数
goto GETKEYDONE;
}
for(i = 0; i < strlen(pcurrentChannelStatus->keyParam.aszTermKey); i ++)
{
if((pcurrentChannelStatus->keyParam.aszTermKey)[i] == cNewKey)
{//接收到结束按键
goto GETKEYDONE;
}
}
break;
GETKEYDONE:
CServiceDataQueue::CreateParamList(&preplyParamList, 1, pcurrentChannelStatus->iServiceNo, iChannelNo, pcurrentChannelStatus->iISN);
CServiceDataQueue::AddParamListMember_Integer(preplyParamList, 1);
CServiceDataQueue::AddParamListMember_String(preplyParamList, szKeyBuf);
m_replyQueue.AddParamList(preplyParamList);
break;
default:
break;
}
}
}
//检查语音请求队列, 执行指令
int iPlayType;
DWORD dwWaitResult;
int iGetRequestResult;
if(m_requestQueue_Voice.m_Lock.m_hSemaphore == NULL || m_replyQueue.m_Lock.m_hSemaphore == NULL)
{//检查两个队列是否被创建
Sleep(5);
continue;
}
while((dwWaitResult = WaitForSingleObject(m_requestQueue_Voice.m_hEvent_Add, 5)) == WAIT_OBJECT_0
|| m_requestQueue_Voice.IsEmpty() == FALSE)
{//有语音请求
iGetRequestResult = m_requestQueue_Voice.GetParamList(&prequestParamList);
if(dwWaitResult == WAIT_OBJECT_0 && iGetRequestResult != 0)
{
/* Sleep(1);
这不是错误,因为上面的ISEMPTY()==FALSE已将队列成员处理完了
AfxMessageBox("WaitForSingleObject()返回WAIT_OBJECT_0,但队列却为空");
*/
continue;
}
if(iGetRequestResult != 0)
continue;
//执行语音指令
pcurrentChannelStatus = &(pchannelStatus[prequestParamList->iChannelNo - 1]);
iChannelNo = prequestParamList->iChannelNo;
if(pcurrentChannelStatus->bOffHook == FALSE
&& prequestParamList->iServiceNo != SERVICE_OFFHOOK
&& prequestParamList->iServiceNo != SERVICE_WTRING)
{//如果当前通道是挂机,就不接收除OFFHOOK和WTRING以外的任何指令
continue;
}
pcurrentChannelStatus->iISN = prequestParamList->ISN;
pcurrentChannelStatus->iServiceNo = prequestParamList->iServiceNo;
switch( prequestParamList->iServiceNo )
{
case SERVICE_WTRING:
ClearChannelStatus(pcurrentChannelStatus);
pcurrentChannelStatus->bOffHook = FALSE;
//显示WTRING字符串来模拟WTRING指令
szDisplayMsg = (char *)malloc(20);
strcpy(szDisplayMsg, "Wtring...");
DisplayChannelMsg(prequestParamList->iChannelNo, szDisplayMsg);
free(szDisplayMsg);
break;
case SERVICE_PLAY1:
case SERVICE_PLAY2:
case SERVICE_PLAY3:
case SERVICE_PLAY4:
case SERVICE_PLAY5:
if(prequestParamList->iServiceNo == SERVICE_PLAY1)
iPlayType = 1;
if(prequestParamList->iServiceNo == SERVICE_PLAY2)
iPlayType = 2;
if(prequestParamList->iServiceNo == SERVICE_PLAY3)
iPlayType = 3;
if(prequestParamList->iServiceNo == SERVICE_PLAY4)
iPlayType = 4;
if(prequestParamList->iServiceNo == SERVICE_PLAY5)
iPlayType = 5;
struct VoiceList *pvoiceList;
char aszVoiceContent[10000];
pvoiceList = (struct VoiceList *)((prequestParamList->pParam)[0].pParam);
//生成语音字符串
aszVoiceContent[0] = 0;
for(i = 0; i < pvoiceList->nCount; i ++)
{
if((pvoiceList->pmember)[i].iType == 0)
{//声音文件名
strcat(aszVoiceContent, (char *)((pvoiceList->pmember)[i].pVoice));
}
else
{
sprintf(aszVoiceContent + strlen(aszVoiceContent), "%s@%d", (char *)((pvoiceList->pmember)[i].pVoice), (pvoiceList->pmember)[i].iType);
}
strcat(aszVoiceContent, ";");
}
//显示语音字符串来模拟放音
szDisplayMsg = (char *)malloc(strlen(aszVoiceContent) + 20);
sprintf(szDisplayMsg, "Play%d %s", iPlayType, aszVoiceContent);
DisplayChannelMsg(prequestParamList->iChannelNo, szDisplayMsg);
free(szDisplayMsg);
//填写应答
CServiceDataQueue::CreateParamList(&preplyParamList, 1, pcurrentChannelStatus->iServiceNo, pcurrentChannelStatus->iChannelNo, pcurrentChannelStatus->iISN);
CServiceDataQueue::AddParamListMember_Integer(preplyParamList, 1);
m_replyQueue.AddParamList(preplyParamList);
break;
case SERVICE_GETKEY:
//分析指令参数
//最大按键数量
if(CVSInterpreter::AbstractData((char *)((prequestParamList->pParam)[0].pParam), 1, aszTemp, ',') == 0)
pcurrentChannelStatus->keyParam.iKeyCount = atoi(aszTemp);
else
pcurrentChannelStatus->keyParam.iKeyCount = 0;
//结束符
if(CVSInterpreter::AbstractData((char *)((prequestParamList->pParam)[0].pParam), 2, aszTemp, ',') == 0)
strcpy(pcurrentChannelStatus->keyParam.aszTermKey, aszTemp);
else
(pcurrentChannelStatus->keyParam.aszTermKey)[0] = 0;
//等待时间
if(CVSInterpreter::AbstractData((char *)((prequestParamList->pParam)[0].pParam), 3, aszTemp, ',') == 0)
pcurrentChannelStatus->keyParam.iWaitTime = atoi(aszTemp);
else
pcurrentChannelStatus->keyParam.iWaitTime = 0;
//根据等待时间设定超时
if(pcurrentChannelStatus->keyParam.iWaitTime != 0)
{//为对应的模拟窗口设置按键超时
if(IsWindow(psimuPhone[pcurrentChannelStatus->iChannelNo - 1].m_hWnd))
SetTimer(psimuPhone[pcurrentChannelStatus->iChannelNo - 1].m_hWnd, 1, pcurrentChannelStatus->keyParam.iWaitTime * 1000, NULL);
else
{
AfxMessageBox("getkey hwnd not valid");
Sleep(1);
}
}
//显示GETKEY字符串来模拟GETKEY指令
szDisplayMsg = (char *)malloc(strlen((char *)(prequestParamList->pParam)[0].pParam) + 20);
sprintf(szDisplayMsg, "GetingKey %s", (char *)(prequestParamList->pParam)[0].pParam);
DisplayChannelMsg(prequestParamList->iChannelNo, szDisplayMsg);
free(szDisplayMsg);
break;
case SERVICE_LANG:
char aszLangParam[100];
int iLangType;
iLangType = 0;
if(CVSInterpreter::AbstractData((char *)((prequestParamList->pParam)[0].pParam),
1,
aszLangParam,
',') != 0)
{
wprintf_err1("SimuPhone error: LANG 1st param error");
break;
}
if(stricmp(aszLangParam, "mandarin") == 0)
iLangType = 1;
if(stricmp(aszLangParam, "cantonese") == 0)
iLangType = 2;
if(stricmp(aszLangParam, "english") == 0)
iLangType = 3;
if(iLangType == 0)
{
wprintf_err1("SimuPhone error: LANG 1st param error, not mandarin, cantonese, or english");
break;
}
if(CVSInterpreter::AbstractData((char *)((prequestParamList->pParam)[0].pParam),
2,
aszLangParam,
',') != 0)
{
wprintf_err1("SimuPhone error: LANG 2nd param error");
break;
}
if(aszLangParam[strlen(aszLangParam) - 1] != '\\')
sprintf(pcurrentChannelStatus->aszVoiceFilePath, "%s\\", aszLangParam);
else
sprintf(pcurrentChannelStatus->aszVoiceFilePath, "%s", aszLangParam);
pcurrentChannelStatus->iLangType = iLangType;
//显示LANG字符串来模拟LANG指令
szDisplayMsg = (char *)malloc(strlen((char *)(prequestParamList->pParam)[0].pParam) + 20);
sprintf(szDisplayMsg, "Lang %s", (char *)(prequestParamList->pParam)[0].pParam);
DisplayChannelMsg(prequestParamList->iChannelNo, szDisplayMsg);
free(szDisplayMsg);
//填写应答
CServiceDataQueue::CreateParamList(&preplyParamList, 1, pcurrentChannelStatus->iServiceNo, pcurrentChannelStatus->iChannelNo, pcurrentChannelStatus->iISN);
CServiceDataQueue::AddParamListMember_Integer(preplyParamList, 1);
m_replyQueue.AddParamList(preplyParamList);
break;
default:
break;
}
}
}
return 0;
}
int CSimuPhone::Create(int iChannelNo)
{
//非模式对话框
CDialog::Create(IDD_DIALOG_SIMUPHONE);
char aszWindowText[100] = "\0";
sprintf(aszWindowText, "语音通道 %d", iChannelNo);
SetWindowText(aszWindowText);
ShowWindow(SW_SHOW);
m_iChannelNo = iChannelNo;
return 0;
}
void CSimuPhone::OnBitmapHookstate()
{
HANDLE hBitmap;
if(m_bOnHook)
{
hBitmap = LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_OFFHOOK), IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE);
PostThreadMessage(dwSimuDialogicThreadID, WM_USER_DIALIN, m_iChannelNo, 0);
}
else
{
hBitmap = LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_ONHOOK), IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE);
PostThreadMessage(dwSimuDialogicThreadID, WM_USER_ONHOOK, m_iChannelNo, 0);
}
m_bOnHook = !m_bOnHook;
::SendMessage(::GetDlgItem(this->m_hWnd, IDC_BITMAP_HOOKSTATE), STM_SETIMAGE, 0, (LPARAM)hBitmap);
}
void CSimuPhone::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
switch(nIDEvent)
{
case 1: //按键超时事件
PostThreadMessage(dwSimuDialogicThreadID, WM_USER_GETKEYTIMEOUT, m_iChannelNo, 0);
KillTimer(1);
break;
default:
break;
}
CDialog::OnTimer(nIDEvent);
}
BOOL CSimuPhone::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if(pMsg->message == WM_CHAR)
{
if((pMsg->wParam >= 0x30 && pMsg->wParam <= 0x39) //0-9
|| pMsg->wParam == 0x2a //"*"
|| pMsg->wParam == 0x23 //"#"
)
{//是电话按键
PostThreadMessage(dwSimuDialogicThreadID, WM_USER_KEY, m_iChannelNo, (LPARAM)pMsg->wParam);
return FALSE;
}
}
if(pMsg->message == WM_CHAR && pMsg->wParam == 0x2b)
{//"+" 替代"#"
PostThreadMessage(dwSimuDialogicThreadID, WM_USER_KEY, m_iChannelNo, (LPARAM)'#');
return FALSE;
}
if(pMsg->message == WM_CHAR && pMsg->wParam == 0x2e)
{//"."替代"*"
PostThreadMessage(dwSimuDialogicThreadID, WM_USER_KEY, m_iChannelNo, (LPARAM)'*');
return FALSE;
}
if(pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN)
{//ENTER键, 代替"#"
PostThreadMessage(dwSimuDialogicThreadID, WM_USER_KEY, m_iChannelNo, (LPARAM)'#');
return FALSE;
}
return CDialog::PreTranslateMessage(pMsg);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -