Example #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);
            }
        }
Example #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);
        }