anchor.diff:      ".*?"                           %% any
   ])).
   
  +-define(SOCKET_OPTS, [{active, once}, {packet, line}]).
  +
   -record(state, {protocol, transport, socket, timeout, deviceId = 0}).
   
   %%%===================================================================
  
positive.code:   {stop, Reason :: term(), NewState :: #state{}}).
  handle_info({command, Command}, State) ->
    do_execute_command(State, Command);
  handle_info({tcp, _, ?TRASH}, State = #state{socket = Socket, transport = Transport}) ->
    Transport:setopts(Socket, [{active, once}]),
    {noreply, State, ?TIMEOUT};
  handle_info({tcp, Socket, Data}, State = #state{socket = Socket, transport = Transport}) when byte_size(Data) > 1 ->
    Transport:setopts(Socket, [{active, once}]),
    do_process_data(State, Data);
  handle_info({tcp_closed, _Socket}, State) ->
    {stop, normal, State};
  
negative.code:   {stop, Reason :: term()} | ignore).
  init({Ref, Socket, Transport, Opts}) ->
    ok = ranch:accept_ack(Ref),
    ok = Transport:setopts(Socket, ?SOCKET_OPTS),
    Protocol = proplists:get_value(protocol, Opts),
    gen_server:enter_loop(?MODULE, [],
      #state{protocol = Protocol, socket = Socket, transport = Transport}, ?TIMEOUT).
  