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
 public void read(IModuleBoardBridge bridge)
 {
     if (eventConfig[2] == NO_ID)
     {
         bridge.sendCommand(new byte[] { eventConfig[0], eventConfig[1] });
     }
     else
     {
         bridge.sendCommand(eventConfig);
     }
 }
Ejemplo n.º 4
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);
        }
        private async Task createRouteAsync(bool ready)
        {
            if (pendingRoutes.Count != 0 && (ready || pendingRoutes.Count == 1))
            {
                var top = pendingRoutes.Peek();

                try
                {
                    top.Item1(top.Item2);
                    foreach (var entry in top.Item2.state.namedProcessors)
                    {
                        if (persistent.namedProducers.ContainsKey(entry.Key))
                        {
                            throw new IllegalRouteOperationException(string.Format("Duplicate producer name present: '{0}'", entry.Key));
                        }
                        persistent.namedProducers.Add(entry.Key, entry.Value.Item2.source);
                    }

                    Queue <byte> dataProcIds = null;
                    if (persistent.modules.TryGetValue(typeof(IDataProcessor).FullName, out var module))
                    {
                        DataProcessor dataProc = module as DataProcessor;
                        dataProcIds = await dataProc.queueDataProcessors(top.Item2.state.dataProcessors);

                        foreach (var entry in top.Item2.state.namedProcessors)
                        {
                            if (entry.Value.Item2.source.eventConfig[0] == (byte)DATA_PROCESSOR)
                            {
                                dataProc.nameToId.Add(entry.Key, entry.Value.Item2.source.eventConfig[2]);
                            }
                        }
                    }

                    Queue <LoggedDataConsumer> logConsumers = null;
                    if (persistent.modules.TryGetValue(typeof(ILogging).FullName, out module))
                    {
                        logConsumers = await(module as Logging).CreateLoggersAsync(top.Item2.state.subscribedProducers
                                                                                   .FindAll(p => p.Item3)
                                                                                   .Aggregate(new Queue <DataTypeBase>(), (acc, e) =>
                        {
                            acc.Enqueue(e.Item1);
                            return(acc);
                        })
                                                                                   );
                    }

                    Queue <byte> eventIds = null;
                    if (persistent.modules.TryGetValue(typeof(Event).FullName, out module))
                    {
                        Event eventModule = module as Event;

                        var eventCodeBlocks = top.Item2.state.feedback.Aggregate(new Queue <Tuple <DataTypeBase, Action> >(), (acc, e) =>
                        {
                            if (!persistent.namedProducers.ContainsKey(e.Item1))
                            {
                                throw new IllegalRouteOperationException("\'" + e.Item1 + "\' is not associated with any data producer or named component");
                            }
                            var source = persistent.namedProducers[e.Item1];
                            acc.Enqueue(Tuple.Create <DataTypeBase, Action>(source, () => bridge.sendCommand(e.Item3, source, DATA_PROCESSOR, DataProcessor.PARAMETER, e.Item2.eventConfig[2], e.Item4)));

                            return(acc);
                        });
                        top.Item2.state.reactions.ForEach(e => eventCodeBlocks.Enqueue(Tuple.Create <DataTypeBase, Action>(e.Item1, () => e.Item2(e.Item1))));

                        eventIds = await eventModule.queueEvents(eventCodeBlocks);
                    }

                    List <DeviceDataConsumer> consumers = new List <DeviceDataConsumer>();
                    top.Item2.state.subscribedProducers.ForEach(producer =>
                    {
                        if (logConsumers != null && producer.Item3)
                        {
                            var logger        = logConsumers.Dequeue();
                            logger.subscriber = producer.Item2;
                            consumers.Add(logger);
                        }
                        else
                        {
                            StreamedDataConsumer newConsumer = new StreamedDataConsumer(producer.Item1, producer.Item2);
                            newConsumer.enableStream(bridge);
                            consumers.Add(newConsumer);
                        }
                    });

                    pendingRoutes.Dequeue();

                    Route newRoute = new Route(persistent.id, consumers, dataProcIds, eventIds,
                                               top.Item2.state.namedProcessors.Count != 0 ? new List <string>(top.Item2.state.namedProcessors.Keys) : null, bridge);
                    persistent.activeRoutes.Add(persistent.id, newRoute);
                    persistent.id++;

                    top.Item3.SetResult(newRoute);
                }
                catch (Exception e)
                {
                    pendingRoutes.Dequeue();
                    top.Item3.SetException(e);
                }
                finally
                {
                    await createRouteAsync(true);
                }
            }
        }
Ejemplo n.º 6
0
 public void Commit()
 {
     bridge.sendCommand(command);
 }