UNPKG

bt-seneca-msc

Version:

A pure Javascript API for the Seneca Multi Smart Calibrator (MSC) device, using web bluetooth.

110 lines (105 loc) 3.11 kB
var constants = require("../constants"); var utils = require("../utils"); var CommandType = constants.CommandType; /** * Command to the meter, may include setpoint * */ class Command { /** * Creates a new command * @param {CommandType} ctype */ constructor(ctype = CommandType.NONE_UNKNOWN) { this.type = parseInt(ctype); this.setpoint = null; this.setpoint2 = null; this.error = false; this.pending = true; this.request = null; this.response = null; } static CreateNoSP(ctype) { var cmd = new Command(ctype); return cmd; } static CreateOneSP(ctype, setpoint) { var cmd = new Command(ctype); cmd.setpoint = parseFloat(setpoint); return cmd; } static CreateTwoSP(ctype, set1, set2) { var cmd = new Command(ctype); cmd.setpoint = parseFloat(set1); cmd.setpoint2 = parseFloat(set2); return cmd; } toString() { return "Type: " + utils.Parse(CommandType, this.type) + ", setpoint:" + this.setpoint + ", setpoint2: " + this.setpoint2 + ", pending:" + this.pending + ", error:" + this.error; } /** * Gets the default setpoint for this command type * @returns {Array} setpoint(s) expected */ defaultSetpoint() { switch (this.type) { case CommandType.GEN_THERMO_B: case CommandType.GEN_THERMO_E: case CommandType.GEN_THERMO_J: case CommandType.GEN_THERMO_K: case CommandType.GEN_THERMO_L: case CommandType.GEN_THERMO_N: case CommandType.GEN_THERMO_R: case CommandType.GEN_THERMO_S: case CommandType.GEN_THERMO_T: case CommandType.GEN_Cu50_3W: case CommandType.GEN_Cu50_2W: case CommandType.GEN_Cu100_2W: case CommandType.GEN_Ni100_2W: case CommandType.GEN_Ni120_2W: case CommandType.GEN_PT100_2W: case CommandType.GEN_PT500_2W: case CommandType.GEN_PT1000_2W: return { "Temperature (°C)": 0.0 }; case CommandType.GEN_V: return { "Voltage (V)": 0.0 }; case CommandType.GEN_mV: return { "Voltage (mV)": 0.0 }; case CommandType.GEN_mA_active: case CommandType.GEN_mA_passive: return { "Current (mA)": 0.0 }; case CommandType.GEN_LoadCell: return { "Imbalance (mV/V)": 0.0 }; case CommandType.GEN_Frequency: return { "Frequency (Hz)": 0.0 }; case CommandType.GEN_PulseTrain: return { "Pulses count": 0, "Frequency (Hz)": 0.0 }; case CommandType.SET_UThreshold_F: return { "Uthreshold (V)": 2.0 }; case CommandType.SET_Sensitivity_uS: return { "Sensibility (uS)": 2.0 }; case CommandType.SET_ColdJunction: return { "Cold junction compensation": 0.0 }; case CommandType.SET_Ulow: return { "U low (V)": 0.0 / constants.MAX_U_GEN }; case CommandType.SET_Uhigh: return { "U high (V)": 5.0 / constants.MAX_U_GEN }; case CommandType.SET_ShutdownDelay: return { "Delay (s)": 60 * 5 }; default: return {}; } } isGeneration() { return utils.isGeneration(this.type); } isMeasurement() { return utils.isMeasurement(this.type); } isSetting() { return utils.isSetting(this.type); } isValid() { return (utils.isMeasurement(this.type) || utils.isGeneration(this.type) || utils.isSetting(this.type)); } } module.exports = Command;