fcp package

Subpackages

Submodules

fcp.c_generator module

c-generator.

Usage:
c-generator.py generate <json> <template> <skel> <output> c-generator.py (-h | –help) c-generator.py –version
Options:
-h –help Show this screen. –version Show version.
fcp.c_generator.c_gen(templates, output, json_file, skel, logger)[source]
fcp.c_generator.check_output(output)[source]
fcp.c_generator.check_version(j, logger)[source]
fcp.c_generator.write_files(output, files)[source]

fcp.can module

class fcp.can.CANMessage(sid: int, dlc: int, timestamp: int, data16: List[int] = [], data64=-1)[source]

Bases: object

static decode_CANmessage(message)[source]
static decode_bstring(bstring)[source]

Decode bytestring encoded message into CANMessage.

See encode_bstring for details on the string format used.

static decode_json(j)[source]

Decode JSON encoded message into CANMessage.

See encode_json for details on the JSON format used.

static decode_kvaser_csv(csv, start_time)[source]
static decode_struct(s)[source]

Decode C struct encoded message into CANMessage.

See encode_struct for details on the struct format used.

encode_bstring()[source]

Encode message as a utf-8 byte string encoded comma separated list of fields. Example: 100,8,1,2,3,4,1. Encodes sid: 100, dlc: 8, data[0]: 1, data[1]: 2, data[2]: 3, data[3]: 4, timestamp: 1

encode_json()[source]

Encode message as a utf-8 byte string encoded JSON object. Example: {‘sid’: 100, ‘dlc’: 8, ‘data’: [1,2,3,4], ‘timestamp’: 1}

encode_struct()[source]

Encode message as a CAN struct:

typedef struct {
    union {
        struct {
                uint16_t dev_id:5; // Least significant
                // First bit of msg_id determines if msg is reserved or not.
                // 0 == reserved (higher priority) (0-31 decimal)
                uint16_t msg_id:6; // Most significant
        };
        uint16_t sid;
    };
    uint16_t dlc:4;
    uint16_t data[4];
} CANdata;
get_data16()[source]
get_data64()[source]
get_data8()[source]
fcp.can.test_decode_bstring()[source]
fcp.can.test_decode_json()[source]
fcp.can.test_decode_kvaser_csv()[source]
fcp.can.test_encode_bstring()[source]
fcp.can.test_encode_json()[source]
fcp.can.test_encode_struct()[source]

fcp.dbc_reader module

fcp.dbc_writer module

fcp.device module

fcp.device.main(args)[source]

fcp.docs module

fcp.docs.check_out_dir(out)[source]

Create output directory.

Out:output directory path.
Returns:Failure and error message.
fcp.docs.generate_docs(spec, out, link_location, logger)[source]
fcp.docs.markdown(spec, root)[source]

fcp.docs_css module

fcp.fcp_lib module

class fcp.fcp_lib.Fcp(spec)[source]

Bases: object

decode_get(signal)[source]
decode_log(signal)[source]
decode_msg(msg: fcp.can.CANMessage)[source]
decode_set(signal)[source]
encode_get(sid: int, dst: int, config: int)[source]
encode_msg(sid: int, msg_name: str, signals: Dict[str, float]) → fcp.can.CANMessage[source]
encode_set(sid: int, dst: int, config: int, value: int)[source]
find_config(dev, id)[source]
find_device(id)[source]
find_msg(msg)[source]
fcp.fcp_lib.bitmask(n)[source]
fcp.fcp_lib.conv_endianess(value: int, signal: fcp.spec.Signal)[source]
fcp.fcp_lib.decode_signal(signal, value)[source]
fcp.fcp_lib.encode_signal(signal, value)[source]
fcp.fcp_lib.test_bitmask()[source]

fcp.generator module

fcp.generator.build_can_ids(spec, tpl)[source]
fcp.generator.build_common(spec, tpl)[source]
fcp.generator.build_devices(spec, device, tpl)[source]
fcp.generator.build_enums(spec, tpl)[source]
fcp.generator.build_msg_sig(device)[source]
fcp.generator.date()[source]
fcp.generator.decode_signal_sig(device, message, signal)[source]
fcp.generator.decode_signature(device, message, signal)[source]
fcp.generator.device_struct_sig(device)[source]
fcp.generator.dst_type_decide(signal: fcp.spec.Signal)[source]
fcp.generator.enum_endianess(signal)[source]
fcp.generator.enum_type(signal)[source]
fcp.generator.msg_struct_sig(device, message)[source]
fcp.generator.multiplexor(signal, message)[source]
fcp.generator.spec_struct_sig(spec)[source]

fcp.gui module

class fcp.gui.ArgDetails(gui, node: fcp.spec.Argument, parent)[source]

Bases: fcp.gui.NodeDetails

load_atts(ui, node)[source]
staticMetaObject = <PySide2.QtCore.QMetaObject object>
class fcp.gui.CfgDetails(gui, node, parent)[source]

Bases: fcp.gui.NodeDetails

load_atts(ui, node)[source]
staticMetaObject = <PySide2.QtCore.QMetaObject object>
class fcp.gui.CfgWidget(gui, parent)[source]

Bases: PySide2.QtWidgets.QWidget

add_cfg(cfg=None)[source]
open_details(checked)[source]
reload()[source]
save()[source]
staticMetaObject = <PySide2.QtCore.QMetaObject object>
class fcp.gui.CmdDetails(gui, node, parent)[source]

Bases: fcp.gui.NodeDetails

add_arg(arg=None)[source]
load_atts(ui, node)[source]
staticMetaObject = <PySide2.QtCore.QMetaObject object>
class fcp.gui.CmdWidget(gui, parent)[source]

Bases: PySide2.QtWidgets.QWidget

add_cmd(cmd=None)[source]
open_details(checked)[source]
reload()[source]
save()[source]
staticMetaObject = <PySide2.QtCore.QMetaObject object>
class fcp.gui.DeviceDetails(gui, node: fcp.spec.Device, parent)[source]

Bases: fcp.gui.NodeDetails

add_node(node=None)[source]
load_atts(ui, node)[source]
open_cfg(clicked)[source]
open_cmd(clicked)[source]
staticMetaObject = <PySide2.QtCore.QMetaObject object>
class fcp.gui.DeviceWidget(gui, node, details=None, layout=None)[source]

Bases: fcp.gui.NodeDetails

load_atts(ui, node)[source]
staticMetaObject = <PySide2.QtCore.QMetaObject object>
class fcp.gui.EnumDetails(gui, node, parent)[source]

Bases: fcp.gui.NodeDetails

add_value(enum_value=None)[source]
load_atts(ui, node)[source]
save()[source]
staticMetaObject = <PySide2.QtCore.QMetaObject object>
class fcp.gui.EnumValueDetails(gui, node, parent)[source]

Bases: fcp.gui.NodeDetails

load_atts(ui, node)[source]
staticMetaObject = <PySide2.QtCore.QMetaObject object>
class fcp.gui.EnumWidget(gui, parent)[source]

Bases: PySide2.QtWidgets.QWidget

add_enum(enum=None)[source]
reload()[source]
save()[source]
staticMetaObject = <PySide2.QtCore.QMetaObject object>
class fcp.gui.FakeParent[source]

Bases: object

setVisible(visibility: bool)[source]
class fcp.gui.Gui(logger)[source]

Bases: PySide2.QtWidgets.QMainWindow

add_device(device=None)[source]
config_shortcuts()[source]
connect_buttons()[source]
load_json(filename)[source]
open_json()[source]
reload()[source]
save_json()[source]
staticMetaObject = <PySide2.QtCore.QMetaObject object>
validate()[source]
class fcp.gui.LogDetails(gui, node, parent)[source]

Bases: fcp.gui.NodeDetails

load_atts(ui, node)[source]
staticMetaObject = <PySide2.QtCore.QMetaObject object>
class fcp.gui.LogWidget(gui, parent)[source]

Bases: PySide2.QtWidgets.QWidget

add_log(log=None)[source]
reload()[source]
save()[source]
staticMetaObject = <PySide2.QtCore.QMetaObject object>
class fcp.gui.MessageDetails(gui, node: fcp.spec.Message, parent)[source]

Bases: fcp.gui.NodeDetails

add_node(node=None)[source]
load_atts(ui, node)[source]
staticMetaObject = <PySide2.QtCore.QMetaObject object>
class fcp.gui.MessageWidget(gui, node: fcp.spec.Message, details=None, layout=None)[source]

Bases: fcp.gui.NodeDetails

load_atts(ui, node)[source]
staticMetaObject = <PySide2.QtCore.QMetaObject object>
class fcp.gui.NodeDetails(gui, node, parent=None, details=None, layout=None)[source]

Bases: PySide2.QtWidgets.QWidget

Node (Device, Message, Signal, Log, Config, Command) interface

connect_atts()[source]
delete()[source]
load_atts(ui, node)[source]
open_details(checked)[source]
raise_widget(checked)[source]
reload()[source]
save()[source]
staticMetaObject = <PySide2.QtCore.QMetaObject object>
class fcp.gui.SignalDetails(gui, node: fcp.spec.Signal, parent)[source]

Bases: fcp.gui.NodeDetails

load_atts(ui, node)[source]
staticMetaObject = <PySide2.QtCore.QMetaObject object>
class fcp.gui.SignalWidget(gui, node, details=None, layout=None)[source]

Bases: fcp.gui.NodeDetails

load_atts(ui, node)[source]
staticMetaObject = <PySide2.QtCore.QMetaObject object>
fcp.gui.gui(file, logger)[source]

fcp.input module

fcp.input.to_type(str, f)[source]

fcp.spec module

class fcp.spec.Argument(parent: Optional[fcp.spec.Command] = None, name: str = '', id: int = 0, comment: str = '')[source]

Bases: object

Argument node. Represents a Command Argument.

Parameters:
  • name – Name of the Argument.
  • id – Argument identifier.
  • comment – description of the Argument.
compile() → Dict[str, Any][source]

Transform python class node to its dictionary representation.

Returns:A dictionary containing the node parameters
decompile(d: Dict[str, Any]) → None[source]

Transform node dictionary representation into a python class.

Parameters:d – Node dictionary
get_comment() → str[source]
get_id() → int[source]
get_name() → str[source]
set_comment(comment: str) → None[source]
set_id(id: int) → None[source]
set_name(name: str) → None[source]
class fcp.spec.Command(parent: Optional[fcp.spec.Device] = None, name: str = '', n_args: int = 3, comment: str = '', id: int = 0, args: Dict[str, fcp.spec.Argument] = None, rets: Dict[str, fcp.spec.Argument] = None)[source]

Bases: object

Command node. Represents a Command.

Parameters:
  • name – Name of the Command.
  • n_args – Number of arguments in the Command.
  • comment – description of the Command.
  • id – Command identifier.
  • args – Dictionary containing the Command’s input Arguments.
  • rets – Dictionary containing the Command’s output Arguments.
add_arg(arg: fcp.spec.Argument) → None[source]

Add a input Argument to Command.

Parameters:arg – Argument to be added
Returns:Operation success status: True - Success, False - Failure
add_ret(ret: fcp.spec.Argument) → None[source]

Add a output Argument to Command.

Parameters:ret – Argument to be added
Returns:Operation success status: True - Success, False - Failure
compile() → Dict[str, Any][source]

Transform python class node to its dictionary representation.

Returns:A dictionary containing the node parameters
decompile(d: Dict[str, Any]) → None[source]

Transform node dictionary representation into a python class.

Parameters:d – Node dictionary
get_comment() → str[source]
get_id() → int[source]
get_n_args() → int[source]
get_name() → str[source]
normalize()[source]
set_comment(comment: str) → None[source]
set_id(id: int) → None[source]
set_n_args(n_args: int) → None[source]
set_name(name: str) → None[source]
class fcp.spec.Common(parent: fcp.spec.Spec = None, name: str = 'common', id: int = 0, msgs: Dict[str, fcp.spec.Message] = None, cfgs: Dict[str, fcp.spec.Config] = None, cmds: Dict[str, fcp.spec.Command] = None)[source]

Bases: object

add_msg(msg: fcp.spec.Message) → bool[source]
compile() → Dict[str, Any][source]

Transform python class node to its dictionary representation.

Returns:A dictionary containing the node parameters
decompile(d: Dict[str, Any]) → None[source]

Transform node dictionary representation into a python class.

Parameters:d – Node dictionary
get_id() → int[source]
get_name() → str[source]
set_id(id: int) → None[source]
set_name(name: str) → None[source]
class fcp.spec.Config(parent: Optional[fcp.spec.Device] = None, name: str = '', id: int = 0, comment: str = '')[source]

Bases: object

Config node. Represents a Config.

Parameters:
  • name – Name of the Config.
  • id – Config identifier.
  • comment – description of the Config.
compile() → Dict[str, Any][source]

Transform python class node to its dictionary representation.

Returns:A dictionary containing the node parameters
decompile(d: Dict[str, Any]) → None[source]

Transform node dictionary representation into a python class.

Parameters:d – Node dictionary
get_comment() → str[source]
get_id() → int[source]
get_name() → str[source]
normalize()[source]
set_comment(comment: str) → None[source]
set_id(id: int) → None[source]
set_name(name: str) → None[source]
class fcp.spec.Device(parent: Optional[fcp.spec.Spec] = None, name: str = 'default_name', id: int = 0, msgs: Dict[str, fcp.spec.Message] = None, cmds: Dict[str, fcp.spec.Command] = None, cfgs: Dict[str, fcp.spec.Config] = None)[source]

Bases: object

Device node, Represents a CAN device.

Parameters:
  • name – Name of the Device.
  • id – FST Device identifier, lowest 5 bits of the identifier.
  • msgs – Dictionary containing the Device messages.
  • cmds – Dictionary containing the Device commands.
  • cfgs – Dictionary containing the Device configs.

isn’t automatically sent.

add_cfg(cfg: fcp.spec.Config) → None[source]
add_cmd(cmd: fcp.spec.Command) → None[source]
add_msg(msg: fcp.spec.Message) → bool[source]

Add a Message to Device.

Parameters:msg – Message to be added.
Returns:Operation success status: True - Success, False - Failure
compile() → Dict[str, Any][source]

Transform python class node to its dictionary representation.

Returns:A dictionary containing the node parameters
decompile(d: Dict[str, Any]) → None[source]

Transform node dictionary representation into a python class.

Parameters:d – Node dictionary
get_cfg(name: str) → Optional[fcp.spec.Config][source]

Get a Config from Device by its name.

Parameters:name – Config name.
Returns:Config or None if not found.
get_cmd(name: str) → Optional[fcp.spec.Command][source]

Get a Command from Device by its name.

Parameters:name – Command name.
Returns:Command or None if not found.
get_id() → int[source]
get_msg(name: str) → Optional[fcp.spec.Message][source]

Get a Message from Device by its name.

Parameters:name – Message name.
Returns:Message or None if not found.
get_name() → str[source]
normalize()[source]

Update messages, commands and configs dictionary keys.

rm_cfg(name: str) → bool[source]

Remove a Config from Device.

Parameters:name – Name of the Config to be removed.
rm_cmd(name: str) → bool[source]

Remove a Command from Device.

Parameters:name – Name of the Command to be removed.
rm_msg(name: str) → bool[source]

Remove a Message from Device.

Parameters:name – Name of the Message to be removed.
set_id(id: int) → None[source]
set_name(name: str) → None[source]
class fcp.spec.Enum(parent: Optional[fcp.spec.Spec] = None)[source]

Bases: object

Fcp Enum. C lookalike for FCP type definitions with name-value associations.

compile() → Dict[str, Any][source]
decompile(d: Dict[str, Any]) → None[source]

Transform node dictionary representation into a python class.

Parameters:d – Node dictionary
get_name() → str[source]
get_value() → int[source]
normalize()[source]
set_name(name: str) → None[source]
set_value(name: int) → None[source]
class fcp.spec.EnumValue(parent: Optional[fcp.spec.Enum] = None)[source]

Bases: object

Fcp EnumValue. C lookalike for FCP type definitions with name-value associations.

compile() → Dict[str, Any][source]
decompile(d: Dict[str, Any]) → None[source]

Transform node dictionary representation into a python class.

Parameters:d – Node dictionary
get_name() → str[source]
get_value() → int[source]
set_name(name: str) → None[source]
set_value(value: int) → None[source]
class fcp.spec.Log(parent: Optional[fcp.spec.Spec] = None, id: int = 0, name: str = '', n_args: int = 3, comment: str = '', string: str = '')[source]

Bases: object

Log protocol node.

Parameters:
  • id – Log integer identifier.
  • name – Name of the Log node.
  • n_args – Number of arguments in the Log node.
  • comment – Description of the Log node
  • string – Display string for the Log node.
compile() → Dict[str, Any][source]

Transform python class node to its dictionary representation.

Returns:A dictionary containing the node parameters
decompile(d: Dict[str, Any]) → None[source]

Transform node dictionary representation into a python class.

Parameters:d – Node dictionary
get_comment() → str[source]
get_id() → int[source]
get_n_args() → int[source]
get_name() → str[source]
get_string() → str[source]
set_comment(comment: str) → None[source]
set_id(id: int) → None[source]
set_n_args(n_args: int) → None[source]
set_name(name: str) → None[source]
set_string(string: str) → None[source]
class fcp.spec.Message(parent: Optional[fcp.spec.Device] = None, name: str = '', id: int = 0, dlc: int = 8, signals: Dict[str, fcp.spec.Signal] = None, frequency: int = 0, description: str = '')[source]

Bases: object

Message node, Represents a CAN message, similar to a DBC message.

Parameters:
  • name – Name of the Message.
  • id – FST Message identifier, highest 6 bits of the identifier.
  • dlc – Message DLC.
  • signals – Dictionary containing the Message signals.
  • frequency – Transmission period in millisecond. If 0 message

isn’t automatically sent.

add_signal(signal: fcp.spec.Signal) → bool[source]

Add a Signal to Message.

Parameters:signal – Signal to be added
Returns:Operation success status: True - Success, False - Failure
compile() → Dict[str, Any][source]

Transform python class node to its dictionary representation.

Returns:A dictionary containing the node parameters
decompile(d: Dict[str, Any]) → None[source]

Transform node dictionary representation into a python class.

Parameters:d – Node dictionary
get_description() → str[source]
get_dlc() → int[source]
get_frequency() → int[source]
get_id() → int[source]
get_name() → str[source]
get_signal(name: str) → Optional[fcp.spec.Signal][source]

Get a Signal from Message by its name.

Parameters:name – Signal name.
Returns:Signal or None if not found.
normalize()[source]

Update signals dictionary keys.

rm_signal(name: str) → bool[source]

Remove a Signal from Spec.

Parameters:signal – Signal to be removed.
set_description(description: str) → None[source]
set_dlc(dlc: int) → None[source]
set_frequency(frequency: int) → None[source]
set_id(id: int) → None[source]
set_name(name: str) → None[source]
class fcp.spec.Signal(parent: Optional[fcp.spec.Message] = None, name: str = '', start: int = 0, length: int = 0, scale: float = 1, offset: float = 0, unit: str = '', comment: str = '', min_value: int = 0, max_value: int = 0, type: str = 'unsigned', byte_order: str = 'little_endian', mux: str = '', mux_count: int = 1, alias: str = '')[source]

Bases: object

Signal node. Represents a CAN signal, similar to a DBC signal.

Parameters:
  • name – Name of the Signal.
  • start – Start bit
  • length – Signal bit size.
  • scale – Scaling applied to the signal’s data.
  • offset – Offset applied to the signal’s data.
  • unit – Unit of the Signal after applying scaling and offset.
  • comment – Description of the Signal.
  • min_value – Minimum value allowed to the Signal’s data.
  • max_value – Maximum value allowed to the Signal’s data.
  • type – Type of the Signal’s data.
  • mux – Name of the mux Signal. None if the Signal doesn’t belong to a multiplexed Message.
  • mux_count – Number of signals that the mux can reference for this Muxed signal.
compile() → Dict[str, Any][source]

Transform python class node to its dictionary representation.

Returns:A dictionary containing the node parameters
decompile(d: Dict[str, Any]) → None[source]

Transform node dictionary representation into a python class.

Parameters:d – Node dictionary
get_alias() → str[source]
get_byte_order() → str[source]
get_comment() → str[source]
get_length() → int[source]
get_max_value() → float[source]
get_min_value() → float[source]
get_mux() → str[source]
get_mux_count() → int[source]
get_name() → str[source]
get_offset() → float[source]
get_scale() → float[source]
get_start() → int[source]
get_type() → str[source]
get_unit() → str[source]
set_alias(alias: str) → None[source]
set_byte_order(byte_order: str) → None[source]
set_comment(comment: str) → None[source]
set_length(length: int) → None[source]
set_max_value(max_value: float) → None[source]
set_min_value(min_value: float) → None[source]
set_mux(mux: str) → None[source]
set_mux_count(mux_count: int) → None[source]
set_name(name: str) → None[source]
set_offset(offset: float) → None[source]
set_scale(scale: float) → None[source]
set_start(start: int) → None[source]
set_type(type: str) → None[source]
set_unit(unit: str) → None[source]
class fcp.spec.Spec[source]

Bases: object

FCP root node. Holds all Devices, Messages, Signals, Logs, Configs, Commands and Arguments.

add_device(device: fcp.spec.Device) → bool[source]

Add a Device to Spec.

Parameters:device – Device to be added
Returns:Operation success status: True - Success, False - Failure
add_enum(enum: fcp.spec.Enum) → bool[source]

Add a Enum to Spec.

Parameters:enum – Enum to be added
Returns:Operation success status: True - Success, False - Failure
add_log(log: fcp.spec.Log) → bool[source]

Add a Log to Spec.

Parameters:log – Log to be added
Returns:Operation success status: True - Success, False - Failure
compile() → Dict[str, Any][source]

Transform python class node to its dictionary representation.

Returns:A dictionary containing the node parameters
decompile(d: Dict[str, Any]) → None[source]

Transform node dictionary representation into a python class.

Parameters:d – Node dictionary
get_device(name: str) → Optional[fcp.spec.Device][source]

Get a Device from Spec by its name.

Parameters:name – Device name.
Returns:Device or None if not found.
get_log(name: str) → Optional[fcp.spec.Log][source]

Get a Log from Spec by its name.

Parameters:name – Log name.
Returns:Log or None if not found.
normalize()[source]

Update devices and logs dictionary keys.

rm_cmd(command: fcp.spec.Command) → None[source]

Remove a Command from Spec.

Parameters:command – Command to be removed.
rm_config(config: fcp.spec.Config) → None[source]

Remove a Config from Spec.

Parameters:config – Config to be removed.
rm_device(device: fcp.spec.Device) → None[source]

Remove a Device from Spec.

Parameters:device – Device to be removed.
rm_enum(enum)[source]

Remove a Enum from Spec.

Parameters:log – Enum to be removed.
rm_enum_value(enum_value)[source]

Remove a Enum from Spec.

Parameters:log – EnumValue to be removed.
rm_log(log)[source]

Remove a Log from Spec.

Parameters:log – Log to be removed.
rm_message(message: fcp.spec.Message) → None[source]

Remove a Message from Spec.

Parameters:message – Message to be removed.
rm_node(node: Any) → None[source]

Remove a node from Spec.

Parameters:node – node to be removed.
rm_signal(signal: fcp.spec.Signal) → None[source]

Remove a Signal from Spec.

Parameters:signal – Signal to be removed.
fcp.spec.decompose_id(sid: int) → Tuple[int, int][source]

Find the dev_id and the msg_id from the sid.

fcp.spec.field(default_factory)[source]
fcp.spec.handle_key_not_found(d: dict, key: str)[source]
fcp.spec.make_dict()[source]
fcp.spec.make_sid(dev_id: int, msg_id: int) → int[source]

Find the sid from the dev_id and the msg_id

fcp.spec.normalize(xs: Dict[str, Any], key: Callable[[Any], str] = None)[source]
Update xs dictionary keys according to key.
By default key is lambda x : x.name
Parameters:
  • xs – Dictionary containing spec node
  • key – Function that returns the key for a particular node

fcp.template module

class fcp.template.Tpl(logger, template_dir)[source]

Bases: object

check_tpl_dir()[source]
open_tpl_files()[source]
render(name, *args, **kwargs)[source]

fcp.validator module

c-generator.

Usage:
validator.py validate <json> validator.py (-h | –help) validator.py –version
Options:
-h –help Show this screen. –version Show version.
fcp.validator.check(category, arg)[source]
fcp.validator.check_decorator(category)[source]
fcp.validator.fail_msg(node, msg)[source]
fcp.validator.spec_repeated_names(spec)[source]
fcp.validator.validate(logger, spec)[source]

fcp.version module

Module contents