Beispiel #1
0
        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);
        }
Beispiel #2
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;
                }
            }
        }
Beispiel #3
0
 public void SendNoWaitResponse(XBeeModule xbeeModule, bool sendLocal = true)
 {
     if (sendLocal)
     {
         xbeeModule.SendATCmdLocalNoResponse(this);
     }
     else
     {
         // not yet implemented
     }
 }
        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);
        }
Beispiel #5
0
 public bool SendAndWaitResponse(XBeeModule xbeeModule, bool sendLocal = true)
 {
     if (sendLocal)
     {
         byte commandId = xbeeModule.SendATCmdLocal(this);
         if (!m_responseParsedEv.WaitOne(AdapterHelper.MAX_WAIT_TIMEOUT))
         {
             xbeeModule.RemovePendingATCmd(commandId);
             return(false);
         }
         else
         {
             return(true);
         }
     }
     else
     {
         // not yet implemented
         return(false);
     }
 }
Beispiel #6
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;
            }
        }
        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();
            }
        }
Beispiel #8
0
 public bool SetRxIndicatorMode(XBeeModule xbeeCommand)
 {
     m_payload = EXPLICIT_RX_INDICATOR;
     return(SendAndWaitResponse(xbeeCommand));
 }
Beispiel #9
0
 public bool SetDefaultApiMode(XBeeModule xbeeCommand)
 {
     m_payload = DEFAULT_API_MODE;
     return(SendAndWaitResponse(xbeeCommand));
 }