Class: StarEthernet::StatusItem
- Inherits:
-
Object
- Object
- StarEthernet::StatusItem
- Defined in:
- lib/star_ethernet/status_item.rb
Defined Under Namespace
Classes: ErrorStatus, HeaderStatus, PresenterStatus, PrinterStatus, SensorStatus
Instance Attribute Summary collapse
-
#etb ⇒ Object
Returns the value of attribute etb.
-
#purpose ⇒ Object
writeonly
Sets the attribute purpose.
-
#statuses ⇒ Object
readonly
Returns the value of attribute statuses.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
Class Method Summary collapse
Instance Method Summary collapse
- #append_status(status) ⇒ Object
-
#initialize(statuses: []) ⇒ StatusItem
constructor
A new instance of StatusItem.
- #message ⇒ Object
- #need_to_change_paper? ⇒ Boolean
- #offline? ⇒ Boolean
- #unhealthy? ⇒ Boolean
Constructor Details
#initialize(statuses: []) ⇒ StatusItem
Returns a new instance of StatusItem.
7 8 9 10 11 12 |
# File 'lib/star_ethernet/status_item.rb', line 7 def initialize(statuses: []) @statuses = statuses @etb = nil @time = Time.now @purpose = nil end |
Instance Attribute Details
#etb ⇒ Object
Returns the value of attribute etb.
5 6 7 |
# File 'lib/star_ethernet/status_item.rb', line 5 def etb @etb end |
#purpose=(value) ⇒ Object (writeonly)
Sets the attribute purpose
4 5 6 |
# File 'lib/star_ethernet/status_item.rb', line 4 def purpose=(value) @purpose = value end |
#statuses ⇒ Object (readonly)
Returns the value of attribute statuses.
3 4 5 |
# File 'lib/star_ethernet/status_item.rb', line 3 def statuses @statuses end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
3 4 5 |
# File 'lib/star_ethernet/status_item.rb', line 3 def time @time end |
Class Method Details
.decode_status(status_raw_data) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/star_ethernet/status_item.rb', line 78 def self.decode_status(status_raw_data) status_item = StatusItem.new status_data = status_raw_data.unpack('H*').first byte1 = status_data[0..1].hex # todo status byte byte2 = status_data[2..3].hex # todo version status byte3 = status_data[4..5].hex status_item.append_status(PrinterStatus::OfflineBySwitchInput) if byte3 & 0b01000000 > 0 status_item.append_status(PrinterStatus::CoverOpen) if byte3 & 0b00100000 > 0 status_item.append_status(PrinterStatus::Offline) if byte3 & 0b00001000 > 0 status_item.append_status(PrinterStatus::ConversionSwitchClosed) if byte3 & 0b00000100 > 0 status_item.append_status(PrinterStatus::EtbCommandExecuted) if byte3 & 0b00000010 > 0 byte4 = status_data[6..7].hex status_item.append_status(ErrorStatus::StoppedByHighHeadTemperature) if byte4 & 0b01000000 > 0 status_item.append_status(ErrorStatus::NonRecoverableError) if byte4 & 0b00100000 > 0 status_item.append_status(ErrorStatus::AutoCutterError) if byte4 & 0b00001000 > 0 status_item.append_status(ErrorStatus::MechanicalError) if byte4 & 0b00000100 > 0 byte5 = status_data[8..9].hex status_item.append_status(ErrorStatus::ReceiveBufferOverflow) if byte5 & 0b01000000 > 0 status_item.append_status(ErrorStatus::CommandError) if byte5 & 0b00100000 > 0 status_item.append_status(ErrorStatus::BmError) if byte5 & 0b00001000 > 0 status_item.append_status(ErrorStatus::PresenterPageJamError) if byte5 & 0b00000100 > 0 status_item.append_status(ErrorStatus::HeadUpError) if byte5 & 0b00000010 > 0 byte6 = status_data[10..11].hex status_item.append_status(SensorStatus::PaperEnd) if byte6 & 0b00001000 > 0 status_item.append_status(SensorStatus::PaperNearInsideEnd) if byte6 & 0b00000100 > 0 status_item.append_status(SensorStatus::PaperNearOutsideEnd) if byte6 & 0b00000010 > 0 byte7 = status_data[12..13].hex # todo byte8 = status_data[14..15].hex status_item.etb = ((byte8 >> 1) & 0b00000111) + ((byte8 >> 2) & 0b00011000) byte9 = status_data[16..17].hex # todo status_item end |
Instance Method Details
#append_status(status) ⇒ Object
18 19 20 |
# File 'lib/star_ethernet/status_item.rb', line 18 def append_status(status) @statuses.push(status) end |
#message ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/star_ethernet/status_item.rb', line 30 def msg = @statuses.empty? ? "[#{@time.to_s}] Normal status" : "[#{@time.to_s}] #{@statuses.map{ |status| status.to_s }.join(', ')}" msg += " etb:#{@etb}" msg += " (#{@purpose})" if @purpose msg end |
#need_to_change_paper? ⇒ Boolean
26 27 28 |
# File 'lib/star_ethernet/status_item.rb', line 26 def need_to_change_paper? @statuses.any? { |s| [SensorStatus::PaperEnd, SensorStatus::PaperNearInsideEnd, SensorStatus::PaperNearOutsideEnd].include?(s)} end |
#offline? ⇒ Boolean
14 15 16 |
# File 'lib/star_ethernet/status_item.rb', line 14 def offline? @statuses.include?(PrinterStatus::Offline) end |
#unhealthy? ⇒ Boolean
22 23 24 |
# File 'lib/star_ethernet/status_item.rb', line 22 def unhealthy? @statuses.reject{ |s| s == PrinterStatus::EtbCommandExecuted}.any? end |