
var epro1_oper = {
	cmd:0,
	comm_port:"",
	comm_baud:"",
	comm_parity:-1,
	comm_stopbit:-1,
	vbus_mod:1,
	uid:"581900230A00801",
	pwd:"20191029",
	delayfire:100,
	amend_v:0,
	bus_voltage:0,
	sorftenhance:1,
	commaddr:21,
	flash_r_bgaddr:15872,//0x3E00,
	flash_r_len:8,
	flash_r_data:"",
	flash_w_addr:15872,//0x3E00,
	flash_w_data:"",
	sys_states:"0000",
	firmware:"",
	auset_addr_fac:400,
	readrate_class:0,
	cycle_bgaddr:21,
	cycle_endaddr:421,
	cycle_group_count:50,
	cycle_bgdelay:0,
	cycle_addr:21,
	cycle_stepdelay:50,
	cycle_bguid:"581900230A00801",
	cycle_rundelay:10,
	cycle_runcount:1,
	cycle_test:0,
	fire_delay_excue:150,
	update_firmware:"",
};
var ep1_qthandle = null;
var eep1_excuedcmd;
var ep1_excued_rtv;
var ep1_cmd_excue_busy = 0
var ep1_recive_buf = [];
var ep1_bus_switch = 0;
var ep1_bus_heartbeat = 1;
var ep1_updata_rtvinfo = "";
var ep1_log_flag = 0;
function Ep1_Start_Comm()
{
	console.log("Ep1_Start_Comm ");
	if( typeof(ep1_qthandle) != "undefined"  && ep1_qthandle != null )
	{
		ep1_qthandle.SearchCommport();
		console.log("SearchCommport ");
	}
}
function Ep1_Open_CommPort(main_serial)
{
	epro1_oper.comm_port =main_serial.comm_port;
	epro1_oper.comm_baud =main_serial.comm_baud;
	epro1_oper.comm_parity =main_serial.comm_parity;
	epro1_oper.comm_stopbit = main_serial.comm_stopbit;
	
	Main_Close_CommPort_Select();
	var json_str = JSON.stringify(epro1_oper);
	console.log(json_str);
	if( typeof(ep1_qthandle) != "undefined"  && ep1_qthandle != null )
	{
		ep1_qthandle.OpenCommPort(json_str);
	}
}

function GetEp1_InputInfo()
{
	epro1_oper.uid = $("#ep1_uid").val();
	epro1_oper.pwd = $("#ep1_pwd").val();
	epro1_oper.delayfire =  parseInt($("#ep1_delayfire").val(),10);
	epro1_oper.commaddr =  parseInt($("#ep1_commaddr").val(),10);
	epro1_oper.flash_r_bgaddr =  parseInt($("#ep1_flash_r_bgaddr").val(),16);
	epro1_oper.flash_r_len = parseInt($("#ep1_flash_r_len").val(),10);
	epro1_oper.flash_r_data =  $("#ep1_flash_w_data").val();
	epro1_oper.flash_addr = parseInt($("#ep1_flash_w_addr").val(),16);
	epro1_oper.flash_w_data =  $("#ep1_flash_w_data").val();
	epro1_oper.auset_addr_fac =  parseInt($("#ep1_auset_addr_fac").val(),10);
	epro1_oper.cycle_bgaddr =  parseInt($("#ep1_cycle_bgaddr").val(),10);
	epro1_oper.cycle_endaddr =  parseInt($("#ep1_cycle_endaddr").val(),10);
	epro1_oper.cycle_group_count =  parseInt($("#ep1_cycle_group_count").val(),10);
	epro1_oper.cycle_bgdelay =  parseInt($("#ep1_cycle_bgdelay").val(),10);
	epro1_oper.cycle_stepdelay =  parseInt($("#ep1_cycle_stepdelay").val(),10);
	epro1_oper.cycle_bguid =  $("#ep1_cycle_bguid").val();
	epro1_oper.cycle_rundelay =  parseInt($("#ep1_cycle_rundelay").val(),10);
	epro1_oper.cycle_runcount =  parseInt($("#ep1_cycle_runcount").val(),10);
	epro1_oper.fire_delay_excue =  parseInt($("#ep1_fire_delay_excue").val(),10);
	epro1_oper.readrate_class =  parseInt($("#ep1_readrate_class").val(),10);
	epro1_oper.update_firmware = $("#ep1_update_firmware").val()
}

async function Ep1_cmd(cmd)
{
	
	if(ep1_cmd_excue_busy > 0)
	{
		ShowCommMes("正在执行命令",MesgType.MESG_TYPE_INFO);
		return;
	}
	ep1_cmd_excue_busy = 1;
	epro1_oper.cmd = cmd;
	GetEp1_InputInfo();
	await Ep1_ExcueOperCmd();
	ep1_cmd_excue_busy = 0;
	
}
function Show_Def()
{
	$("#ep1_uid").val(epro1_oper.uid);
	$("#ep1_pwd").val(epro1_oper.pwd);
	if(epro1_oper.delayfire > 0 && epro1_oper.delayfire < 30000 )
	{
		$("#ep1_delayfire").val(epro1_oper.delayfire);
	}else{
		$("#ep1_delayfire").val('');
	}
	
	$("#ep1_commaddr").val(epro1_oper.commaddr);
	$("#ep1_flash_r_bgaddr").val(Int2HexStr(epro1_oper.flash_r_bgaddr,"",0));
	$("#ep1_flash_r_len").val(epro1_oper.flash_r_len);
	$("#ep1_flash_r_data").val(epro1_oper.flash_r_data);
	$("#ep1_flash_w_addr").val(Int2HexStr(epro1_oper.flash_w_addr,"",0));
	$("#ep1_flash_w_data").val(epro1_oper.flash_w_data);
	$("#ep1_auset_addr_fac").val(epro1_oper.auset_addr_fac);
	$("#ep1_run_cfg_value").val(epro1_oper.run_cfg_value);
	$("#ep1_cycle_bgaddr").val(epro1_oper.cycle_bgaddr);
	$("#ep1_cycle_endaddr").val(epro1_oper.cycle_endaddr);
	$("#ep1_cycle_group_count").val(epro1_oper.cycle_group_count);
	$("#ep1_cycle_bgdelay").val(epro1_oper.cycle_bgdelay);
	$("#ep1_cycle_stepdelay").val(epro1_oper.cycle_stepdelay);
	$("#ep1_cycle_bguid").val(epro1_oper.cycle_bguid);
	$("#ep1_cycle_rundelay").val(epro1_oper.cycle_rundelay);
	$("#ep1_cycle_runcount").val(epro1_oper.cycle_runcount);
	$("#ep1_sys_amend").val(epro1_oper.amend_v);
	$("#ep1_sys_states").val(epro1_oper.sys_states);
	$("#ep1_firmware").val(epro1_oper.firmware);
	$("#ep1_bus_voltage").val(epro1_oper.bus_voltage);
	$("#ep1_readrate_class").val(epro1_oper.readrate_class);
	$("#ep1_update_firmware").val(epro1_oper.update_firmware);
}
function Ep1_Init()
{
	var form = layui.form;
	form.render();
	form.on('switch', function(data){
	var id = data.elem.id;
	if(id == "mes_save_log")
	{
		if(this.checked)
		{
			ep1_log_flag = 1;
		}
		else{
			ep1_log_flag = 0;
		}
		 layer.tips('日志记录 '+  (this.checked ? 'true' : 'false'), data.othis)
	}
	 });
	
	 //if(typeof(qt) != "undefined" &&  qt != null )
	 if(typeof(qchannel) != "undefined" &&  qchannel != null )
	{
	
		 if(ep1_qthandle != null && typeof(ep1_qthandle) != "undefined")
		 {
			 console.log("Ep1_Inited  OK ---");
		 }
		 else
		 {
			ep1_qthandle = qchannel.objects.ep1_qthandle;
		   if((typeof(ep1_qthandle) != "undefined") && (ep1_qthandle != null) )
		   {
				console.log("Ep1_Init  OK ---");
				
				ep1_qthandle.ShowCommMes.connect(function(mesg,type){
					ShowCommMes(mesg,type);
					
				});
				ep1_qthandle.ShowCommport.connect(function(jsoninfo){
					Main_ShowCommport(jsoninfo);
				});
				ep1_qthandle.EP1Comm_Recive.connect(function(jsoninfo){
					EP1Comm_Recive(jsoninfo);
				});
				
				ep1_qthandle.FirmWateUpdate_Return.connect(function(jsoninfo){
					ep1_excuedcmd = 0xFFFE;//获取固件更新返回
					ep1_updata_rtvinfo = jsoninfo;
					
				});
		   }
		}
			 
	}
		   
	 Show_Def();
	 //console.log(Int2HexStr(65536,"0x",0));
}
function Ep1_HeartBeat()
{
	
	var bus_volate = ep1_recive_buf[5] + (ep1_recive_buf[6] << 8);
	bus_volate = bus_volate / 10;
	bus_volate = bus_volate.toFixed(1);
	var bus_current = ep1_recive_buf[7] + (ep1_recive_buf[8] << 8)+(ep1_recive_buf[9] << 16)+(ep1_recive_buf[10] << 24);
	bus_current = bus_current/1000;
	bus_current = bus_current.toFixed(2);
	var mes = "总线电压 "+bus_volate+"V 总线电流  "+bus_current+"mA"
	ShowCommMes(mes,MesgType.MESG_TYPE_INFO);
}

function EP1Comm_Recive(jsoninfo)
{
	var frame = JSON.parse(jsoninfo);
	ep1_recive_buf = frame;
	ep1_excuedcmd = frame[4];
	var frame_str = "Rx: "+ Bytes2Str(frame) ;
	if(ep1_excuedcmd == 0xFE)
	{
		ShowCommMes(frame_str,MesgType.MESG_TYPE_INFO);
		Ep1_HeartBeat();
	}else{
		ep1_excued_rtv = frame[7];
		ShowCommMes(frame_str,MesgType.MESG_TYPE_INFO,ep1_log_flag);
		BTInfoCount(1);
		if(ep1_excued_rtv != 0)
		{
			BTErrorCount(1);
		}
	}
}

function Ep1_CmdData(addr,func,cmd,param,read_len)
{
	
	return Epro_CmdData(addr,func,cmd,param,read_len);
	
}
var Ep1_Cmd_Head = "EST";
function Ep1_SendCmd(cmd_buf)
{
	
	var buf = Str2Bytes(Ep1_Cmd_Head);
	buf[3] = 0; //数据长度
	buf[4] = epro1_oper.cmd;
	for(var index = 0; index < cmd_buf.length;index++)
	{
		buf[5+index] = cmd_buf[index];
	}
	buf[3] = buf.length;
	var json_str = JSON.stringify(buf);
	console.log(json_str);
	if( typeof(ep1_qthandle) != "undefined"  && ep1_qthandle != null )
	{
		ep1_qthandle.Ep1_SendData(json_str);
	}
	var mes = "Tx:" + Bytes2Str(buf);
	ShowCommMes(mes,MesgType.MESG_TYPE_INFO,ep1_log_flag);
}
function Ep1_Beep(count)
{
	var param  = [0,0,count];
	epro1_oper.cmd = 0xFE;
	Ep1_SendCmd(param);
	
}
async function Ep1_SwitchBus()
{
	var mes_ = ""
	var param  = [0,0,0];
	if(ep1_bus_switch == 0)
	{
		param[2] = 1;
		ep1_bus_switch = 1;
		mes_ = "开总线";
	}else{
		
		param[2] = 0;
		ep1_bus_switch = 0;
		mes_ = "关总线";
	}
	ep1_excuedcmd = 0;
	Ep1_SendCmd(param);
	var rtv = await Ep1_WaitCmdExcu(epro1_oper.cmd,1000);
	if(rtv == 0)
	{
		ShowCommMes(mes_,MesgType.MESG_TYPE_INFO);
	}
	return rtv;
}
async function Ep1_SwitchHeartBeat()
{
	var mes_ = ""
	var param  = [0,0,0];
	if(ep1_bus_heartbeat == 0)
	{
		param[2] = 1;
		ep1_bus_heartbeat = 1;
		mes_ = "开心跳";
	}else{
		
		param[2] = 0;
		ep1_bus_heartbeat = 0;
		mes_ = "关心跳";
	}
	ep1_excuedcmd = 0;
	Ep1_SendCmd(param);
	var rtv = await Ep1_WaitCmdExcu(epro1_oper.cmd,1000);
	if(rtv == 0)
	{
		ShowCommMes(mes_,MesgType.MESG_TYPE_INFO);
	}
	return rtv;
}
//同步非阻塞延时
async function Ep1_WaitCmdExcu( cmd,  time_out)
{
    if(time_out == 0)
        return 0;
    time_out = parseInt ( (time_out+19)/20);
    ep1_excued_rtv = 0;
    while((time_out > 0) && (ep1_excued_rtv < 1))
    {
        if(ep1_excuedcmd == cmd)
        {
            break;
        }
        await  TransSleep(20);
        time_out--;
    }
   if(ep1_excued_rtv != 0)
    {
    	 ShowCommMes("命令执行失败",MesgType.MESG_TYPE_ERROR,ep1_log_flag);
    	 return 2;
    }
    if(time_out > 0 )
    {
    	
        return 0;
    }  
   else
    {
       ShowCommMes("EP1 通信超时 oper_cmd "+cmd,MesgType.MESG_TYPE_ERROR,ep1_log_flag);
       return  1;

    }
    
}

async function Ep1_ReadCmdByAddr(cmd,read_len)
{
	var param = [];
	var cmd_buf = Ep1_CmdData(epro1_oper.commaddr,8,cmd,param,read_len+4);
	ep1_excuedcmd = 0;
	Ep1_SendCmd(cmd_buf);
	var rtv = await Ep1_WaitCmdExcu(epro1_oper.cmd,1000);
	var read_buf = [];
	if(rtv == 0)
	{
		read_buf = ArrayCopy(ep1_recive_buf,read_buf,11,read_len);
		//read_buf = [0x35, 0x38, 0x31, 0x39, 0x30, 0x30, 0x32, 0x33];
	}
	return read_buf;
}


async function Ep1_WriteFlash_Program(regaddr,programdata)
{
	var cmd_buf = [];
	regaddr >>= 2; //地址除以4
	cmd_buf[0] = regaddr & 0xFF; 
	cmd_buf[1] = (regaddr >> 8) & 0xFF;
	cmd_buf[2] = programdata.length;
	cmd_buf[3] = 0;
	for(var index = 0; index < programdata.length;index++)
	{
		cmd_buf[4+index] = programdata[index];
	}
	cmd_buf = Ep1_CmdData(epro1_oper.comaddr,63,0,cmd_buf,2);
	ep1_excuedcmd = 0;
	Ep1_SendCmd(cmd_buf);
	var rtv = await Ep1_WaitCmdExcu(epro1_oper.cmd,1000);
	return rtv;
	
}

async function Ep1_WriteFlash(eraseType)
{
	
	var regexp = /(,|;|0x|0X)/g;
	var w_data = epro1_oper.flash_w_data.replace(regexp," ");
	var w_data_array = w_data.split(" ");
	var w_data_temp = '' ;
	for(var index = 0; index < w_data_array.length;index++)
	{
		var str = w_data_array[index];
		if(str.length < 1)
		{
			continue;
		}else if(str.length == 1)
		{
			str = "0"+str;
		}
		if(str.length != 2)
		{
			continue;
		}
		w_data_temp += str;
	}
	w_data = HexStr2Bytes(w_data_temp);
	if(w_data.length < 1)
	{
		return;
	}
	epro1_oper.flash_w_data = w_data;
	var cmd_buf = [];
	var regaddr = epro1_oper.flash_r_bgaddr;
	regaddr >>= 2; //地址除以4
	cmd_buf[0] = regaddr & 0xFF; 
	cmd_buf[1] = (regaddr >> 8) & 0xFF;
	cmd_buf[2] = w_data.length;
	cmd_buf[3] = eraseType;
	for(var index = 0; index < w_data.length;index++)
	{
		cmd_buf[4+index] = w_data[index];
	}
	cmd_buf = Ep1_CmdData(epro1_oper.commaddr,63,0,cmd_buf,2);
	ep1_excuedcmd = 0;
	Ep1_SendCmd(cmd_buf);
	var rtv = await Ep1_WaitCmdExcu(epro1_oper.cmd,1000);
	if(rtv == 0)
	{
		var mes = "地址 "+epro1_oper.commaddr+" 向Flash地址" + epro1_oper.flash_r_bgaddr+" 写数据成功 "+epro1_oper.flash_w_data;
		ShowCommMes(mes,MesgType.MESG_TYPE_INFO);
	}
	return rtv;
	
}
async function Ep1_ReadFlashCmd()
{
	var cmd_buf = [];
	var regaddr = epro1_oper.flash_r_bgaddr;
	regaddr >>= 2; //地址除以4
	cmd_buf[0] = regaddr & 0xFF; 
	cmd_buf[1] = (regaddr >> 8) & 0xFF;
	cmd_buf[2] = epro1_oper.flash_r_len;
	cmd_buf = Ep1_CmdData(epro1_oper.commaddr,62,0,cmd_buf,epro1_oper.flash_r_len+6);
	ep1_excuedcmd = 0;
	Ep1_SendCmd(cmd_buf);
	var rtv = await Ep1_WaitCmdExcu(epro1_oper.cmd,1000);
	var read_buf = [];
	if(rtv == 0)
	{
		read_buf = ArrayCopy(ep1_recive_buf,read_buf,13,epro1_oper.flash_r_len);
		epro1_oper.flash_r_data = Bytes2Str(read_buf);
		var mes = "地址 "+epro1_oper.commaddr+" 读取Flash地址 "+ epro1_oper.flash_r_bgaddr+" 数据 " + epro1_oper.flash_r_data;
		ShowCommMes(mes,MesgType.MESG_TYPE_INFO);
		$("#ep1_flash_r_data").val(epro1_oper.flash_r_data);
		//read_buf = [0x35, 0x38, 0x31, 0x39, 0x30, 0x30, 0x32, 0x33];
	}
	return read_buf;
}
async function Ep1_FastCfgCmd()
{
	var uid_arr =  Str2Bytes(epro1_oper.uid);  
	var feature = PrapareUIDFeatrue2(uid_arr);
	var temp_buf = [];
	temp_buf[0] = epro1_oper.delayfire & 0xFF;
	temp_buf[1] = (epro1_oper.delayfire >> 8) & 0xFF;
	ArrayAppend(temp_buf,feature,feature.length,2);
	cmd_buf = Ep1_CmdData(epro1_oper.commaddr,19,0,feature,5);
	ep1_excuedcmd = 0;
	Ep1_SendCmd(cmd_buf);
	var rtv = await Ep1_WaitCmdExcu(epro1_oper.cmd,1000);
	if(rtv == 0)
	{
		var states_buf = []; 
		ArrayCopy(ep1_recive_buf,states_buf,10,2);
		var delay_ = (ep1_recive_buf[9] & 0xFF) << 8;
		delay_ += (ep1_recive_buf[8] & 0xFF)
		if(delay_ < 5 || delay_ > 30005)
			delay_ = "未设置";
		else
		{
			delay_ -= 5;
			epro1_oper.delayfire = delay_;
			$("#ep1_delayfire").val(delay_);
		}
			
		epro1_oper.sys_states = Bytes2Str(states_buf);
		$("#ep1_sys_states").val(epro1_oper.sys_states);
		var mes = "地址 "+ epro1_oper.commaddr+" 状态值 "+ epro1_oper.sys_states+" 延时：" + delay_;
		ShowCommMes(mes,MesgType.MESG_TYPE_INFO);
	}
	return rtv;
}
async function Ep1_CheckSelfCmd(addr,checktype)
{
	var param = [];
	var cmd = 0;
	switch(checktype)
	{
		case 0: cmd = 16 ; break;//标准自检
		case 1: cmd = 19 ;break;//工厂半成品检
		case 3:	cmd = 22 ;break;//起爆开关检测
	}
	var cmd_buf = Ep1_CmdData(addr,8,cmd,param,0);
	ep1_excuedcmd = 0;
	Ep1_SendCmd(cmd_buf);
	var rtv = await Ep1_WaitCmdExcu(epro1_oper.cmd,1000);
	return rtv;
	
}
async function Ep1_ReadFirmwareCmd()
{
	var read_buf = await Ep1_ReadCmdByAddr(4,4);
	if(read_buf.length > 1)
	{
		epro1_oper.firmware = Bytes2Str(read_buf);
		var mes = "地址 "+ epro1_oper.commaddr+" 固件版本  "+ epro1_oper.firmware;
		ShowCommMes(mes,MesgType.MESG_TYPE_INFO);
		$("#ep1_firmware").val(epro1_oper.firmware);
		return 0;
	}
	return 1;
	
}
async function Ep1_ReadSysStatesCmd()
{
	var states_buf = await Ep1_ReadCmdByAddr(3,4);
	if(states_buf.length > 1)
	{
		epro1_oper.sys_states = Bytes2Str(states_buf);
		$("#ep1_sys_states").val(epro1_oper.sys_states);
		var mes = "地址 "+ epro1_oper.commaddr+" 状态值 "+ epro1_oper.sys_states;
		ShowCommMes(mes,MesgType.MESG_TYPE_INFO);
		return 0;
	}
	return 1;
	
}

async function Ep1_VerifiPwdCmd(addr,pwd)
{
	var pwd_buf = Str2Bytes(epro1_oper.pwd);
	var cmd_buf = Ep1_CmdData(epro1_oper.commaddr,4,0,pwd_buf,2);
	ep1_excuedcmd = 0;
	Ep1_SendCmd(cmd_buf);
	var rtv = await Ep1_WaitCmdExcu(epro1_oper.cmd,1000);
	if(rtv == 0)
	{
		var mes = "地址 "+ epro1_oper.commaddr+" 密码验证成功"
		ShowCommMes(mes,MesgType.MESG_TYPE_INFO);
	}
	return rtv;
}

async function Ep1_SetPWDFlag()
{
	var param = [];
	var read_len = 0;
	if((epro1_oper.commaddr& 0x03FF) != 0)
		read_len = 2;
	var cmd_buf = Ep1_CmdData(epro1_oper.commaddr,8,24,param,read_len);
	ep1_excuedcmd = 0;
	Ep1_SendCmd(cmd_buf);
	var rtv = await Ep1_WaitCmdExcu(epro1_oper.cmd,1000);
	if(rtv == 0){
		ShowCommMes("密码标志置位成功",MesgType.MESG_TYPE_INFO);
	}
	return rtv ;
}

async function Ep1_ClkAmend(bgaddr,endaddr)
{
	var param = [];
	param[0] = bgaddr&0xFF;
	param[1] = (bgaddr >> 8)&0xFF;
	param[2] = endaddr&0xFF;
	param[3] = (endaddr >> 8) &0xFF;
	var cmd_buf = Ep1_CmdData(0,8,12,param,0);
	ep1_excuedcmd = 0;
	Ep1_SendCmd(cmd_buf);
	var rtv = await Ep1_WaitCmdExcu(epro1_oper.cmd,1000);
	return rtv;
}
/*
 * type 巡检类型 0 起爆巡检 1 在线巡检
 */
async function Ep1_Inspect(bgaddr,endaddr,type)
{
	var param = [];
	var cmd;
	param[0] = bgaddr&0xFF;
	param[1] = (bgaddr >> 8)&0xFF;
	param[2] = endaddr&0xFF;
	param[3] = (endaddr >> 8) &0xFF;
	if(type > 0)
	{
		cmd = 29;
	}else{
		cmd = 15;
	}
	var rtd = {
		rtv : 1,
		ok_addr:[],
		ng_addr:[],
	};
	var cmd_buf = Ep1_CmdData(0,8,cmd,param,0);
	ep1_excuedcmd = 0;
	Ep1_SendCmd(cmd_buf);
	var rtv = await Ep1_WaitCmdExcu(epro1_oper.cmd,1000);
	
	rtd.rtv =  rtv;
	if(rtv != 0)
		return rtd;
    var ok_addr_buf = [];
	var ng_addr_buf = [];
	var index = 8;
	var inspect_addr = bgaddr;
	var ok_index = 0;
	var ng_index = 0;
	while(inspect_addr < endaddr)
	{
		var data = ep1_recive_buf[index];//？待定
		index++;
		for(var i = 0; i < 8 ;i++)
		{
			if(inspect_addr >= endaddr)
			{
				break;
			}
			if((data & 0x01) > 0) 
			{
				ok_addr_buf[ok_index++] = inspect_addr;
			}else{
				ng_addr_buf[ng_index++] = inspect_addr;
			}
			inspect_addr++;
			data >>= 1;
		}
	}
	rtd.ok_addr = ok_addr_buf;
	rtd.ng_addr = ng_addr_buf;
	return rtd;
}
async function Ep1_DoCmd(addr,cmd)
{
	var param = [];
	var cmd_buf = Ep1_CmdData(addr,8,cmd,param,0);
	ep1_excuedcmd = 0;
	Ep1_SendCmd(cmd_buf);
	var rtv = await Ep1_WaitCmdExcu(epro1_oper.cmd,1000);
	return rtv;
}
async function Ep1_Charge()
{
	var rtv =  await Ep1_DoCmd(0,10);
	if(rtv == 0){
		ShowCommMes("执行充电成功",MesgType.MESG_TYPE_INFO);
	}
	return rtv;
}
async function Ep1_ChipReset()
{
	var rtv =  await Ep1_DoCmd(0,0xFD);
	if(rtv == 0){
		ShowCommMes("芯片复位执行成功",MesgType.MESG_TYPE_INFO);
	}
	return rtv;
}
async function Ep1_DisCharge()
{
	var rtv = await Ep1_DoCmd(0,11);
	if(rtv == 0){
		ShowCommMes("执行放电成功",MesgType.MESG_TYPE_INFO);
	}
	return rtv;
}
async function Ep1_OnLineCheck()
{
	var param = [];
	var cmd_buf = Ep1_CmdData(epro1_oper.commaddr,9,0,param,2);
	ep1_excuedcmd = 0;
	Ep1_SendCmd(cmd_buf);
	var rtv = await Ep1_WaitCmdExcu(epro1_oper.cmd,1000);
	if(rtv == 0){
		ShowCommMes("模块在线",MesgType.MESG_TYPE_INFO);
	}
	return rtv;
}
async function Ep1_ClkAmend_Task()
{

	var bgaddr = epro1_oper.cycle_bgaddr;
	while(bgaddr < epro1_oper.cycle_endaddr)
	{
		await Ep1_ClkAmend(bgaddr,bgaddr+epro1_oper.cycle_group_count);
		bgaddr+= epro1_oper.cycle_group_count;
		await TransSleep(1000);
		
	}
}
async function Ep1_Inspect_Task(type)
{
	var bgaddr = epro1_oper.cycle_bgaddr;
	var endaddr_ = 0;
	while(bgaddr < epro1_oper.cycle_endaddr)
	{
		endaddr_ = bgaddr+epro1_oper.cycle_group_count;
		if(endaddr_ > epro1_oper.cycle_endaddr )
		{
			endaddr_ = epro1_oper.cycle_endaddr;
		}
		var rtd = await Ep1_Inspect(bgaddr,endaddr_,type);
		bgaddr+= epro1_oper.cycle_group_count;
		await TransSleep(1000);
		var mes = "巡检成功： ";
		for(var index = 0; index < rtd.ok_addr.length;index++)
		{
			mes += rtd.ok_addr[index]+" ";
		}
		if(rtd.ok_addr.length > 0)
			ShowCommMes(mes,MesgType.MESG_TYPE_INFO);
		var mes = "巡检失败： ";
		for(var index = 0; index < rtd.ng_addr.length;index++)
		{
			mes += rtd.ng_addr[index]+" ";
		}
		if(rtd.ng_addr.length > 0)
			ShowCommMes(mes,MesgType.MESG_TYPE_ERROR);
	}
}
async function Ep1_Sleep()
{
	var rtv =  await Ep1_DoCmd(epro1_oper.commaddr,14);
	if(rtv == 0){
		ShowCommMes("执行休眠成功",MesgType.MESG_TYPE_INFO);
	}
	return rtv;
}
async function Ep1_AWake()
{
	var param = [];
	var cmd_buf = Ep1_CmdData(epro1_oper.commaddr,9,0,param,2);
	ep1_excuedcmd = 0;
	Ep1_SendCmd(cmd_buf);
	var rtv = await Ep1_WaitCmdExcu(epro1_oper.cmd,1000);
	if(rtv == 0){
		ShowCommMes("执行唤醒成功",MesgType.MESG_TYPE_INFO);
	}
	return rtv;
}
async function Ep1_Blast()
{
	var rtv = await Ep1_DoCmd(0,13);
	if(rtv == 0){
		ShowCommMes("执行起爆成功",MesgType.MESG_TYPE_INFO);
	}
	return rtv;
}
async function Ep1_ResetPWDFlag()
{
	
	var param = [];
	var read_len = 0;
	if((epro1_oper.commaddr& 0x03FF) != 0)
		read_len = 2;
	var cmd_buf = Ep1_CmdData(epro1_oper.commaddr,8,25,param,read_len);
	ep1_excuedcmd = 0;
	Ep1_SendCmd(cmd_buf);
	var rtv = await Ep1_WaitCmdExcu(epro1_oper.cmd,1000);
	if(rtv == 0){
		ShowCommMes("重置密码成功",MesgType.MESG_TYPE_INFO);
	}
	return rtv;
}
async function Ep1_RunBootLoader()
{
	var rtv =  await Ep1_DoCmd(epro1_oper.commaddr,0xFE);
	if(rtv == 0){
		ShowCommMes("执行跳转成功",MesgType.MESG_TYPE_INFO);
	}
	return rtv;
}
async function Ep1_RestAddr()
{
	param[0] = epro1_oper.commaddr & 0xFF;
	param[1] = (epro1_oper.commaddr >> 8) & 0xFF;
	var rtv = await Ep1_WriteRunCfgCmd(1,8,2,param);
	if(rtv == 0)
	{
		ShowCommMes("地址 "+ epro1_oper.commaddr+" 延时设置成功",MesgType.MESG_TYPE_INFO);
	}
	return rtv;
}
async function Ep1_ReadUID()
{
	
	var read_buf = await  Ep1_ReadCmdByAddr(1,15);
	if(read_buf.length > 1){
		epro1_oper.uid = String.fromCharCode.apply(null,read_buf.slice(0,15));
		var mes = "地址 "+epro1_oper.commaddr +"  UID："+ epro1_oper.uid;
		ShowCommMes(mes,MesgType.MESG_TYPE_INFO);
		$("#ep1_uid").val(epro1_oper.uid);
		return 0;
	}
	return 1;
}
async function Ep1_WriteUID()
{
	var uid_arr = Str2Bytes(epro1_oper.uid);
	var cmd_buf = Ep1_CmdData(epro1_oper.commaddr,1,0,uid_arr,2);
	ep1_excuedcmd = 0;
	Ep1_SendCmd(cmd_buf);
	var rtv = await Ep1_WaitCmdExcu(epro1_oper.cmd,1000);
	if(rtv == 0)
	{
		ShowCommMes(epro1_oper.commaddr + " UID 写入成功",MesgType.MESG_TYPE_INFO);
	}
	return rtv;
}

async function Ep1_VerifiUidFeature()
{
	var uid_arr = Str2Bytes(epro1_oper.uid);
	var feature = PrapareUIDFeatrue2(uid_arr);
	var cmd_buf = Ep1_CmdData(epro1_oper.commaddr,17,0,feature,2);
	ep1_excuedcmd = 0;
	Ep1_SendCmd(cmd_buf);
	var rtv = await Ep1_WaitCmdExcu(epro1_oper.cmd,1000);
	if(rtv == 0)
	{
		ShowCommMes(epro1_oper.commaddr + " UID 特征码验证成功",MesgType.MESG_TYPE_INFO);
	}
	return rtv;
}


async function Ep1_ReadPWD()
{
	var param = Str2Bytes(epro1_oper.uid);
	param[param.length]= 0x02;
	var cmd_buf = Ep1_CmdData(0,15,0,param,12);
	cmd_buf[2] = 0x08;
	ep1_excuedcmd = 0;
	Ep1_SendCmd(cmd_buf);
	var rtv = await Ep1_WaitCmdExcu(epro1_oper.cmd,1000);
	if(rtv == 0){
		var read_buf = [] ;
		ArrayCopy(ep1_recive_buf,read_buf,11,8);
		epro1_oper.pwd = String.fromCharCode.apply(null,read_buf.slice(0,8));
		var mes = "地址 "+epro1_oper.commaddr +"  PWD："+ epro1_oper.pwd;
		ShowCommMes(mes,MesgType.MESG_TYPE_INFO);
		$("#ep1_pwd").val(epro1_oper.pwd);
	}
	return rtv;
}

async function Ep1_WritePWD()
{
	var pwd_arr = Str2Bytes(epro1_oper.pwd);
	var cmd_buf = Ep1_CmdData(epro1_oper.commaddr,2,0,pwd_arr,2);
	ep1_excuedcmd = 0;
	Ep1_SendCmd(cmd_buf);
	var rtv = await Ep1_WaitCmdExcu(epro1_oper.cmd,1000);
	if(rtv == 0){
		ShowCommMes(epro1_oper.commaddr + " 密码 写入成功",MesgType.MESG_TYPE_INFO);
	}
	return rtv;
}



async function Ep1_SearchTask()
{
	var param = [];
	param[0] = epro1_oper.auset_addr_fac & 0x0FF;
	param[1] = (epro1_oper.auset_addr_fac >> 8) & 0x0FF;
	var cmd_buf = Ep1_CmdData(0,8,28,param,0)
	ep1_excuedcmd = 0;
	Ep1_SendCmd(cmd_buf);
	var rtv = await Ep1_WaitCmdExcu(epro1_oper.cmd,1000);
	if(rtv == 0){
		ShowCommMes("设置自动分配地址因子成功 " + epro1_oper.auset_addr_fac  ,MesgType.MESG_TYPE_INFO);
	}
	return rtv;
}
async function Ep1_SetReadClass()
{
	var param = [];
	param[0] = epro1_oper.readrate_class & 0x0FF;
	var cmd_buf = Ep1_CmdData(0,8,27,param,0)
	ep1_excuedcmd = 0;
	Ep1_SendCmd(cmd_buf);
	var rtv = await Ep1_WaitCmdExcu(epro1_oper.cmd,1000);
	if(rtv == 0){
		ShowCommMes("设置通讯档位成功 " ,MesgType.MESG_TYPE_INFO);
	}
	return rtv;
}
async function Ep1_ReadDelay()
{
	 var data = await  Ep1_ReadCmdByAddr(8,2);
	 if(data.length > 1){
	  {
	  	var delay_ = data[1];
	  	delay_ <<= 8;
	  	delay_ |= data[0];
	  	var mes ="";
	  	if(delay_ < 5)
	  	{
	  		mes = "地址："+ epro1_oper.commaddr +" 未设置";
	  		epro1_oper.delayfire = 0;
	  	}else{
	  		delay_ -= 5;
	  		mes = "地址："+ epro1_oper.commaddr +" 延时为 "+delay_;
	  		$("#ep1_delayfire").val(delay_);
	  		epro1_oper.delayfire = delay_;
	  	}
	  	ShowCommMes(mes,MesgType.MESG_TYPE_INFO);
	  }
		return 0;
	}
	 return 1;
 }
async function Ep1_WriteDelay()
{
	var param = [];
	param[0] = epro1_oper.delayfire & 0xFF;
	param[1] = (epro1_oper.delayfire >> 8) & 0xFF;
	var cmd_buf = Ep1_CmdData(epro1_oper.commaddr,5,0,param,2);
	ep1_excuedcmd = 0;
	Ep1_SendCmd(cmd_buf);
	var rtv = await Ep1_WaitCmdExcu(epro1_oper.cmd,1000);
	if(rtv == 0){
		ShowCommMes("地址 "+epro1_oper.commaddr + " 延时设置成功"  ,MesgType.MESG_TYPE_INFO);
	}
	return rtv;
}

async function Ep1_WriteEnhanceTime()
{
	var param = [];
	param[0] = epro1_oper.delayfire & 0xFF;
	param[1] = (epro1_oper.delayfire >> 8) & 0xFF;
	var cmd_buf = Ep1_CmdData(epro1_oper.commaddr,18,0,param,2);
	ep1_excuedcmd = 0;
	Ep1_SendCmd(cmd_buf);
	var rtv = await Ep1_WaitCmdExcu(epro1_oper.cmd,1000);
	if(rtv == 0){
		ShowCommMes("地址 "+epro1_oper.commaddr + " 抗震延时设置成功"  ,MesgType.MESG_TYPE_INFO);
	}
	return rtv;
}

async function Ep1_ReadAddr()
{
	var param = Str2Bytes(epro1_oper.uid);
	param[param.length]= 0x07;
	var cmd_buf = Ep1_CmdData(0,15,0,param,6);
	cmd_buf[2] = 0x08;
	ep1_excuedcmd = 0;
	Ep1_SendCmd(cmd_buf);
	var rtv = await Ep1_WaitCmdExcu(epro1_oper.cmd,1000);
	if(rtv == 0)
	{
	 	var read_buf = [];
		ArrayCopy(ep1_recive_buf,read_buf,11,2);
		epro1_oper.commaddr = (read_buf[1] << 8) + (read_buf[0] & 0xFF) ;
		epro1_oper.commaddr &= 0x3FF 
		epro1_oper.pwd = String.fromCharCode.apply(null,read_buf.slice(0,8));
		var mes = "UID  "+epro1_oper.uid +"  地址 "+ epro1_oper.commaddr;
		ShowCommMes(mes,MesgType.MESG_TYPE_INFO);
		$("#ep1_commaddr").val(epro1_oper.commaddr);
	}
	return rtv;
}


async function Ep1_WriteAddr()
{
	var param = Str2Bytes(epro1_oper.uid);
	param[param.length]= epro1_oper.commaddr & 0xFF;
	param[param.length]= (epro1_oper.commaddr >> 8) & 0xFF;
	var cmd_buf = Ep1_CmdData(0,7,0,param,2);
	ep1_excuedcmd = 0;
	Ep1_SendCmd(cmd_buf);
	var rtv = await Ep1_WaitCmdExcu(epro1_oper.cmd,1000);
	if(rtv == 0){
		var mes = "UID  "+epro1_oper.uid +"  设置地址 "+ epro1_oper.commaddr +"成功";
		ShowCommMes(mes,MesgType.MESG_TYPE_INFO);
	}
	return rtv;
}

async function Ep1_BlastSetAddr()
{
	var param = [];
	param[0]= epro1_oper.commaddr & 0xFF;
	param[1]= (epro1_oper.commaddr >> 8) & 0xFF;
	var cmd_buf = Ep1_CmdData(1,7,0,param,2);
	ep1_excuedcmd = 0;
	Ep1_SendCmd(cmd_buf);
	var rtv = await Ep1_WaitCmdExcu(epro1_oper.cmd,1000);
	if(rtv == 0){
		var mes ="广播设置地址 "+ epro1_oper.commaddr +"成功";
		ShowCommMes(mes,MesgType.MESG_TYPE_INFO);
	}
	return rtv;
}

async function Ep1_FireDelayExcue()
{
	var param = [];
	param[0]= epro1_oper.fire_delay_excue & 0xFF;
	param[1]= (epro1_oper.fire_delay_excue >> 8) & 0xFF;
	var cmd_buf = Ep1_CmdData(0,8,26,param,0);
	ep1_excuedcmd = 0;
	Ep1_SendCmd(cmd_buf);
	var rtv = await Ep1_WaitCmdExcu(epro1_oper.cmd,1000);
	if(rtv == 0){
		ShowCommMes("延迟起爆成功",MesgType.MESG_TYPE_INFO);
	}
	return rtv;
}

async function Ep1_ReadAmend()
{
	var data = await Ep1_ReadCmdByAddr(21,2);
	if(data.length > 1)
	{
		var amend = (data[1] << 8) | data[0] ;
		if((amend & 0x8000) > 0)
		{
			var temp = (~0)& (~0xFFFF);
			temp |= amend;
			amend = 0-temp;
		}
		
		mes = "地址："+ epro1_oper.commaddr +" 校准值 "+amend;
	  	ShowCommMes(mes,MesgType.MESG_TYPE_INFO);
	  	$("#ep1_sys_amend").val(amend);
	  	return 0;
	 }
	return 1;
}

async function Ep1_ReadBusV()
{
	var data = await Ep1_ReadCmdByAddr(23,2);
	if(data.length > 1)
	{
		var bus_v = (data[1] << 8) | data[0] ;
		epro1_oper.bus_voltage = (bus_v / 4096)*3.3/0.43*3.43;
		epro1_oper.bus_voltage = epro1_oper.bus_voltage.toFixed(1);
		mes = "地址："+ epro1_oper.commaddr +" 电压值 "+epro1_oper.bus_voltage;
	  	ShowCommMes(mes,MesgType.MESG_TYPE_INFO);
	  	$("#ep1_bus_voltage").val(epro1_oper.bus_voltage);
	  	return 0;
	 }
	return 1;
}

 async function Ep1_LoadFirmwareFile()
{
	if( typeof(ep1_qthandle) != "undefined"  && ep1_qthandle != null )
	{
	   ep1_qthandle.GetFirmWare();
	   ep1_excuedcmd = 0;
	   var rtv = await Ep1_WaitCmdExcu(0xFFFE,10000000);
	   ShowCommMes("选择固件文件",MesgType.MESG_TYPE_INFO);
		if(rtv == 0){
			epro1_oper.update_firmware = ep1_updata_rtvinfo;
			$("#ep1_update_firmware").val(epro1_oper.update_firmware);
		}
	}

}



async function Ep1_JumpLoader()
{
	var rtv =  await Ep1_DoCmd(0,0xFE);
	if(rtv == 0){
		ShowCommMes("跳转运行加载程序设置成功",MesgType.MESG_TYPE_INFO);
	}
	return rtv;
}
async function Ep1_CleanProgram()
{
	var rtv =  await Ep1_DoCmd(0,0xFC);
	if(rtv == 0){
		ShowCommMes("跳转运行加载程序设置成功",MesgType.MESG_TYPE_INFO);
	}
	return rtv;
}
async function Ep1_RunApp()
{
	var file_info = [0,0,0,0,0,0];
	var cmd_buf = Ep1_CmdData(epro1_oper.commaddr,8,0xFD,file_info,0);
	ep1_excuedcmd = 0;
	Ep1_SendCmd(cmd_buf);
	var rtv = await Ep1_WaitCmdExcu(epro1_oper.cmd,1000);
	if(rtv == 0){
		ShowCommMes("运行APP配置成功",MesgType.MESG_TYPE_INFO);
	}
	return rtv;
}
async function Ep1_UpdateEpro()
{
	var file_size = 0;
	var file_info = [];
	var check_sum  = 0;
	if( typeof(ep1_qthandle) != "undefined"  && ep1_qthandle != null )
	{
		ep1_excuedcmd = 0;
		ep1_qthandle.OpenFirmWare(epro1_oper.update_firmware);
	    var rtv = await Ep1_WaitCmdExcu(0xFFFE,10000);
		if(rtv != 0){
			ShowCommMes("文件打开失败",MesgType.MESG_TYPE_ERROR);
		}
		console.log("open file "+ep1_updata_rtvinfo);
		file_info =  JSON.parse(ep1_updata_rtvinfo);
		if(file_info.length != 6)
		{
			ShowCommMes("文件打开失败",MesgType.MESG_TYPE_ERROR);
		}
		file_size = file_info[4] | (file_info[5]<<8);
		ShowCommMes(epro1_oper.update_firmware + " 文件大小： "+file_size +" file_info " + file_info);
	}
	rtv = await Ep1_JumpLoader();
	if(rtv != 0)
	{
		return;
	}
	ShowCommMes("等待从机复位",MesgType.MESG_TYPE_INFO);
	await  TransSleep(2000);
	rtv = await Ep1_Charge();
	if(rtv != 0)
	{
		return;
	}
	await  TransSleep(5000+epro1_oper.delayfire);
	rtv = await Ep1_CleanProgram();
	if(rtv != 0)
	{
		return;
	}
	await  TransSleep(2000);
	ShowCommMes("开始编程");
	var write_len = 0;
	var count = 0;
	var regaddr = 0x400;
	var write_data ;
	while(count < file_size)
	{
		if((count+16) < file_size)
		{
			write_len = 16;
		}else{
			write_len = file_size - count;
		}
		
		
		if( typeof(ep1_qthandle) != "undefined"  && ep1_qthandle != null )
		{
			ep1_excuedcmd = 0;
			ep1_qthandle.ReadFirmWare(count,  write_len);
		   var rtv = await Ep1_WaitCmdExcu(0xFFFE,10000);
			if(rtv != 0){
				ShowCommMes("读取文件数据失败",MesgType.MESG_TYPE_ERROR);
				return ;
			}
		    write_data = JSON.parse(ep1_updata_rtvinfo);
			
		}
		rtv = await Ep1_WriteFlash_Program(regaddr,write_data);
		if(rtv != 0)
		{
			ShowCommMes("地址: "+regaddr.toString(16)+" 写入长度 "+ write_len +" 失败",MesgType.MESG_TYPE_ERROR);
			return;
		}else{
			ShowCommMes("地址: "+regaddr.toString(16)+" 写入长度 "+ write_len +" 成功",MesgType.MESG_TYPE_INFO);
		}
		count += write_len;
		regaddr+= write_len;
	}
	
	await  TransSleep(500);
	ShowCommMes("校验码检测",MesgType.MESG_TYPE_INFO);
	var cmd_buf = Ep1_CmdData(epro1_oper.commaddr,8,0xFD,file_info,0);
	ep1_excuedcmd = 0;
	Ep1_SendCmd(cmd_buf);
	var rtv = await Ep1_WaitCmdExcu(epro1_oper.cmd,1000);
	if(rtv == 0){
		ShowCommMes("校验成功",MesgType.MESG_TYPE_INFO);
	}
	
	
}
async function Ep1_ExcueOperCmd()
{
	var once_excue = 0;
	if(epro1_oper.cycle_test > 0)
	{
		epro1_oper.commaddr = epro1_oper.cycle_bgaddr;
		epro1_oper.uid = epro1_oper.cycle_bguid;
		epro1_oper.delayfire = epro1_oper.cycle_bgdelay;
		epro1_oper.cycle_addr = epro1_oper.cycle_bgaddr;
	}else{
		once_excue = 1;
	}
	while((epro1_oper.cycle_test > 0 && epro1_oper.cycle_runcount > 0) || (once_excue > 0))
	{
		epro1_oper.cycle_runcount--;
		once_excue = 0;
		switch(epro1_oper.cmd )
		{
			case 1 : await Ep1_Charge();break;
			case 2 : await Ep1_DisCharge();break;
			case 3 : await Ep1_OnLineCheck();break;
			case 4 : await Ep1_Blast();break;
			case 5 : await Ep1_ClkAmend_Task();break;
			case 6 : await Ep1_AWake();break;
			case 7 : await Ep1_CheckSelfCmd(0,0);break;
			case 8 : await Ep1_CheckSelfCmd(0,1);break;
			case 9 : await Ep1_CheckSelfCmd(0,3);break;
			case 10: await Ep1_Sleep();break;
			case 11: await Ep1_SwitchBus();break;
			case 12: await Ep1_SwitchHeartBeat();break;
			case 13: await Ep1_Inspect_Task(1);break;
			case 14: await Ep1_Inspect_Task(0);break;
			case 15: await Ep1_ResetPWDFlag();break;
			case 16: await Ep1_FastCfgCmd(); break;
			case 17: await Ep1_ReadUID();break;
			case 18: await Ep1_WriteUID();break;
			case 19: await Ep1_VerifiUidFeature();break;
			case 20: await Ep1_ReadPWD();break;
			case 21: await Ep1_WritePWD();break;
			case 22: await Ep1_VerifiPwdCmd();break;
			case 23: await Ep1_SetPWDFlag();break;
			case 24: await Ep1_ReadDelay();break;
			case 25: await Ep1_WriteDelay();break;
			case 26: await Ep1_WriteEnhanceTime();break;
			case 27: await Ep1_ReadAddr();break;
			case 28: await Ep1_WriteAddr();break;
			case 29: await Ep1_BlastSetAddr();break;
			case 30: await Ep1_FireDelayExcue();break;
			case 31: await Ep1_SearchTask(); break;
			case 32: await Ep1_SetReadClass();break;
			case 33: await Ep1_ReadSysStatesCmd();break;
			case 34: await Ep1_ReadFirmwareCmd();break;
			case 35: await Ep1_ReadAmend();break;
			case 36: await Ep1_ReadBusV();break;
			case 37: await Ep1_ReadFlashCmd();break;
			case 38: await Ep1_WriteFlash(0);break;
			case 39: await Ep1_WriteFlash(1);break;
			case 40: await Ep1_JumpLoader();break;
			case 41: await Ep1_CleanProgram();break;
			case 42: await Ep1_UpdateEpro();break;
			case 43: await Ep1_RunApp();break;
			case 44: epro1_oper.cycle_runcount = 0;Ep1_LoadFirmwareFile();break;
			default : return;
			
		}
		if(epro1_oper.cycle_test > 0)
		{
			if(epro1_oper.cycle_rundelay > 0)
			{
				await  TransSleep(epro1_oper.cycle_rundelay);
			}
			Ep1_CycleParamUpdate();
			
		}
		
	}
	if(epro1_oper.cycle_test > 0)
	{
		var btnobj = $("#ep1_Cycletest");
		epro1_oper.cycle_test = 0;
		btnobj.removeClass("layui-btn-warm");
	}
}
function Ep1_CycleParamUpdate()
{
	if(epro1_oper.cycle_addr < epro1_oper.cycle_endaddr)
	{
		epro1_oper.cycle_addr++;	
	}else{
		epro1_oper.cycle_addr = epro1_oper.cycle_bgaddr;
	}
	epro1_oper.commaddr = epro1_oper.cycle_addr;
	epro1_oper.delayfire = (epro1_oper.commaddr - epro1_oper.cycle_bgaddr)*epro1_oper.cycle_stepdelay + epro1_oper.cycle_bgdelay;
   var flow_str = epro1_oper.cycle_bguid.slice(11,15);
    var uidhead = epro1_oper.cycle_bguid.slice(0,11);
    var flow_num = parseInt(flow_str,10);
    flow_num = flow_num+epro1_oper.commaddr - epro1_oper.cycle_bgaddr;
	epro1_oper.uid = uidhead + IntFormat(4,flow_num);
}
function Ep1_CycleTestBtn()
{
	
	var btnobj = $("#ep1_Cycletest");
	if(epro1_oper.cycle_test > 0)
	{
		epro1_oper.cycle_test = 0;
		btnobj.removeClass("layui-btn-warm");
	}else{
		epro1_oper.cycle_test  = 1;
		btnobj.addClass("layui-btn-warm");
	}
	
}
