/*===================================-======================================*/
/*                              ALERT ACTIONS                               */
/*-----------------------------------=--------------------------------------*/
/* AUTHORs:        Abdelouahab Abdesselam

   DESIGN ISSUEs:  this are actions to do when the warning or alarm comes: In fact, the 
   				   actions here consists just to write a formated message to the channel alarm 
   				   (warn or alarm) datapoint (see datapoint structure). the other (real) actions 
   				   are done there via a dpConnect() workfuntion to these datapoint elements (see 
   				   the second alarm scrtipt (file) in the script directory).

   MODIF_HISTORY:  28.10.2003 - first version
                   03.12.03   - connection is to channel alarm datapoint and no 
                                longer to the crate one.
/*--------------------------------------------------------------------------*/

warningAlarmCame(string dpeName, time timeNow, string alarm_type)
{
	int status;
    string dpeStat, local_time, alert_warn, dpeAlertWarnMsg, dpeAlertWarnCount; 
	dyn_string dpeSplit, dpeSplit2;  
  
	//split the dpeName to three parts (to get rid fo :alert_hdl). remeber that the format of 
	//dpeName is SCTdcs02:parameterPath:alert... 
	dpeSplit=strsplit(dpeName, ":"); 
	//split the second part (to get the path without the parameter name (drop parameter.Recv) 
	dpeSplit2=strsplit(dpeSplit[2], "."); 

	//===============================================================================================
	//form the path of the channel status 
	//dpeStat = dpeSplit[1]+":"+dpeSplit2[1]+"."+dpeSplit2[2]+"."+substr(dpeSplit2[3], 0, 2)+"_Stat"; 
	//set the channel status  
    //dpGet(dpeStat+":_online.._value", status);  
    // if(((status&0xC)!=0x0)&&((status&0x3)!=0x3)) {....}
    //status = status & 0xFC;   status = status | stat; 
    //status = 12;
 	//dpSet(dpeStat+":_original.._value", status);
 	//===============================================================================================
	
	//get local time dd/mm/yy/ hh/mm/ss PM(AM)
    //local_time = formatTime("%c", timeNow);	 
    local_time = formatTime("%H:%M:%S %d/%m/%Y", timeNow);
     
	//form the path of the parameter  (without .Recv)
  	dpeName = dpeSplit[1]+":"+dpeSplit2[1]+"."+dpeSplit2[2]+"."+dpeSplit2[3];  
   
    //write alert or warning message and increment the alarm counter (one per crate)
    switch(alarm_type)
    	{
    		case "WARNING":
    			//warning message address
   				dpeAlertWarnMsg = dpeSplit2[1]+"."+dpeSplit2[2]+".WarnMesg.Message:_original.._value";
   				//warining information message 
   				sprintf(alert_warn, "WARNING CAME    |    %s    |    %s", dpeName, local_time); 
   			break;
   			case "ALARM":
   				//Alarm message address
   				dpeAlertWarnMsg = dpeSplit2[1]+"."+dpeSplit2[2]+".AlrmMesg.Message:_original.._value";
   				//Alarm information message 
   				sprintf(alert_warn, "ALARM CAME      |    %s    |    %s", dpeName, local_time); 
   			break;
   		}

 	//write Alarm information to warning or alert datapoint element  
  	dpSet(dpeAlertWarnMsg, alert_warn); 
  	//increment the alarm counter
  	//dpSet(dpeAlertWarnCount, +1); 
}


//==============================================================================
//this are actions to do when the warning or alarm goess: it consists just to write
// a formated message to the crate alarm (warn or alarm) datapoint. the other actions
// are done there via a dpConnect
//==============================================================================

warningAlarmWent(string dpeName, time timeNow, string alarm_type)
{    
	string dpeStat, local_time, alert_warn, dpeAlertWarnMsg, dpeAlertWarnCount;  
	dyn_string dpeSplit, dpeSplit2;   
    int status; 
	
	//split the dpeName to three parts. remeber that the format is SCTdcs02:parameterPath:alhd_  
	dpeSplit=strsplit(dpeName, ":");  
	//split the second part (to get the path without the parameter name (drop parameter.Recv)  
	dpeSplit2=strsplit(dpeSplit[2], "."); 
	
	//================================================================================================= 
	//form the path of the channel status  
	//dpeStat = dpeSplit[1]+":"+dpeSplit2[1]+"."+dpeSplit2[2]+"."+substr(dpeSplit2[3], 0, 2)+"_Stat";  
	//set the channel status   
    //dpGet(dpeStat+":_online.._value", status);   
  
    //status = status & 0xFC;  
    //status = 8;
	//dpSet(dpeStat+":_original.._value", status); 
	//=================================================================================================
	
	//get local time dd/mm/yy/ hh/mm/ss PM(AM)
    //local_time = formatTime("%c", timeNow);	
    local_time = formatTime("%H:%M:%S %d/%m/%Y", timeNow);  
	//form the path of the parameter  
  	dpeName = dpeSplit[1]+":"+dpeSplit2[1]+"."+dpeSplit2[2]+"."+dpeSplit2[3]; 
  	
	//write alert or warning message to alarm datapoint (one per crate)
    switch(alarm_type)
    	{
    		case "WARNING":
    			//warning message address
   				dpeAlertWarnMsg = dpeSplit2[1]+"."+dpeSplit2[2]+".WarnMesg.Message:_original.._value";
   				//warining information message
   				sprintf(alert_warn, "WARNING WENT    |    %s    |    %s", dpeName, local_time); 
   			break;
   			case "ALARM":
   				//Alarm message address
   				dpeAlertWarnMsg = dpeSplit2[1]+"."+dpeSplit2[2]+".AlrmMesg.Message:_original.._value";
   				//Alarm information message
   				sprintf(alert_warn, "ALARM WENT      |    %s    |    %s", dpeName, local_time); 
   			break;
   		}

 	//write Alarm information to warning or alert and decrement the alarm counter  
  	dpSet(dpeAlertWarnMsg, alert_warn); 
  	//decrement the alarm counter
  	//dpSet(dpeAlertWarnCount, -1); 
}
