Skip to content

Commit

Permalink
Bitstring logging improved (HEX)
Browse files Browse the repository at this point in the history
  • Loading branch information
alde103 committed Mar 1, 2024
1 parent 152e699 commit 6fa5769
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.3.12

* Improve bitstring logging.

## 0.3.11

* Elixir 1.15 (OTP 26) warnings fixed.
Expand Down
2 changes: 1 addition & 1 deletion lib/rtu/master.ex
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ defmodule Modbux.Rtu.Master do

def handle_call({:request, cmd}, _from, state) do
uart_frame = Rtu.pack_req(cmd)
Logger.debug("(#{__MODULE__}) Frame: #{inspect(uart_frame <> <<0x00>>)}")
Logger.debug("(#{__MODULE__}) Frame: #{inspect(uart_frame, base: :hex)}")
UART.flush(state.uart_pid)
UART.write(state.uart_pid, uart_frame)

Expand Down
2 changes: 1 addition & 1 deletion lib/rtu/slave.ex
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ defmodule Modbux.Rtu.Slave do
end

def handle_info({:circuits_uart, device, {:error, reason, bad_frame}}, state) do
Logger.warning("(#{__MODULE__}) Error with \"#{device}\" received: #{bad_frame}, reason: #{reason}")
Logger.warning("(#{__MODULE__}) Error with \"#{device}\" received: #{inspect(bad_frame, base: :hex)}, reason: #{reason}")

case reason do
:einval ->
Expand Down
2 changes: 1 addition & 1 deletion lib/tcp/server/server_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ defmodule Modbux.Tcp.Server.Handler do
end

def handle_info({:tcp, socket, data}, state) do
Logger.debug("(#{__MODULE__}) Received: #{data} ")
Logger.debug("(#{__MODULE__}) Received: #{inspect(data, base: :hex)} ")
{cmd, transid} = Tcp.parse_req(data)
Logger.debug("(#{__MODULE__}) Received Modbux request: #{inspect({cmd, transid})}")

Expand Down
7 changes: 5 additions & 2 deletions lib/tcp/tcp.ex
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ defmodule Modbux.Tcp do
if size == r_size do
payload
else
Logger.error("#{__MODULE__} size = #{size}, payload_size = #{r_size}, msg = #{inspect(msg)}")
Logger.error(
"#{__MODULE__} size = #{size}, payload_size = #{r_size}, msg = #{inspect(msg, base: :hex)}"
)

nil
end

Expand All @@ -73,7 +76,7 @@ defmodule Modbux.Tcp do
end

def unwrap(inv_data) do
Logger.error("#{__MODULE__} invalid data: #{inspect(inv_data)}")
Logger.error("#{__MODULE__} invalid data: #{inspect(inv_data, base: :hex)}")
raise("#{__MODULE__} invalid data: #{inspect(inv_data)}")
end
end
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Modbux.Mixfile do
use Mix.Project

@version "0.3.11"
@version "0.3.12"
@source_url "https://github.com/valiot/modbux"


Expand Down
2 changes: 1 addition & 1 deletion test/tcp/modbus_tcp_client_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ defmodule ModbuxTcpClientTest do
end

test "test Client errors" do
{:ok, cpid} = Client.start_link(ip: {127, 0, 0, 1}, port: 5000)
{:ok, cpid} = Client.start_link(ip: {127, 0, 0, 1}, tcp_port: 5000)
assert {:error, :econnrefused} == Client.connect(cpid)
assert {:error, :closed} == Client.close(cpid)
end
Expand Down

0 comments on commit 6fa5769

Please sign in to comment.