Ejemplo n.º 1
0
        private void UpdateDecodeInfo(ZigBeeDecoder.ZigBeeHeader header)
        {
            //something has changed, clear old data
            _decodeDataTable.Clear();

            //No decode info is available, create defaults
            if (DecoderGroups.Count(x => x.Header == header) == 0)
            {
                SetDecodeDefaults(header.Len);
            }
            else
            {
                var dg = DecoderGroups.First(x => x.Header == header);

                //No decode info is available, create defaults
                if (dg.DecoderInfoList.Count == 0)
                {
                    SetDecodeDefaults(header.Len);
                }
                else
                {
                    foreach (var di in dg.DecoderInfoList)
                    {
                        var dr = _decodeDataTable.NewRow();
                        dr["Name"]        = di.Name;
                        dr["Start Bit"]   = di.StartBit;
                        dr["Bit Length"]  = di.BitLength;
                        dr["Start Byte"]  = di.StartByte;
                        dr["Byte Length"] = di.ByteLength;
                        dr["Signed"]      = di.Signed;
                        dr["Factor"]      = di.Factor;
                        dr["Unit"]        = di.Unit;
                        dr["Notes"]       = di.Notes;
                        dr["Raw Data"]    = "";
                        dr["Value"]       = "";
                        _decodeDataTable.Rows.Add(dr);
                    }
                }
            }
        }
Ejemplo n.º 2
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.º 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);
                }
            }
        }