/// <summary> /// 生成csv文件 /// </summary> /// <param name="logtxt"></param> /// <param name="path"></param> public static void WriteCSV(UnmannedData logtxt, string path, Boolean isFirstWriteCsv) { if (string.IsNullOrEmpty(path)) { return; } try { string strPath = DateTime.Now.ToString("yyyyMMdd") + "RadarDatalog.csv"; StreamWriter sw = new StreamWriter(new FileStream(path + "\\" + strPath, FileMode.Append), Encoding.GetEncoding("Windows-1252"));//Windows-1252 \GB2312 if (isFirstWriteCsv) { WriteHeader(sw); } string txt = logtxt.V + "," + logtxt.A + "," + logtxt.R + "," + logtxt.P + "," + logtxt.S + "," + logtxt.CH + "," + logtxt.FrameState + "," + logtxt.SysFrameNo; //sw.Write(); sw.WriteLine(txt); sw.Close(); } catch { } }
/// <summary> /// 单条BK数据处理 /// </summary> /// <param name="data"></param> /// <returns></returns> /// Num 1 fft 15380 sig 36227 clu 55 kf 139 //--- F 4690 O 1/2/0! --- //BK //00: S 55.62, R 2.05, V 0.00, A -4.00 //AK //00: S 49.54, R 5.46, V 0.02, A -12.05,S 1 //01: S 55.62, R 2.09, V -0.04, A -3.29,S 1 public static List <UnmannedData> SingleBkDataProcess(string data) { //解析头 string framSystemNumber = DecodeHeadData(data); if (string.IsNullOrEmpty(framSystemNumber)) { return(null); } //解析BK -- string[] resultFirstString = Regex.Split(data, "BK", RegexOptions.IgnoreCase); if (resultFirstString.Length > 1) { string[] resultSecondString = Regex.Split(resultFirstString[1], "AK", RegexOptions.IgnoreCase); if (resultSecondString.Length < 2) { return(null); } string[] strTemp = Regex.Split(resultSecondString[0], "\r\n\t", RegexOptions.IgnoreCase); List <UnmannedData> nameDataList = new List <UnmannedData>(); for (int i = 0; i < strTemp.Length; i++) { if (string.IsNullOrEmpty(strTemp[i])) { continue; } UnmannedData nameData = new UnmannedData(); string[] strS = Regex.Split(strTemp[i], ",", RegexOptions.IgnoreCase); if (strS.Length < 4) { continue; //00: S 55.62, R 2.05, V 0.00, A -4.00 } string[] strST = strS[0].Split('S'); string[] strSR = strS[1].Split('R'); string[] strSV = strS[2].Split('V'); string[] strSA = strS[3].Split('A'); if (strST.Length < 2 || strSR.Length < 2 || strSV.Length < 2 || strSA.Length < 2 || strSA.Length < 2) { continue; } if (string.IsNullOrEmpty(strST[1]) || string.IsNullOrEmpty(strSR[1]) || string.IsNullOrEmpty(strSV[1]) || string.IsNullOrEmpty(strSA[1])) { continue; } if (!IsNumeric(strST[1]) || !IsNumeric(strSR[1]) || !IsNumeric(strSV[1]) || !IsNumeric(strSA[1])) { continue; } nameData.P = double.Parse(strST[1].Replace(" ", "")); nameData.R = double.Parse((strSR[1].Replace(" ", ""))); nameData.V = double.Parse(strSV[1].Replace(" ", "")); nameData.A = double.Parse(strSA[1].Replace(" ", "")); nameData.DataType = "BK"; nameData.CH = i; nameData.SysFrameNo = framSystemNumber; nameDataList.Add(nameData); } return(nameDataList); } else { return(null); } }
public static String FrameStart = "0500"; //帧结尾 /// <summary> /// 解析PCAN数据 /// </summary> /// <param name="strData"></param> /// <returns></returns> public static List <UnmannedData> AnalyticalPcanData(List <String> strData) { if (strData.Count <= 0) { return(null); } List <UnmannedData> listUd = new List <UnmannedData>(); uint[] DataBuf = new uint[9]; int j = 0; foreach (String temp in strData) { j++; string[] strArray = temp.Split(' '); for (int i = 0; i < strArray.Length - 1; i++) { DataBuf[i] = Convert.ToUInt32(strArray[i], 16); } if (((DataBuf[0] << 8 | DataBuf[1]) & 0xFFFF) == 0xFFFF) { flag = 1;//当前报文是标量报文 } else { flag = 0;//当前报文为矢量报文 } UnmannedData ud = new UnmannedData(); //当前报文是标量报文时按照标量报文格式进行解析 if (flag == 1) { float R = (float)(((DataBuf[2] << 8) | DataBuf[3]) / 10.0); float V = (float)((((DataBuf[4] << 8) | DataBuf[5]) / 100.0) - 81.9); float angle1 = (float)(((DataBuf[6] << 8) | DataBuf[7]) / 10.0 - 180.0); ud.A = angle1; ud.R = R; ud.V = V; ud.DataType = "AK"; ud.CH = j; ud.FrameState = 1; } else if (flag == 0) { //当前的报文是矢量报文时按照矢量报文的格式解析 float Rx = (float)((((DataBuf[0] & 0x7f) << 8) | DataBuf[1]) / 100.0); //不算最高位的符号位 if ((DataBuf[0] & 0x80) > 0) //Rx是负数的情况 { Rx = -Rx; } float Ry = (float)(((DataBuf[2] & 0x7f) << 8 | DataBuf[3]) / 100.0);//不算最高位的符号位 if ((DataBuf[2] & 0x80) > 0) { Ry = -Ry; } float Vx = (float)(((DataBuf[4] & 0x7f) << 2 | (DataBuf[5] & 0xc0) >> 6) / 10.0);//不算最高位的符号位 if ((DataBuf[4] & 0x80) > 0) { Vx = -Vx; } float Vy = (float)((((DataBuf[5] & 0x1f) << 4) | (DataBuf[6] & 0xf0) >> 4) / 10.0); if ((DataBuf[5] & 0x20) > 0) { Vy = -Vy; } float angle = (float)((((DataBuf[6] & 0x07) << 8) | DataBuf[7]) / 10.0); if ((DataBuf[6] & 0x8) > 0)//angle是负数 { angle = -angle; } //暂时不做处理 //return null; ud.A = Math.Round(angle, 2); //ud.A = Convert.ToSingle(Convert.ToDecimal(angle).ToString("f2")); //ud.R = Math.Sqrt(Rx * Rx + Ry * Ry); ud.R = Math.Round(Rx, 2); ud.V = Math.Round(Ry, 2); ud.CH = j; ud.DataType = "AK"; ud.FrameState = 1; Console.WriteLine("ud.R = " + ud.R + " ;ud.V = " + ud.V + " ;ud.A = " + ud.A); } listUd.Add(ud); } return(listUd); }
/// <summary> /// 单条AK数据处理 /// </summary> /// <param name="data"></param> /// <returns></returns> /// Num 1 fft 15380 sig 36227 clu 55 kf 139 //--- F 4690 O 1/2/0! --- //BK //00: S 55.62, R 2.05, V 0.00, A -4.00 //AK //00: S 49.54, R 5.46, V 0.02, A -12.05,S 1 //01: S 55.62, R 2.09, V -0.04, A -3.29,S 1 public static List <UnmannedData> SingleAkDataProcess(string data) { //解析头 -- F 4690 string framSystemNumber = DecodeHeadData(data); if (string.IsNullOrEmpty(framSystemNumber)) { return(null); } //解析Ak -- string[] resultAkString = Regex.Split(data, "AK", RegexOptions.IgnoreCase); if (resultAkString.Length > 1) { string[] strAkTemp = Regex.Split(resultAkString[1], "\r\n\t", RegexOptions.IgnoreCase); List <UnmannedData> nameDataList = new List <UnmannedData>(); for (int i = 0; i < strAkTemp.Length; i++) { if (string.IsNullOrEmpty(strAkTemp[i])) { continue; } UnmannedData nameData = new UnmannedData(); string[] strS = Regex.Split(strAkTemp[i], ",", RegexOptions.IgnoreCase); if (strS.Length < 5) { continue; //00: S 50.65, R 5.45, V 0.00, A -11.29,S 1 } string[] strST = strS[0].Split('S'); string[] strSR = strS[1].Split('R'); string[] strSV = strS[2].Split('V'); string[] strSA = strS[3].Split('A'); string pass = @"[\t\r\n\s]"; string[] strSS = Regex.Replace(strS[4], pass, "").Split('S'); if (strST.Length < 2 || strSR.Length < 2 || strSV.Length < 2 || strSA.Length < 2 || strSS.Length < 2) { continue; } if (string.IsNullOrEmpty(strST[1]) || string.IsNullOrEmpty(strSR[1]) || string.IsNullOrEmpty(strSV[1]) || string.IsNullOrEmpty(strSA[1]) || string.IsNullOrEmpty(strSS[1])) { continue; } if (!IsNumeric(strST[1]) || !IsNumeric(strSR[1]) || !IsNumeric(strSV[1]) || !IsNumeric(strSA[1]) || !IsNumeric(strSS[1])) { continue; } nameData.P = double.Parse(strST[1].Replace(" ", "")); nameData.R = double.Parse(strSR[1].Replace(" ", "")); nameData.V = double.Parse(strSV[1].Replace(" ", "")); nameData.A = double.Parse(strSA[1].Replace(" ", "")); nameData.S = Convert.ToInt32(strSS[1].Replace(" ", "")); nameData.CH = i; nameData.FrameState = Convert.ToInt32(strSS[1]); nameData.DataType = "AK"; nameData.SysFrameNo = framSystemNumber; nameDataList.Add(nameData); } return(nameDataList); } return(null); }