Browse Source

more tools

mwaiblinger 3 months ago
parent
commit
584c263eaa
2 changed files with 96 additions and 0 deletions
  1. 41
    0
      tools/data2obj.py
  2. 55
    0
      tools/obj2data.py

+ 41
- 0
tools/data2obj.py View File

@@ -0,0 +1,41 @@
1
+#! /usr/bin/env python
2
+import sys
3
+
4
+msg_id=int(str(sys.argv[1]),0) & 0x1FFFFFFF
5
+msg_prio=msg_id>>26
6
+msg_type=(msg_id>>24) & 0x03
7
+msg_dst=(msg_id>>16) & 0xFF
8
+msg_src=(msg_id>>8) & 0xFF
9
+msg_cmd=msg_id & 0xFF
10
+
11
+#print('id: {0:b}'.format(msg_id))
12
+print('id: {0:#010x} {0:#031b}'.format(msg_id ,msg_id))
13
+#print("id:", hex(msg_id), format(40,str(bin(msg_id))))
14
+
15
+print('prio: {0:#03x}       {0:#04b}'.format(msg_prio))
16
+print('type: {0:#03x}       {0:#04b}'.format(msg_type))
17
+print('dst: {0:#04x} {0:#010b}'.format(msg_dst))
18
+print('src: {0:#04x} {0:#010b}'.format(msg_src))
19
+print('cmd: {0:#04x} {0:#010b}'.format(msg_cmd))
20
+
21
+
22
+nmsg_prio=msg_id>>26
23
+nmsg_type=(msg_id>>24) & 0x03
24
+nmsg_src=(msg_id>>18) & 0x3F
25
+nmsg_dst=(msg_id>>12) & 0x3F
26
+nmsg_targ=(msg_id>>6) & 0x3F
27
+nmsg_cmd=msg_id & 0x1F
28
+
29
+
30
+print('New schema')
31
+
32
+#print('id: {0:b}'.format(msg_id))
33
+print('id: {0:#010x} {0:#031b}'.format(msg_id))
34
+#print("id:", hex(msg_id), format(40,str(bin(msg_id))))
35
+
36
+print('prio:   {0:#04x} {0:#04b}'.format(nmsg_prio))
37
+print('type:   {0:#04x} {0:#04b}'.format(nmsg_type))
38
+print('src:    {0:#04x} {0:#08b}'.format(nmsg_src))
39
+print('dst:    {0:#04x} {0:#08b}'.format(nmsg_dst))
40
+print('target: {0:#04x} {0:#08b}'.format(nmsg_targ))
41
+print('cmd:    {0:#04x} {0:#07b}'.format(nmsg_cmd))

+ 55
- 0
tools/obj2data.py View File

@@ -0,0 +1,55 @@
1
+#! /usr/bin/env python
2
+import sys
3
+import json
4
+#stuff = json.loads(sys.argv[1])
5
+
6
+
7
+#data = json.load(sys.stdin)
8
+
9
+
10
+#print(json.dumps(sys.stdin, sort_keys=True, indent=4))
11
+###print str(sys.argv[1])
12
+#print(stuff['foo'])
13
+
14
+#print(json.dumps(data, indent=4))
15
+
16
+#msg_id=int(str(sys.argv[1]),0)
17
+#msg_prio=msg_id>>26
18
+#msg_type=(msg_id>>24) & 0x03
19
+#msg_dst=(msg_id>>16) & 0xFF
20
+#msg_src=(msg_id>>8) & 0xFF
21
+#msg_cmd=msg_id & 0xFF
22
+
23
+#print "id:", hex(msg_id), bin(msg_id)
24
+#print "prio:", hex(msg_prio), bin(msg_prio)
25
+#print "type:", hex(msg_type), bin(msg_type)
26
+#print "dst:", hex(msg_dst), bin(msg_dst)
27
+#print "src:", hex(msg_src), bin(msg_src)
28
+#print "cmd:", hex(msg_cmd), bin(msg_cmd)
29
+import sys
30
+import simplejson as json
31
+
32
+
33
+def main(args):
34
+    try:
35
+        inputFile = open(args[1])
36
+        input = json.load(inputFile)
37
+        inputFile.close()
38
+    except IndexError:
39
+        usage()
40
+        return False
41
+    if len(args) < 3:
42
+        print json.dumps(input, sort_keys = False, indent = 10)
43
+    else:
44
+        outputFile = open(args[2], "w")
45
+        json.dump(input, outputFile, sort_keys = False, indent = 4)
46
+        outputFile.close()
47
+    return True
48
+
49
+
50
+def usage():
51
+    print __doc__
52
+
53
+
54
+if __name__ == "__main__":
55
+    sys.exit(not main(sys.argv))