Beispiel #1
0
        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));
        }
Beispiel #2
0
        internal async Task QueryTimeAsync()
        {
            ///remove
            return;

            queryTimeTask = new TimedTask <bool>();
            await queryTimeTask.Execute("Failed to receive current time tick within {0}ms", bridge.TimeForResponse,
                                        () => bridge.sendCommand(new byte[] { (byte)LOGGING, Util.setRead(TIME) }));
        }
Beispiel #3
0
 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));
 }
Beispiel #4
0
        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()
        {
            readConfigTask = new TimedTask <byte[]>();
            bridge.addRegisterResponseHandler(Tuple.Create((byte)ACCELEROMETER, Util.setRead(DATA_CONFIG)),
                                              response => readConfigTask.SetResult(response));

            if (orientationDataType == null)
            {
                orientationDataType = new Mma8452qOrientationDataType();
            }
        }
Beispiel #6
0
        protected override void init()
        {
            readAdConfigTask   = new TimedTask <byte[]>();
            readConnParamsTask = 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 => readAdConfigTask.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]));
            }
        }
Beispiel #7
0
 protected override void init()
 {
     readConfigTask = new TimedTask <byte[]>();
     bridge.addRegisterResponseHandler(Tuple.Create((byte)GYRO, Util.setRead(CONFIG)), response => readConfigTask.SetResult(response));
 }
Beispiel #8
0
 protected override void init()
 {
     beginMacroTask = new TimedTask <byte>();
     bridge.addRegisterResponseHandler(Tuple.Create((byte)MACRO, BEGIN), response => beginMacroTask.SetResult(response[2]));
 }
Beispiel #9
0
        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));
        }
Beispiel #10
0
 protected override void init()
 {
     createEventTask = new TimedTask <byte>();
     bridge.addRegisterResponseHandler(Tuple.Create((byte)EVENT, ENTRY), response => createEventTask.SetResult(response[2]));
 }
Beispiel #11
0
        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));
 }
 internal ActiveDataProducer(DataTypeBase dataTypeBase, IModuleBoardBridge bridge)  : base(dataTypeBase, bridge)
 {
     readTask = new TimedTask <T>();
 }