Module: TimexDatalinkClient::Helpers::CharEncoders
- Included in:
- Protocol1::Alarm, Protocol1::Eeprom::Anniversary, Protocol1::Eeprom::Appointment, Protocol1::Eeprom::List, Protocol1::Eeprom::PhoneNumber, Protocol1::TimeName, Protocol3::Alarm, Protocol3::Eeprom::Anniversary, Protocol3::Eeprom::Appointment, Protocol3::Eeprom::List, Protocol3::Eeprom::PhoneNumber, Protocol3::Time, Protocol4::Alarm, Protocol4::Eeprom::Anniversary, Protocol4::Eeprom::Appointment, Protocol4::Eeprom::List, Protocol4::Eeprom::PhoneNumber, Protocol4::Time, Protocol6::Alarm, Protocol6::Eeprom::PhoneNumber, Protocol6::Time, Protocol9::Alarm, Protocol9::Eeprom::Chrono, Protocol9::Eeprom::PhoneNumber, Protocol9::TimeName, Protocol9::Timer
- Defined in:
- lib/timex_datalink_client/helpers/char_encoders.rb
Constant Summary collapse
- CHARS =
"0123456789abcdefghijklmnopqrstuvwxyz !\"#$%&'()*+,-./:\\;=@?_|<>[]"
- CHARS_PROTOCOL_6 =
"0123456789 abcdefghijklmnopqrstuvwxyz!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"
- EEPROM_CHARS =
"0123456789abcdefghijklmnopqrstuvwxyz !\"#$%&'()*+,-./:\\;=@?_|<>["
- PHONE_CHARS =
"0123456789cfhpw "
- INVALID_CHAR =
" "
- EEPROM_TERMINATOR =
0x3f
Instance Method Summary collapse
- #chars_for(string_chars, char_map: CHARS, length: nil, pad: false) ⇒ Object
- #eeprom_chars_for(string_chars, length: 31) ⇒ Object
- #phone_chars_for(string_chars) ⇒ Object
- #protocol_6_chars_for(string_chars, length: nil, pad: false) ⇒ Object
Instance Method Details
#chars_for(string_chars, char_map: CHARS, length: nil, pad: false) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/timex_datalink_client/helpers/char_encoders.rb', line 14 def chars_for(string_chars, char_map: CHARS, length: nil, pad: false) formatted_chars = string_chars.downcase[0..length.to_i - 1] formatted_chars = formatted_chars.ljust(length) if pad formatted_chars.each_char.map do |char| char_map.index(char) || char_map.index(INVALID_CHAR) end end |
#eeprom_chars_for(string_chars, length: 31) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/timex_datalink_client/helpers/char_encoders.rb', line 27 def eeprom_chars_for(string_chars, length: 31) chars = chars_for(string_chars, char_map: EEPROM_CHARS, length:).append(EEPROM_TERMINATOR) packed_int = chars.each_with_index.sum do |char, index| char << (6 * index) end packed_int.digits(256) end |
#phone_chars_for(string_chars) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/timex_datalink_client/helpers/char_encoders.rb', line 37 def phone_chars_for(string_chars) chars = chars_for(string_chars, char_map: PHONE_CHARS, length: 12) packed_int = chars.each_with_index.sum do |char, index| char << (4 * index) end packed_int.digits(256) end |
#protocol_6_chars_for(string_chars, length: nil, pad: false) ⇒ Object
23 24 25 |
# File 'lib/timex_datalink_client/helpers/char_encoders.rb', line 23 def protocol_6_chars_for(string_chars, length: nil, pad: false) chars_for(string_chars, char_map: CHARS_PROTOCOL_6, length:, pad:) end |