📄 form1.cs
字号:
for(int i=0; i < m_MaxChNum; i++)
{
lvi = new ListViewItem();
lvi.Text = i.ToString();
lvi.ImageIndex = i;
lvsi = new ListViewItem.ListViewSubItem();
lvsi.Text = GetChanelType(i);
lvi.SubItems.Add(lvsi);
lvsi = new ListViewItem.ListViewSubItem();
mtrunkState= GetChanelState(i);
nInfo=ScanATrunkCh(i,mtrunkState.statevalue);
lvsi.Text =mtrunkState.state;
lvi.SubItems.Add(lvsi);
lvsi = new ListViewItem.ListViewSubItem();
lvsi.Text =nInfo;
lvi.SubItems.Add(lvsi);
lvsi = new ListViewItem.ListViewSubItem();
lvsi.Text =mtrunkState.CallerId;
lvi.SubItems.Add(lvsi);
this.listView1.Items.Add(lvi);
}
}
private TRUNK_STRUCT GetChanelState(int index)
{
mtrunkState.CallerId="";
int state = SsmGetChState(index);
switch (state)
{
case 0:
mtrunkState.state = "Idle";
mtrunkState.statevalue=0;
break;
case 1:
mtrunkState.state = "Pickup";
mtrunkState.statevalue=1;
break;
case 2:
mtrunkState.state = "Ringing";
mtrunkState.statevalue=2;
byte[] szID=new byte[12];
SsmGetCallerId(index,szID);
mtrunkState.CallerId+='\0';
mtrunkState.CallerId=System.Text.Encoding.ASCII.GetString(szID);
break;
case 3:
mtrunkState.state = "Talking";
mtrunkState.statevalue=3;
break;
case 4:
mtrunkState.state = "WaitDltn";
mtrunkState.statevalue=4;
break;
case 5:
mtrunkState.state = "Dialing";
mtrunkState.statevalue=5;
break;
case 6:
mtrunkState.state = "WaitDlRslt";
mtrunkState.statevalue=6;
break;
case 7:
mtrunkState.state = "Hangup";
mtrunkState.statevalue=7;
break;
case 9:
mtrunkState.state = "WaitPickup";
mtrunkState.statevalue=9;
break;
default:
break;
}
return mtrunkState;
}
private string GetChanelType(int index)
{
string strType = null;
int type = SsmGetChType(index);
switch (type)
{
case 0:
strType = "AnalogCh";
break;
case 1:
strType = "UserCh";
break;
case 2:
strType = "UserCh";
break;
case 3:
strType = "RecordCh";
break;
case 20:
strType = "-1";
break;
default:
strType = "-1";
break;
}
return strType;
}
private void TimerEvent_Test(object sender, System.EventArgs e)
{
}
private void hangup_Click(object sender, System.EventArgs e)
{
int nResutlt=SsmHangup(Curch);
if (nResutlt!=0)
MessageBox.Show(SsmGetLastErrMsgA());
}
private string ScanATrunkCh(int ch,int nstate )
{
string mCurinfo="";
if (nstate ==7)//hangup
{
SsmHangup(ch);
switch(mLineState[ch])
{
case TRUNK_STATE.TRK_CHECK_PLAY_WELCOM:
SsmStopPlayFileList(ch);
mCurinfo="playing welcom";
break;
case TRUNK_STATE.TRK_CHECK_PLAY_PASSWORD:
case TRUNK_STATE.TRK_CHECK_REC_START:
case TRUNK_STATE.TRK_CHECK_PLAY_SELECT:
case TRUNK_STATE.TRK_CHECK_PLAY_BYEBYE:
{
SsmStopPlayIndex(ch);
mCurinfo="stop playing index";
}
break;
case TRUNK_STATE.TRK_CHECK_REC_END:
{
SsmStopRecToFile(ch);
mCurinfo="stop recording";
}
break;
case TRUNK_STATE.TRK_CHECK_PLAY_RECORD:
{
SsmStopPlayFile(ch);
mCurinfo="stop playing file";
}
break;
}
mLineState[ch] = TRUNK_STATE.TRK_IDLE;
}
switch(mLineState[ch])
{
case TRUNK_STATE.TRK_IDLE:
if( nstate == 2 ) //ringing
{
SsmPickup(ch);
mLineState[ch] = TRUNK_STATE.TRK_WAIT_CONNECT;
}
break;
case TRUNK_STATE.TRK_WAIT_CONNECT:
if( nstate == 3 )//talking
mLineState[ch] = TRUNK_STATE.TRK_PLAY_WELCOM;
mCurinfo="playing welcom";
break;
case TRUNK_STATE.TRK_PLAY_WELCOM:
SsmClearFileList(ch);
if((SsmAddToFileList(ch,"..\\..\\..\\..\\..\\..\\..\\DemoVoc\\Welcom1.voc",6,0,-1)==-1 ||
SsmAddToFileList(ch,"..\\..\\..\\..\\..\\..\\..\\DemoVoc\\Welcom2.voc",6,0,-1)==-1) )
{
SsmHangup(ch);
MessageBox.Show(SsmGetLastErrMsgA());
mLineState[ch] = TRUNK_STATE.TRK_IDLE;
}
else
if(SsmPlayFileList(ch) == -1)
{
SsmHangup( ch );
MessageBox.Show(SsmGetLastErrMsgA());
mLineState[ch] = TRUNK_STATE.TRK_IDLE;
}
else
mLineState[ch] = TRUNK_STATE.TRK_CHECK_PLAY_WELCOM;
break;
case TRUNK_STATE.TRK_CHECK_PLAY_WELCOM:
if( SsmCheckPlay(ch) > 0) //end of playing "welcom"
{
mLineState[ch] = TRUNK_STATE.TRK_PLAY_SELECT;
mCurinfo="end of playing welcom";
}
break;
case TRUNK_STATE.TRK_PLAY_SELECT:
SsmSetDtmfStopPlay(ch,true); //enable DTMF-Stop-Play function
if(SsmPlayIndexString(ch,"Select") == -1)
{
SsmHangup( ch );
MessageBox.Show(SsmGetLastErrMsgA());
mLineState[ch] = TRUNK_STATE.TRK_IDLE;
}
else
{
SsmClearRxDtmfBuf(ch);
mLineState[ch] = TRUNK_STATE.TRK_CHECK_PLAY_SELECT;
}
mCurinfo="playing select";
break;
case TRUNK_STATE.TRK_CHECK_PLAY_SELECT:
/////////////////////////////////////////////////////
if(SsmGetRxDtmfLen(ch) >= 1 && (SsmCheckPlay(ch) == 2 || SsmCheckPlay(ch) == 1))
{
string tmp1="";
tmp1+= '\0';
byte[] str=new byte[1];
int tt=SsmGet1stDtmf(ch, str);
SsmClearRxDtmfBuf(ch);
tmp1=System.Text.Encoding.ASCII.GetString(str);
char[]tmp=tmp1.ToCharArray();
switch(tmp[0])
{
case '1': //DTMF=1: record to file "test.voc"
if(SsmPlayIndexString(ch,"RecPrompt") == -1) //play "press any key to start, and any key again to stop".
{
SsmHangup( ch );
MessageBox.Show(SsmGetLastErrMsgA());
mLineState[ch] = TRUNK_STATE.TRK_IDLE;
}
else
{
mLineState[ch] = TRUNK_STATE.TRK_CHECK_REC_START;
}
break;
case '2': //DTMF=2: play recorded file "test.voc"
mCurinfo=" play recorded file test.voc";
if(File.Exists("test.voc"))
if(SsmPlayFile(ch,"test.voc",6,0,0xFFFFFFFF) == -1)
{
SsmHangup( ch );
MessageBox.Show(SsmGetLastErrMsgA());
mLineState[ch] = TRUNK_STATE.TRK_IDLE;
}
else
mLineState[ch] = TRUNK_STATE.TRK_CHECK_PLAY_RECORD;
else
if(SsmPlayIndexString(ch,"FileNotFound") == -1) //play "file not found" message
{
SsmHangup( ch );
MessageBox.Show(SsmGetLastErrMsgA());
mLineState[ch] = TRUNK_STATE.TRK_IDLE;
}
else
mLineState[ch] = TRUNK_STATE.TRK_CHECK_PLAY_RECORD;
break ;
case '3': //DTMF=3: play user's password,some sample digital
SsmSetDtmfStopPlay(ch,false); //disable DTMF-Stop-Play function while playing password
if(SsmPlayIndexString(ch,"YourPasswordIs,1,2,3,4") == -1) //play "your password is 1234".
{
SsmHangup( ch );
MessageBox.Show(SsmGetLastErrMsgA());
mLineState[ch] = TRUNK_STATE.TRK_IDLE;
mCurinfo=SsmGetLastErrMsgA();
}
else
mLineState[ch] = TRUNK_STATE.TRK_CHECK_PLAY_PASSWORD;
break;
case '0': //DTMF=0: end of service,play "Byebye"
if ( SsmPlayIndexString(ch, "Byebye" )== -1 )
{ SsmHangup( ch );
MessageBox.Show(SsmGetLastErrMsgA());
mLineState[ch] = TRUNK_STATE.TRK_IDLE;
}
else
mLineState[ch]= TRUNK_STATE.TRK_CHECK_PLAY_BYEBYE;
mCurinfo="end of service,play 'Byebye'";
break;
default:
break;
}
}
break;
case TRUNK_STATE.TRK_CHECK_PLAY_PASSWORD:
mCurinfo="checking password";
if(SsmCheckPlay(ch) > 0) //this channel is not playing index now
mLineState[ch]= TRUNK_STATE.TRK_PLAY_SELECT;
mCurinfo="this channel is playing index now";
break ;
case TRUNK_STATE.TRK_CHECK_REC_START:
if(SsmGetRxDtmfLen(ch) >= 1)
{
SsmClearRxDtmfBuf(ch);
mCurinfo="start recording";
if( SsmRecToFile(ch,"test.voc",6,0,0xffffffff,0,0) == -1) //start from 16000L,maxmium 10 seconds
{
SsmHangup( ch );
MessageBox.Show(SsmGetLastErrMsgA());
mLineState[ch] = TRUNK_STATE.TRK_IDLE;
mCurinfo=SsmGetLastErrMsgA();
}
else
mLineState[ch] = TRUNK_STATE.TRK_CHECK_REC_END;
mCurinfo="start recording";
}
break;
case TRUNK_STATE.TRK_CHECK_REC_END:
if(SsmGetRxDtmfLen(ch)>=1 || SsmChkRecToFile(ch)==0)
{
SsmStopRecToFile(ch);
mLineState[ch]= TRUNK_STATE.TRK_PLAY_SELECT;
mCurinfo="stop recording";
}
break ;
case TRUNK_STATE.TRK_CHECK_PLAY_RECORD:
if(SsmCheckPlay(ch) > 0)
mLineState[ch] = TRUNK_STATE.TRK_PLAY_SELECT;
mCurinfo="Playing select";
break;
case TRUNK_STATE.TRK_CHECK_PLAY_BYEBYE:
if(SsmCheckPlay(ch) > 0)
{
SsmHangup(ch);
mLineState[ch] = TRUNK_STATE.TRK_IDLE;
}
break ;
//////////////////////////////////////////////////////
}//end switch
return mCurinfo;
}
private void phoNum_TextChanged(object sender, System.EventArgs e)
{
PhoNum=this.phoNum.Text;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -