diff --git a/Lawo.EmberPlusSharp/S101/S101Robot.cs b/Lawo.EmberPlusSharp/S101/S101Robot.cs index 7d87bf42..934f701f 100644 --- a/Lawo.EmberPlusSharp/S101/S101Robot.cs +++ b/Lawo.EmberPlusSharp/S101/S101Robot.cs @@ -122,7 +122,7 @@ private async void SendMessages() private async void OnClientEmberDataReceived(object sender, MessageReceivedEventArgs e) { - await this.taskQueue.Enqueue(() => this.ProcessIncoming(e)); + await this.taskQueue.Enqueue(() => this.ProcessIncomingMessage(e)); } private void OnClientConnectionLost(object sender, ConnectionLostEventArgs e) @@ -140,21 +140,18 @@ private async Task SendMessagesAsync() switch (this.logReader.EventType) { case "OutOfFrameByte": - await this.client.SendOutOfFrameByteAsync(this.logReader.GetPayload()[0]); + if (!await this.SendEvent(() => this.client.SendOutOfFrameByteAsync( + this.logReader.GetPayload()[0]))) + { + return; + } + break; case "Message": if (this.logReader.Message.Command is EmberData) { - if (this.firstMessageDirection == null) - { - this.firstMessageDirection = this.logReader.Direction; - } - - if (this.sendFirstMessage == (this.firstMessageDirection == this.logReader.Direction)) - { - await this.client.SendMessageAsync(this.logReader.Message, this.logReader.GetPayload()); - } - else + if (!await this.SendEvent(() => this.client.SendMessageAsync( + this.logReader.Message, this.logReader.GetPayload()))) { return; } @@ -176,7 +173,7 @@ private async Task SendMessagesAsync() } [SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "The exception is forwarded.")] - private Task ProcessIncoming(MessageReceivedEventArgs e) + private Task ProcessIncomingMessage(MessageReceivedEventArgs e) { try { @@ -203,6 +200,24 @@ private Task ProcessIncoming(MessageReceivedEventArgs e) return this.SendMessagesAsync(); } + private async Task SendEvent(Func sendOperation) + { + if (this.firstMessageDirection == null) + { + this.firstMessageDirection = this.logReader.Direction; + } + + if (this.sendFirstMessage == (this.firstMessageDirection == this.logReader.Direction)) + { + await sendOperation(); + return true; + } + else + { + return false; + } + } + private string ToXml(byte[] payload) { var xml = new StringBuilder(payload.Length * 10); diff --git a/Lawo.EmberPlusSharpTest/Model/GlowLoggerProxyTest.cs b/Lawo.EmberPlusSharpTest/Model/GlowLoggerProxyTest.cs index ef8ebd8d..5f2a7960 100644 --- a/Lawo.EmberPlusSharpTest/Model/GlowLoggerProxyTest.cs +++ b/Lawo.EmberPlusSharpTest/Model/GlowLoggerProxyTest.cs @@ -48,10 +48,11 @@ public void MainTest() typeof(ModelPayloads), "SapphireLog.xml")) using (var reader = XmlReader.Create(resourceStream)) { - var robotTask = S101Robot.RunAsync(proS101, GlowTypes.Instance, reader, false); + var robotTask = S101Robot.RunAsync(proS101, GlowTypes.Instance, reader, true); using (var con = await Consumer.CreateAsync(conS101)) { + await conS101.SendOutOfFrameByteAsync(0x00); await robotTask; } } diff --git a/Lawo.EmberPlusSharpTest/Model/Test/EmberDataPayloads/SapphireLog.xml b/Lawo.EmberPlusSharpTest/Model/Test/EmberDataPayloads/SapphireLog.xml index 492df242..4baa3c80 100644 --- a/Lawo.EmberPlusSharpTest/Model/Test/EmberDataPayloads/SapphireLog.xml +++ b/Lawo.EmberPlusSharpTest/Model/Test/EmberDataPayloads/SapphireLog.xml @@ -1,6 +1,6 @@ - + 00 00 EmberData 01 0A 02 @@ -12,8 +12,6 @@ - FE000E00018001020A0260806B80A0806280A0030201200000000000000000EDFDDDFFFE000E00016001020A021353FF - FE000E0001C001021F02601F6B1DA01B6319A003020101A1123110A00A0C085361707068697265A1020C0085E5FF 00 EmberData 01 1F 02 @@ -45,8 +43,6 @@ - FE000E010194E4FF - FE000E00018001020A0260806B80A0806A80A0030D0101A2806480A0806280A003020120000000000000000000000000000000008BD2FFFE000E00016001020A021353FF 00 KeepAliveRequest @@ -57,8 +53,6 @@ KeepAliveResponse - FE000E0201FDDCCEFF - FE000E0001C001021F0260456B43A01B6A19A0040D020101A111310FA0090C07536F7572636573A1020C00A0246A22A0040D020102A11A3118A00A0C086964656E74697479A10A0C086964656E74697479FDDAFDD8FF 00 EmberData 01 1F 02 @@ -105,8 +99,6 @@ - FE000E00018001020A0260806B80A0806A80A0040D020101A2806480A0806280A003020120000000000000000000000000A0806A80A0040D020102A2806480A0806280A00302012000000000000000000000000000000000E832FFFE000E00016001020A021353FF - FE000E0001C001021F02608200C76B8200C3A01B6A19A0050D03010101A110310EA0080C064650474D2031A1020C00A01B6A19A0050D03010102A110310EA0080C064650474D2032A1020C00A0346932A0050D03010201A1293127A0090C0770726F64756374A1090C0770726F64756374A503020103A20A0C087361707068697265A051694FA0050D03010202A1463144A0090C07636F6D70616E79A1090C07636F6D70616E79A503020103A2270C25286329204C2D532D422042726F61646361737420546563686E6F6C6F6769657320476D6248EECAFF 00 EmberData 01 1F 02 @@ -171,8 +163,6 @@ - FE000E00018001020A0260806B80A0806A80A0050D03010101A2806480A0806280A003020120000000000000000000000000A0806A80A0050D03010102A2806480A0806280A00302012000000000000000000000000000000000C091FFFE000E00016001020A021353FF - FE000E0001C001021F02608201246B820120A01B6A19A0060D0401010102A10F310DA0070C054661646572A1020C00A0196A17A0060D0401010103A10D310BA0050C03445350A1020C00A0566954A0060D0401010101A14A3148A00C0C0A417564696F2054797065A503020101A72E0C2C4E6F6E650A4D6F6E6F0A53746572656F0A537572726F756E6420352E310A537572726F756E6420352E312B32A203020102A01B6A19A0060D0401010202A10F310DA0070C054661646572A1020C00A0196A17A0060D0401010203A10D310BA0050C03445350A1020C00A0566954A0060D0401010201A14A3148A00C0C0A417564696F2054797065A503020101A72E0C2C4E6F6E650A4D6F6E6F0A53746572656F0A537572726F756E6420352E310A537572726F756E6420352E312B32A2030201022839FF 00 EmberData 01 1F 02 @@ -275,8 +265,6 @@ Surround 5.1+2 - FE000E00018001020A0260806B80A0806A80A0060D0401010102A2806480A0806280A003020120000000000000000000000000A0806A80A0060D0401010103A2806480A0806280A003020120000000000000000000000000A0806A80A0060D0401010202A2806480A0806280A003020120000000000000000000000000A0806A80A0060D0401010203A2806480A0806280A003020120000000000000000000000000000000000EA5FFFE000E00016001020A021353FF - FE000E0001C001021F02608201B36B8201AFA02D692BA0070D050101010201A120311EA0080C064E756D626572A503020101A403020178A303020100A203020101A03B6939A0070D050101010202A12E312CA00A0C0864422056616C7565A503020103A4050903800309A3050903C00801A20B0909C0071FFDDFFDDFFDDFFDDFFDDFBFA030692EA0070D050101010203A1233121A00A0C08506F736974696F6EA503020103A404020200FDDFA303020100A203020100A01C6A1AA0070D050101010301A10F310DA0070C05496E707574A1020C00A01C6A1AA0070D050101010302A10F310DA0070C0544656C6179A1020C00A02D692BA0070D050101020201A120311EA0080C064E756D626572A503020101A403020178A303020100A203020102A0356933A0070D050101020202A1283126A00A0C0864422056616C7565A503020103A4050903800309A3050903C00801A2050903800309A031692FA0070D050101020203A1243122A00A0C08506F736974696F6EA503020103A404020200FDDFA303020100A204020200FDDFA01C6A1AA0070D050101020301A10F310DA0070C05496E707574A1020C00A01C6A1AA0070D050101020302A10F310DA0070C0544656C6179A1020C001045FF 00 EmberData 01 1F 02 @@ -413,8 +401,6 @@ Surround 5.1+2 - FE000E00018001020A0260806B80A0806A80A0070D050101010301A2806480A0806280A003020120000000000000000000000000A0806A80A0070D050101010302A2806480A0806280A003020120000000000000000000000000A0806A80A0070D050101020301A2806480A0806280A003020120000000000000000000000000A0806A80A0070D050101020302A2806480A0806280A00302012000000000000000000000000000000000D8BCFFFE000E00016001020A021353FF - FE000E0001C001021F02608201AE6B8201AAA02F692DA0080D06010101030101A121311FA0060C044761696EA503020103A4050903800409A3050903C0040FA2020900A0236921A0080D06010101030102A1153113A0070C055068617365A503020103A2030101FDDFA04A6948A0080D06010101030103A13C313AA0090C074C52204D6F6465A503020103A7230C2173746572656F0A722D3E620A736964650A6C2D3E620A6D6F6E6F0A6D732D3E7879A203020100A031692FA0080D06010101030201A1233121A00B0C0954696D6520286D7329A503020103A4050903800855A3020900A2020900A02F692DA0080D06010102030101A121311FA0060C044761696EA503020103A4050903800409A3050903C0040FA2020900A0236921A0080D06010102030102A1153113A0070C055068617365A503020103A203010100A04A6948A0080D06010102030103A13C313AA0090C074C52204D6F6465A503020103A7230C2173746572656F0A722D3E620A736964650A6C2D3E620A6D6F6E6F0A6D732D3E7879A203020100A031692FA0080D06010102030201A1233121A00B0C0954696D6520286D7329A503020103A4050903800855A3020900A20209009232FF 00 EmberData 01 1F 02 @@ -507,6 +493,5 @@ ms->xy - - + 00 \ No newline at end of file