public async Task AckRespValidTestMethod() { byte[] expectedMessageBytes = new byte[] { 0x20, 0x20 }; var testStream = new MemoryStream(); var msgResp = new AckRespMessage(); await msgResp.WriteAsync(testStream); var actualMessageBytes = ReadStream(testStream); CollectionAssert.AreEqual(expectedMessageBytes, actualMessageBytes, string.Format("message not valid, expected {0}, received {1}", ByteArrayToString(expectedMessageBytes), ByteArrayToString(actualMessageBytes))); }
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); //} }
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); }