class StarEthernet::StatusItem

Attributes

etb[RW]
purpose[W]
statuses[R]
time[R]

Public Class Methods

decode_status(status_raw_data) click to toggle source
# 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
new(statuses: []) click to toggle source
# File lib/star_ethernet/status_item.rb, line 7
def initialize(statuses: [])
  @statuses = statuses
  @etb = nil
  @time = Time.now
  @purpose = nil
end

Public Instance Methods

append_status(status) click to toggle source
# File lib/star_ethernet/status_item.rb, line 18
def append_status(status)
  @statuses.push(status)
end
message() click to toggle source
# File lib/star_ethernet/status_item.rb, line 30
def message
  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?() click to toggle source
# 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?() click to toggle source
# File lib/star_ethernet/status_item.rb, line 14
def offline?
  @statuses.include?(PrinterStatus::Offline)
end
unhealthy?() click to toggle source
# File lib/star_ethernet/status_item.rb, line 22
def unhealthy?
  @statuses.reject{ |s| s == PrinterStatus::EtbCommandExecuted}.any?
end