protected override void init() { base.init(); readConfigTask = new TimedTask <byte[]>(); bridge.addRegisterResponseHandler(Tuple.Create((byte)ACCELEROMETER, Util.setRead(DATA_CONFIG)), response => readConfigTask.SetResult(response)); }
protected override void init() { readConfigTask = new TimedTask <byte[]>(); bridge.addRegisterResponseHandler(Tuple.Create((byte)ACCELEROMETER, Util.setRead(DATA_CONFIG)), response => readConfigTask.SetResult(response)); if (orientationDataType == null) { orientationDataType = new Mma8452qOrientationDataType(); } }
protected override void init() { readConfigTask = new TimedTask <byte[]>(); bridge.addRegisterResponseHandler(Tuple.Create((byte)GYRO, Util.setRead(CONFIG)), response => readConfigTask.SetResult(response)); }
protected override void init() { beginMacroTask = new TimedTask <byte>(); bridge.addRegisterResponseHandler(Tuple.Create((byte)MACRO, BEGIN), response => beginMacroTask.SetResult(response[2])); }
protected override void init() { spiReadTask = new TimedTask <byte[]>(); i2cReadTask = new TimedTask <byte[]>(); bridge.addDataIdHeader(Tuple.Create((byte)SERIAL_PASSTHROUGH, Util.setRead(I2C_RW))); bridge.addDataHandler(Tuple.Create((byte)SERIAL_PASSTHROUGH, Util.setRead(I2C_RW), DIRECT_I2C_READ_ID), response => i2cReadTask.SetResult(response)); bridge.addDataIdHeader(Tuple.Create((byte)SERIAL_PASSTHROUGH, Util.setRead(SPI_RW))); bridge.addDataHandler(Tuple.Create((byte)SERIAL_PASSTHROUGH, Util.setRead(SPI_RW), DIRECT_SPI_READ_ID), response => spiReadTask.SetResult(response)); }
protected override void init() { queryLogConfigTask = new TimedTask <byte[]>(); createLoggerTask = new TimedTask <byte>(); queryEntriesTask = new TimedTask <byte[]>(); bridge.addRegisterResponseHandler(Tuple.Create((byte)LOGGING, Util.setRead(TRIGGER)), response => queryLogConfigTask.SetResult(response)); bridge.addRegisterResponseHandler(Tuple.Create((byte)LOGGING, TRIGGER), response => createLoggerTask.SetResult(response[2])); bridge.addRegisterResponseHandler(Tuple.Create((byte)LOGGING, READOUT_NOTIFY), response => { void processLogData(byte[] logEntry, int offset) { byte logId = (byte)(logEntry[0 + offset] & 0x1f), resetUid = (byte)((logEntry[0 + offset] & ~0x1f) >> 5); uint tick = BitConverter.ToUInt32(logEntry, 1 + offset); if (!rollbackTimestamps.TryGetValue(resetUid, out uint rollback) || rollback < tick) { var timestamp = computeTimestamp(resetUid, tick); byte[] logData = new byte[LOG_ENTRY_SIZE]; Array.Copy(logEntry, 5 + offset, logData, 0, LOG_ENTRY_SIZE); if (dataLoggers.TryGetValue(logId, out var logger)) { logger.handleLogMessage(bridge, logId, timestamp, logData, errorHandler); } else { errorHandler?.Invoke(LogDownloadError.UNKNOWN_LOG_ENTRY, logId, timestamp, logData); } } }; processLogData(response, 2); if (response.Length == 20) { processLogData(response, 11); } }); bridge.addRegisterResponseHandler(Tuple.Create((byte)LOGGING, Util.setRead(TIME)), response => { // if in the middle of a log download, don't update the reference // rollbackTimestamps var is cleared after readout progress hits 0 if (rollbackTimestamps.Count == 0) { uint tick = BitConverter.ToUInt32(response, 2); byte resetUid = (response.Length > 6) ? response[6] : (byte)0xff; latestReference = new TimeReference { resetUid = resetUid, tick = tick, timestamp = DateTime.Now }; if (resetUid != 0xff) { logReferenceTicks[resetUid] = latestReference; } } if (queryTimeTask != null) { queryTimeTask.SetResult(true); queryTimeTask = null; } }); bridge.addRegisterResponseHandler(Tuple.Create((byte)LOGGING, Util.setRead(LENGTH)), response => queryEntriesTask.SetResult(response)); }
protected override void init() { createProcessorTask = new TimedTask <byte>(); pullProcessorConfigTask = new TimedTask <byte[]>(); stateDataProducers = new Dictionary <string, IForcedDataProducer>(); bridge.addRegisterResponseHandler(Tuple.Create((byte)DATA_PROCESSOR, ADD), response => createProcessorTask.SetResult(response[2])); bridge.addRegisterResponseHandler(Tuple.Create((byte)DATA_PROCESSOR, Util.setRead(ADD)), response => pullProcessorConfigTask.SetResult(response)); }
protected override void init() { readValueTask = new TimedTask <byte[]>(); foreach (var _ in new byte[] { MODE, CALIBRATION_STATUS, ACC_CALIB_DATA, GYRO_CALIB_DATA, MAG_CALIB_DATA }) { bridge.addRegisterResponseHandler(Tuple.Create((byte)SENSOR_FUSION, Util.setRead(_)), response => readValueTask.SetResult(response)); } }
protected override void init() { createEventTask = new TimedTask <byte>(); bridge.addRegisterResponseHandler(Tuple.Create((byte)EVENT, ENTRY), response => createEventTask.SetResult(response[2])); }
protected override void init() { queryLogConfigTask = new TimedTask <byte[]>(); createLoggerTask = new TimedTask <byte>(); if (rollbackTimestamps == null) { rollbackTimestamps = new Dictionary <byte, uint>(); } bridge.addRegisterResponseHandler(Tuple.Create((byte)LOGGING, Util.setRead(TRIGGER)), response => queryLogConfigTask.SetResult(response)); bridge.addRegisterResponseHandler(Tuple.Create((byte)LOGGING, TRIGGER), response => createLoggerTask.SetResult(response[2])); bridge.addRegisterResponseHandler(Tuple.Create((byte)LOGGING, READOUT_NOTIFY), response => { processLogData(response, 2); if (response.Length == 20) { processLogData(response, 11); } }); bridge.addRegisterResponseHandler(Tuple.Create((byte)LOGGING, READOUT_PROGRESS), response => { uint nEntriesLeft = BitConverter.ToUInt32(response, 2); if (nEntriesLeft == 0) { rollbackTimestamps.Clear(); downloadTask.SetResult(true); downloadTask = null; } else { updateHandler?.Invoke(nEntriesLeft, nLogEntries); } }); bridge.addRegisterResponseHandler(Tuple.Create((byte)LOGGING, Util.setRead(TIME)), response => { // if in the middle of a log download, don't update the reference // rollbackTimestamps var is cleared after readout progress hits 0 if (rollbackTimestamps.Count == 0) { uint tick = BitConverter.ToUInt32(response, 2); byte resetUid = (response.Length > 6) ? response[6] : (byte)0xff; latestReference = new TimeReference(resetUid, tick, DateTime.Now); if (resetUid != 0xff) { logReferenceTicks[resetUid] = latestReference; } } if (queryTimeTask != null) { queryTimeTask.SetResult(true); queryTimeTask = null; } }); bridge.addRegisterResponseHandler(Tuple.Create((byte)LOGGING, Util.setRead(LENGTH)), response => { int payloadSize = response.Length - 2; nLogEntries = BitConverter.ToUInt32(response, 2); if (nLogEntries == 0) { rollbackTimestamps.Clear(); downloadTask.SetResult(true); downloadTask = null; } else { updateHandler?.Invoke(nLogEntries, nLogEntries); uint nEntriesNotify = nUpdates == 0 ? 0 : (uint)(nLogEntries * (1.0 / nUpdates)); // In little endian, [A, B, 0, 0] is equal to [A, B] byte[] command = new byte[payloadSize + sizeof(uint)]; Array.Copy(response, 2, command, 0, payloadSize); Array.Copy(BitConverter.GetBytes(nEntriesNotify), 0, command, payloadSize, sizeof(uint)); bridge.sendCommand(LOGGING, READOUT, command); } }); if (bridge.lookupModuleInfo(LOGGING).revision >= REVISION_EXTENDED_LOGGING) { bridge.addRegisterResponseHandler(Tuple.Create((byte)LOGGING, READOUT_PAGE_COMPLETED), response => bridge.sendCommand(new byte[] { (byte)LOGGING, READOUT_PAGE_CONFIRM })); } }
protected override void init() { readValueTask = new TimedTask <byte[]>(); bridge.addRegisterResponseHandler(Tuple.Create((byte)SENSOR_FUSION, Util.setRead(MODE)), response => readValueTask.SetResult(response)); bridge.addRegisterResponseHandler(Tuple.Create((byte)SENSOR_FUSION, Util.setRead(CALIBRATION_STATUS)), response => readValueTask.SetResult(response)); }
protected override void init() { readAdConfigTask = new TimedTask <byte[]>(); readConnParamsTask = new TimedTask <byte[]>(); readTxPowerTask = new TimedTask <byte[]>(); bridge.addRegisterResponseHandler(Tuple.Create((byte)SETTINGS, Util.setRead(DEVICE_NAME)), response => readAdConfigTask.SetResult(response)); bridge.addRegisterResponseHandler(Tuple.Create((byte)SETTINGS, Util.setRead(TX_POWER)), response => readTxPowerTask.SetResult(response)); bridge.addRegisterResponseHandler(Tuple.Create((byte)SETTINGS, Util.setRead(SCAN_RESPONSE)), response => readAdConfigTask.SetResult(response)); bridge.addRegisterResponseHandler(Tuple.Create((byte)SETTINGS, Util.setRead(AD_INTERVAL)), response => readAdConfigTask.SetResult(response)); if (bridge.lookupModuleInfo(SETTINGS).revision >= CONN_PARAMS_REVISION) { bridge.addRegisterResponseHandler(Tuple.Create((byte)SETTINGS, Util.setRead(CONNECTION_PARAMS)), response => readConnParamsTask.SetResult(response)); } if (bridge.lookupModuleInfo(SETTINGS).revision >= CHARGE_STATUS_REVISION) { bridge.addRegisterResponseHandler(Tuple.Create((byte)SETTINGS, Util.setRead(POWER_STATUS)), response => powerStatusProducer.SetReadResult(response[2])); bridge.addRegisterResponseHandler(Tuple.Create((byte)SETTINGS, Util.setRead(CHARGE_STATUS)), response => chargeStatusProducer.SetReadResult(response[2])); } }
protected override void init() { readConfigTask = new TimedTask <byte[]>(); bridge.addRegisterResponseHandler(Tuple.Create((byte)IBEACON, Util.setRead(AD_UUID)), response => readConfigTask.SetResult(response)); bridge.addRegisterResponseHandler(Tuple.Create((byte)IBEACON, Util.setRead(MAJOR)), response => readConfigTask.SetResult(response)); bridge.addRegisterResponseHandler(Tuple.Create((byte)IBEACON, Util.setRead(MINOR)), response => readConfigTask.SetResult(response)); bridge.addRegisterResponseHandler(Tuple.Create((byte)IBEACON, Util.setRead(RX)), response => readConfigTask.SetResult(response)); bridge.addRegisterResponseHandler(Tuple.Create((byte)IBEACON, Util.setRead(TX)), response => readConfigTask.SetResult(response)); bridge.addRegisterResponseHandler(Tuple.Create((byte)IBEACON, Util.setRead(PERIOD)), response => readConfigTask.SetResult(response)); }
protected override void init() { dcTaskSource = null; readTmpValueTask = new TimedTask <byte[]>(); bridge.addRegisterResponseHandler(Tuple.Create((byte)DEBUG, Util.setRead(TMP_VALUE)), response => readTmpValueTask.SetResult(response)); }
internal void SetReadResult(T result) { readTask.SetResult(result); }