www.pudn.com > Fax_Event_Message.rar > Fax_Event_VCDLG.cpp
// Fax_Event_VCDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Fax_Event_VC.h"
#include "Fax_Event_VCDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
public:
void InitLabAbout();
// 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)
virtual BOOL OnInitDialog();
//}}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)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFax_Event_VCDlg dialog
CFax_Event_VCDlg::CFax_Event_VCDlg(CWnd* pParent /*=NULL*/)
: CDialog(CFax_Event_VCDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CFax_Event_VCDlg)
m_strAppendFile = _T("");
m_nAutoOrNot = -1;
m_nFaxSpeed = 1;
m_bRecord = FALSE;
m_strSetId = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_nTabShow = 0;
m_LogFile = NULL;
m_bLog = FALSE;
pFront = NULL;
pRear = NULL;
}
CFax_Event_VCDlg::~CFax_Event_VCDlg()
{
int nCheck;
if(m_LogFile != NULL)
fclose(m_LogFile);
for(int i = 0; i < m_nTotalCh; i++)
{
nCheck = SsmGetChType(i);
if(nCheck == -1)
WriteLog("Fail to call SsmGetChType");
else if(nCheck == FAX_CH || nCheck == SOFTFAX_CH)
GlobalFree(m_FaxCh[i].pffSCT);
}
while(pFront)
{
pRear = pFront->pNext;
free(pFront);
pFront = pRear;
}
}
void CFax_Event_VCDlg::DoDataExchange(CDataExchange* pDX)
{
int nOldFaxSpeed = m_nFaxSpeed;
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CFax_Event_VCDlg)
DDX_Control(pDX, IDC_COMBO_FAX_CH, m_cmbFaxCh);
DDX_Control(pDX, IDC_TAB, m_TabCtrl);
DDX_Control(pDX, IDC_LIST_TRUNK, m_TrkChList);
DDX_Control(pDX, IDC_LIST_FAX, m_FaxChList);
DDX_Control(pDX, IDC_COMBO_TRKCH, m_cmbTrkChNo);
DDX_Control(pDX, IDC_COMBO_TRK_CH, m_cmbTrkCh);
DDX_Control(pDX, IDC_COMBO_FAXCH, m_cmbFaxChNo);
DDX_Text(pDX, IDC_EDIT_APPEND_FILE, m_strAppendFile);
DDX_Radio(pDX, IDC_RADIO_AUTO, m_nAutoOrNot);
DDX_Radio(pDX, IDC_RADIO_SPEED4800, m_nFaxSpeed);
DDX_Check(pDX, IDC_CHECK_RECORD, m_bRecord);
DDX_Text(pDX, IDC_EDIT_SET_ID, m_strSetId);
//}}AFX_DATA_MAP
if(nOldFaxSpeed != m_nFaxSpeed)
{
//set maximum fax speed
if(m_nFaxSpeed == 0) SsmFaxSetMaxSpeed(4800);
else if(m_nFaxSpeed == 1) SsmFaxSetMaxSpeed(9600);
else if(m_nFaxSpeed == 2) SsmFaxSetMaxSpeed(14400);
}
}
BEGIN_MESSAGE_MAP(CFax_Event_VCDlg, CDialog)
//{{AFX_MSG_MAP(CFax_Event_VCDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_RADIO_SPEED4800, OnRadioSpeed4800)
ON_BN_CLICKED(IDC_RADIO_SPEED9600, OnRadioSpeed9600)
ON_BN_CLICKED(IDC_RADIO_SPEED14400, OnRadioSpeed14400)
ON_BN_CLICKED(IDC_BUTTON_APPEND_FILE, OnButtonAppendFile)
ON_BN_CLICKED(IDC_BUTTON_APPEND_SEND, OnButtonAppendSend)
ON_BN_CLICKED(IDC_BUTTON_FAX_STOP, OnButtonFaxStop)
ON_BN_CLICKED(IDC_RADIO_AUTO, OnRadioAuto)
ON_BN_CLICKED(IDC_RADIO_MANUAL, OnRadioManual)
ON_NOTIFY(TCN_SELCHANGE, IDC_TAB, OnSelchangeTab)
ON_WM_SHOWWINDOW()
ON_CBN_SELCHANGE(IDC_COMBO_TRK_CH, OnSelchangeComboTrkCh)
ON_BN_CLICKED(IDC_CHECK_RECORD, OnCheckRecord)
ON_CBN_SELCHANGE(IDC_COMBO_TRKCH, OnSelchangeComboTrkch)
ON_BN_CLICKED(IDC_BUTTON_SET_ID, OnButtonSetId)
ON_EN_CHANGE(IDC_EDIT_SET_ID, OnChangeEditSetId)
ON_WM_DESTROY()
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFax_Event_VCDlg message handlers
BOOL CFax_Event_VCDlg::OnInitDialog()
{
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, FALSE); // Set small icon
// TODO: Add extra initialization here
// set up a vacant queue
pRear = pFront = (PFAX_TASK)malloc(sizeof(FAX_TASK));
pFront->pNext = NULL;
g_dwLanguageConversion = GetThreadLocale();
InitLab();
if(g_dwLanguageConversion == g_dwCHINESE_SIMPLIFIED)
{
TC_ITEM tci;
tci.mask = TCIF_TEXT;
tci.pszText = "接收传真";
m_TabCtrl.InsertItem(0, &tci);
tci.pszText = "发送传真";
m_TabCtrl.InsertItem(1, &tci);
tci.pszText = "增加页眉";
m_TabCtrl.InsertItem(2, &tci);
tci.pszText = "截掉页眉";
m_TabCtrl.InsertItem(3, &tci);
}
else
{
TC_ITEM tci;
tci.mask = TCIF_TEXT;
tci.pszText = "Receive Fax";
m_TabCtrl.InsertItem(0, &tci);
tci.pszText = "Send Fax";
m_TabCtrl.InsertItem(1, &tci);
tci.pszText = "Add Header";
m_TabCtrl.InsertItem(2, &tci);
tci.pszText = "Cut off Header";
m_TabCtrl.InsertItem(3, &tci);
}
m_FirstDlg.Create(IDD_FIRST_DLG, m_TabCtrl.GetActiveWindow());
m_SecondDlg.Create(IDD_SECOND_DLG, m_TabCtrl.GetActiveWindow());
m_ThirdDlg.Create(IDD_THIRD_DLG, m_TabCtrl.GetActiveWindow());
m_FourthDlg.Create(IDD_FOURTH_DLG, m_TabCtrl.GetActiveWindow());
if(!InitCtiBoard())
{
PostQuitMessage(0);
return FALSE;
}
InitFaxChListCtrl(); //initialize fax channel list
UpdateFaxChListCtrl(); //update fax channel list
InitTrunkChListCtrl(); //initialize trunk channel list
UpdateTrunkChListCtrl();//update trunk channel list
//creat log file
char szLogFile[MAX_PATH];
sprintf(szLogFile , "%s\\Fax.Log", m_szCurPath);
m_LogFile = fopen(szLogFile , "a+");
if(m_LogFile == NULL)
{
if(g_dwLanguageConversion == g_dwCHINESE_SIMPLIFIED)
AfxMessageBox(_T("创建log文件时候出错"));
else
AfxMessageBox(_T("Error while creating log file"));
m_bLog = FALSE;
}
else
m_bLog = TRUE;
// set event_message programming mode
EVENT_SET_INFO EventSet;
EventSet.dwWorkMode = EVENT_MESSAGE;
EventSet.lpHandlerParam = this->GetSafeHwnd();
SsmSetEvent(-1, -1, TRUE, &EventSet);
SetTimer(1, 200, NULL);
return TRUE; // return TRUE unless you set the focus to a control
}
void CFax_Event_VCDlg::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 CFax_Event_VCDlg::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 CFax_Event_VCDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CFax_Event_VCDlg::OnRadioSpeed4800()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
}
void CFax_Event_VCDlg::OnRadioSpeed9600()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
}
void CFax_Event_VCDlg::OnRadioSpeed14400()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
}
void CFax_Event_VCDlg::OnButtonAppendFile()
{
// TODO: Add your control notification handler code here
CFileDialog cf(1, NULL, NULL, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, "Fax File(*.tif)|*.tif|Tif File(*.fax)|*.fax|Tiff File(*.tiff)|*.tiff|All File(*.*)|*.*|",NULL);
char szPath[MAX_PATH];
GetCurrentDirectory(MAX_PATH, m_szCurPath);
strcpy(szPath, m_szCurPath);
cf.m_ofn.lpstrInitialDir = szPath;
if(cf.DoModal() == IDOK)
{
strcpy(m_strAppendFile.GetBuffer(MAX_PATH), cf.GetFileName());
UpdateData(FALSE);
m_strAppendFile.ReleaseBuffer(-1);
}
}
// Append:Send
void CFax_Event_VCDlg::OnButtonAppendSend()
{
// TODO: Add your control notification handler code here
char sz[50];
m_cmbFaxChNo.GetLBText(m_cmbFaxChNo.GetCurSel(), sz);
int n = atoi(sz);
strcpy(m_szAppendFile, m_strAppendFile.GetBuffer(m_strAppendFile.GetLength()));
m_strAppendFile.ReleaseBuffer();
if(SsmFaxAppendSend(n, m_szAppendFile) == -1)
WriteLog("Fail to call SsmFaxAppendSend");
}
// stop faxing
void CFax_Event_VCDlg::OnButtonFaxStop()
{
// TODO: Add your control notification handler code here
char sz[50];
m_cmbFaxChNo.GetLBText(m_cmbFaxChNo.GetCurSel(), sz);
int n = atoi(sz);
if(SsmFaxStop(n) == -1)
WriteLog("Fail to call SsmFaxStop");
}
// receive/send fax automatically
void CFax_Event_VCDlg::OnRadioAuto()
{
// TODO: Add your control notification handler code here
char sz[50];
UpdateData(TRUE);
m_cmbTrkChNo.GetLBText(m_cmbTrkChNo.GetCurSel(), sz);
int n = atoi(sz);
m_TrkCh[n].nAutoOrNot = m_nAutoOrNot;
}
// receive/send fax according to the voice
void CFax_Event_VCDlg::OnRadioManual()
{
// TODO: Add your control notification handler code here
char sz[50];
UpdateData(TRUE);
m_cmbTrkChNo.GetLBText(m_cmbTrkChNo.GetCurSel(), sz);
int n = atoi(sz);
m_TrkCh[n].nAutoOrNot = m_nAutoOrNot;
}
// initialize board
BOOL CFax_Event_VCDlg::InitCtiBoard()
{
char szShIndex[MAX_PATH]; // path to ShIndex.ini
char szShConfig[MAX_PATH]; // path to ShConfig.ini
CString str;
int nCheck;
int nChk;
GetCurrentDirectory(MAX_PATH, m_szCurPath);
strcpy(szShIndex, m_szCurPath);
strcpy(szShConfig, m_szCurPath);
strcat(szShIndex, "\\ShIndex.ini");
strcat(szShConfig, "\\ShConfig.ini");
// load configuration file and initialize system
if (SsmStartCti(szShConfig, szShIndex) == -1)
{
// get initialization error message
SsmGetLastErrMsg(m_szErrMsg);
AfxMessageBox(m_szErrMsg, MB_OK);
return FALSE;
}
// Judge if the number of initialized boards is the same as
// that of boards specified in the configuration file
if(SsmGetMaxUsableBoard() != SsmGetMaxCfgBoard())
{
SsmGetLastErrMsg(m_szErrMsg);
AfxMessageBox(m_szErrMsg, MB_OK);
return FALSE;
}
m_nTotalCh = SsmGetMaxCh(); // get max channels of boards
if(m_nTotalCh == -1)
WriteLog("Fail to call SsmGetMaxCh");
m_SecondDlg.m_cmbFaxCh.InsertString(-1, "None");
m_SecondDlg.m_cmbTrkCh.InsertString(-1, "None");
m_cmbTrkCh.InsertString(-1, "None");
m_cmbTrkChNo.InsertString(-1, "None");
m_cmbFaxChNo.InsertString(-1, "None");
m_cmbFaxCh.InsertString(-1, "None");
for(int i = 0; i < m_nTotalCh; i++)
{
m_TrkCh[i].bEnCalled = FALSE;
nCheck = SsmGetChType(i);
if(nCheck == -1)
WriteLog("Fail to call SsmGetChType");
// fax channel or soft fax
else if(nCheck == FAX_CH || nCheck == SOFTFAX_CH)
{
m_FaxCh[i].pffSCT = (PFAX_FILE_SCT)GlobalAlloc(GMEM_FIXED, sizeof(FAX_FILE_SCT)*50);
strcpy(m_FaxCh[i].szChErrMsg, "");
strcpy(m_FaxCh[i].szRcvPathFile, "");
strcpy(m_FaxCh[i].szSendFile, "");
strcpy(m_FaxCh[i].szSendPath, "");
strcpy(m_FaxCh[i].szPage, "");
strcpy(m_FaxCh[i].szGetID, "");
m_FaxCh[i].nStep = FAX_IDLE;
m_FaxCh[i].nAnswered = 0;
m_FaxCh[i].bUseful = FALSE;
m_FaxCh[i].nAllBytes = 0;
m_FaxCh[i].nSendBytes = 0;
m_FaxCh[i].nRcvBytes = 0;
m_FaxCh[i].nCheckEnd = 0;
str.Format("%d", i);
m_SecondDlg.m_cmbFaxCh.InsertString(-1, str);
m_cmbFaxChNo.InsertString(-1, str);
m_cmbFaxCh.InsertString(-1, str);
}
else
{
int nDirection;
// get automatic call progress enable flag and call direction
nCheck = SsmGetAutoCallDirection(i, &nDirection);
if(nCheck == -1)
WriteLog("Fail to call SsmGetAutoCallDirection");
// enable automatic call progress
else if(nCheck == 1)
{
m_TrkCh[i].nCallFlag = -1;
m_TrkCh[i].nStep = TRK_IDLE;
m_TrkCh[i].szChErrMsg[0] = '\0';
m_TrkCh[i].bEnCalled = TRUE;
m_TrkCh[i].nAutoOrNot = 0;
m_TrkCh[i].bRecord = TRUE;
m_TrkCh[i].szDtmf[0] = 0;
m_TrkCh[i].szDtmfChose[0]= 0;
m_TrkCh[i].bUseful = FALSE;
m_TrkCh[i].nIndex = 0;
m_TrkCh[i].nFirstDtmf = 0;
m_TrkCh[i].bLinked = FALSE;
m_TrkCh[i].nTimer = -1;
strcpy(m_TrkCh[i].szCallerId, "");
str.Format("%d", i);
m_SecondDlg.m_cmbTrkCh.InsertString(-1, str);
m_cmbTrkCh.InsertString(-1, str);
m_cmbTrkChNo.InsertString(-1, str);
}
}
}//end of for
m_SecondDlg.m_cmbFaxCh.SetCurSel(0);
m_cmbFaxChNo.SetCurSel(0);
m_cmbFaxCh.SetCurSel(0);
m_cmbTrkCh.SetCurSel(0);
m_cmbTrkChNo.SetCurSel(0);
m_SecondDlg.m_cmbTrkCh.SetCurSel(0);
// load speech data "Step1.voc" and "Step2.voc"
nCheck = SsmLoadIndexData(1, "", 6, "Step1.voc", 0, -1);
nChk = SsmLoadIndexData(2, "", 6, "Step2.voc", 0, -1);
if(nCheck == -1 || nChk == -1)
{
if(g_dwLanguageConversion == g_dwCHINESE_SIMPLIFIED)
AfxMessageBox(_T("加载语音文件失败"));
else
AfxMessageBox(_T("Failed to load speech file"));
if(SsmCloseCti() == -1) //close board drivers
WriteLog("Failed to call SsmCloseCti");
return FALSE;
}
return TRUE;
}
void CFax_Event_VCDlg::OnSelchangeTab(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
int n = m_TabCtrl.GetCurSel();
switch(n)
{
case 0:
m_nTabShow = 0;
m_FirstDlg.ShowWindow(SW_SHOW);
m_SecondDlg.ShowWindow(SW_HIDE);
m_ThirdDlg.ShowWindow(SW_HIDE);
m_FourthDlg.ShowWindow(SW_HIDE);
break;
case 1:
m_nTabShow = 1;
m_FirstDlg.ShowWindow(SW_HIDE);
m_SecondDlg.ShowWindow(SW_SHOW);
m_ThirdDlg.ShowWindow(SW_HIDE);
m_FourthDlg.ShowWindow(SW_HIDE);
break;
case 2:
m_nTabShow = 2;
m_FirstDlg.ShowWindow(SW_HIDE);
m_SecondDlg.ShowWindow(SW_HIDE);
m_ThirdDlg.ShowWindow(SW_SHOW);
m_FourthDlg.ShowWindow(SW_HIDE);
break;
case 3:
m_nTabShow = 3;
m_FirstDlg.ShowWindow(SW_HIDE);
m_SecondDlg.ShowWindow(SW_HIDE);
m_ThirdDlg.ShowWindow(SW_HIDE);
m_FourthDlg.ShowWindow(SW_SHOW);
break;
}
*pResult = 0;
}
void CFax_Event_VCDlg::OnShowWindow(BOOL bShow, UINT nStatus)
{
CDialog::OnShowWindow(bShow, nStatus);
// TODO: Add your message handler code here
CRect tabRect, itemRect,CFaxDlgRect;
int nX, nY, nXc, nYc;
m_TabCtrl.GetClientRect(&tabRect);
m_TabCtrl.GetItemRect(0, &itemRect);
GetClientRect(&CFaxDlgRect);
nX = CFaxDlgRect.right - tabRect.right;
nY = CFaxDlgRect.bottom - (tabRect.bottom - itemRect.bottom + itemRect.top);
nXc = tabRect.right - 15;// - (itemRect.right - itemRect.left); //2006.10.25 pm 12:50
nYc = tabRect.bottom - itemRect.bottom - 12; // pm 3:33
switch (m_nTabShow)
{
case 0:
m_TabCtrl.SetCurSel(0);
m_FirstDlg.SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_SHOWWINDOW);
m_SecondDlg.SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_HIDEWINDOW);
m_ThirdDlg.SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_HIDEWINDOW);
m_FourthDlg.SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_HIDEWINDOW);
break;
case 1:
m_TabCtrl.SetCurSel(1);
m_FirstDlg.SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_HIDEWINDOW);
m_SecondDlg.SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_SHOWWINDOW);
m_ThirdDlg.SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_HIDEWINDOW);
m_FourthDlg.SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_HIDEWINDOW);
break;
case 2:
m_TabCtrl.SetCurSel(2);
m_FirstDlg.SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_HIDEWINDOW);
m_SecondDlg.SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_HIDEWINDOW);
m_ThirdDlg.SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_SHOWWINDOW);
m_FourthDlg.SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_HIDEWINDOW);
break;
case 3:
m_TabCtrl.SetCurSel(3);
m_FirstDlg.SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_HIDEWINDOW);
m_SecondDlg.SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_HIDEWINDOW);
m_ThirdDlg.SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_HIDEWINDOW);
m_FourthDlg.SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_SHOWWINDOW);
break;
}
}
// write log messages
void CFax_Event_VCDlg::WriteLog(char *szLog)
{
if(FALSE == m_bLog)
return;
CString szWriteLog;
SYSTEMTIME st;
GetLocalTime(&st);
szWriteLog.Format("%04d-%02d-%02d %02d:%02d:%02d : %s\n", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, szLog);
fwrite((LPCTSTR)szWriteLog , szWriteLog.GetLength() , 1 , m_LogFile);
fflush(m_LogFile);
}
void CFax_Event_VCDlg::InitFaxChListCtrl()
{
int nCheck;
static int ColumnWidth[10] = {40, 150, 40, 100, 100, 120, 120, 150};
LV_COLUMN lvc;
lvc.mask = LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
if(g_dwLanguageConversion == g_dwCHINESE_SIMPLIFIED)
{
lvc.iSubItem = 0;
lvc.pszText = "通道" ;
lvc.cx = ColumnWidth[0];
m_FaxChList.InsertColumn(0, &lvc);
lvc.iSubItem = 1;
lvc.pszText = "通道状态";
lvc.cx = ColumnWidth[1];
m_FaxChList.InsertColumn(1, &lvc);
lvc.iSubItem = 2;
lvc.pszText = "页数";
lvc.cx = ColumnWidth[2];
m_FaxChList.InsertColumn(2, &lvc);
lvc.iSubItem = 3;
lvc.pszText = "对方ID号";
lvc.cx = ColumnWidth[3];
m_FaxChList.InsertColumn(3, &lvc);
lvc.iSubItem = 4;
lvc.pszText = "当前文件名";
lvc.cx = ColumnWidth[4];
m_FaxChList.InsertColumn(4, &lvc);
lvc.iSubItem = 5;
lvc.pszText = "传真字节数";
lvc.cx = ColumnWidth[5];
m_FaxChList.InsertColumn(5, &lvc);
lvc.iSubItem = 6;
lvc.pszText = "传真执行结果";
lvc.cx = ColumnWidth[6];
m_FaxChList.InsertColumn(6, &lvc);
lvc.iSubItem = 7;
lvc.pszText = "出错信息";
lvc.cx = ColumnWidth[7];
m_FaxChList.InsertColumn(7, &lvc);
}
else
{
lvc.iSubItem = 0;
lvc.pszText = "Ch" ;
lvc.cx = ColumnWidth[0];
m_FaxChList.InsertColumn(0, &lvc);
lvc.iSubItem = 1;
lvc.pszText = "Channel state";
lvc.cx = ColumnWidth[1];
m_FaxChList.InsertColumn(1, &lvc);
lvc.iSubItem = 2;
lvc.pszText = "Page number";
lvc.cx = ColumnWidth[2];
m_FaxChList.InsertColumn(2, &lvc);
lvc.iSubItem = 3;
lvc.pszText = "Remote ID";
lvc.cx = ColumnWidth[3];
m_FaxChList.InsertColumn(3, &lvc);
lvc.iSubItem = 4;
lvc.pszText = "Current file name";
lvc.cx = ColumnWidth[4];
m_FaxChList.InsertColumn(4, &lvc);
lvc.iSubItem = 5;
lvc.pszText = "Number of fax bytes";
lvc.cx = ColumnWidth[5];
m_FaxChList.InsertColumn(5, &lvc);
lvc.iSubItem = 6;
lvc.pszText = "Execution result of faxing";
lvc.cx = ColumnWidth[6];
m_FaxChList.InsertColumn(6, &lvc);
lvc.iSubItem = 7;
lvc.pszText = "Error message";
lvc.cx = ColumnWidth[7];
m_FaxChList.InsertColumn(7, &lvc);
}
char dig[3];
for(int i = 0; i < m_nTotalCh; i++)
{
nCheck = SsmGetChType(i);
if(nCheck == -1)
WriteLog("Fail to call SsmGetChType");
else if(nCheck == FAX_CH || nCheck == SOFTFAX_CH)
{
m_FaxChList.InsertItem(i, _itoa(i, dig, 10));
}
}
}
void CFax_Event_VCDlg::InitTrunkChListCtrl()
{
static int ColumnWidth[10] = {40, 80, 90, 100, 150, 150};
LV_COLUMN lvc;
lvc.mask = LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
if(g_dwLanguageConversion == g_dwCHINESE_SIMPLIFIED)
{
lvc.iSubItem = 0;
lvc.pszText = "通道" ;
lvc.cx = ColumnWidth[0];
m_TrkChList.InsertColumn(0, &lvc);
lvc.iSubItem = 1;
lvc.pszText = "通道状态";
lvc.cx = ColumnWidth[1];
m_TrkChList.InsertColumn(1, &lvc);
lvc.iSubItem = 2;
lvc.pszText = "传真过程状态";
lvc.cx = ColumnWidth[2];
m_TrkChList.InsertColumn(2, &lvc);
lvc.iSubItem = 3;
lvc.pszText = "主叫号码";
lvc.cx = ColumnWidth[3];
m_TrkChList.InsertColumn(3, &lvc);
lvc.iSubItem = 4;
lvc.pszText = "DTMF按键";
lvc.cx = ColumnWidth[4];
m_TrkChList.InsertColumn(4, &lvc);
lvc.iSubItem = 5;
lvc.pszText = "出错信息";
lvc.cx = ColumnWidth[5];
m_TrkChList.InsertColumn(5, &lvc);
}
else
{
lvc.iSubItem = 0;
lvc.pszText = "Ch" ;
lvc.cx = ColumnWidth[0];
m_TrkChList.InsertColumn(0, &lvc);
lvc.iSubItem = 1;
lvc.pszText = "Channel state";
lvc.cx = ColumnWidth[1];
m_TrkChList.InsertColumn(1, &lvc);
lvc.iSubItem = 2;
lvc.pszText = "Faxing state";
lvc.cx = ColumnWidth[2];
m_TrkChList.InsertColumn(2, &lvc);
lvc.iSubItem = 3;
lvc.pszText = "Calling party number";
lvc.cx = ColumnWidth[3];
m_TrkChList.InsertColumn(3, &lvc);
lvc.iSubItem = 4;
lvc.pszText = "DTMF";
lvc.cx = ColumnWidth[4];
m_TrkChList.InsertColumn(4, &lvc);
lvc.iSubItem = 5;
lvc.pszText = "Error messages";
lvc.cx = ColumnWidth[5];
m_TrkChList.InsertColumn(5, &lvc);
}
char dig[3];
for(int i = 0; i < m_nTotalCh; i++)
{
if(m_TrkCh[i].bEnCalled)
{
m_TrkChList.InsertItem(i, _itoa(i, dig, 10));
}
}
}
void CFax_Event_VCDlg::OnSelchangeComboTrkCh()
{
// TODO: Add your control notification handler code here
char sz[50];
m_cmbTrkCh.GetLBText(m_cmbTrkCh.GetCurSel(), sz);
int n = atoi(sz);
m_bRecord = m_TrkCh[n].bRecord;
UpdateData(FALSE);
}
//recording
void CFax_Event_VCDlg::OnCheckRecord()
{
// TODO: Add your control notification handler code here
char sz[50];
UpdateData(TRUE);
m_cmbTrkCh.GetLBText(m_cmbTrkCh.GetCurSel(), sz);
int n = atoi(sz);
m_TrkCh[n].bRecord = m_bRecord;
}
void CFax_Event_VCDlg::UpdateFaxChListCtrl()
{
char szNewStat[250], szOldStat[250];
char szStatemsg[100];
int nIndex = 0;
int nCheck;
for(int i = 0; i < m_nTotalCh; i++)
{
nCheck = SsmGetChType(i); //get channel type
if(nCheck == -1)
WriteLog("Fail to call SsmGetChType");
else if(nCheck != FAX_CH && nCheck != SOFTFAX_CH)
continue;
if(g_dwLanguageConversion == g_dwCHINESE_SIMPLIFIED)
{
switch(m_FaxCh[i].nStep)
{
case FAX_IDLE: strcpy(szNewStat, "空闲"); break;
case FAX_CHECK_END:
if(m_FaxCh[i].nDirection == C_SEND_FAX)
{
strcpy(szNewStat, "正在发送:");
}
else
{
strcpy(szNewStat, "正在接收:");
}
nCheck = SsmFaxGetChStateMsg(i, szStatemsg); //get fax state
if(nCheck == -1)
WriteLog("Fail to call SsmFaxGetChStateMsg");
else if(nCheck == 0)
{
strcat(szNewStat, szStatemsg);
}
break;
}
}
else
{
switch(m_FaxCh[i].nStep)
{
case FAX_IDLE: strcpy(szNewStat, "Idle"); break;
case FAX_CHECK_END:
if(m_FaxCh[i].nDirection == C_SEND_FAX)
{
strcpy(szNewStat, "Sending:");
}
else
{
strcpy(szNewStat, "Receiving:");
}
nCheck = SsmFaxGetChStateMsg(i, szStatemsg); //state of fax channel
if(nCheck == -1)
WriteLog("Fail to call SsmFaxGetChStateMsg");
else if(nCheck == 0)
{
strcat(szNewStat, szStatemsg);
}
break;
}
}
m_FaxChList.GetItemText(nIndex, 1, szOldStat, 29);
if(strcmp(szNewStat, szOldStat) != 0)
{
m_FaxChList.SetItemText(nIndex, 1, szNewStat);
}
// display page number of fax
m_FaxChList.GetItemText(nIndex, 2, szOldStat, 29);
if(strcmp(m_FaxCh[i].szPage, szOldStat) != 0)
{
m_FaxChList.SetItemText(nIndex, 2, m_FaxCh[i].szPage);
}
// display ID of the receiver's fax machine
sprintf(m_FaxCh[i].szGetID, " ");
if(SsmFaxGetID(i, m_FaxCh[i].szGetID) == -1)
WriteLog("Fail to call SsmFaxGetID");
m_FaxChList.GetItemText(nIndex, 3, szOldStat, 50);
if(strcmp(m_FaxCh[i].szGetID, szOldStat) != 0)
{
m_FaxChList.SetItemText(nIndex, 3, m_FaxCh[i].szGetID);
}
if(m_FaxCh[i].nStep != FAX_IDLE)
{
// display fax file name
if(m_FaxCh[i].nDirection == C_SEND_FAX) //send
{
strcpy(szNewStat, m_FaxCh[i].szSendFile);
}
else //receive
strcpy(szNewStat,m_FaxCh[i].szRcvPathFile);
m_FaxChList.GetItemText(nIndex, 4, szOldStat, 250);
if(strcmp(szNewStat, szOldStat) != 0)
{
m_FaxChList.SetItemText(nIndex, 4, szNewStat);
}
// display number of bytes being sent or received
if(m_FaxCh[i].nDirection == C_SEND_FAX)
{
// get total number of bytes to be sent
m_FaxCh[i].nAllBytes = SsmFaxGetAllBytes(i);
// get number of bytes sent
m_FaxCh[i].nSendBytes = SsmFaxGetSendBytes(i);
sprintf(szNewStat, "%d:%d", m_FaxCh[i].nAllBytes, m_FaxCh[i].nSendBytes);
}
else
{
// get number of bytes received
m_FaxCh[i].nRcvBytes = SsmFaxGetRcvBytes(i);
sprintf(szNewStat, "%d", m_FaxCh[i].nRcvBytes);
}
m_FaxChList.GetItemText(nIndex, 5, szOldStat, 60);
if(strcmp(szNewStat, szOldStat) != 0)
{
m_FaxChList.SetItemText(nIndex, 5, szNewStat);
}
}
// display faxing state
m_FaxChList.GetItemText(nIndex, 6, szOldStat, 60);
sprintf(szNewStat, "%d", m_FaxCh[i].nCheckEnd);
if(strcmp(szNewStat, szOldStat) != 0)
{
m_FaxChList.SetItemText(nIndex, 6, szNewStat);
}
// display error message
m_FaxChList.GetItemText(nIndex, 7, szOldStat, 60);
if(strcmp(m_FaxCh[i].szChErrMsg, szOldStat) != 0)
{
m_FaxChList.SetItemText(nIndex, 7, m_FaxCh[i].szChErrMsg);
}
nIndex++;
}
}
void CFax_Event_VCDlg::UpdateTrunkChListCtrl()
{
char szNewStat[250], szOldStat[250];
int nIndex = 0;
for(int i = 0; i < m_nTotalCh; i++)
{
if(!m_TrkCh[i].bEnCalled)
continue;
if(g_dwLanguageConversion == g_dwCHINESE_SIMPLIFIED)
{
switch(SsmGetChState(i)) //get channel state
{
case -1: wsprintf(szNewStat,"-1"); break;
case S_CALL_STANDBY: wsprintf(szNewStat,"空闲"); break;
case S_CALL_PICKUPED: wsprintf(szNewStat,"摘机"); break;
case S_CALL_RINGING: wsprintf(szNewStat,"振铃"); break;
case S_CALL_TALKING: wsprintf(szNewStat,"通话"); break;
case S_CALL_ANALOG_WAITDIALTONE: wsprintf(szNewStat,"WtDT"); break;
case S_CALL_ANALOG_TXPHONUM: wsprintf(szNewStat,"Dl.."); break;
case S_CALL_ANALOG_WAITDIALRESULT: wsprintf(szNewStat,"WtDl"); break;
case S_CALL_PENDING: wsprintf(szNewStat,"挂起"); break;
case S_CALL_OFFLINE: wsprintf(szNewStat,"断线"); break;
case S_CALL_WAIT_REMOTE_PICKUP: wsprintf(szNewStat,"回铃"); break;
case S_CALL_UNAVAILABLE: wsprintf(szNewStat,"不可用"); break;
case S_CALL_LOCKED: wsprintf(szNewStat,"呼出保留"); break;
case S_CALL_LocalBlock: wsprintf(szNewStat,"本地闭塞"); break;
case S_CALL_RemoteBlock: wsprintf(szNewStat,"对端闭塞"); break;
case S_CALL_Ss1InWaitPhoNum : wsprintf(szNewStat,"接收被叫"); break;
case S_CALL_Ss1InWaitFwdStop : wsprintf(szNewStat,"等待前向"); break;
case S_CALL_Ss1InWaitCallerID: wsprintf(szNewStat,"接收主叫"); break;
case S_CALL_Ss1InWaitKD : wsprintf(szNewStat,"接收KD"); break;
case S_CALL_Ss1InWaitKDStop : wsprintf(szNewStat,"等KD停发"); break;
case S_CALL_SS1_SAYIDLE : wsprintf(szNewStat,"发送示闲"); break;
case S_CALL_SS1WaitIdleCAS : wsprintf(szNewStat,"等待示闲"); break;
case S_CALL_SS1PhoNumHoldup : wsprintf(szNewStat,"S_CALL_SS1PhoNumHoldup"); break;
case S_CALL_Ss1InWaitStopSendA3p: wsprintf(szNewStat,"S_CALL_Ss1InWaitStopSendA3p"); break;
case S_CALL_Ss1OutWaitBwdAck : wsprintf(szNewStat,"等待后向占用证实信令”"); break;
case S_CALL_Ss1OutTxPhoNum : wsprintf(szNewStat,"发送被叫"); break;
case S_CALL_Ss1OutWaitAppendPhoNum: wsprintf(szNewStat,"号码不足"); break;
case S_CALL_Ss1OutTxCallerID : wsprintf(szNewStat,"发送主叫"); break;
case S_CALL_Ss1OutWaitKB : wsprintf(szNewStat,"等待KB"); break;
case S_FAX_ROUND : wsprintf(szNewStat,"状态转移过程中"); break;
case S_FAX_PhaseA : wsprintf(szNewStat,"呼叫建立"); break;
case S_FAX_PhaseB : wsprintf(szNewStat,"报文前处理"); break;
case S_FAX_SendDCS : wsprintf(szNewStat,"发送DCS信号"); break;
case S_FAX_Train : wsprintf(szNewStat,"传输训练"); break;
case S_FAX_PhaseC : wsprintf(szNewStat,"报文传输"); break;
case S_FAX_PhaseD : wsprintf(szNewStat,"报文后处理"); break;
case S_FAX_NextPage: wsprintf(szNewStat,"传输下页"); break;
case S_FAX_AllSent : wsprintf(szNewStat,"传输结束"); break;
case S_FAX_PhaseE : wsprintf(szNewStat,"呼叫释放"); break;
case S_FAX_Reset : wsprintf(szNewStat,"复位猫"); break;
case S_FAX_Init : wsprintf(szNewStat,"初始化猫"); break;
case S_FAX_RcvDCS : wsprintf(szNewStat,"接收DCS"); break;
case S_FAX_SendFTT : wsprintf(szNewStat,"发送训练失败信号FTT");break;
case S_FAX_SendCFR : wsprintf(szNewStat,"发送证实信号CFR"); break;
case S_TUP_WaitPcmReset: wsprintf(szNewStat,"电路复原"); break;
case S_TUP_WaitSAM: wsprintf(szNewStat,"等待SAM"); break;
case S_TUP_WaitGSM: wsprintf(szNewStat,"等待GSM"); break;
case S_TUP_WaitCLF: wsprintf(szNewStat,"等待CLF"); break;
case S_TUP_WaitPrefix: wsprintf(szNewStat,"接收局号"); break;
case S_TUP_WaitDialAnswer: wsprintf(szNewStat,"等待应答"); break;
case S_TUP_WaitRLG: wsprintf(szNewStat,"等待RLG"); break;
case S_ISDN_OUT_WAIT_NET_RESPONSE: wsprintf(szNewStat, "等待网络响应"); break;
case S_ISDN_OUT_PLS_APPEND_NO: wsprintf(szNewStat, "等待追加号码"); break;
case S_ISDN_IN_CHK_CALL_IN: wsprintf(szNewStat, "检测到呼入"); break;
case S_ISDN_IN_RCVING_NO: wsprintf(szNewStat,"正在接收号码"); break;
case S_ISDN_IN_WAIT_TALK: wsprintf(szNewStat, "准备进入通话"); break;
case S_ISDN_OUT_WAIT_ALERT: wsprintf(szNewStat, "等待提醒信号"); break;
case S_ISDN_CALL_BEGIN: wsprintf(szNewStat, "呼叫起始"); break;
case S_ISDN_WAIT_HUANGUP: wsprintf(szNewStat, "等待释放"); break;
case S_CALL_SENDRING: wsprintf(szNewStat, "发送振铃"); break;
default: wsprintf(szNewStat,"S=%d",i); break;
}
}
else
{
switch(SsmGetChState(i)) //get channel state
{
case -1: wsprintf(szNewStat,"-1"); break;
case S_CALL_STANDBY: wsprintf(szNewStat,"Idle"); break;
case S_CALL_PICKUPED: wsprintf(szNewStat,"Off-hook"); break;
case S_CALL_RINGING: wsprintf(szNewStat,"Ringing"); break;
case S_CALL_TALKING: wsprintf(szNewStat,"Talking"); break;
case S_CALL_ANALOG_WAITDIALTONE: wsprintf(szNewStat,"WtDT"); break;
case S_CALL_ANALOG_TXPHONUM: wsprintf(szNewStat,"Dl.."); break;
case S_CALL_ANALOG_WAITDIALRESULT: wsprintf(szNewStat,"WtDl"); break;
case S_CALL_PENDING: wsprintf(szNewStat,"Pending"); break;
case S_CALL_OFFLINE: wsprintf(szNewStat,"Off-line"); break;
case S_CALL_WAIT_REMOTE_PICKUP: wsprintf(szNewStat,"Ringback tone"); break;
case S_CALL_UNAVAILABLE: wsprintf(szNewStat,"Unavailable"); break;
case S_CALL_LOCKED: wsprintf(szNewStat,"Outbound call locked"); break;
case S_CALL_LocalBlock: wsprintf(szNewStat,"Local block"); break;
case S_CALL_RemoteBlock: wsprintf(szNewStat,"Remote block"); break;
case S_CALL_Ss1InWaitPhoNum : wsprintf(szNewStat,"Receiving called party number"); break;
case S_CALL_Ss1InWaitFwdStop : wsprintf(szNewStat,"Waiting for forward signal"); break;
case S_CALL_Ss1InWaitCallerID: wsprintf(szNewStat,"Receiving calling party number"); break;
case S_CALL_Ss1InWaitKD : wsprintf(szNewStat,"Receiving KD"); break;
case S_CALL_Ss1InWaitKDStop : wsprintf(szNewStat,"Waiting for KD off"); break;
case S_CALL_SS1_SAYIDLE : wsprintf(szNewStat,"Sending idle signal"); break;
case S_CALL_SS1WaitIdleCAS : wsprintf(szNewStat,"Waiting for the idle signal from the other side"); break;
case S_CALL_SS1PhoNumHoldup : wsprintf(szNewStat,"S_CALL_SS1PhoNumHoldup"); break;
case S_CALL_Ss1InWaitStopSendA3p: wsprintf(szNewStat,"S_CALL_Ss1InWaitStopSendA3p"); break;
case S_CALL_Ss1OutWaitBwdAck : wsprintf(szNewStat,"Waiting for a signal confirming backward occupation"); break;
case S_CALL_Ss1OutTxPhoNum : wsprintf(szNewStat,"Sending called party number"); break;
case S_CALL_Ss1OutWaitAppendPhoNum: wsprintf(szNewStat,"Incomplete number"); break;
case S_CALL_Ss1OutTxCallerID : wsprintf(szNewStat,"Sending calling party number"); break;
case S_CALL_Ss1OutWaitKB : wsprintf(szNewStat,"Waiting for KB"); break;
case S_FAX_ROUND : wsprintf(szNewStat,"In state transition"); break;
case S_FAX_PhaseA : wsprintf(szNewStat,"Call setup"); break;
case S_FAX_PhaseB : wsprintf(szNewStat,"Message preprocessing"); break;
case S_FAX_SendDCS : wsprintf(szNewStat,"Sending DCS"); break;
case S_FAX_Train : wsprintf(szNewStat,"Transmit training"); break;
case S_FAX_PhaseC : wsprintf(szNewStat,"Message transmitting"); break;
case S_FAX_PhaseD : wsprintf(szNewStat,"Message postprocessing"); break;
case S_FAX_NextPage: wsprintf(szNewStat,"Transmitting next page"); break;
case S_FAX_AllSent : wsprintf(szNewStat,"End of transmission"); break;
case S_FAX_PhaseE : wsprintf(szNewStat,"Call release"); break;
case S_FAX_Reset : wsprintf(szNewStat,"Modem reset"); break;
case S_FAX_Init : wsprintf(szNewStat,"Initializing modem"); break;
case S_FAX_RcvDCS : wsprintf(szNewStat,"Receiving DCS"); break;
case S_FAX_SendFTT : wsprintf(szNewStat,"Sending Signal FTT");break;
case S_FAX_SendCFR : wsprintf(szNewStat,"Sending Signal CFR "); break;
case S_TUP_WaitPcmReset: wsprintf(szNewStat,"Circuit reset"); break;
case S_TUP_WaitSAM: wsprintf(szNewStat,"Waiting for SAM"); break;
case S_TUP_WaitGSM: wsprintf(szNewStat,"Waiting for GSM"); break;
case S_TUP_WaitCLF: wsprintf(szNewStat,"Waiting for CLF"); break;
case S_TUP_WaitPrefix: wsprintf(szNewStat,"Receiving prefix"); break;
case S_TUP_WaitDialAnswer: wsprintf(szNewStat,"Waiting for response"); break;
case S_TUP_WaitRLG: wsprintf(szNewStat,"Waiting for RLG"); break;
case S_ISDN_OUT_WAIT_NET_RESPONSE: wsprintf(szNewStat, "Waiting for network response"); break;
case S_ISDN_OUT_PLS_APPEND_NO: wsprintf(szNewStat, "Waiting for number to be appended"); break;
case S_ISDN_IN_CHK_CALL_IN: wsprintf(szNewStat, "Inbound call detected"); break;
case S_ISDN_IN_RCVING_NO: wsprintf(szNewStat,"Receiving number"); break;
case S_ISDN_IN_WAIT_TALK: wsprintf(szNewStat, "Ready to talk"); break;
case S_ISDN_OUT_WAIT_ALERT: wsprintf(szNewStat, "Waiting for alerting signal"); break;
case S_ISDN_CALL_BEGIN: wsprintf(szNewStat, "Start calling"); break;
case S_ISDN_WAIT_HUANGUP: wsprintf(szNewStat, "Waiting for release"); break;
case S_CALL_SENDRING: wsprintf(szNewStat, "Sending ring"); break;
default: wsprintf(szNewStat,"S=%d",i); break;
}
}
m_TrkChList.GetItemText(nIndex, 1, szOldStat, 29) ;
if(strcmp(szNewStat, szOldStat) != 0)
{
m_TrkChList.SetItemText(nIndex, 1, szNewStat);
}
if(g_dwLanguageConversion == g_dwCHINESE_SIMPLIFIED)
{
switch(m_TrkCh[i].nStep)
{
case TRK_IDLE: strcpy(szNewStat, "空闲"); break ;
case TRK_PLAY_VOC1: strcpy(szNewStat, "播放提示语1"); break ;
case TRK_PLAY_VOC2: strcpy(szNewStat, "播放提示语2"); break ;
case TRK_FAXING: strcpy(szNewStat, "通话..."); break ;
case TRK_DIALING: strcpy(szNewStat, "正在拨号"); break ;
default: strcpy(szNewStat, "未定义"); break ;
}
}
else
{
switch(m_TrkCh[i].nStep)
{
case TRK_IDLE: strcpy(szNewStat, "Idle"); break ;
case TRK_PLAY_VOC1: strcpy(szNewStat, "Play voice1"); break ;
case TRK_PLAY_VOC2: strcpy(szNewStat, "Play voice2"); break ;
case TRK_FAXING: strcpy(szNewStat, "Talking..."); break ;
case TRK_DIALING: strcpy(szNewStat, "Dialing..."); break ;
default: strcpy(szNewStat, "Undefined"); break ;
}
}
m_TrkChList.GetItemText(nIndex, 2, szOldStat, 29) ;
if(strcmp(szNewStat, szOldStat) != 0)
{
m_TrkChList.SetItemText(nIndex, 2, szNewStat);
}
// display calling party number
m_TrkChList.GetItemText(nIndex, 3, szOldStat, 29) ;
if(strcmp(m_TrkCh[i].szCallerId, szOldStat) != 0)
{
m_TrkChList.SetItemText(nIndex, 3, m_TrkCh[i].szCallerId);
}
// display DTMF
sprintf(szNewStat, "%s", m_TrkCh[i].szDtmf);
m_TrkChList.GetItemText(nIndex, 4, szOldStat, 29);
if(strcmp(szNewStat, szOldStat) != 0)
{
m_TrkChList.SetItemText(nIndex, 4, szNewStat);
}
//display error messages
m_TrkChList.GetItemText(nIndex, 5, szOldStat, 60);
if(strcmp(m_TrkCh[i].szChErrMsg, szOldStat) != 0)
{
m_TrkChList.SetItemText(nIndex, 5, m_TrkCh[i].szChErrMsg);
}
nIndex++;
}
}
// search for idle fax channel
int CFax_Event_VCDlg::FindAnIdleFaxCh()
{
int nCheck;
for(int i = 0; i < m_nTotalCh; i++)
{
nCheck = SsmGetChType(i);
if(nCheck == -1)
WriteLog("Fail to call SsmGetChType");
else if((nCheck == FAX_CH || nCheck == SOFTFAX_CH)
&& m_FaxCh[i].nStep == FAX_IDLE && m_FaxCh[i].bUseful == FALSE)
return i;
}
return -1;
}
// search for idle trunk channel
int CFax_Event_VCDlg::FindAnIdleTrunkCh()
{
for(int i = 0; i < m_nTotalCh; i++)
{
if(m_TrkCh[i].bEnCalled == TRUE && m_TrkCh[i].bUseful == FALSE
&& m_TrkCh[i].nStep == TRK_IDLE)
return i;
}
return -1;
}
void CFax_Event_VCDlg::OnSelchangeComboTrkch()
{
// TODO: Add your control notification handler code here
char sz[50];
m_cmbTrkChNo.GetLBText(m_cmbTrkChNo.GetCurSel(), sz);
int n = atoi(sz);
m_nAutoOrNot = m_TrkCh[n].nAutoOrNot;
UpdateData(FALSE);
}
// set ID of fax machine
void CFax_Event_VCDlg::OnButtonSetId()
{
// TODO: Add your control notification handler code here
char sz[50];
char str[50];
m_cmbFaxCh.GetLBText(m_cmbFaxCh.GetCurSel(), sz);
int n = atoi(sz);
strcpy(str, m_strSetId.GetBuffer(m_strSetId.GetLength()));
m_strSetId.ReleaseBuffer();
if(SsmFaxSetID(n, str) == -1)
WriteLog("Fail to call SsmFaxSetID");
}
void CFax_Event_VCDlg::OnChangeEditSetId()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
UpdateData(TRUE);
}
void CFax_Event_VCDlg::OnDestroy()
{
CDialog::OnDestroy();
// TODO: Add your message handler code here
// unload speech data loaded in the memory
SsmFreeIndexData(1);
SsmFreeIndexData(2);
//close board drivers
if(SsmCloseCti() == -1)
WriteLog("Failed to call SsmCloseCti");
}
LRESULT CFax_Event_VCDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
// TODO: Add your specialized code here and/or call the base class
int nEventCode; //event ID
int nCh; //channel ID
int nCheck;
if(message > WM_USER)
{
nEventCode = message - WM_USER;
if(nEventCode == E_SYS_TIMEOUT)
{
// identify the channel number according to the flag 'timer'
for(int i = 0; i < m_nTotalCh; i++)
{
if(wParam == (WPARAM)(m_TrkCh[i].nTimer))
{
nCh = i;
break;
}
}
}
else
nCh = wParam;
nCheck = SsmGetChType(nCh);
if(nCheck == -1)
{
WriteLog("Fail to call SsmGetChType");
}
else if(nCheck == FAX_CH || nCheck == SOFTFAX_CH)
{
FaxProc(nEventCode, nCh, lParam);
}
else
{
if(m_TrkCh[nCh].bEnCalled == TRUE)
{
TrunkProc(nEventCode, nCh, lParam);
}
}
UpdateFaxChListCtrl();
UpdateTrunkChListCtrl();
}
return CDialog::WindowProc(message, wParam, lParam);
}
void CFax_Event_VCDlg::TrunkProc(UINT event, WPARAM wParam, LPARAM lParam)
{
int nCh;
int nChannel;
char szRecFile[250];
DWORD dwDtmf;
DWORD dwToneAnalyze;
int i;
char temp[1];
int nNewState;
nCh = wParam;
switch(event)
{
case E_CHG_ChState:
{
nNewState = (int)(lParam & 0xFFFF); //new state
if(nNewState == S_CALL_RINGING) //ring detected
{
if(m_TrkCh[nCh].nStep == TRK_IDLE)
{
m_TrkCh[nCh].bUseful = TRUE;
if(SsmPickup(nCh) == -1) //pick up
WriteLog("Fail to call SsmPickup");
m_TrkCh[nCh].nCallFlag = 0;
sprintf(szRecFile,"channel%d.pcm", nCh);
if(m_TrkCh[nCh].bRecord)
{
if(SsmRecToFile(nCh, szRecFile, -1, 0, -1, -1, 0) == -1) //record
WriteLog("Fail to call SsmRecToFile");
// turn on record mixer
if(SsmSetRecMixer(nCh, 1, 0) == -1)
WriteLog("Fail to call SsmSetRecMixer");
}
if(SsmGetCallerId(nCh, m_TrkCh[nCh].szCallerId) == -1)
WriteLog("Fail to call SsmGetCallerId");
CString str;
m_SecondDlg.m_cmbFaxCh.GetWindowText(str);
if(str == "None")
nChannel = -1;
else
nChannel = atoi(str);
if(nChannel != -1)
{
if(m_FaxCh[nChannel].nStep != FAX_IDLE || m_FaxCh[nChannel].bUseful == TRUE)
{
if((nChannel = FindAnIdleFaxCh()) == -1)
{
// idle fax channel is unavailable
Hangup(nCh);
break;
}
}
}
else
{
if((nChannel = FindAnIdleFaxCh()) == -1)
{
// idle fax channel is unavailable
Hangup(nCh);
break;
}
}
// idle fax channel is available
m_FaxCh[nChannel].bUseful = TRUE;
// manual
if(m_TrkCh[nCh].nAutoOrNot)
{
m_TrkCh[nCh].nStep = TRK_PLAY_VOC1;
m_TrkCh[nCh].nToFaxCh = nChannel;
m_TrkCh[nCh].bLinked = TRUE;
m_FaxCh[nChannel].nTrunkCh = nCh;
// turn on 'DTMF_stop_play' switch
if(SsmSetDtmfStopPlay(nCh, 1) == -1)
WriteLog("Fail to call SsmSetDtmfStopPlay");
if(SsmPlayIndexString(nCh, "1") == -1) //play voice 1
WriteLog("Fail to call SsmPlayIndexString");
if(SsmClearRxDtmfBuf(nCh) == -1) //Clear buffer
WriteLog("Fail to call SsmClearRxDtmfBuf");
// turn on timer
if((m_TrkCh[nCh].nTimer = SsmStartTimer(15000, 1)) == -1)
WriteLog("Fail to call SsmStartTimer");
}
// automatic
else
{
m_TrkCh[nCh].nToFaxCh = nChannel;
m_TrkCh[nCh].bLinked = TRUE;
m_FaxCh[nChannel].nDirection = C_RECEIVE_FAX; //receive
m_FaxCh[nChannel].nTrunkCh = nCh;
m_TrkCh[nCh].nStep = TRK_FAXING;
// set up bus connection between fax and trunk channel
if(SsmTalkWith(nCh, nChannel) == -1)
WriteLog("Fail to call SsmTalkWith");
SendMessage(WM_USER+E_MSG_RCV_FAX, nChannel, nCh);
}
}
}
// remote hungup
else if(nNewState == S_CALL_PENDING)
{
if(m_TrkCh[nCh].nStep == TRK_PLAY_VOC1)
{
// turn off timer
if(SsmStopTimer(m_TrkCh[nCh].nTimer) == -1)
WriteLog("Fail to call SsmStopTimer");
m_TrkCh[nCh].nTimer = -1;
if(SsmStopPlayIndex(nCh) == -1)
WriteLog("Fail to call SsmStopPlayIndex");
}
else if(m_TrkCh[nCh].nStep == TRK_PLAY_VOC2)
{
if(SsmStopPlayIndex(nCh) == -1)
WriteLog("Fail to call SsmStopPlayIndex");
}
else if(m_TrkCh[nCh].nStep == TRK_FAXING)
{
// tear down bus connection between fax and trunk channel
if(SsmStopTalkWith(nCh, m_TrkCh[nCh].nToFaxCh) == -1)
WriteLog("Fail to call SsmStopTalkWith");
SendMessage(WM_USER+E_MSG_OFFLINE, m_TrkCh[nCh].nToFaxCh, NULL);
}
Hangup(nCh);
}
}
break;
// event generated by the driver when DTMF is received
case E_CHG_RcvDTMF:
{
dwDtmf = lParam & 0xFFFF; //the latest DTMF received
*temp = (char)dwDtmf;
m_TrkCh[nCh].szDtmf[m_TrkCh[nCh].nIndex++] = *temp;
if(m_TrkCh[nCh].nIndex >= 99)
{
m_TrkCh[nCh].nIndex = 0;
}
m_TrkCh[nCh].szDtmf[m_TrkCh[nCh].nIndex] = 0;
if((*temp) == '1' || (*temp) == '2')
{
if(m_TrkCh[nCh].nStep == TRK_PLAY_VOC1)
{
m_TrkCh[nCh].nFirstDtmf++;
if(m_TrkCh[nCh].nFirstDtmf == 1)
{
*m_TrkCh[nCh].szDtmfChose = *temp;
if(SsmPlayIndexString(nCh, "2") == -1) //play voice 2
WriteLog("Fail to call SsmPlayIndexString");
if(SsmStopTimer(m_TrkCh[nCh].nTimer) == -1)
WriteLog("Fail to call SsmStopTimer");
m_TrkCh[nCh].nTimer = -1;
m_TrkCh[nCh].nStep = TRK_PLAY_VOC2;
}
}
}
}
break;
// event generated by the driver when the timer is overtime
case E_SYS_TIMEOUT:
{
if(SsmStopTimer(m_TrkCh[nCh].nTimer) == -1)
WriteLog("Fail to call SsmStopTimer");
m_TrkCh[nCh].nTimer = -1;
Hangup(nCh);
}
// event generated by the driver when the result of tone analysis changes
case E_CHG_ToneAnalyze:
{
dwToneAnalyze = lParam & 0xFFFF; //the result of tone analysis
i = dwToneAnalyze;
if(i == 7) //F1 tone
{
if(m_TrkCh[nCh].nStep == TRK_PLAY_VOC1
|| m_TrkCh[nCh].nStep == TRK_PLAY_VOC2)
{
if(m_TrkCh[nCh].nStep == TRK_PLAY_VOC1)
{
if(SsmStopTimer(m_TrkCh[nCh].nTimer) == -1)
WriteLog("Fail to call SsmStopTimer");
m_TrkCh[nCh].nTimer = -1;
}
m_FaxCh[m_TrkCh[nCh].nToFaxCh].nDirection = C_RECEIVE_FAX; //receive
if(SsmStopPlayIndex(nCh) == -1) //stop playing
WriteLog("Fail to call SsmStopPlayIndex");
if(SsmTalkWith(nCh, m_TrkCh[nCh].nToFaxCh) == -1)
WriteLog("Fail to call SsmTalkWith");
m_FaxCh[m_TrkCh[nCh].nToFaxCh].nAnswered = 1;
m_TrkCh[nCh].nStep = TRK_FAXING;
SendMessage(WM_USER+E_MSG_RCV_FAX, m_TrkCh[nCh].nToFaxCh, nCh);
}
else if(m_TrkCh[nCh].nStep == TRK_FAXING)
{
m_FaxCh[m_TrkCh[nCh].nToFaxCh].nAnswered = 1;
}
}
else if(i == 8) //F2 tone
{
if(m_TrkCh[nCh].nStep == TRK_PLAY_VOC1
|| m_TrkCh[nCh].nStep == TRK_PLAY_VOC2)
{
if(m_TrkCh[nCh].nStep == TRK_PLAY_VOC1)
{
if(SsmStopTimer(m_TrkCh[nCh].nTimer) == -1)
WriteLog("Fail to call SsmStopTimer");
m_TrkCh[nCh].nTimer = -1;
}
m_FaxCh[nCh].nDirection = C_SEND_FAX; //send
if(SsmStopPlayIndex(i) == -1) //stop playing
WriteLog("Fail to call SsmStopPlayIndex");
if(SsmTalkWith(i, nCh) == -1)
WriteLog("Fail to call SsmTalkWith");
m_FaxCh[nCh].nAnswered = 1;
m_TrkCh[i].nStep = TRK_FAXING;
SendMessage(WM_USER+E_MSG_SEND_FAX, m_TrkCh[nCh].nToFaxCh, nCh);
}
else if(m_TrkCh[nCh].nStep == TRK_FAXING)
{
m_FaxCh[m_TrkCh[nCh].nToFaxCh].nAnswered = 1;
}
}
}
break;
// event generated by the driver when the playing stops
case E_PROC_PlayEnd:
{
if(m_TrkCh[nCh].nStep == TRK_PLAY_VOC2)
{
if(SsmTalkWith(nCh, m_TrkCh[nCh].nToFaxCh) == -1)
WriteLog("Fail to call SsmTalkWith");
if(*m_TrkCh[nCh].szDtmfChose == '1')
{
m_FaxCh[m_TrkCh[nCh].nToFaxCh].nDirection = C_SEND_FAX; //send
SendMessage(WM_USER+E_MSG_SEND_FAX, m_TrkCh[nCh].nToFaxCh, nCh);
}
else
{
m_FaxCh[m_TrkCh[nCh].nToFaxCh].nDirection = C_RECEIVE_FAX;//receive
SendMessage(WM_USER+E_MSG_RCV_FAX, m_TrkCh[nCh].nToFaxCh, nCh);
}
m_TrkCh[nCh].nStep = TRK_FAXING;
}
}
break;
// event generated by the driver when the fax channel state turns to be idle
case E_MSG_FAX_IDLE:
{
if(SsmStopTalkWith(nCh, m_TrkCh[nCh].nToFaxCh) == -1)
WriteLog("Fail to call SsmStopTalkWith");
Hangup(nCh);
}
break;
// event generated by the driver when the task of auto-dialing progresses
case E_PROC_AutoDial:
{
i = lParam;
if(m_TrkCh[nCh].nStep == TRK_DIALING)
{
switch(i)
{
case DIAL_NO_DIALTONE:
if(g_dwLanguageConversion == g_dwCHINESE_SIMPLIFIED)
strcpy(m_TrkCh[nCh].szChErrMsg, "无拨号音");
else
strcpy(m_TrkCh[nCh].szChErrMsg, "No dial tone");
WriteLog(m_TrkCh[nCh].szChErrMsg);
Hangup(nCh);
break;
case DIAL_BUSYTONE:
if(g_dwLanguageConversion == g_dwCHINESE_SIMPLIFIED)
strcpy(m_TrkCh[nCh].szChErrMsg, "忙音");
else
strcpy(m_TrkCh[nCh].szChErrMsg, "Busy tone");
WriteLog(m_TrkCh[nCh].szChErrMsg);
Hangup(nCh);
break;
case DIAL_ECHO_NOVOICE:
if(g_dwLanguageConversion == g_dwCHINESE_SIMPLIFIED)
strcpy(m_TrkCh[nCh].szChErrMsg, "回铃后无声");
else
strcpy(m_TrkCh[nCh].szChErrMsg, "Silent after ringback tone");
WriteLog(m_TrkCh[nCh].szChErrMsg);
Hangup(nCh);
break;
case DIAL_NOVOICE:
if(g_dwLanguageConversion == g_dwCHINESE_SIMPLIFIED)
strcpy(m_TrkCh[nCh].szChErrMsg, "拨号后无声");
else
strcpy(m_TrkCh[nCh].szChErrMsg, "Silent after dial tone");
WriteLog(m_TrkCh[nCh].szChErrMsg);
Hangup(nCh);
break;
case DIAL_VOICEF1:
if(g_dwLanguageConversion == g_dwCHINESE_SIMPLIFIED)
strcpy(m_TrkCh[nCh].szChErrMsg, "对端传真机摘机,并处于发送状态");
else
strcpy(m_TrkCh[nCh].szChErrMsg, "The receiver's fax machine answers and it is in transmitting process");
WriteLog(m_TrkCh[nCh].szChErrMsg);
Hangup(nCh);
break;
case DIAL_NOANSWER:
if(g_dwLanguageConversion == g_dwCHINESE_SIMPLIFIED)
strcpy(m_TrkCh[nCh].szChErrMsg, "没人接听");
else
strcpy(m_TrkCh[nCh].szChErrMsg, "Nobody answers");
WriteLog(m_TrkCh[nCh].szChErrMsg);
Hangup(nCh);
break;
// called party picked up (voice detected)
case DIAL_VOICE:
if(!m_TrkCh[nCh].nAutoOrNot) //send automatically
{
if(SsmTalkWith(nCh, m_TrkCh[nCh].nToFaxCh) == -1)
WriteLog("Fail to call SsmTalkWith");
m_FaxCh[m_TrkCh[nCh].nToFaxCh].nAnswered = 0;
m_FaxCh[m_TrkCh[nCh].nToFaxCh].nDirection = C_SEND_FAX; //send
m_TrkCh[nCh].nStep = TRK_FAXING;
SendMessage(WM_USER+E_MSG_SEND_FAX, m_TrkCh[nCh].nToFaxCh, nCh);
}
else //manual
{
// turn on 'DTMF_stop_play' switch
if(SsmSetDtmfStopPlay(nCh, 1) == -1)
WriteLog("Fail to call SsmSetDtmfStopPlay");
if(SsmPlayIndexString(nCh, "1") == -1) //play voice 1
WriteLog("Fail to call SsmPlayIndexString");
if(SsmClearRxDtmfBuf(nCh) == -1) //clear DTMF buffer
WriteLog("Fail to call SsmClearRxDtmfBuf");
if((m_TrkCh[nCh].nTimer = SsmStartTimer(15000, 1)) == -1)
WriteLog("Fail to call SsmStartTimer");
m_TrkCh[nCh].nStep = TRK_PLAY_VOC1;
}
break;
//F2 tone detected
case DIAL_VOICEF2:
if(SsmTalkWith(nCh, m_TrkCh[nCh].nToFaxCh) == -1)
WriteLog("Fail to call SsmTalkWith");
m_FaxCh[m_TrkCh[nCh].nToFaxCh].nAnswered = 1;
m_FaxCh[m_TrkCh[nCh].nToFaxCh].nDirection = C_SEND_FAX; //send
m_TrkCh[i].nStep = TRK_FAXING;
SendMessage(WM_USER+E_MSG_SEND_FAX, m_TrkCh[nCh].nToFaxCh, nCh);
break;
case DIAL_INVALID_PHONUM:
if(g_dwLanguageConversion == g_dwCHINESE_SIMPLIFIED)
strcpy(m_TrkCh[nCh].szChErrMsg, "空号");
else
strcpy(m_TrkCh[nCh].szChErrMsg, "empty phone number");
WriteLog(m_TrkCh[nCh].szChErrMsg);
Hangup(nCh);
break;
default :
break;
}//end of switch
}//end of if
}
break;
// event generated by us when faxing task is available
case E_MSG_HAVETASK:
{
if((SsmPickup(nCh)) == -1) //pick up
{
MessageBox("SsmPickup Fail", "Fail", MB_OK);
WriteLog("Fail to call SsmPickup");
}
sprintf(szRecFile, "channel%d.pcm", nCh);
if(m_TrkCh[nCh].bRecord)
{
if(SsmRecToFile(nCh, szRecFile, -1, 0, -1, -1, 0) == -1) //record
WriteLog("Fail to call SsmRecToFile");
// turn on record mixer
if(SsmSetRecMixer(nCh, 1, 0) == -1)
WriteLog("Fail to call SsmSetRecMixer");
}
if(SsmAutoDial(nCh, m_TrkCh[nCh].szCallNo) == -1) //auto-dialing failed
{
SsmGetLastErrMsg(m_TrkCh[nCh].szChErrMsg);
WriteLog(m_TrkCh[nCh].szChErrMsg);
Hangup(nCh);
}
else
{
m_TrkCh[nCh].nCallFlag = 1;
m_TrkCh[nCh].nStep = TRK_DIALING;
}
}
break;
}//end of switch of event
}
void CFax_Event_VCDlg::FaxProc(UINT event, WPARAM wParam, LPARAM lParam)
{
int i; //Channel ID
int m, n;
CString strTemp, str;
i = wParam;
switch(event)
{
// event indicating the start of faxing
case E_MSG_SEND_FAX:
{
if(m_FaxCh[i].nStep == FAX_IDLE)
{
if(m_TrkCh[m_FaxCh[i].nTrunkCh].nCallFlag == 0) //inbound call
{
m_FaxCh[i].nHowFile = m_SecondDlg.m_nHowFile;
if(m_FaxCh[i].nHowFile == 0) //single file
{
strcpy(m_FaxCh[i].szSendFile, m_SecondDlg.m_strSendFile.GetBuffer(m_SecondDlg.m_strSendFile.GetLength()));
m_SecondDlg.m_strSendFile.ReleaseBuffer();
m_FaxCh[i].nStartPage = m_SecondDlg.nStartPage;
m_FaxCh[i].nEndPage = m_SecondDlg.nEndPage;
}
else if(m_FaxCh[i].nHowFile == 1) //multi-file
{
strcpy(m_FaxCh[i].szSendPath, m_SecondDlg.m_strSendPath.GetBuffer(m_SecondDlg.m_strSendPath.GetLength()));
m_SecondDlg.m_strSendPath.ReleaseBuffer();
m_FaxCh[i].nSCTNumber = m_SecondDlg.nSCTNumber;
for(int jj = 0; jj < m_FaxCh[i].nSCTNumber; jj++)
{
*((m_FaxCh[i].pffSCT)+jj) = m_SecondDlg.ffSCT[jj];
}
}
else if(m_FaxCh[i].nHowFile == 2) //multi-file(page number is optional)
{
m_FaxCh[i].nSCTNumber = m_SecondDlg.nSCTNumber;
for(int jj = 0; jj < m_FaxCh[i].nSCTNumber; jj++)
{
*((m_FaxCh[i].pffSCT)+jj) = m_SecondDlg.ffSCT[jj];
}
}
} //end of nCallFlag
m_TrkCh[m_FaxCh[i].nTrunkCh].nCallFlag = -1;
if(m_FaxCh[i].nHowFile == 0) //single file
{
// page number is not set
if(m_FaxCh[i].nStartPage == 1 && m_FaxCh[i].nEndPage == -1)
{
if(SsmFaxStartSend(i, m_FaxCh[i].szSendFile) == -1) //send
{
SsmGetLastErrMsg(m_FaxCh[i].szChErrMsg);
WriteLog(m_FaxCh[i].szChErrMsg);
m_FaxCh[i].nStep = FAX_IDLE;
strcpy(m_FaxCh[i].szRcvPathFile, "");
strcpy(m_FaxCh[i].szSendFile, "");
strcpy(m_FaxCh[i].szSendPath, "");
SendMessage(WM_USER+E_MSG_FAX_IDLE, m_FaxCh[i].nTrunkCh, i);
}
else
{
m_FaxCh[i].nStep = FAX_CHECK_END;
}
}
// page number is set
else
{
if(SsmFaxStartSend(i, m_FaxCh[i].szSendFile) == -1) //send
{
SsmGetLastErrMsg(m_FaxCh[i].szChErrMsg);
m_FaxCh[i].nStep = FAX_IDLE;
strcpy(m_FaxCh[i].szRcvPathFile, "");
strcpy(m_FaxCh[i].szSendFile, "");
strcpy(m_FaxCh[i].szSendPath, "");
SendMessage(WM_USER+E_MSG_FAX_IDLE, m_FaxCh[i].nTrunkCh, i);
}
else
m_FaxCh[i].nStep = FAX_CHECK_END;
}
}
else if(m_FaxCh[i].nHowFile == 1) //multi-file
{
for(int jj = 0; jj < m_FaxCh[i].nSCTNumber; jj++)
{
if(m_FaxCh[i].szSendFile[0] != 0)
strcat(m_FaxCh[i].szSendFile, ";");
strcat(m_FaxCh[i].szSendFile, ((m_FaxCh[i].pffSCT)+jj)->szFileName);
}
if(SsmFaxSendMultiFile(i, m_FaxCh[i].szSendPath, m_FaxCh[i].szSendFile) == -1)
{
SsmGetLastErrMsg(m_FaxCh[i].szChErrMsg);
m_FaxCh[i].nStep = FAX_IDLE;
strcpy(m_FaxCh[i].szRcvPathFile, "");
strcpy(m_FaxCh[i].szSendFile, "");
strcpy(m_FaxCh[i].szSendPath, "");
SendMessage(WM_USER+E_MSG_FAX_IDLE, m_FaxCh[i].nTrunkCh, i);
}
else
m_FaxCh[i].nStep = FAX_CHECK_END;
}
else if(m_FaxCh[i].nHowFile == 2) //multi-file(page number is optional)
{
for(int jj = 0; jj < m_FaxCh[i].nSCTNumber; jj++)
{
if(m_FaxCh[i].szSendFile[0] != 0)
strcat(m_FaxCh[i].szSendFile, ";");
strcat(m_FaxCh[i].szSendFile, ((m_FaxCh[i].pffSCT)+jj)->szFileName);
}
PFAX_FILE_SCT pSCT;
pSCT = m_FaxCh[i].pffSCT;
if(SsmFaxSendMultiFileEx(i, pSCT, m_FaxCh[i].nSCTNumber) == -1) //send
{
SsmGetLastErrMsg(m_FaxCh[i].szChErrMsg);
WriteLog(m_FaxCh[i].szChErrMsg);
m_FaxCh[i].nStep = FAX_IDLE;
strcpy(m_FaxCh[i].szRcvPathFile, "");
strcpy(m_FaxCh[i].szSendFile, "");
strcpy(m_FaxCh[i].szSendPath, "");
SendMessage(WM_USER+E_MSG_FAX_IDLE, m_FaxCh[i].nTrunkCh, i);
}
else
m_FaxCh[i].nStep = FAX_CHECK_END;
}
}
}
break;
case E_MSG_RCV_FAX:
{
if(m_FaxCh[i].nStep == FAX_IDLE)
{
strcpy(m_FaxCh[i].szRcvPathFile, m_FirstDlg.m_strRcvPath.GetBuffer(m_FirstDlg.m_strRcvPath.GetLength()));
m_FirstDlg.m_strRcvPath.ReleaseBuffer();
strcat(m_FaxCh[i].szRcvPathFile, "\\");
// fax file name + channel ID
strTemp.Format("%s", m_FirstDlg.m_strRcvFile);
strTemp.TrimRight();
str = strTemp.Right(5);
m = str.GetLength();
n = str.Find('.');
str.Format("%d", i);
n = strTemp.GetLength() - m + n;
for(int jj = 0; jj < str.GetLength(); jj++)
{
strTemp.Insert(n + jj, str[jj]);
}
strcat(m_FaxCh[i].szRcvPathFile, strTemp.GetBuffer(strTemp.GetLength()));
strTemp.ReleaseBuffer();
if(SsmFaxStartReceive(i, m_FaxCh[i].szRcvPathFile) == -1) //receive
{
SsmGetLastErrMsg(m_FaxCh[i].szChErrMsg);
WriteLog(m_FaxCh[i].szChErrMsg);
m_FaxCh[i].nStep = FAX_IDLE;
strcpy(m_FaxCh[i].szRcvPathFile, "");
strcpy(m_FaxCh[i].szSendFile, "");
strcpy(m_FaxCh[i].szSendPath, "");
SendMessage(WM_USER+E_MSG_FAX_IDLE, m_FaxCh[i].nTrunkCh, i);
}
else
{
m_FaxCh[i].nStep = FAX_CHECK_END;
}
}
}
break;
case E_PROC_FaxEnd:
{
if(m_FaxCh[i].nStep == FAX_CHECK_END)
{
m_FaxCh[i].nCheckEnd = lParam;
switch(m_FaxCh[i].nCheckEnd)
{
case 1 :
if(g_dwLanguageConversion == g_dwCHINESE_SIMPLIFIED)
WriteLog("传真成功");
else
WriteLog("Succeed in faxing");
m_FaxCh[i].nStep = FAX_IDLE;
strcpy(m_FaxCh[i].szRcvPathFile, "");
strcpy(m_FaxCh[i].szSendFile, "");
strcpy(m_FaxCh[i].szSendPath, "");
SendMessage(WM_USER+E_MSG_FAX_IDLE, m_FaxCh[i].nTrunkCh, i);
break;
case 2 :
if(SsmFaxGetPages(i) > 0 || SsmFaxGetSendBytes(i) > 0)
{
if(g_dwLanguageConversion == g_dwCHINESE_SIMPLIFIED)
WriteLog("传真失败 : 传真在页面阶段失败");
else
WriteLog("Failed to fax : failure in page phase");
}
else
{
if(m_FaxCh[i].nAnswered == 1)
{
if(g_dwLanguageConversion == g_dwCHINESE_SIMPLIFIED)
WriteLog("传真失败 : 传真在握手阶段失败");
else
WriteLog("Failed to fax : failure in handshake phase");
}
else if(m_FaxCh[i].nAnswered == 0)
{
if(g_dwLanguageConversion == g_dwCHINESE_SIMPLIFIED)
WriteLog("传真失败 : 对方未按\"开始\"键,发送超时");
else
WriteLog("Failed to fax : the receiver doesn't press key 'start' or time out when waiting for key 'start'");
}
}
m_FaxCh[i].nStep = FAX_IDLE;
strcpy(m_FaxCh[i].szRcvPathFile, "");
strcpy(m_FaxCh[i].szSendFile, "");
strcpy(m_FaxCh[i].szSendPath, "");
SendMessage(WM_USER+E_MSG_FAX_IDLE, m_FaxCh[i].nTrunkCh, i);
break;
}//end of switch
}
}
break;
case E_CHG_FaxPages:
{
_itoa(lParam, m_FaxCh[i].szPage, 10);
}
break;
// event indicating the hangup of the remote fax machine
case E_MSG_OFFLINE:
{
if(m_FaxCh[i].nStep == FAX_CHECK_END)
{
if(SsmFaxStop(i) == -1)
WriteLog("Fail to call SsmFaxStop");
m_FaxCh[i].nStep = FAX_IDLE;
strcpy(m_FaxCh[i].szRcvPathFile, "");
strcpy(m_FaxCh[i].szSendFile, "");
strcpy(m_FaxCh[i].szSendPath, "");
}
}
break;
}//end of switch of event
}
void CFax_Event_VCDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
// scan task queue
ScanTaskQueue();
CDialog::OnTimer(nIDEvent);
}
void CFax_Event_VCDlg::Hangup(int nChannel)
{
int nCh = nChannel;
if(SsmHangup(nCh) == -1) //remote hangup
WriteLog("Fail to call SsmHangup");
if(SsmStopRecToFile(nCh) == -1) //stop recording
WriteLog("Fail to call SsmStopRecToFile");
m_TrkCh[nCh].nStep = TRK_IDLE;
strcpy(m_TrkCh[nCh].szCallerId, "");
if(m_TrkCh[nCh].bLinked)
{
m_FaxCh[m_TrkCh[nCh].nToFaxCh].bUseful = FALSE; //the channel is useful
m_TrkCh[nCh].bLinked = FALSE;
}
m_TrkCh[nCh].bUseful = FALSE; //useful
m_TrkCh[nCh].nFirstDtmf = 0;
m_TrkCh[nCh].nIndex = 0;
m_TrkCh[nCh].szDtmf[0] = 0;
m_TrkCh[nCh].szDtmfChose[0] = 0;
}
void CFax_Event_VCDlg::ScanTaskQueue()
{
int nTrunkCh;
int nFaxCh;
FAX_TASK *p = pFront;
while(p->pNext)
{
// faxing task available
nTrunkCh = p->pNext->nTrkCh;
if(nTrunkCh == -1 && (nTrunkCh = FindAnIdleTrunkCh()) != -1
|| nTrunkCh != -1 && m_TrkCh[nTrunkCh].bUseful == FALSE && m_TrkCh[nTrunkCh].nStep == TRK_IDLE)
{
nFaxCh = p->pNext->nFaxCh;
// scan next task if idle fax channel is unavailable
if((nFaxCh == -1) && ((nFaxCh = FindAnIdleFaxCh()) == -1)
|| (nFaxCh != -1) && ((m_FaxCh[nFaxCh].nStep != FAX_IDLE) || (m_FaxCh[nFaxCh].bUseful == TRUE)))
{
p = p->pNext;
continue;
}
// begin the task if idle fax channel is available
else
{
m_TrkCh[nTrunkCh].nLineState = SsmGetChState(nTrunkCh);
if(m_TrkCh[nTrunkCh].nLineState == -1)
WriteLog("Fail to call SsmGetChState");
else if(m_TrkCh[nTrunkCh].nLineState != S_CALL_STANDBY)
{
p = p->pNext;
continue;
}
m_TrkCh[nTrunkCh].bLinked = TRUE;
m_TrkCh[nTrunkCh].bUseful = TRUE;
m_FaxCh[nFaxCh].bUseful = TRUE;
m_TrkCh[nTrunkCh].nToFaxCh = nFaxCh;
m_FaxCh[nFaxCh].nTrunkCh = nTrunkCh;
m_FaxCh[nFaxCh].nHowFile = p->pNext->nHowFile;
strcpy(m_TrkCh[nTrunkCh].szCallNo, p->pNext->szCallNo);
if(m_FaxCh[nFaxCh].nHowFile == 0) //single file
{
m_FaxCh[nFaxCh].nStartPage = p->pNext->nStartPage;
m_FaxCh[nFaxCh].nEndPage = p->pNext->nEndPage;
strcpy(m_FaxCh[nFaxCh].szSendFile, p->pNext->szSendFile);
}
if(m_FaxCh[nFaxCh].nHowFile == 1) //multi-file
{
strcpy(m_FaxCh[nFaxCh].szSendPath, p->pNext->szSendPath);
m_FaxCh[nFaxCh].nSCTNumber = p->pNext->nSCTNumber;
for(int jj = 0; jj < m_FaxCh[nFaxCh].nSCTNumber; jj++)
{
*((m_FaxCh[nFaxCh].pffSCT)+jj) = p->pNext->ffSCT[jj];
}
}
if(m_FaxCh[nFaxCh].nHowFile == 2) //multi-file(page number is optional)
{
m_FaxCh[nFaxCh].nSCTNumber = p->pNext->nSCTNumber;
for(int jj = 0; jj < m_FaxCh[nFaxCh].nSCTNumber; jj++)
{
*((m_FaxCh[nFaxCh].pffSCT)+jj) = p->pNext->ffSCT[jj];
}
}
SendMessage(WM_USER+E_MSG_HAVETASK, nTrunkCh, nFaxCh);
FAX_TASK *q = p->pNext;
p->pNext = q->pNext;
if(pRear == q)
pRear = p;
free(q);
break;
}
}
else
p = p->pNext;
}
}
void CFax_Event_VCDlg::InitLab()
{
if(g_dwLanguageConversion == g_dwCHINESE_SIMPLIFIED)
{
//Chinese
strLab[0].Format("传真速率");
strLab[1].Format("传真追加与终止");
strLab[2].Format("传真通道");
strLab[3].Format("浏览");
strLab[4].Format("收发传真方式");
strLab[5].Format("中继通道");
strLab[6].Format("自动收发传真");
strLab[7].Format("提示收发传真");
strLab[8].Format("录音设置");
strLab[9].Format("中继通道");
strLab[10].Format("录音");
strLab[11].Format("传真ID设置");
strLab[12].Format("传真通道");
strLab[13].Format("设置ID号");
}
else
{ //English
strLab[0].Format("Faxing speed");
strLab[1].Format("Fax appending/stopping");
strLab[2].Format("FaxCh ID");
strLab[3].Format("Browse");
strLab[4].Format("Fax receiving/transmitting mode");
strLab[5].Format("TrunkCh ID");
strLab[6].Format("Automatic");
strLab[7].Format("Manual");
strLab[8].Format("Recording Setting");
strLab[9].Format("TrunkCh ID");
strLab[10].Format("Record");
strLab[11].Format("Fax ID Setting");
strLab[12].Format("FaxCh ID");
strLab[13].Format("ID setting");
}
SetWinTextLab(this, IDC_STATIC_FAXSPEED, strLab[0]);
SetWinTextLab(this, IDC_STATIC_APPEND_STOP, strLab[1]);
SetWinTextLab(this, IDC_STATIC_FAXCH, strLab[2]);
SetWinTextLab(this, IDC_BUTTON_APPEND_FILE, strLab[3]);
SetWinTextLab(this, IDC_STATIC_FAX_MODE, strLab[4]);
SetWinTextLab(this, IDC_STATIC_TRUNKCH, strLab[5]);
SetWinTextLab(this, IDC_RADIO_AUTO, strLab[6]);
SetWinTextLab(this, IDC_RADIO_MANUAL, strLab[7]);
SetWinTextLab(this, IDC_STATIC_RECORD, strLab[8]);
SetWinTextLab(this, IDC_STATIC_TRUNKCH_ID, strLab[9]);
SetWinTextLab(this, IDC_CHECK_RECORD, strLab[10]);
SetWinTextLab(this, IDC_STATIC_FAX_ID, strLab[11]);
SetWinTextLab(this, IDC_STATIC_FAXCH_ID, strLab[12]);
SetWinTextLab(this, IDC_STATIC_SETID, strLab[13]);
}
BOOL CAboutDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
InitLabAbout();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CAboutDlg::InitLabAbout()
{
CString strLabAbout[10];
if(g_dwLanguageConversion == g_dwCHINESE_SIMPLIFIED)
{
//Chinese
strLabAbout[0].Format("Fax_Event_VC 2.0 版");
strLabAbout[1].Format("版权所有 (C) 2006");
strLabAbout[2].Format("确定");
}
else
{
//English
strLabAbout[0].Format("Fax_Event_VC V2.0");
strLabAbout[1].Format("Copyright (c) 2006 All right reserved");
strLabAbout[2].Format("OK");
}
SetWinTextLab(this, IDC_STATIC_EDITION, strLabAbout[0]);
SetWinTextLab(this, IDC_STATIC_COPYRIGHT, strLabAbout[1]);
SetWinTextLab(this, IDOK, strLabAbout[2]);
}