Пример #1
0
 private void deletePGNsToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (dataGridViewPGNs.Focused)
     {
         // We set all selected items to null, and then rebuild the array of PGNDefns
         for (int i = 0; i < dataGridViewPGNs.Rows.Count; i++)
         {
             if (dataGridViewPGNs.Rows[i].Selected)
             {
                 PGNDefnCol.PGNDefns[i] = null;
             }
         }
         var newPGNDefns = new PGNDefn[PGNDefnCol.PGNDefns.Length - dataGridViewPGNs.SelectedRows.Count];
         int j           = 0;
         for (int i = 0; i < PGNDefnCol.PGNDefns.Length; i++)
         {
             if (PGNDefnCol.PGNDefns[i] != null)
             {
                 newPGNDefns[j++] = PGNDefnCol.PGNDefns[i];
             }
         }
         PGNDefnCol.PGNDefns = newPGNDefns;
         UpdateGridDisplays(GridViewsUpdateType.RebindPGNs);
     }
 }
Пример #2
0
        // Request a screen update of the GridViews and ProopertyGrid
        private void UpdateGridDisplays(GridViewsUpdateType UpdateType)
        {
            if (PGNDefnCol == null)
            {
                dataGridViewPGNs.DataSource       = null;
                dataGridViewFields.DataSource     = null;
                propertyGridField.SelectedObject  = null;
                toolStripStatusLabelPGNCount.Text = "";
            }
            if (UpdateType >= GridViewsUpdateType.RebindPGNs)
            {
                if (PGNDefnCol == null)
                {
                    dataGridViewPGNs.DataSource       = null;
                    dataGridViewPGNs.Enabled          = false;
                    toolStripStatusLabelPGNCount.Text = "";
                }
                else
                {
                    dataGridViewPGNs.DataSource       = PGNDefnCol.PGNDefns;
                    dataGridViewPGNs.Enabled          = true;
                    toolStripStatusLabelPGNCount.Text = PGNDefnCol.PGNDefns.Count() + " PGNs.";
                    if (UpdateType == GridViewsUpdateType.RebindPGNsAndSelectLast)
                    {
                        dataGridViewPGNs.FirstDisplayedScrollingRowIndex = dataGridViewPGNs.RowCount - 1;
                        dataGridViewPGNs.Rows[dataGridViewPGNs.RowCount - 1].Selected = true;
                    }
                }
            }
            if (UpdateType >= GridViewsUpdateType.RebindFields)
            {
                if ((dataGridViewPGNs.DataSource != null) &&
                    (dataGridViewPGNs.SelectedRows.Count == 1) &&
                    (dataGridViewPGNs.SelectedRows.Count <= PGNDefnCol.PGNDefns.Length))
                {
                    PGNDefn pgnDefn = PGNDefnCol.PGNDefns[dataGridViewPGNs.SelectedRows[0].Index];
                    dataGridViewFields.DataSource = pgnDefn.Fields;

                    dataGridViewFields.Enabled = true;
                    dataGridViewFields.Refresh();
                    // dataGridViewFields_SelectionChanged(sender, null);
                    FieldDataGridTitle.Text = "PGN "
                                              + pgnDefn.PGN
                                              + (((pgnDefn.Name != null && pgnDefn.Name != "") ? " (" + PGNDefnCol.PGNDefns[dataGridViewPGNs.SelectedRows[0].Index].Name + ")" : ""))
                                              + " Fields";
                    if (UpdateType == GridViewsUpdateType.RebindFieldsAndSelectLast)
                    {
                        dataGridViewFields.FirstDisplayedScrollingRowIndex = dataGridViewFields.RowCount - 1;
                        dataGridViewFields.Rows[dataGridViewFields.RowCount - 1].Selected = true;
                    }
                }
                else
                {
                    dataGridViewFields.DataSource = null;
                    dataGridViewFields.Enabled    = false;
                    FieldDataGridTitle.Text       = "(No PGN selected)";
                    // dataGridViewFields_SelectionChanged(sender, null);
                }
            }
            if (UpdateType >= GridViewsUpdateType.RebindFieldProperties)
            {
                if ((dataGridViewFields.DataSource != null) && (dataGridViewFields.SelectedRows.Count == 1))
                {
                    propertyGridField.SelectedObject = ((N2kField[])dataGridViewFields.DataSource)[dataGridViewFields.SelectedRows[0].Index];
                    propertyGridField.Enabled        = true;
                    propertyGridField.Refresh();
                    PropertyGridTitle.Text             = "Definition of Field '" + ((N2kField[])dataGridViewFields.DataSource)[dataGridViewFields.SelectedRows[0].Index].Name + "'";
                    FieldClassTypeListComboBox.Enabled = true;
                    FieldClassTypeListComboBox.Text    = (((N2kField[])dataGridViewFields.DataSource)[dataGridViewFields.SelectedRows[0].Index]).GetType().Name;
                    // We remember the values of the properties in each PGNField
                    UpdatePropertyValuesDict(ref FieldPropertyValues, propertyGridField.SelectedObject);
                }
                else
                {
                    propertyGridField.SelectedObject   = null;
                    propertyGridField.Enabled          = false;
                    PropertyGridTitle.Text             = "(No field selected)";
                    FieldClassTypeListComboBox.Text    = "";
                    FieldClassTypeListComboBox.Enabled = false;
                }
            }
        }
Пример #3
0
        public PGNDefn[] GetPGNInfos()
        // Get an array of PGNDefn records, effectively converting from KeesDefinitions
        // into our own PGNDefn array
        {
            PGNDefn[] result = new PGNDefn[KeesPGNDefns.Count()];
            int       j      = 0;

            foreach (KeesPGNDefn kPGN in KeesPGNDefns)
            {
                N2kField[] f = new N2kField[kPGN.Fields != null ? kPGN.Fields.Count() : 0];

                if (kPGN.Fields != null)
                {
                    int i = 0;
                    foreach (KeesField kField in kPGN.Fields)
                    {
                        double scale;
                        if (!double.TryParse(kField.Resolution, NumberStyles.Number, CultureInfo.InvariantCulture, out scale))
                        {
                            scale = 1.0;
                        }

                        /* // Old method for working out scale...
                         * switch (kField.Resolution)
                         * {
                         *  case "0.1":
                         *      scale = 0.1;
                         *      break;
                         *  case "0.01":
                         *      scale = 0.01;
                         *      break;
                         *  case "0.001":
                         *      scale = 0.001;
                         *      break;
                         *  case "0.004":
                         *      scale = 0.004;
                         *      break;
                         *  case "1e-006":
                         *      scale = 1e-6;
                         *      break;
                         *  case "0.0001":
                         *      scale = 0.001;
                         *      break;
                         *  default:
                         *      scale = 1;
                         *      break;
                         * }
                         */

                        if ((kPGN.PGN == 130842) && (kField.Order == 17) && (kField.Name == "Spare"))
                        {
                            // AJM: I think this is probably an unsigned integer based on Description="0=unavailable"
                            f[i++] = new N2kUIntField {
                                Name = kField.Name, BitOffset = kField.BitOffset, BitLength = kField.BitLength, Description = kField.Description
                            };
                        }
                        else if (CultureInfo.InvariantCulture.CompareInfo.IndexOf(kField.Name, "Instance", CompareOptions.IgnoreCase) >= 0)
                        {
                            f[i++] = new N2kInstanceField {
                                Name = kField.Name, BitOffset = kField.BitOffset, BitLength = kField.BitLength, Description = kField.Description
                            };
                        }
                        else if ((kField.Name == "SID"))
                        {
                            f[i++] = new N2kUIntField {
                                FormatAs = FormatEnum.SID, Name = kField.Name, BitOffset = kField.BitOffset, BitLength = kField.BitLength, Description = kField.Description
                            };
                        }
                        else if ((kField.Name == "PGN"))
                        {
                            // We force all PGNBs to be UInt; Kees has one defined as an Integer in 59904, but no such 'Integer' defn in 59392
                            f[i++] = new N2kUIntField {
                                Name = kField.Name, BitOffset = kField.BitOffset, BitLength = kField.BitLength, Description = kField.Description
                            };
                        }
                        else if ((kField.Name == "Speed") || (kField.Name == "SOG"))
                        {
                            //f[i++] = new SpeedField { DisplayName = kField.DisplayName, BitOffset = kField.BitOffset, BitLength = kField.BitLength, Description = kField.Description, Scale = scale };
                            f[i++] = new N2kUDblField {
                                FormatAs = FormatEnum.Speed, Name = kField.Name, BitOffset = kField.BitOffset, BitLength = kField.BitLength, Description = kField.Description, Scale = scale
                            };
                        }
                        else if ((kField.Name == "Depth") || (kField.Name == "SOG"))
                        {
                            // This is probably unsigned based on FFFFFFFF appearing to mean 'unavailable'
                            f[i++] = new N2kUDblField {
                                FormatAs = FormatEnum.Length, Name = kField.Name, BitOffset = kField.BitOffset, BitLength = kField.BitLength, Description = kField.Description, Scale = scale
                            };
                        }
                        else
                        {
                            switch (kField.Type)
                            {
                            case null:
                                if ((kField.Resolution == null) || (kField.Resolution == ""))
                                {
                                    f[i++] = new N2kUIntField {
                                        Name = kField.Name, BitOffset = kField.BitOffset, BitLength = kField.BitLength, Description = kField.Description
                                    };
                                }
                                else
                                {
                                    f[i++] = new N2kDblField {
                                        Name = kField.Name, BitOffset = kField.BitOffset, BitLength = kField.BitLength, Description = kField.Description, Scale = scale
                                    };
                                }
                                break;

                            case "ASCII text":
                                f[i++] = new N2kASCIIField {
                                    Name = kField.Name, BitOffset = kField.BitOffset, BitLength = kField.BitLength, Description = kField.Description
                                };
                                break;

                            case "Binary data":
                            case "String with start/stop byte":      // We need new type for this
                                f[i++] = new N2kBinaryField {
                                    Name = kField.Name, BitOffset = kField.BitOffset, BitLength = kField.BitLength, Description = kField.Description
                                };
                                break;

                            case "Manufacturer code":
                                f[i++] = new N2kBinaryField {
                                    Name = kField.Name, BitOffset = kField.BitOffset, BitLength = kField.BitLength, Description = kField.Description
                                };
                                break;

                            case "Date":
                                //f[i++] = new DateField { DisplayName = kField.DisplayName, BitOffset = kField.BitOffset, BitLength = kField.BitLength, Description = kField.Description };
                                f[i++] = new N2kUIntField {
                                    FormatAs = FormatEnum.Date, Name = kField.Name, BitOffset = kField.BitOffset, BitLength = kField.BitLength, Description = kField.Description
                                };
                                break;

                            case "Degrees":      // Degrees changed to angle on Kees?
                            case "Angle":
                                if (((kField.Resolution == "0.0001 rad") || (kField.Resolution == "0.0001")))
                                {
                                    // We convert the units from Radians to Degrees
                                    if (kField.Signed)
                                    {
                                        f[i++] = new N2kDblField {
                                            FormatAs = FormatEnum.Heading, Name = kField.Name, BitOffset = kField.BitOffset, BitLength = kField.BitLength, Description = kField.Description, Scale = 0.0001 * 180 / Math.PI
                                        };
                                    }
                                    else
                                    {
                                        f[i++] = new N2kUDblField {
                                            FormatAs = FormatEnum.Heading, Name = kField.Name, BitOffset = kField.BitOffset, BitLength = kField.BitLength, Description = kField.Description, Scale = 0.0001 * 180 / Math.PI
                                        };
                                    }
                                }
                                else
                                {
                                    Console.WriteLine("Unknown Kees Degrees field data");
                                }
                                break;

                            case "IEEE Float":
                                f[i++] = new N2kDblField {
                                    FormatAs = FormatEnum.Number, Name = kField.Name, BitOffset = kField.BitOffset, BitLength = 32, Description = kField.Description, Scale = scale
                                };
                                break;

                            case "Integer":
                                f[i++] = new N2kIntField {
                                    Name = kField.Name, BitOffset = kField.BitOffset, BitLength = kField.BitLength, Description = kField.Description
                                };
                                break;

                            case "Latitude":
                                if (kField.BitLength == 32)
                                {
                                    // LatField
                                    f[i++] = new N2kDblField {
                                        FormatAs = FormatEnum.Latitude, Name = kField.Name, BitOffset = kField.BitOffset, BitLength = 32, Description = kField.Description, Scale = 1e-7
                                    };
                                }
                                else if (kField.BitLength == 64)
                                {
                                    // LatField
                                    f[i++] = new N2kDblField {
                                        FormatAs = FormatEnum.Latitude, Name = kField.Name, BitOffset = kField.BitOffset, BitLength = 64, Description = kField.Description, Scale = 1e-16
                                    };
                                }
                                else
                                {
                                    Console.WriteLine("Unknown Kees Latitude field data");
                                }
                                break;

                            case "Longitude":
                                if (kField.BitLength == 32)
                                {
                                    // LonField
                                    f[i++] = new N2kDblField {
                                        FormatAs = FormatEnum.Longitude, Name = kField.Name, BitOffset = kField.BitOffset, BitLength = 32, Description = kField.Description, Scale = 1e-7
                                    };
                                }
                                else if (kField.BitLength == 64)
                                {
                                    // LonField
                                    f[i++] = new N2kDblField {
                                        FormatAs = FormatEnum.Longitude, Name = kField.Name, BitOffset = kField.BitOffset, BitLength = 64, Description = kField.Description, Scale = 1e-16
                                    };
                                }
                                else
                                {
                                    Console.WriteLine("Unknown Kees Longitude field data");
                                }
                                break;

                            case "Lookup table":
                                f[i++] = new N2kEnumField {
                                    Name = kField.Name, BitOffset = kField.BitOffset, BitLength = kField.BitLength, Description = kField.Description, EnumPairArray = kField.EnumPairArray
                                };
                                break;

                            case "Temperature":
                                if ((kField.Units == null) || (kField.Units == "K"))
                                {
                                    // We convert this to Celcius
                                    // f[i++] = new TemperatureField { DisplayName = kField.DisplayName, BitOffset = kField.BitOffset, BitLength = kField.BitLength, Description = kField.Description };
                                    f[i++] = new N2kUDblField {
                                        FormatAs = FormatEnum.Temperature, Name = kField.Name, BitOffset = kField.BitOffset, BitLength = kField.BitLength, Description = kField.Description, Scale = 0.01, Offset = -273.15
                                    };
                                }
                                else
                                {
                                    Console.WriteLine("Unknown Kees Temperature field data");
                                }
                                break;

                            case "Time":
                                // TimeField
                                f[i++] = new N2kUDblField {
                                    FormatAs = FormatEnum.Time, Name = kField.Name, BitOffset = kField.BitOffset, BitLength = kField.BitLength, Description = kField.Description, Scale = 0.0001
                                };
                                break;

                            case "Speed":
                                f[i++] = new N2kUDblField {
                                    FormatAs = FormatEnum.Speed, Name = kField.Name, BitOffset = kField.BitOffset, BitLength = kField.BitLength, Description = kField.Description, Scale = scale
                                };
                                break;

                            default:
                                Console.WriteLine("Unknown Kees Field");
                                break;
                            }
                        }
                    }
                }
                uint ByteLength = 0;
                foreach (N2kField field in f)
                {
                    ByteLength = (uint)Math.Max(ByteLength, (int)(((uint)((uint)field.BitOffset + (uint)field.BitLength + 7)) >> 3));
                }
                if (kPGN.PGN == 129029)
                {
                    ByteLength = 43;   // Add 3 extra bytes missing in Kees data
                }
                result[j++] = new PGNDefn {
                    PGN = kPGN.PGN, Name = kPGN.Description, Description = "", ByteLength = ByteLength, Fields = f
                };
            }
            return(result);
        }