/// <summary> /// 更新一个网关-UI /// </summary> /// <param name="yourVaneConfig"></param> /// <param name="yourIndex"></param> public void updataGW(vaneConfig yourVaneConfig, int yourIndex) { myVaneBroadcastConfigList[yourIndex] = new vaneConfigBroadcast(25, yourVaneConfig); listViewEx_GWlist.Items[yourIndex] = new ListViewItem(new string[] { (yourIndex + 1).ToString(), myVaneConfigTool.getIpByBytes(myVaneConfigTool.pickOutContent(yourVaneConfig, 0x89)), myVaneConfigTool.getUtf8StrByBytes(myVaneConfigTool.pickOutContent(yourVaneConfig, 0x99)), myVaneConfigTool.getUtf8StrByBytes(myVaneConfigTool.pickOutContent(yourVaneConfig, 0x87)), myVaneConfigTool.findInterpretation(myShareData.myNewVersionFlagDictionary, myVaneConfigTool.pickOutContent(yourVaneConfig, 0x9D)), myVaneConfigTool.findInterpretation(myShareData.myGWAbilityDictionary, myVaneConfigTool.pickOutContent(yourVaneConfig, 0xA1)) }); }
void timer_vcBroadcast_Tick(object sender, EventArgs e) { if (myVaneBroadcastConfigList.Count != 0) { for (int i = 0; i < myVaneBroadcastConfigList.Count; i++) { myVaneBroadcastConfigList[i].liveClick--; if (myVaneBroadcastConfigList[i].liveClick < 1) { delGW(myVaneBroadcastConfigList, i); } } } if (socket.Available > 0) { byte[] tempData = new byte[socket.Available]; socket.ReceiveFrom(tempData, ref ep); richTextBox_BroadcastRecord.Text += myVaneConfigTool.getHexByBytes(tempData) + "\n"; vaneConfig tempvaneConfig = myVaneConfigTool.myConfigDataAnalyze(tempData); if (tempvaneConfig.errorMsg == "") { if (myVaneBroadcastConfigList.Count > 0) { bool tempIsNew = true; for (int i = 0; i < myVaneBroadcastConfigList.Count; i++) { if (ContrastVaneConfigItem(myVaneBroadcastConfigList[i].myVaneConfig, tempvaneConfig, 0x99)) { tempIsNew = false; myVaneBroadcastConfigList[i].liveClick = 25; if (!(ContrastVaneConfigItem(myVaneBroadcastConfigList[i].myVaneConfig, tempvaneConfig, 0x9D) && ContrastVaneConfigItem(myVaneBroadcastConfigList[i].myVaneConfig, tempvaneConfig, 0x87) && ContrastVaneConfigItem(myVaneBroadcastConfigList[i].myVaneConfig, tempvaneConfig, 0x89))) { updataGW(tempvaneConfig, i); } break; } } if (tempIsNew) { addGW(myVaneBroadcastConfigList, tempvaneConfig); } } else { addGW(myVaneBroadcastConfigList, tempvaneConfig); } } else { ErrorLog.PutInLog(tempvaneConfig.errorMsg); } } }
void timer_wifiCfgBroadcast_Tick(object sender, EventArgs e) { if (wifiCfgBroadcastLifeTime < 0) { stopWifiCfgBroadcast(); } else { wifiCfgBroadcastLifeTime--; progressBarX_WifiConfig.Value += 1; if (myWifiCfgBroadcast.Available > 0) { byte[] tempData = new byte[myWifiCfgBroadcast.Available]; myWifiCfgBroadcast.ReceiveFrom(tempData, ref tempEp); //MessageBox.Show(myVaneConfigTool.getHexByBytes(tempData)); vaneConfig tempvaneConfig = myVaneConfigTool.myConfigDataAnalyze(tempData); listView_WifiConfigDataBack.BeginUpdate(); listView_WifiConfigDataBack.Items.Add(new ListViewItem(new string[] { "", "" })); foreach (KeyValuePair <byte[], byte[]> tempKvp in tempvaneConfig.Contents) { //如果接收到wifi配置返回 if (myVaneConfigTool.isBytesSame(tempKvp.Key, new byte[] { 0x00, 0x81 }) && myVaneConfigTool.isBytesSame(tempKvp.Value, new byte[] { 0x00, 0xA1 })) { if (myVaneConfigTool.isBytesSame(myVaneConfigTool.pickOutContent(tempvaneConfig, 0x84), new byte[] { 0x00, 0x00, 0x00, 0x00 })) { } else { } } string tempKey = myVaneConfigTool.findInterpretation(myShareData.myWifiAssignedNumberDictionary, tempKvp.Key); string tempValue = myVaneConfigTool.getVaneWifiContentVaule(tempKvp); listView_WifiConfigDataBack.Items.Add(new ListViewItem(new string[] { tempKey, tempValue })); } listView_WifiConfigDataBack.EnsureVisible(listView_WifiConfigDataBack.Items.Count - 1); listView_WifiConfigDataBack.EndUpdate(); } } }
public bool ContrastVaneConfigItem(vaneConfig yourVaneConfigA, vaneConfig yourVaneConfigB, byte yourAssignedNumber) { byte[] tempA = myVaneConfigTool.pickOutContent(yourVaneConfigA, yourAssignedNumber); byte[] tempB = myVaneConfigTool.pickOutContent(yourVaneConfigB, yourAssignedNumber); if (tempA == null || tempB == null) { return(false); } if (tempA.Length == tempB.Length) { for (int i = 0; i < tempA.Length; i++) { if (tempA[i] != tempB[i]) { return(false); } } return(true); } else { return(false); } }
/// <summary> /// here i will receive the back data /// </summary> /// <param name="yourData">back data </param> void nowSocket_nowReceiveData(byte[] yourData) { richTextBox_resData.Text += myVaneConfigTool.getHexByBytes(yourData) + "\n"; vaneConfig nowCig = new vaneConfig(""); nowCig = myVaneConfigTool.myConfigDataAnalyze(yourData); listView_AllDataBack.BeginUpdate(); listView_AllDataBack.Items.Add(new ListViewItem(new string[] { "", "" })); foreach (KeyValuePair <byte[], byte[]> tempKvp in nowCig.Contents) { //如果是口令返回则更新Token信息 if (myVaneConfigTool.isBytesSame(tempKvp.Key, new byte[] { 0x00, 0x81 }) && myVaneConfigTool.isBytesSame(tempKvp.Value, new byte[] { 0x00, 0x05 })) { nowVaneConfigRequestData.myRunTimeGwID = myVaneConfigTool.pickOutContent(nowCig, 0x86); nowVaneConfigRequestData.myRunTimeGwToken = myVaneConfigTool.rmBytesEnd(myVaneConfigTool.pickOutContent(nowCig, 0x98)); if (myVaneConfigTool.isBytesSame(myVaneConfigTool.pickOutContent(nowCig, 0x84), new byte[] { 0x00, 0x00, 0x00, 0x00 })) { addMessage("login seccuse"); } else { MessageBox.Show("密码错误,请重新登录"); addMessage("密码错误,请重新登录"); } } //获取或处理测试返回 if (isTest) { //添加返回 if (myVaneConfigTool.isBytesSame(tempKvp.Key, new byte[] { 0x00, 0x81 }) && myVaneConfigTool.isBytesSame(tempKvp.Value, new byte[] { 0x00, 0x0B })) { if (myVaneConfigTool.isBytesSame(myVaneConfigTool.pickOutContent(nowCig, 0x84), new byte[] { 0x00, 0x00, 0x00, 0x00 })) { nowTestState.nextStep = 2; int tempTime = setTimeOut - myTimeOut; addMessage("添加EP成功,即将删除 TIME:" + tempTime); nowTestState.addSuccuseCount++; } else { nowTestState.nextStep = 1; addMessage("添加EP失败,即将重新添加"); nowTestState.addFailCount++; } RefreshResult(); } //删除返回 if (myVaneConfigTool.isBytesSame(tempKvp.Key, new byte[] { 0x00, 0x81 }) && myVaneConfigTool.isBytesSame(tempKvp.Value, new byte[] { 0x00, 0x0D })) { if (myVaneConfigTool.isBytesSame(myVaneConfigTool.pickOutContent(nowCig, 0x84), new byte[] { 0x00, 0x00, 0x00, 0x00 })) { nowTestState.nextStep = 1; addMessage("删除EP成功,即将重新添加"); ////************************ //nowTestState.waitTime += 30; //addMessage("进入延时"); ////************************ nowTestState.delSuccuseCount++; } else { nowTestState.nextStep = 2; addMessage("删除EP失败,即将重新删除"); nowTestState.delFailCount++; } RefreshResult(); } } string tempKey, tempValue = ""; tempKey = myVaneConfigTool.findInterpretation(myShareData.myAssignedNumberDictionary, tempKvp.Key); tempValue = myVaneConfigTool.getVaneContentVaule(tempKvp); listView_AllDataBack.Items.Add(new ListViewItem(new string[] { tempKey, tempValue })); } listView_AllDataBack.EnsureVisible(listView_AllDataBack.Items.Count - 1); listView_AllDataBack.EndUpdate(); }
/// <summary> /// here i will receive the back data /// </summary> /// <param name="yourData">back data </param> public void nowSocket_nowReceiveData(byte[] yourData) { //MessageBox.Show(myVaneConfigTool.getHexByBytes(yourData)); richTextBox_vaneConfigResponse.Text += "ReceiveData: " + myVaneConfigTool.getHexByBytes(yourData) + "\n"; vaneConfig nowCig = new vaneConfig(""); nowCig = myVaneConfigTool.myConfigDataAnalyze(yourData); List <ListViewItem> myTempItems = new List <ListViewItem>(); bool isHeatBeat = false; myTempItems.Add(new ListViewItem(new string[] { "", "" })); foreach (KeyValuePair <byte[], byte[]> tempKvp in nowCig.Contents) { //如果是心跳返回 if (myVaneConfigTool.isBytesSame(tempKvp.Key, new byte[] { 0x00, 0x81 }) && myVaneConfigTool.isBytesSame(tempKvp.Value, new byte[] { 0x00, 0x02 })) { isHeatBeat = true; break; } //如果是口令返回则更新Token信息 else if (myVaneConfigTool.isBytesSame(tempKvp.Key, new byte[] { 0x00, 0x81 }) && myVaneConfigTool.isBytesSame(tempKvp.Value, new byte[] { 0x00, 0x05 })) { nowVaneConfigRequestData.myRunTimeGwID = myVaneConfigTool.pickOutContent(nowCig, 0x86); nowVaneConfigRequestData.myRunTimeGwToken = myVaneConfigTool.rmBytesEnd(myVaneConfigTool.pickOutContent(nowCig, 0x98)); if (!myVaneConfigTool.isBytesSame(myVaneConfigTool.pickOutContent(nowCig, 0x84), new byte[] { 0x00, 0x00, 0x00, 0x00 })) { MessageBox.Show("您输入的密码可能是错误的!"); } } //如果返回EP列表信息则进行进一步解析 else if (myVaneConfigTool.isBytesSame(tempKvp.Key, new byte[] { 0x00, 0x81 }) && myVaneConfigTool.isBytesSame(tempKvp.Value, new byte[] { 0x00, 0x09 })) { try { showEpList(myVaneConfigTool.pickOutContent(nowCig, 0x8F)); } catch (Exception ex) { ErrorLog.PutInLog(ex); MessageBox.Show(ex.Message); } richTextBox_epListData.Text = myVaneConfigTool.getHexByBytes(myVaneConfigTool.pickOutContent(nowCig, 0x8F)); } //如果返回的版本检查结果,追加解析 else if (myVaneConfigTool.isBytesSame(tempKvp.Key, new byte[] { 0x00, 0x81 }) && myVaneConfigTool.isBytesSame(tempKvp.Value, new byte[] { 0x00, 0x16 })) { try { showVerList(myVaneConfigTool.pickOutContents(nowCig, 0xA6)); } catch (Exception ex) { ErrorLog.PutInLog(ex); MessageBox.Show(ex.Message); } } //如果是一键添加返回的EP添加信息 else if (myVaneConfigTool.isBytesSame(tempKvp.Key, new byte[] { 0x00, 0x81 }) && myVaneConfigTool.isBytesSame(tempKvp.Value, new byte[] { 0x00, 0x1B })) { listView_addAllEpList.Items.Add(new ListViewItem(new string[] { (listView_addAllEpList.Items.Count + 1).ToString(), myVaneConfigTool.byteToHexStr(myVaneConfigTool.pickOutContent(nowCig, 0x91)) })); } string tempKey, tempValue = ""; tempKey = myVaneConfigTool.findInterpretation(myShareData.myAssignedNumberDictionary, tempKvp.Key); tempValue = myVaneConfigTool.getVaneContentVaule(tempKvp); myTempItems.Add(new ListViewItem(new string[] { tempKey, tempValue })); } if (isHeatBeat) { pictureBox_headHeart.Image = ((AutoRunner)(this.Parent.Parent.Parent.Parent)).imageListForButton.Images[4]; } else { if (myTempItems.Count > 0) { listView_AllDataBack.BeginUpdate(); foreach (ListViewItem tempListViewItem in myTempItems) { listView_AllDataBack.Items.Add(tempListViewItem); } listView_AllDataBack.EnsureVisible(listView_AllDataBack.Items.Count - 1); listView_AllDataBack.EndUpdate(); } } }
/// <summary> /// 添加一个网关-UI /// </summary> /// <param name="yourBrdList"></param> /// <param name="yourVaneConfig"></param> public void addGW(List <vaneConfigBroadcast> yourBrdList, vaneConfig yourVaneConfig) { yourBrdList.Add(new vaneConfigBroadcast(20, yourVaneConfig)); updataGWlist(yourBrdList); }