Ejemplo n.º 1
0
        public override bool Equals(object o)
        {
            if (o == this)
            {
                return(true);
            }

            if (o is TaggedDevice)
            {
                TaggedDevice td = (TaggedDevice)o;
                return((td.DeviceContainer.Equals(this.DeviceContainer)) && (td.DeviceType.Equals(this.DeviceType)) && (td.Min.Equals(this.Min)) && (td.Max.Equals(this.Max)) && (td.Init.Equals(this.Init)) && (td.ClusterName.Equals(this.ClusterName)) && (td.Label.Equals(this.Label)));
            }
            return(false);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Method startElement
        ///
        /// </summary>
        /// <param name="name"> </param>
        /// <param name="atts">
        /// </param>
        public virtual void startElement(string name, XmlReader reader)
        {
            switch (name.ToUpper())
            {
            case ("CLUSTER"):
            {
                // Parse cluster elements here, keeping track of them with a Stack.
                try
                {
                    clusterStack.Push(reader.GetAttribute("name"));
                }
                catch (ArgumentNullException) {; }
                catch (InvalidOperationException) {; }
                break;
            }

            case ("LABEL"):
            {
                reader.Read();
                if (currentDevice == null)
                {
                    // This means we have a branch instead of a sensor or actuator
                    // so, set label accordingly
                    try
                    {
                        currentDevice       = branchStack.Peek();
                        currentDevice.Label = reader.Value.Trim();
                        currentDevice       = null;
                    }
                    catch (InvalidOperationException)
                    {
                        // don't do anything yet.
                    }
                }
                else
                {
                    currentDevice.Label = reader.Value.Trim();
                }

                //System.out.println("This device's label is: " + currentDevice.label);
                break;
            }

            case ("CHANNEL"):
            {
                reader.Read();
                if (currentDevice == null)
                {
                    // This means we have a branch instead of a sensor or actuator
                    // so, set channel accordingly
                    try
                    {
                        currentDevice = branchStack.Peek();
                        currentDevice.ChannelFromString = reader.Value.Trim();
                        currentDevice = null;
                    }
                    catch (InvalidOperationException)
                    {
                        // don't do anything yet.
                    }
                }
                else
                {
                    currentDevice.ChannelFromString = reader.Value.Trim();
                }
                break;
            }

            case ("MAX"):
            {
                reader.Read();
                currentDevice.Max = reader.Value.Trim();

                //System.out.println("This device's max message is: " + currentDevice.max);
                break;
            }

            case ("MIN"):
            {
                reader.Read();
                currentDevice.Min = reader.Value.Trim();

                //System.out.println("This device's min message is: " + currentDevice.min);
                break;
            }

            case ("INIT"):
            {
                reader.Read();
                currentDevice.Init = reader.Value.Trim();

                //System.out.println("This device's init message is: " + currentDevice.init);
                break;
            }

            case ("BRANCH"):
            {
                string attributeAddr = "null";
                try
                {
                    attributeAddr = reader.GetAttribute("addr");
                }
                catch (ArgumentNullException) {; }

                currentDevice = new TaggedDevice();         // instantiates object

                setTaggedDeviceMembers(attributeAddr, "branch");

                // push the not-quite-finished branch TaggedDevice on the branch stack.
                branchStack.Push(currentDevice);
                // put currentDevice in the branch vector that holds all branch objects.
                branchVector.Add(currentDevice);
                // put currentDevice in deviceList (if it is of type "branch", of course)
                deviceList.Add(currentDevice);
                break;
            }

            case ("SENSOR"):
            case ("ACTUATOR"):
            {
                string attributeAddr = "null";
                string attributeType = "null";
                try
                {
                    attributeAddr = reader.GetAttribute("addr");
                }
                catch (ArgumentNullException) {; }
                try
                {
                    attributeType = reader.GetAttribute("type");
                }
                catch (ArgumentNullException) {; }

                // first, find tag type to instantiate by CLASS NAME!
                // if the tag has a "." in it, it indicates the package
                // path was included in the tag type.
                string className;

                if (attributeType.IndexOf(".", StringComparison.Ordinal) > 0)
                {
                    className = attributeType;
                }
                else
                {
                    className = "com.dalsemi.onewire.application.tag." + attributeType;
                }

                // instantiate the appropriate object based on tag type (i.e., "Contact", "Switch", etc)
                try
                {
                    Type genericClass = Type.GetType(className);

                    currentDevice = (TaggedDevice)Activator.CreateInstance(genericClass);
                }
                catch (System.Exception e)
                {
                    throw new Exception("Can't load 1-Wire Tag Type class (" + className + "): " + e.Message);
                }

                setTaggedDeviceMembers(attributeAddr, attributeType);
                break;
            }
            }
        }
Ejemplo n.º 3
0
    //--------
    //-------- Constructors
    //--------

    /// <summary>
    /// Constructor a frame to contain the device data.  Provide
    /// the device and the log file name
    /// </summary>
    public DeviceFrame(TaggedDevice dev, string logFile) : base(dev.DeviceContainer.AddressAsString)
    {
        // construct the frame

        // init
        pollDelay       = 0;
        readButtonClick = false;
        num_format      = NumberFormat.Instance;
        num_format.MaximumFractionDigits = 2;
        num_format.MinimumFractionDigits = 0;
        num_format.MinimumIntegerDigits  = 2;
        num_format.GroupingUsed          = false;
        lastReading = "none";

        // get ref to the tagged device and log file
        this.dev     = dev;
        this.logFile = logFile;

        // set the look and feel to the system look and feel
        try
        {
            UIManager.LookAndFeel = UIManager.SystemLookAndFeelClassName;
        }
        catch (Exception e)
        {
            Debug.WriteLine(e.ToString());
            Debug.Write(e.StackTrace);
        }

        // add an event listener to end the aplication when the frame is closed
        addWindowListener(new WindowAdapterAnonymousInnerClassHelper(this, e));

        // create the main panel
        mainPanel = new JPanel(new GridLayout(3, 1));

        // create the sub-panels
        topPanel        = new JPanel();
        topPanel.Layout = new BoxLayout(topPanel, BoxLayout.Y_AXIS);
        topPanel.Border = BorderFactory.createEmptyBorder(10, 10, 10, 10);

        centerPanel            = new JPanel();
        centerPanel.Layout     = new BoxLayout(centerPanel, BoxLayout.Y_AXIS);
        centerPanel.Border     = BorderFactory.createEmptyBorder(10, 10, 10, 10);
        centerPanel.Background = Color.white;

        bottomPanel        = new JPanel();
        bottomPanel.Layout = new BoxLayout(bottomPanel, BoxLayout.Y_AXIS);
        bottomPanel.Border = BorderFactory.createEmptyBorder(10, 10, 10, 10);

        // fill the panels
        // top
        clusterLabel = new JLabel("Cluster: " + dev.ClusterName);
        topPanel.add(clusterLabel);

        mainLabel = new JLabel(dev.Label);
        mainLabel.HorizontalAlignment = JLabel.CENTER;
        mainLabel.Font = new Font("SansSerif", Font.PLAIN, 20);
        topPanel.add(mainLabel);

        logCheck = new JCheckBox("Logging Enable", false);
        logCheck.addActionListener(this);
        topPanel.add(logCheck);

        // center
        timeLabel = new JLabel("Last Reading: none");
        timeLabel.HorizontalAlignment = JLabel.CENTER;
        centerPanel.add(timeLabel);

        // bottom
        readButton            = new JButton("Read Once");
        readButton.AlignmentX = Component.LEFT_ALIGNMENT;
        readButton.addActionListener(this);
        bottomPanel.add(readButton);

        string[] selectionStrings = new string[] { "No Polling", "1 second", "30 seconds", "1 minute", "10 minutes", "1 hour" };
        pollCombo            = new JComboBox(selectionStrings);
        pollCombo.Editable   = false;
        pollCombo.AlignmentX = Component.LEFT_ALIGNMENT;
        pollCombo.addActionListener(this);
        bottomPanel.add(pollCombo);

        pathLabel            = new JLabel("Path: " + dev.OWPath.ToString());
        pathLabel.AlignmentX = Component.LEFT_ALIGNMENT;
        bottomPanel.add(pathLabel);

        // add to main
        mainPanel.add(topPanel);
        mainPanel.add(centerPanel);
        mainPanel.add(bottomPanel);

        // add to frame
        ContentPane.add(mainPanel);

        // pack the frame
        pack();

        // resize the window and put in random location
        Dimension current_sz = Size;

        Size = new Dimension(current_sz.width * 3 / 2, current_sz.height);
        Toolkit   tool = Toolkit.DefaultToolkit;
        Dimension mx   = tool.ScreenSize;
        Dimension sz   = Size;
        Random    rand = new Random();

        setLocation(rand.Next((mx.width - sz.width) / 2), rand.Next((mx.height - sz.height) / 2));

        // make visible
        Visible = true;
    }