Sha256: 55e9712f02c149799da8e272ac1e4972e11792c1ba79fa57baadf4f6b00af19f
Contents?: true
Size: 1.47 KB
Versions: 2
Compression:
Stored size: 1.47 KB
Contents
require 'rint_core/g_code/codes' require 'active_support/core_ext/object/blank' module RintCore module Driver # Handles the parsing of printer responses and formats commands sent to the printer. module Parsing private def format_command(command) (command.strip + "\n").split(RintCore::GCode::Codes::COMMENT_SYMBOL).first.encode(config.encoding) end def get_checksum(command) command.bytes.inject{|a,b| a^b}.to_s end def prefix_command(command, line_number) prefix = ('N' + line_number.to_s + ' ' + command.strip).encode(config.encoding) prefix+'*'+get_checksum(prefix) end def get_response_type(line) return :invalid unless line.present? || line.class == String return :error if line.include?(config.error_response) return :debug if line.include?(config.debug_response) return :online if line.start_with?(*config.online_response) return :valid if line.start_with?(*config.good_response) && !line.include?(*config.temperature_response) return :temperature_response if line.start_with?(*config.good_response) && line.include?(*config.temperature_response) return :temperature if line.include?(*config.temperature_response) return :resend if line.start_with?(*config.resend_response) return :invalid end def get_resend_number(line) line.sub('N:', '').sub('N', '').sub(':', '').strip.split.first.to_i end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rintcore-0.0.5 | lib/rint_core/driver/parsing.rb |
rintcore-0.0.4 | lib/rint_core/driver/parsing.rb |