@w2a-iiot/parsers
Version:
WIKA JavaScript parsers
452 lines (447 loc) • 13.9 kB
TypeScript
/** END CONSTANTS */
/**
* @asType integer
* @minimum 1
* @maximum 224
*/
type fPort = number;
interface ChannelMeasurement {
channelId: number;
value: number;
channelName: string;
}
interface UplinkInput$1 {
/**
* The uplink payload byte array, where each byte is represented by an integer between 0 and 255.
* @format: integer[]
*/
bytes: number[];
/**
* The uplink message LoRaWAN `fPort`
* @format: int
*/
fPort: fPort;
/**
* ISO 8601 string representation of the time the message was received by the network server.
*/
recvTime?: string;
}
type OutputError = string;
type OutputWarning = string;
interface OutputFailure {
/**
* A list of error messages while decoding the provided payload.
*/
errors: OutputError[];
}
interface BaseMessage {
warnings?: OutputWarning[];
}
interface BaseData<TMessage extends number = number> {
messageType: TMessage;
configurationId: number;
}
declare const ALARM_EVENT_NAMES_DICTIONARY: readonly ["triggered", "disappeared"];
declare const PROCESS_ALARM_TYPE_NAMES_DICTIONARY: readonly ["low threshold", "high threshold", "falling slope", "rising slope", "low threshold with delay", "high threshold with delay"];
declare const CONFIGURATION_STATUS_NAMES_DICTIONARY: {
readonly 32: "configuration successful";
readonly 48: "configuration rejected";
readonly 96: "command successful";
readonly 112: "command failed";
};
interface UplinkOutputSuccessfulMeasurements extends BaseMessage {
data: BaseData<0x01 | 0x02> & {
measurements: {
channels: [ChannelMeasurement] | [
ChannelMeasurement,
ChannelMeasurement
];
};
};
}
interface UplinkOutputSuccessfulProcessAlarms extends BaseMessage {
data: BaseData<0x03> & {
processAlarms: Array<{
channelId: number;
channelName: string;
event: 0 | 1;
eventName: (typeof ALARM_EVENT_NAMES_DICTIONARY)[number];
alarmType: number;
alarmTypeName: (typeof PROCESS_ALARM_TYPE_NAMES_DICTIONARY)[number];
value: number;
}>;
};
}
interface ChannelTechnicalAlarmData {
channelId: number;
channelName: string;
event: 0 | 1;
eventName: 'triggered' | 'disappeared';
causeOfFailure: 0 | 1 | 2 | 3 | 4 | 5;
causeOfFailureName: 'no alarm' | 'open condition' | 'short condition' | 'saturated low' | 'saturated high' | 'ADC communication error';
}
interface UplinkOutputSuccessfulTechnicalAlarms extends BaseMessage {
data: BaseData<0x04> & {
technicalAlarms: ChannelTechnicalAlarmData[];
};
}
interface UplinkOutputSuccessfulConfigurationStatus extends BaseMessage {
data: {
messageType: 0x06;
configurationStatus: {
configurationId: number;
statusId: keyof typeof CONFIGURATION_STATUS_NAMES_DICTIONARY;
status: (typeof CONFIGURATION_STATUS_NAMES_DICTIONARY)[keyof typeof CONFIGURATION_STATUS_NAMES_DICTIONARY];
};
};
}
interface UplinkOutputSuccessfulRadioUnitIdentification extends BaseMessage {
data: BaseData<0x07> & {
radioUnitIdentification: {
productId: 0x0E;
productSubId: 0x00;
radioUnitModemFirmwareVersion: `${number}.${number}.${number}`;
radioUnitModemHardwareVersion: `${number}.${number}.${number}`;
radioUnitFirmwareVersion: `${number}.${number}.${number}`;
radioUnitHardwareVersion: `${number}.${number}.${number}`;
serialNumber: string;
};
};
}
interface UplinkOutputSuccessfulKeepAlive extends BaseMessage {
data: BaseData<0x08> & {
deviceStatistic: {
numberOfMeasurements: number;
numberOfTransmissions: number;
batteryResetSinceLastKeepAlive: boolean;
estimatedBatteryPercent: number;
batteryCalculationError: boolean;
radioUnitTemperatureLevel_C: number;
};
};
}
type UplinkOutputSuccessful = UplinkOutputSuccessfulMeasurements | UplinkOutputSuccessfulProcessAlarms | UplinkOutputSuccessfulTechnicalAlarms | UplinkOutputSuccessfulConfigurationStatus | UplinkOutputSuccessfulRadioUnitIdentification | UplinkOutputSuccessfulKeepAlive;
type UplinkInput = UplinkInput$1;
type UplinkOutput = UplinkOutputSuccessful | OutputFailure;
interface DownlinkInputResetToFactory {
deviceAction: 'resetToFactory';
}
interface DownlinkInputBatteryReset {
/**
* @asType integer
* @minimum 1
* @maximum 31
* @default 1
*/
configurationId?: number;
deviceAction: 'resetBatteryIndicator';
}
/**
* A channel can be reenabled with an "empty" process alarm message (no alarms)
*/
interface DownlinkInputDisableChannel {
/**
* @asType integer
* @minimum 1
* @maximum 31
* @default 1
*/
configurationId?: number;
deviceAction: 'disableChannel';
configuration: {
channel0?: {
disable: true;
};
channel1?: {
disable: true;
};
};
}
/**
* measuring rate * publication factor has to be less than or equal 172,800
*/
interface DownlinkInputMainConfiguration {
/**
* @asType integer
* @minimum 1
* @maximum 31
* @default 1
*/
configurationId?: number;
deviceAction: 'setMainConfiguration';
configuration: {
/**
* @asType integer
* @minimum 60
* @maximum 86400
*/
measuringRateWhenNoAlarm: number;
/**
* @asType integer
* @minimum 1
* @maximum 2880
*/
publicationFactorWhenNoAlarm: number;
/**
* @asType integer
* @minimum 60
* @maximum 86400
*/
measuringRateWhenAlarm: number;
/**
* @asType integer
* @minimum 1
* @maximum 2880
*/
publicationFactorWhenAlarm: number;
};
}
interface DownlinkInputSetProcessAlarmConfiguration {
/**
* @asType integer
* @minimum 1
* @maximum 31
* @default 1
*/
configurationId?: number;
deviceAction: 'setProcessAlarmConfiguration';
configuration: {
channel0?: ChannelConfig$1;
channel1?: ChannelConfig$1;
};
}
/**
* Offset value for measurement correction.
* Only uses the first 2 decimal places.
* Unit: percent (%)
* @minimum -5
* @maximum 5
* @example 2.75
* @unit percent
*/
type Offset = number;
interface DownlinkInputSetMeasureOffsetConfiguration {
/**
* @asType integer
* @minimum 1
* @maximum 31
* @default 1
*/
configurationId?: number;
deviceAction: 'setMeasureOffsetConfiguration';
configuration: {
channel0?: {
measureOffset: Offset;
};
channel1?: {
measureOffset: Offset;
};
};
}
/**
* Start-up time in seconds (s).
* Only uses the first decimal place.
* @minimum 0.1
* @maximum 15
* @unit seconds
*/
type StartUpTime = number;
interface DownlinkInputsetStartUpTimeConfiguration {
/**
* @asType integer
* @minimum 1
* @maximum 31
* @default 1
*/
configurationId?: number;
deviceAction: 'setStartUpTimeConfiguration';
configuration: {
/**
* Start-up time for channel 0 in seconds (s).
* Only uses the first decimal place.
* @unit seconds
*/
channel0?: {
startUpTime: StartUpTime;
};
/**
* Start-up time for channel 1 in seconds (s).
* Only uses the first decimal place.
* @unit seconds
*/
channel1?: {
startUpTime: StartUpTime;
};
};
}
interface ChannelConfig$1 {
/**
* Dead Band setting is limited to a maximum of 20% of the radio unit measuring range.
* An invalid dead band value makes the whole channel process alarm configuration invalid.
* Only uses the first 2 decimal places.
* @minimum 0
* @maximum 20
*/
deadBand: number;
alarms?: {
/**
* High threshold alarm appears for a measurement above threshold + dead band
* and disappears for a measurement below threshold - dead band.
* In percent (%) of the measuring range.
* Only uses the first 2 decimal places.
* @minimum 0
* @maximum 100
* @example 75.75
* @unit percent
*/
lowThreshold?: number;
/**
* High threshold alarm appears for a measurement above threshold + dead band
* and disappears for a measurement below threshold - dead band.
* In percent (%) of the measuring range.
* Only uses the first 2 decimal places.
* @minimum 0
* @maximum 100
* @example 80.80
* @unit percent
*/
highThreshold?: number;
lowThresholdWithDelay?: {
/**
* Value for low threshold with delay.
* Only uses the first 2 decimal places.
* In percent (%) of the measuring range.
* @minimum 0
* @maximum 100
* @example 10.10
* @unit percent
*/
value: number;
/**
* Delay in seconds (s). Must be a multiple of both the measurement period without alarm
* and the measurement period with alarm.
* @asType integer
* @minimum 0
* @maximum 65535
* @unit seconds
*/
delay: number;
};
highThresholdWithDelay?: {
/**
* Value for high threshold with delay in percent (%).
* Only uses the first 2 decimal places.
* In percent (%) of the measuring range.
* @minimum 0
* @maximum 100
* @example 90.90
* @unit percent
*/
value: number;
/**
* Delay in seconds (s). Must be a multiple of both the measurement period without alarm
* and the measurement period with alarm.
* @asType integer
* @minimum 0
* @maximum 65535
* @unit seconds
*/
delay: number;
};
/**
* Rising slope alarm value in percent (%). Slope alarms can only be configured for a maximum of 50%
* of the radio unit measuring range.
* Only uses the first 2 decimal places.
* @minimum 0
* @maximum 50
* @example 25.25
* @unit percent
*/
risingSlope?: number;
/**
* Falling slope alarm value in percent (%). Slope alarms can only be configured for a maximum of 50%
* of the radio unit measuring range.
* Only uses the first 2 decimal places.
* @minimum 0
* @maximum 50
* @example 25.25
* @unit percent
*/
fallingSlope?: number;
};
}
type DownlinkInput = DownlinkInputResetToFactory | DownlinkInputBatteryReset | DownlinkInputDisableChannel | DownlinkInputMainConfiguration | DownlinkInputSetProcessAlarmConfiguration | DownlinkInputSetMeasureOffsetConfiguration | DownlinkInputsetStartUpTimeConfiguration;
type Frame = number[];
type DownlinkActions = Extract<DownlinkInput, {
deviceAction: 'resetToFactory' | 'resetBatteryIndicator';
}>;
type StartUpTimeConfig = Required<Extract<DownlinkInput, {
deviceAction: 'setStartUpTimeConfiguration';
}>['configuration']>['channel0'];
type MeasurementOffsetConfig = Required<Extract<DownlinkInput, {
deviceAction: 'setMeasureOffsetConfiguration';
}>['configuration']>['channel0'];
type ChannelConfig = (Required<Extract<DownlinkInput, {
deviceAction: 'setProcessAlarmConfiguration';
}>['configuration']>['channel0']) & Partial<StartUpTimeConfig> & Partial<MeasurementOffsetConfig>;
type MainConfig = Required<Extract<DownlinkInput, {
deviceAction: 'setMainConfiguration';
}>['configuration']>;
interface DownlinkConfigurationFrame {
deviceAction: 'downlinkConfiguration';
configurationId?: number;
/**
* @deprecated This field is deprecated and will be removed in the future. Use `configurationId` instead.
*/
transactionId?: number;
/**
* The spreading factor to use.
* By default assumes the worst case scenario (SF12 = 51 bytes per message).
* @default 'SF12'
* @preserve
*/
spreadingFactor?: keyof typeof spreadingFactorLookUp;
configuration: {
mainConfiguration?: MainConfig;
channel0?: boolean | ChannelConfig;
channel1?: boolean | ChannelConfig;
};
}
type NETRIS2DownlinkInput = DownlinkActions | DownlinkConfigurationFrame;
type NETRIS2DownlinkOutput = {
success: true;
data: {
frames: Frame[];
};
errors?: undefined;
} | {
success: false;
data?: undefined;
errors: string[];
};
/**
* Used to look up the amount of bytes per message for a given spreading factor.
*/
declare const spreadingFactorLookUp: {
readonly SF7: 222;
readonly 7: 222;
readonly SF8: 222;
readonly 8: 222;
readonly SF9: 115;
readonly 9: 115;
readonly SF10: 51;
readonly 10: 51;
readonly SF11: 51;
readonly 11: 51;
readonly SF12: 51;
readonly 12: 51;
};
declare function NETRIS2Parser(): {
encodeDownlink: (input: NETRIS2DownlinkInput) => NETRIS2DownlinkOutput;
decodeUplink: (input: UplinkInput) => UplinkOutput;
decodeHexUplink: (input: Omit<UplinkInput, "bytes"> & {
bytes: unknown;
}) => UplinkOutput;
adjustRoundingDecimals: (newDecimals: number) => void;
};
export { type NETRIS2DownlinkInput, type NETRIS2DownlinkOutput, NETRIS2Parser };