timeline-state-resolver
Version:
Have timeline, control stuff
68 lines • 2.08 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ControlCommand = exports.ViscaInquiryCommand = exports.ViscaCommand = exports.AbstractCommand = void 0;
const enums_1 = require("../enums");
class AbstractCommand {
}
exports.AbstractCommand = AbstractCommand;
class ViscaCommand extends AbstractCommand {
constructor() {
super(...arguments);
this.commandType = enums_1.CommandType.ViscaCommand;
}
toIntWithZeroes(n) {
n = n & 0xffff;
let result = 0;
for (let i = 0; i < 4; i++) {
const chunk = (n >> (4 * i)) & 0xf;
result |= chunk << (8 * i + 4);
}
return result >>> 4;
}
toBigIntWithZeroes(n) {
const b = BigInt(n & 0xfffff);
let result = 0n;
for (let i = 0n; i < 5; i++) {
const chunk = (b >> (4n * i)) & 0xfn;
result |= chunk << (8n * i + 4n);
}
return result >> 4n;
}
}
exports.ViscaCommand = ViscaCommand;
class ViscaInquiryCommand extends AbstractCommand {
constructor() {
super(...arguments);
this.commandType = enums_1.CommandType.ViscaInquiry;
}
fromIntWithZeroes(n) {
n = n << 4;
let result = 0;
for (let i = 0; i < 4; i++) {
const chunk = (n >> (8 * i + 4)) & 0xf;
result |= chunk << (4 * i);
}
return result & 0xffff;
}
fromBigIntWithZeroes(x) {
x = x << 4n;
let result = 0n;
for (let i = 0n; i < 5; i++) {
const chunk = (x >> (8n * i + 4n)) & 0xfn;
result |= chunk << (4n * i);
}
return Number(result & 0xfffffn);
}
from2sComplement(x) {
return x & 0x80000 ? x - (1 << 20) : x;
}
}
exports.ViscaInquiryCommand = ViscaInquiryCommand;
class ControlCommand extends AbstractCommand {
constructor() {
super(...arguments);
this.commandType = enums_1.CommandType.ControlCommand;
}
}
exports.ControlCommand = ControlCommand;
//# sourceMappingURL=abstractCommand.js.map