📄 form1.cs
字号:
ChannelState[ch].WorkState = (int)CH_STATE.CH_OFFLINE;
ChannelState[ch].Lcd = new char[MAX_LCD_LEN];
ClearCallID(ref pEvent); //Clear phone number buffer
}
}
break;
case E_RCV_DSTDChannel:
{
switch(pEvent.dwParam)
{
case DST_RING_OFF:
{
ChannelState[ch].Dir = (int)DIRECTION.UNKNOWN;
ChannelState[ch].WorkState = (int)CH_STATE.CH_IDLE;
GetCallID(ref pEvent); //Get phone number
}
break;
case DST_OFFHOOK:
{
ChannelState[ch].Dir = (int)DIRECTION.DOWN;
ChannelState[ch].WorkState = (int)CH_STATE.CH_ACTIVE;
StartRecord(ch);
}
break;
case DST_MSG_CHG:
{
for(nIndex = 0; nIndex < pEvent.dwDataLength; nIndex++)
{
ChannelState[ch].Lcd[nIndex] = (char)pEvent.pvBuffer[nIndex];
}
ChannelState[ch].LCDLen = pEvent.dwDataLength;
}
break;
default:
break;
}
}
break;
default:
break;
}
}
break;
case (int)CH_STATE.CH_ACTIVE:
{
switch(pEvent.wEventCode)
{
case E_CHG_ChState:
{
if ((pEvent.dwParam & 0xffff) == (int)TRUNK_STATUS.S_CALL_OFFLINE) //Judge channel state
{
ChannelState[ch].Dir = (int)DIRECTION.UNKNOWN;
ChannelState[ch].WorkState = (int)CH_STATE.CH_OFFLINE;
ChannelState[ch].Lcd = new char[MAX_LCD_LEN];
ClearCallID(ref pEvent); //Clear phone number buffer
if (ChannelState[ch].IsRecord != 0)
{
StopRecord(ch); //Stop record
}
}
}
break;
case E_RCV_DSTDChannel:
{
switch(pEvent.dwParam)
{
case DST_ONHOOK:
{
ChannelState[ch].Dir = (int)DIRECTION.UNKNOWN;
ChannelState[ch].WorkState = (int)CH_STATE.CH_IDLE;
GetCallID(ref pEvent);
StopRecord(ch);
}
break;
case DST_MSG_CHG:
{
for(nIndex = 0; nIndex < pEvent.dwDataLength; nIndex++)
{
ChannelState[ch].Lcd[nIndex] = (char)pEvent.pvBuffer[nIndex];
}
ChannelState[ch].LCDLen = pEvent.dwDataLength;
}
break;
case DST_ABANDONED:
{
ChannelState[ch].WorkState = (int)CH_STATE.CH_WAITFOR_ONHOOK;
GetCallID(ref pEvent);
StopRecord(ch);
}
break;
default:
break;
}
}
break;
default:
break;
}
}
break;
case (int)CH_STATE.CH_OFFLINE:
{
if ((pEvent.wEventCode==E_CHG_ChState) && ((pEvent.dwParam & 0xffff)==(int)TRUNK_STATUS.S_CALL_STANDBY))
{
ChannelState[ch].Dir = (int)DIRECTION.UNKNOWN;
ChannelState[ch].Lcd = new char[MAX_LCD_LEN];
ChannelState[ch].WorkState = (int)CH_STATE.CH_IDLE;
ClearCallID(ref pEvent); //Clear phone number buffer
}
}
break;
case (int)CH_STATE.CH_WAITFOR_ONHOOK:
{
switch(pEvent.wEventCode)
{
case E_CHG_ChState:
{
if ((pEvent.dwParam & 0xffff) == (int)TRUNK_STATUS.S_CALL_OFFLINE) //Judge channel state
{
ChannelState[ch].Dir = (int)DIRECTION.UNKNOWN;
ChannelState[ch].WorkState = (int)CH_STATE.CH_OFFLINE;
if (ChannelState[ch].IsRecord != 0)
{
StopRecord(ch); //Stop record
}
}
}
break;
case E_RCV_DSTDChannel:
{
switch(pEvent.dwParam)
{
case DST_ONHOOK:
{
ChannelState[ch].Dir = (int)DIRECTION.UNKNOWN;
ChannelState[ch].WorkState = (int)CH_STATE.CH_IDLE;
}
break;
case DST_MSG_CHG:
{
for(nIndex = 0; nIndex < pEvent.dwDataLength; nIndex++)
{
ChannelState[ch].Lcd[nIndex] = (char)pEvent.pvBuffer[nIndex];
}
ChannelState[ch].LCDLen = pEvent.dwDataLength;
}
break;
default:
break;
}
}
break;
default:
break;
}
}
break;
default:
break;
}
}//EventHandler End
public void GetCallID(ref SSM_EVENT pEvent)
{
int ch;
int IDPos;
int LCDPos;
int NumStarPos = 0;
int NumStopPos = 0;
ch = pEvent.nReference;
if (ChannelState[ch].LCDLen < 2)
{
return;
}
LCDPos = ChannelState[ch].LCDLen - 1;
IDPos = 0;
//find the number's start position and end position in the LCD information;
while (LCDPos > 0)
{
if (NumStopPos == 0)
{
if ((int)ChannelState[ch].Lcd[LCDPos]<0x39 && (int)ChannelState[ch].Lcd[LCDPos]>0x30)
{
NumStopPos = LCDPos ;
}
}
else
{
if ((int)ChannelState[ch].Lcd[LCDPos]>0x39 || (int)ChannelState[ch].Lcd[LCDPos]<0x30)
{
NumStarPos = LCDPos + 1;
break ;
}
}
LCDPos --;
}
if ((NumStarPos==0) && (NumStopPos==0) && (ChannelState[ch].Lcd[0]>0x39||ChannelState[ch].Lcd[0]<0x30))
{
return; //not found any number;
}
ChannelState[ch].CallIdLen = NumStopPos - NumStarPos + 1;
for(IDPos=0; IDPos<ChannelState[ch].CallIdLen; IDPos++)
{
ChannelState[ch].pCallId[IDPos] = ChannelState[ch].Lcd[NumStarPos];
NumStarPos ++;
}
ChannelState[ch].pCallId[IDPos] = '\0';
return;
}
public void ClearCallID(ref SSM_EVENT pEvent)
{
int ch;
ch = pEvent.nReference;
ChannelState[ch].pCallId = new char[MAX_CALLID_LEN];
return;
}
public void StartRecord(int ch)
{
string recFile;
recFile = "Test" + ch.ToString() + ".wav";
//Start the file sound recording task on the designates channel. -1:error
if(SsmRecToFile(ch, recFile, nRecFormat, 0, -1, 0, 0) == -1)
{
WriteLog(SsmGetLastErrMsgA());
}
ChannelState[ch].IsRecord = (int)CH_RECORD.RECORD;
return;
}
public void StopRecord(int ch)
{
int nreChkRecToFile;
ChannelState[ch].IsRecord = (int)CH_RECORD.UNRECORD;
//Obtains the situation of the file sound recording task. -1:error
nreChkRecToFile = SsmChkRecToFile(ch);
if(nreChkRecToFile == -1)
{
WriteLog(SsmGetLastErrMsgA());
}
if(nreChkRecToFile == 1) //1:Recording
{
//Stop the file sound recording task. -1:error
if(SsmStopRecToFile(ch) == -1)
{
WriteLog(SsmGetLastErrMsgA());
}
}
return;
}
//write log messages
void WriteLog(string szLog)
{
string path = "SHR.log";
using (StreamWriter w = File.AppendText(path))
{
w.Write("\r\nLog Entry : ");
w.WriteLine("{0} {1}",DateTime.Now .ToLongDateString(),DateTime.Now .ToLongTimeString ());
w.WriteLine (" :{0}",szLog);
w.WriteLine ("---------------------------------------------------------------------------");
w.Flush();
w.Close();
}
}
private void radioButton1_CheckedChanged(object sender, System.EventArgs e)
{
nRecFormat = -1;
}
private void radioButton2_CheckedChanged(object sender, System.EventArgs e)
{
nRecFormat = 6;
}
private void radioButton3_CheckedChanged(object sender, System.EventArgs e)
{
nRecFormat = 7;
}
private void radioButton4_CheckedChanged(object sender, System.EventArgs e)
{
nRecFormat = 17;
}
private void radioButton5_CheckedChanged(object sender, System.EventArgs e)
{
nRecFormat = 131;
}
private void radioButton6_CheckedChanged(object sender, System.EventArgs e)
{
nRecFormat = 0xff83;
}
private void timer1_Tick(object sender, System.EventArgs e)
{
UpdateChannelState();
}
private void button1_Click(object sender, System.EventArgs e)
{
if(comboBox1.Text == "") return;
int Cur_Line = int.Parse(comboBox1.Text);
if (ListenChannel != Cur_Line )
{
if(ListenChannel < MaxLine)
{
if (SsmStopListenTo(ListenChannel,0) == -1) //Stop listen
{
MessageBox.Show(SsmGetLastErrMsgA());
return;
}
ChannelState[ListenChannel].IsListen = (int)CH_LISTEN.UNLISTEN;
}
if (SsmListenTo(Cur_Line,0) == -1) //Listen
{
MessageBox.Show(SsmGetLastErrMsgA());
return;
}
ChannelState[Cur_Line].IsListen = (int)CH_LISTEN.LISTEN;
ListenChannel = Cur_Line;
}
return;
}
private void button2_Click(object sender, System.EventArgs e)
{
if(ListenChannel < MaxLine)
{
ChannelState[ListenChannel].IsListen = (int)CH_LISTEN.UNLISTEN;
if (SsmStopListenTo(ListenChannel,0) == -1) //Stop listen
{
MessageBox.Show(SsmGetLastErrMsgA());
}
ListenChannel = MaxLine;
}
return;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -