public static void UpdateDataBlock(DataBlock dataBlock, DataString dataString) { for (int i = 0; i < dataString.Data.Length; i++) { dataBlock.Parts[i].DataString = dataString.Data[i]; } }
private static DataString CreateDataString(ZBlockDescribe zBlockDescribe) { DataString dataString = new DataString(); dataString.BlockWord = zBlockDescribe.BlockWord; dataString.Data = new string[zBlockDescribe.ZParts.Length]; dataString.Value = new float[zBlockDescribe.ZParts.Length]; return(dataString); }
private void Convert() { dataString = new DataString(); dataString.BlockWord = byte.Parse(dataWidget1.DataString); zBlockDescribe = new ZBlockDescribe(); zBlockDescribe.BlockName = dataWidget3.DataString; zBlockDescribe.BlockWord = byte.Parse(dataWidget1.DataString); if (dataWidget2.DataString == "") { dataString.Data = new string[list.Count]; dataString.Value = new float[list.Count]; zBlockDescribe.ZParts = new ZPartDescribe[list.Count]; //zBlockDescribe.ZPartNum = list.Count; for (int i = 0; i < list.Count; i++) { zBlockDescribe.ZParts[i].Name = list[i].DataName; zBlockDescribe.ZParts[i].DataType = ConvertType(list[i].DataType); zBlockDescribe.ZParts[i].Index = (byte)i; dataString.Data[i] = list[i].DataString; } } else { dataString.Data = new string[list.Count + 1]; dataString.Value = new float[list.Count + 1]; zBlockDescribe.ZParts = new ZPartDescribe[list.Count + 1]; //zBlockDescribe.ZPartNum = list.Count + 1; dataString.Data[0] = dataWidget2.DataString; zBlockDescribe.ZParts[0].DataType = DataTypeEnum.Reserve; zBlockDescribe.ZParts[0].Index = 0; zBlockDescribe.ZParts[0].Name = "保留位"; zBlockDescribe.ZParts[0].BlockWord = zBlockDescribe.BlockWord; for (int i = 1; i < list.Count + 1; i++) { zBlockDescribe.ZParts[i].BlockWord = zBlockDescribe.BlockWord; zBlockDescribe.ZParts[i].Name = list[i - 1].DataName; zBlockDescribe.ZParts[i].DataType = ConvertType(list[i - 1].DataType); zBlockDescribe.ZParts[i].Index = (byte)i; dataString.Data[i] = list[i - 1].DataString; } } }
private void FlyRec(DataString dataString) { if (FlyRecStream != null) { StringBuilder sb = new StringBuilder(100); sb.Append("0x"); sb.Append(dataString.BlockWord.ToString("X")); for (int i = 0; i < dataString.Data.Length; i++) { sb.Append(" "); sb.Append(dataString.Data[i]); } FlyRecStream.WriteLine(sb.ToString()); } }
private void Convert() { dataString = new DataString(); dataString.BlockWord = byte.Parse(dataWidget1.DataString); zBlockDescribe = new ZBlockDescribe(); zBlockDescribe.BlockName = dataWidget3.DataString; zBlockDescribe.BlockWord = byte.Parse(dataWidget1.DataString); if (dataWidget2.DataString == "") { dataString.Data = new string[list.Count]; dataString.Value = new float[list.Count]; zBlockDescribe.ZParts = new ZPartDescribe[list.Count]; //zBlockDescribe.ZPartNum = list.Count; for (int i = 0; i < list.Count; i++) { zBlockDescribe.ZParts[i].Name = list[i].DataName; zBlockDescribe.ZParts[i].DataType = ConvertType(list[i].DataType); zBlockDescribe.ZParts[i].Index = (byte)i; dataString.Data[i] = list[i].DataString; } } else { dataString.Data = new string[list.Count + 1]; dataString.Value = new float[list.Count + 1]; zBlockDescribe.ZParts = new ZPartDescribe[list.Count + 1]; //zBlockDescribe.ZPartNum = list.Count + 1; dataString.Data[0] = dataWidget2.DataString; zBlockDescribe.ZParts[0].DataType = DataTypeEnum.Reserve; zBlockDescribe.ZParts[0].Index = 0; zBlockDescribe.ZParts[0].Name = "保留位"; zBlockDescribe.ZParts[0].BlockWord = zBlockDescribe.BlockWord; for (int i = 1; i < list.Count + 1; i++) { zBlockDescribe.ZParts[i].BlockWord = zBlockDescribe.BlockWord; zBlockDescribe.ZParts[i].Name = list[i-1].DataName; zBlockDescribe.ZParts[i].DataType = ConvertType(list[i-1].DataType); zBlockDescribe.ZParts[i].Index = (byte)i; dataString.Data[i] = list[i-1].DataString; } } }
public static DataString GetDataString(ZBlock zBlock, ZBlockDescribe zBlockDescribe) { DataString dataString = CreateDataString(zBlockDescribe); int p = 0; for (int i = 0; i < zBlockDescribe.ZParts.Length; i++)//根据描述信息及数据,循环完成数据的读取及格式化. { int I; uint U; float F; string S; switch (zBlockDescribe.ZParts[i].DataType) { case DataTypeEnum.U8: U = zBlock.Data[p]; p += 1; F = U; S = ToStr(U, zBlockDescribe.ZParts[i].ShowType); break; case DataTypeEnum.U16: U = BitConverter.ToUInt16(zBlock.Data, p); p += 2; F = U; S = ToStr(U, zBlockDescribe.ZParts[i].ShowType); break; case DataTypeEnum.U32: U = BitConverter.ToUInt32(zBlock.Data, p); p += 4; F = U; S = ToStr(U, zBlockDescribe.ZParts[i].ShowType); break; case DataTypeEnum.S16: I = BitConverter.ToInt16(zBlock.Data, p); p += 2; F = I; S = ToStr(I, zBlockDescribe.ZParts[i].ShowType); break; case DataTypeEnum.S32: I = BitConverter.ToInt32(zBlock.Data, p); p += 4; F = I; S = ToStr(I, zBlockDescribe.ZParts[i].ShowType); break; case DataTypeEnum.F32: F = BitConverter.ToSingle(zBlock.Data, p); p += 4; S = ToStr(F, zBlockDescribe.ZParts[i].ShowType); break; case DataTypeEnum.C: F = 0; char[] cs = new char[12]; int n = 0; for (n = 0; n < zBlockDescribe.ZParts[i].CharLength / 8; n++) { char c = (char)zBlock.Data[n]; if (c == 0) { break; } cs[n] = c; } S = new string(cs, 0, n); break; case DataTypeEnum.Reserve: U = zBlock.Reserve; F = U; S = ToStr(U, zBlockDescribe.ZParts[i].ShowType); break; default: F = 0; S = ""; break; } dataString.Data[i] = S; dataString.Value[i] = F; } return(dataString); }
private static DataString CreateDataString(ZBlockDescribe zBlockDescribe) { DataString dataString = new DataString(); dataString.BlockWord = zBlockDescribe.BlockWord; dataString.Data = new string[zBlockDescribe.ZParts.Length]; dataString.Value = new float[zBlockDescribe.ZParts.Length]; return dataString; }
public static void UpdateDataBlock(DataBlock dataBlock, DataString dataString) { for (int i = 0; i < dataString.Data.Length; i++) { dataBlock.Parts[i].DataString=dataString.Data[i]; } }
void ZProtocolProcessObj_OnReceviceBlock() { while (ZProtocolProcessObj.BufferBlockNum > 0) { ZBlock zBlock = ZProtocolProcessObj.FetchBlock();//取出数据 ZBlockDescribe zBlockDescribe = new ZBlockDescribe(); try { zBlockDescribe = ZDescribeProcessObj.Lookup(zBlock.Word);//查询描述 if (zBlockDescribe.BlockWord != 0 && zBlockDescribe.BlockWord == zBlock.Word) { DataString dataString = Converter.GetDataString(zBlock, zBlockDescribe); //格式化数据 Converter.UpdateDataBlock(Blocks[zBlock.Word], dataString); //更新显示 //附加处理 //记录飞行状态数据 if (cbFlyRec.Checked == true) { FlyRec(dataString); } //TODO:特定命令字处理 //显示消息 ShowMessage(ref zBlock); } } catch { // WriteLine("Undefine Word:0x" + zBlock.Word.ToString("X")); } try { zBlockDescribe = ZDescribeProcessObjMin.Lookup(zBlock.Word);//查询描述 if (zBlockDescribe.BlockWord != 0 && zBlockDescribe.BlockWord == zBlock.Word) { DataString dataString = Converter.GetDataString(zBlock, zBlockDescribe); //格式化数据 Converter.UpdateDataBlock(BlocksMin[zBlock.Word], dataString); //更新显示 switch (dataString.BlockWord) { case 0x5B: dataGraphics1.AddData(dataString.Value[0]); //x位置 dataGraphics2.AddData(dataString.Value[1]); //y位置 dataGraphics3.AddData(dataString.Value[2]); //高度 break; case 0x5C: dataGraphics4.AddData(dataString.Value[0]); //x速度 dataGraphics6.AddData(dataString.Value[1]); //y速度 dataGraphics10.AddData(dataString.Value[2]); //z速度 break; case 0x59: dataGraphics5.AddData(dataString.Value[0]); //俯仰角 dataGraphics7.AddData(dataString.Value[1]); //滚转角 dataGraphics9.AddData(dataString.Value[2]); //航向角 break; case 0x5A: dataGraphics8.AddData(dataString.Value[2]); //航向角速度 break; case 0x52: dataGraphicsTwoLine1.AddData(dataString.Value[0], 0); //算法舵量A dataGraphicsTwoLine2.AddData(dataString.Value[1], 0); //算法舵量B dataGraphicsTwoLine3.AddData(dataString.Value[2], 0); //算法舵量C break; case 0x53: dataGraphicsTwoLine4.AddData(dataString.Value[0], 0); //算法舵量D dataGraphicsTwoLine5.AddData(dataString.Value[1], 0); //算法舵量E break; case 0x54: dataGraphicsTwoLine1.AddData(dataString.Value[0], 1); //遥控舵量A dataGraphicsTwoLine2.AddData(dataString.Value[1], 1); //遥控舵量B dataGraphicsTwoLine3.AddData(dataString.Value[2], 1); //遥控舵量C break; case 0x55: dataGraphicsTwoLine4.AddData(dataString.Value[0], 1); //遥控舵量D dataGraphicsTwoLine5.AddData(dataString.Value[1], 1); //遥控舵量E break; default: break; } } } catch { // WriteLine("Undefine Word:0x" + zBlock.Word.ToString("X")); } } }