Skip to content

Commit eaad9d0

Browse files
author
CI
committed
Sync to GitHub
1 parent bc75750 commit eaad9d0

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

lib/bacnet/stack/transport/mstp_transport.ex

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,6 +1271,19 @@ if Code.ensure_loaded?(Circuits.UART) do
12711271
end
12721272

12731273
@doc false
1274+
def handle_info({:serial_crash, reason}, %State{} = state) do
1275+
# This message is either sent by ReceiveFSM or when writing UART fails
1276+
Logger.error(fn ->
1277+
"BacMstpTransport: UART error encountered and shutting down, error: " <> inspect(reason)
1278+
end)
1279+
1280+
# Stop everything
1281+
ReceiveFSM.close(state.receive_fsm)
1282+
UART.close(state.uart_pid)
1283+
1284+
{:stop, {:uart_error, reason}, state}
1285+
end
1286+
12741287
def handle_info(:wakeup_use_token, %State{} = state) do
12751288
{:noreply, state, {:continue, :use_token}}
12761289
end
@@ -2646,6 +2659,12 @@ if Code.ensure_loaded?(Circuits.UART) do
26462659
inspect(reason)
26472660
end)
26482661

2662+
# Common errors are :badf and :eio
2663+
# They are bad enough we need to stop (serial port is gone, dead, etc.)
2664+
if reason not in [:eagain, :eintr] do
2665+
send(self(), {:serial_crash, reason})
2666+
end
2667+
26492668
{:error, state}
26502669
end
26512670
end

lib/bacnet/stack/transport/mstp_transport/receive_fsm.ex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ if Code.ensure_loaded?(Circuits.UART) do
138138
inspect(reason)
139139
end)
140140

141+
if reason not in [:eagain, :eintr] do
142+
# Notify Transport Master and it will shut everything down
143+
send(data.transport_master, {:serial_crash, reason})
144+
end
145+
141146
{:keep_state, %{data | event_count: data.event_count + 1}}
142147
end
143148

0 commit comments

Comments
 (0)