Ejemplo n.º 1
0
        public NodeInfo(byte[] data)
        {
            if (data == null)
                throw new ArgumentNullException("data");

            if (data.Length < 28)
                throw new ArgumentException("data length not sufficient to fill NodeInfo");

            var stack = new SimpleStack(data);
            Name = stack.PopName();
            Description = stack.PopString();
            Location = stack.PopString();
            Address = stack.PopAddress();
            Type = stack.PopString();
            Hardware = stack.PopName();
            Version = stack.PopName();
            DigitalInputs = stack.PopByte();
            DigitalOutputs = stack.PopByte();
            AnalogInputs = stack.PopByte();
            CounterInputs = stack.PopByte();
            PwmOutputs = stack.PopByte();
            WiresCount = stack.PopByte();
            DevicesCount = stack.PopByte();
            SensorsCount = stack.PopByte();
            ResetPin = stack.PopByte();
        }
Ejemplo n.º 2
0
 public DeviceAction(byte[] array, int startIndex = 0)
 {
     var stack = new SimpleStack(array, startIndex);
     _device = stack.PopName();
     _action = stack.PopString();
     _values = stack.PopArray();
 }
Ejemplo n.º 3
0
 public DeviceStatus(byte[] array, int start = 0) : this()
 {
     if (array == null || array.Length < start) return;
     var stack = new SimpleStack(array, start);
     Index = stack.PopByte();
     Device = stack.PopName();
     Status = stack.PopString();
 }
Ejemplo n.º 4
0
 public DeviceEvent(byte[] array, int startIndex = 0)
 {
     if (array != null)
     {
         var stack = new SimpleStack(array, startIndex);
         _device = stack.PopName();
         _event = stack.PopString();
         _status = stack.PopString();
         _time = stack.PopUInt32();
         _values = stack.PopArray();
     }
     else 
     {
         _device = string.Empty;
         _event = string.Empty;
         _status = string.Empty;
         _time = 0;
         _values = null;
     }
 }
Ejemplo n.º 5
0
        public NodeStatusInfo(byte[] data)
        {
            var stack = new SimpleStack(data);
            //Bit Mask:
            //----------
            //00: Inputs
            //01: Outputs
            //02: Analogs
            //04: Counters
            //08: Pwms
            //16: Devices
            //32: Sensors
            Mask = stack.PopByte();

            //Node global status
            Time = stack.PopUInt32();

            NodeStatus = (NodeStatusValues)stack.PopByte();
            BusStatus = (BusStatus)stack.PopByte();

            LastError = (NodeErrorCodes)stack.PopByte();
            TotalErrors = stack.PopUInt32();
            
            var size = stack.PopByte(); Inputs = size > 0 ? new byte[size] : null;
            size = stack.PopByte(); Outputs = size > 0 ? new byte[size] : null;
            size = stack.PopByte(); Analogs = size > 0 ? new ushort[size] : null;
            size = stack.PopByte(); Counters = size > 0 ? new uint[size] : null;
            size = stack.PopByte(); Pwms = size > 0 ? new ushort[size] : null;
            size = stack.PopByte(); Devices = size > 0 ? new string[size] : null;
            size = stack.PopByte(); Sensors = size > 0 ? new float[size] : null;

            LastActivatedInput = stack.PopName();
            LastActivatedOutput = stack.PopName();

            //Inputs
            if ((Mask & 0x01) != 0 && Inputs!=null)
                for (var i = 0; i < Inputs.Length; i++)
                    Inputs[i] = stack.PopByte();
            //Outputs
            if ((Mask & 0x02) != 0 && Outputs != null)
                for (var i = 0; i < Outputs.Length; i++)
                    Outputs[i] = stack.PopByte();
            //Analogs
            if ((Mask & 0x04) != 0 && Analogs != null)
                for (var i = 0; i < Analogs.Length; i++)
                    Analogs[i] = stack.PopUInt16();
            //Counters
            if ((Mask & 0x08) != 0 && Counters != null)
                for (var i = 0; i < Counters.Length; i++)
                    Counters[i] = stack.PopUInt32();
            //Pwms
            if ((Mask & 0x10) != 0 && Pwms != null)
                for (var i = 0; i < Pwms.Length; i++)
                    Pwms[i] = stack.PopUInt16();
            //Devices
            if ((Mask & 0x20) != 0 && Devices!= null)
                for (var i = 0; i < Devices.Length; i++)
                    //Get status string
                    Devices[i] = stack.PopString();
            //Sensors
            if ((Mask & 0x40) != 0 && Sensors != null)
                for (var i = 0; i < Sensors.Length; i++)
                    //Get last sensor read
                    Sensors[i] = stack.PopSingle();
        }
Ejemplo n.º 6
0
 /// <summary>
 /// HBus compatible constructor
 /// </summary>
 /// <param name="data"></param>
 /// <param name="index"></param>
 public DeviceInfo(byte[] data, int index = 0) : this()
 {
     var stack = new SimpleStack(data, index);
     Index = stack.PopByte();
     Name = stack.PopName();
     //Address = stack.PopAddress();
     Description = stack.PopString();
     Location = stack.PopString();
     Class = stack.PopString();
     Hardware = stack.PopString();
     Version = stack.PopString();
     Actions = stack.PopStringArray();
 }