1.0.4 • Published 3 years ago

@westh/umxxc-parser v1.0.4

Weekly downloads
-
License
GPL-3.0
Repository
github
Last release
3 years ago

@westh/umxxc-parser

Parse messages from UMxxC devices, that is for instance the UM24C, UM25C, or the UM34C.

This parser is a derivative of these guys' work:

Whereas the above repos provide a complete 'suite' for getting and parsing the data from a UMxxC device this is merely the parser.

Installation

npm install @westh/umxxc-parser

Usage

const umxxcParser = require('@westh/umxxc-parser')

const messageToBeParsed = Buffer.from('...') // ...however you get your data from the UMxxC device
const parsedMessage = umxxcParser.parse(messageToBeParsed)

The parsedMessage will contain something that looks like the following:

{
  model: 'UM34C',
  voltage: 4.84, // [V] for UM25C this value will be decivolts
  current: 25, // [mA] for UM25C this value will be tenth-milliamps
  power: 121, // [mW]
  temperature: {
    celsius: 23,
    fahrenheit: 74
  },
  selectedGroup: 0,
  groups: [
    { accumulatedCurrent: 2, accumulatedPower: 10 }, // [mAh] [mWh]
    { accumulatedCurrent: 0, accumulatedPower: 0 },
    { accumulatedCurrent: 0, accumulatedPower: 0 },
    { accumulatedCurrent: 0, accumulatedPower: 0 },
    { accumulatedCurrent: 0, accumulatedPower: 0 },
    { accumulatedCurrent: 0, accumulatedPower: 0 },
    { accumulatedCurrent: 0, accumulatedPower: 0 },
    { accumulatedCurrent: 0, accumulatedPower: 0 },
    { accumulatedCurrent: 0, accumulatedPower: 0 },
    { accumulatedCurrent: 0, accumulatedPower: 0 }
  ],
  usbDataPlus: 0.04, // [V]
  usbDataMinus: 0.03, // [V]
  chargingMode: 7,
  accumulatedCurrent: 2, // [mAh]
  accumulatedPower: 10, // [mWh]
  thresholdCurrent: 0, // [A] and is the threshold at which accumulated... is captured
  accumulatedTime: 390, // [s]
  connected: 1,
  screenTimeout: 1,
  screenBrightness: 3,
  resistance: 193.6, // [Ω]
  screenMode: 2,
  unknown: <Buffer 15 d4>
}

Description

Basically the parser does what is described below to whatever Buffer you might throw at it. The calculations mentioned in the 'Meaning' column are taken care of, except for the edge cases for the UM25C which are not handled at the moment.

OffsetLengthTypeMeaning
02modelModel ID
22measurementVoltage - UM25C: millivolts (divide by 1000 to get V), UM24C/UM34C: centivolts (divide by 100 to get V)
42measurementAmperage - UM25C tenth-milliamps (divide by 10000 to get A), UM24C/UM34C: milliamps (divide by 1000 to get A)
64measurementWattage (in mW, divide by 1000 to get W)
102measurementTemperature (in Celsius)
122measurementTemperature (in Fahrenheit)
142configurationCurrently selected data group, zero-indexed
1680measurementArray of 10 main capacity data groups (where the first one, group 0, is the ephemeral one) -- for each data group: 4 bytes mAh, 4 bytes mWh
962measurementUSB data line voltage (positive) in centivolts (divide by 100 to get V)
982measurementUSB data line voltage (negative) in centivolts (divide by 100 to get V)
1002measurementCharging mode index
1024measurementmAh from threshold-based recording
1064measurementmWh from threshold-based recording
1102configurationCurrently configured threshold for recording (in centiamps, divide by 100 to get A)
1124measurementDuration of threshold recording, in cumulative seconds
1162configurationThreshold recording active (1 if recording, 0 if not)
1182configurationCurrent screen timeout setting, in minutes (0-9, 0 is no screen timeout)
1202configurationCurrent backlight setting (0-5, 0 is dim, 5 is full brightness)
1224measurementResistance in deci-ohms (divide by 10 to get ohms)
1262configurationCurrent screen (zero-indexed, same order as on device)
1281unknown
1291checksum/unknownChecksum (UM34C) or unknown

Source RDTech UM series by sigrok.

Testing

Running yarn test will first run yarn build and then test both the CommonJS and ESM version.

License

GPL-3.0