UNPKG

@iotile/iotile-device

Version:

A typescript library for interfacing with IOTile BLE devices

65 lines 2.79 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var utc_assigner_1 = require("../../common/utc-assigner"); var config_1 = require("../../config"); var constants_1 = require("./constants"); function ensureUTCTimestamps(waveforms, reports) { var waveIDMap = createWaveMap(reports); var timeMap = new utc_assigner_1.UTCAssigner({ allowImprecise: true }); timeMap.markAnchorStream(constants_1.START_STREAM, "epoch"); timeMap.markAnchorStream(constants_1.END_STREAM, "epoch"); for (var _i = 0, reports_1 = reports; _i < reports_1.length; _i++) { var report = reports_1[_i]; timeMap.addAnchorsFromReport(report); } for (var waveID in waveforms) { var wave = waveforms[waveID]; if (!(waveID in waveIDMap)) { config_1.catUTCAssigner.warn("Dropping waveform " + waveID + " that was not present in controller reports"); continue; } if (wave.utcTimestamp != null) continue; var readingID = waveIDMap[waveID]; try { wave.utcTimestamp = timeMap.assignUTCTimestamp(readingID, wave.deviceTimestamp); config_1.catUTCAssigner.debug("Assigned " + wave.utcTimestamp + " to waveform id " + waveID + " with controller ID " + readingID); } catch (err) { config_1.catUTCAssigner.warn("Could not assign UTC timestamp to waveform " + waveID + " with controller ID " + readingID + " and timestamp 0x" + wave.deviceTimestamp.toString(16)); } } } exports.ensureUTCTimestamps = ensureUTCTimestamps; function dropNonUTCTimestamps(waveforms) { var dropCount = 0; for (var waveID in waveforms) { var wave = waveforms[waveID]; if (wave.utcTimestamp == null) { delete waveforms[waveID]; dropCount += 1; } } return dropCount; } exports.dropNonUTCTimestamps = dropNonUTCTimestamps; // {x.value: x.reading_id for x in user_report.visible_readings if x.stream == 0x5020} function createWaveMap(reports) { var waveMap = {}; for (var _i = 0, reports_2 = reports; _i < reports_2.length; _i++) { var report = reports_2[_i]; config_1.catUTCAssigner.debug("Adding waveforms from report streamer " + report.streamer + " id range " + report.readingIDRange[0] + ", " + report.readingIDRange[1] + " with " + report.readings.length + " readings."); if (report.streamer == 0) { for (var _a = 0, _b = report.readings; _a < _b.length; _a++) { var reading = _b[_a]; if (reading.stream == 0x5020) { waveMap[reading.value] = reading.id; } } } } return waveMap; } //# sourceMappingURL=utc-reconstruction.js.map