-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a1c8b62
Showing
7 changed files
with
406 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
.PHONY: install | ||
install: | ||
poetry install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |