コード例 #1
0
        public void GetNeighbors(XBeeModule xbeeModule, ZigBeeDevice device)
        {
            // clear list
            m_neighborList.Clear();

            // get 1st part of neighbor table
            m_payload[0] = 0;
            if (!SendCommand(xbeeModule, device))
            {
                m_neighborList.Clear();
                return;
            }

            // get rest of neighbor table
            // note that by Zigbee standard nb of entry in neighbor table can't exceed 1 byte
            m_payload[0] = Convert.ToByte(m_neighborList.Count);
            while (m_neighborList.Count < m_nbOfNeighbors)
            {
                if (!SendCommand(xbeeModule, device))
                {
                    m_neighborList.Clear();
                    return;
                }
            }
        }
コード例 #2
0
ファイル: ZigBeeEndPoint.cs プロジェクト: Jaejoon/winiot-app
        internal ZigBeeEndPoint(ZigBeeEndPoint Other)
        {
            this.m_device = Other.m_device;

            this.Id                  = Other.Id;
            this.DeviceId            = Other.DeviceId;
            this.m_originalProfileId = Other.m_originalProfileId;
            this.m_commandProfileId  = Other.m_commandProfileId;

            this.Name            = Other.Name;
            this.Vendor          = Other.Vendor;
            this.Model           = Other.Model;
            this.Version         = Other.Version;
            this.FirmwareVersion = Other.FirmwareVersion;
            this.SerialNumber    = Other.SerialNumber;
            this.Description     = Other.Description;

            this.m_basicCluster = Other.m_basicCluster;
            this.m_inClusters   = Other.m_inClusters;
            this.m_outClusters  = Other.m_outClusters;

            try
            {
                this.Signals = new List <IAdapterSignal>(Other.Signals);
            }
            catch (OutOfMemoryException ex)
            {
                Debug.WriteLine(ex);
                throw;
            }
        }
コード例 #3
0
ファイル: ZigBeeCommand.cs プロジェクト: lee12180/winiot-uwp
        protected bool SendCommand(XBeeModule xbeeModule, ZigBeeDevice destination, ZigBeeEndPoint endPoint = null)
        {
            bool retVal = false;

            // send ZigBee command then wait for response if required
            m_destination = destination;
            m_endPoint    = endPoint;
            if (m_responseRequired)
            {
                byte sequenceNumber = xbeeModule.SendZigBeeCommand(this);
                retVal = m_responseParsedEv.WaitOne(AdapterHelper.MAX_WAIT_TIMEOUT);
                if (!retVal)
                {
                    // no response received in time
                    xbeeModule.RemovePendingZigBeeCmd(sequenceNumber);
                }
            }
            else
            {
                xbeeModule.SendZigBeeCommandNoResponse(this);
                retVal = true;
            }

            return(retVal);
        }
コード例 #4
0
        public void RemoveCommands(ZigBeeDevice device)
        {
            // sanity check
            if (device == null)
            {
                return;
            }

            // remove all server command associated with a specific device
            lock (m_commandList)
            {
                // 1st build list of elements to remove then remove them from list
                List <ZclServerCommand> elementsToRemove = new List <ZclServerCommand>();
                foreach (var element in m_commandList)
                {
                    if (element.MatchDevice(device))
                    {
                        elementsToRemove.Add(element);
                    }
                }

                foreach (var element in elementsToRemove)
                {
                    m_commandList.Remove(element);
                }
            }
        }
コード例 #5
0
 public bool MatchDevice(ZigBeeDevice device)
 {
     if (m_cluster.EndPoint.Device.MacAddress == device.MacAddress)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
コード例 #6
0
        internal ManagementLeave(ZigBeeDevice device)
        {
            m_isZdoCommand      = true;
            m_clusterId         = MANAGEMENT_LEAVE_CLUSTER_ID;
            m_responseClusterId = MANAGEMENT_LEAVE_RESPONSE_CLUSTER_ID;
            m_device            = device;

            Name         = EXPOSED_NAME;
            Description  = COMMAND_DESCRIPTION;
            InputParams  = new List <IAdapterValue>();
            OutputParams = new List <IAdapterValue>();
        }
コード例 #7
0
        public bool GetListOfAttributeIds(XBeeModule xbeeModule, ZigBeeDevice device, ZigBeeEndPoint endPoint, UInt16 clusterId, out List <UInt16> attributeIdList)
        {
            m_status = ZclHelper.ZCL_ERROR_SUCCESS;

            // reset list of attribute Ids
            attributeIdList = null;
            m_attributeIdList.Clear();
            m_discoveryCompleted = false;

            // set cluster Id
            m_clusterId         = clusterId;
            m_responseClusterId = clusterId;

            // add header and ZCL payload to command payload
            while (!m_discoveryCompleted)
            {
                m_payload = new byte[m_zclHeader.Length + m_zclPayload.Length];
                Array.Copy(m_zclHeader, m_payload, m_zclHeader.Length);
                // update start Id in Zcl payload if necessary
                if (m_attributeIdList.Count != 0)
                {
                    UInt16 lastId = m_attributeIdList.Last();
                    lastId++;
                    byte[] newStartId = AdapterHelper.ToZigBeeFrame(lastId);
                    Array.Copy(newStartId, 0, m_zclPayload, 0, newStartId.Length);
                }
                Array.Copy(m_zclPayload, 0, m_payload, m_zclHeader.Length, m_zclPayload.Length);

                // send command
                if (!SendCommand(xbeeModule, device, endPoint) ||
                    m_status != ZclHelper.ZCL_ERROR_SUCCESS)
                {
                    return(false);
                }
            }

            // set out value
            attributeIdList = m_attributeIdList;

            return(true);
        }
コード例 #8
0
        public void GetEndPoints(XBeeModule xbeeModule, ZigBeeDevice device)
        {
            // sanity check
            if (null == device)
            {
                return;
            }

            // reset end point list
            m_endPointList.Clear();

            // set payload
            m_payload = AdapterHelper.ToZigBeeFrame(device.NetworkAddress);

            // send command
            if (!SendCommand(xbeeModule, device))
            {
                loggingServices.WriteLine <ActiveEndPoints>("[" + device.MacAddress + "] Failed to get endPoints");
                m_endPointList.Clear();
                return;
            }
        }
コード例 #9
0
        public void GetDescriptor(XBeeModule xbeeModule, ZigBeeDevice device, byte endPointId)
        {
            // sanity check
            if (null == device)
            {
                return;
            }

            // reset (in case descriptor has already been set by previous GetDescriptor call)
            Reset();

            // set payload
            // (network address of device then end point Id)
            byte[] tempBytes = AdapterHelper.ToZigBeeFrame(device.NetworkAddress);
            Array.Copy(tempBytes, m_payload, tempBytes.Length);
            m_payload[tempBytes.Length] = endPointId;

            // send command
            if (!SendCommand(xbeeModule, device))
            {
                Reset();
            }
        }
コード例 #10
0
ファイル: XBeeModule.cs プロジェクト: lee12180/winiot-uwp
        public void Initialize(out ZigBeeDevice adapter)
        {
            // initialize communication with XBee module
            try
            {
                m_serialController.InitializeAsync().Wait();
            }
            catch (Exception ex)
            {
                Debug.WriteLine("{0}.{1}: An exception occurred:\n    {2}", this.GetType().Name, nameof(this.Initialize), ex);
                throw;
            }
            m_serialController.OnByteReception += GetBytesFromModule;

            // make sure there is a valid command Id
            NextCommandId();

            // get information about XBee module
            //-----------------------------------

            // get hardware version
            HV_Command hvCommand = new HV_Command();

            if (hvCommand.SendAndWaitResponse(this))
            {
                m_HWVersion = hvCommand.HWVersion;
            }

            // get software version
            VR_Command vrCommand = new VR_Command();

            if (vrCommand.SendAndWaitResponse(this))
            {
                m_SWVersion = vrCommand.SWVersion;
            }

            // get MAC address
            byte[]     macAddress = null;
            SL_Command slCommand  = new SL_Command();
            SH_Command shCommand  = new SH_Command();

            if (slCommand.SendAndWaitResponse(this) &&
                shCommand.SendAndWaitResponse(this))
            {
                macAddress = new byte[shCommand.MacAddressHightPart.Length + slCommand.MacAddressLowerPart.Length];
                Array.Copy(shCommand.MacAddressHightPart, 0, macAddress, 0, shCommand.MacAddressHightPart.Length);
                Array.Copy(slCommand.MacAddressLowerPart, 0, macAddress, shCommand.MacAddressHightPart.Length, slCommand.MacAddressLowerPart.Length);
            }

            MY_Command myCommand = new MY_Command();

            myCommand.SendAndWaitResponse(this);

            // set RX indicator mode
            // note this API mode is necessary to get response to ZDO and ZCL commands
            AO_Command aoCommand = new AO_Command();

            aoCommand.SetRxIndicatorMode(this);

            adapter = new ZigBeeDevice(myCommand.NetworkAddress, AdapterHelper.UInt64FromXbeeFrame(macAddress, 0), false);
        }
コード例 #11
0
ファイル: ZigBeeEndPoint.cs プロジェクト: Jaejoon/winiot-app
        internal void Initialize(ZigBeeDevice device)
        {
            LoggingServices loggingServices = new LoggingServices();
            ZclAttribute    attribute       = null;

            // save away parent device
            m_device          = device;
            m_managementLeave = new ManagementLeave(m_device);

            ZigBeeProfileLibrary profileLibrary = ZigBeeProfileLibrary.Instance;
            string profileName;
            string deviceType;

            profileLibrary.GetProfileAndDeviceNames(m_originalProfileId, DeviceId, out profileName, out deviceType, out m_commandProfileId);

            // set name and description
            this.Description = profileName + " - " + deviceType;
            this.Name        = deviceType;

            //get some information from Basic cluster, e.g.: manufacturer name, model name, HW version, application version...
            if (m_basicCluster.InternalAttributeList.TryGetValue(BasicCluster.ATTRIBUTE_MANUFACTURER_NAME, out attribute))
            {
                object value;
                if (attribute.Read(out value))
                {
                    this.Vendor = (String)value;
                    //loggingServices.WriteLine<ZigBeeEndPoint>(" Vendor = ["+ this.Vendor + "]");
                }
                //else
                //{
                //    loggingServices.WriteLine<ZigBeeEndPoint>(" No Vendor");
                //}
            }
            if (m_basicCluster.InternalAttributeList.TryGetValue(BasicCluster.ATTRIBUTE_MODEL_IDENTIFIER, out attribute))
            {
                object value;
                if (attribute.Read(out value))
                {
                    this.Model = (String)value;
                    //loggingServices.WriteLine<ZigBeeEndPoint>(" Model = [" + this.Model + "]");
                }
                //else
                //{
                //    loggingServices.WriteLine<ZigBeeEndPoint>(" No Model");
                //}
            }
            if (m_basicCluster.InternalAttributeList.TryGetValue(BasicCluster.ATTRIBUTE_HW_VERSION, out attribute))
            {
                object value;
                if (attribute.Read(out value))
                {
                    this.FirmwareVersion = Convert.ToUInt32((byte)value).ToString();
                    //loggingServices.WriteLine<ZigBeeEndPoint>(" FirmwareVersion = [" + this.FirmwareVersion + "]");
                }
                //else
                //{
                //    loggingServices.WriteLine<ZigBeeEndPoint>(" No FirmwareVersion");
                //}
            }
            if (m_basicCluster.InternalAttributeList.TryGetValue(BasicCluster.ATTRIBUTE_APPLICATION_VERSION, out attribute))
            {
                object value;
                if (attribute.Read(out value))
                {
                    this.Version = Convert.ToUInt32((byte)value).ToString();
                    //loggingServices.WriteLine<ZigBeeEndPoint>(" Version = [" + this.Version + "]");
                }
                //else
                //{
                //    loggingServices.WriteLine<ZigBeeEndPoint>(" No Version");
                //}
            }

            // create AllJoyn LSF if this device is a light
            ZigBeeProfileLibrary.DeviceType zigBeeDeviceType;
            if (profileLibrary.IsLight(m_originalProfileId, DeviceId, out zigBeeDeviceType))
            {
                m_lsfHandler = new LSFHandler(this, zigBeeDeviceType);
            }

            // create signals
            CreateSignals();
        }