Skip to content

Commit a3e535b

Browse files
committed
- formated library source code
1 parent 865c47c commit a3e535b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+14810
-12873
lines changed

lib60870/ASDUParsingException.cs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,14 @@
2323

2424
namespace lib60870
2525
{
26-
[Serializable]
27-
public class ASDUParsingException : Exception
28-
{
29-
30-
31-
public ASDUParsingException (string message) : base(message)
32-
{
33-
34-
}
35-
}
26+
[Serializable]
27+
public class ASDUParsingException : Exception
28+
{
29+
public ASDUParsingException(string message)
30+
: base(message)
31+
{
32+
}
33+
}
3634
}
3735

3836

lib60870/BufferFrame.cs

Lines changed: 49 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -23,61 +23,64 @@
2323

2424
namespace lib60870
2525
{
26-
/// <summary>
27-
/// Implementation of Frame to encode into a given byte array
28-
/// </summary>
29-
internal class BufferFrame : Frame {
26+
/// <summary>
27+
/// Implementation of Frame to encode into a given byte array
28+
/// </summary>
29+
internal class BufferFrame : Frame
30+
{
31+
private byte[] buffer;
32+
private int startPos;
33+
private int bufPos;
3034

31-
private byte[] buffer;
32-
private int startPos;
33-
private int bufPos;
35+
public BufferFrame(byte[] buffer, int startPos)
36+
{
37+
this.buffer = buffer;
38+
this.startPos = startPos;
39+
this.bufPos = startPos;
40+
}
3441

35-
public BufferFrame(byte[] buffer, int startPos) {
36-
this.buffer = buffer;
37-
this.startPos = startPos;
38-
this.bufPos = startPos;
39-
}
42+
public BufferFrame Clone()
43+
{
44+
byte[] newBuffer = new byte[GetMsgSize()];
4045

41-
public BufferFrame Clone()
42-
{
43-
byte[] newBuffer = new byte[GetMsgSize()];
46+
int newBufPos = 0;
4447

45-
int newBufPos = 0;
48+
for (int i = startPos; i < bufPos; i++)
49+
{
50+
newBuffer[newBufPos++] = buffer[i];
51+
}
4652

47-
for (int i = startPos; i < bufPos; i++) {
48-
newBuffer [newBufPos++] = buffer [i];
49-
}
53+
BufferFrame clone = new BufferFrame(newBuffer, 0);
54+
clone.bufPos = newBufPos;
5055

51-
BufferFrame clone = new BufferFrame (newBuffer, 0);
52-
clone.bufPos = newBufPos;
56+
return clone;
57+
}
5358

54-
return clone;
55-
}
59+
public override void ResetFrame()
60+
{
61+
bufPos = startPos;
62+
}
5663

57-
public override void ResetFrame ()
58-
{
59-
bufPos = startPos;
60-
}
64+
public override void SetNextByte(byte value)
65+
{
66+
buffer[bufPos++] = value;
67+
}
6168

62-
public override void SetNextByte (byte value)
63-
{
64-
buffer [bufPos++] = value;
65-
}
69+
public override void AppendBytes(byte[] bytes)
70+
{
71+
for (int i = 0; i < bytes.Length; i++)
72+
buffer[bufPos++] = bytes[i];
73+
}
6674

67-
public override void AppendBytes (byte[] bytes)
68-
{
69-
for (int i = 0; i < bytes.Length; i++)
70-
buffer [bufPos++] = bytes [i];
71-
}
75+
public override int GetMsgSize()
76+
{
77+
return bufPos;
78+
}
7279

73-
public override int GetMsgSize () {
74-
return bufPos;
75-
}
76-
77-
public override byte[] GetBuffer ()
78-
{
79-
return buffer;
80-
}
81-
}
80+
public override byte[] GetBuffer()
81+
{
82+
return buffer;
83+
}
84+
}
8285
}
83-
86+

lib60870/CP16Time2a.cs

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,39 +25,42 @@
2525

2626
namespace lib60870
2727
{
28-
public class CP16Time2a
29-
{
30-
private byte[] encodedValue = new byte[2];
28+
public class CP16Time2a
29+
{
30+
private byte[] encodedValue = new byte[2];
3131

32-
internal CP16Time2a (byte[] msg, int startIndex)
33-
{
34-
if (msg.Length < startIndex + 3)
35-
throw new ASDUParsingException ("Message too small for parsing CP16Time2a");
32+
internal CP16Time2a(byte[] msg, int startIndex)
33+
{
34+
if (msg.Length < startIndex + 3)
35+
throw new ASDUParsingException("Message too small for parsing CP16Time2a");
3636

37-
for (int i = 0; i < 2; i++)
38-
encodedValue [i] = msg [startIndex + i];
39-
}
37+
for (int i = 0; i < 2; i++)
38+
encodedValue[i] = msg[startIndex + i];
39+
}
4040

41-
public CP16Time2a(int elapsedTimeInMs)
42-
{
43-
ElapsedTimeInMs = elapsedTimeInMs;
44-
}
41+
public CP16Time2a(int elapsedTimeInMs)
42+
{
43+
ElapsedTimeInMs = elapsedTimeInMs;
44+
}
4545

46-
public int ElapsedTimeInMs {
47-
get {
48-
return (encodedValue[0] + (encodedValue[1] * 0x100));
49-
}
46+
public int ElapsedTimeInMs
47+
{
48+
get
49+
{
50+
return (encodedValue[0] + (encodedValue[1] * 0x100));
51+
}
5052

51-
set {
52-
encodedValue [0] = (byte) (value % 0x100);
53-
encodedValue [1] = (byte) (value / 0x100);
54-
}
55-
}
53+
set
54+
{
55+
encodedValue[0] = (byte)(value % 0x100);
56+
encodedValue[1] = (byte)(value / 0x100);
57+
}
58+
}
5659

57-
public byte[] GetEncodedValue()
58-
{
59-
return encodedValue;
60-
}
60+
public byte[] GetEncodedValue()
61+
{
62+
return encodedValue;
63+
}
6164

6265
public override string ToString()
6366
{

0 commit comments

Comments
 (0)