def decode(self, data): """ Take the data bytearray. Decode the data to populate the velocities. :param data: Bytearray for the dataset. """ packet_pointer = Ensemble.GetBaseDataSize(self.name_len) for beam in range(self.element_multiplier): for bin_num in range(self.num_elements): self.GoodEarth[bin_num][beam] = Ensemble.GetInt32( packet_pointer, Ensemble().BytesInInt32, data) packet_pointer += Ensemble().BytesInInt32 logger.debug(self.GoodEarth)
def decode_data_sets(self, ens): """ Decode the datasets in the ensemble. :param ens: Ensemble data. Decode the dataset. :return: Return the decoded ensemble. """ #print(ens) packetPointer = Ensemble().HeaderSize type = 0 numElements = 0 elementMultiplier = 0 imag = 0 nameLen = 0 name = "" dataSetSize = 0 # Create the ensemble ensemble = Ensemble() # Add the raw data to the ensemble #ensemble.AddRawData(ens) # Decode the ensemble datasets for x in range(Ensemble().MaxNumDataSets): # Check if we are at the end of the payload if packetPointer >= len(ens): break # Get the dataset info ds_type = Ensemble.GetInt32( packetPointer + (Ensemble.BytesInInt32 * 0), Ensemble().BytesInInt32, ens) num_elements = Ensemble.GetInt32( packetPointer + (Ensemble.BytesInInt32 * 1), Ensemble().BytesInInt32, ens) element_multiplier = Ensemble.GetInt32( packetPointer + (Ensemble.BytesInInt32 * 2), Ensemble().BytesInInt32, ens) image = Ensemble.GetInt32( packetPointer + (Ensemble.BytesInInt32 * 3), Ensemble().BytesInInt32, ens) name_len = Ensemble.GetInt32( packetPointer + (Ensemble.BytesInInt32 * 4), Ensemble().BytesInInt32, ens) name = str( ens[packetPointer + (Ensemble.BytesInInt32 * 5):packetPointer + (Ensemble.BytesInInt32 * 5) + 8], 'UTF-8') # Calculate the dataset size data_set_size = Ensemble.GetDataSetSize(ds_type, name_len, num_elements, element_multiplier) # Beam Velocity if "E000001" in name: logger.debug(name) bv = BeamVelocity(num_elements, element_multiplier) bv.decode(ens[packetPointer:packetPointer + data_set_size]) ensemble.AddBeamVelocity(bv) # Instrument Velocity if "E000002" in name: logger.debug(name) iv = InstrumentVelocity(num_elements, element_multiplier) iv.decode(ens[packetPointer:packetPointer + data_set_size]) ensemble.AddInstrumentVelocity(iv) # Earth Velocity if "E000003" in name: logger.debug(name) ev = EarthVelocity(num_elements, element_multiplier) ev.decode(ens[packetPointer:packetPointer + data_set_size]) ensemble.AddEarthVelocity(ev) # Amplitude if "E000004" in name: logger.debug(name) amp = Amplitude(num_elements, element_multiplier) amp.decode(ens[packetPointer:packetPointer + data_set_size]) ensemble.AddAmplitude(amp) # Correlation if "E000005" in name: logger.debug(name) corr = Correlation(num_elements, element_multiplier) corr.decode(ens[packetPointer:packetPointer + data_set_size]) ensemble.AddCorrelation(corr) # Good Beam if "E000006" in name: logger.debug(name) gb = GoodBeam(num_elements, element_multiplier) gb.decode(ens[packetPointer:packetPointer + data_set_size]) ensemble.AddGoodBeam(gb) # Good Earth if "E000007" in name: logger.debug(name) ge = GoodEarth(num_elements, element_multiplier) ge.decode(ens[packetPointer:packetPointer + data_set_size]) ensemble.AddGoodEarth(ge) # Ensemble Data if "E000008" in name: logger.debug(name) ed = EnsembleData(num_elements, element_multiplier) ed.decode(ens[packetPointer:packetPointer + data_set_size]) ensemble.AddEnsembleData(ed) # Ancillary Data if "E000009" in name: logger.debug(name) ad = AncillaryData(num_elements, element_multiplier) ad.decode(ens[packetPointer:packetPointer + data_set_size]) ensemble.AddAncillaryData(ad) # Bottom Track if "E000010" in name: logger.debug(name) bt = BottomTrack(num_elements, element_multiplier) bt.decode(ens[packetPointer:packetPointer + data_set_size]) ensemble.AddBottomTrack(bt) # NMEA data if "E000011" in name: logger.debug(name) nd = NmeaData(num_elements, element_multiplier) nd.decode(ens[packetPointer:packetPointer + data_set_size]) ensemble.AddNmeaData(nd) # System Setup if "E000014" in name: logger.debug(name) ss = SystemSetup(num_elements, element_multiplier) ss.decode(ens[packetPointer:packetPointer + data_set_size]) ensemble.AddSystemSetup(ss) # Range Tracking if "E000015" in name: logger.debug(name) rt = RangeTracking(num_elements, element_multiplier) rt.decode(ens[packetPointer:packetPointer + data_set_size]) ensemble.AddRangeTracking(rt) # Move to the next dataset packetPointer += data_set_size return ensemble
def decode(self, data): """ Take the data bytearray. Decode the data to populate the values. :param data: Bytearray for the dataset. """ packet_pointer = Ensemble.GetBaseDataSize(self.name_len) self.EnsembleNumber = Ensemble.GetInt32( packet_pointer + Ensemble().BytesInInt32 * 0, Ensemble().BytesInInt32, data) self.NumBins = Ensemble.GetInt32( packet_pointer + Ensemble().BytesInInt32 * 1, Ensemble().BytesInInt32, data) self.NumBeams = Ensemble.GetInt32( packet_pointer + Ensemble().BytesInInt32 * 2, Ensemble().BytesInInt32, data) self.DesiredPingCount = Ensemble.GetInt32( packet_pointer + Ensemble().BytesInInt32 * 3, Ensemble().BytesInInt32, data) self.ActualPingCount = Ensemble.GetInt32( packet_pointer + Ensemble().BytesInInt32 * 4, Ensemble().BytesInInt32, data) self.Status = Ensemble.GetInt32( packet_pointer + Ensemble().BytesInInt32 * 5, Ensemble().BytesInInt32, data) self.Year = Ensemble.GetInt32( packet_pointer + Ensemble().BytesInInt32 * 6, Ensemble().BytesInInt32, data) self.Month = Ensemble.GetInt32( packet_pointer + Ensemble().BytesInInt32 * 7, Ensemble().BytesInInt32, data) self.Day = Ensemble.GetInt32( packet_pointer + Ensemble().BytesInInt32 * 8, Ensemble().BytesInInt32, data) self.Hour = Ensemble.GetInt32( packet_pointer + Ensemble().BytesInInt32 * 9, Ensemble().BytesInInt32, data) self.Minute = Ensemble.GetInt32( packet_pointer + Ensemble().BytesInInt32 * 10, Ensemble().BytesInInt32, data) self.Second = Ensemble.GetInt32( packet_pointer + Ensemble().BytesInInt32 * 11, Ensemble().BytesInInt32, data) self.HSec = Ensemble.GetInt32( packet_pointer + Ensemble().BytesInInt32 * 12, Ensemble().BytesInInt32, data) self.SerialNumber = str( data[packet_pointer + Ensemble().BytesInInt32 * 13:packet_pointer + Ensemble().BytesInInt32 * 21], "UTF-8") self.SysFirmwareRevision = struct.unpack( "B", data[packet_pointer + Ensemble().BytesInInt32 * 21 + 0:packet_pointer + Ensemble().BytesInInt32 * 21 + 1])[0] self.SysFirmwareMinor = struct.unpack( "B", data[packet_pointer + Ensemble().BytesInInt32 * 21 + 1:packet_pointer + Ensemble().BytesInInt32 * 21 + 2])[0] self.SysFirmwareMajor = struct.unpack( "B", data[packet_pointer + Ensemble().BytesInInt32 * 21 + 2:packet_pointer + Ensemble().BytesInInt32 * 21 + 3])[0] self.SysFirmwareSubsystemCode = str( data[packet_pointer + Ensemble().BytesInInt32 * 21 + 3:packet_pointer + Ensemble().BytesInInt32 * 21 + 4], "UTF-8") self.SubsystemConfig = struct.unpack( "B", data[packet_pointer + Ensemble().BytesInInt32 * 22 + 3:packet_pointer + Ensemble().BytesInInt32 * 22 + 4])[0] logger.debug(self.EnsembleNumber) logger.debug( str(self.Month) + "/" + str(self.Day) + "/" + str(self.Year) + " " + str(self.Hour) + ":" + str(self.Minute) + ":" + str(self.Second) + "." + str(self.HSec)) logger.debug(self.SerialNumber) logger.debug( str(self.SysFirmwareMajor) + "." + str(self.SysFirmwareMinor) + "." + str(self.SysFirmwareRevision) + "-" + str(self.SysFirmwareSubsystemCode)) logger.debug(self.SubsystemConfig)