diff --git a/Ccs/ccs_function_lib.py b/Ccs/ccs_function_lib.py index 9bcbac405afc78c7efad6a7deb26d1c3f7525e65..728e79cd8db74fc532ebafec1265082d7a1adea7 100644 --- a/Ccs/ccs_function_lib.py +++ b/Ccs/ccs_function_lib.py @@ -2016,6 +2016,20 @@ def filter_rows(rows, st=None, sst=None, apid=None, sid=None, time_from=None, ti return rows +def filter_by_discr(rows, pi1_off, pi1_wid, pi1_val): + """ + + :param rows: + :param pi1_off: + :param pi1_wid: + :param pi1_val: + :return: + """ + + rows = rows.filter(func.mid(DbTelemetry.raw, pi1_off + 1, pi1_wid) == pi1_val.to_bytes(pi1_wid, 'big')) + return rows + + ## # CRC check # @@ -2100,6 +2114,27 @@ def get_pool_rows(pool_name, check_existence=False): return rows +def get_hk_val(pool_name, sid, par_id, apid=None): + + assert isinstance(sid, int) + + dbcon = scoped_session_idb() + apid_filt = '' if apid is None else ' AND pid_apid={:d}'.format(apid) + res = dbcon.execute('SELECT pid_descr FROM pid WHERE pid_type=3 and pid_stype=25 and pid_pi1_val={:d}{}'.format(sid, apid_filt)).fetchall() + dbcon.close() + + if not res: + return + + hk, = res[0] + # TODO: user defined HKs + + if isinstance(par_id, int): + pass # TODO + + return get_param_values(pool_name=pool_name, hk=hk, param=par_id, last=1, mk_array=False) + + # get values of parameter from HK packets def get_param_values(tmlist=None, hk=None, param=None, last=0, numerical=False, tmfilter=True, pool_name=None, mk_array=True, nocal=False): """ @@ -2186,7 +2221,11 @@ def get_param_values(tmlist=None, hk=None, param=None, last=0, numerical=False, descr, unit, name = param, None, None bylen = csize(ufmt) - tmlist_filt = Tm_filter_st(tmlist, st=st, sst=sst, apid=apid, sid=sid)[-last:] if tmfilter else tmlist[-last:] + if isinstance(tmlist, list): + tmlist_filt = Tm_filter_st(tmlist, st=st, sst=sst, apid=apid, sid=sid)[-last:] if tmfilter else tmlist[-last:] + else: + tmlist_filt = filter_rows(tmlist, st=st, sst=sst, apid=apid, sid=sid)[-last:] if tmfilter else tmlist[-last:] + tmlist_filt = [x.raw for x in tmlist_filt] if name is not None: que = 'SELECT pcf.pcf_categ,pcf.pcf_curtx from pcf where pcf_name="%s"' % name @@ -2198,9 +2237,16 @@ def get_param_values(tmlist=None, hk=None, param=None, last=0, numerical=False, return categ, curtx = fetch[0] - xy = [(get_cuctime(tm), - get_calibrated(name, read_stream(io.BytesIO(tm[offby:offby + bylen]), ufmt, offbi=offbi), - properties=[ptc, pfc, categ, curtx], numerical=numerical, nocal=True)) for tm in tmlist_filt] # no calibration here, done below on array + + if mk_array: + xy = [(get_cuctime(tm), + get_calibrated(name, read_stream(io.BytesIO(tm[offby:offby + bylen]), ufmt, offbi=offbi), + properties=[ptc, pfc, categ, curtx], numerical=numerical, nocal=True)) for tm in tmlist_filt] # no calibration here, done below on array + else: + xy = [(get_cuctime(tm), + get_calibrated(name, read_stream(io.BytesIO(tm[offby:offby + bylen]), ufmt, offbi=offbi), + properties=[ptc, pfc, categ, curtx], numerical=numerical, nocal=nocal)) for tm in + tmlist_filt] else: xy = [(get_cuctime(tm), read_stream(io.BytesIO(tm[offby:offby + bylen]), ufmt, offbi=offbi)) for tm in tmlist_filt] diff --git a/Tst/prep_test_env.py b/Tst/prep_test_env.py index 53a483b9c02c7e50d415ea781a265fc8a5000eb7..9323b77d3e351aebf71c05687b745ee9b07a3e08 100755 --- a/Tst/prep_test_env.py +++ b/Tst/prep_test_env.py @@ -29,7 +29,7 @@ logger.addHandler(hdlr=console_hdlr) file_hdlr = toolbox.create_file_handler(file=log_file) logger.addHandler(hdlr=file_hdlr) -pool_name = 'new_tmtc_pool' +pool_name = 'LIVE' def run(pool_name): logger.info('1) ------------------- Start the simulators -------------------') diff --git a/Tst/testing_library/testlib/tm.py b/Tst/testing_library/testlib/tm.py index 5bf8438ce0df3817d023c9b378b4adea2d3e6926..fe9b16746348487fc540ba6ce5038d47ee42a7b9 100644 --- a/Tst/testing_library/testlib/tm.py +++ b/Tst/testing_library/testlib/tm.py @@ -979,7 +979,56 @@ def extract_apid_from_packetid(packet_id): return apid -def get_tc_ack(pool_name="LIVE", ack_types=None, tc_apid=321): +def confirm_pkt(pool_name, st, sst, apid=None, pi1_off=None, pi1_wid=None, pi1_val=None, wait=0): + """ + Confirm reception of TM packet with service type st and sub-tpye sst after last TC. + By using the pi1_* parameters, an additional constraint using a discriminant can be applied. + + :param pool_name: + :param st: + :param sst: + :param apid: + :param pi1_off: byte offset of discriminant parameter in the entire packet (i.e., incl. PUS header) + :param pi1_wid: size of discriminant parameter in bytes + :param pi1_val: discriminant value + :param wait: seconds to wait before running the check + :return: + """ + + time.sleep(wait) + + tc_data = get_data_of_last_tc(pool_name, apid=apid) + + if tc_data is None: + return False, [] + + t_tc_sent = tc_data[0] + tc_idx = tc_data[1] + tc_head_bytes = tc_data[2] + + tms = cfl.get_pool_rows(pool_name) + tms = tms.filter(cfl.DbTelemetry.stc == st, cfl.DbTelemetry.sst == sst, cfl.DbTelemetry.idx > tc_idx).order_by(cfl.DbTelemetry.idx) + + if pi1_off and pi1_wid and pi1_val: + tms = cfl.filter_by_discr(tms, pi1_off, pi1_wid, pi1_val) + + pkt = tms.first() + + if pkt is None: + return False, [] + else: + return True, pkt.raw + + +def verify_tc_ack(pool_name, ack_types=None, tc_apid=321): + """ + Confirm acknowledgement of last TC packet. + + :param pool_name: + :param ack_types: list of ACK types (i.e., service 1 sub-types) to check for + :param tc_apid: + :return: + """ if ack_types is None: remaining = [1, 7] @@ -1045,6 +1094,11 @@ def get_tc_ack(pool_name="LIVE", ack_types=None, tc_apid=321): return result, ack_pkts +def get_hk_val(pool_name, sid, par_id, apid=None): + + return cfl.get_hk_val(pool_name, sid, par_id, apid=apid) + + def get_tc_acknow(pool_name="LIVE", tc_apid=321, tc_ssc=None, tm_st=1, tm_sst=None): """ Check if for the TC acknowledgement packets can be found in the database. diff --git a/Tst/tst/verification_tab.py b/Tst/tst/verification_tab.py index a9fdb9f10ff3c15f0f4fd7aa3363fd71a6b1c92f..19a5c4f1850464fd0b4f4b3de68fc0e65d0a013b 100644 --- a/Tst/tst/verification_tab.py +++ b/Tst/tst/verification_tab.py @@ -41,6 +41,10 @@ Verification_6 = "tm." + tm.get_packet_length.__name__ + str(inspect.signature(( Verification_7 = "tm." + tm.get_version_number.__name__ + str(inspect.signature((tm.get_version_number))) Verification_8 = "tm." + tm.get_data_of_last_tc.__name__ + str(inspect.signature((tm.get_data_of_last_tc))) Verification_9 = "tm." + tm.verify_no_more_hk.__name__ + str(inspect.signature((tm.verify_no_more_hk))) +Verification_10 = "tm." + tm.verify_tc_ack.__name__ + str(inspect.signature((tm.verify_tc_ack))) +Verification_11 = "tm." + tm.confirm_pkt.__name__ + str(inspect.signature((tm.confirm_pkt))) +Verification_12 = "tm." + tm.get_hk_val.__name__ + str(inspect.signature((tm.get_hk_val))) + @@ -51,6 +55,9 @@ Verification_9 = "tm." + tm.verify_no_more_hk.__name__ + str(inspect.signature(( descr_8 = "Get Timestamp of TM before last TC, get IID of last TC, get first 4 bytes of TC raw data." descr_9 = "Check if there are no more HK packets" +descr_10 = "Verify acknowledgement of TC" +descr_11 = "Confirm that packet ST, SST has been received" +descr_12 = "Get parameter value from HK packet" @@ -63,7 +70,10 @@ verification_list = [ ("Get Packet Length", None, None, "descr", Verification_6), ("Get Version Number", None, None, "descr", Verification_7), ("Get Data of last TC", None, None, descr_8, Verification_8), - ("Test if there are no more HK packets", None, None, descr_9, Verification_9) + ("Test if there are no more HK packets", None, None, descr_9, Verification_9), + ("Verify TC ACK", None, None, descr_10, Verification_10), + ("Confirm pkt", None, None, descr_11, Verification_11), + ("HK val", None, None, descr_12, Verification_12) ]