-
Notifications
You must be signed in to change notification settings - Fork 3
/
Iec61850State.cs
129 lines (123 loc) · 4.09 KB
/
Iec61850State.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
* Copyright (C) 2013 Pavel Charvat
*
* This file is part of IEDExplorer.
*
* IEDExplorer is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* IEDExplorer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with IEDExplorer. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.IO;
using System.Collections.Generic;
using System.Net.Sockets;
using System.Threading;
using MMS_ASN1_Model;
namespace IEDExplorer
{
class Iec61850State: TcpState
{
/// <summary>
/// Size of data buffer.
/// </summary>
public const int dataBufferSize = 2048;
/// <summary>
/// Index of receive buffer.
/// </summary>
public int dataBufferIndex = 0;
/// <summary>
/// TPKT Length
/// </summary>
public int TpktLen = 0;
/// <summary>
/// TPKT Datagram buffer.
/// </summary>
public byte[] dataBuffer = new byte[dataBufferSize];
/// <summary>
/// Upper level protocol state
/// </summary>
public Iec61850lStateEnum istate = Iec61850lStateEnum.IEC61850_STATE_START;
/// <summary>
/// TPKT Receive state
/// </summary>
public TpktState kstate = TpktState.TPKT_RECEIVE_START;
/// <summary>
/// OSI Receive state
/// </summary>
public OsiProtocolState ostate = OsiProtocolState.OSI_STATE_START;
/// <summary>
/// MMS File service state
/// </summary>
public FileTransferState fstate = FileTransferState.FILE_NO_ACTION;
/// <summary>
/// OSI Protocol emulation
/// </summary>
public OsiEmul osi = new OsiEmul();
/// <summary>
/// MMS Protocol emulation
/// </summary>
public Scsm_MMS mms = new Scsm_MMS();
/// <summary>
/// Input stream of MMS parsing
/// </summary>
public MemoryStream msMMS = new MemoryStream();
/// <summary>
/// Memory for continuation of requests
/// </summary>
public Identifier continueAfter;
/// <summary>
/// Memory for continuation of file directory requests
/// </summary>
public FileName continueAfterFileDirectory;
/// <summary>
/// Server data
/// </summary>
public NodeIed ied = new NodeIed("ied");
/// <summary>
/// Server named variable lists
/// </summary>
public NodeIed lists = new NodeIed("lists");
/// <summary>
/// Server RP blocks (reports)
/// </summary>
public NodeIed reports = new NodeIed("reports");
/// <summary>
/// Server files
/// </summary>
public NodeIed files = new NodeIed("files");
/// <summary>
/// Queue for sending data from another threads
/// </summary>
public Queue<WriteQueueElement> SendQueue = new Queue<WriteQueueElement>();
public ManualResetEvent sendQueueWritten = new ManualResetEvent(false);
public NodeBase[] lastOperationData = null;
public Iec61850State()
{
(ied as NodeIed).iecs = this;
(lists as NodeIed).iecs = this;
(files as NodeIed).iecs = this;
(reports as NodeIed).iecs = this;
}
public void NextState()
{
}
public void Send(NodeBase[] Data, CommAddress Address, ActionRequested Action)
{
WriteQueueElement el = new WriteQueueElement(Data, Address, Action);
lock (SendQueue)
{
SendQueue.Enqueue(el);
}
sendQueueWritten.Set();
}
}
}