public void UpdateBinList()
 {
     BinList.Clear();
     foreach (Bin bin in _currentUser.BinList)
     {
         BinList.Add(bin);
     }
 }
Beispiel #2
0
        /// <summary>
        /// Receive the ensemble and decode it to output the data.
        /// </summary>
        /// <param name="ens">Ensemble.</param>
        /// <param name="origDataFormat">Original Data Format.</param>
        public void ReceiveEnsemble(DataSet.Ensemble ens, AdcpCodec.CodecEnum origDataFormat)
        {
            // Set the buffer size to display data
            // To much data will make the system run slower
            int dataOutputMax = 5000;

            // Set the maximum bin for bin list
            if (ens.IsEnsembleAvail)
            {
                // If it different from what is now
                if (BinList.Count != ens.EnsembleData.NumBins)
                {
                    // Subtract 1 because 0 based
                    NumBins = ens.EnsembleData.NumBins - 1;

                    // Clear and repopulate
                    BinList.Clear();
                    for (int x = 0; x < ens.EnsembleData.NumBins; x++)
                    {
                        BinList.Add(x);
                    }
                }
            }

            // If the HeadingOffset is set or
            // If they want to retransform the data or
            // They are replacing the heading with GPS heading,
            // The data needs to be retransformed to use the new heading.
            // Retransform the data with the new heading
            // Apply HDT heading if requried and available
            // This will also apply the heading offset
            if (_options.IsRetransformData || _options.IsUseGpsHeading || _options.HeadingOffset != 0)
            {
                // Retransform the Profile datas
                Transform.ProfileTransform(ref ens, origDataFormat, 0.25f, _options.SelectedHeadingSource, _options.HeadingOffset);

                // Retransform the Bottom Track data
                // This will also create the ship data
                Transform.BottomTrackTransform(ref ens, origDataFormat, 0.90f, 10.0f, _options.SelectedHeadingSource, _options.HeadingOffset);

                // WaterMass transform data
                // This will also create the ship data
                if (ens.IsInstrumentWaterMassAvail)
                {
                    Transform.WaterMassTransform(ref ens, origDataFormat, 0.90f, 10.0f, _options.SelectedHeadingSource, _options.HeadingOffset, _options.ShipXdcrOffset);
                }
            }

            // Remove the Ship speed from the data
            RemoveShipSpeed(ref ens);

            // Water Track
            if (_options.IsCalculateWaterTrack)
            {
                _manualWT.Calculate(ref ens, _options.WtMinBin, _options.WtMaxBin);
            }

            if (_options.SelectedFormat == DataOutputViewOptions.ENCODING_VMDAS)
            {
                VmDasAsciiCodec.VmDasAsciiOutput output = _codecVmDas.Encode(ens, _options.VmDasMinBin, _options.VmDasMaxBin);

                // Display data
                DataOutput = output.Ascii;

                // Max size of data output buffer
                dataOutputMax = 5000;

                // Send data to serial port
                SendDataToSerial(output.Ascii);

                // Write data to file if turned on
                WriteData(output.Ascii);

                // Update the Min and Max Bin selection
                if (_options.VmDasMinBin != output.BinSelected.MinBin)
                {
                    MinBin = output.BinSelected.MinBin;
                }

                if (_options.VmDasMaxBin != output.BinSelected.MaxBin)
                {
                    MaxBin = output.BinSelected.MaxBin;
                }
            }
            else if (_options.SelectedFormat == DataOutputViewOptions.ENCODING_PD6_PD13)
            {
                // PD6 or PD13
                EnsToPd6_13Codec.Pd6_13Data output = _codecPd6_13.Encode(ens);

                // Output all the strings
                foreach (var line in output.Data)
                {
                    // Output to display
                    DataOutput += line;

                    // Output to the serial port
                    // Trim it because the serial port adds a carrage return
                    SendDataToSerial(line, false);

                    // Write data to file if turned on
                    WriteData(line.Trim());
                }

                // Max size of data output buffer
                dataOutputMax = 1000;
            }
            else if (_options.SelectedFormat == DataOutputViewOptions.ENCODING_Binary_ENS)
            {
                // Convert to binary array
                byte[] rawEns = ens.Encode();

                // Output to display
                DataOutput += ens.ToString();

                // Output data to the serial port
                _serialPort.SendData(rawEns, 0, rawEns.Length);

                // Write data to file if turned on
                WriteData(rawEns);

                // Max size of data output buffer
                dataOutputMax = 10000;
            }
            else if (_options.SelectedFormat == DataOutputViewOptions.ENCODING_PD0)
            {
                byte[] pd0 = null;

                switch (_options.SelectedCoordTransform)
                {
                case PD0.CoordinateTransforms.Coord_Beam:
                    pd0 = ens.EncodePd0Ensemble(PD0.CoordinateTransforms.Coord_Beam);
                    break;

                case PD0.CoordinateTransforms.Coord_Instrument:
                    pd0 = ens.EncodePd0Ensemble(PD0.CoordinateTransforms.Coord_Instrument);
                    break;

                case PD0.CoordinateTransforms.Coord_Ship:
                    pd0 = ens.EncodePd0Ensemble(PD0.CoordinateTransforms.Coord_Ship);
                    break;

                case PD0.CoordinateTransforms.Coord_Earth:
                    pd0 = ens.EncodePd0Ensemble(PD0.CoordinateTransforms.Coord_Earth);
                    break;
                }

                // Output to display
                DataOutput += System.Text.ASCIIEncoding.ASCII.GetString(pd0);

                // Output data to serial port
                _serialPort.SendData(pd0, 0, pd0.Length);

                // Write data to file if turned on
                WriteData(pd0);

                // Max output buffer size
                dataOutputMax = 10000;
            }
            else if (_options.SelectedFormat == DataOutputViewOptions.ENCODING_RETRANSFORM_PD6)
            {
            }

            // Keep the Buffer to a set limit
            if (DataOutput.Length > dataOutputMax)
            {
                DataOutput = DataOutput.Substring(DataOutput.Length - dataOutputMax);
            }
        }
Beispiel #3
0
        public bool LoadFile(string filename)
        {
            // clear some variables
            selectedBin = null;
            modifiedBins.Clear();

            // filename can be any file or a .binmap
            bool isBinmap = false;

            try
            {
                isBinmap = loadBinmapFile(filename);
            }
            catch (Exception e)
            {
                LastError = "Exception while trying to load binmap file: " + e.Message;
                return(false);
            }

            if (isBinmap)
            {
                DataFilename   = Path.Combine(Path.GetDirectoryName(filename), BinmapDataFilename);
                BinmapFilename = filename;
            }
            else
            {
                DataFilename   = filename;
                BinmapFilename = filename + ".binmap";
            }

            if (!File.Exists(DataFilename))
            {
                LastError = "The associated file '" + DataFilename + "' was not found!";
                return(false);
            }

            list.Lock();

            try
            {
                byte[] bytes = File.ReadAllBytes(DataFilename);

                list.Clear();

                int offset = 0;

                foreach (byte b in bytes)
                {
                    Bin item = new Bin(b, offset);
                    list.AddItem(item);
                    offset++;
                }
            }
            catch (Exception e)
            {
                LastError = "Failed to load data: " + e.Message;
                return(false);
            }

            try
            {
                loadBinmapFile(BinmapFilename, true);
            }
            catch (Exception e)
            {
                LastError = "Exception while trying to load binmap file: " + e.Message;
                return(false);
            }

            list.Unlock();
            saveButton.Visible  = list.NumVisible > 0;
            gotoInput.Visible   = saveButton.Visible;
            searchInput.Visible = saveButton.Visible;
            return(true);
        }