Useful Functions
This document outlines some of the useful functions available in MARTe2-Python for a application.
MARTe2Application
The MARTe2Application instance is the first place to start, not only is it the central class of this repository and how to construct a MARTe2 Application, it contains very useful functions which are described further below.
The pythonic object representation of a MARTe2 application, how to build it and ultimately write this into it’s string configuration format.
CPU Configurator
The CPU Configurator function is fairly useful, simply copy and paste the below code into your python to convert numeric CPU configuration to their hexadecimal equivalent.
CPU_OFFSET_FROM_ONE = 0 # 0 to start at cpu 1
def cpu_thread_gen(x):
''' Generate a cpu core to used based on thread number x and pre-defined offset from core 1. '''
return str(hex(2 ** (x + CPU_OFFSET_FROM_ONE)))
GAM Functions
gam_functions.py contains functions that create or maniuplate gams
- martepy.functions.gam_functions.addAlias(signal: tuple)
If an Alias is not set, set it to the basic name
- martepy.functions.gam_functions.addDimensions(signal: tuple)
If a signal does not contain elements or dimensions, add them
- martepy.functions.gam_functions.assignUniqueName(signal: tuple, signals_list: list)
Ensures that a signal is uniquely named compared to a list of signals
- martepy.functions.gam_functions.consolidate(thread_0_functions, gam_type, config_name, inputs=[], outputs=[], prepend=False)
- Parameters:
thread_0_functions (list[]) – list of references to rtcc1blocks specific class
gam_type (str) – type of gam
config_name (str) – SDN config
inputs (list[tuple[str, dict[]]]) – input signal
outputs (list[tuple[str, dict[]]]) – output signal
- Return gam:
marte2 gam
- Return type:
marte2 gam
Add a GAM which creates a constant signal or reads a signal from SDN but check first if a similarly named GAM of that type exists, and if it does simply add the signals provided to this method into the pre-existing GAM.
- martepy.functions.gam_functions.findSignalInFunctionList(signal, functions)
Will return the signal that matches a given signal in a list of functions
- martepy.functions.gam_functions.getAlias(signal_key)
Return the alias of a signal
- martepy.functions.gam_functions.getDatasource(signal)
Simplification of getting a signals datasource
- martepy.functions.gam_functions.getGamByName(name: str, function_list)
Returns a GAM based on the name in a given function list
- martepy.functions.gam_functions.getKeyAttribute(signal, key)
Given a specific MARTe2Config key, retrieve the value
- martepy.functions.gam_functions.getParameterName(parameter_name: str)
This takes the serialized name of a parameter and returns it’s attribute name
- martepy.functions.gam_functions.isMatchingSignal(signal, other_signal)
Here we say a signal is the same if it has the same alias and datasource where the signal exists.
- martepy.functions.gam_functions.removeKeysFromConfig(signal: tuple, keys: list)
Safely Delete keys from a signal
- martepy.functions.gam_functions.setDatasource(signal, datasource)
Simplification of setting a signals datasource
- martepy.functions.gam_functions.setKeyAttribute(signal, key, value)
Set a attribute of the MARTe Config
Extra Functions
extra_functions.py contains additional useful functions
- exception martepy.functions.extra_functions.ConfigGeneratorError
Generic exception for errors encountered during configuration generation
- martepy.functions.extra_functions.calculateStackSize(signals)
- Parameters:
signals (list[tuple[str, dict[]]]) – inputs and outputs
- Return stacksize:
total size of variable types
- Return type:
int
Given a function, how big is the input and output signal stack size of the variables
- martepy.functions.extra_functions.findIndexByDictKey(list_i, key, value)
This will search through a list of dictionaries and find a key value matching pair # this is intended for where dictionaries are identified by a unique key/value.
- martepy.functions.extra_functions.form(sig_name, type_, num=None, datasource='DDB0', alias=None, default=None)
- Parameters:
sig_name (str) – signal name
type (str) – signal type
num (int) – number of elements
datasource (str) – MARTe datasource
alias (str) – signal alias
- Returns:
output signals formatted
- Return type:
list[tuple[str, dict[]]]
Formats the input/output signals
- martepy.functions.extra_functions.getname(object_cls)
Return the name of an object, omitting the +
- martepy.functions.extra_functions.isfloat(value)
Is our value a valid float value?
- martepy.functions.extra_functions.isint(value)
Is our value a valid integer?
- martepy.functions.extra_functions.normalizeSignal(signal)
Checks that a signal has elements and dimensions and removes these if not otherwise it ensures they are both set. It also handles defaults in this context, if a default is with zero dimensions/elements, it will remove the {} encapsulation of default.
Bin2CSV
The Bin2CSV tool can be used to parse a binary file generated in MARTe2 into a CSV file. It currently supports arrays and singles of int32, uint32, float32, uint64, float64, uint16, uint8.
Note: User specific types cannot be incorporated into the FileReader and need to be split out
Usage:
conv = Bin2CSV(source_binary, output_csv)
conv.main()