Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • mecinam2/ccs
1 result
Select Git revision
Show changes
...@@ -67,6 +67,7 @@ _pcf_cache = {} ...@@ -67,6 +67,7 @@ _pcf_cache = {}
_cap_cache = {} _cap_cache = {}
_txp_cache = {} _txp_cache = {}
_pcf_descr_cache = {} _pcf_descr_cache = {}
_pid_to_pcf_name = {}
project = cfg.get('ccs-database', 'project') project = cfg.get('ccs-database', 'project')
pc = importlib.import_module(PCPREFIX + str(project).upper()) pc = importlib.import_module(PCPREFIX + str(project).upper())
...@@ -761,7 +762,7 @@ def Tmformatted(tm, separator='\n', sort_by_name=False, textmode=True, udef=Fals ...@@ -761,7 +762,7 @@ def Tmformatted(tm, separator='\n', sort_by_name=False, textmode=True, udef=Fals
# #
# Decode source data field of TM packet # Decode source data field of TM packet
# @param tm TM packet bytestring # @param tm TM packet bytestring
def Tmdata(tm, udef=False, floatfmt=None): def Tmdata(tm: bytes, udef=False, floatfmt=None):
""" """
:param tm: :param tm:
...@@ -869,14 +870,14 @@ def Tmdata(tm, udef=False, floatfmt=None): ...@@ -869,14 +870,14 @@ def Tmdata(tm, udef=False, floatfmt=None):
else: else:
que = 'SELECT pcf.pcf_name,pcf.pcf_descr,pcf.pcf_ptc,pcf.pcf_pfc,pcf.pcf_curtx,pcf.pcf_width,\ que = 'SELECT pcf.pcf_name,pcf.pcf_descr,pcf.pcf_ptc,pcf.pcf_pfc,pcf.pcf_curtx,pcf.pcf_width,\
pcf.pcf_unit,pcf.pcf_pid,vpd_pos,vpd_grpsize,vpd_fixrep from vpd left join pcf on \ pcf.pcf_unit,pcf.pcf_pid,pcf_related,vpd_pos,vpd_grpsize,vpd_fixrep,vpd_pidref from vpd left join pcf on \
vpd.vpd_name=pcf.pcf_name where vpd_tpsd={} AND pcf_name NOT LIKE "DPTG%" \ vpd.vpd_name=pcf.pcf_name where vpd_tpsd={} AND pcf_name NOT LIKE "DPTG%" \
AND pcf_name NOT LIKE "SCTG%" ORDER BY vpd_pos'.format(tpsd) AND pcf_name NOT LIKE "SCTG%" ORDER BY vpd_pos'.format(tpsd)
dbres = dbcon.execute(que) dbres = dbcon.execute(que)
params_in = dbres.fetchall() params_in = dbres.fetchall()
vals_params = read_variable_pckt(data, params_in) vals_params = read_variable_pckt(data, params_in)
tmdata = [(get_calibrated(i[0], j, floatfmt=floatfmt), i[6], i[1], pidfmt(i[7]), j) for j, i in vals_params] tmdata = [(get_calibrated(i[0], j, floatfmt=floatfmt, ispid=i[-1], pidval=i[7]), i[6], i[1], pidfmt(i[7]), j) for j, i in vals_params]
# tmdata = [(get_calibrated(i[0], j[0]), i[6], i[1], pidfmt(i[7]), j) for i, j in zip(params, vals_params)] # tmdata = [(get_calibrated(i[0], j[0]), i[6], i[1], pidfmt(i[7]), j) for i, j in zip(params, vals_params)]
if spid is not None: if spid is not None:
...@@ -1558,7 +1559,7 @@ def read_variable_pckt(tm_data, parameters, tc=False): ...@@ -1558,7 +1559,7 @@ def read_variable_pckt(tm_data, parameters, tc=False):
return result return result
def read_stream_recursive(tms, parameters, decoded=None, bit_off=0, tc=False): def read_stream_recursive(tms, parameters, decoded=None, bit_off=0, tc=False, fmtpids=None):
""" """
Recursively operating function for decoding variable length packets Recursively operating function for decoding variable length packets
...@@ -1571,22 +1572,26 @@ def read_stream_recursive(tms, parameters, decoded=None, bit_off=0, tc=False): ...@@ -1571,22 +1572,26 @@ def read_stream_recursive(tms, parameters, decoded=None, bit_off=0, tc=False):
""" """
decoded = [] if decoded is None else decoded decoded = [] if decoded is None else decoded
fmtpids = {} if fmtpids is None else fmtpids
skip = 0 skip = 0
for par_idx, par in enumerate(parameters): for par_idx, par in enumerate(parameters):
if skip > 0: if skip > 0:
skip -= 1 skip -= 1
continue continue
grp = par[-2] grp = par[-3]
if grp is None: # None happens for UDEF if grp is None: # None happens for UDEF
grp = 0 grp = 0
fmt = ptt(par[2], par[3]) fmt = ptt(par[2], par[3])
if fmt == 'deduced': if fmt == 'deduced':
raise NotImplementedError('Deduced parameter type PTC=11') fmt = get_pid_fmt(fmtpids.get(par[8]))
# add pid to par info for use in calibration func
par = par[:7] + (fmtpids.get(par[8]),) + par[8:]
# raise NotImplementedError('Deduced parameter type PTC=11')
fixrep = par[-1] fixrep = par[-2]
# don't use fixrep in case of a TC, since it is only defined for TMs # don't use fixrep in case of a TC, since it is only defined for TMs
if grp and fixrep and not tc: if grp and fixrep and not tc:
...@@ -1605,16 +1610,26 @@ def read_stream_recursive(tms, parameters, decoded=None, bit_off=0, tc=False): ...@@ -1605,16 +1610,26 @@ def read_stream_recursive(tms, parameters, decoded=None, bit_off=0, tc=False):
decoded.append((value, par)) decoded.append((value, par))
if par[-1].upper() == 'Y':
fmtpids[par[0]] = value
if grp != 0: if grp != 0:
skip = grp skip = grp
rep = value rep = value
while rep > 0: while rep > 0:
decoded = read_stream_recursive(tms, parameters[par_idx + 1:par_idx + 1 + grp], decoded, bit_off=bit_off, tc=tc) decoded = read_stream_recursive(tms, parameters[par_idx + 1:par_idx + 1 + grp], decoded, bit_off=bit_off, tc=tc, fmtpids=fmtpids)
rep -= 1 rep -= 1
return decoded return decoded
def get_pid_fmt(pid):
if pid not in _dp_items:
# return None
raise ValueError('Cannot determine format for PID={}'.format(pid))
return _dp_items.get(pid).get('fmt')
def tc_param_alias_reverse(paf, cca, val, pname=None): def tc_param_alias_reverse(paf, cca, val, pname=None):
""" """
...@@ -1697,7 +1712,8 @@ def pidfmt_reverse(val): ...@@ -1697,7 +1712,8 @@ def pidfmt_reverse(val):
# Calibrate raw parameter values # Calibrate raw parameter values
# @param pcf_name PCF_NAME # @param pcf_name PCF_NAME
# @param rawval Raw value of the parameter # @param rawval Raw value of the parameter
def get_calibrated(pcf_name, rawval, properties=None, numerical=False, dbcon=None, nocal=False, floatfmt=None): def get_calibrated(pcf_name, rawval, properties=None, numerical=False, dbcon=None, nocal=False, floatfmt=None,
ispid='N', pidval=None):
""" """
:param pcf_name: :param pcf_name:
...@@ -1706,12 +1722,18 @@ def get_calibrated(pcf_name, rawval, properties=None, numerical=False, dbcon=Non ...@@ -1706,12 +1722,18 @@ def get_calibrated(pcf_name, rawval, properties=None, numerical=False, dbcon=Non
:param numerical: :param numerical:
:param dbcon: :param dbcon:
:param nocal: :param nocal:
:param floatfmt:
:param ispid:
:return: :return:
""" """
if rawval is None: if rawval is None:
return return
# override pcf_name if parameter is deduced
if pidval is not None:
pcf_name = get_pcf_name_from_pid(pidval)
if properties is None: if properties is None:
# cache # cache
...@@ -1744,6 +1766,9 @@ def get_calibrated(pcf_name, rawval, properties=None, numerical=False, dbcon=Non ...@@ -1744,6 +1766,9 @@ def get_calibrated(pcf_name, rawval, properties=None, numerical=False, dbcon=Non
except IndexError: except IndexError:
return rawval return rawval
if ispid == 'Y':
return get_pid_name(rawval)
if type_par == timepack[0]: if type_par == timepack[0]:
return timecal(rawval) return timecal(rawval)
# elif categ == 'T' or type_par.startswith('ascii'): # elif categ == 'T' or type_par.startswith('ascii'):
...@@ -4493,6 +4518,17 @@ def pcf_name_to_descr(pcfname): ...@@ -4493,6 +4518,17 @@ def pcf_name_to_descr(pcfname):
return res[0][0] return res[0][0]
def get_pcf_name_from_pid(pid):
if pid in _pid_to_pcf_name:
return _pid_to_pcf_name[pid]
que = 'SELECT pcf_name FROM pcf WHERE pcf_pid={}'.format(pid)
res = scoped_session_idb.execute(que).fetchall()
_pid_to_pcf_name[pid] = res[0][0]
return _pid_to_pcf_name[pid]
def get_tm_id(pcf_descr=None): def get_tm_id(pcf_descr=None):
""" """
...@@ -7516,7 +7552,7 @@ try: ...@@ -7516,7 +7552,7 @@ try:
except (SQLOperationalError, NotImplementedError, IndexError): except (SQLOperationalError, NotImplementedError, IndexError):
logger.warning('Could not get S13 info from MIB, using default values') logger.warning('Could not get S13 info from MIB, using default values')
SDU_PAR_LENGTH = 1 SDU_PAR_LENGTH = 1
S13_HEADER_LEN_TOTAL = 21 S13_HEADER_LEN_TOTAL = 25
S13_DATALEN_PAR_OFFSET = 19 S13_DATALEN_PAR_OFFSET = 23
S13_DATALEN_PAR_SIZE = 2 S13_DATALEN_PAR_SIZE = 2
...@@ -279,7 +279,7 @@ ...@@ -279,7 +279,7 @@
"columns": { "columns": {
"PCF_NAME": " VARCHAR(12) NOT NULL ", "PCF_NAME": " VARCHAR(12) NOT NULL ",
"PCF_DESCR": " VARCHAR(24) NULL DEFAULT NULL ", "PCF_DESCR": " VARCHAR(24) NULL DEFAULT NULL ",
"PCF_PID": " INT(10) NULL DEFAULT NULL ", "PCF_PID": " BIGINT NULL DEFAULT NULL ",
"PCF_UNIT": " VARCHAR(4) NULL DEFAULT NULL ", "PCF_UNIT": " VARCHAR(4) NULL DEFAULT NULL ",
"PCF_PTC": " INT(2) NOT NULL ", "PCF_PTC": " INT(2) NOT NULL ",
"PCF_PFC": " INT(5) NOT NULL ", "PCF_PFC": " INT(5) NOT NULL ",
...@@ -1033,4 +1033,4 @@ ...@@ -1033,4 +1033,4 @@
"default_character_set": "latin1" "default_character_set": "latin1"
} }
} }
} }
\ No newline at end of file