public override void disableStream(IModuleBoardBridge bridge) { if ((source.eventConfig[1] & 0x80) == 0x0) { if (source.eventConfig[2] == DataTypeBase.NO_ID) { if (bridge.numDataHandlers(source.eventConfigAsTuple()) == 1) { bridge.sendCommand(new byte[] { source.eventConfig[0], source.eventConfig[1], 0x0 }); } } else { if (bridge.numDataHandlers(source.eventConfigAsTuple()) == 1) { if (source.eventConfig[0] == (byte)DATA_PROCESSOR && source.eventConfig[1] == DataProcessor.NOTIFY) { bridge.sendCommand(new byte[] { source.eventConfig[0], DataProcessor.NOTIFY_ENABLE, source.eventConfig[2], 0x0 }); } } } } else { if (bridge.numDataHandlers(source.eventConfigAsTuple()) == 1) { source.markSilent(); } } bridge.removeDataHandler(source.eventConfigAsTuple(), dataResponseHandler); }
public override void enableStream(IModuleBoardBridge bridge) { addDataHandler(bridge); if ((source.eventConfig[1] & 0x80) == 0x0) { if (source.eventConfig[2] == DataTypeBase.NO_ID) { if (bridge.numDataHandlers(source.eventConfigAsTuple()) == 1) { bridge.sendCommand(new byte[] { source.eventConfig[0], source.eventConfig[1], 0x1 }); } } else { bridge.sendCommand(new byte[] { source.eventConfig[0], source.eventConfig[1], 0x1 }); if (bridge.numDataHandlers(source.eventConfigAsTuple()) == 1) { if (source.eventConfig[0] == (byte)DATA_PROCESSOR && source.eventConfig[1] == DataProcessor.NOTIFY) { bridge.sendCommand(new byte[] { source.eventConfig[0], DataProcessor.NOTIFY_ENABLE, source.eventConfig[2], 0x1 }); } } } } else { source.markLive(); } }
internal GpioVirtualPin(DataTypeBase adc, DataTypeBase absRef, byte pin, IModuleBoardBridge bridge) { adcType = adc; absRefType = absRef; this.pin = pin; this.bridge = bridge; }
internal void handleLogMessage(IModuleBoardBridge bridge, byte logId, DateTime timestamp, byte[] data, Action <LogDownloadError, byte, DateTime, byte[]> errorHandler) { if (handler == null) { errorHandler?.Invoke(LogDownloadError.UNHANDLED_LOG_DATA, logId, timestamp, data); return; } if (logEntries.TryGetValue(logId, out var logEntry)) { logEntry.Enqueue(data); } else { errorHandler?.Invoke(LogDownloadError.UNKNOWN_LOG_ENTRY, logId, timestamp, data); } if (logEntries.Values.Aggregate(true, (acc, e) => acc && e.Count != 0)) { byte[] merged = new byte[source.attributes.length()]; int offset = 0; orderedIds.Aggregate(new List <byte[]>(), (acc, id) => { logEntries.TryGetValue(id, out var cached); acc.Add(cached.Dequeue()); return(acc); }).ForEach(entry => { Array.Copy(entry, 0, merged, offset, Math.Min(entry.Length, source.attributes.length() - offset)); offset += entry.Length; }); call(source.createData(true, bridge, merged, timestamp)); } }
internal DataBase(IModuleBoardBridge bridge, DataTypeBase datatype, DateTime timestamp, byte[] bytes) { this.timestamp = timestamp; this.bytes = bytes; this.bridge = bridge; this.datatype = datatype; }
internal override void restoreTransientVars(IModuleBoardBridge bridge) { foreach (GpioPin it in pins) { it.restoreTransientVars(bridge); } }
internal override void restoreTransientVars(IModuleBoardBridge bridge) { foreach (TemperatureSensor it in sensors) { it.restoreTransientVars(bridge); } }
public Temperature(IModuleBoardBridge bridge) : base(bridge) { var info = bridge.lookupModuleInfo(TEMPERATURE); byte i = 0; sensors = new List <ISensor>(); tempDataTypes = new List <DataTypeBase>(); foreach (byte it in info.extra) { var dataType = new TemperatureFloatData(i); tempDataTypes.Add(dataType); switch (it) { case (byte)SensorType.NrfSoc: sensors.Add(new TemperatureSensor(SensorType.NrfSoc, dataType, bridge)); break; case (byte)SensorType.ExtThermistor: sensors.Add(new ExternalThermistor(dataType, bridge)); break; case (byte)SensorType.BoschEnv: sensors.Add(new TemperatureSensor(SensorType.BoschEnv, dataType, bridge)); break; case (byte)SensorType.PresetThermistor: sensors.Add(new TemperatureSensor(SensorType.PresetThermistor, dataType, bridge)); break; } i++; } }
private static Tuple <DateTime, int> fillTimestamp(IModuleBoardBridge bridge, DataTypeBase source, byte[] response) { if (source.eventConfig[0] == (byte)DATA_PROCESSOR && source.eventConfig[1] == DataProcessor.NOTIFY) { var dataprocessor = bridge.GetModule <IDataProcessor>() as DataProcessor; return(fillTimestamp(bridge, dataprocessor.lookupProcessor(source.eventConfig[2]), response, 0)); } return(Tuple.Create(DateTime.Now, 0)); }
internal override void restoreTransientVars(IModuleBoardBridge bridge) { base.restoreTransientVars(bridge); foreach (Tuple <DataTypeBase, EditorImplBase> it in activeProcessors.Values) { it.Item2.restoreTransientVars(bridge); } }
internal override void restoreTransientVars(IModuleBoardBridge bridge) { base.restoreTransientVars(bridge); foreach (DeviceDataConsumer it in consumers) { it.addDataHandler(bridge); } }
public AccelerometerBosch(IModuleBoardBridge bridge) : base(bridge) { accDataType = new BoschCartesianFloatData(DATA_INTERRUPT, 1); packedAccDataType = new BoschCartesianFloatData(PACKED_ACC_DATA, 3); orientationDataType = new BoschOrientationDataType(); flatDataType = new BoschFlatDataType(); tapDataType = new BoschTapDataType(); lowHighDataType = new BoschLowHighGDataType(); motionDataType = new BoschMotionDataType(); }
public void read(IModuleBoardBridge bridge, byte[] parameters) { int length = (eventConfig[2] == NO_ID ? 2 : 3); byte[] cmd = new byte[parameters.Length + length]; Array.Copy(eventConfig, 0, cmd, 0, length); Array.Copy(parameters, 0, cmd, length, parameters.Length); bridge.sendCommand(cmd); }
public SensorFusionBosch(IModuleBoardBridge bridge) : base(bridge) { corrAccType = new CorrectedAccelerationDataType(); corrAngVelType = new CorrectedAngularVelocityDataType(); corrBFieldType = new CorrectedBFieldDataType(); quaternionType = new QuaternionDataType(); eulerAnglesType = new EulerAnglesDataType(); gravityType = new FusedAccelerationDataType(GRAVITY_VECTOR); linAccType = new FusedAccelerationDataType(LINEAR_ACC); }
public PatternEditor(IModuleBoardBridge bridge, Color color) { this.bridge = bridge; command[0] = (byte)Module.LED; command[1] = CONFIG; command[2] = (byte)color; command[3] = 0x2; Count(0xff); }
public void read(IModuleBoardBridge bridge) { if (eventConfig[2] == NO_ID) { bridge.sendCommand(new byte[] { eventConfig[0], eventConfig[1] }); } else { bridge.sendCommand(eventConfig); } }
internal override void restoreTransientVars(IModuleBoardBridge bridge) { base.restoreTransientVars(bridge); foreach (var it in activeTasks) { if (it != null) { it.restoreTransientVars(bridge); } } }
public Gpio(IModuleBoardBridge bridge) : base(bridge) { var info = bridge.lookupModuleInfo(GPIO); pins = new List <IPin>(); byte pin = 0; foreach (byte it in info.extra) { pins.Add(new GpioPin(it, pin, bridge)); pin++; } }
internal override void restoreTransientVars(IModuleBoardBridge bridge) { base.restoreTransientVars(bridge); foreach (var it in i2cProducers) { it.Value.restoreTransientVars(bridge); } foreach (var it in spiProducers) { it.Value.restoreTransientVars(bridge); } }
internal GpioPin(byte mask, byte pin, IModuleBoardBridge bridge) : base(bridge) { this.mask = mask; this.pin = pin; if ((mask & 0x2) == 0x2) { adc = new IntegralDataType(GPIO, Util.setRead(READ_AI_ADC), pin, new DataAttributes(new byte[] { 2 }, 1, 0, false)); absRef = new MilliUnitsFloatDataType(GPIO, Util.setRead(READ_AI_ABS_REF), pin, new DataAttributes(new byte[] { 2 }, 1, 0, false)); } if ((mask & 0x1) == 0x1) { digital = new IntegralDataType(GPIO, Util.setRead(READ_DI), pin, new DataAttributes(new byte[] { 1 }, 1, 0, false)); monitor = new IntegralDataType(GPIO, PIN_CHANGE_NOTIFY, pin, new DataAttributes(new byte[] { 1 }, 1, 0, false)); } }
private static Tuple <DateTime, int, uint> fillTimestamp(IModuleBoardBridge bridge, Tuple <DataTypeBase, EditorImplBase> accounter, byte[] response, int offset) { if (accounter != null) { byte[] config = accounter.Item2.config; if (config[0] == DataProcessor.TYPE_ACCOUNTER) { var configObj = accounter.Item2.configObj as AccounterConfig; var logging = bridge.GetModule <ILogging>() as Logging; uint tick = BitConverter.ToUInt32(response, offset); return(Tuple.Create(logging.computeTimestamp(0xff, tick), configObj.length + offset, tick)); } } return(Tuple.Create(DateTime.Now, offset, (uint)0)); }
public MetaWearBoard(IBluetoothLeGatt gatt, ILibraryIO io) { this.gatt = gatt; this.io = io; InMetaBootMode = false; bridge = new ModuleBoardBridge(this); gatt.OnDisconnect = unexpected => { foreach (var it in persistent.modules.Values) { (it as ModuleImplBase).disconnected(); } if (unexpected && OnUnexpectedDisconnect != null) { OnUnexpectedDisconnect(); } }; }
public Settings(IModuleBoardBridge bridge) : base(bridge) { var info = bridge.lookupModuleInfo(SETTINGS); if (info.revision >= DISCONNECTED_EVENT_REVISION) { disconnectDummyProducer = new IntegralDataType(SETTINGS, DISCONNECT_EVENT, new DataAttributes(new byte[] { }, 0, 0, false)); } if (info.revision >= BATTERY_REVISION) { batteryState = new BatteryStateDataType(); } if (info.revision >= CHARGE_STATUS_REVISION && (info.extra.Length > 0 && (info.extra[0] & 0x1) == 0x1)) { powerStatus = new IntegralDataType(SETTINGS, POWER_STATUS, new DataAttributes(new byte[] { 1 }, 1, 0, false)); } if (info.revision >= CHARGE_STATUS_REVISION && (info.extra.Length > 0 && (info.extra[0] & 0x2) == 0x2)) { chargeStatus = new IntegralDataType(SETTINGS, CHARGE_STATUS, new DataAttributes(new byte[] { 1 }, 1, 0, false)); } }
public override IData createData(bool logData, IModuleBoardBridge bridge, byte[] data, DateTime timestamp) { return(new AccelerationFloatData(bridge, this, timestamp, data)); }
public AccelerationFloatData(IModuleBoardBridge bridge, DataTypeBase datatype, DateTime timestamp, byte[] bytes) : base(bridge, datatype, timestamp, bytes) { }
public override IData createData(bool logData, IModuleBoardBridge bridge, byte[] data, DateTime timestamp) { return(new EulerAnglesData(bridge, this, timestamp, data)); }
public SensorFusionBosch(IModuleBoardBridge bridge) : base(bridge) { }
internal SensorFusionAsyncDataProducer(DataTypeBase datatype, byte mask, IModuleBoardBridge bridge) : base(datatype, bridge) { this.mask = mask; }
public override float scale(IModuleBoardBridge bridge) { return(1000000f); }
public override IData createData(bool logData, IModuleBoardBridge bridge, byte[] data, DateTime timestamp) { return(new CorrectedMagneticFieldData(bridge, this, timestamp, data)); }