示例#1
0
        public void ProcessTextMessage(string line)
        {
            lock (_lock)
            {
                var messageList     = new ReceivedMessageList();
                var receivedMessage = messageList.Add(++_rawId, line);

                CanMessage canMessage = ProcessMessageData(line, receivedMessage);
                if (canMessage != null)
                {
                    receivedMessage.CanMessage = canMessage;
                }

                PushReceivedMessages(messageList);
            }
        }
示例#2
0
        int ParseMessages(string data, ReceivedMessageList messageList)
        {
            int length = data.Length;
            int pos    = 0;

            while (true)
            {
                int remain = length - pos;
                if (remain <= 0)
                {
                    break;
                }

                int c = data[pos];
                switch (c)
                {
                case 13:
                    messageList.Add(++_rawId, "ok");
                    pos++;
                    continue;

                case 7:
                    messageList.Add(++_rawId, "error");
                    pos++;
                    continue;
                }

                int end = data.IndexOf('\r', pos);
                if (end < 0)
                {
                    return(pos);
                }

                string message = data.Substring(pos, end - pos);
                pos = end + 1;

                var receivedMessage = messageList.Add(++_rawId, message);


                CanMessage canMessage = ProcessMessageData(message, receivedMessage);
                if (canMessage != null)
                {
                    receivedMessage.CanMessage = canMessage;
                }
            }
            return(-1);
        }
示例#3
0
        internal bool ProcessMessage(CanMessage canMessage, int version)
        {
            var status = Find(canMessage.Data);

            if (status == null)
            {
                status = new CanDataStatus(canMessage);
                _dict.Add(canMessage.Data, status);
                Add(status);
                status.ProcessMessage(canMessage, version);
                return(true);
            }
            else
            {
                status.ProcessMessage(canMessage, version);
                return(false);
            }
        }
示例#4
0
        internal void ProcessMessage(CanMessage canMessage)
        {
            _lastCanMessages.Add(canMessage);
            while (_lastCanMessages.Count > MAX_MESSAGES_TO_HOLD)
            {
                _lastCanMessages.RemoveAt(0);
            }

            Count++;
            if (_isMaskSet)
            {
                canMessage.ApplyMask(_dataMask);
            }
            if (_dataStatuses.ProcessMessage(canMessage, Count))
            {
                NewCount++;
            }
        }
示例#5
0
        private void UpdateData(CanMessage m1, CanMessage m2)
        {
            string text1 = "", text2 = "", diff = "", item1 = "", item2 = "";

            if (m1 != null)
            {
                item1 = m1.DisplayText;
                text1 = Helpers.DataAsBinaryString(m1.Data);
            }
            if (m2 != null)
            {
                item2 = m2.DisplayText;
                text2 = Helpers.DataAsBinaryString(m2.Data);
                diff  = Helpers.DataAsBinaryDiffString(m1.Data ^ m2.Data);
            }

            tbData1.Text    = text1;
            tbData2.Text    = text2;
            tbDataDiff.Text = diff;

            tbItem1.Text = item1;
            tbItem2.Text = item2;
        }
示例#6
0
 internal void ProcessMessage(CanMessage canMessage, int count)
 {
     _message = canMessage;
     _version = count;
     _count++;
 }
示例#7
0
 internal CanDataStatus(CanMessage message)
 {
     _message = message;
 }
示例#8
0
 public void Update(CanMessage m)
 {
     Message = m;
     Version++;
     Count++;
 }
示例#9
0
 public CanMessageStats(CanMessage mes)
 {
     Message = mes;
 }
示例#10
0
        CanMessage ProcessMessageData(string data, ReceivedMessage receivedMessage)
        {
            CanMessage canMessage = null;

            Exception processingException = null;

            try
            {
                int length = data.Length;
                int pos    = 0;
                int c      = data[pos];
                int idLen  = 0;
                switch (c)
                {
                case 'T':
                    idLen = 8;
                    break;

                case 't':
                    idLen = 3;
                    break;
                }

                while (true)
                {
                    if (idLen <= 0)
                    {
                        break;
                    }

                    pos++;

                    if (length < idLen + pos)
                    {
                        break;
                    }

                    string idTxt = data.Substring(pos, idLen);
                    pos += idLen;

                    if (length < pos + 1)
                    {
                        break;
                    }

                    int dataByteCount = int.Parse(data.Substring(pos, 1));
                    if (dataByteCount < 0 || dataByteCount > 8)
                    {
                        break;
                    }
                    pos++;
                    if (length < pos + dataByteCount * 2)
                    {
                        break;
                    }

                    string dataTxt = data.Substring(pos, dataByteCount * 2);
                    pos += dataByteCount * 2;

                    string timeTxt = "00";
                    if (pos < length)
                    {
                        timeTxt = data.Substring(pos);
                    }

                    canMessage           = new CanMessage();
                    canMessage.Id        = Convert.ToInt32(idTxt, 16);
                    canMessage.Time      = Convert.ToInt32(timeTxt, 16);
                    canMessage.DataCount = dataByteCount;
                    for (int i = 0; i < dataByteCount; i++)
                    {
                        string s = dataTxt.Substring(i * 2, 2);
                        byte   b = (byte)Convert.ToInt32(s, 16);
                        canMessage.Data = Helpers.SetDataByte(canMessage.Data, i, b);
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                processingException = ex;
                canMessage          = null;
            }

            if (processingException != null)
            {
                receivedMessage.RawText = "Invalid data: " + data;
                string errorMsg = $"\n{DateTime.Now} Exception: {processingException.Message}\nProcessing '{data}'\nStack Trace:\n {processingException.StackTrace}";
                System.IO.File.AppendAllText("error.log", errorMsg);
            }
            return(canMessage);
        }