<commit_before># RModBus - free implementation of ModBus protocol on Ruby.
#
# Copyright (C) 2008-2011  <NAME>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
require 'gserver'

module ModBus
  # TCP server implementation
  # @example
  #   srv = TCPServer.new(10002, 1)
  #   srv.coils = [1,0,1,1]
  #   srv.discrete_inputs = [1,1,0,0]
  #   srv.holding_registers = [1,2,3,4]
  #   srv.input_registers = [1,2,3,4]
  #   srv.debug = true
  #   srv.start
	class TCPServer < GServer
		include Debug
		include Server

    # Init server
    # @param [Integer] port listen port
    # @param [Integer] uid slave device
    # @param [Hash] opts options of server
    # @option opts [String] :host host of server default '127.0.0.1'
    # @option opts [Float, Integer] :max_connection max of TCP connection with server default 4
		def initialize(port = 502, uid = 1, opts = {})
			@uid = uid
      opts[:host] = DEFAULT_HOST unless opts[:host]
      opts[:max_connection] = 4 unless opts[:max_connection]
			super(port, host = opts[:host], maxConnection = opts[:max_connection])
		end

    # Serve requests
    # @param [TCPSocket] io socket
    def serve(io)
      while not stopped?
        header = io.read(7)
        tx_id = header[0,2]
        proto_id = header[2,2]
        len = header[4,2].unpack('n')[0]
        unit_id = header.getbyte(6)
        if proto_id == "\x00\x00"
          req = io.read(len - 1)
          if unit_id == @uid || unit_id == 0<commit_msg>Add a warning message to ask use UID=255 in TCP Server.<commit_after># RModBus - free implementation of ModBus protocol on Ruby.
#
# Copyright (C) 2008-2011  <NAME>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
require 'gserver'

module ModBus
  # TCP server implementation
  # @example
  #   srv = TCPServer.new(10002, 1)
  #   srv.coils = [1,0,1,1]
  #   srv.discrete_inputs = [1,1,0,0]
  #   srv.holding_registers = [1,2,3,4]
  #   srv.input_registers = [1,2,3,4]
  #   srv.debug = true
  #   srv.start
	class TCPServer < GServer
		include Debug
		include Server

    # Init server
    # @param [Integer] port listen port
    # @param [Integer] uid slave device
    # @param [Hash] opts options of server
    # @option opts [String] :host host of server default '127.0.0.1'
    # @option opts [Float, Integer] :max_connection max of TCP connection with server default 4
		def initialize(port = 502, uid = 1, opts = {})
			@uid = uid

      warn "[WARNING] Please, use UID = 255. It will be fixed in the next release." if @uid != 0xff

      opts[:host] = DEFAULT_HOST unless opts[:host]
      opts[:max_connection] = 4 unless opts[:max_connection]
			super(port, host = opts[:host], maxConnection = opts[:max_connection])
		end

    # Serve requests
    # @param [TCPSocket] io socket
    def serve(io)
      while not stopped?
        header = io.read(7)
        tx_id = header[0,2]
        proto_id = header[2,2]
        len = header[4,2].unpack('n')[0]
        unit_id = header.getbyte(6)
        if proto_id == "\x00\x00"
          req = io.read(len - 1)
          if unit_id == @uid || unit_id == 0
{'fraction_non_alphanumeric': 0.10519677093844601, 'fraction_numerical': 0.031029263370333, 'mean_word_length': 3.0500510725229826, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1042592', 'n_tokens_mistral': 1329, 'n_tokens_neox': 1256, 'n_words': 456}