Exemplo n.º 1
0
 public static void OnBroadcastMessageReceived(BroadcastMessageReceivedEventArgs e)
 {
     var handler = BroadcastMessageReceived;
     if (handler != null)
     {
         handler(null, e);
     }
 }
Exemplo n.º 2
0
        public static void OnBroadcastMessageReceived(BroadcastMessageReceivedEventArgs e)
        {
            var handler = BroadcastMessageReceived;

            handler?.Invoke(null, e);
        }
Exemplo n.º 3
0
        internal async static void PacketReceived(Packet packet, Stream stream)
        {
            
            //Handle Direct return messages : it is possible this should be placed in the packet class!
            if (packet.Header == PacketHeaderType.CommandStationOperationResponse && packet.Payload[0] == Convert.ToByte(PacketIdentifier.CommandStationOperationResponse.TransferErrors))
            {
                var ackResp = new AckRespMessage();
                //if (XpressNetConstants.UseAsyncWrite)
                //{
                //    //ackResp.WriteAsync(stream);
                //}
                //else
                //{
                    await ackResp.WriteAsync(stream);
                //}
            }
            
            //Handle Broadcast Messages

            if (packet.Header == PacketHeaderType.EmergencyStopAll) 
            {
                var bmr = new BroadcastMessageReceivedEventArgs
                {
                    ResponseType = BroadcastType.EmergencyStop,
                    ReceivedTime = DateTime.Now
                };
                OnBroadcastMessageReceived(bmr);

                
            } 
            else if (packet.Header == PacketHeaderType.CommandStationOperationResponse && packet.Payload[0] == Convert.ToByte(PacketIdentifier.CommandStationOperationResponse.NormalOperationsResumedBroadcast))
            {
                var bmr = new BroadcastMessageReceivedEventArgs
                {
                    ResponseType = BroadcastType.NormalOperationResumed,
                    ReceivedTime = DateTime.Now
                };
                OnBroadcastMessageReceived(bmr);
            }
            else if (packet.Header == PacketHeaderType.CommandStationOperationResponse && packet.Payload[0] == Convert.ToByte(PacketIdentifier.CommandStationOperationResponse.TrackPowerOffBroadcast))
            {
                var bmr = new BroadcastMessageReceivedEventArgs
                {
                    ResponseType = BroadcastType.TrackPowerOff,
                    ReceivedTime = DateTime.Now
                };
                OnBroadcastMessageReceived(bmr);
            }
            else if (packet.Header == PacketHeaderType.CommandStationOperationResponse && packet.Payload[0] == Convert.ToByte(PacketIdentifier.CommandStationOperationResponse.ServiceModeEntryBroadcast))
            {
                var bmr = new BroadcastMessageReceivedEventArgs
                {
                    ResponseType = BroadcastType.ServiceModeEntry,
                    ReceivedTime = DateTime.Now
                };
                OnBroadcastMessageReceived(bmr);
            }
            else if (packet.Header == PacketHeaderType.AccessoryDecoderInformation)
            {
                var bmr = new BroadcastMessageReceivedEventArgs
                {
                    ResponseType = BroadcastType.AccessoryFeedback,
                    ReceivedTime = DateTime.Now
                };
                //bmr.Response = 
                OnBroadcastMessageReceived(bmr);
            }
            //else if (packet.Header == PacketHeaderType.LocomotiveFunction && packet.Payload[0] == Convert.ToByte(PacketIdentifier.LocomotiveFunctionResponses.LocomotiveOperatedByAnotherDevice))
            //{
            //BroadcastMessageReceivedEventArgs bmr = new BroadcastMessageReceivedEventArgs();
            //bmr.ResponseType = BroadcastType.LocomotiveOperatedByAnotherDevice;
            //bmr.Response = 
            //OnBroadcastMessageReceived(bmr);
            //}
            //else if (packet.Header == PacketHeaderType.LocomotiveFunction && packet.Payload[0] == Convert.ToByte(PacketIdentifier.LocomotiveFunctionResponses.LocomotiveDoubleHeaderOccupied))
            //{
            //BroadcastMessageReceivedEventArgs bmr = new BroadcastMessageReceivedEventArgs();
            //bmr.ResponseType = BroadcastType.DoubleHeaderOccupied;
            //bmr.Response = 
            //OnBroadcastMessageReceived(bmr);
            //}

            //else //we may wish to send the broadcasts on anyway so this else may have to be removed!!
            //{
                var pump = new PacketRouter();
                pump.DisseminatePacket(packet);
            //}
        }
Exemplo n.º 4
0
        internal static async void PacketReceived(Packet packet, Stream stream)
        {
            //Handle Direct return messages : it is possible this should be placed in the packet class!
            if (packet.Header == PacketHeaderType.CommandStationOperationResponse && packet.Payload[0] == Convert.ToByte(PacketIdentifier.CommandStationOperationResponse.TransferErrors))
            {
                var ackResp = new AckRespMessage();
                //if (XpressNetConstants.UseAsyncWrite)
                //{
                //    //ackResp.WriteAsync(stream);
                //}
                //else
                //{
                await ackResp.WriteAsync(stream);

                //}
            }

            //Handle Broadcast Messages

            if (packet.Header == PacketHeaderType.EmergencyStopAll)
            {
                var bmr = new BroadcastMessageReceivedEventArgs
                {
                    ResponseType = BroadcastType.EmergencyStop,
                    ReceivedTime = DateTime.Now
                };
                OnBroadcastMessageReceived(bmr);
            }
            else if (packet.Header == PacketHeaderType.CommandStationOperationResponse && packet.Payload[0] == Convert.ToByte(PacketIdentifier.CommandStationOperationResponse.NormalOperationsResumedBroadcast))
            {
                var bmr = new BroadcastMessageReceivedEventArgs
                {
                    ResponseType = BroadcastType.NormalOperationResumed,
                    ReceivedTime = DateTime.Now
                };
                OnBroadcastMessageReceived(bmr);
            }
            else if (packet.Header == PacketHeaderType.CommandStationOperationResponse && packet.Payload[0] == Convert.ToByte(PacketIdentifier.CommandStationOperationResponse.TrackPowerOffBroadcast))
            {
                var bmr = new BroadcastMessageReceivedEventArgs
                {
                    ResponseType = BroadcastType.TrackPowerOff,
                    ReceivedTime = DateTime.Now
                };
                OnBroadcastMessageReceived(bmr);
            }
            else if (packet.Header == PacketHeaderType.CommandStationOperationResponse && packet.Payload[0] == Convert.ToByte(PacketIdentifier.CommandStationOperationResponse.ServiceModeEntryBroadcast))
            {
                var bmr = new BroadcastMessageReceivedEventArgs
                {
                    ResponseType = BroadcastType.ServiceModeEntry,
                    ReceivedTime = DateTime.Now
                };
                OnBroadcastMessageReceived(bmr);
            }
            else if (packet.Header == PacketHeaderType.AccessoryDecoderInformation)
            {
                var bmr = new BroadcastMessageReceivedEventArgs
                {
                    ResponseType = BroadcastType.AccessoryFeedback,
                    ReceivedTime = DateTime.Now
                };
                OnBroadcastMessageReceived(bmr);
            }

            var pump = new PacketRouter();

            pump.DisseminatePacket(packet);
        }