Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Seth10001 committed Sep 14, 2023
0 parents commit a1c8b62
Show file tree
Hide file tree
Showing 7 changed files with 406 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

.PHONY: install
install:
poetry install
23 changes: 23 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Important things:
# - need to be able to support any type
# - need to be able to handle booleans
#


can_messages:
- id: 0x11
name: "FrontLights"
schema:
# will parse the next two bytes
- type: "uint_16_t"
name: "throttle"
default: 0

# boolean map
- type: "boolean_map"
bits:
0:
name: "brake"
default: false
- name: "SomeOtherModule"
dbc: "some_message.bdc"
46 changes: 46 additions & 0 deletions datamodule/cpp/module.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include <{{ moduleName }}.hpp>
#include <DataModuleInfo.hpp>

namespace SolarGators {
namespace DataModules {
namespace {
static constexpr uint32_t SIZE = 3;
}

{{ moduleName }}::{{ moduleName }}():
DataModule(SolarGators::DataModuleInfo::FRONT_LIGHTS_ID, 0, SIZE),
{% for attribute in attributes %}
{{ attribute["name"] }}({{ attribute["default"] }})
{% endfor %}
{ }

{{ moduleName }}::~{{ moduleName }}()
{ }

{% for attribute in attributes %}
{{ attribute["type"] }} {{ moduleName }}::Get{{ attribute["name"] }}Val() const
{
return {{ attribute["name"] }};
}
{% endfor %}

void {{ moduleName }}::ToByteArray(uint8_t* buff) const
{
buff[0] = static_cast<uint8_t>(throttle_);
buff[1] = static_cast<uint8_t>(throttle_ >> 8);
buff[2] = static_cast<uint8_t>(breaks_);
}
void {{ moduleName }}::FromByteArray(uint8_t* buff)
{
throttle_ = static_cast<uint16_t>(buff[1]) << 8 | buff[0];
breaks_ = static_cast<bool>(buff[2] & 0x1);
}

#ifdef IS_TELEMETRY
void {{ moduleName }}::PostTelemetry(PythonScripts* scripts) {

}
#endif

} /* namespace DataModules */
} /* namespace SolarGators */
42 changes: 42 additions & 0 deletions datamodule/cpp/module.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* FrontLights.hpp
*
* Created on: Jan 17, 2022
* Author: John Carr
*/

#ifndef SOLARGATORSBSP_STM_DATAMODULES_INC_FRONTLIGHTS_HPP_
#define SOLARGATORSBSP_STM_DATAMODULES_INC_FRONTLIGHTS_HPP_

#include <DataModule.hpp>
#define BUFF_SIZE 50

namespace SolarGators {
namespace DataModules {

class FrontLights: public DataModule {
public:
FrontLights();
~FrontLights();
uint16_t GetThrottleVal() const;
bool GetBreaksVal() const;
uint8_t buffCtr;
uint16_t breaksBuffer[BUFF_SIZE];
// CAN Functions
void ToByteArray(uint8_t* buff) const;
void FromByteArray(uint8_t* buff);
#ifdef IS_TELEMETRY
void PostTelemetry(PythonScripts* scripts);
#endif

protected:
uint16_t throttle_;
bool breaks_;

// TODO: Accelerometer values
};

} /* namespace DataModules */
} /* namespace SolarGators */

#endif /* SOLARGATORSBSP_STM_DATAMODULES_INC_FRONTLIGHTS_HPP_ */
26 changes: 26 additions & 0 deletions datamodule/generate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import os
import sys
import yaml
from jinja2 import Environment, FileSystemLoader, select_autoescape


def main():
config_file = sys.argv[1]

with open(config_file, "r") as f:
config = yaml.safe_load(f)


env = Environment(loader=FileSystemLoader(os.path.dirname(os.path.abspath(__file__))))

cpp_template = env.get_template("cpp/module.cpp")

for can_message in config["can_messages"]:

cpp_template.render(
moduleName=can_message["name"]
)


if __name__ == "__main__":
main()
246 changes: 246 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[tool.poetry]
name = "telemetry-generation"
version = "0.1.0"
description = ""
authors = ["Raymond Bernardo"]
license = "MIT"
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.9"
Jinja2 = "^3.1.2"
pyyaml = "^6.0.1"

[tool.poetry.group.dev.dependencies]
pytest = "^7.4.2"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

0 comments on commit a1c8b62

Please sign in to comment.