-
Notifications
You must be signed in to change notification settings - Fork 0
/
a1.py
59 lines (47 loc) · 1.5 KB
/
a1.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
#! /usr/bin/env python3
#coding: utf-8
#
# arguments are as following
# id room region order priority ccm_type cmope fval
import sys
import struct
LC_CMPOPE_START = 0x5000
LC_CMPOPE_REC_SIZE = 0x20
def byte_arrange(b):
y = hex(b).replace('0x','').rjust(2,'0')
return y
def string_arrange(s,l):
rt = ""
cnt= 0
for c in s:
if cnt>=l:
return rt
b = hex(ord(c)).replace('0x','').rjust(2,'0')
rt += b
cnt += 1
return rt
##########################################################
if __name__ == '__main__':
args = sys.argv
id = int(args[1])
room = int(args[2])
region = int(args[3])
order = int(args[4])
priority = int(args[5])
ccmtype = args[6]
cmope = int(args[7])
fval = float(args[8])
addr = hex(id*LC_CMPOPE_REC_SIZE+LC_CMPOPE_START).replace('0x','').rjust(4,'0')
ih_valid = byte_arrange(1)
ih_room = byte_arrange(room)
ih_region = byte_arrange(region)
order_o = hex(order).replace('0x','').rjust(4,'0')
ih_order = order_o[2:4]+order_o[0:2]
ih_priority = byte_arrange(priority)
ih_ccmtype = string_arrange(ccmtype,20)
ih_cmope = byte_arrange(cmope)
ih_fval = hex(struct.unpack('>I',struct.pack('>f',fval))[0]).replace('0x','')
ihtxt = ih_valid+ih_room+ih_region+ih_order+ih_priority+ih_ccmtype+ih_cmope+ih_fval
sz = hex(int(len(ihtxt)/2)).replace('0x','').rjust(2,'0')
ih =":"+sz+addr+"00"+ihtxt+"FF"
print(ih)