/// <summary> /// Get the data out of the ensemble to encode the TS message. /// </summary> /// <param name="ens">Ensemble data.</param> /// <returns>TA string.</returns> private string EncodeTS(DataSet.Ensemble ens) { DateTime dateAndTime = new DateTime(); byte hundredthSec = 0; float salinity = 0.0f; float temperature = 0.0f; float depthOfTransducer = 0.0f; float speedOfSound = 0.0f; int BIT = 0; RTI.DataSet.DvlDataSet.LeakDetectionOptions leakDetection = RTI.DataSet.DvlDataSet.LeakDetectionOptions.NotInstalled; if (ens.IsEnsembleAvail && ens.IsAncillaryAvail) { dateAndTime = ens.EnsembleData.EnsDateTime; hundredthSec = (byte)ens.EnsembleData.HSec; salinity = ens.AncillaryData.Salinity; temperature = ens.AncillaryData.WaterTemp; depthOfTransducer = ens.AncillaryData.TransducerDepth; speedOfSound = ens.AncillaryData.SpeedOfSound; BIT = ens.EnsembleData.Status.Value; } else if (ens.IsBottomTrackAvail) { salinity = ens.BottomTrackData.Salinity; temperature = ens.BottomTrackData.WaterTemp; depthOfTransducer = ens.BottomTrackData.TransducerDepth; speedOfSound = ens.BottomTrackData.SpeedOfSound; BIT = ens.BottomTrackData.Status.Value; } return(new TS(dateAndTime, hundredthSec, salinity, temperature, depthOfTransducer, speedOfSound, BIT, leakDetection).Encode()); }
/// <summary> /// Decode the sentence given. /// </summary> /// <param name="sent">Sentence to decode</param> public TS(string sent) { // Set the sentence Sentence = sent; // Decode the sentence string[] result = sent.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (result.Length >= NUM_ELEM && result[0].Contains(ID)) { // Remove the plus sign result[1].Replace("+", String.Empty); result[2].Replace("+", String.Empty); result[3].Replace("+", String.Empty); result[4].Replace("+", String.Empty); result[5].Replace("+", String.Empty); result[6].Replace("+", String.Empty); // Trim the results and convert to a float DateAndTime = DateTime.Now; Salinity = 0.0f; Temperature = 0.0f; DepthOfTransducer = 0.0f; SpeedOfSound = 0.0f; BIT = 0; // Pattern for the date and time string pattern = "yyMMddHHmmss"; // DateTime cannot hold the hundredth of a second string dt = result[1].Trim(); if(dt.Length >= 14) { // Store the hundredth of second HundredthSec = Convert.ToByte(dt.Substring(12, 2)); // Remove the hundredth of second from the string dt = dt.Substring(0, 12); } DateTime.TryParseExact(dt, pattern, null, System.Globalization.DateTimeStyles.None, out DateAndTime); Single.TryParse(result[2].Trim(), out Salinity); Single.TryParse(result[3].Trim(), out Temperature); Single.TryParse(result[4].Trim(), out DepthOfTransducer); Single.TryParse(result[5].Trim(), out SpeedOfSound); Int32.TryParse(result[6].Trim(), out BIT); // Leak detection added if(result.Length == 8) { switch(result[7].Trim()) { case LEAKDETECT_OK: LeakDetection = RTI.DataSet.DvlDataSet.LeakDetectionOptions.OK; break; case LEAKDETECT_WATER: LeakDetection = RTI.DataSet.DvlDataSet.LeakDetectionOptions.WaterDetected; break; case LEAKDETECT_NOT_INSTALLED: default: LeakDetection = RTI.DataSet.DvlDataSet.LeakDetectionOptions.NotInstalled; break; } } } }