@robotical/roboticaljs
Version:
Javascript/TS library for Robotical products
81 lines • 3.58 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const raftjs_1 = require("@robotical/raftjs");
const StateInfoGeneric_1 = require("./StateInfoGeneric");
const raftjs_2 = require("@robotical/raftjs");
const SUBSCRIBE_BINARY_MSGS = false;
class SystemTypeGeneric {
constructor() {
this.nameForDialogs = "Generic System";
this.defaultWiFiHostname = "Generic";
this.firmwareDestName = "ricfw";
this.normalFileDestName = "fs";
this.connectorOptions = { wsSuffix: "wsjson", bleConnItvlMs: 50 };
this.BLEServiceUUIDs = ["aa76677e-9cfd-4626-a510-0d305be57c8d", "da903f65-d5c2-4f4d-a065-d1aade7af874"];
this.BLECmdUUID = "aa76677e-9cfd-4626-a510-0d305be57c8e";
this.BLERespUUID = "aa76677e-9cfd-4626-a510-0d305be57c8f";
// Event handler
this._onEvent = null;
// Raft system utils
this._systemUtils = null;
// Device manager
this._deviceManager = new raftjs_2.RaftDeviceManager();
// Latest data from servos, IMU, etc
this._stateInfo = new StateInfoGeneric_1.StateInfoGeneric(this._deviceManager);
// Subscribe for updates
this.subscribeForUpdates = async (systemUtils, enable) => {
// Subscription rate
const subscribeRateHz = 0.1;
try {
const topic = SUBSCRIBE_BINARY_MSGS ? "devbin" : "devjson";
const subscribeDisable = '{"cmdName":"subscription","action":"update",' +
'"pubRecs":[' +
`{"name":"${topic}","rateHz":0,}` +
']}';
const subscribeEnable = '{"cmdName":"subscription","action":"update",' +
'"pubRecs":[' +
`{"name":"${topic}","trigger":"timeorchange","rateHz":${subscribeRateHz.toString()}}` +
']}';
const msgHandler = systemUtils.getMsgHandler();
const ricResp = await msgHandler.sendRICRESTCmdFrame(enable ? subscribeEnable : subscribeDisable);
// Debug
raftjs_1.RaftLog.debug(`subscribe enable/disable returned ${JSON.stringify(ricResp)}`);
}
catch (error) {
raftjs_1.RaftLog.warn(`getRICCalibInfo Failed subscribe for updates ${error}`);
}
};
// Get device manager
this.deviceMgrIF = this._deviceManager;
}
// Setup
setup(systemUtils, onEvent) {
this._systemUtils = systemUtils;
this._onEvent = onEvent;
this._deviceManager.setup(systemUtils);
}
getStateInfo() {
return this._stateInfo;
}
// Invalidate state
stateIsInvalid() { }
;
// Other message type
rxOtherMsgType(payload, frameTimeMs) {
// RICLog.debug(`rxOtherMsgType payload ${RaftUtils.bufferToHex(payload)}`);
raftjs_1.RaftLog.verbose(`rxOtherMsgType payloadLen ${payload.length}`);
const topicIDs = this._stateInfo.updateFromMsg(payload, frameTimeMs, SUBSCRIBE_BINARY_MSGS);
// Call event handler if registered
if (this._onEvent) {
this._onEvent("pub", raftjs_1.RaftPublishEvent.PUBLISH_EVENT_DATA, raftjs_1.RaftPublishEventNames[raftjs_1.RaftPublishEvent.PUBLISH_EVENT_DATA], {
topicIDs: topicIDs,
payload: payload,
frameTimeMs: frameTimeMs,
isBinary: SUBSCRIBE_BINARY_MSGS
});
}
}
;
}
exports.default = SystemTypeGeneric;
//# sourceMappingURL=SystemTypeGeneric.js.map