UNPKG

@iotile/iotile-device

Version:

A typescript library for interfacing with IOTile BLE devices

61 lines 2.45 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const utc_assigner_1 = require("../../common/utc-assigner"); const config_1 = require("../../config"); const constants_1 = require("./constants"); function ensureUTCTimestamps(waveforms, reports) { let waveIDMap = createWaveMap(reports); let timeMap = new utc_assigner_1.UTCAssigner({ allowImprecise: true }); timeMap.markAnchorStream(constants_1.START_STREAM, "epoch"); timeMap.markAnchorStream(constants_1.END_STREAM, "epoch"); for (let report of reports) { timeMap.addAnchorsFromReport(report); } for (let waveID in waveforms) { let 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; let 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) { let dropCount = 0; for (let waveID in waveforms) { let wave = waveforms[waveID]; if (wave.utcTimestamp == null) { delete waveforms[waveID]; dropCount += 1; } } return dropCount; } exports.dropNonUTCTimestamps = dropNonUTCTimestamps; function createWaveMap(reports) { let waveMap = {}; for (let report of reports) { 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 (let reading of report.readings) { if (reading.stream == 0x5020) { waveMap[reading.value] = reading.id; } } } } return waveMap; } //# sourceMappingURL=utc-reconstruction.js.map