epc-tds-ts
Version:
EPC Tag Data Standard encoding and decoding library, written in javascript for Node.js
132 lines (131 loc) • 6.31 kB
JavaScript
"use strict";
/**
* 96-bit Global Location Number With or Without Extension (SGLN)
*
* The SGLN EPC scheme is used to assign a unique identity to a physical location, such as a specific
* building or a specific unit of shelving within a warehouse.
*
* Typical use: Location
*
* @author 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 Utils = require('../utils/utils');
var Epc = require('../epc').Epc;
var Type = require('../type').Type;
var Partition = require('../partition').Partition;
var Sgln96 = /** @class */ (function (_super) {
__extends(Sgln96, _super);
function Sgln96(hexEpc) {
var _this = _super.call(this, Sgln96.TOTAL_BITS) || this;
if (hexEpc) {
_super.prototype.setFromHexString.call(_this, hexEpc);
}
else {
_super.prototype.set.call(_this, Sgln96.EPC_HEADER, Epc.EPC_HEADER_OFFSET, Epc.EPC_HEADER_END);
}
return _this;
}
Sgln96.prototype.clone = function () {
return new Sgln96().setFromBitArray(this);
};
Sgln96.prototype.getType = function () {
return Type.SGLN96;
};
Sgln96.prototype.toTagURI = function () {
var partition = Sgln96.PARTITIONS[this.getPartition()];
return Sgln96.TAG_URI_TEMPLATE(this.getFilter(), this.getSegmentString(partition.a), this.getSegmentString(partition.b), this.getExtension());
};
Sgln96.prototype.toIdURI = function () {
var partition = Sgln96.PARTITIONS[this.getPartition()];
return Sgln96.PID_URI_TEMPLATE(this.getSegmentString(partition.a), this.getSegmentString(partition.b), this.getExtension());
};
Sgln96.prototype.toBarcode = function () {
return this.getGln();
};
Sgln96.prototype.getTotalBits = function () {
return Sgln96.TOTAL_BITS;
};
Sgln96.prototype.getHeader = function () {
return Sgln96.EPC_HEADER;
};
Sgln96.prototype.getPartition = function () {
return _super.prototype.get.call(this, Sgln96.PARTITION_OFFSET, Sgln96.PARTITION_END);
};
Sgln96.prototype.setPartition = function (value) {
if (value < 0 || value >= Sgln96.PARTITIONS.length) {
throw new Error("Value '".concat(value, "' out of range (min: 0, max: ").concat(Sgln96.PARTITIONS.length - 1, ")"));
}
_super.prototype.set.call(this, value, Sgln96.PARTITION_OFFSET, Sgln96.PARTITION_END);
return this;
};
Sgln96.prototype.getGln = function () {
var partition = Sgln96.PARTITIONS[this.getPartition()];
var result = this.getSegmentString(partition.a) + this.getSegmentString(partition.b);
return result + Utils.computeCheckDigit(result);
};
Sgln96.prototype.setGln = function (gln) {
var partition = Sgln96.PARTITIONS[this.getPartition()];
_super.prototype.setSegment.call(this, gln.substring(0, partition.a.digits), partition.a);
_super.prototype.setSegment.call(this, Number(gln.substring(partition.a.digits, partition.a.digits + partition.b.digits)), partition.b);
return this;
};
Sgln96.prototype.getCompany = function () {
return _super.prototype.getSegment.call(this, Sgln96.PARTITIONS[this.getPartition()].a);
};
Sgln96.prototype.setCompany = function (value) {
_super.prototype.setSegment.call(this, value, Sgln96.PARTITIONS[this.getPartition()].a);
return this;
};
Sgln96.prototype.getLocation = function () {
return _super.prototype.getSegment.call(this, Sgln96.PARTITIONS[this.getPartition()].b);
};
Sgln96.prototype.setLocation = function (value) {
_super.prototype.setSegment.call(this, value, Sgln96.PARTITIONS[this.getPartition()].b);
return this;
};
Sgln96.prototype.getExtension = function () {
return _super.prototype.get.call(this, Sgln96.EXTENSION_OFFSET, Sgln96.EXTENSION_END);
};
Sgln96.prototype.setExtension = function (value) {
if (value > Sgln96.MAX_EXTENSION)
throw new Error("Value '".concat(value, "' out of range (min: 0, max: ").concat(Sgln96.MAX_EXTENSION, ")"));
_super.prototype.set.call(this, value, Sgln96.EXTENSION_OFFSET, Sgln96.EXTENSION_END);
return this;
};
Sgln96.EPC_HEADER = 0x32;
Sgln96.TOTAL_BITS = 96;
Sgln96.PARTITION_OFFSET = 11;
Sgln96.PARTITION_END = 14;
Sgln96.EXTENSION_OFFSET = 55;
Sgln96.EXTENSION_END = Sgln96.TOTAL_BITS;
Sgln96.EXTENSION_BITS = 41;
Sgln96.MAX_EXTENSION = Utils.getMaxValue(Sgln96.EXTENSION_BITS); // 274877906943
Sgln96.TAG_URI_TEMPLATE = function (filter, company, location, extension) { return "urn:epc:tag:sgln-96:".concat(filter, ".").concat(company, ".").concat(location, ".").concat(extension); }; // F.C.L.E (Filter, Company, Location, Extension)
Sgln96.PID_URI_TEMPLATE = function (company, location, extension) { return "urn:epc:id:sgln:".concat(company, ".").concat(location, ".").concat(extension); }; // C.L.E (Company, Location, Extension)
// Partition table columns: Company prefix, Location Reference
Sgln96.PARTITIONS = [new Partition(Sgln96.PARTITION_END, 40, 12, 1, 0),
new Partition(Sgln96.PARTITION_END, 37, 11, 4, 1),
new Partition(Sgln96.PARTITION_END, 34, 10, 7, 2),
new Partition(Sgln96.PARTITION_END, 30, 9, 11, 3),
new Partition(Sgln96.PARTITION_END, 27, 8, 14, 4),
new Partition(Sgln96.PARTITION_END, 24, 7, 17, 5),
new Partition(Sgln96.PARTITION_END, 20, 6, 21, 6)]; // 6 20 06 21 6
return Sgln96;
}(Epc));
module.exports = { Sgln96: Sgln96 };