コード例 #1
0
        /// <summary>
        /// Notifies subscribed Modem Status listeners that a Modem Status event packet has been received.
        /// </summary>
        /// <param name="modemStatusEvent">The Modem Status event.</param>
        /// <seealso cref="ModemStatusEvent"/>
        private void NotifyModemStatusReceived(ModemStatusEvent modemStatusEvent)
        {
            logger.Debug(connectionInterface.ToString() + "Modem Status event received.");

            try
            {
                lock (ModemStatusReceived)
                {
                    var handler = ModemStatusReceived;
                    if (handler != null)
                    {
                        var args = new ModemStatusReceivedEventArgs(modemStatusEvent);

                        handler.GetInvocationList().AsParallel().ForAll((action) =>
                        {
                            action.DynamicInvoke(this, args);
                        });
                    }
                }
            }
            catch (Exception e)
            {
                logger.Error(e.Message, e);
            }
        }
コード例 #2
0
        /**
         * Class constructor. Instantiates a new {@code ModemStatusPacket} object
         * with the given modem status.
         *
         * @param modemStatusEvent Modem status event enum. entry.
         *
         * @throws ArgumentNullException if {@code modemStatusEvent == null}.
         */
        public ModemStatusPacket(ModemStatusEvent modemStatusEvent)
            : base(APIFrameType.MODEM_STATUS)
        {
            if (modemStatusEvent == null)
                throw new ArgumentNullException("Modem Status event cannot be null.");

            this.modemStatusEvent = modemStatusEvent;
        }
コード例 #3
0
        /**
         * Class constructor. Instantiates a new {@code ModemStatusPacket} object
         * with the given modem status.
         *
         * @param modemStatusEvent Modem status event enum. entry.
         *
         * @throws ArgumentNullException if {@code modemStatusEvent == null}.
         */
        public ModemStatusPacket(ModemStatusEvent modemStatusEvent)
            : base(APIFrameType.MODEM_STATUS)
        {
            if (modemStatusEvent == null)
            {
                throw new ArgumentNullException("Modem Status event cannot be null.");
            }

            this.modemStatusEvent = modemStatusEvent;
        }
コード例 #4
0
        /**
         * Creates a new {@code ModemStatusPacket} object from the given payload.
         *
         * @param payload The API frame payload. It must start with the frame type
         *                corresponding to a Modem Status packet ({@code 0x8A}).
         *                The byte array must be in {@code OperatingMode.API} mode.
         *
         * @return Parsed Modem Status packet.
         *
         * @throws ArgumentException if {@code payload[0] != APIFrameType.MODEM_STATUS.getValue()} or
         *                                  if {@code payload.Length < {@value #MIN_API_PAYLOAD_LENGTH}}.
         * @throws ArgumentNullException if {@code payload == null} or
         *                              if {@code modemStatusEvent == null}.
         */
        public static ModemStatusPacket CreatePacket(byte[] payload)
        {
            Contract.Requires <ArgumentNullException>(payload != null, "Modem Status packet payload cannot be null.");
            // 1 (Frame type) + 1 (Modem status)
            Contract.Requires <ArgumentException>(payload.Length >= MIN_API_PAYLOAD_LENGTH, "Incomplete Modem Status packet.");
            Contract.Requires <ArgumentException>((payload[0] & 0xFF) == APIFrameType.MODEM_STATUS.GetValue(), "Payload is not a Modem Status packet.");

            // Get the Modem status byte (byte 1).
            int status = payload[1] & 0xFF;

            // Get the Modem Status enum. entry.
            ModemStatusEvent modemStatusEvent = (ModemStatusEvent)status;

            return(new ModemStatusPacket(modemStatusEvent));
        }
コード例 #5
0
        /**
         * Notifies subscribed Modem Status listeners that a Modem Status event
         * packet has been received.
         *
         * @param modemStatusEvent The Modem Status event.
         *
         * @see com.digi.xbee.api.models.ModemStatusEvent
         */
        private void NotifyModemStatusReceived(ModemStatusEvent modemStatusEvent)
        {
            logger.Debug(connectionInterface.ToString() + "Modem Status event received.");

            try
            {
                lock (modemStatusListeners)
                {
                    var runTask = new Action <IModemStatusReceiveListener>(listener =>
                    {
                        lock (listener)
                        {
                            listener.modemStatusEventReceived(modemStatusEvent);
                        }
                    });
                    //ScheduledExecutorService executor = Executors.newScheduledThreadPool(Math.Min(MAXIMUM_PARALLEL_LISTENER_THREADS,
                    //		modemStatusListeners.size()));
                    foreach (IModemStatusReceiveListener listener in modemStatusListeners)
                    {
                        Task.Factory.StartNew((state) =>
                                              runTask((IModemStatusReceiveListener)state), listener);
                        //executor.execute(new Runnable() {
                        //	/*
                        //	 * (non-Javadoc)
                        //	 * @see java.lang.Runnable#run()
                        //	 */
                        //	//@Override
                        //	public void run() {
                        //		// Synchronize the listener so it is not called
                        //		// twice. That is, let the listener to finish its job.
                        //		lock (listener) {
                        //			listener.modemStatusEventReceived(modemStatusEvent);
                        //		}
                        //	}
                        //});
                    }
                    //executor.shutdown();
                }
            }
            catch (Exception e)
            {
                logger.Error(e.Message, e);
            }
        }
コード例 #6
0
        /// <summary>
        /// Creates a new <see cref="ModemStatusPacket"/> object from the given payload.
        /// </summary>
        /// <param name="payload">The API frame payload. It must start with the frame type corresponding
        /// to a Modem Status packet (<c>0x8A</c>). The byte array must be in <see cref="OperatingMode.API"/>
        /// mode.</param>
        /// <returns>Parsed Modem status packet.</returns>
        /// <exception cref="ArgumentException">If <c>payload[0] != APIFrameType.MODEM_STATUS.GetValue()</c>
        /// or if <c>payload.Length <![CDATA[<]]> <see cref="MIN_API_PAYLOAD_LENGTH"/></c>.</exception>
        /// <exception cref="ArgumentNullException">If <c><paramref name="payload"/> == null</c>.</exception>
        public static ModemStatusPacket CreatePacket(byte[] payload)
        {
            if (payload == null)
            {
                throw new ArgumentNullException("Modem Status packet payload cannot be null.");
            }
            // 1 (Frame type) + 1 (Modem status)
            if (payload.Length < MIN_API_PAYLOAD_LENGTH)
            {
                throw new ArgumentException("Incomplete Modem Status packet.");
            }
            if ((payload[0] & 0xFF) != APIFrameType.MODEM_STATUS.GetValue())
            {
                throw new ArgumentException("Payload is not a Modem Status packet.");
            }

            // Get the Modem status byte (byte 1).
            int status = payload[1] & 0xFF;

            // Get the Modem Status enumeration entry.
            ModemStatusEvent modemStatusEvent = (ModemStatusEvent)status;

            return(new ModemStatusPacket(modemStatusEvent));
        }
コード例 #7
0
 /// <summary>
 /// Instantiates a <see cref="ModemStatusReceivedEventArgs"/> object with the provided parameters.
 /// </summary>
 /// <param name="modemStatusEvent">The modem status received.</param>
 public ModemStatusReceivedEventArgs(ModemStatusEvent modemStatusEvent)
 {
     ModemStatusEvent = modemStatusEvent;
 }
コード例 #8
0
 /// <summary>
 /// Gets the modem status ID
 /// </summary>
 /// <param name="source"></param>
 /// <returns>The modem status ID.</returns>
 public static int GetId(this ModemStatusEvent source)
 {
     return((int)source);
 }
コード例 #9
0
 /// <summary>
 /// Returns the <see cref="ModemStatusEvent"/> in string format.
 /// </summary>
 /// <param name="source"></param>
 /// <returns>The <see cref="ModemStatusEvent"/> in string format.</returns>
 public static string ToDisplayString(this ModemStatusEvent source)
 {
     return(string.Format("{0}: {1}", HexUtils.ByteToHexString((byte)(int)source), source.GetDescription()));
 }
コード例 #10
0
 /// <summary>
 /// Gets the modem status description.
 /// </summary>
 /// <param name="source"></param>
 /// <returns>The modem status description.</returns>
 public static string GetDescription(this ModemStatusEvent source)
 {
     return(lookupTable[source]);
 }
コード例 #11
0
        private const int MIN_API_PAYLOAD_LENGTH = 2;         // 1 (Frame type) + 1 (Modem status)

        /// <summary>
        /// Class constructor. Instantiates a new <see cref="ModemStatusPacket"/> object with the
        /// given modem status.
        /// </summary>
        /// <param name="modemStatusEvent">The modem status event enumeration entry.</param>
        /// <seealso cref="ModemStatusEvent"/>
        public ModemStatusPacket(ModemStatusEvent modemStatusEvent)
            : base(APIFrameType.MODEM_STATUS)
        {
            Status = modemStatusEvent;
        }
コード例 #12
0
 public void modemStatusEventReceived(ModemStatusEvent modemStatusEvent)
 {
     if (modemStatusEvent == ModemStatusEvent.STATUS_HARDWARE_RESET
             || modemStatusEvent == ModemStatusEvent.STATUS_WATCHDOG_TIMER_RESET)
     {
         _device.modemStatusReceived = true;
         // Continue execution by notifying the lock object.
         lock (_device.resetLock)
         {
             Monitor.Pulse(_device.resetLock);
         }
     }
 }
コード例 #13
0
        /**
         * Notifies subscribed Modem Status listeners that a Modem Status event
         * packet has been received.
         *
         * @param modemStatusEvent The Modem Status event.
         *
         * @see com.digi.xbee.api.models.ModemStatusEvent
         */
        private void NotifyModemStatusReceived(ModemStatusEvent modemStatusEvent)
        {
            logger.Debug(connectionInterface.ToString() + "Modem Status event received.");

            try
            {
                lock (modemStatusListeners)
                {
                    var runTask = new Action<IModemStatusReceiveListener>(listener =>
                    {
                        lock (listener)
                        {
                            listener.modemStatusEventReceived(modemStatusEvent);
                        }
                    });
                    //ScheduledExecutorService executor = Executors.newScheduledThreadPool(Math.Min(MAXIMUM_PARALLEL_LISTENER_THREADS,
                    //		modemStatusListeners.size()));
                    foreach (IModemStatusReceiveListener listener in modemStatusListeners)
                    {
                        Task.Factory.StartNew((state) =>
                            runTask((IModemStatusReceiveListener)state), listener);
                        //executor.execute(new Runnable() {
                        //	/*
                        //	 * (non-Javadoc)
                        //	 * @see java.lang.Runnable#run()
                        //	 */
                        //	//@Override
                        //	public void run() {
                        //		// Synchronize the listener so it is not called
                        //		// twice. That is, let the listener to finish its job.
                        //		lock (listener) {
                        //			listener.modemStatusEventReceived(modemStatusEvent);
                        //		}
                        //	}
                        //});
                    }
                    //executor.shutdown();
                }
            }
            catch (Exception e)
            {
                logger.Error(e.Message, e);
            }
        }