-
Notifications
You must be signed in to change notification settings - Fork 0
/
ATCommands.py
71 lines (54 loc) · 1.51 KB
/
ATCommands.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
import Constants
def GetVersion():
buffer = bytearray(10)
# header
buffer[0] = Constants.PREFIX
buffer[1] = Constants.CONNECTION_USB
buffer[2] = 2 # payload length
buffer[3] = Constants.TYPE_SILAB
buffer[4] = Constants.RESERVE
buffer[5] = Constants.LINK_DOWN
buffer[6] = 0
buffer[7] = 0
# payload
buffer[8] = 0xB0
buffer[9] = 0x00
return bytes(buffer)
def ResetAtmel():
buffer = bytearray(10)
# header
buffer[0] = Constants.PREFIX
buffer[1] = Constants.CONNECTION_USB
buffer[2] = 2 # payload length
buffer[3] = Constants.TYPE_SILAB
buffer[4] = Constants.RESERVE
buffer[5] = Constants.LINK_DOWN
buffer[6] = 0
buffer[7] = 0
# payload
buffer[8] = 0xB0
buffer[9] = 0x0C
return bytes(buffer)
def SendImageData(subpart_data, total_subpart, subpart, length):
buffer = bytearray(248)
# header
buffer[0] = Constants.PREFIX
buffer[1] = Constants.CONNECTION_USB
buffer[2] = 240 #payload length
buffer[3] = Constants.TYPE_SILAB
buffer[4] = Constants.RESERVE
buffer[5] = Constants.LINK_DOWN
buffer[6] = 0
buffer[7] = 0
# payload
buffer[8] = 0xB0
buffer[9] = 0x01
buffer[10] = (total_subpart >> 8) & 0xFF
buffer[11] = total_subpart & 0xFF
buffer[12] = (subpart >> 8) & 0xFF
buffer[13] = subpart & 0xFF
for i in range(0, length):
buffer[i + 14] = subpart_data[i]
for i in range(length, 234):
buffer[i + 14] = 0xFF
return bytes(buffer)