Esempio n. 1
0
        public static XBeeAddress64 Read(XBeeApi sender, XBeeAddress remoteXbee)
        {
            var sh = sender.Send(AtCmd.SerialNumberHigh).To(remoteXbee).GetResponse();
            var sl = sender.Send(AtCmd.SerialNumberLow).To(remoteXbee).GetResponse();

            return(Parse((AtResponse)sl, (AtResponse)sh));
        }
Esempio n. 2
0
 protected void NotifyDataReceived(byte[] payload, XBeeAddress sender)
 {
     if (DataReceived != null)
     {
         DataReceived(this, payload, sender);
     }
 }
Esempio n. 3
0
        public static void Write(XBeeApi sender, XBeeAddress remoteXbee, ApiModes mode)
        {
            var request = sender.Send(AtCmd.ApiEnable, new[] {(byte) mode}).To(remoteXbee);
            var response = (AtResponse) request.GetResponse();

            if (!response.IsOk)
                throw new XBeeException("Failed to write api mode");
        }
Esempio n. 4
0
        public static void Write(XBeeApi sender, XBeeAddress remoteXbee, string nodeIdentifier)
        {
            var value = Arrays.ToByteArray(nodeIdentifier, 0, MaxNodeIdentifierLength);
            var request = sender.Send(AtCmd.NodeIdentifier, value).To(remoteXbee);
            var response = (AtResponse) request.GetResponse();

            if (!response.IsOk)
                throw new XBeeException("Failed to write node identifier");
        }
Esempio n. 5
0
        public static void Write(XBeeApi sender, XBeeAddress remoteXbee, ApiModes mode)
        {
            var request  = sender.Send(AtCmd.ApiEnable, new[] { (byte)mode }).To(remoteXbee);
            var response = (AtResponse)request.GetResponse();

            if (!response.IsOk)
            {
                throw new XBeeException("Failed to write api mode");
            }
        }
Esempio n. 6
0
        public static void Write(XBeeApi sender, XBeeAddress remoteXbee, string nodeIdentifier)
        {
            var value    = Arrays.ToByteArray(nodeIdentifier, 0, MaxNodeIdentifierLength);
            var request  = sender.Send(AtCmd.NodeIdentifier, value).To(remoteXbee);
            var response = (AtResponse)request.GetResponse();

            if (!response.IsOk)
            {
                throw new XBeeException("Failed to write node identifier");
            }
        }
Esempio n. 7
0
        protected XBeeAddress16 GetNetworkAddress(XBeeAddress serialAddress)
        {
            if (!(serialAddress is XBeeAddress64))
            {
                throw new ArgumentException();
            }

            return(_addressLookupEnabled && AddressLookup.Contains(serialAddress)
                ? (XBeeAddress16)AddressLookup[serialAddress]
                : XBeeAddress16.Unknown);
        }
Esempio n. 8
0
 /// <summary>
 /// Reads remote module basic information
 /// </summary>
 /// <param name="sender">XBee module that will send AT command to remote target</param>
 /// <param name="remoteXbee">XBee module which infomation will be retrieved</param>
 /// <returns>Remote XBee basic infomation</returns>
 public static XBeeConfiguration Read(XBeeApi sender, XBeeAddress remoteXbee)
 {
     return new XBeeConfiguration(sender, remoteXbee)
     {
         ApiMode = Common.ApiMode.Read(sender, remoteXbee),
         HardwareVersion = Common.HardwareVersion.Read(sender, remoteXbee),
         Firmware = Common.Firmware.Read(sender, remoteXbee),
         SerialNumber = Common.SerialNumber.Read(sender, remoteXbee),
         NodeIdentifier = Common.NodeIdentifier.Read(sender, remoteXbee)
     };
 }
Esempio n. 9
0
        public RemoteAtCommand CreateRequest(ushort atCommand, XBeeAddress destination, params byte[] value)
        {
            if (destination is XBeeAddress16)
            {
                throw new ArgumentException("64 bit address expected", "destination");
            }

            return(new RemoteAtCommand(atCommand, (XBeeAddress64)destination, GetNetworkAddress(destination), value)
            {
                FrameId = _idGenerator.GetNext()
            });
        }
Esempio n. 10
0
 public TxRequest(XBeeAddress destination, byte[] payload)
     : this(payload)
 {
     if (destination is XBeeAddress16)
     {
         DestinationSerial  = XBeeAddress64.Broadcast;
         DestinationAddress = (XBeeAddress16)destination;
     }
     else
     {
         DestinationSerial  = (XBeeAddress64)destination;
         DestinationAddress = XBeeAddress16.Unknown;
     }
 }
Esempio n. 11
0
 public ExplicitTxRequest(XBeeAddress destination, byte[] payload, byte srcEndpoint, byte destEndpoint, ushort clusterId, ushort profileId)
     : this(payload, srcEndpoint, destEndpoint, clusterId, profileId)
 {
     if (destination is XBeeAddress16)
     {
         DestinationSerial  = XBeeAddress64.Broadcast;
         DestinationAddress = (XBeeAddress16)destination;
     }
     else
     {
         DestinationSerial  = (XBeeAddress64)destination;
         DestinationAddress = XBeeAddress16.Unknown;
     }
 }
Esempio n. 12
0
 public TxRequest(XBeeAddress destination, byte[] payload)
     : this(payload)
 {
     if (destination is XBeeAddress16)
     {
         DestinationSerial = XBeeAddress64.Broadcast;
         DestinationAddress = (XBeeAddress16) destination;
     }
     else
     {
         DestinationSerial = (XBeeAddress64) destination;
         DestinationAddress = XBeeAddress16.Unknown;
     }
 }
Esempio n. 13
0
        private static void OnDataReceived(XBeeApi receiver, byte[] data, XBeeAddress sender)
        {
            var dataStr = new string(Encoding.UTF8.GetChars(data));

            switch (dataStr)
            {
                case Ping:
                    receiver.Send(Pong).To(sender).NoResponse();
                    break;

                case Pong:
                    Debug.Print("Received Pong from " + sender);
                    break;
            }
        }
Esempio n. 14
0
        private static void OnDataReceived(XBeeApi receiver, byte[] data, XBeeAddress sender)
        {
            var dataStr = new string(Encoding.UTF8.GetChars(data));

            switch (dataStr)
            {
            case Ping:
                receiver.Send(Pong).To(sender).NoResponse();
                break;

            case Pong:
                Debug.Print("Received Pong from " + sender);
                break;
            }
        }
Esempio n. 15
0
        public XBeeRequest CreateRequest(byte[] payload, XBeeAddress destination)
        {
            if (Config.IsSeries1())
            {
                return new TxRequest(destination, payload)
                       {
                           FrameId = _idGenerator.GetNext()
                       }
            }
            ;

            if (!(destination is XBeeAddress64) || destination == null)
            {
                throw new ArgumentException("64 bit address expected", "destination");
            }

            return(new Api.Zigbee.TxRequest((XBeeAddress64)destination, GetNetworkAddress(destination), payload)
            {
                FrameId = _idGenerator.GetNext()
            });
        }
Esempio n. 16
0
 public static string Read(XBeeApi sender, XBeeAddress remoteXbee)
 {
     var request = sender.Send(AtCmd.NodeIdentifier).To(remoteXbee);
     return Parse((AtResponse) request.GetResponse());
 }
Esempio n. 17
0
 public IRequest To(ushort networkAddress)
 {
     DestinationAddress = new XBeeAddress16(networkAddress);
     return this;
 }
Esempio n. 18
0
        // Creating requests

        public XBeeRequest CreateRequest(string payload, XBeeAddress destination)
        {
            return(CreateRequest(Arrays.ToByteArray(payload), destination));
        }
Esempio n. 19
0
 public static ApiModes Read(XBeeApi sender, XBeeAddress remoteXbee)
 {
     var request = sender.Send(AtCmd.ApiEnable).To(remoteXbee);
     return Parse((AtResponse) request.GetResponse());
 }
Esempio n. 20
0
 public IRequest To(ulong serialNumber)
 {
     DestinationAddress = new XBeeAddress64(serialNumber);
     return this;
 }
Esempio n. 21
0
 public IRequest To(XBeeAddress destination)
 {
     DestinationAddress = destination;
     return this;
 }
Esempio n. 22
0
 /// <summary>
 ///   TODO: Update Comments
 ///     
 /// </summary>
 /// <param name="sender" type="NETMF.OpenSource.XBee.Api.XBee">
 ///     <para>
 ///         
 ///     </para>
 /// </param>
 /// <param name="remoteXbee" type="NETMF.OpenSource.XBee.Api.XBeeAddress">
 ///     <para>
 ///         
 ///     </para>
 /// </param>
 public static void Write(XBeeApi sender, XBeeAddress remoteXbee)
 {
     var request = sender.Send(AtCmd.Write).To(remoteXbee);
     Parse((AtResponse) request.GetResponse());
 }
Esempio n. 23
0
        public static ApiModes Read(XBeeApi sender, XBeeAddress remoteXbee)
        {
            var request = sender.Send(AtCmd.ApiEnable).To(remoteXbee);

            return(Parse((AtResponse)request.GetResponse()));
        }
Esempio n. 24
0
 public TxRequest(XBeeAddress destination, byte[] payload, Options option = Options.Unicast)
 {
     Destination = destination;
     Payload     = payload;
     Option      = option;
 }
Esempio n. 25
0
 public static XBeeAddress64 Read(XBeeApi sender, XBeeAddress remoteXbee)
 {
     var sh = sender.Send(AtCmd.SerialNumberHigh).To(remoteXbee).GetResponse();
     var sl = sender.Send(AtCmd.SerialNumberLow).To(remoteXbee).GetResponse();
     return Parse((AtResponse)sl, (AtResponse)sh);
 }
Esempio n. 26
0
 public IRequest ToAll()
 {
     DestinationAddress = XBeeAddress64.Broadcast;
     return this;
 }
Esempio n. 27
0
 public TxRequest(XBeeAddress destination, byte[] payload, Options option = Options.Unicast)
 {
     Destination = destination;
     Payload = payload;
     Option = option;
 }
Esempio n. 28
0
 private XBeeConfiguration(XBeeApi xbee, XBeeAddress remoteXbee = null)
 {
     _xbee = xbee;
     _remoteXbee = remoteXbee;
 }
Esempio n. 29
0
 protected void Init()
 {
     ExpectedResponse = Response.Single;
     TimeoutValue = PacketParser.DefaultParseTimeout;
     DestinationAddress = null;
     DestinationNode = null;
     Filter = null;
 }
Esempio n. 30
0
        public static HardwareVersions Read(XBeeApi sender, XBeeAddress remoteXBee)
        {
            var request = sender.Send(AtCmd.HardwareVersion).To(remoteXBee);

            return(Parse((AtResponse)request.GetResponse()));
        }
Esempio n. 31
0
        protected XBeeAddress16 GetNetworkAddress(XBeeAddress serialAddress)
        {
            if (!(serialAddress is XBeeAddress64))
                throw new ArgumentException();

            return _addressLookupEnabled && AddressLookup.Contains(serialAddress)
                ? (XBeeAddress16)AddressLookup[serialAddress]
                : XBeeAddress16.Unknown;
        }
Esempio n. 32
0
 protected void NotifyDataReceived(byte[] payload, XBeeAddress sender)
 {
     if (DataReceived != null)
         DataReceived(this, payload, sender);
 }
Esempio n. 33
0
        /// <summary>
        ///   TODO: Update Comments
        ///
        /// </summary>
        /// <param name="sender" type="NETMF.OpenSource.XBee.Api.XBee">
        ///     <para>
        ///
        ///     </para>
        /// </param>
        /// <param name="remoteXbee" type="NETMF.OpenSource.XBee.Api.XBeeAddress">
        ///     <para>
        ///
        ///     </para>
        /// </param>
        public static void Write(XBeeApi sender, XBeeAddress remoteXbee)
        {
            var request = sender.Send(AtCmd.Write).To(remoteXbee);

            Parse((AtResponse)request.GetResponse());
        }
Esempio n. 34
0
 // Creating requests
 public XBeeRequest CreateRequest(string payload, XBeeAddress destination)
 {
     return CreateRequest(Arrays.ToByteArray(payload), destination);
 }
Esempio n. 35
0
        public XBeeRequest CreateRequest(byte[] payload, XBeeAddress destination)
        {
            if (Config.IsSeries1())
                return new TxRequest(destination, payload)
                    {FrameId = _idGenerator.GetNext()};

            if (!(destination is XBeeAddress64) || destination == null)
                throw new ArgumentException("64 bit address expected", "destination");

            return new Api.Zigbee.TxRequest((XBeeAddress64)destination, GetNetworkAddress(destination), payload)
                { FrameId = _idGenerator.GetNext() };
        }
Esempio n. 36
0
        public static string Read(XBeeApi sender, XBeeAddress remoteXbee)
        {
            var request = sender.Send(AtCmd.NodeIdentifier).To(remoteXbee);

            return(Parse((AtResponse)request.GetResponse()));
        }
Esempio n. 37
0
        public RemoteAtCommand CreateRequest(ushort atCommand, XBeeAddress destination, params byte[] value)
        {
            if (destination is XBeeAddress16)
                throw new ArgumentException("64 bit address expected", "destination");

            return new RemoteAtCommand(atCommand, (XBeeAddress64) destination, GetNetworkAddress(destination), value)
                { FrameId = _idGenerator.GetNext() };
        }
Esempio n. 38
0
 public static string Read(XBeeApi sender, XBeeAddress remoteXbee)
 {
     var request = sender.Send(AtCmd.FirmwareVersion).To(remoteXbee);
     return Parse((AtResponse) request.GetResponse());
 }
Esempio n. 39
0
        public void Receive(byte[] source_buffer, int size, XBeeAddress addr)
        {
            try
            {
                var ret             = Codes.DecodeErrors.NoError;
                var instance_buffer = new byte[size];
                Array.Copy(source_buffer, instance_buffer, size);
                var pdu = CODEC.Decode(instance_buffer, ref ret);

                if (pdu == null || ret != Codes.DecodeErrors.NoError)
                {
                    STrace.Debug(GetType().FullName, String.Format("XBEE: Error la PDU no se pudo decodificar reason={0}", ret));
                    return;
                }

                pdu.Transporte = this;
                pdu.Destino    = new Destino {
                    XBee = addr
                };
                var d      = Devices.I().FindById(pdu.IdDispositivo);
                var devlog = (d != null ? d.LogId : "?");
                var myData = Thread.GetNamedDataSlot("device");
                Thread.SetData(myData, d);

                STrace.Debug(GetType().FullName, pdu.Trace(""));
                if (d != null)
                {
                    d.Trace();
                }

                if (d != null && d.State == DeviceTypes.States.ONNET)
                {
                    d.Transporte = this;
                    d.Touch(pdu.Destino);
                }
                else if (d != null)
                {
                    if ((Codes.HighCommand)pdu.CH != Codes.HighCommand.LoginRequest)
                    {
                        // si el dispositivo no esta registrado, entonces enviamos
                        // mensaje de registracion requerida.
                        STrace.Debug(GetType().FullName, String.Format("DEVICE[{0}]/XBEE: Enviando Login requerido", devlog));
                        var rta = new PDU
                        {
                            IdDispositivo = pdu.IdDispositivo,
                            Seq           = pdu.Seq,
                            Options       = pdu.Options,
                            Destino       = pdu.Destino,
                            CH            = ((byte)Codes.HighCommand.LoginRequerido),
                            CL            = 0x00
                        };
                        Send(rta);
                        Thread.SetData(myData, null);
                        return;
                    }
                }

                var t = ObtenerTransaccion(pdu.IdTransaccion);
                if (t == null)
                {
                    if (pdu.CH < 0x80)
                    {
                        STrace.Debug(GetType().FullName, String.Format("DEVICE[{0}]/XBEE: Nueva Transaccion Entrante CH={1} Seq={2}", devlog, pdu.CH, pdu.Seq));

                        var mrs = new MRS(pdu, this, TransactionUser);
                        if (d != null && d.HackBugXBEEv99)
                        {
                            d.Transporte = this;
                        }
                        NuevaTransaccion(mrs, pdu);
                        mrs.Start();
                    }
                    else
                    {
                        STrace.Debug(GetType().FullName, String.Format("DEVICE[{0}]/XBEE: RTA HUERFANA CH={1}", devlog, pdu.CH));
                    }
                }
                else
                {
                    STrace.Debug(GetType().FullName, String.Format("DEVICE[{0}]/XBEE: Recivo Retransmision CH={1} Seq={2}", devlog, pdu.CH, pdu.Seq));
                    t.RecibePDU(pdu);
                }
            }
            catch (Exception e)
            {
                STrace.Exception(GetType().FullName, e);
            }
        }