Skip to content

Commit

Permalink
canTx header done
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiajun-Huang committed Jan 3, 2025
1 parent 6334767 commit b85e460
Show file tree
Hide file tree
Showing 11 changed files with 2,932 additions and 1,253 deletions.
1,496 changes: 1,496 additions & 0 deletions output/app/app_canTx.c

Large diffs are not rendered by default.

1,284 changes: 1,284 additions & 0 deletions output/app/app_canTx.h

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion scripts/code_generation/jsoncan/generate_can_from_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

modules = {
AppCanUtilsModule(can_db, args.board): os.path.join("app", "app_canUtils"),
# AppCanTxModule(can_db, args.board): os.path.join("app", "app_canTx"),
AppCanTxModule(can_db, args.board): os.path.join("app", "app_canTx"),
# AppCanRxModule(can_db, args.board): os.path.join("app", "app_canRx"),
# AppCanAlertsModule(can_db, args.board): os.path.join("app", "app_canAlerts"),
# AppCanDataCaptureModule(can_db): os.path.join("app", "app_canDataCapture"),
Expand Down
13 changes: 9 additions & 4 deletions scripts/code_generation/jsoncan/src/can_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
This file contains various classes to fully describes a CAN bus: The nodes, messages, and signals on the bus.
"""

from dataclasses import dataclass
from typing import List, Union, Dict
import logging
from dataclasses import dataclass
from typing import Dict, List, Union

from strenum import StrEnum

from .json_parsing.schema_validation import AlertsEntry
from .utils import bits_for_uint, bits_to_bytes, is_int, pascal_to_screaming_snake_case, pascal_to_snake_case

from .utils import (bits_for_uint, bits_to_bytes, is_int,
pascal_to_screaming_snake_case, pascal_to_snake_case)

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -188,6 +189,10 @@ def snake_name(self):

def scremming_snake_name(self):
return pascal_to_screaming_snake_case(self.name)

# type of the message
def c_type(self):
return self.name + "_Signals"


@dataclass(frozen=True)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import jinja2 as j2

from .c_writer import *
from .utils import load_template


class AppCanTxModule(CModule):
Expand Down Expand Up @@ -171,3 +174,15 @@ def source(self):
cw.add_line()

return str(cw)

def header_template(self):
template = load_template("app_canTx.h.j2")
j2_env = j2.Environment(loader=j2.BaseLoader, extensions=['jinja2.ext.loopcontrols'])
template = j2_env.from_string(template)
return template.render(messages=self._db.tx_msgs_for_node(self._node))

def source_template(self):
template = load_template("app_canTx.c.j2")
j2_env = j2.Environment(loader=j2.BaseLoader, extensions=['jinja2.ext.loopcontrols'])
template = j2_env.from_string(template)
return template.render(source=self.source())
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* @note This file is auto-generated. Do not modify!
*/
// clang-format off

#pragma once

/* ------------------------------- Includes ------------------------------- */

#include "app_canUtils.h"

/* ------------------------- Function Prototypes -------------------------- */

/**
* Initialize TX signals to their starting values.
*/
void app_canTx_init(void);



{% for msg in messages -%}
{%- for signal in msg.signals -%}
/**
* Update value stored in TX table of signal {{ signal.name }} in msg {{ msg.name }}.
*/
void app_canTx_{{ signal.name }}_set({{ signal.datatype() }} value);
{% endfor -%}
{% endfor %}

{% for msg in messages -%}
{%- for signal in msg.signals -%}
/**
* Get value stored in TX table of signal {{ signal.name }} in msg {{ msg.name }}.
*/
{{ signal.datatype() }} app_canTx_{{ msg.name }}_{{ signal.name }}_get(void);
{% endfor -%}
{% endfor %}

{% for msg in messages -%}
/**
* Get pointer to value stored in TX table of msg {{ msg.name }}.
*/
{{ msg.c_type() }}* app_canTx_{{ msg.name }}_getData();
{% endfor %}




Loading

0 comments on commit b85e460

Please sign in to comment.