C++ ostream made optional #342

Merged
gaisser merged 71 commits from mueller/fsfw-printers into development 2021-01-12 15:27:14 +01:00
Owner
  • Should be merged after bundled update.
  • Proper printf support, ostreams can be excluded by setting option in FSFWConfig now. This can reduce code size by 150-250 kB. (which might be good for more constrained embedded systems). See ServiceInterfacePrinter.h. This reduced the Debug executable size for the RTEMS debug executable for the STM32 by 400-500 kB (!!!!).
  • Includes color support for both ostreams and printf support. Includes special initialization to enable coloring for Windows hosted builds.
  • Task of adding printf versions to each sif:: output is a task which is kind of awkward to automate because of their different formatting. I would say this is done piece by piece as we go forward, kind of like the size_t replacements.
  • Amalgamated header which determines automatically which service interface to use depending on FSFWConfig.h configuration. Users can just use #include <fsfw/serviceinterface/ServiceInterface.h>
  • If CPP streams are excluded, sif:: calls won't work anymore and need to be replaced by their printf counterparts. For the fsfw, this can be done by checking the processor define FSFW_CPP_OSTREAM_ENABLED from FSFWConfig.h. For mission code, developers need to replace sif:: calls by the printf counterparts, but only if the CPP stream are excluded. If this is not the case, everything should work as usual.
  • In the future, all print ouputs could be wrapped in another preprocessor define to disable output completely.

This fixes #168 .

Python script to perform wrapping of sif:: calls in preprocessor defines used in the misson code (used for fsfw_example folder). Replace fsfw by the folder where the preprocessor replacements should be made (because changes were already made in fsfw).

import os
import enum


class ProcessingType(enum.Enum):
    COMPLETE = enum.auto()
    UTILITY = enum.auto()


PROCESSING_TYPE = ProcessingType.UTILITY


def main():
	# Specify folder to perform wrappin on
    read_all_files("fsfw_example", True)


def read_all_files(folder, root_folder: bool, nesting_depth: int = 0):
    for file in os.listdir(folder):
		# Add files to be ignored
        if file in [".git", ".idea", ".project", ".settings"]:
            continue
        if ".py" in file or ".a" in file:
            continue
		# Replace fsfw by the folders which should be searched
        if file not in ["fsfw"] and root_folder:
            continue
        if os.path.isdir(os.path.join(folder, file)):
            read_all_files(os.path.join(folder, file), False, nesting_depth + 1)
            continue
        print("Checking file " + str(os.path.join(folder, file)))
        with open(os.path.join(folder, file), "r") as in_file:
            try:
                rows = [x for x in in_file]
            except UnicodeDecodeError:
                print("Decoding error in file " + str(file) + ", continuing..")
                continue
            do_write, rows = process_rows(rows)
        if do_write:
            with open(os.path.join(folder, file), "w") as in_file:
                print("Write file %s" % (os.path.join(folder, file)))
                in_file.writelines(rows)


def process_rows(rows: list[str]):
    multi_line = False
    write = False
    for index, row in enumerate(rows):
        if PROCESSING_TYPE == ProcessingType.COMPLETE:
            new_lines = row
            if "sif::" in row:
                print("SIF found in line " + str(index) + " file " + str(file))
                define_line = "#if FSFW_CPP_OSTREAM_ENABLED == 1\n"
                new_lines = define_line + new_lines
                if "std::endl" in row or "std::flush" in row:
                    print("One line SIF output from line" + str(index))
                    new_lines += "#endif\n"
                    write = True
                elif not multi_line:
                    multi_line = True
            if multi_line:
                if "std::endl" in row or "std::flush" in row:
                    print("Multiline output found in " + str(file) + " with ending on row "
                          + str(index))
                    new_lines += "#endif\n"
                    write = True
                    multi_line = False
            rows[index] = new_lines
        elif PROCESSING_TYPE == ProcessingType.UTILITY:
            new_line = row
            if "CPP_OSTREAM_ENABLED == 1" in row:
                new_line = row.replace("CPP_OSTREAM_ENABLED == 1", "FSFW_CPP_OSTREAM_ENABLED == 1")
                write = True
            rows[index] = new_line
    return write, rows


if __name__ == "__main__":
    main()
- Should be merged after bundled update. - Proper printf support, ostreams can be excluded by setting option in FSFWConfig now. This can reduce code size by 150-250 kB. (which might be good for more constrained embedded systems). See `ServiceInterfacePrinter.h`. This reduced the Debug executable size for the RTEMS debug executable for the STM32 by 400-500 kB (!!!!). - Includes color support for both ostreams and printf support. Includes special initialization to enable coloring for Windows hosted builds. - Task of adding printf versions to each sif:: output is a task which is kind of awkward to automate because of their different formatting. I would say this is done piece by piece as we go forward, kind of like the size_t replacements. - Amalgamated header which determines automatically which service interface to use depending on `FSFWConfig.h` configuration. Users can just use `#include <fsfw/serviceinterface/ServiceInterface.h>` - If CPP streams are excluded, sif:: calls won't work anymore and need to be replaced by their printf counterparts. For the fsfw, this can be done by checking the processor define `FSFW_CPP_OSTREAM_ENABLED` from `FSFWConfig.h`. For mission code, developers need to replace sif:: calls by the printf counterparts, but only if the CPP stream are excluded. If this is not the case, everything should work as usual. - In the future, all print ouputs could be wrapped in another preprocessor define to disable output completely. This fixes #168 . Python script to perform wrapping of sif:: calls in preprocessor defines used in the misson code (used for fsfw_example folder). Replace fsfw by the folder where the preprocessor replacements should be made (because changes were already made in fsfw). ```py import os import enum class ProcessingType(enum.Enum): COMPLETE = enum.auto() UTILITY = enum.auto() PROCESSING_TYPE = ProcessingType.UTILITY def main(): # Specify folder to perform wrappin on read_all_files("fsfw_example", True) def read_all_files(folder, root_folder: bool, nesting_depth: int = 0): for file in os.listdir(folder): # Add files to be ignored if file in [".git", ".idea", ".project", ".settings"]: continue if ".py" in file or ".a" in file: continue # Replace fsfw by the folders which should be searched if file not in ["fsfw"] and root_folder: continue if os.path.isdir(os.path.join(folder, file)): read_all_files(os.path.join(folder, file), False, nesting_depth + 1) continue print("Checking file " + str(os.path.join(folder, file))) with open(os.path.join(folder, file), "r") as in_file: try: rows = [x for x in in_file] except UnicodeDecodeError: print("Decoding error in file " + str(file) + ", continuing..") continue do_write, rows = process_rows(rows) if do_write: with open(os.path.join(folder, file), "w") as in_file: print("Write file %s" % (os.path.join(folder, file))) in_file.writelines(rows) def process_rows(rows: list[str]): multi_line = False write = False for index, row in enumerate(rows): if PROCESSING_TYPE == ProcessingType.COMPLETE: new_lines = row if "sif::" in row: print("SIF found in line " + str(index) + " file " + str(file)) define_line = "#if FSFW_CPP_OSTREAM_ENABLED == 1\n" new_lines = define_line + new_lines if "std::endl" in row or "std::flush" in row: print("One line SIF output from line" + str(index)) new_lines += "#endif\n" write = True elif not multi_line: multi_line = True if multi_line: if "std::endl" in row or "std::flush" in row: print("Multiline output found in " + str(file) + " with ending on row " + str(index)) new_lines += "#endif\n" write = True multi_line = False rows[index] = new_lines elif PROCESSING_TYPE == ProcessingType.UTILITY: new_line = row if "CPP_OSTREAM_ENABLED == 1" in row: new_line = row.replace("CPP_OSTREAM_ENABLED == 1", "FSFW_CPP_OSTREAM_ENABLED == 1") write = True rows[index] = new_line return write, rows if __name__ == "__main__": main() ```
muellerr added the
feature
label 2021-01-03 15:18:56 +01:00
muellerr added 63 commits 2021-01-03 15:18:57 +01:00
muellerr changed title from FSFW: Ostream optional to C++ ostream made optional 2021-01-03 15:22:56 +01:00
muellerr added 1 commit 2021-01-03 15:31:52 +01:00
muellerr added 1 commit 2021-01-03 16:48:27 +01:00
muellerr added 1 commit 2021-01-04 15:38:53 +01:00
Author
Owner

I will propabkly rename the fsfw namespace to sif

I will propabkly rename the `fsfw` namespace to `sif`
muellerr added 1 commit 2021-01-12 15:05:41 +01:00
muellerr added 1 commit 2021-01-12 15:06:49 +01:00
muellerr added 3 commits 2021-01-12 15:14:26 +01:00
gaisser added 1 commit 2021-01-12 15:25:54 +01:00
gaisser merged commit 5639273d9b into development 2021-01-12 15:27:14 +01:00
gaisser added this to the ASTP 1.0.0 Local pools milestone 2021-01-26 14:27:37 +01:00
Sign in to join this conversation.
No description provided.