void Train(double digit, int endian) { calcResults.Clear(); for (int idIndex = 0; idIndex < idClasses.Count; idIndex++) { IDCLASS idClass = idClasses[idIndex]; if (idClass.framePoints.Count == 0) { continue; } int dlc = idClass.framePoints[0].frameX.DataLen; for (int startIndex = 0; startIndex <= dlc - digit; startIndex++) { List <DOUBLEPOINT> lfPoints = new List <DOUBLEPOINT>(); double lfX; for (int f = 0; f < idClass.framePoints.Count; f++) { lfX = jointValue(idClass.framePoints[f].frameX, startIndex, Convert.ToInt32(Math.Floor(digit + 0.6)), endian); lfPoints.Add(new DOUBLEPOINT(lfX, idClass.framePoints[f].lfY)); } Coefficient coefficient = linearRegression(lfPoints); double sd = calculateStandardDeviation(lfPoints, coefficient); calcResults.Add(new CALCULATIONRESULT(idClass.id, startIndex, sd, coefficient, lfPoints)); } } }
void countFramePoint(List <CAN_OBJ> dataPacket, UDSServiceFormat udsReq) { for (int i = 1; i < udsFrameIndex.Count - 1; i++) { int prevIndex = udsFrameIndex[i - 1]; int index = udsFrameIndex[i]; int nextIndex = udsFrameIndex[i + 1]; //检验UDS是否正确 CAN_OBJ udsFrame = dataPacket[index]; int valueIndex = 2, c; for (c = 0; c < udsReq.parameterList.Count; c++, valueIndex++) { if (udsReq.parameterList[c] != udsFrame.Data[valueIndex]) { break; } } if (c < udsReq.parameterList.Count) { continue; } //计算值 float udsValue = 0; int cnt = udsFrame.Data[0] & 0x0f; for (int d = valueIndex; d <= cnt; d++) { udsValue *= 256; udsValue += udsFrame.Data[d]; } int allIdCount; //找前面 allIdCount = idClasses.Count; setNotFoundFramePoint(); for (int p = index - 1; p > prevIndex && allIdCount > 0; p--) { IDCLASS idClass = idClasses.Find(x => x.id.Equals(dataPacket[p].ID)); if (idClass.hasFoundFramePoint == false) { idClass.hasFoundFramePoint = true; allIdCount--; idClass.framePoints.Add(new FRAMEPOINT(dataPacket[p], udsValue)); } } //找后面 allIdCount = idClasses.Count; setNotFoundFramePoint(); for (int n = index + 1; n < nextIndex && allIdCount > 0; n++) { IDCLASS idClass = idClasses.Find(x => x.id.Equals(dataPacket[n].ID)); if (idClass.hasFoundFramePoint == false) { idClass.hasFoundFramePoint = true; allIdCount--; idClass.framePoints.Add(new FRAMEPOINT(dataPacket[n], udsValue)); } } } }