for( c=Fgloba.m_GCIStartingIndex;c<2/*(int)(Fgloba.m_NumChans+Fgloba.m_GCIStartingIndex)*/;c++ )
{
cOut.GoToMark();
printf(") Configuring... channel %03d == Wait time %d \n",c,Fgloba.CConfWtime);
Sleep(Fgloba.CConfWtime);
if( !GetConfigFromDatabase(c) )
return false;
if( !SetChanConfig(c) )
return false;
}
This my code
GetConfigfromdatabase and set chanconfig functions are here.... for loop is running for only 2 time....
bool ChannelConfig::GetConfigFromDatabase(int c)
{
bool ret=true;
char configID [10];
char chanID [10];
strcpy( Fgloba.Activate, "y");
strcpy( Fgloba.Summation, "y");
strcpy( Fgloba.CallerId, "y");
Fgloba.Sensitivity = 38;
strcpy( Fgloba.RunEvent, "n");
Fgloba.TrigerType = 1;
strcpy( Fgloba.RunMoni, "n");
Fgloba.Moni = 0;
strcpy( Fgloba.RunTerm, "n");
Fgloba.Term = 0;
Fgloba.FMinDuration = 5 ;
Fgloba.FMaxDuration = 3600;
Fgloba.minSilence = 100;
Fgloba.maxSilence = 3000;
Fgloba.minActivity = 40;
Fgloba.maxActivity = 10000;
Fgloba.ThrshLow = -51;
Fgloba.ThrshHigh = -48;
strcpy(Fgloba.RunGain, "y");
Fgloba.ChannelGain = 20;
strcpy(Fgloba.RunSumGain, "n");
Fgloba.SumGain = -50; /* */
strcpy(Fgloba.HPFilter, "n");
strcpy(Fgloba.AGC, "n");
Fgloba.AGCId = 1;
strcpy(Fgloba.ECC, "n");
strcpy( Fgloba.RunPriGain, "n");
Fgloba.InputPriGain = 0;
strcpy( Fgloba.RunSecGain, "n");
Fgloba.InputSecGain = 0;
Fgloba.TMA = -18;
Fgloba.AGCR= 400;
Fgloba.DGCR= 4;
Fgloba.MA= 18;
strcpy(Fgloba.RunLV, "n");
Fgloba.LVthHigh = 15;
Fgloba.LVthLow = -15;
Fgloba.LVDeglitchTime = 50;
Fgloba.PhoneModel = 0;
Fgloba.ClientMaxDuration = 3200;
Fgloba.Watermark_Buffer = 1625;
Fgloba.BUFFER_SIZE = 8125;
Fgloba.PreACTDuration = 0;
chdev[c]->BR_EVT1 = 0;
chdev[c]->BR_EVT2 = 0;
chdev[c]->ER_EVT1 = 0;
chdev[c]->ER_EVT2 = 0;
chdev[c]->IN_EVT1 = 0;
chdev[c]->IN_EVT2 = 0;
chdev[c]->OU_EVT1 = 0;
chdev[c]->OU_EVT2 = 0;
chdev[c]->StartTO = 3000;
chdev[c]->StopTO = 3000;
chdev[c]->IncTO = 3000;
chdev[c]->OutTO = 3000;
chdev[c]->BR_COMB = 1; //0 is OR 1 is AND
chdev[c]->ER_COMB = 1; //0 is OR 1 is AND
chdev[c]->IN_COMB = 1; //0 is OR 1 is AND
chdev[c]->OU_COMB = 1; //0 is OR 1 is AND
chdev[c]->FileDataValidFlag =false;
if(Fgloba.SQLStore)
{
try
{
database ChanConfigValue;
sprintf(chanID, "%d", c );
strcpy(configID, ChanConfigValue.GetSelectStringField("channel", "ConfigId", "ChanId", chanID ) );
strcpy( Fgloba.CallerId, ChanConfigValue.GetSelectStringField("config", "CallerId", "ConfigId", configID ) );
Fgloba.Sensitivity = ChanConfigValue.GetSelectField("config", "CIdValue", "ConfigId", configID);
Fgloba.TrigerType = ChanConfigValue.GetSelectField("config", "Event", "ConfigId", configID);
Fgloba.FMinDuration = ChanConfigValue.GetSelectField("config", "minDur", "ConfigId", configID);
Fgloba.FMaxDuration = ChanConfigValue.GetSelectField("config", "maxDur", "ConfigId", configID);
Fgloba.minSilence = ChanConfigValue.GetSelectField("config", "minSil", "ConfigId", configID);
Fgloba.maxSilence = ChanConfigValue.GetSelectField("config", "maxSil", "ConfigId", configID);
Fgloba.minActivity = ChanConfigValue.GetSelectField("config", "minAct", "ConfigId", configID);
Fgloba.maxActivity = ChanConfigValue.GetSelectField("config", "maxAct", "ConfigId", configID);
Fgloba.ThrshLow = ChanConfigValue.GetSelectField("config", "thLow", "ConfigId", configID);
Fgloba.ThrshHigh = ChanConfigValue.GetSelectField("config", "thHigh", "ConfigId", configID);
strcpy(Fgloba.RunVolume, ChanConfigValue.GetSelectStringField("config", "RunVolume", "ConfigId", configID ));
Fgloba.Volume = ChanConfigValue.GetSelectField ("config", "Volume", "ConfigId", configID);
strcpy(Fgloba.RunGain, ChanConfigValue.GetSelectStringField("config", "RunGain", "ConfigId", configID ));
Fgloba.ChannelGain = ChanConfigValue.GetSelectField ("config", "Gain", "ConfigId", configID);
strcpy(Fgloba.RunSumGain, ChanConfigValue.GetSelectStringField("config", "RunSumGain", "ConfigId", configID ));
Fgloba.SumGain = ChanConfigValue.GetSelectField ("config", "SumGain", "ConfigId", configID);
strcpy(Fgloba.HPFilter, ChanConfigValue.GetSelectStringField("config", "HPFilter", "ConfigId", configID ));
strcpy(Fgloba.AGC, ChanConfigValue.GetSelectStringField("config", "AGC", "ConfigId", configID ));
Fgloba.AGCId =ChanConfigValue.GetSelectField("config", "AGCId", "ConfigId", configID);
strcpy(Fgloba.ECC, ChanConfigValue.GetSelectStringField("config", "ECC", "ConfigId", configID ));
Fgloba.Watermark_Buffer = ChanConfigValue.GetSelectField("config", "WMBufSize", "ConfigId", configID );
Fgloba.BUFFER_SIZE = ChanConfigValue.GetSelectField("config", "TmpBufSize", "ConfigId", configID );
Fgloba.PhoneModel = ChanConfigValue.GetSelectField("config", "PhoneModel", "ConfigId", configID );
Fgloba.PreACTDuration = ChanConfigValue.GetSelectField("config", "PreActDur", "ConfigId", configID );
Fgloba.ClientMaxDuration = ChanConfigValue.GetSelectField("config", "ClientMaxDur", "ConfigId", configID );
//GAIN
strcpy(Fgloba.RunPriGain, ChanConfigValue.GetSelectStringField("Gain", "RunPriGain", "GainID", configID ));
Fgloba.InputPriGain = ChanConfigValue.GetSelectField ("Gain", "PriGain", "GainID", configID);
strcpy(Fgloba.RunSecGain, ChanConfigValue.GetSelectStringField("Gain", "RunPriGain", "GainID", configID ));
Fgloba.InputSecGain = ChanConfigValue.GetSelectField ("Gain", "SecGain", "GainID", configID);
// AGC
Fgloba.TMA = ChanConfigValue.GetSelectField("AGC", "TMA", "AgcID", configID);
Fgloba.AGCR = ChanConfigValue.GetSelectField("AGC", "Attack", "AgcID", configID);
Fgloba.DGCR = ChanConfigValue.GetSelectField("AGC", "Decay", "AgcID", configID);
Fgloba.MA = ChanConfigValue.GetSelectField("AGC", "MA", "AgcID", configID);
// Loop Voltage
strcpy(Fgloba.RunLV, ChanConfigValue.GetSelectStringField("config", "RunLV", "ConfigID", configID ));
if( strnicmp(Fgloba.RunLV ,"y",1)==0 )
{
Fgloba.LVthHigh = ChanConfigValue.GetSelectField("LoopVoltage", "thHigh", "LVID", configID);
Fgloba.LVthLow = ChanConfigValue.GetSelectField("LoopVoltage", "thLow", "LVID", configID);
Fgloba.LVDeglitchTime = ChanConfigValue.GetSelectField("LoopVoltage", "DeglitchTime", "LVID", configID);
}
chdev[c]->MaxSilence = Fgloba.maxSilence;
chdev[c]->ClientMaxDuration = Fgloba.ClientMaxDuration;
chdev[c]->Watermark_Buffer = Fgloba.Watermark_Buffer;
chdev[c]->PreACTDuration = Fgloba.PreACTDuration;
chdev[c]->FMinDuration = Fgloba.FMinDuration;
chdev[c]->FMaxDuration = Fgloba.FMaxDuration;
chdev[c]->BUFFER_SIZE = Fgloba.BUFFER_SIZE;
chdev[c]->TrigerType = Fgloba.TrigerType;
chdev[c]->PhoneMake = Fgloba.PhoneModel;
if( (chdev[c]->TrigerType == 2) || (chdev[c]->TrigerType == 3) )
chdev[c]->MaxSilence = 0;
if(chdev[c]->PhoneMake != 0)
{
int temp=0;
char phone[10];
sprintf(phone,"%d",Fgloba.PhoneModel);
char tmp[10];
temp = ChanConfigValue.GetSelectField("phonemodel", "DChanStartEvt1", "PhoneId", phone);
if(temp != 0)
{
sprintf(tmp,"%d",temp);
chdev[c]->BR_EVT1 = ChanConfigValue.GetSelectField("ngxevent", "EventValue", "EventId", tmp);
}
temp = ChanConfigValue.GetSelectField("phonemodel", "DChanStartEvt2", "PhoneId", phone);
if(temp != 0)
{
sprintf(tmp,"%d",temp);
chdev[c]->BR_EVT2 = ChanConfigValue.GetSelectField("ngxevent", "EventValue", "EventId", tmp);
}
temp = ChanConfigValue.GetSelectField("phonemodel", "DChanStopEvt1", "PhoneId", phone);
if(temp != 0)
{
sprintf(tmp,"%d",temp);
chdev[c]->ER_EVT1 = ChanConfigValue.GetSelectField("ngxevent", "EventValue", "EventId", tmp);
}
temp = ChanConfigValue.GetSelectField("phonemodel", "DChanStopEvt2", "PhoneId", phone);
if(temp != 0)
{
sprintf(tmp,"%d",temp);
chdev[c]->ER_EVT2 = ChanConfigValue.GetSelectField("ngxevent", "EventValue", "EventId", tmp);
}
temp = ChanConfigValue.GetSelectField("phonemodel", "DChanIncEvt1", "PhoneId", phone);
if(temp != 0)
{
sprintf(tmp,"%d",temp);
chdev[c]->IN_EVT1 = ChanConfigValue.GetSelectField("ngxevent", "EventValue", "EventId", tmp);
}
temp = ChanConfigValue.GetSelectField("phonemodel", "DChanIncEvt2", "PhoneId", phone);
if(temp != 0)
{
sprintf(tmp,"%d",temp);
chdev[c]->IN_EVT2 = ChanConfigValue.GetSelectField("ngxevent", "EventValue", "EventId", tmp);
}
temp = ChanConfigValue.GetSelectField("phonemodel", "DChanOutEvt1", "PhoneId", phone);
if(temp != 0)
{
sprintf(tmp,"%d",temp);
chdev[c]->OU_EVT1 = ChanConfigValue.GetSelectField("ngxevent", "EventValue", "EventId", tmp);
}
temp = ChanConfigValue.GetSelectField("phonemodel", "DChanOutEvt2", "PhoneId", phone);
if(temp != 0)
{
sprintf(tmp,"%d",temp);
chdev[c]->OU_EVT2 = ChanConfigValue.GetSelectField("ngxevent", "EventValue", "EventId", tmp);
}
if( !strcmp(ChanConfigValue.GetSelectStringField("phonemodel", "DChanStartOpr", "PhoneId", phone),"OR"))
chdev[c]->BR_COMB = 0;
else
chdev[c]->BR_COMB = 1;
if( !strcmp(ChanConfigValue.GetSelectStringField("phonemodel", "DChanStopOpr", "PhoneId", phone),"OR"))
chdev[c]->ER_COMB = 0;
else
chdev[c]->ER_COMB = 1;
if( !strcmp(ChanConfigValue.GetSelectStringField("phonemodel", "DChanIncOpr", "PhoneId", phone),"OR"))
chdev[c]->IN_COMB = 0;
else
chdev[c]->IN_COMB = 1;
if( !strcmp(ChanConfigValue.GetSelectStringField("phonemodel", "DChanOutOpr", "PhoneId", phone),"OR"))
chdev[c]->OU_COMB = 0;
else
chdev[c]->OU_COMB = 1;
chdev[c]->StartTO = ChanConfigValue.GetSelectField("phonemodel", "StartTo", "PhoneId", phone);
chdev[c]->StopTO = ChanConfigValue.GetSelectField("phonemodel", "StopTo", "PhoneId", phone);
chdev[c]->IncTO = ChanConfigValue.GetSelectField("phonemodel", "IncTo", "PhoneId", phone);
chdev[c]->OutTO = ChanConfigValue.GetSelectField("phonemodel", "OutTo", "PhoneId", phone);
}
}
catch (...)
{
Falarm.ErrReport(2, "!ERROR 5001A: While getting configuration from database ");
ret=GetConfigFromTextFile(c);
}
if( (chdev[c]->TrigerType == 2) || (chdev[c]->TrigerType == 3) )
chdev[c]->MaxSilence = 0;
}
return ret;
}
/////////////////////////////////////////////////////////////////////////////////////////////////
bool ChannelConfig::SetChanConfig (int c)
{
bool bEnable = false;;
MT_ACTPARAMS ActParams = {0};
ULONG ActPLength = sizeof (ActParams );
ActParams.threshold_low = Fgloba.ThrshLow;
ActParams.threshold_high = Fgloba.ThrshHigh;
ActParams.min_silence = Fgloba.minSilence;
ActParams.max_silence = Fgloba.maxSilence;
ActParams.min_activity = Fgloba.minActivity;
ActParams.max_activity = Fgloba.maxActivity;
if ( !fhandleMT( MTSetACTDParams (c, &ActParams, &ActPLength),
"MTSetACTDParams() channel %d", c ) )
{
cout << "!ERROR 5002A: Could not set ACTD params. " << endl;
return false;
}
// Set Gain
if( strnicmp(Fgloba.RunGain,"y",1)==0 )
{
if( !fhandleMT( MTSetGain (c,Fgloba.ChannelGain),
"MTSetGain() Gain %d channel %d",Fgloba.ChannelGain, c) )
{
cout << "!ERROR 5002B: Could not set Gain. " << endl;
return false;
}
}
// Set Primary Gain
if( strnicmp(Fgloba.RunPriGain,"y",1)==0 )
{
if( !fhandleMT( MTChInputSetGain (c,0,Fgloba.InputPriGain),
"MTChInputSetGain() Primary Gain %d channel %d",Fgloba.InputPriGain, c) )
{
cout << "!ERROR 5002B: Could not set Gain. " << endl;
return false;
}
}
// Set Secondary Gain
if( strnicmp(Fgloba.RunSecGain,"y",1)==0 )
{
if( !fhandleMT( MTChInputSetGain (c,1,Fgloba.InputSecGain),
"MTChInputSetGain() Secondary Gain %d channel %d",Fgloba.InputSecGain, c) )
{
cout << "!ERROR 5002B: Could not set Gain. " << endl;
return false;
}
}
// Set Volume
if( strnicmp(Fgloba.RunVolume,"y",1)==0 )
{
if( !fhandleMT( MTSetVolume (c,Fgloba.Volume),
"MTSetVolume() Volume %d channel %d",Fgloba.Volume, c) )
{
cout << "!ERROR 5002B: Could not set Volume. " << endl;
return false;
}
}
// Set Sum Gain
if( strnicmp(Fgloba.RunSumGain,"y",1)==0 )
{
if( !fhandleMT( MTSetSummationGain(0,0,Fgloba.SumGain),
"MTSetSummationGain() SumGain %d channel %d",Fgloba.SumGain,c) )
{
cout << "!ERROR 5002B: Could not set SumGain. " << endl;
return false;
}
}
// Set Caller ID
if( !fhandleMT( MTEnableCallerID (c,Fgloba.Sensitivity),
"MTEnableCallerID() Sensitivity %d channel %d",Fgloba.Sensitivity, c) )
{
cout << "!ERROR 5002C: Could not Enable CallerID. " << endl;
return false;
}
// Set High Pass Filter
if( strnicmp(Fgloba.HPFilter,"y",1)==0 )
bEnable = true;
else
bEnable = false;
if( !fhandleMT( MTHighpassFilterControl (c,bEnable),
"MTHighpassFilterControl() %d channel %d",bEnable, c) )
{
cout << "!ERROR 5002C: Could not MTHighpassFilterControl. " << endl;
return false;
}
// Set AGC
if( strnicmp(Fgloba.AGC,"y",1)==0 )
{
if( !fhandleMT( MTAGCControl (c,true),
"MTAGCControl() 1 channel %d", c) )
{
cout << "!ERROR 5002C: Could not MTAGCControl. " << endl;
return false;
}
if( !fhandleMT( MTSetAGC (c,Fgloba.TMA, Fgloba.AGCR, Fgloba.DGCR, Fgloba.MA),
"MTSetAGC(TMA=%d AGCR=%d DGCR=%d MA=%d) channel %d",Fgloba.TMA, Fgloba.AGCR, Fgloba.DGCR, Fgloba.MA, c) )
{
cout << "!ERROR 5002C: Could not set MTSetAGC. " << endl;
return false;
}
}
else
{
if( !fhandleMT( MTAGCControl (c,false),
"MTAGCControl() 0 channel %d", c) ){
cout << "!ERROR 5002C: Could not MTAGCControl. " << endl;
return false;
}
}
//Set Echo Control and Noise Cancelation
if( strnicmp(Fgloba.ECC,"y",1)==0 )
{
bEnable = true;
//else
//bEnable = false;
if( !fhandleMT( MTSetECControl (c,bEnable),
"MTSetECControl() %d channel %d",bEnable, c) )
{
cout << "!ERROR 5002C: Could not set MTSetECControl. " << endl;
return false;
}
}
// Loop Voltage
if( strnicmp(Fgloba.RunLV ,"y",1)==0 )
{
if( !fhandleMT( MTSetLVParams (c, Fgloba.LVthLow, Fgloba.LVthHigh, Fgloba.LVDeglitchTime),
"MTSetLVParams(channel=%d thHigh=%d thLow=%d DegTime=%d) ",c, Fgloba.LVthHigh, Fgloba.LVthLow, Fgloba.LVDeglitchTime) )
{
cout << "!ERROR 5002C: Could not set MTSetLVParams. " << endl;
return false;
}
}
return true;
}