Beispiel #1
0
        private void M_udpListener_NewMessageReceived(object sender, MyMessageArgs e)
        {
            //StringBuilder myString = new StringBuilder(BitConverter.ToString(e.data));
            //myString.Append("\r\n\r\n");
            //writer.WriteToFile(myString);

            dataReadCounter++;
            telemetry.CopyByteArrayToThis(e.data);

            if (this.InvokeRequired)
            {
                this.Invoke((MethodInvoker)(delegate
                {
                    if (!DataReceiveResolutionTimer.Enabled)
                    {
                        lbl_ReadCounter.ForeColor = Color.FromArgb(229, 126, 49);
                        lbl_ReadCounter.Font = new Font(lbl_ReadCounter.Font, FontStyle.Bold);
                        lbl_ReadCounter.Text = dataReadCounter.ToString();
                        lbl_LastDataTime.Text = "Last Data Time : " + DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss");
                        DataReceiveResolutionTimer.Start();
                    }
                }));
            }
            else
            {
                if (!DataReceiveResolutionTimer.Enabled)
                {
                    lbl_ReadCounter.ForeColor = Color.FromArgb(229, 126, 49);
                    lbl_ReadCounter.Font      = new Font(lbl_ReadCounter.Font, FontStyle.Bold);
                    lbl_ReadCounter.Text      = dataReadCounter.ToString();
                    lbl_LastDataTime.Text     = "Last Data Time : " + DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss");
                    DataReceiveResolutionTimer.Start();
                }
            }
        }
        private void M_udpListener_NewMessageReceived(object sender, MyMessageArgs e)
        {
            //StringBuilder myString = new StringBuilder(BitConverter.ToString(e.data));
            //myString.Append("\r\n\r\n");
            //writer.WriteToFile(myString);

            dataReadCounter++;
            UInt16 headerSize  = 2;
            UInt16 checksumLen = 4;
            UInt16 messageLen  = BitConverter.ToUInt16(e.data, 2);

            if (e.data.Length >= messageLen + checksumLen)
            {
                byte[] message  = e.data.Skip(headerSize).Take(messageLen).ToArray();
                byte[] chk      = message.Skip(messageLen - checksumLen).Take(checksumLen).ToArray();
                UInt32 checksum = BitConverter.ToUInt32(chk, 0);

                if (Utils.Utils.Adler32(message, (UInt16)(messageLen - checksumLen)) == checksum)
                {
                    //telemetry.CopyByteArrayToThis(e.data.Skip(24).Take(BitConverter.ToUInt16(e.data, 22)).ToArray());
                    HighLigtLabel(lbl_ReadCounter, dataReadCounter.ToString());
                    telemetry = allData.Update(e.data.Skip(24).Take(BitConverter.ToUInt16(e.data, 22)).ToArray());
                    MEMsData.InsertRecord(telemetry.modules.mems.acce);
                }
                else
                {
                    checksumErrorCounter++;
                    //HighLigtLabel(lbl_ChecksumErrorCounter, "Checksum Error Count : " + checksumErrorCounter.ToString());
                }
            }
        }