UNPKG

epc-tds-ts

Version:

EPC Tag Data Standard encoding and decoding library, written in javascript for Node.js

98 lines (97 loc) 3.88 kB
"use strict"; /* * EPC Tag Data Standard * 2021 Sergio S. */ var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var BitArray = require('./utils/bit-array').BitArray; var Epc = /** @class */ (function (_super) { __extends(Epc, _super); function Epc(length) { return _super.call(this, length) || this; } Epc.prototype.clone = function () { throw new Error('Unimplemented method.'); }; Epc.prototype.getType = function () { throw new Error('Unimplemented method.'); }; Epc.prototype.toTagURI = function () { throw new Error('Unimplemented method.'); }; Epc.prototype.toIdURI = function () { throw new Error('Unimplemented method.'); }; Epc.prototype.toBarcode = function () { throw new Error('Unimplemented method.'); }; Epc.prototype.getTotalBits = function () { throw new Error('Unimplemented method.'); }; Epc.prototype.getHeader = function () { throw new Error('Unimplemented method.'); }; /** * The filter value is additional control information that may be included in * the EPC memory bank of a Gen 2 tag. The intended use of the filter value is * to allow an RFID reader to select or deselect the tags corresponding to * certain physical objects, to make it easier to read the desired tags in an * environment where there may be other tags present in the environment * @return */ Epc.prototype.getFilter = function () { return _super.prototype.get.call(this, Epc.FILTER_OFFSET, Epc.FILTER_END); }; /** * 0.- All Others (see Section 10.1). * 1.- Point of Sale (POS) Trade Item . * 2.- Full Case for Transport. * 3.- Reserved (see Section 10.1). * 4.- Inner Pack Trade Item Grouping for Handling. * 5.- Reserved (see Section 10.1). * 6.- Unit Load. * 7.- Unit inside Trade Item or component inside a * product not intended for individual sale. * @param value */ Epc.prototype.setFilter = function (value) { if (value < 0 || value > Epc.FILTER_MAX_VALUE) { throw new Error("Value '".concat(value, "' out of range (min: 0, max: ").concat(Epc.FILTER_MAX_VALUE, ")")); } _super.prototype.set.call(this, value, Epc.FILTER_OFFSET, Epc.FILTER_END); return this; }; Epc.prototype.getSegment = function (segment) { return _super.prototype.get.call(this, segment.start, segment.end); }; Epc.prototype.setSegment = function (value, segment) { if (value < 0 || value > segment.maxValue) { throw new Error("Value '".concat(value, "' out of range (min: 0, max: ").concat(segment.maxValue, ")")); } _super.prototype.set.call(this, value, segment.start, segment.end); }; Epc.prototype.getSegmentString = function (segment) { return String(this.getSegment(segment)).padStart(segment.digits, '0'); }; Epc.EPC_HEADER_OFFSET = 0; Epc.EPC_HEADER_END = 8; Epc.FILTER_OFFSET = 8; Epc.FILTER_END = 11; Epc.FILTER_MAX_VALUE = 7; return Epc; }(BitArray)); module.exports = { Epc: Epc };