def send_request(whid,actionCode,parameters):
	"""
	Creates the request to send to the web socket from a button in SCADA.
	Args:
		whid = identifier of the warehouse ie MAN2
		actionCode : possible actionCode as per MAP data model (int values):
			0 	->	Not used
			1	->	Start
			2	->	Stop
			3	->	Reset
			4	->	Get
			5	->	Set
			6	->	Enable
			7	->	Disable
		parameters = dictionary with the parameters of the command
			{"commandTarget":id,
			"commandCode":action,
			"commandTimestamp":time_stamp,
			"commandParams":""}
	Returns:
		a messsage that inform the user about there status of the request
	"""
	import sys
	try:
		loggerName=whid+ "_SCADA"
		logger = system.util.getLogger(loggerName)
		tag_provider = "[%s_SCADA_TAG_PROVIDER]" % (whid)
		messages_to_send = {}
		message_payload = {}
		message_list = []
		returnMessage=""
		time_stamp = system.date.toMillis(system.date.now())

		payloadParams={}
		if not parameters["commandTarget"] or parameters["commandTarget"] == "":
			returnMessage = "Missing commandTarget parameter. Command can\'t be executed" 
			logger.trace(returnMessage)
			return returnMessage
		payloadParams["commandTarget"]=parameters["commandTarget"]
		if not parameters["commandCode"] or parameters["commandCode"] == "":
			returnMessage = "Missing commandCode parameter. Command can\'t be executed" 
			logger.trace(returnMessage)
			return returnMessage
		payloadParams["commandCode"]=parameters["commandCode"]
		payloadParams["commandTimeout"]=2000			
		payloadParams["commandTimestamp"]=time_stamp
		payloadParams["commandParams"]=parameters["commandParams"]
		
		message_payload["parameters"] = payloadParams
		message_payload["action"] = "command"
		message_payload["siteId"] = whid
		message_list.append(message_payload)
		messages_to_send["message_list"] = message_list
		system.tag.writeBlocking([tag_provider + "System/wbsckt_messages_send"], [system.util.jsonEncode(messages_to_send)])
		return "Message sent correctly"
		
	except:
		exc_type, exc_obj, tb = sys.exc_info()
		lineno = tb.tb_lineno
		exceptionMessage=str(lineno)+" -> "+str(exc_type)+" -> "+str(exc_obj)
		errorMessage = "Error while sending a command :  "+exceptionMessage
		logger.fatal(errorMessage)
		return errorMessage
		
def send_request_old_to_be_removed(whid, id, action):
	
	"""
	Creates the request to send to the web socket from a button in SCADA.
	
	Args:
		id =Unique material handling equipment id.
		request = Type of request i.e Start, Stop, Reset.			  
	Returns:
		N/A
	"""
	"""{"action": "command", "parameters": {"": "Reset", "siteId": "DNG2"}}"""
	messages_to_send = {}
	message_payload = {}
	message_list = []
	time_stamp = system.date.toMillis(system.date.now())
	parameters = {"commandTarget":id, "commandCode":action, "commandTimestamp":time_stamp,
	"commandToken":"", "commandTimeout":2000, "commandParams":""}
	message_payload["parameters"] = parameters
	message_payload["action"] = "command"
	message_payload["siteId"] = whid
	message_list.append(message_payload)
	messages_to_send["message_list"] = message_list
	tag_provider = "[%s_SCADA_TAG_PROVIDER]" % (whid)
	system.tag.writeBlocking([tag_provider + "System/wbsckt_messages_send"], 
							[system.util.jsonEncode(messages_to_send)])


def send_download_request(whid, filters, session_id):
	
	"""
	Creates the request to download alarm history
	to the web socket from a button in SCADA.
	
	Args:
		whid = four character whid for the project
		filters = filter string for passing with the download request.
		These a re similar to the url parameters but do not need encoding.
		session_id = unique session id of the perspective session.			  
	Returns:
		N/A
	Example:
	{"action":"download", "parameters":{"siteId":"FED1", "sessionId":"bob2", 
	"filter": "MinimumDuration=360000&Type=1"}}
	"""
	messages_to_send = {}
	message_payload = {}
	message_list = []
	time_stamp = system.date.toMillis(system.date.now())
	parameters = {"siteId":whid, "sessionId": session_id, "filter": filters}
	message_payload["parameters"] = parameters
	message_payload["action"] = "download"
#	message_payload["siteId"] = whid
	message_list.append(message_payload)
	messages_to_send["message_list"] = message_list
	tag_provider = "[%s_SCADA_TAG_PROVIDER]" % (whid)
	system.tag.writeBlocking([tag_provider + "System/wbsckt_messages_send"], 
							[system.util.jsonEncode(messages_to_send)])
