private void buttonUpdateTable_Click(object sender, EventArgs e) { m_aChannel = new byte[this.listViewEx1.Items.Count]; for (int i = 0; i < this.listViewEx1.Items.Count; i++) { try { m_aChannel[i] = byte.Parse(this.listViewEx1.Items[i].SubItems[1].Text); } catch { } } ByteBuilder bb = new ByteBuilder(); bb.Clear(); bb.Append((byte)this.GetChannelTable().Length); bb.Append(this.GetChannelTable()); if (!RcpProtocol.Instance.SendBytePkt(RcpProtocol.Instance.BuildCmdPacketByte(RcpProtocol.RCP_MSG_CMD, RcpProtocol.RCP_CMD_SET_HOPPING_TBL, bb.GetByteArray()))) { } bb.Clear(); }
public byte[] EncodeMessage(byte[] buffer, int offset, int count) { lock (_sync) { var @sealed = new byte[count]; _sealing.ProcessBytes(buffer, offset, count, @sealed, 0); var concatHash = _signing.ComputeHash(_builder.Append(_clientSequence).Append(buffer, offset, count).ToArray()); _builder.Clear(); _sealing.ProcessBytes(concatHash, 0, _seal.Length, _seal, 0); var signed = _builder.Append(Ntlmv2Cipher.Version).Append(_seal).Append(_clientSequence).Append(@sealed).ToArray(); _builder.Clear(); _clientSequence++; return(signed); } }
// Returns offset into response content public UInt32 Request(ref HttpRequest request, Boolean keepAlive, ByteBuilder builder) { builder.Clear(); UInt32 requestOffset = request.Build(builder, this, keepAlive); if (requestLogger != null) { requestLogger(builder, requestOffset); } UInt32 retryCount = 0; RETRY: Open(default(BufStruct)); Boolean clearedRequest = false; UInt32 responseContentOffset; try { socket.Send(builder.bytes, (int)requestOffset, (int)(builder.contentLength - requestOffset), 0); builder.Clear(); // clear the request for using it as the receive buffer clearedRequest = true; responseContentOffset = ReadResponse(keepAlive, builder); } catch (SocketException) { if (retryCount > 0) { throw; } retryCount++; if (clearedRequest) { requestOffset = request.Build(builder, this, keepAlive); // Must rebuild the request } goto RETRY; } return(responseContentOffset); }
public static PolicyPacket GetPacket(ByteBuilder builder) { if (builder.Length == 0) { return(null); } var bytes = builder.ToArray(); builder.Clear(); return(new PolicyPacket(bytes)); }
public int DecodeMessage(byte[] buffer, int offset, int count, byte[] output, int outOff) { lock (_sync) { _sealing.ProcessBytes(buffer, offset + MessageOffset, count - MessageOffset, output, outOff); _sealing.ProcessBytes(buffer, offset + SealOffset, _seal.Length, _seal, 0); var concatHash = _signing.ComputeHash(_builder.Append(buffer, SequenceOffset, 4).Append(output, outOff, count - MessageOffset).ToArray()); _builder.Clear(); if (!_seal.SequenceEqual(concatHash.Take(Ntlmv2Cipher.SealLength))) { throw new Exception("Server signature check failed"); } return(count - MessageOffset); } }
private void SetModulePowerTable(byte[] data) { int size = data[5]; if (size > data.Length - 9) { return; } refModulePwr = new UInt16[(size >> 1)]; ByteBuilder ba = new ByteBuilder(); for (int i = 0; i < (size >> 1); i++) { refModulePwr[i] = Convert.ToUInt16(data[(i * 2) + 6] << 8); refModulePwr[i] += data[i * 2 + 7]; } FormPowerLevellTable formPowerLevelTable = new FormPowerLevellTable(); formPowerLevelTable.SetPowerLevel(refModulePwr, aCalOffsetTbl); if (formPowerLevelTable.ShowDialog() == DialogResult.OK) { refModulePwr = (UInt16[])formPowerLevelTable.APower.Clone(); ba.Clear(); ba.Append((byte)(refModulePwr.Length * 2)); for (int i = 0; i < refModulePwr.Length; i++) { ba.Append((UInt16)refModulePwr[i]); } if (!RcpProtocol.Instance.SendBytePkt(RcpProtocol.Instance.BuildCmdPacketByte(RcpProtocol.RCP_MSG_CMD, RcpProtocol.RCP_CMD_SET_MODULE_PWR_TBL, ba.GetByteArray()))) { } } }
// Update is called once per frame void Update() { //创建敌人 if (detectors.Count != 0) { foreach (GameObject obj in detectors) { if (!obj.activeSelf) { deletes.AddLast(obj); } } foreach (GameObject obj in deletes) { detectors.Remove(obj); GameObject.Destroy(obj); } foreach (GameObject obj in detectors) { GameObject rival = Instantiate(rivalPrefab, new Vector3(obj.transform.position.x, rivalPrefab.transform.position.y, obj.transform.position.z), Quaternion.identity); rival.transform.Rotate(0f, Random.Range(-180f, 180f), 0f, Space.Self); rivalList.AddLast(rival); RivalController controller = rival.GetComponent <RivalController>(); controller.DelegateDie(new DieCallback(OnRivalDie)); controller.id = idNext; ++idNext; GameObject.Destroy(obj); ++completeNum; } detectors.Clear(); deletes.Clear(); } //询问服务器是否需新创建敌人 if (isCreateOver && createRivalNum <= 0 && isRecv) { StartCoroutine("ResetRecv"); byteBuilder.Add(System.BitConverter.GetBytes(Network.RIVAL_NUM)); byteBuilder.Add(System.BitConverter.GetBytes(rivalList.Count)); Global.network.Send(byteBuilder.GetByes()); byteBuilder.Clear(); isRecv = false; } else if (!isCreateOver && requestNum == createRivalNum) //检查是否创建成功 { createRivalNum = requestNum - completeNum; //开始将未创建成功的创建 for (int i = 0; i < createRivalNum; ++i) { CreateDetector(); } requestNum = 0; completeNum = 0; } if (!isCreateOver && createRivalNum <= 0) //检查是否全部创建完成 { completeNum = 0; requestNum = 0; createRivalNum = 0; isCreateOver = true; } if (isCreateOver && createRivalNum > 0) //检查是否有待创建的敌人 { //开始将未创建成功的创建 for (int i = 0; i < createRivalNum; ++i) { CreateDetector(); } isCreateOver = false; requestNum = 0; completeNum = 0; } }
public void HeaderRecvHandler(ref SelectControl selectControl, Socket clientSocket, Buf ignore) { builder.EnsureTotalCapacity(builder.contentLength + 128); UInt32 dataOffset; try { dataOffset = Http.ReadHttpHeaders(clientSocket, builder); } catch (Exception e) { if (WebServer.Logger != null) { WebServer.Logger.WriteLine("[{0}] Closed: {1}", clientLogString, e.Message); } selectControl.RemoveReceiveSocket(clientSocket); return; } // // Parse the request // try { UInt32 parseOffset = 0; Slice httpMethod; httpMethod.offset = parseOffset; httpMethod.limit = builder.bytes.IndexOfUInt32(parseOffset, dataOffset, (Byte)' '); if (httpMethod.limit == UInt32.MaxValue) { throw new FormatException("Invalid request: no space after HTTP method"); } parseOffset = (uint)httpMethod.limit + 1; Slice httpResource; httpResource.offset = parseOffset; httpResource.limit = builder.bytes.IndexOfUInt32(parseOffset, dataOffset, (Byte)' '); if (httpResource.limit == UInt32.MaxValue) { throw new FormatException("Invalid request: no space after HTTP resource"); } parseOffset = (uint)httpResource.limit + 1; this.method = httpMethod.Decode(builder.bytes); this.resource = httpResource.Decode(builder.bytes); headerContentLength = Http.GetContentLength(builder.bytes, 0, dataOffset); if (headerContentLength != UInt32.MaxValue) { throw new NotImplementedException(String.Format("Content-Length {0} is not implemented", headerContentLength)); } } catch (Exception e) { if (WebServer.Logger != null) { WebServer.Logger.WriteLine("[{0}] InvalidRequest: {1}", clientLogString, e.Message); } clientSocket.Shutdown(SocketShutdown.Both); clientSocket.Close(); selectControl.RemoveReceiveSocket(clientSocket); return; } if (WebServer.Logger != null) { WebServer.Logger.WriteLine("[{0}] {1} {2}", clientLogString, method, resource); } if (!method.Equals("GET")) { if (WebServer.Logger != null) { WebServer.Logger.WriteLine("[{0}] Unsupported HTTP Method: {1}", clientLogString, method); } clientSocket.Shutdown(SocketShutdown.Both); clientSocket.Close(); selectControl.RemoveReceiveSocket(clientSocket); return; } String filename = WebServer.HttpResourceToFile(resource); if (!File.Exists(filename)) { clientSocket.Send(NotFound404); clientSocket.Shutdown(SocketShutdown.Both); clientSocket.Close(); selectControl.RemoveReceiveSocket(clientSocket); return; } builder.Clear(); FileInfo fileInfo = new FileInfo(filename); Int64 fileLength = fileInfo.Length; builder.AppendAscii("HTTP/1.1 200 OK\r\nContent-Length: "); builder.AppendAscii(fileLength.ToString()); builder.AppendAscii("\r\n\r\n"); using (FileStream fileStream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { UInt32 bufferLeft = (uint)builder.bytes.Length - builder.contentLength; if (fileLength <= bufferLeft) { fileStream.ReadFullSize(builder.bytes, (int)builder.contentLength, (int)fileLength); clientSocket.Send(builder.bytes, 0, (int)(builder.contentLength + fileLength), 0); } else { Int64 fileLeft = fileLength; fileStream.ReadFullSize(builder.bytes, (int)builder.contentLength, (int)bufferLeft); clientSocket.Send(builder.bytes); fileLeft -= bufferLeft; while (fileLeft > builder.bytes.Length) { fileStream.ReadFullSize(builder.bytes, 0, builder.bytes.Length); clientSocket.Send(builder.bytes); fileLeft -= builder.bytes.Length; } if (fileLeft > 0) { fileStream.ReadFullSize(builder.bytes, 0, (int)fileLeft); clientSocket.Send(builder.bytes, 0, (int)fileLeft, 0); } } clientSocket.Close(); selectControl.RemoveReceiveSocket(clientSocket); } }
// Update is called once per frame void Update() { //死亡则慢慢下沉消失 if (humanController.health <= 0 && !isDead) { if (dieCallbacks != null) { dieCallbacks(gameObject); //死亡回调 } isDead = true; Destroy(GetComponent <CharacterController>()); Destroy(GetComponent <Rigidbody>()); Destroy(GetComponent <SphereCollider>()); StopAllCoroutines(); StartCoroutine(Die()); return; } if (humanController.health != humanController.MaxHealth && humanController.health > 0 && !isTrace && !isShoot) { isTrace = true; isPatrol = false; isShoot = false; } if (isInRotate) { return; } // Debug.Log("Next"); if (!isDead) { //移动 if (isPatrol) { // Debug.Log("WALK"); // nav.enabled = false; // StopCoroutine("Trace"); humanController.Idle(); if (Vector3.Angle(patrolForward, transform.forward) > 5.0f) //判断是否需要转向 { // Debug.Log("ChangeTo:"+patrolForward + transform.forward + (patrolForward == transform.forward) +" "+); // StopCoroutine("RotateByFrame"); RotateTowards(patrolForward); return; } humanController.Walk(walkSpeed, 0f); } else if (isTrace) //追踪 { if (playerLastPosition == Vector3.zero || (Global.player.transform.position - playerLastPosition).magnitude > 3f) { /*向服务器发送路径计算请求 */ byteBuilder.Add(System.BitConverter.GetBytes(Network.RIVAL_REQUEST)); byteBuilder.Add(System.BitConverter.GetBytes(id)); byteBuilder.Add(System.BitConverter.GetBytes(Network.SEARCH_ROAD)); byteBuilder.Add(System.BitConverter.GetBytes((int)(transform.position.x + 0.5))); byteBuilder.Add(System.BitConverter.GetBytes((int)(transform.position.z + 0.5))); byteBuilder.Add(System.BitConverter.GetBytes((int)(Global.player.transform.position.x + 0.5))); byteBuilder.Add(System.BitConverter.GetBytes((int)(Global.player.transform.position.z + 0.5))); Global.network.Send(byteBuilder.GetByes()); byteBuilder.Clear(); // nav.enabled = true; // nav.SetDestination(Global.player.transform.position); // humanController.Run(0, 0); playerLastPosition = Global.player.transform.position; } } else if (vertical != 0 || horizontal != 0) { humanController.Run(vertical * runSpeed, horizontal * runSpeed); // nav.enabled = false; StopCoroutine("Trace"); humanController.Idle(); } else { // humanController.Idle(); // nav.enabled = false; // StopCoroutine("Trace"); StopAllCoroutines(); humanController.Idle(); } //设置视线 Ray tar = new Ray(transform.position + shootRectify, transform.forward); if (Physics.Raycast(tar, out sightHit)) { lookAtPoint = sightHit.point; } //检测是否玩家在视线内 Vector3 targetV = Global.player.transform.position - transform.position; // Debug.Log(Vector3.Angle(transform.forward, targetV)); if (Vector3.Angle(transform.forward, targetV) <= sightAngle) { Ray detect = new Ray(transform.position + shootRectify, targetV); RaycastHit h; if (Physics.Raycast(detect, out h)) { // Debug.Log("Hit:"+h.collider.gameObject.layer+" "+h.collider.name); // Debug.DrawRay(transform.position, targetV, Color.black); if (h.collider.gameObject.layer == 11) { // Debug.Log("Human"); float dis = (transform.position - Global.player.transform.position).magnitude; if (!isTrace && !isShoot) //若在巡逻状态 { Debug.Log("In Sight"); //在视线内 byteBuilder.Add(System.BitConverter.GetBytes(Network.RIVAL_REQUEST)); byteBuilder.Add(System.BitConverter.GetBytes(id)); byteBuilder.Add(System.BitConverter.GetBytes(Network.PLAYER_IN_SIGHT)); Global.network.Send(byteBuilder.GetByes()); byteBuilder.Clear(); } else if (!isShoot && dis < weaponController.maxAttackDis) //若不在射击状态 { byteBuilder.Add(System.BitConverter.GetBytes(Network.RIVAL_REQUEST)); byteBuilder.Add(System.BitConverter.GetBytes(id)); byteBuilder.Add(System.BitConverter.GetBytes(Network.PLAYER_IN_SHOOT)); Global.network.Send(byteBuilder.GetByes()); byteBuilder.Clear(); } else if (isShoot && dis > weaponController.maxAttackDis) //若在射击状态但不在攻击距离内 { byteBuilder.Add(System.BitConverter.GetBytes(Network.RIVAL_REQUEST)); byteBuilder.Add(System.BitConverter.GetBytes(id)); byteBuilder.Add(System.BitConverter.GetBytes(Network.PLAYER_OUT_SHOOT)); Global.network.Send(byteBuilder.GetByes()); byteBuilder.Clear(); } } else if (isShoot) //出视线外 { byteBuilder.Add(System.BitConverter.GetBytes(Network.RIVAL_REQUEST)); byteBuilder.Add(System.BitConverter.GetBytes(id)); byteBuilder.Add(System.BitConverter.GetBytes(Network.PLAYER_OUT_SHOOT)); Global.network.Send(byteBuilder.GetByes()); byteBuilder.Clear(); } } } //shoot if (isShoot) { Debug.Log("SHOOT"); //若无子弹则换弹 if (weaponController.bulletNumNow <= 0) { weaponController.bulletSum = weaponController.bulletMaxHold + 100; //设置子弹无限 humanController.Reload(); } else { transform.LookAt(Global.player.transform, transform.up); if (humanController.Attack1() && weaponController.Shoot()) { Ray ray = new Ray(transform.position + shootRectify, transform.forward + transform.right * Random.Range(-shootBias, shootBias) + transform.up * Random.Range(-shootBias, shootBias)); if (Physics.Raycast(ray, out hit)) { //若击中环境,刀子无击中效果 if (hit.collider.gameObject.layer == 9 && weaponController.category != WeaponCategory.Knife) { GameObject shootSmoke = Instantiate(shootSmokePrefab, hit.point, Quaternion.identity); shootSmoke.transform.localRotation.SetLookRotation(hit.normal); //获取击中物体的颜色 Color color = hit.collider.gameObject.GetComponent <MeshRenderer>().material.color; ParticleSystem particleSystem = shootSmoke.GetComponent <ParticleSystem>(); //设置起始颜色 ParticleSystem.MainModule main = particleSystem.main; main.startColor = color; //设置颜色渐变 ParticleSystem.ColorOverLifetimeModule col = particleSystem.colorOverLifetime; col.enabled = true; Gradient grad = new Gradient(); grad.SetKeys(new GradientColorKey[] { new GradientColorKey(color, 0.4f), new GradientColorKey(color, 1.0f) }, new GradientAlphaKey[] { new GradientAlphaKey(1.0f, 0.0f), new GradientAlphaKey(0.0f, 1.0f) }); col.color = grad; GameObject.Destroy(shootSmoke, 0.5f); //设置0.2s后销毁烟雾效果 } //若击中人 else if (hit.collider.gameObject.layer == 11) { hit.collider.gameObject.GetComponent <HumanAnimController>().Damaged(weaponController.damage, hit.point); } } } } } } }
private void reader_operate() { byte region = 0x11; byte[] param = new byte[2]; UInt16 power = 200; ByteBuilder bb = new ByteBuilder(); if (!InvokeRequired) { regionVal = this.cb_region.SelectedIndex; // return; } this.Invoke(new MethodInvoker(delegate() { regionVal = this.cb_region.SelectedIndex; })); if (RcpProtocol.Instance.m_bRcpReceivedPacket != false) { RcpProtocol.Instance.m_bRcpReceivedPacket = false; } //switch ((string)cbRegion.SelectedItem) switch (regionVal) { case 0: //"Korea":// Korea (0x11) region = 0x11; param[0] = 0x14; param[1] = 0; break; case 1: //""US":// US (0x21) region = 0x21; param[0] = 1; param[1] = 0; break; case 2: //""US2":// US2 (0x22) region = 0x22; param[0] = 0x19; param[1] = 0; break; case 3: //""Europe":// Europe (0x31) region = 0x31; param[0] = 0x0A; param[1] = 0; break; case 4: //""Japan":// Japan (0x41) region = 0x41; param[0] = 0x18; param[1] = 0; break; case 5: //""China1":// China1 (0x51) region = 0x51; param[0] = 1; param[1] = 0; break; case 6: //""China2":// China2 (0x52) region = 0x52; param[0] = 1; param[1] = 0; break; } if (!RcpProtocol.Instance.SendBytePkt(RcpProtocol.Instance.BuildCmdPacketByte(RcpProtocol.RCP_MSG_CMD, RcpProtocol.RCP_CMD_SET_REGION, new byte[] { region }))) { return; } WaitForReceived(); // System.Threading.Thread.Sleep(100); if (param[1] < 10) { param[1] = (byte)((byte)param[1] * ((byte)10)); } if (!RcpProtocol.Instance.SendBytePkt(RcpProtocol.Instance.BuildCmdPacketByte(RcpProtocol.RCP_MSG_CMD, RcpProtocol.RCP_CMD_SET_CH, param))) { } WaitForReceived(); bb.Append((UInt16)power); if (!RcpProtocol.Instance.SendBytePkt(RcpProtocol.Instance.BuildCmdPacketByte(RcpProtocol.RCP_MSG_CMD, RcpProtocol.RCP_CMD_SET_TX_PWR, bb.GetByteArray()))) { } bb.Clear(); WaitForReceived(); System.Threading.Thread.Sleep(100); if (!RcpProtocol.Instance.SendBytePkt(RcpProtocol.Instance.BuildCmdPacketByte(RcpProtocol.RCP_MSG_CMD, RcpProtocol.RCP_CMD_SET_CW, new byte[] { 0xFF }))) { } bb.Clear(); WaitForReceived(); System.Threading.Thread.Sleep(500); }
public bool compare_DynamicRange(double min_range, double max_range) { ByteBuilder bb = new ByteBuilder(); UInt16 minRange_power = 100; UInt16 maxRange_power = 200; bool dynmic_range_Flag = false; // double margine_power = Convert.ToDouble(cmd_data[3]); double ReadData = 0f; bb.Append((UInt16)(minRange_power)); if (!RcpProtocol.Instance.SendBytePkt(RcpProtocol.Instance.BuildCmdPacketByte(RcpProtocol.RCP_MSG_CMD, RcpProtocol.RCP_CMD_SET_TX_PWR, bb.GetByteArray()))) { } bb.Clear(); WaitForReceived(); if (!RcpProtocol.Instance.SendBytePkt(RcpProtocol.Instance.BuildCmdPacketByte(RcpProtocol.RCP_MSG_CMD, RcpProtocol.RCP_CMD_SET_CW, new byte[] { 0xFF }))) { } WaitForReceived(); System.Threading.Thread.Sleep(500); DirectWrite(m_Spectrum1, "CALC:MARK1:MAX"); System.Threading.Thread.Sleep(100); DirectWrite(m_Spectrum1, "CALC:MARK1:Y?"); System.Threading.Thread.Sleep(100); DirectRead(m_Spectrum1, ref temp, "0"); ReadData = temp;//(double)ioSpectrumAnalyzer.ReadNumber(IEEEASCIIType.ASCIIType_R8, true); System.Threading.Thread.Sleep(100); if (ReadData <= min_range && (ReadData > (min_range - 2))) { dynmic_range_Flag = true; __gRange_minVal = ReadData; } else { dynmic_range_Flag = false; return(dynmic_range_Flag); } //System.Threading.Thread.Sleep(1000); bb.Append((UInt16)(maxRange_power)); if (!RcpProtocol.Instance.SendBytePkt(RcpProtocol.Instance.BuildCmdPacketByte(RcpProtocol.RCP_MSG_CMD, RcpProtocol.RCP_CMD_SET_TX_PWR, bb.GetByteArray()))) { } bb.Clear(); WaitForReceived(); System.Threading.Thread.Sleep(500); DirectWrite(m_Spectrum1, "CALC:MARK1:MAX"); System.Threading.Thread.Sleep(100); DirectWrite(m_Spectrum1, "CALC:MARK1:Y?"); System.Threading.Thread.Sleep(100); DirectRead(m_Spectrum1, ref temp, "0"); ReadData = temp;//(double)ioSpectrumAnalyzer.ReadNumber(IEEEASCIIType.ASCIIType_R8, true); System.Threading.Thread.Sleep(100); // DisplayMsgString("max power :" + Convert.ToString(ReadData) + "\r\n"); if (ReadData > (max_range + 0.8f)) { dynmic_range_Flag = true; __gRange_maxVal = ReadData; } else { dynmic_range_Flag = false; return(dynmic_range_Flag); } return(dynmic_range_Flag); }
public void cal_confirmation() { ByteBuilder bb = new ByteBuilder(); float power = 0f; double ReadData = 0; byte region = 0x11; byte[] param = new byte[2]; double ConfirmData = 0; if (RcpProtocol.Instance.m_bRcpReceivedPacket != false) { RcpProtocol.Instance.m_bRcpReceivedPacket = false; } //switch ((string)cbRegion.SelectedItem) switch (regionVal) { case 0: //"Korea":// Korea (0x11) region = 0x11; param[0] = 0x14; param[1] = 0; break; case 1: //""US":// US (0x21) region = 0x21; param[0] = 1; param[1] = 0; break; case 2: //""US2":// US2 (0x22) region = 0x22; param[0] = 0x19; param[1] = 0; break; case 3: //""Europe":// Europe (0x31) region = 0x31; param[0] = 0x0A; param[1] = 0; break; case 4: //""Japan":// Japan (0x41) region = 0x41; param[0] = 0x18; param[1] = 0; break; case 5: //""China1":// China1 (0x51) region = 0x51; param[0] = 1; param[1] = 0; break; case 6: //""China2":// China2 (0x52) region = 0x52; param[0] = 1; param[1] = 0; break; } if (!RcpProtocol.Instance.SendBytePkt(RcpProtocol.Instance.BuildCmdPacketByte(RcpProtocol.RCP_MSG_CMD, RcpProtocol.RCP_CMD_SET_REGION, new byte[] { region }))) { return; } WaitForReceived(); // System.Threading.Thread.Sleep(100); if (param[1] < 10) { param[1] = (byte)((byte)param[1] * ((byte)10)); } if (!RcpProtocol.Instance.SendBytePkt(RcpProtocol.Instance.BuildCmdPacketByte(RcpProtocol.RCP_MSG_CMD, RcpProtocol.RCP_CMD_SET_CH, param))) { } WaitForReceived(); if (!InvokeRequired) { power = (float)(Convert.ToDouble(this.comboBox_StartPosition.Text)); } this.Invoke(new MethodInvoker(delegate() { //power = (float)(Convert.ToDouble((string)this.comboBox_StartPosition.SelectedItem)); power = (float)(Convert.ToDouble(this.comboBox_StartPosition.Text)); })); bb.Append((UInt16)((power) * 10)); if (!RcpProtocol.Instance.SendBytePkt(RcpProtocol.Instance.BuildCmdPacketByte(RcpProtocol.RCP_MSG_CMD, RcpProtocol.RCP_CMD_SET_MODULE_TX_PWR, bb.GetByteArray()))) { } bb.Clear(); WaitForReceived(); if (!RcpProtocol.Instance.SendBytePkt(RcpProtocol.Instance.BuildCmdPacketByte(RcpProtocol.RCP_MSG_CMD, RcpProtocol.RCP_CMD_SET_CW, new byte[] { 0xFF }))) { } WaitForReceived(); System.Threading.Thread.Sleep(1000); DirectWrite(m_Spectrum1, "CALC:MARK1:MAX"); System.Threading.Thread.Sleep(100); DirectWrite(m_Spectrum1, "CALC:MARK1:Y?"); System.Threading.Thread.Sleep(100); DirectRead(m_Spectrum1, ref temp, "0"); if (!InvokeRequired) { ConfirmData = Convert.ToDouble(comboBox_StartPosition.Text); } this.Invoke(new MethodInvoker(delegate() { ConfirmData = Convert.ToDouble(comboBox_StartPosition.Text); })); ReadData = temp;//(double)ioSpectrumAnalyzer.ReadNumber(IEEEASCIIType.ASCIIType_R8, true); if (ReadData <= ConfirmData + 1 && ReadData >= ConfirmData - 0.5f) { if (!InvokeRequired) { lb_calConfirm.Text = "Pass"; lb_calConfirm.ForeColor = Color.Blue; button_CP_TBL.Enabled = true; // return; } this.Invoke(new MethodInvoker(delegate() { lb_calConfirm.Text = "Pass"; lb_calConfirm.ForeColor = Color.Blue; button_CP_TBL.Enabled = true; })); } else { if (!InvokeRequired) { lb_calConfirm.Text = "Fail"; lb_calConfirm.ForeColor = Color.Red; button_CP_TBL.Enabled = true; // return; } this.Invoke(new MethodInvoker(delegate() { lb_calConfirm.Text = "Fail"; lb_calConfirm.ForeColor = Color.Red; button_CP_TBL.Enabled = true; })); } if (!RcpProtocol.Instance.SendBytePkt(RcpProtocol.Instance.BuildCmdPacketByte(RcpProtocol.RCP_MSG_CMD, RcpProtocol.RCP_CMD_SET_CW, new byte[] { 0x00 }))) { } }
private void StartCalibration() { ByteBuilder bb = new ByteBuilder(); UInt16 power = 200; double ReadData = 0; double StartPosition = 0; int tblSize = 0; if (RcpProtocol.Instance.m_bRcpReceivedPacket != false) { RcpProtocol.Instance.m_bRcpReceivedPacket = false; } if (!InvokeRequired) { lb_calConfirm.Text = "Processing"; lb_calConfirm.ForeColor = Color.Blue; // return; } this.Invoke(new MethodInvoker(delegate() { lb_calConfirm.Text = "Processing"; lb_calConfirm.ForeColor = Color.Blue; })); if (!InvokeRequired) { StartPosition = Convert.ToDouble(comboBox_StartPosition.Text); // return; } this.Invoke(new MethodInvoker(delegate() { StartPosition = Convert.ToDouble(comboBox_StartPosition.Text); })); int Range = 0; if (!InvokeRequired) { Range = Convert.ToInt32(comboBox_Range.Text); // return; } this.Invoke(new MethodInvoker(delegate() { Range = Convert.ToInt32(comboBox_Range.Text); })); equipment_Setup(); reader_operate(); System.Threading.Thread.Sleep(100); for (int i = 0; i < MatchedOffset.Length; i++) { if (StartPosition == Range) { tblSize = i + 1; } while (StartPosition >= Range) { DirectWrite(m_Spectrum1, "CALC:MARK1:MAX"); System.Threading.Thread.Sleep(100); DirectWrite(m_Spectrum1, "CALC:MARK1:Y?"); System.Threading.Thread.Sleep(100); DirectRead(m_Spectrum1, ref temp, "0"); ReadData = temp;//(double)ioSpectrumAnalyzer.ReadNumber(IEEEASCIIType.ASCIIType_R8, true); System.Threading.Thread.Sleep(100); if (StartPosition < ReadData) { bb.Append((UInt16)(power--)); if (!RcpProtocol.Instance.SendBytePkt(RcpProtocol.Instance.BuildCmdPacketByte(RcpProtocol.RCP_MSG_CMD, RcpProtocol.RCP_CMD_SET_TX_PWR, bb.GetByteArray()))) { } bb.Clear(); //System.Threading.Thread.Sleep(100); bb.Clear(); WaitForReceived(); } else { // MatchedOffset[j] = (power - 200f) / 10; MatchedOffset[i] = power; break; } if (power < 100) { break; } } StartPosition -= 0.5f; } if (!InvokeRequired) { StartPosition = Convert.ToDouble(comboBox_StartPosition.Text); } this.Invoke(new MethodInvoker(delegate() { StartPosition = Convert.ToDouble(comboBox_StartPosition.Text); })); for (int i = 0; i < MatchedOffset.Length; i++) { ListViewItem lvi = new ListViewItem(Convert.ToString(StartPosition - (0.5 * i))); if (!InvokeRequired) { lvi.SubItems.Add(Convert.ToString(MatchedOffset[i])); this.listViewEx2.Items.Add(lvi); } this.Invoke(new MethodInvoker(delegate() { lvi.SubItems.Add(Convert.ToString(MatchedOffset[i])); this.listViewEx2.Items.Add(lvi); })); } //////////Reset / Registry Update ///////////// if (!RcpProtocol.Instance.SendBytePkt(RcpProtocol.Instance.BuildCmdPacketByte(RcpProtocol.RCP_MSG_CMD, RcpProtocol.RCP_CMD_CTL_RESET, null))) { } WaitForReceived(); // System.Threading.Thread.Sleep(100); System.Threading.Thread.Sleep(500); /////////Table Update////// // DisplayMsgString(Convert.ToString(tblSize)); refModulePwr = new UInt16[tblSize]; for (int j = 0; j < tblSize; j++) { refModulePwr[j] = MatchedOffset[j]; } bb.Append((byte)(refModulePwr.Length * 2)); for (int i = 0; i < refModulePwr.Length; i++) { bb.Append((UInt16)refModulePwr[i]); } if (!RcpProtocol.Instance.SendBytePkt (RcpProtocol.Instance.BuildCmdPacketByte (RcpProtocol.RCP_MSG_CMD, RcpProtocol.RCP_CMD_SET_MODULE_PWR_TBL, bb.GetByteArray()))) { } bb.Clear(); WaitForReceived(); // System.Threading.Thread.Sleep(100); bb.Append(0x01); if (!RcpProtocol.Instance.SendBytePkt(RcpProtocol.Instance.BuildCmdPacketByte(RcpProtocol.RCP_MSG_CMD, RcpProtocol.RCP_UPDATE_FLASH, bb.GetByteArray()))) { } WaitForReceived(); // System.Threading.Thread.Sleep(100); // float power = 0f; ///////////Calibration Confirmation//////////////////// System.Threading.Thread.Sleep(500); cal_confirmation(); }