-
Notifications
You must be signed in to change notification settings - Fork 0
/
econding.py
126 lines (95 loc) · 2.61 KB
/
econding.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
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
__author__ = 'dragosmc'
# typedef struct tagFIS_REG_H2D
# {
# // DWORD 0
# BYTE fis_type; // FIS_TYPE_REG_H2D
#
# BYTE pmport:4; // Port multiplier
# BYTE rsv0:3; // Reserved
# BYTE c:1; // 1: Command, 0: Control
#
# BYTE command; // Command register
# BYTE featurel; // Feature register, 7:0
#
# // DWORD 1
# BYTE lba0; // LBA low register, 7:0
# BYTE lba1; // LBA mid register, 15:8
# BYTE lba2; // LBA high register, 23:16
# BYTE device; // Device register
#
# // DWORD 2
# BYTE lba3; // LBA register, 31:24
# BYTE lba4; // LBA register, 39:32
# BYTE lba5; // LBA register, 47:40
# BYTE featureh; // Feature register, 15:8
#
# // DWORD 3
# BYTE countl; // Count register, 7:0
# BYTE counth; // Count register, 15:8
# BYTE icc; // Isochronous command completion
# BYTE control; // Control register
#
# // DWORD 4
# BYTE rsv1[4]; // Reserved
# } FIS_REG_H2D;
class regH2d:
def __init__(self):
# DWORD 0
self.fis_type = 0x34
self.pmport = 0x0
self.c = 0x01
self.command = 0xEC
self.feature = 0x00
# DWORD 1
self.lba0 = 0x00
self.lba1 = 0x00
self.lba2 = 0x00
self.device = 0x0
# DWORD 2
self.lba3 = 0x00
self.lba4 = 0x00
self.lba5 = 0x00
self.feature = 0x00
# DWORD 3
self.countl = 0x00
self.counth = 0x00
self.icc = 0x00
self.control = 0x00
# DWORD 4
self.rsv1 = 0x0
def to_byte_array(self):
btrl = bytearray(self.fis_type)
print binascii.hexlify(btrl)
temp = bytearray(self.pmport)
btrl = btrl + temp
temp = bytearray(self.c)
btrl = btrl + temp
temp = bytearray(self.command)
btrl = btrl + temp
temp = bytearray(self.feature)
btrl = btrl + temp
temp = bytearray(self.lba0)
btrl = btrl + temp
temp = bytearray(self.lba1)
btrl = btrl + temp
temp = bytearray(self.lba2)
btrl = btrl + temp
temp = bytearray(self.device)
btrl = btrl + temp
temp = bytearray(self.lba3)
btrl = btrl + temp
temp = bytearray(self.lba4)
btrl = btrl + temp
temp = bytearray(self.lba5)
btrl = btrl + temp
temp = bytearray(self.feature)
btrl = btrl + temp
temp = bytearray(self.countl)
btrl = btrl + temp
temp = bytearray(self.counth)
btrl = btrl + temp
temp = bytearray(self.icc)
btrl = btrl + temp
temp = bytearray(self.control)
btrl = btrl + temp
return btrl