11import xmltodict
22from typing import Dict
33from adidt .dt import dt
4+ from adidt .utils import profilewiz
45import fdt
56import math
67
@@ -11,92 +12,8 @@ def handle_ints(val):
1112 return int (hex ((val + (1 << 32 )) % (1 << 32 )), 16 )
1213
1314
14- def coefs_to_long_string (coefs ):
15- """Convert coefficient array to string.
16-
17- Args:
18- coefs (list): Coefficients.
19-
20- Returns:
21- str: Coefficients as a string.
22- """
23- result = ""
24- for coef in coefs .split ("\n " ):
25- coef = coef .replace (" " , "" )
26- result += f"({ coef } ) "
27- return result [:- 1 ]
28-
29-
30- def profile_to_xml (filename ):
31- # Update profile to non-shitty xml
32- with open (filename ) as sxmlfile :
33- sxmldata = sxmlfile .read ()
34- # Correct each header
35- outfile = []
36- for line in sxmldata .split ("\n " ):
37- if "<" in line and "</" not in line :
38- within = line [line .find ("<" ) + 1 : line .find (">" )]
39- # Fix all prop=val
40- if "," in within :
41- oline = []
42- # print(line)
43- for index , sline in enumerate (line .split (" " )):
44- if index == 3 :
45- sline = f"Bandwidth={ sline } "
46- if index in [4 , 6 ]:
47- sline = sline + "="
48- oline += [sline ]
49- line = " " .join (oline )
50- line = line .replace ("," , "" )
51- line = line .replace ("= " , "=" )
52- if " " in within :
53- # print(line)
54- oline = []
55- spaces = 0
56- for sline in line .split (" " ):
57- if len (sline ) > 0 :
58- starter = sline + " "
59- break
60- spaces += 1
61- for sline in line .split (" " ):
62- if (
63- len (oline ) == 0
64- and len (sline )
65- and "<" not in sline
66- and ">" not in sline
67- and "=" not in sline
68- ):
69- oline += [f'type="{ sline } "' ]
70- if "=" in sline :
71- sline = sline .replace (">" , "" )
72- sline = sline .replace ("<" , "" )
73- p = sline .split ("=" )[0 ]
74- v = sline .split ("=" )[1 ]
75- # print(f"{p}={v}")
76- oline += [f'{ p } ="{ v } "' ]
77-
78- # print(" "*spaces+starter+" ".join(oline)+">")
79- outfile += [" " * spaces + starter + " " .join (oline ) + ">" ]
80- else :
81- # print(line)
82- if "=" in line :
83- s1 = line .find ("<" )
84- s2 = line .find (">" )
85- within = line [s1 + 1 : s2 ]
86- o = within .split ("=" )
87- ss = f"{ o [0 ]} >{ o [1 ]} </{ o [0 ]} "
88- line = line .replace (within , ss )
89- # print(line)
90-
91- outfile += [line ]
92- else :
93- outfile += [line ]
94-
95- return "\n " .join (outfile )
96-
97-
9815def parse_profile (filename ):
99- nsxml = profile_to_xml (filename )
16+ nsxml = profilewiz . profile_to_xml (filename )
10017 profile = xmltodict .parse (nsxml )["profile" ]
10118
10219 rx = profile ['rx' ]
@@ -160,22 +77,22 @@ def parse_profile(filename):
16077
16178 tx ["filter" ]["@gain_dB" ] = f"({ tx ['filter' ]['@gain_dB' ]} )"
16279
163- rx ["rxAdcProfile" ]["coefs" ] = coefs_to_long_string (rx ["rxAdcProfile" ]["#text" ])
80+ rx ["rxAdcProfile" ]["coefs" ] = profilewiz . coefs_to_long_string (rx ["rxAdcProfile" ]["#text" ])
16481 del (rx ["rxAdcProfile" ]["#text" ])
165- rx ["filter" ]["coefs" ] = coefs_to_long_string (rx ["filter" ]["#text" ])
82+ rx ["filter" ]["coefs" ] = profilewiz . coefs_to_long_string (rx ["filter" ]["#text" ])
16683 del (rx ["filter" ]["#text" ])
16784
168- orx ["filter" ]["coefs" ] = coefs_to_long_string (orx ["filter" ]["#text" ])
85+ orx ["filter" ]["coefs" ] = profilewiz . coefs_to_long_string (orx ["filter" ]["#text" ])
16986 del (orx ["filter" ]["#text" ])
170- orx ["orxBandPassAdcProfile" ]["coefs" ] = coefs_to_long_string (orx ["orxBandPassAdcProfile" ]["#text" ])
87+ orx ["orxBandPassAdcProfile" ]["coefs" ] = profilewiz . coefs_to_long_string (orx ["orxBandPassAdcProfile" ]["#text" ])
17188 del (orx ["orxBandPassAdcProfile" ]["#text" ])
172- orx ["orxLowPassAdcProfile" ]["coefs" ] = coefs_to_long_string (orx ["orxLowPassAdcProfile" ]["#text" ])
89+ orx ["orxLowPassAdcProfile" ]["coefs" ] = profilewiz . coefs_to_long_string (orx ["orxLowPassAdcProfile" ]["#text" ])
17390 del (orx ["orxLowPassAdcProfile" ]["#text" ])
17491
175- tx ["filter" ]["coefs" ] = coefs_to_long_string (tx ["filter" ]["#text" ])
92+ tx ["filter" ]["coefs" ] = profilewiz . coefs_to_long_string (tx ["filter" ]["#text" ])
17693 del (tx ["filter" ]["#text" ])
17794
178- lpbk ["lpbkAdcProfile" ]["coefs" ] = coefs_to_long_string (lpbk ["lpbkAdcProfile" ]["#text" ])
95+ lpbk ["lpbkAdcProfile" ]["coefs" ] = profilewiz . coefs_to_long_string (lpbk ["lpbkAdcProfile" ]["#text" ])
17996 del (lpbk ["lpbkAdcProfile" ]["#text" ])
18097
18198 return {"rx" : rx , "tx" : tx , "orx" : orx , "lpbk" : lpbk , "clocks" : clocks }
0 commit comments