Merged in f5soh/librepilot/update_credits (pull request #529)
[librepilot.git] / flight / libraries / PyMite / tools / pmOdDecoder.py
blobe17a59bf32ec66cd38d0baf4964e407b8cc2c02a
1 #!/usr/bin/env python
3 # This file is Copyright 2009, 2010 Dean Hall.
5 # This file is part of the Python-on-a-Chip program.
6 # Python-on-a-Chip is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1.
9 # Python-on-a-Chip is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 # A copy of the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1
13 # is seen in the file COPYING in this directory.
15 """
16 PyMite Object Descriptor Decoder
17 ================================
19 Decodes an object descriptor value into its bit fields.
20 """
22 ## @file
23 # @copybrief pmOldDecoder
25 ## @package pmOldDecoder
26 # @brief PyMite Object Descriptor Decoder
28 # Decodes an object descriptor value into its bit fields.
31 import sys, pprint
34 __usage__ = """USAGE:
35 ./pmOdDecoder.py odvalue
36 """
39 TYPES = (
40 'OBJ_TYPE_NON',
41 'OBJ_TYPE_INT',
42 'OBJ_TYPE_FLT',
43 'OBJ_TYPE_STR',
44 'OBJ_TYPE_TUP',
45 'OBJ_TYPE_COB',
46 'OBJ_TYPE_MOD',
47 'OBJ_TYPE_CLO',
48 'OBJ_TYPE_FXN',
49 'OBJ_TYPE_CLI',
50 'OBJ_TYPE_CIM',
51 'OBJ_TYPE_NIM',
52 'OBJ_TYPE_NOB',
53 'OBJ_TYPE_THR',
54 0x0E,
55 'OBJ_TYPE_BOOL',
56 'OBJ_TYPE_CIO',
57 'OBJ_TYPE_MTH',
58 'OBJ_TYPE_LST',
59 'OBJ_TYPE_DIC',
60 0x14,0x15,0x16,0x17,0x18,
61 'OBJ_TYPE_FRM',
62 'OBJ_TYPE_BLK',
63 'OBJ_TYPE_SEG',
64 'OBJ_TYPE_SGL',
65 'OBJ_TYPE_SQI',
66 'OBJ_TYPE_NFM',
70 def od_decode(odvalue):
71 return {
72 "val": odvalue,
73 "size": (odvalue & 0x001F) * 4,
74 "type": TYPES[(odvalue & 0x3E00) >> 9],
75 "mark": (odvalue & 0x4000) >> 14,
76 "free": (odvalue & 0x8000) >> 15,
80 def to_int(s):
81 if s.startswith("0x"):
82 return int(s, 16)
83 return int(s)
86 def main():
87 odvalues = sys.argv[1:]
88 odvalues = map(to_int, odvalues)
89 ods = map(od_decode, odvalues)
90 for od in ods:
91 print("%d (0x%04x): %s[%d], f=%d, m=%d"
92 % (od['val'], od['val'], od['type'], od['size'], od['free'], od['mark']))
95 if __name__ == "__main__":
96 main()