private bool SetReferParam(NodeMsg desdev, UdpClient client, referparm type, byte[] mparams) { byte[] bytes = null; //初始化设置参数及发送数组 switch (type) { case referparm.Sgthreshold: //PC--->Node:F1 + 20 + ReferID(2byte) + SigThreshold(1byte) + CS +F2 bytes = new byte[7]; bytes[1] = 0x20; bytes[4] = mparams[0]; break; case referparm.Sgstrengthfac: //PC--->Node:F1 + 22 + ReferID(2byte) + Sigk(1byte) + CS +F2 bytes = new byte[7]; bytes[1] = 0x22; bytes[4] = mparams[0]; break; default: return(false); } //赋值ID System.Buffer.BlockCopy(desdev.ID, 0, bytes, 2, 2); //设置包头包尾 bytes[0] = 0xF1; bytes[bytes.Length - 1] = 0xF2; //设置校验和 bytes[bytes.Length - 2] = 0; for (int i = 0; i < bytes.Length - 2; i++) { bytes[bytes.Length - 2] += bytes[i]; } //传送固件数据 SysParam.cbparm = false; SysParam.sendcount = 3; while (true) { SysParam.tickcount = Environment.TickCount; SysParam.sendcount--; client.Send(bytes, bytes.Length, desdev.mendpoint); while (Environment.TickCount - SysParam.tickcount < ConstInfor.recnwtimeout && (!SysParam.cbparm)) { Thread.Sleep(1); } if (SysParam.cbparm || SysParam.sendcount <= 0) { break; } } return(SysParam.cbparm); }
private referparam ReadReferParam(NodeMsg desdev, UdpClient client, referparm type) { byte[] bytes = new byte[6]; bytes[0] = 0xF1; bytes[bytes.Length - 1] = 0xF2; System.Buffer.BlockCopy(desdev.ID, 0, bytes, 2, 2); switch (type) { case referparm.Sgthreshold: bytes[1] = 0x21; break; case referparm.Sgstrengthfac: bytes[1] = 0x23; break; case referparm.Reset: bytes[1] = 0x27; break; } bytes[bytes.Length - 2] = 0; for (int i = 0; i < bytes.Length - 2; i++) { bytes[bytes.Length - 2] += bytes[i]; } SysParam.cbparm = false; SysParam.sendcount = 3; while (true) { SysParam.tickcount = Environment.TickCount; SysParam.sendcount--; client.Send(bytes, bytes.Length, desdev.mendpoint); while (Environment.TickCount - SysParam.tickcount < ConstInfor.recrefertimeout && (!SysParam.cbparm)) { Thread.Sleep(1); } if (SysParam.sendcount <= 0 || SysParam.cbparm) { break; } } if (!SysParam.cbparm) { return(null); } return(SysParam.mfrprm); }