|
| 1 | +namespace RS485_Monitor.tests; |
| 2 | +using NUnit.Framework; |
| 3 | + |
| 4 | +public class BaseTelegramTest |
| 5 | +{ |
| 6 | + [Test] |
| 7 | + public void ParseTelegramSuccessful() |
| 8 | + { |
| 9 | + byte[] raw = new byte[] { 0xB6, 0x6B, 0xAA, 0xDA, 0x0A, 0x02, 0x00, 0x04, 0x00, 0x00, 0x13, 0x00, 0x00, 0x02, 0x01, 0x1C, 0x0D }; |
| 10 | + |
| 11 | + BaseTelegram telegram = new(raw); |
| 12 | + |
| 13 | + Assert.That(telegram.Type, Is.EqualTo(BaseTelegram.TelegramType.READ_RESPONSE)); |
| 14 | + Assert.That(telegram.Destination, Is.EqualTo(0xDA)); |
| 15 | + Assert.That(telegram.Source, Is.EqualTo(0xAA)); |
| 16 | + Assert.That(telegram.Valid, Is.EqualTo(true)); |
| 17 | + } |
| 18 | + |
| 19 | + [Test] |
| 20 | + public void ParseTelegramRequestSuccessful() |
| 21 | + { |
| 22 | + byte[] raw = new byte[] { 0xC5, 0x5C, 0xAA, 0xDA, 0x0A, 0x02, 0x00, 0x04, 0x00, 0x00, 0x13, 0x00, 0x00, 0x02, 0x01, 0x1C, 0x0D }; |
| 23 | + |
| 24 | + BaseTelegram telegram = new(raw); |
| 25 | + |
| 26 | + Assert.That(telegram.Type, Is.EqualTo(BaseTelegram.TelegramType.READ_REQUEST)); |
| 27 | + Assert.That(telegram.Destination, Is.EqualTo(0xDA)); |
| 28 | + Assert.That(telegram.Source, Is.EqualTo(0xAA)); |
| 29 | + Assert.That(telegram.Valid, Is.EqualTo(true)); |
| 30 | + } |
| 31 | + |
| 32 | + [Test] |
| 33 | + public void ParseTelegramWrongChecksum() |
| 34 | + { |
| 35 | + byte[] raw = new byte[] { 0xB6, 0x6B, 0xAA, 0xDA, 0x0A, 0x02, 0x10, 0x04, 0x00, 0x00, 0x13, 0x00, 0x00, 0x02, 0x01, 0x1C, 0x0D }; |
| 36 | + |
| 37 | + BaseTelegram telegram = new(raw); |
| 38 | + |
| 39 | + Assert.That(telegram.Type, Is.EqualTo(BaseTelegram.TelegramType.READ_RESPONSE)); |
| 40 | + Assert.That(telegram.Destination, Is.EqualTo(0xDA)); |
| 41 | + Assert.That(telegram.Source, Is.EqualTo(0xAA)); |
| 42 | + Assert.That(telegram.Valid, Is.EqualTo(false)); |
| 43 | + } |
| 44 | + |
| 45 | +} |
0 commit comments