Class: TimexDatalinkClient::Protocol7::Eeprom::Activity

Inherits:
Object
  • Object
show all
Includes:
Helpers::FourByteFormatter
Defined in:
lib/timex_datalink_client/protocol_7/eeprom/activity.rb

Constant Summary collapse

METADATA_BYTES_BASE =
6
METADATA_BYTES_SIZE =
5
PACKETS_TERMINATOR =
0x04

Constants included from Helpers::FourByteFormatter

Helpers::FourByteFormatter::BYTE_NULL, Helpers::FourByteFormatter::BYTE_TERMINATOR_ENDF, Helpers::FourByteFormatter::BYTE_TERMINATOR_ENDR

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers::FourByteFormatter

#four_byte_format_for

Constructor Details

#initialize(time:, messages:, random_speech:) ⇒ Activity

Create an Activity instance.

Parameters:

  • time (::Time)

    Time of activity.

  • messages (Array<Array<Integer>>)

    Messages for activity.

  • random_speech (Boolean)

    If activity should have random speech.



59
60
61
62
63
# File 'lib/timex_datalink_client/protocol_7/eeprom/activity.rb', line 59

def initialize(time:, messages:, random_speech:)
  @time = time
  @messages = messages
  @random_speech = random_speech
end

Instance Attribute Details

#messagesObject

Returns the value of attribute messages.



51
52
53
# File 'lib/timex_datalink_client/protocol_7/eeprom/activity.rb', line 51

def messages
  @messages
end

#random_speechObject

Returns the value of attribute random_speech.



51
52
53
# File 'lib/timex_datalink_client/protocol_7/eeprom/activity.rb', line 51

def random_speech
  @random_speech
end

#timeObject

Returns the value of attribute time.



51
52
53
# File 'lib/timex_datalink_client/protocol_7/eeprom/activity.rb', line 51

def time
  @time
end

Class Method Details

.packets(activities) ⇒ Array

Compile data for all activities.

Parameters:

  • activities (Array<Activity>)

    Activities to compile data for.

Returns:

  • (Array)

    Compiled data of all activities.



20
21
22
# File 'lib/timex_datalink_client/protocol_7/eeprom/activity.rb', line 20

def self.packets(activities)
  header(activities) + (activities) + [PACKETS_TERMINATOR]
end

Instance Method Details

#messages_packetArray<Integer>

Compile a message packet for an activity.

Returns:

  • (Array<Integer>)

    Array of integers that represent bytes.



82
83
84
# File 'lib/timex_datalink_client/protocol_7/eeprom/activity.rb', line 82

def messages_packet
  four_byte_format_for(messages)
end

#metadata_packet(activity_index) ⇒ Array<Integer>

Compile a metadata packet for an activity.

Parameters:

  • activity_index (Integer)

    Activity index.

Returns:

  • (Array<Integer>)

    Array of integers that represent bytes.



69
70
71
72
73
74
75
76
77
# File 'lib/timex_datalink_client/protocol_7/eeprom/activity.rb', line 69

def (activity_index)
  [
    time.hour,
    time.min,
    messages.count,
    (activity_index),
    0
  ].flatten
end