📄 form1.cs
字号:
ListViewItem.ListViewSubItem lvsi;
nTemp = SsmGetChType(i);
if(nTemp == -1)
MessageBox.Show("Fail to call SsmGetChType");
else if(nTemp == 3)
{
lvi = new ListViewItem();
lvi.Text = i.ToString();
switch(ChState[i].WorkState)
{
case (int)TRUNK_STATE.TRK_IDLE:
str = "Idle";
break;
case (int)TRUNK_STATE.TRK_PICKUP:
str = "Off-hook";
break;
case (int)TRUNK_STATE.TRK_RINGING:
str = "Ringing";
break;
case (int)TRUNK_STATE.TRK_RECORD:
str = "Recording";
break;
case (int)TRUNK_STATE.TRK_OUTLINE:
str = "Off-line";
break;
}
lvsi = new ListViewItem.ListViewSubItem();
lvsi.Text = str;
lvi.SubItems.Add(lvsi);
str = "";
switch(ChState[i].ConState)
{
case (int)Control.DTMF_CTRL:
str = "Code-control";
break;
case (int)Control.VOICE_CTRL:
str = "Voice-control";
break;
case (int)Control.VOLTAGE_CTRL:
str = "Voltage-control";
break;
}
lvsi = new ListViewItem.ListViewSubItem();
lvsi.Text = str;
lvi.SubItems.Add(lvsi);
lvsi = new ListViewItem.ListViewSubItem();
if(ChState[i].ConState == (int)Control.DTMF_CTRL)
lvsi.Text = "*";
else
lvsi.Text = "";
lvi.SubItems.Add(lvsi);
lvsi = new ListViewItem.ListViewSubItem();
str = "";
str = new string(ChState[i].szDTMF);
lvsi.Text = str;
lvi.SubItems.Add(lvsi);
lvsi = new ListViewItem.ListViewSubItem();
lvsi.Text = ChState[i].szCallerId;
lvi.SubItems.Add(lvsi);
this.listView1.Items.Add(lvi);
}
}
}
[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")]
protected override void WndProc(ref Message m)
{
int nCh; //channel ID
int nNewState; //new state
string str; //recording file
char[] temp = new char[1]; //latest DTMF character
ushort wDtmf;
byte[] szCallerId = new byte[20];
// Listen for operating system messages.
int nMsg = m.Msg - WM_USER;
if((nMsg > 0) && (ChState[(int)m.WParam].WorkState != -1))
{
switch (nMsg)
{
case E_SYS_BargeIn: //BargeIn event is detected
{
nCh = (int)m.WParam; //wParam: number of channel output the event
if(ChState[nCh].bIgnoreLineVoltage)
{
if(ChState[nCh].WorkState == (int)TRUNK_STATE.TRK_IDLE)
{
if((ChState[nCh].ConState == (int)Control.VOICE_CTRL) && ((int)m.LParam == 1))
{
//recording file name + channel Id + time
str = "Test" + nCh.ToString() + "." + System.DateTime.Now.Hour.ToString() + "="
+ System.DateTime.Now.Minute.ToString() + "=" + System.DateTime.Now.Second.ToString()
+ ".wav";
if(SsmRecToFile(nCh, str, -1, 0, -1, 8000, 0) == -1) //start recording
{
MessageBox.Show("Fail to call SsmRecToFile");
}
ChState[nCh].WorkState = (int)TRUNK_STATE.TRK_RECORD;
}
}
}
else
{
if(ChState[nCh].WorkState == (int)TRUNK_STATE.TRK_PICKUP)
{
if((ChState[nCh].ConState == (int)Control.VOICE_CTRL) && ((int)m.LParam == 1))
{
//recording file name + channel Id + time
str = "Test" + nCh.ToString() + "." + System.DateTime.Now.Hour.ToString() + "="
+ System.DateTime.Now.Minute.ToString() + "=" + System.DateTime.Now.Second.ToString()
+ ".wav";
if(SsmRecToFile(nCh, str, -1, 0, -1, 8000, 0) == -1) //start recording
{
MessageBox.Show("Fail to call SsmRecToFile");
}
ChState[nCh].WorkState = (int)TRUNK_STATE.TRK_RECORD;
}
}
}
}
break;
case E_SYS_NoSound:
{
nCh = (int)m.WParam; //wParam: number of channel output the event
if(ChState[nCh].bIgnoreLineVoltage)
{
if(ChState[nCh].WorkState == (int)TRUNK_STATE.TRK_RECORD)
{
if(ChState[nCh].ConState == (int)Control.VOICE_CTRL)
{
if(SsmStopRecToFile(nCh) == -1) //stop recording
{
MessageBox.Show("Fail to call function SsmStopRecToFile()");
}
ChState[nCh].WorkState = (int)TRUNK_STATE.TRK_IDLE;
}
}
}
}
break;
case E_CHG_ChState: //channel state change event
{
nCh = (int)m.WParam; //wParam: number of channel output the event
nNewState = (int)((int)m.LParam & 0xFFFF); //lParam:uint(HWORD wOldState---old state,LWORD wNewState---new state)
if(nNewState == (int)TRUNK_STATUS.S_CALL_STANDBY)
{
ChState[nCh].szDTMF[0] = '\0'; //clear DTMF buffer
ChState[nCh].szCallerId = "";
ChState[nCh].nIndex = 0;
ChState[nCh].WorkState = (int)TRUNK_STATE.TRK_IDLE;
if(SsmStopRecToFile(nCh) == -1) //stop recording
{
MessageBox.Show("Fail to call SsmStopRecToFile");
}
if(SsmClearRxDtmfBuf(nCh) == -1) //clear dtmf receive buffer
{
MessageBox.Show("Fail to call SsmClearRxDtmfBuf");
}
}
else if(nNewState == (int)TRUNK_STATUS.S_CALL_PICKUPED)
{
ChState[nCh].WorkState = (int)TRUNK_STATE.TRK_PICKUP;
if(SsmGetCallerId(nCh, szCallerId) == -1)
MessageBox.Show("Fail to call SsmGetCallerId");
ChState[nCh].szCallerId += '\0';
ChState[nCh].szCallerId = System.Text.Encoding.ASCII.GetString(szCallerId);
}
else if(nNewState == (int)TRUNK_STATUS.S_CALL_OFFLINE)
{
if(SsmStopRecToFile(nCh) == -1) //stop recording
{
MessageBox.Show("Fail to call SsmStopRecToFile");
}
ChState[nCh].WorkState = (int)TRUNK_STATE.TRK_OUTLINE;
if(SsmClearRxDtmfBuf(nCh) == -1) //cleare DTMF receive buffer
{
MessageBox.Show("Fail to call SsmClearRxDtmfBuf");
}
ChState[nCh].szDTMF[0] = '\0'; //clear DTMF buffer
ChState[nCh].nIndex = 0;
}
switch(ChState[nCh].WorkState)
{
/* case (int)TRUNK_STATE.TRK_IDLE:
{
if(nNewState == (int)TRUNK_STATUS.S_CALL_RINGING)
{
ChState[nCh].WorkState = (int)TRUNK_STATE.TRK_RINGING;
//receive CallerId
if(SsmGetCallerId(nCh, szCallerId) == -1)
MessageBox.Show("Fail to call SsmGetCallerId");
ChState[nCh].szCallerId += '\0';
ChState[nCh].szCallerId = System.Text.Encoding.ASCII.GetString(szCallerId);
}
}
break;
*/
case (int)TRUNK_STATE.TRK_PICKUP:
{
if(ChState[nCh].ConState == (int)Control.VOLTAGE_CTRL)
{
if(nNewState == (int)TRUNK_STATUS.S_CALL_PICKUPED)
{
//recording file name + channel Id + time
str = "Test" + nCh.ToString() + "." + System.DateTime.Now.Hour.ToString() + "="
+ System.DateTime.Now.Minute.ToString() + "=" + System.DateTime.Now.Second.ToString()
+ ".wav";
if(SsmRecToFile(nCh, str, -1, 0, -1, 8000, 0) == -1) //start recording
{
MessageBox.Show("Failed to call SsmRecToFile");
}
ChState[nCh].WorkState = (int)TRUNK_STATE.TRK_RECORD;
}
}
}
break;
case (int)TRUNK_STATE.TRK_OUTLINE:
{
nCh = (int)m.WParam; //number of channel output the event
if(nNewState == (int)TRUNK_STATUS.S_CALL_STANDBY)
{
ChState[nCh].WorkState = (int)TRUNK_STATE.TRK_IDLE;
}
}
break;
default:
break;
} //end of workstate
}
break;
case E_CHG_RcvDTMF: //DTMF receive event
{
nCh = (int)m.WParam; //number of channel output the event
wDtmf = (ushort)((int)m.LParam & 0xFFFF); //uint(HWORD wDtmfLen:length of DTMFs received,LWORD wNewChar--new DTMF character received)
temp[0] = (char)wDtmf;
//store DTMF received into buffer
ChState[nCh].szDTMF[ChState[nCh].nIndex++] = temp[0];
if(ChState[nCh].nIndex >= 99)
{
ChState[nCh].nIndex = 0;
}
ChState[nCh].szDTMF[ChState[nCh].nIndex] = '\0';
if(ChState[nCh].WorkState == (int)TRUNK_STATE.TRK_PICKUP)
{
if(ChState[nCh].ConState == (int)Control.DTMF_CTRL)
{
if((temp[0]) == '*')
{
//recording file name + channel Id + time
str = "Test" + nCh.ToString() + "." + System.DateTime.Now.Hour.ToString() + "="
+ System.DateTime.Now.Minute.ToString() + "=" + System.DateTime.Now.Second.ToString()
+ ".wav";
if(SsmRecToFile(nCh, str, -1, 0, -1, 8000, 0) == -1) //start recording
{
MessageBox.Show("Fail to call SsmRecToFile");
}
ChState[nCh].WorkState = (int)TRUNK_STATE.TRK_RECORD;
}
}
}
else if(ChState[nCh].WorkState == (int)TRUNK_STATE.TRK_RECORD)
{
if(ChState[nCh].ConState == (int)Control.DTMF_CTRL)
{
if((temp[0]) == '*')
{
if(SsmStopRecToFile(nCh) == -1) //stop recording
{
MessageBox.Show("Failed to call SsmStopRecToFile");
}
ChState[nCh].WorkState = (int)TRUNK_STATE.TRK_PICKUP;
}
}
}
}
break;
case E_PROC_RecordEnd: //recording end event
{
nCh = (int)m.WParam; //number of channel output the event
if(ChState[nCh].WorkState == (int)TRUNK_STATE.TRK_RECORD)
{
ChState[nCh].WorkState = (int)TRUNK_STATE.TRK_PICKUP;
}
}
break;
case E_CHG_RingCount:
nCh = (int)m.WParam;
if((ChState[nCh].WorkState == (int)TRUNK_STATE.TRK_IDLE ) && ((int)m.LParam == 2)) //twice ringing
{
ChState[nCh].WorkState = (int)TRUNK_STATE.TRK_RINGING;
//receive CallerId
if(SsmGetCallerId(nCh, szCallerId) == -1)
MessageBox.Show("Fail to call SsmGetCallerId");
ChState[nCh].szCallerId += '\0';
ChState[nCh].szCallerId = System.Text.Encoding.ASCII.GetString(szCallerId);
}
break;
}
UpdateChList();
}
base.WndProc(ref m);
}
private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
if(comboBox1.Text != "None")
{
int nSel = int.Parse(comboBox1.Text);
switch(ChState[nSel].ConState)
{
case (int)Control.VOICE_CTRL:
radioButton1.Checked = true;
radioButton2.Checked = false;
radioButton3.Checked = false;
break;
case (int)Control.VOLTAGE_CTRL:
radioButton1.Checked = false;
radioButton2.Checked = true;
radioButton3.Checked = false;
break;
case (int)Control.DTMF_CTRL:
radioButton1.Checked = false;
radioButton2.Checked = false;
radioButton3.Checked = true;
break;
}
}
}
private void radioButton1_CheckedChanged(object sender, System.EventArgs e)
{
if(radioButton1.Checked == true)
{
if(comboBox1.Text != "")
ChState[int.Parse(comboBox1.Text)].ConState = (int)Control.VOICE_CTRL;
}
UpdateChList();
}
private void radioButton2_CheckedChanged(object sender, System.EventArgs e)
{
if(radioButton2.Checked == true)
{
if(comboBox1.Text != "")
ChState[int.Parse(comboBox1.Text)].ConState = (int)Control.VOLTAGE_CTRL;
}
UpdateChList();
}
private void radioButton3_CheckedChanged(object sender, System.EventArgs e)
{
if(radioButton3.Checked == true)
{
if(comboBox1.Text != "")
ChState[int.Parse(comboBox1.Text)].ConState = (int)Control.DTMF_CTRL;
}
UpdateChList();
}
private void button1_Click(object sender, System.EventArgs e)
{
Form2 dlg = new Form2();
dlg.ShowDialog();
}
private void button2_Click(object sender, System.EventArgs e)
{
Form3 dlg = new Form3();
dlg.ShowDialog();
}
private void button3_Click(object sender, System.EventArgs e)
{
Form4 dlg = new Form4();
dlg.ShowDialog();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -