Ejemplo n.º 1
0
        //Update our memory of the decoder info
        private void SaveDecoderInfo()
        {
            YuneecDecoder.DecoderGroup dg;

            if (DecoderGroups.Count(x => x.Header == (SelectedMessageHeader)) == 0)
            {
                dg = new YuneecDecoder.DecoderGroup
                {
                    Header = SelectedMessageHeader
                };
                DecoderGroups.Add(dg);
            }
            else
            {
                dg = DecoderGroups.First(x => x.Header == (SelectedMessageHeader));
                dg.DecoderInfoList.Clear();
            }

            for (var i = 0; i < _decodeDataTable.Rows.Count; i++)
            {
                var dr = _decodeDataTable.Rows[i];

                var di = new YuneecDecoder.DecoderInfo
                {
                    Name       = dr["Name"] == DBNull.Value ? "" : (string)dr["Name"],
                    StartBit   = int.Parse((string)dr["Start Bit"]),
                    BitLength  = int.Parse((string)dr["Bit Length"]),
                    StartByte  = int.Parse((string)dr["Start Byte"]),
                    ByteLength = float.Parse((string)dr["Byte Length"]),
                    Signed     = bool.Parse((string)dr["Signed"]),
                    Factor     = float.Parse((string)dr["Factor"]),
                    Unit       = (string)dr["Unit"],
                    Notes      = (string)dr["Notes"]
                };

                dg.DecoderInfoList.Add(di);
            }
        }
Ejemplo n.º 2
0
        private void loadToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var ofd = new OpenFileDialog {
                Filter = @"*.csv|*.csv", Multiselect = false
            };

            if (ofd.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            DecoderGroups.Clear();
            YuneecDecoder.DecoderGroup dg = null;

            using (var sr = new StreamReader(ofd.FileName))
            {
                while (sr.EndOfStream == false)
                {
                    var line = sr.ReadLine();
                    if (line == null)
                    {
                        continue;
                    }

                    var items = line.Split(',');

                    if (items.Length == 6) //New Decode group
                    {
                        if (dg != null)
                        {
                            DecoderGroups.Add(dg);
                        }

                        //"Length,Sequence Number,Source Address,Source PAN ID,Destination PAN ID,Destination Address"
                        dg = new YuneecDecoder.DecoderGroup
                        {
                            Header = new ZigBeeDecoder.ZigBeeHeader
                            {
                                Len         = byte.Parse(items[0]),
                                SequenceNum = byte.Parse(items[1]),
                                Src         = ushort.Parse(items[2]),
                                Pan         = ushort.Parse(items[3]),
                                DestPan     = ushort.Parse(items[4]),
                                DestAddr    = ushort.Parse(items[5])
                            }
                        };
                    }

                    if (items.Length == 9) //new Decode info
                    {
                        //"Name,Start Bit,Bit Length,Start Byte,Byte Length,Signed,Factor,Unit,Notes"
                        var di = new YuneecDecoder.DecoderInfo
                        {
                            Name       = items[0],
                            StartBit   = int.Parse(items[1]),
                            BitLength  = int.Parse(items[2]),
                            StartByte  = int.Parse(items[3]),
                            ByteLength = float.Parse(items[4]),
                            Signed     = bool.Parse(items[5]),
                            Factor     = float.Parse(items[6]),
                            Unit       = items[7],
                            Notes      = items[8]
                        };

                        dg?.DecoderInfoList.Add(di);
                    }
                }

                DecoderGroups.Add(dg);
            }

            MessageSelectionUpdate(dataGridView_messages);
        }
Ejemplo n.º 3
0
        // Runs on its own thread to get UDP packets from the Texas Instrument broadcaster
        private void UpdClientThread()
        {
            _threadRunning = true;
            while (_threadRunning)
            {
                var remoteEp = new IPEndPoint(IPAddress.Any, 11000);

                var data = _udpServer.Receive(ref remoteEp);

                if (ZigBeeDecoder.PacketSnifferHeader.TryParse(data, out var psh) == false)
                {
                    return;
                }

                if (ZigBeeDecoder.ZigBeeHeader.TryParse(data, out var header, ZigBeeDecoder.PacketSnifferHeader.Size) == false)
                {
                    return;
                }

                var message = ZigBeeDecoder.Conversion.ByteArrayToString(data, ZigBeeDecoder.PacketSnifferHeader.Size);

                //Add new message to group
                if (DecoderGroups.Count(x => x.Header == header) == 0)
                {
                    var dg = new YuneecDecoder.DecoderGroup
                    {
                        Header = header
                    };
                    DecoderGroups.Add(dg);

                    var dr = _messageDataTable.NewRow();
                    dr["Count"]   = psh.PacketNumber;
                    dr["Time"]    = DateTime.Now.ToString("HH:mm:ss:fff");
                    dr["Message"] = message;
                    _messageDataTable.Rows.Add(dr);
                }

                //Update existing message
                else
                {
                    for (var i = 0; i < _messageDataTable.Rows.Count; i++)
                    {
                        var dr    = _messageDataTable.Rows[i];
                        var bytes = ZigBeeDecoder.Conversion.Message2Bytes(dr["Message"] as string);

                        if (ZigBeeDecoder.ZigBeeHeader.TryParse(bytes, out var msgHeader) == false)
                        {
                            continue;
                        }

                        if (header != msgHeader)
                        {
                            continue;
                        }

                        dr["Count"]   = psh.PacketNumber;
                        dr["Time"]    = DateTime.Now.ToString("HH:mm:ss:fff");
                        dr["Message"] = message;
                        break;
                    }
                }

                if (SelectedMessageHeader != null &&
                    SelectedMessageHeader == header)
                {
                    SelectedMessage = ZigBeeDecoder.Conversion.Message2Bytes(message);
                    UpdateDecodeValues(SelectedMessage);
                }
            }
        }