예제 #1
0
        public IRouteComponent Filter(Comparison op, ComparisonOutput output, params float[] references)
        {
            if (source.attributes.length() > 4)
            {
                throw new IllegalRouteOperationException("Cannot compare data longer than 4 bytes");
            }

            if (source.attributes.length() <= 0)
            {
                throw new IllegalRouteOperationException("Cannot compare null data");
            }

            if (source.eventConfig[0] == (byte)SENSOR_FUSION)
            {
                throw new IllegalRouteOperationException("Cannot compare sensor sensor fusion data");
            }

            if (state.bridge.getFirmware().CompareTo(MULTI_COMPARISON_MIN_FIRMWARE) < 0)
            {
                float scaledReference      = references[0] * source.scale(state.bridge);
                DataProcessorConfig config = new SingleValueComparisonConfig(source.attributes.signed, op, (int)scaledReference);
                var next = source.transform(config, state.bridge.GetModule <IDataProcessor>() as DataProcessor);

                return(postCreate(next.Item2, new SingleValueComparatorEditor(config, next.Item1, state.bridge)));
            }

            bool anySigned = false;

            foreach (float it in references)
            {
                anySigned |= it < 0;
            }
            bool signed = source.attributes.signed || anySigned;

            {
                DataProcessorConfig config = new MultiValueComparisonConfig(signed, source.attributes.length(), op, output,
                                                                            MultiValueComparatorEditor.fillReferences(source.scale(state.bridge), source, references));
                var next = source.transform(config, state.bridge.GetModule <IDataProcessor>() as DataProcessor);

                return(postCreate(next.Item2, new MultiValueComparatorEditor(config, next.Item1, state.bridge)));
            }
        }
        public IRouteComponent Filter(Comparison op, ComparisonOutput output, params float[] references)
        {
            if (source.attributes.length() > 4)
            {
                throw new IllegalRouteOperationException("Cannot compare data longer than 4 bytes");
            }

            if (source.attributes.length() <= 0)
            {
                throw new IllegalRouteOperationException("Cannot compare null data");
            }

            if (source.eventConfig[0] == (byte)SENSOR_FUSION)
            {
                throw new IllegalRouteOperationException("Cannot compare sensor sensor fusion data");
            }

            if (state.bridge.getFirmware().CompareTo(MULTI_COMPARISON_MIN_FIRMWARE) < 0)
            {
                float scaledReference = references[0] * source.scale(state.bridge);

                byte[] config = new byte[8];
                config[0] = 0x6;
                config[1] = (byte)(source.attributes.signed || references[0] < 0 ? 1 : 0);
                config[2] = (byte)op;
                config[3] = 0;
                Array.Copy(Util.intToBytesLe((int)(scaledReference)), 0, config, 4, 4);

                return(postCreate(null, new SingleValueComparatorEditor(config, source.dataProcessorCopy(source, source.attributes.dataProcessorCopy()), state.bridge)));
            }

            bool anySigned = false;

            foreach (float it in references)
            {
                anySigned |= it < 0;
            }
            bool signed = source.attributes.signed || anySigned;

            DataTypeBase processor;

            if (output == ComparisonOutput.PassFail || output == ComparisonOutput.Zone)
            {
                DataAttributes newAttrs = new DataAttributes(new byte[] { 1 }, 1, 0, false);
                processor = new IntegralDataType(source, DATA_PROCESSOR, DataProcessor.NOTIFY, newAttrs);
            }
            else
            {
                processor = source.dataProcessorCopy(source, source.attributes.dataProcessorCopy());
            }

            {
                //scope conflict with 'config' variable name
                byte[] config = new byte[2 + references.Length * source.attributes.length()];
                config[0] = 0x6;
                config[1] = (byte)((signed ? 1 : 0) | ((source.attributes.length() - 1) << 1) | ((int)op << 3) | ((int)output << 6));

                byte[] referenceValues = MultiValueComparatorEditor.fillReferences(source.scale(state.bridge), source, references);
                Array.Copy(referenceValues, 0, config, 2, referenceValues.Length);

                return(postCreate(null, new MultiValueComparatorEditor(config, processor, state.bridge)));
            }
        }