anchor.diff:    ok = ranch:accept_ack(Ref),
     Protocol = proplists:get_value(protocol, Opts),
     {ok, Pattern} = re:compile(?PATTERN),
  -  loop(#state{protocol = Protocol, socket = Socket, transport = Transport, pattern = Pattern}).
  +  loop(#device_state{protocol = Protocol, socket = Socket, transport = Transport, timeout = infinity, pattern = Pattern}).
   
   % echo "39. wialon"
   % (echo -n -e "#D#030816;142342;5354.33140;N;02730.14582;E;0;0;0;NA;NA;NA;NA;;NA;NA\r\n";) | nc -v localhost 5003
  -loop(State = #state{protocol = Protocol, socket = Socket, transport = Transport, device = Device, pattern = Pattern}) ->
  -  case Transport:recv(Socket, 0, infinity) of
  +loop(State = #device_state{protocol = Protocol, socket = Socket, transport = Transport, timeout = Timeout, deviceId = DeviceId, pattern = Pattern}) ->
  +  case Transport:recv(Socket, 0, Timeout) of
       {ok, Data} ->
         em_logger:info("[packet] unit: ip = '~s' data: ~s", [em_hardware:resolve(Socket), Data]),
         [_, Head, Body] = binary:split(Data, [<<"#">>], [global]),
  
positive.code:             {error, _Reason} ->
                em_logger:info("[packet] unit: ip = '~s' unknown device with imei = '~s'", [em_hardware:resolve(Socket), Imei]),
                send_packet(State, <<"#AL#0">>),
                Transport:close(Socket);
              {ok, FindDevice} ->
                send_packet(State, <<"#AL#1">>),
                loop(State#state{device = FindDevice})
            end;
          {data, PositionModel} ->
            Position = PositionModel#position{
              deviceId = Device#device.id,
              protocol = atom_to_binary(Protocol, utf8),
              attributes = #{
                ?KEY_IP => em_hardware:resolve(Socket)
              }
            },
            case em_data_manager:create_position(Device, Position) of
              {ok, _} -> send_packet(State, <<"#AD#1">>);
              _ -> send_packet(State, <<"#AD#0">>)
            end,
  
negative.code:   binary:part(Data, Pos, Len).
  
  
  send_packet(#device_state{socket = Socket, transport = Transport}, Bin) ->
    Transport:send(Socket, <<Bin/binary, "\r\n">>).
  
  test() ->
  