forked from invveritas/PYIEC60870-104
/
GIFactory.py
65 lines (53 loc) · 2.13 KB
/
GIFactory.py
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
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 10 15:33:00 2015
GIFactory
Class used to build a GI command telegram
@author: Martin Baldinger / martin.baldinger@gmail.com
"""
from CommandFactory import CommandFactory
from myfunctions import int_to_hex_bytes
class GIFactory(CommandFactory):
"""
Extends CommandFactory class. It is used to send general interrogations.
"""
def __init__(self, ASDU):
"""
Builds the general interrogation command as a list of bytes.
"""
CommandFactory.__init__(self)
# 1) length of APDU
self.command.append(14)
# 2-5) Control Fields
# leave them all zero for the moment
# we need to care about them later, when trying to check whether
# telegrams arrived and were processed or not
self.command.append(self.ZERO_BYTE)
self.command.append(self.ZERO_BYTE)
self.command.append(self.ZERO_BYTE)
self.command.append(self.ZERO_BYTE)
# 6) Type Identification
self.command.append(self.TYPE_C_IC_NA_1)
# 7) SQ / Number of Objects
self.command.append(1)
# 8) T / P/N / Cause of Transmission
self.command.append(self.COT_ACTIVATION)
# COT is always "activation", even if switching off!!!
# 9) Originator Address
# this is always zero in our case
self.command.append(self.ZERO_BYTE)
# 10-11) ASDU address
asdu_bytes = int_to_hex_bytes(ASDU)
# - low octet
self.command.append(asdu_bytes[1])
# - high octet
self.command.append(asdu_bytes[0])
# 12-n) IOA is always zero for general interrogation command
# IOA - low octet
self.command.append(self.ZERO_BYTE)
# IOA - high octet
self.command.append(self.ZERO_BYTE)
# IOA - special - always 0 in our case
self.command.append(self.ZERO_BYTE)
# Object Information - always one byte in our case
self.command.append(self.GENERAL_INTERROGATION)