Class: RubyTDMS::Objects::Channel
- Defined in:
- lib/ruby_tdms/objects/channel.rb
Instance Attribute Summary collapse
-
#chunk_length ⇒ Object
readonly
Returns the value of attribute chunk_length.
-
#chunk_offsets ⇒ Object
readonly
Returns the value of attribute chunk_offsets.
-
#chunk_value_count ⇒ Object
readonly
Returns the value of attribute chunk_value_count.
-
#data_length ⇒ Object
readonly
Returns the value of attribute data_length.
-
#data_type ⇒ Object
readonly
Returns the value of attribute data_type.
-
#data_type_id ⇒ Object
readonly
Returns the value of attribute data_type_id.
-
#dimensions ⇒ Object
readonly
Returns the value of attribute dimensions.
-
#raw_data_offset ⇒ Object
readonly
Returns the value of attribute raw_data_offset.
-
#value_count ⇒ Object
readonly
Returns the value of attribute value_count.
-
#value_offset ⇒ Object
readonly
Returns the value of attribute value_offset.
Attributes inherited from Base
#path, #properties, #segment, #stream
Instance Method Summary collapse
- #as_json ⇒ Object
-
#calculate_offsets ⇒ Object
After all channels in a segment have been read, we have to determine our raw data starting offset and the offsets for all individual values, based on the number of chunks in the segment as well as whether the segment is interleaved.
-
#continue_stream(stream, raw_index, previous_channel) ⇒ Object
When a channel is continued in a new segment, this method is called rather than #parse_stream.
-
#initialize(path, document, segment) ⇒ Channel
constructor
A new instance of Channel.
- #name ⇒ Object
-
#parse_stream(stream, raw_index) ⇒ Object
Get all data from the stream to configure ourself with data type, number of values, etc.
- #values ⇒ Object
Constructor Details
#initialize(path, document, segment) ⇒ Channel
Returns a new instance of Channel.
11 12 13 14 15 |
# File 'lib/ruby_tdms/objects/channel.rb', line 11 def initialize(path, document, segment) super @chunk_offsets = [] @value_count = 0 end |
Instance Attribute Details
#chunk_length ⇒ Object (readonly)
Returns the value of attribute chunk_length.
8 9 10 |
# File 'lib/ruby_tdms/objects/channel.rb', line 8 def chunk_length @chunk_length end |
#chunk_offsets ⇒ Object (readonly)
Returns the value of attribute chunk_offsets.
8 9 10 |
# File 'lib/ruby_tdms/objects/channel.rb', line 8 def chunk_offsets @chunk_offsets end |
#chunk_value_count ⇒ Object (readonly)
Returns the value of attribute chunk_value_count.
8 9 10 |
# File 'lib/ruby_tdms/objects/channel.rb', line 8 def chunk_value_count @chunk_value_count end |
#data_length ⇒ Object (readonly)
Returns the value of attribute data_length.
8 9 10 |
# File 'lib/ruby_tdms/objects/channel.rb', line 8 def data_length @data_length end |
#data_type ⇒ Object (readonly)
Returns the value of attribute data_type.
8 9 10 |
# File 'lib/ruby_tdms/objects/channel.rb', line 8 def data_type @data_type end |
#data_type_id ⇒ Object (readonly)
Returns the value of attribute data_type_id.
8 9 10 |
# File 'lib/ruby_tdms/objects/channel.rb', line 8 def data_type_id @data_type_id end |
#dimensions ⇒ Object (readonly)
Returns the value of attribute dimensions.
8 9 10 |
# File 'lib/ruby_tdms/objects/channel.rb', line 8 def dimensions @dimensions end |
#raw_data_offset ⇒ Object (readonly)
Returns the value of attribute raw_data_offset.
8 9 10 |
# File 'lib/ruby_tdms/objects/channel.rb', line 8 def raw_data_offset @raw_data_offset end |
#value_count ⇒ Object (readonly)
Returns the value of attribute value_count.
8 9 10 |
# File 'lib/ruby_tdms/objects/channel.rb', line 8 def value_count @value_count end |
#value_offset ⇒ Object (readonly)
Returns the value of attribute value_offset.
8 9 10 |
# File 'lib/ruby_tdms/objects/channel.rb', line 8 def value_offset @value_offset end |
Instance Method Details
#as_json ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/ruby_tdms/objects/channel.rb', line 23 def as_json super.merge({ name: name, data_type: data_type.name.split('::').last, dimensions: dimensions, values: values.to_a }) end |
#calculate_offsets ⇒ Object
After all channels in a segment have been read, we have to determine our raw data starting offset and the offsets for all individual values, based on the number of chunks in the segment as well as whether the segment is interleaved.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/ruby_tdms/objects/channel.rb', line 67 def calculate_offsets previous_channel = nil channels = @segment.raw_channels me = channels.index self previous_channel = channels[me - 1] if me and me > 0 if @segment.interleaved_data? @value_offset = @segment.raw_channels.map(&:data_length).reduce :+ else @value_offset = @data_length end @raw_data_offset = @segment.raw_data_offset if previous_channel @raw_data_offset = previous_channel.raw_data_offset @raw_data_offset += @segment.interleaved_data? ? previous_channel.data_length : previous_channel.chunk_length end @segment.chunk_count.times do @chunk_offsets << @raw_data_offset + @chunk_offsets.length * @chunk_length end @value_count = @chunk_value_count * @segment.chunk_count end |
#continue_stream(stream, raw_index, previous_channel) ⇒ Object
When a channel is continued in a new segment, this method is called rather than #parse_stream
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/ruby_tdms/objects/channel.rb', line 51 def continue_stream(stream, raw_index, previous_channel) @chunk_value_count = previous_channel.chunk_value_count @data_length = previous_channel.data_length @data_type = previous_channel.data_type @data_type_id = previous_channel.data_type_id @dimensions = previous_channel.dimensions @chunk_length = @data_length * @dimensions * @chunk_value_count # Size of the data for this channel in a given chunk. super stream, previous_channel end |
#name ⇒ Object
18 19 20 |
# File 'lib/ruby_tdms/objects/channel.rb', line 18 def name path.to_a.last end |
#parse_stream(stream, raw_index) ⇒ Object
Get all data from the stream to configure ourself with data type, number of values, etc.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/ruby_tdms/objects/channel.rb', line 34 def parse_stream(stream, raw_index) @data_type_id = stream.read_u32 @dimensions = stream.read_u32 @chunk_value_count = stream.read_u64 @data_type = DataTypes.find_by_id @data_type_id # Get the data length for variable length types (when DataTypes::LENGTH_IN_BYTES is nil) @data_length = @data_type::LENGTH_IN_BYTES || stream.read_u64 # Chunk length is the same as data length for variable length types @chunk_length = @data_type::LENGTH_IN_BYTES.nil? ? @data_length : @data_length * @dimensions * @chunk_value_count # Size of the data for this channel in a given chunk. super stream end |
#values ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/ruby_tdms/objects/channel.rb', line 92 def values @values ||= begin klass = if @data_type::LENGTH_IN_BYTES.nil? StringChannelEnumerator else ChannelEnumerator end klass.new self end end |