Coder Social home page Coder Social logo

gm1356's Introduction

splread - Read Sound Level from GM1356 meters

This tool is intended to read, and print to stdout, the current sound level from a USB-connected GM1356 sound level meter.

The GM1356 is not a precision instrument, but it's handy if you want to measure and monitor sound levels over a long period of time.

Requirements

You will need to have installed the following:

  • libhidapi

For Ubuntu Linux, you can install libhidapi as follows:

apt-get install libhidapi-dev

You can simply build the tool by invoking make in the source directory. The output file, called splread is invoked with the appropriate command line arguments.

For information on invoking the binary, run splread with the -h command line argument.

I want to run this automatically!

You can install the included systemd units as a user. There are two required units - one for a FIFO that splread will feed its messages to, and one for the splread service itself. Edit them both to ensure the paths to the FIFO, the EnvironmentFile and the service ExecStart make sense for your machine.

Ediut the contents of the environment file to match your use case. There is a sample splread.env file included in the source code distribution.

Once you've done that, copy or link the files to ~/.config/systemd/user/ and invoke:

  • systemctl --user daemon-reload
  • systemctl --user start splread.service;

You should be good to go. Any status or error messages from splread will go to the journal for later consumption.

I keep having to run this as root!!1

Copy the file 99-gm1356.rules to /etc/udev/rules.d then go through your distribution's dance to reload udev rules. For many it will simply be:

udevadm control -R

then either unplug/replug the device or invoke

udevadm trigger

if you're too lazy to replug.

Details

I don't understand the details of the protocol super well, but I can say the following:

  1. The protocol is USB-HID carried over a full-speed USB link
  2. Each HID report (input and output) is 8 bytes long

There are two types of messages I've seen: CONFIGURE and MEASURE. A CONFIGURE message seems to only involve the first two bytes of the report:

  1. 0x56 - indicates the CONFIGURE command
  2. 1 byte of flags where:
    • 0x40 indicates we're in fast mode (bit not set == in slow mode)
    • 0x10 indicates we're measuring dBC rather than dBA (bit not set == dBA)
    • bits 0-3 are one of the enumerated supported ranges:
      • 0 == 30-130 dB
      • 1 == 30-80 dB
      • 2 == 50-100 dB
      • 3 == 60-110 dB
      • 4 == 80-130 dB
      • All others are unknown/unsupported

It seems this gets a response where the first byte is 0xc4 consistently. You should poll until you get this response, because HID messages can and will get lost in transit.

The MEASURE/TRIGGER message is as follows:

  1. 0xb3 - indicates the MEASURE/TRIGGER command It seems that all other bytes are "don't care" values.

The response is as follows:

  1. 2 bytes representing the sound level, in 100ths of a decibel (i.e. divide by 100 to get dB value)
  2. 1 byte of flags where:
    • 0x40 indicates we're in fast mode (bit not set == in slow mode)
    • 0x20 indicates we're in hold max mode (bit not set == normal mode)
    • 0x10 indicates we're measuring dBC rather than dBA (bit not set == dBA)
    • bits 0-3 are one of the enumerated supported ranges:
      • 0 == 30-130 dB
      • 1 == 30-80 dB
      • 2 == 50-100 dB
      • 3 == 60-110 dB
      • 4 == 80-130 dB
      • All others are unknown/unsupported

Still working out what the remaining 5 bytes actually represent.

gm1356's People

Contributors

pvachon avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

Forkers

roaders elbaton

gm1356's Issues

I need to reboot my pi each time I run splread

First of all: thank you so much for this repo! I spent a very frustrating weekend trying to get this sound level meter working with my pi and was about to give up when I came across your repo and it enables me to read the data fine so thanks very much!

I do have one pretty annoying issue though - if I run splread and then quite it (using ctrl c in a console) the process stops but I am unable to start it again without rebooting my pi! I get the following when I try to restart it:

SPL-I-STARTUP, Starting the Chinese SPL Meter Reader (splread.c:409 in main)
SPL-I-POLL-INTERVAL, Setting poll interval to 1000 milliseconds (splread.c:365 in _parse_args)
SPL-I-DEVICE, Device found: 64bd:74e3 path: 0001:0003:00 serial: (null) (splread.c:147 in splread_find_device)
SPL-E-REQUEST-FAIL, Failed to write 8 bytes to device (wrote -1): hid_error is not implemented yet (splread.c:215 in splread_send_req)
SPL-F-CONFIG-FAIL, Failed to set configuration for SPL meter, aborting (splread.c:296 in splread_set_config)
SPL-F-BAD-CONFIG, Failed to load configuration, aborting. (splread.c:434 in main)

I am afraid that I know NOTHING about C++ and reading through the code makes very little sense to me! Can you give me any pointers on how to fix this issue?

Many thanks.

How to append output to daily file?

I am trying to log all measurements to a log file, preferably named like "/var/log/gm1356/20220613.txt"

Using the README file, I have managed to compile, run splread as a service on a Debian/Ubuntu system.

However, how do I send the output of this service splread to a local log file?
Can I use the created socket for this? Or should I change the service configuration to append all data to a log file?
I would really appreciate a simple step by step explanation how to do this, as my Linux skills are a bit limited.

Thank you,
Yaspr

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.