forked from Ebolon/iec104
-
Notifications
You must be signed in to change notification settings - Fork 0
/
acpi.py
53 lines (36 loc) · 1005 Bytes
/
acpi.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
# -*- coding: utf-8 -*-
import struct
TESTFR_CON = '\x83\x00\x00\x00'
TESTFR_ACT = [0x68,0x04,0x43,0x00]#'\x43\x00\x00\x00'
STOPDT_CON = '\x23\x00\x00\x00'
STOPDT_ACT = '\x13\x00\x00\x00'
STARTDT_CON = [0x68,0x04,0x0b,0x00]#'\x0b\x00\x00\x00'
STARTDT_ACT = '\x07\x00\x00\x00'
def start_act_frame():
frame = [None]*6
frame[0] = 0x68
frame[1] = 0x04
frame[2] = 0x07
frame[3] = 0x00
frame[4] = 0x00
frame[5] = 0x00
return frame
def testfr_con_frame():
frame = [None]*6
frame[0] = 0x68
frame[1] = 0x04
frame[2] = 0x83
frame[3] = 0x00
frame[4] = 0x00
frame[5] = 0x00
return frame
def i_frame(ssn, rsn):
return struct.pack('<1BHH', 0x64, ssn << 1, rsn << 1)
def s_frame(rsn):
return struct.pack('<3BH', 0x64, 0x01, 0x00, rsn << 1)
def parse_i_frame(data):
ssn, rsn = struct.unpack('<2H', data)
return ssn >> 1, rsn >> 1
def parse_s_frame(data):
rsn = struct.unpack_from('<2H', data)[1]
return rsn >> 1