/// <summary> /// dataset转化为list的platinfo /// </summary> /// <param name="ds">datable</param> /// <returns></returns> public static List <PlatInfo> DS2List(DataTable dt) { List <PlatInfo> result = new List <PlatInfo>(); for (int j = 0; j < dt.Rows.Count; j++) { PlatInfo temp = (PlatInfo)Activator.CreateInstance(typeof(PlatInfo)); PropertyInfo[] propertys = temp.GetType().GetProperties(); foreach (PropertyInfo pi in propertys) { for (int i = 0; i < dt.Columns.Count; i++) { if (pi.Name.Equals(dt.Columns[i].ColumnName)) { // 数据库NULL值单独处理 if (dt.Rows[j][i] != DBNull.Value) { pi.SetValue(temp, dt.Rows[j][i], null); } else { pi.SetValue(temp, null, null); } break; } } } result.Add(temp); } return(result); }
/// <summary> /// 将datatable转为platinfo对象 /// </summary> /// <param name="dt"></param> /// <returns>不是一条结果就返回null</returns> public static PlatInfo Dt2pl(DataTable dt) { if (dt.Rows.Count != 1) { return(null); } else { PlatInfo temp = (PlatInfo)Activator.CreateInstance(typeof(PlatInfo)); PropertyInfo[] propertys = temp.GetType().GetProperties(); foreach (PropertyInfo pi in propertys) { for (int i = 0; i < dt.Columns.Count; i++) { if (pi.Name.Equals(dt.Columns[i].ColumnName)) { if (dt.Rows[0][i] != DBNull.Value) { pi.SetValue(temp, dt.Rows[0][i], null); } else { pi.SetValue(temp, null, null); } break; } } } return(temp); } }
/// <summary> /// 检测电脑正在使用的检测平台的数目是否超过规定 /// </summary> /// <param name="temp"></param> /// <returns></returns> private static bool IsAllow(PlatInfo temp) { int num = 0; num += (temp.PlatComs.Equals("空闲") || temp.PlatComs.Equals("未启用")) ? 0 : 1; num += (temp.PlatIcs.Equals("空闲") || temp.PlatIcs.Equals("未启用")) ? 0 : 1; num += (temp.PlatChus_msb.Equals("空闲") || temp.PlatChus_msb.Equals("未启用")) ? 0 : 1; num += (temp.PlatChus_xzy.Equals("空闲") || temp.PlatChus_xzy.Equals("未启用")) ? 0 : 1; num += (temp.PlatChus_csb.Equals("空闲") || temp.PlatChus_csb.Equals("未启用")) ? 0 : 1; num += (temp.PlatZhos.Equals("空闲") || temp.PlatZhos.Equals("未启用")) ? 0 : 1; int AllowNum = Convert.ToInt32(CommonFunction.dicBooks["AllowNum"]); return(num < AllowNum ? true : false); }
// 初始化 private void myInitialize() { ssh = null; shell = null; isConnected = false; remoteWorkPath = ""; remoteFolder = "_TensileConvTemp"; tcExeFileName = "TensileConv.out"; devCnt = -1; platInfo = new PlatInfo(); allDevInfo = new List <DevInfo>(); allDevInfo.Clear(); N = 1; W = H = 14; C = 1024; K = 256; OutW = OutH = OutK = OutN = 0; InputSize = WeightSize = OutputSize = "0MB"; Calculation = TheoryElapsedTime = "0"; initInfoFlag = true; kernelParamFlag = false; finishFlag = false; KernelIterations = 100; ElapsedTime = Performence = Efficiency = "0"; BestElapsedTime = BestPerformence = BestEfficiency = "0"; SearchingPercent = 0; SearchedKernel = TotalKernel = 0; TunnedProblem = TotalProblem = 1; pck_order = 123; c_lds_atomic = c_lds_split = c_l2_atomic = c_l2_split = 1; k_out_maps = 8; group_size_x = 64; group_size_y = 1; global_size_x = 1; global_size_y = 1; sig_slot_size = l2_tmp_size = "0MB"; mean_err = 0; }
private void procEnvironmentInfo(String str) { String[] tmpStrArr; Action act; if (str.Contains("*************************************************************************")) { if (platInfoStart == false) { platInfoStart = true; platInfo = new PlatInfo(); allDevInfo = new List <DevInfo>(); allDevInfo.Clear(); } else { platInfoStart = false; act = new Action(() => { tbxPlatName.Text = platInfo.platName; tbxPlatVen.Text = platInfo.platVen; tbxPlatVer.Text = platInfo.platVer; }); this.Dispatcher.Invoke(act); } } if (platInfoStart) { if (str.Contains("Platform Name")) { tmpStrArr = str.Split(new char[] { ':', '=' }); platInfo.platName = tmpStrArr.Last().Trim(); } if (str.Contains("Version")) { tmpStrArr = str.Split(new char[] { ':', '=' }); platInfo.platVer = tmpStrArr.Last().Trim(); } if (str.Contains("Vendor Name")) { tmpStrArr = str.Split(new char[] { ':', '=' }); platInfo.platVen = tmpStrArr.Last().Trim(); } } if (str.Contains("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")) { if (devInfoStart == false) { devInfoStart = true; devInfoTmp = new DevInfo(); devCnt++; } else { devInfoStart = false; allDevInfo.Add(devInfoTmp); act = new Action(() => { lbxDevList.Items.Add("device: " + devCnt.ToString()); lbxDevList.SelectedIndex = 0; tbxDevName.Text = allDevInfo[0].devName; tbxDevVen.Text = allDevInfo[0].devVen; tbxDevVer.Text = allDevInfo[0].rtVer; tbxDevCU.Text = allDevInfo[0].cuNum; tbxDevFreq.Text = allDevInfo[0].freq; tbxDevPerf.Text = allDevInfo[0].perf; }); this.Dispatcher.Invoke(act); } } if (devInfoStart) { if (str.Contains("Vendor Name")) { tmpStrArr = str.Split(new char[] { ':', '=' }); devInfoTmp.devVen = tmpStrArr.Last().Trim(); } if (str.Contains("Device Name")) { tmpStrArr = str.Split(new char[] { ':', '=' }); devInfoTmp.devName = tmpStrArr.Last().Trim(); } if (str.Contains("Runtime Version")) { tmpStrArr = str.Split(new char[] { ':', '=' }); devInfoTmp.rtVer = tmpStrArr.Last().Trim(); } if (str.Contains("CU Number")) { tmpStrArr = str.Split(new char[] { ':', '=' }); devInfoTmp.cuNum = tmpStrArr.Last().Trim(); } if (str.Contains("Core Frequency")) { tmpStrArr = str.Split(new char[] { ':', '=' }); devInfoTmp.freq = tmpStrArr.Last().Trim(); } if (str.Contains("Performance(fp32)")) { tmpStrArr = str.Split(new char[] { ':', '=' }); devInfoTmp.perf = tmpStrArr.Last().Trim(); } } }
public PhoneInfo(DppInfo ddp, PlatInfo plat, byte[] rkh) { Ddp = ddp; Plat = plat; Rkh = rkh; }
/// <summary> /// id+ip+port+type+入网/出网(1+4+2+1+1) /// </summary> /// <param name="session"></param> /// <param name="requestInfo"></param> public override void ExecuteCommand(MySession session, MyRequestInfo requestInfo) { lock (CommonFunction.obj_66) { string re = "00"; bool f; bool isallowexit; Myadapter_p = new Dt_PlateInfoTableAdapter(); myadapter_w = new DT_WaringPlatTableAdapter(); var info = requestInfo; int id = Convert.ToInt32(info.Data.Substring(2, 2), 16); string ip = DataHelper.Str2IP(info.Data.Substring(4, 8)); string port = Convert.ToInt32(info.Data.Substring(12, 4), 16).ToString(); string type = info.Data.Substring(16, 2); string cmd = info.Data.Substring(18, 2); //入网 根据id查询数据库(有,更新数据)(没有,插入数据) //出网 根据id查询数据库(有,更新数据) (没有,不做操作) 检查其状态是否可以立即出网,并回复。若不可以标记状态为待出网,通知其下次上传。 //更新platinfo 和 heart 入网成功加入heart,出网成功移除heart,dictionary存储heartinfo //加锁,当执行01操作时不能执行出网操作,避免 if (cmd.Equals("AA")) { //入网 try { pl = Replat(id); if (pl == null) { pl = new PlatInfo(); f = false; } else { f = true; } switch (type) { case "01": heart = new HeartInfo(id, "命令检测", ip, port, 00, "正常"); pl.PlatComs = "空闲"; pl.PlatComp = port; break; case "02": heart = new HeartInfo(id, "IC卡卡控", ip, port, 00, "正常"); pl.PlatIcs = "空闲"; pl.PlatIcp = port; break; case "03": heart = new HeartInfo(id, "膜式表初检", ip, port, 00, "正常"); pl.PlatChus_msb = "空闲"; pl.PlatChup_msb = port; break; case "04": heart = new HeartInfo(id, "修正仪初检", ip, port, 00, "正常"); pl.PlatChus_xzy = "空闲"; pl.PlatChup_xzy = port; break; case "05": heart = new HeartInfo(id, "超声波初检", ip, port, 00, "正常"); pl.PlatChus_csb = "空闲"; pl.PlatChup_csb = port; break; case "06": heart = new HeartInfo(id, "终检", ip, port, 00, "正常"); pl.PlatZhos = "空闲"; pl.PlatZhop = port; break; } pl.IP = ip; pl.id = id; if (f) { Myadapter_p.UpdatePlat( pl.IP, pl.PlatComs, pl.PlatIcs, pl.PlatChus_msb, pl.PlatChus_xzy, pl.PlatChus_csb, pl.PlatZhos, pl.PlatComp, pl.PlatIcp, pl.PlatChup_msb, pl.PlatChup_xzy, pl.PlatChup_csb, pl.PlatZhop, pl.id); } else { Myadapter_p.InsertPlat( pl.id, pl.IP, pl.PlatComs, pl.PlatIcs, pl.PlatChus_msb, pl.PlatChus_xzy, pl.PlatChus_csb, pl.PlatZhos, pl.PlatComp, pl.PlatIcp, pl.PlatChup_msb, pl.PlatChup_xzy, pl.PlatChup_csb, pl.PlatZhop); } //入网成功 CommonFunction.platInfos[id] = pl; CommonFunction.hearts[id + type] = heart; re = "AA"; //此检测平台是否为异常的平台,修改数据库 DataTable dtw = myadapter_w.GetDataBy_it(id.ToString(), heart.Type, 0); if (dtw.Rows.Count != 0) { myadapter_w.UpdateMP(1, DateTime.Now, heart.Type, id.ToString(), 0); PostLl(id.ToString(), heart.Type, "正常"); } LogHelper.Info(id + " " + type + " 入网成功"); } catch (Exception e) { LogHelper.Error("入网失败" + e); re = "55"; } } else if (cmd.Equals("55")) { //出网 lock (CommonFunction.obj_44) { try { pl = Replat(id); if (pl != null) { switch (type) { case "01": if (pl.PlatComs.Equals("空闲") || pl.PlatComs.Equals("待出网")) { pl.PlatComs = "未启用"; isallowexit = true; } else { pl.PlatComs = "待出网"; isallowexit = false; } break; case "02": if (pl.PlatIcs.Equals("空闲") || pl.PlatIcs.Equals("待出网")) { pl.PlatIcs = "未启用"; isallowexit = true; } else { pl.PlatIcs = "待出网"; isallowexit = false; } break; case "03": if (pl.PlatChus_msb.Equals("空闲") || pl.PlatChus_msb.Equals("待出网")) { pl.PlatChus_msb = "未启用"; isallowexit = true; } else { pl.PlatChus_msb = "待出网"; isallowexit = false; } break; case "04": if (pl.PlatChus_xzy.Equals("空闲") || pl.PlatChus_xzy.Equals("待出网")) { pl.PlatChus_xzy = "未启用"; isallowexit = true; } else { pl.PlatChus_xzy = "待出网"; isallowexit = false; } break; case "05": if (pl.PlatChus_csb.Equals("空闲") || pl.PlatChus_csb.Equals("待出网")) { pl.PlatChus_csb = "未启用"; isallowexit = true; } else { pl.PlatChus_csb = "待出网"; isallowexit = false; } break; case "06": if (pl.PlatZhos.Equals("空闲") || pl.PlatZhos.Equals("待出网")) { pl.PlatZhos = "未启用"; isallowexit = true; } else { pl.PlatZhos = "待出网"; isallowexit = false; } break; default: isallowexit = false; break; } Myadapter_p.UpdatePlat( pl.IP, pl.PlatComs, pl.PlatIcs, pl.PlatChus_msb, pl.PlatChus_xzy, pl.PlatChus_csb, pl.PlatZhos, pl.PlatComp, pl.PlatIcp, pl.PlatChup_msb, pl.PlatChup_xzy, pl.PlatChup_csb, pl.PlatZhop, pl.id); CommonFunction.platInfos[id] = pl; if (isallowexit) { CommonFunction.hearts.Remove(id + type); re = "AA"; LogHelper.Info(id + " " + type + " 出网成功"); } else { re = "BB"; } } } catch (Exception e) { LogHelper.Error("出网失败" + e); re = "55"; } } } try { //回复检测平台,入网成功或失败,出网成功或失败或等一次检测 IPAddress Ip = IPAddress.Parse(ip); int Port = Convert.ToInt32(port); string send_66 = DownCommond.GenerateSendFrame("66" + re, info, true, false); Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); socket.Connect(Ip, Port); socket.Send(DataHelper.Str2Byte(send_66)); socket.Close(); LogHelper.Info("回复66:" + send_66); } catch (Exception e) { LogHelper.Error("无法连接入网检测平台" + e); } } }
/// <summary> /// 输入检测类型,返回安排的检测平台号 /// 有优先测表的情况下,普通表无法使用最后两台检测主机,优先表可以使用所有的检测主机 /// </summary> /// <param name="number"></param> /// <returns></returns> private static string[] Plat_AnPai(int number, string type, bool ishavepri, bool isprivilege) { int count_p = CommonFunction.platInfos.Count; string[] result = new string[] { "空", "空", "空", "空" }; if (ishavepri && !isprivilege) { count_p = Math.Max(0, count_p - 2); } try { switch (number) { case 1: for (int i = 0; i < count_p; i++) { int id = CommonFunction.platInfos[i].id; //根据id查询出一条platinfo的记录 DataTable dt = Myadapter_p.GetDataBy1(id); PlatInfo temp = DataHelper.Dt2pl(dt); if (temp.PlatComs.Equals("空闲") && IsAllow(temp)) { temp.PlatComs = "准备"; result[0] = id.ToString(); result[1] = temp.IP; result[2] = temp.PlatComp; result[3] = "PlatComs"; // Myadapter_p.UpdatePlatCom(temp.PlatComs, id); return(result); } } break; case 2: for (int i = 0; i < count_p; i++) { int id = CommonFunction.platInfos[i].id; //根据id查询出一条platinfo的记录 DataTable dt = Myadapter_p.GetDataBy1(id); PlatInfo temp = DataHelper.Dt2pl(dt); if (temp.PlatIcs.Equals("空闲") && IsAllow(temp)) { temp.PlatIcs = "准备"; result[0] = id.ToString(); result[1] = temp.IP; result[2] = temp.PlatIcp; result[3] = "PlatIcs"; // Myadapter_p.UpdatePlatIc(temp.PlatIcs, id); return(result); } } break; case 3: for (int i = 0; i < count_p; i++) { int id = CommonFunction.platInfos[i].id; //根据id查询出一条platinfo的记录 DataTable dt = Myadapter_p.GetDataBy1(id); PlatInfo temp = DataHelper.Dt2pl(dt); if (type.Equals("膜式表") || type.Equals("IC卡-膜式表")) { if (temp.PlatChus_msb.Equals("空闲") && IsAllow(temp)) { //temp.PlatChus_msb = "准备"; result[0] = id.ToString(); result[1] = temp.IP; result[2] = temp.PlatChup_msb; result[3] = "PlatChus_msb"; // Myadapter_p.UpdatePlatChu_msb(temp.PlatChus_msb, id); return(result); } } if (type.Equals("修正仪") || type.Equals("IC卡-修正仪")) { if (temp.PlatChus_xzy.Equals("空闲") && IsAllow(temp)) { //temp.PlatChus_xzy = "准备"; result[0] = id.ToString(); result[1] = temp.IP; result[2] = temp.PlatChup_xzy; result[3] = "PlatChus_xzy"; // Myadapter_p.UpdatePlatChu_xzy(temp.PlatChus_xzy, id); return(result); } } if (type.Equals("超声波") || type.Equals("IC卡-超声波")) { if (temp.PlatChus_csb.Equals("空闲") && IsAllow(temp)) { //temp.PlatChus_csb = "准备"; result[0] = id.ToString(); result[1] = temp.IP; result[2] = temp.PlatChup_csb; result[3] = "PlatChus_csb"; // Myadapter_p.UpdatePlatChu_csb(temp.PlatChus_csb, id); return(result); } } } break; case 4: for (int i = 0; i < count_p; i++) { int id = CommonFunction.platInfos[i].id; //根据id查询出一条platinfo的记录 DataTable dt = Myadapter_p.GetDataBy1(id); PlatInfo temp = DataHelper.Dt2pl(dt); if (temp.PlatZhos.Equals("空闲") && IsAllow(temp)) { //temp.PlatZhos = "准备"; result[0] = id.ToString(); result[1] = temp.IP; result[2] = temp.PlatZhop; result[3] = "PlatZhos"; // Myadapter_p.UpdatePlatZho(temp.PlatZhos, id); return(result); } } break; default: break; } } catch (System.Exception e) { LogHelper.Error("分配时出错" + e); } return(result); }