npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

flotron-decoder

v5.0.0

Published

This function, decode, serves as a payload decoder for logger data, specifically for a combination of battery, analog, and digital data types. It extracts and transforms the payload data based on the logger type and specified scaling parameters.

Downloads

33

Readme

Payload Decoder Documentation

This function, decode, serves as a payload decoder for logger data, specifically for a combination of battery, analog, and digital data types. It extracts and transforms the payload data based on the logger type and specified scaling parameters.

Function Signature

function decode(loggerType, payload, analogMin, analogMax, batteryMin = 0, batteryMax = 3600)

Parameters

  • loggerType (string): A string indicating the type of logger data, specifying the presence of battery ("B"), analog ("A"), and digital ("D") data types.
  • payload (string): The raw payload data to be decoded.
  • analogMin (number): The minimum value for analog data scaling.
  • analogMax (number): The maximum value for analog data scaling.
  • batteryMin (number, optional): The minimum value for battery data scaling. Defaults to 0.
  • batteryMax (number, optional): The maximum value for battery data scaling. Defaults to 3600.

Return Value

An object containing three arrays:

  • Battery: Array containing decoded and scaled battery data.
  • Analog: Array containing decoded and scaled analog data.
  • Digital: Array containing decoded and averaged digital data.

Implementation

Initialization

  • Variables are declared to track the counts and arrays for battery, analog, and digital data.
  • Trackers are initialized to manage the iteration through the payload.

Data Extraction and Simplification

  • The function iterates through the payload based on the logger type and extracts data into respective arrays.
  • Each array is then simplified by calculating the average of subarrays.

Scaling

Battery Data

  • The battery data is scaled from the raw values to a specified range using a linear scaling formula.
  • The scaled battery data is constrained within the specified range.

Analog Data

  • Analog data is scaled similarly to the battery data, using a linear scaling formula.
  • The scaled analog data is constrained within the specified range.

Digital Data

Digital data is averaged within each subarray.

Example Usage

const loggerType = "BAAADD";
const payload = "0A0F00B01400C82100D0ABCDEF";
const analogMin = 0;
const analogMax = 100;
const batteryMin = 0;
const batteryMax = 3600;

const decodedData = decode(loggerType, payload, analogMin, analogMax, batteryMin, batteryMax);
console.log(decodedData);

This function is designed to handle decoding payloads from a logger device and can be customized by adjusting scaling parameters according to the specific characteristics of the data.

Attribution

Created by Hanno Vorster, 2024