示例#1
0
    def test_writeToCSV(self):
        yaml_doc = """
        - !Packet
          name: Packet1
          fields:
            - !Field
              name:       col1
              desc:       test column 1
              bytes:      0
              type:       MSB_U16
              mask:       0x10
              enum:
                a: testa
            - !Field
              name: SampleTime
              type: TIME64
              bytes: 1
        """

        csv_row1 = [
            "col1",
            "0",
            "2",
            "0x10",
            "MSB",
            "MSB_U16",
            "test column 1",
            "a: testa",
        ]

        with open(self.test_yaml_file, "wt") as out:
            out.write(yaml_doc)

        tlmdict = tlm.TlmDict(self.test_yaml_file)

        writer = tlm.TlmDictWriter(tlmdict=tlmdict)
        writer.write_to_csv(self.test_outpath)

        expected_csv = os.path.join(self.test_outpath, "Packet1.csv")
        assert os.path.isfile(expected_csv)

        with open(expected_csv, "rt") as csvfile:
            reader = csv.reader(csvfile)
            # skip header
            next(reader)
            actual_row = next(reader)
            assert actual_row[0] == csv_row1[0]
            assert actual_row[1] == csv_row1[1]
            assert actual_row[4] == csv_row1[4]

        os.remove(self.test_yaml_file)
        os.remove(expected_csv)
示例#2
0
    def test_writeToCSV(self):
        yaml_doc = """
        - !Packet
          name: Packet1
          fields:
            - !Field
              name:       col1
              desc:       test column 1
              bytes:      0
              type:       MSB_U16
              mask:       0x10
              enum:
                a: testa
            - !Field
              name: SampleTime
              type: TIME64
              bytes: 1
        """

        csv_row1 = [
            'col1', '0', '2', '0x10', 'MSB', 'MSB_U16', 'test column 1',
            'a: testa'
        ]

        with open(self.test_yaml_file, 'wb') as out:
            out.write(yaml_doc)

        tlmdict = tlm.TlmDict(self.test_yaml_file)

        writer = tlm.TlmDictWriter(tlmdict=tlmdict)
        writer.writeToCSV(self.test_outpath)

        expected_csv = os.path.join(self.test_outpath, 'Packet1.csv')
        assert os.path.isfile(expected_csv)

        with open(expected_csv, 'rb') as csvfile:
            reader = csv.reader(csvfile)
            # skip header
            reader.next()
            actual_row = reader.next()
            assert actual_row[0] == csv_row1[0]
            assert actual_row[1] == csv_row1[1]
            assert actual_row[4] == csv_row1[4]

        os.remove(self.test_yaml_file)
        os.remove(expected_csv)
示例#3
0
def main():
    parser = argparse.ArgumentParser(
        description=__doc__,
        formatter_class=argparse.RawDescriptionHelpFormatter)

    # Add optional command line arguments
    parser.add_argument("--format", default="csv")
    parser.add_argument("--path", default="")

    group = parser.add_mutually_exclusive_group(required=True)
    group.add_argument("--tlm", action="store_true", default=False)
    group.add_argument("--cmd", action="store_true", default=False)

    # Get command line arguments
    args = vars(parser.parse_args())

    # output format for the file
    format = args["format"]

    # output path
    path = args["path"]

    # initialize telemetry dictionary writer
    if args["tlm"]:
        writer = tlm.TlmDictWriter()

    # initialize command dictionary writer
    if args["cmd"]:
        log.error("Not yet supported")
        sys.exit()

    # write to csv
    if format == "csv":
        writer.writeToCSV(output_path=path)
    else:
        log.error("Invalid <format> specified.")