コード例 #1
0
        public string getNextMsg()
        {
            byte[] msg = new byte[16];

            int bytesRead = inputFS.Read(msg, 0, 16);

            if (bytesRead < 16)
            {
                inputFS.Close();
                blockStatsSW.Flush();
                blockStatsSW.Close();
                errorStatsSW.Flush();
                errorStatsSW.Close();
                rawMsgsSW.Flush();
                rawMsgsSW.Close();
                return(""); // Empty string indicates EOF
            }
            msgCount++;
            rawMsgsSW.Write(msgCount.ToString() + " " + BuildOldStyleMsg(msg) + "\n");
            // Check to make sure message is valid

            // Check message format
            if (!(CheckFormat(msg)))
            {
                errorCounter++;
                if (!(ignoreFormatErrors))
                {
                    MessageBoxResult res = MessageBox.Show("Message does not match required format!\n" +
                                                           "Select Yes to continue, No to ignore further errors, or Cancel to stop processing " +
                                                           "messages.\n" + BitConverter.ToString(msg).Replace("-", "") + "\n" + this.errorDetail,
                                                           "Parse Error", MessageBoxButton.YesNoCancel);
                    if (res == MessageBoxResult.No)
                    {
                        ignoreFormatErrors = true;
                    }
                    if (res == MessageBoxResult.Cancel)
                    {
                        //cancelConversion = true;
                        return("");
                    }
                }

                //return "FORMAT0000000000000000000D"; // Breaks Timestamp extraction
                //return "0000000000000000000000000D"; // Pick something better for error indication
                //Temp treating like an OK message
            }

            CheckBlock(msg);

            if (cancelConversion)
            {
                if (errorCounter > 0)
                {
                    MessageBoxResult res = MessageBox.Show("There were errors encountered during processing. See error log for details.\nThe total number of errors found is " + errorCounter.ToString() + " errors.", "Parse Error", MessageBoxButton.OK);
                }
                return("");
            }
            else // we have a good message, lets see if the timestamp is OK
            {
                string retVal    = BuildOldStyleMsg(msg);
                int    timestamp = MsgUtils.getTimestampInt(retVal);
                if (!bfirstTimestamp)
                {
                    firstTimestamp  = timestamp;
                    bfirstTimestamp = true;
                }
                if (!(timestamp >= lastTimestamp))
                {
                    errorCounter++;
                    string errorString = "\n\nError Count: " + errorCounter.ToString() +
                                         "\n Message Number: " + msgCount.ToString() +
                                         "\n This Timestamp: " + timestamp.ToString() + "\n High Timestamp: " +
                                         lastTimestamp.ToString() + "\n Difference: " + (timestamp - lastTimestamp).ToString() +
                                         "\n ID " + MsgUtils.getCobIdString(retVal);
                    errorStatsSW.Write(errorString);

                    if (!(ignoreTimestampErrors))
                    {
                        MessageBoxResult res = MessageBox.Show("Timestamp Error: Current timestamp is earlier " +
                                                               "than a previous timestamp!\nSelect Yes to continue, No to ignore further errors, or " +
                                                               "Cancel to stop processing messages.\n" + errorString,
                                                               "Parse Error",
                                                               MessageBoxButton.YesNoCancel);

                        if (res == MessageBoxResult.No)
                        {
                            ignoreTimestampErrors = true;
                        }
                        if (res == MessageBoxResult.Cancel)
                        {
                            //cancelConversion = true;
                            retVal = "";
                        }
                    }
                }


                if (timestamp >= lastTimestamp)
                {
                    lastTimestamp = timestamp;
                }

                // Format message like the old format
                // Timestamp , cob ID, data bytes, data
                return(retVal);
            }
        }