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)); }
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 override float scale(IModuleBoardBridge bridge) { return((bridge.GetModule <IGyroBmi160>() as GyroBmi160).Scale); }
internal string CreateIdentifier(IModuleBoardBridge bridge) { string myIdentifier = null; switch ((Module)eventConfig[0]) { case SWITCH: myIdentifier = "switch"; break; case ACCELEROMETER: { var module = bridge.GetModule <IAccelerometer>(); if (module is AccelerometerMma8452q) { myIdentifier = AccelerometerMma8452q.createIdentifier(this); } else if (module is AccelerometerBmi160) { myIdentifier = AccelerometerBmi160.createIdentifier(this); } else if (module is AccelerometerBma255) { myIdentifier = AccelerometerBosch.createIdentifier(this); } else { myIdentifier = null; } break; } case TEMPERATURE: myIdentifier = string.Format("temperature[{0}]", eventConfig[2]); break; case GPIO: myIdentifier = Gpio.createIdentifier(this); break; case DATA_PROCESSOR: myIdentifier = DataProcessor.createIdentifier(this, bridge.GetModule <IDataProcessor>() as DataProcessor, bridge.getFirmware()); break; case SERIAL_PASSTHROUGH: myIdentifier = SerialPassthrough.createIdentifier(this); break; case SETTINGS: myIdentifier = Settings.createIdentifier(this); break; case BAROMETER: myIdentifier = BarometerBosch.createIdentifier(this); break; case GYRO: myIdentifier = attributes.length() > 2 ? "angular-velocity" : string.Format("angular-velocity[{0}]", (attributes.offset >> 1)); break; case AMBIENT_LIGHT: myIdentifier = "illuminance"; break; case MAGNETOMETER: myIdentifier = attributes.length() > 2 ? "magnetic-field" : string.Format("magnetic-field[{0}]", (attributes.offset >> 1)); break; case HUMIDITY: myIdentifier = "relative-humidity"; break; case COLOR_DETECTOR: myIdentifier = attributes.length() > 2 ? "color" : string.Format("color[{0}]", (attributes.offset >> 1)); break; case PROXIMITY: myIdentifier = "proximity"; break; case SENSOR_FUSION: myIdentifier = SensorFusionBosch.createIdentifier(this); break; } if (myIdentifier == null) { throw new InvalidOperationException("Cannot create identifier string for data type: " + Util.arrayToHexString(eventConfig)); } return((input != null && !input.eventConfig.SequenceEqual(eventConfig) ? input.CreateIdentifier(bridge) + ":" : "") + myIdentifier); }
public override float scale(IModuleBoardBridge bridge) { return((bridge.GetModule <IAccelerometerBosch>() as AccelerometerBosch).DataScale); }
internal BoschMotionDataProducer(DataTypeBase dataTypeBase, IModuleBoardBridge bridge) : base(MOTION_INTERRUPT_ENABLE, 0x0, dataTypeBase, bridge) { accelerometer = bridge.GetModule <IAccelerometerBosch>() as AccelerometerBosch; }
public override void addDataHandler(IModuleBoardBridge bridge) { if (source.eventConfig[2] != DataTypeBase.NO_ID) { bridge.addDataIdHeader(Tuple.Create(source.eventConfig[0], source.eventConfig[1])); } if (dataResponseHandler == null) { Func <Type, object> accounterExtra(uint value) { return(type => { if (type == typeof(uint)) { return value; } return null; }); } if (source.attributes.copies > 1) { byte dataUnitLength = source.attributes.unitLength(); dataResponseHandler = response => { DateTime now = DateTime.Now; var accounter = findParent(bridge.GetModule <IDataProcessor>() as DataProcessor, source, DataProcessor.TYPE_ACCOUNTER); AccountType accountType = accounter != null ? (accounter.Item2.configObj as AccounterConfig).type : AccountType.Time; for (int i = 0, j = source.eventConfig[2] == DataTypeBase.NO_ID ? 2 : 3; i < source.attributes.copies && j < response.Length; i++, j += dataUnitLength) { var account = fillTimestamp(bridge, accounter, response, j); byte[] dataRaw = new byte[dataUnitLength - (account.Item2 - j)]; Array.Copy(response, account.Item2, dataRaw, 0, dataRaw.Length); var data = source.createData(false, bridge, dataRaw, accounter == null || accountType == AccountType.Count ? now : account.Item1); if (accountType == AccountType.Count) { data.extraFn = accounterExtra(account.Item3); } call(data); } }; } else { dataResponseHandler = response => { byte[] dataRaw; if (source.eventConfig[2] == DataTypeBase.NO_ID) { dataRaw = new byte[response.Length - 2]; Array.Copy(response, 2, dataRaw, 0, dataRaw.Length); } else { dataRaw = new byte[response.Length - 3]; Array.Copy(response, 3, dataRaw, 0, dataRaw.Length); } AccountType accountType = AccountType.Time; Tuple <DateTime, int, uint> extra; if (source.eventConfig[0] == (byte)DATA_PROCESSOR && source.eventConfig[1] == DataProcessor.NOTIFY) { var dataprocessor = bridge.GetModule <IDataProcessor>() as DataProcessor; var processor = dataprocessor.lookupProcessor(source.eventConfig[2]); extra = fillTimestamp(bridge, processor, dataRaw, 0); if (extra.Item2 > 0) { byte[] copy = new byte[dataRaw.Length - extra.Item2]; Array.Copy(dataRaw, extra.Item2, copy, 0, copy.Length); dataRaw = copy; accountType = (processor.Item2.configObj as AccounterConfig).type; } } else { extra = Tuple.Create(DateTime.Now, 0, (uint)0); } var packer = findParent(bridge.GetModule <IDataProcessor>() as DataProcessor, source, DataProcessor.TYPE_PACKER); if (packer != null) { byte dataUnitLength = packer.Item2.source.attributes.unitLength(); byte[] unpacked = new byte[dataUnitLength]; for (int i = 0, j = 3 + extra.Item2; i < packer.Item2.source.attributes.copies && j < response.Length; i++, j += dataUnitLength) { Array.Copy(response, j, unpacked, 0, unpacked.Length); var data = source.createData(false, bridge, unpacked, extra.Item1); if (accountType == AccountType.Count) { data.extraFn = accounterExtra(extra.Item3); } call(data); } } else { var data = source.createData(false, bridge, dataRaw, extra.Item1); if (accountType == AccountType.Count) { data.extraFn = accounterExtra(extra.Item3); } call(data); } }; } } bridge.addDataHandler(source.eventConfigAsTuple(), dataResponseHandler); }
public void remove(IModuleBoardBridge bridge, bool sync) { Logging logging = bridge.GetModule <ILogging>() as Logging; orderedIds.ForEach(id => logging.Remove(id, sync)); }
public override void addDataHandler(IModuleBoardBridge bridge) { if (source.eventConfig[2] != DataTypeBase.NO_ID) { bridge.addDataIdHeader(Tuple.Create(source.eventConfig[0], source.eventConfig[1])); } if (dataResponseHandler == null) { if (source.attributes.copies > 1) { byte dataUnitLength = source.attributes.unitLength(); dataResponseHandler = response => { DateTime now = DateTime.Now; Tuple <DataTypeBase, EditorImplBase> accounter = findParent(bridge.GetModule <IDataProcessor>() as DataProcessor, source, DataProcessor.TYPE_ACCOUNTER); for (int i = 0, j = source.eventConfig[2] == DataTypeBase.NO_ID ? 2 : 3; i < source.attributes.copies && j < response.Length; i++, j += dataUnitLength) { Tuple <DateTime, int> account = fillTimestamp(bridge, accounter, response, j); byte[] dataRaw = new byte[dataUnitLength - (account.Item2 - j)]; Array.Copy(response, account.Item2, dataRaw, 0, dataRaw.Length); call(source.createData(false, bridge, dataRaw, accounter == null ? now : account.Item1)); } }; } else { dataResponseHandler = response => { byte[] dataRaw; if (source.eventConfig[2] == DataTypeBase.NO_ID) { dataRaw = new byte[response.Length - 2]; Array.Copy(response, 2, dataRaw, 0, dataRaw.Length); } else { dataRaw = new byte[response.Length - 3]; Array.Copy(response, 3, dataRaw, 0, dataRaw.Length); } Tuple <DateTime, int> account = fillTimestamp(bridge, source, dataRaw); if (account.Item2 > 0) { byte[] copy = new byte[dataRaw.Length - account.Item2]; Array.Copy(dataRaw, account.Item2, copy, 0, copy.Length); dataRaw = copy; } Tuple <DataTypeBase, EditorImplBase> packer = findParent(bridge.GetModule <IDataProcessor>() as DataProcessor, source, DataProcessor.TYPE_PACKER); if (packer != null) { byte dataUnitLength = packer.Item2.source.attributes.unitLength(); byte[] unpacked = new byte[dataUnitLength]; for (int i = 0, j = 3 + account.Item2; i < packer.Item2.source.attributes.copies && j < response.Length; i++, j += dataUnitLength) { Array.Copy(response, j, unpacked, 0, unpacked.Length); call(source.createData(false, bridge, unpacked, account.Item1)); } } else { call(source.createData(false, bridge, dataRaw, account.Item1)); } }; } } bridge.addDataHandler(source.eventConfigAsTuple(), dataResponseHandler); }