Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare fcp development #14

Merged
merged 5 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions example/example.fcp
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
version: "3"

import iib;

/*this is a comment*/
enum master_state {
OFF = 0;
ON = 1;
INVALID = 2;
}
};

enum master_state2 {
OFF = 0;
ON = 1;
INVALID = 2;
}
};

/* this is a comment */
struct master_ts {
/* this is a comment regarding master_ts_state */
master_ts_state: u1 | unit("m/s");
master_ts_off_reason: u7;
}
master_ts_state @ 0: u1 | unit("m/s");
master_ts_off_reason @ 1: u7;
};

struct master_cell_error {
cell_id: u8;
cell_error: u16;
}
cell_id @ 0: u8;
cell_error @ 1: u16;
};
17 changes: 8 additions & 9 deletions example/example.fpi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
device master {
id : 14;
}
version: "3"

device master: id(14) {};

/*Sent by master and this is a comment*/
broadcast master_ts {
Expand All @@ -10,16 +10,16 @@ broadcast master_ts {
type: master_ts;
signal master_ts_state {
scale: 2.0;
}
}
};
};


broadcast master_status {
id : 15;
dlc : 8;
device: master;
type: master_ts;
}
};

broadcast master_cell_error{
id: 960;
Expand All @@ -30,6 +30,5 @@ broadcast master_cell_error{
mux_count: 144;
mux: cell_id;
start: 48;
}
}

};
};
8 changes: 5 additions & 3 deletions example/iib.fcp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
version: "3"

struct iib_status {
timestamp: u32;
status: u8;
}
timestamp @ 0: u32;
status @ 1: u8;
};
1 change: 0 additions & 1 deletion fcp/version.py

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion hooks/check_release_notes
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import sys
import os

def main(args):
with open("fcp/version.py") as f:
with open("src/fcp/version.py") as f:
txt = f.read()
version = txt.split("=")[1].strip()
version = "v"+version[1:-1]+".md"
Expand Down
2 changes: 1 addition & 1 deletion hooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
set -e
hooks/check_release_notes
hooks/black
hoos/pylint
#hooks/pylint
1 change: 1 addition & 0 deletions plugins/fcp_nop/fcp_nop/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .generator import Generator, Verifier
15 changes: 15 additions & 0 deletions plugins/fcp_nop/fcp_nop/generator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from fcp.codegen import CodeGenerator
from fcp.verifier import BaseVerifier, simple_error


class Verifier(BaseVerifier):
pass


class Generator(CodeGenerator):
def __init__(self):
pass

def generate(self, fcp, templates={}, skels={}):
print(fcp)
return {}
15 changes: 15 additions & 0 deletions plugins/fcp_nop/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from setuptools import setup, find_packages

setup(
name="fcp_nop",
description="",
version="0.1",
author="Joao Freitas",
author_email="joaj.freitas@gmail.com",
license="GPLv3",
url="https://gitlab.com/joajfreitas/fcp-cgen",
packages=find_packages(),
install_requires=["fcp"],
long_description="",
long_description_content_type="text/markdown",
)
22 changes: 22 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[project]
name = "fcp"
version = "1.0.0"
description = "CAN bus manager"
license = {file = "LICENSE.txt"}
readme = "README.md"
url = "https://github.com/joajfreitas/fcp-core"
requires-python = ">=3.12"
dependencies = [
"click",
"lark",
"coloredlogs",
"serde",
"termcolor"
]

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project.scripts]
fcp = "fcp.__main__:main"
File renamed without changes.
File renamed without changes.
18 changes: 7 additions & 11 deletions fcp/codegen.py → src/fcp/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ def gen(self, fcp, templates, skels, output_path):

self.output_path = pathlib.Path(output_path)

for path, content in self.generate(
fcp, self.output_path, templates, skels
).items():
for path, content in self.generate(fcp, templates, skels).items():
logging.info(f"Generating {path}")
os.makedirs(path.parent, exist_ok=True)
with open(path, "w", encoding="utf-8") as file:
Expand All @@ -52,24 +50,22 @@ def __init__(self):

def list_generators(self):
"""Find installed generators"""
return {
name: importlib.import_module(name)
for finder, name, ispkg in pkgutil.iter_modules()
if name.startswith("fcp_")
}
return [
name for _, name, _ in pkgutil.iter_modules() if name.startswith("fcp_")
]

def get_generator(self, generator_name):
"""Get generator by name."""
generators = self.list_generators()
if "fcp_" + generator_name not in generators.keys():
available_generators = [name[4:] for name in generators.keys()]
if "fcp_" + generator_name not in generators:
available_generators = [name[4:] for name in generators]
logging.error("Code generator %s not available", generator_name)
logging.info(
"Currently available code generators: %s", available_generators
)
sys.exit(1)

return generators["fcp_" + generator_name]
return importlib.import_module("fcp_" + generator_name)

def get_templates(self, template_dir):
if template_dir is None:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions src/fcp/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VERSION = "1.0.0"
File renamed without changes.