Giter VIP home page Giter VIP logo

tm_mercury's People

Contributors

electricshaman avatar mobileoverlord avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tm_mercury's Issues

Reader process crashes if you unplug while in async read mode

Steps to reproduce

  1. Start the service via iex -S mix
  2. Start up a new reader process with {:ok, pid} = Reader.start_link(device: "/dev/ttyACM0")
  3. Put the read in read async mode: Reader.read_async_start(pid, self())
  4. Unplug the reader

Current behavior

The reader's pseudo async task is unaware of the connection status so it continues trying to send data through the Transport. Since the transport is pre-occupied while waiting to reconnect to the device, the call through Transport.send_data times out. The task is linked to the reader, so the reader crashes too (as it should).

01:03:27.718 [info]  Disconnecting from RFID reader at /dev/ttyACM0

01:03:27.718 [error] RFID UART error: :eio

01:03:27.718 [info]  Connecting to RFID reader at /dev/ttyACM0

01:03:28.720 [info]  Connecting to RFID reader at /dev/ttyACM0

01:03:29.723 [info]  Connecting to RFID reader at /dev/ttyACM0

01:03:30.726 [info]  Connecting to RFID reader at /dev/ttyACM0

01:03:31.727 [info]  Connecting to RFID reader at /dev/ttyACM0
** (EXIT from #PID<0.181.0>) exited in: :gen_server.call(#PID<0.190.0>, {:send, <<34, 0, 0, 19, 1, 244>>})
    ** (EXIT) time out
                                
01:03:32.159 [error] Task #PID<0.195.0> started from :ttyACM0 terminating
** (stop) exited in: :gen_server.call(#PID<0.190.0>, {:send, <<34, 0, 0, 19, 1, 244>>})
    ** (EXIT) time out
    (stdlib) gen_server.erl:204: :gen_server.call/2
    (tm_mercury) lib/tm_mercury/transport.ex:37: TM.Mercury.Transport.send_data/2
    (tm_mercury) lib/tm_mercury/reader.ex:554: TM.Mercury.Reader.execute_read_sync/3
    (tm_mercury) lib/tm_mercury/reader.ex:510: TM.Mercury.Reader.pseudo_read_async/4
    (elixir) lib/task/supervised.ex:85: Task.Supervised.do_apply/2
    (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
Function: #Function<6.93679168/0 in TM.Mercury.Reader.read_async_start/5>
    Args: []

Expected behavior

The reader should not crash if disconnected while in read async mode.

Ideally the reader would suspend async reading while it is disconnected and then resume if/when it reconnects.

Reboot is broken

It crashes the reader process if you try to call it.
We broke it somehow during the recent refactoring/fixes.

iex(29)> Reader.reboot(:ttyACM0)
** (EXIT from #PID<0.181.0>) an exception was raised:
    ** (FunctionClauseError) no function clause matching in TM.Mercury.Reader.reboot_reader/1
        (tm_mercury) lib/tm_mercury/reader.ex:452: TM.Mercury.Reader.reboot_reader(%{async_pid: #PID<0.199.0>, init: %TM.Mercury.Reader{antennas: 1, model: nil, power_mode: :full, region: :na, tag_protocol: :gen2}, read_timeout: 500, reader: %TM.Mercury.Reader{antennas: 1, model: :micro, power_mode: :full, region: :na, tag_protocol: :gen2}, status: :connected, transport: #PID<0.189.0>})
        (tm_mercury) lib/tm_mercury/reader.ex:326: TM.Mercury.Reader.handle_call/3
        (stdlib) gen_server.erl:615: :gen_server.try_handle_call/4
        (stdlib) gen_server.erl:647: :gen_server.handle_msg/5
        (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3

16:04:09.067 [error] GenServer :ttyACM0 terminating
** (FunctionClauseError) no function clause matching in TM.Mercury.Reader.reboot_reader/1
    (tm_mercury) lib/tm_mercury/reader.ex:452: TM.Mercury.Reader.reboot_reader(%{async_pid: #PID<0.199.0>, init: %TM.Mercury.Reader{antennas: 1, model: nil, power_mode: :full, region: :na, tag_protocol: :gen2}, read_timeout: 500, reader: %TM.Mercury.Reader{antennas: 1, model: :micro, power_mode: :full, region: :na, tag_protocol: :gen2}, status: :connected, transport: #PID<0.189.0>})
    (tm_mercury) lib/tm_mercury/reader.ex:326: TM.Mercury.Reader.handle_call/3
    (stdlib) gen_server.erl:615: :gen_server.try_handle_call/4
    (stdlib) gen_server.erl:647: :gen_server.handle_msg/5
    (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
Last message: :reboot

Tag phase might be wrong/unreliable

For the same tag sitting undisturbed on top of the reader for a few minutes, the tag's phase returned a wide distribution of values.

Value Count Frequency %
160 11 9.17
5 10 8.33
109 9 7.5
165 8 6.67
70 7 5.83
19 5 4.17
42 5 4.17
47 5 4.17
115 5 4.17
14 4 3.33
25 4 3.33
61 4 3.33
112 4 3.33
22 3 2.5
123 3 2.5
171 3 2.5
28 2 1.67
30 2 1.67
33 2 1.67
53 2 1.67
56 2 1.67
73 2 1.67
75 2 1.67
84 2 1.67
157 2 1.67
163 2 1.67
11 1 0.83
16 1 0.83
64 1 0.83
78 1 0.83
104 1 0.83
106 1 0.83
129 1 0.83
154 1 0.83
174 1 0.83
177 1 0.83

Reader repeatedly executes clear_tag_id_buffer and reset_reader_statistics in async mode

Right now the pseudo async mode calls the public read_sync API on the Reader process, so all of the preparation ops for read_sync are called during each interval of the async loop. e.g. clearing the tag buffer (which async already does itself), and resetting the reader statistics like RF on-time and noise floor.

We should add a new public read_sync_prepared call that the async task can use. It would skip clearing the tag buffer and resetting the statistics, reducing the number of request/response cycles to the reader in the async interval from 5 to 3 when tags are present, and 3 to 1 when none are present.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.