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();
            }
        }
Ejemplo n.º 3
0
 internal GpioVirtualPin(DataTypeBase adc, DataTypeBase absRef, byte pin, IModuleBoardBridge bridge)
 {
     adcType     = adc;
     absRefType  = absRef;
     this.pin    = pin;
     this.bridge = bridge;
 }
Ejemplo n.º 4
0
        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));
            }
        }
Ejemplo n.º 5
0
 internal DataBase(IModuleBoardBridge bridge, DataTypeBase datatype, DateTime timestamp, byte[] bytes)
 {
     this.timestamp = timestamp;
     this.bytes     = bytes;
     this.bridge    = bridge;
     this.datatype  = datatype;
 }
Ejemplo n.º 6
0
 internal override void restoreTransientVars(IModuleBoardBridge bridge)
 {
     foreach (GpioPin it in pins)
     {
         it.restoreTransientVars(bridge);
     }
 }
Ejemplo n.º 7
0
 internal override void restoreTransientVars(IModuleBoardBridge bridge)
 {
     foreach (TemperatureSensor it in sensors)
     {
         it.restoreTransientVars(bridge);
     }
 }
Ejemplo n.º 8
0
        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++;
            }
        }
Ejemplo n.º 9
0
 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));
 }
Ejemplo n.º 10
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);
                }
            }
Ejemplo n.º 12
0
 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();
 }
Ejemplo n.º 13
0
        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);
 }
Ejemplo n.º 15
0
            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);
            }
Ejemplo n.º 16
0
 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);
                    }
                }
            }
Ejemplo n.º 18
0
        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++;
            }
        }
Ejemplo n.º 19
0
        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);
            }
        }
Ejemplo n.º 20
0
            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();
                }
            };
        }
Ejemplo n.º 23
0
        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));
            }
        }
Ejemplo n.º 24
0
 public override IData createData(bool logData, IModuleBoardBridge bridge, byte[] data, DateTime timestamp)
 {
     return(new AccelerationFloatData(bridge, this, timestamp, data));
 }
Ejemplo n.º 25
0
 public AccelerationFloatData(IModuleBoardBridge bridge, DataTypeBase datatype, DateTime timestamp, byte[] bytes) :
     base(bridge, datatype, timestamp, bytes)
 {
 }
Ejemplo n.º 26
0
 public override IData createData(bool logData, IModuleBoardBridge bridge, byte[] data, DateTime timestamp)
 {
     return(new EulerAnglesData(bridge, this, timestamp, data));
 }
Ejemplo n.º 27
0
 public SensorFusionBosch(IModuleBoardBridge bridge) : base(bridge)
 {
 }
Ejemplo n.º 28
0
 internal SensorFusionAsyncDataProducer(DataTypeBase datatype, byte mask, IModuleBoardBridge bridge) : base(datatype, bridge)
 {
     this.mask = mask;
 }
Ejemplo n.º 29
0
 public override float scale(IModuleBoardBridge bridge)
 {
     return(1000000f);
 }
Ejemplo n.º 30
0
 public override IData createData(bool logData, IModuleBoardBridge bridge, byte[] data, DateTime timestamp)
 {
     return(new CorrectedMagneticFieldData(bridge, this, timestamp, data));
 }