-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathTransmissionSequence.cs
64 lines (50 loc) · 2.13 KB
/
TransmissionSequence.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using System;
using ProgrammingChallenge2.Codecs;
using ProgrammingChallenge2.Model;
namespace ProgrammingChallenge2
{
public class TransmissionSequence
{
public long Run(IDataSource source, IEncoder encoder, IDecoder decoder, long msgCount, bool debug)
{
long totalBytesTransmitted = 0;
for (long i = 0; i < msgCount; i++)
{
var sourceData = source.GetNextDataPoint();
var encodedData = encoder.Encode(sourceData);
// This is where the data is normally transmitted via network
totalBytesTransmitted += encodedData.LongLength;
var decodedData = decoder.Decode(encodedData);
var areEqual = IotDevice.AreEquals(sourceData, decodedData, false);
if (!areEqual || debug)
{
Console.WriteLine();
Console.WriteLine("##########################################################");
Console.WriteLine($"Message number: {i + 1}");
Console.WriteLine();
Console.WriteLine("source data:");
Console.WriteLine(sourceData);
Console.WriteLine();
Console.WriteLine("encoded data:");
Console.WriteLine(BitConverter.ToString(encodedData).Replace("-", ""));
Console.WriteLine();
Console.WriteLine("decoded data:");
Console.WriteLine(decodedData);
Console.WriteLine();
if (!areEqual)
{
// run this again to get debug outputs
IotDevice.AreEquals(sourceData, decodedData, true);
}
Console.WriteLine($"Encoding/Decoding successful: {areEqual}");
}
if (debug)
{
Console.WriteLine("Press any key to send the next message.");
Console.ReadKey();
}
}
return totalBytesTransmitted;
}
}
}