diff --git a/FrontLights.cpp b/FrontLights.cpp new file mode 100644 index 0000000..d1294ca --- /dev/null +++ b/FrontLights.cpp @@ -0,0 +1,51 @@ +#include +#include + +namespace SolarGators { +namespace DataModules { +namespace { + static constexpr uint32_t SIZE = 3; +} + +FrontLights::FrontLights(): + DataModule(SolarGators::DataModuleInfo::FRONT_LIGHTS_ID, 0, SIZE), + + throttle(0) + +{ } + +FrontLights::~FrontLights() +{ } + + +uint_16_t FrontLights::GetthrottleVal() const +{ + return throttle; +} + + +void FrontLights::ToByteArray(uint8_t* buff) const +{ + + + buff[0] = static_cast(throttle << 0); + + buff[1] = static_cast(throttle << 1); + + +} +void FrontLights::FromByteArray(uint8_t* buff) +{ + + throttle_ = static_cast(buff[1]) << 8 | buff[0]; + +} + +#ifdef IS_TELEMETRY +void FrontLights::PostTelemetry(PythonScripts* scripts) { + +} +#endif + +} /* namespace DataModules */ +} /* namespace SolarGators */ \ No newline at end of file diff --git a/datamodule/cpp/DataModuleInfo.hpp b/datamodule/cpp/DataModuleInfo.hpp new file mode 100644 index 0000000..e69de29 diff --git a/datamodule/cpp/module.cpp b/datamodule/cpp/module.cpp index f732c9d..2509dfa 100644 --- a/datamodule/cpp/module.cpp +++ b/datamodule/cpp/module.cpp @@ -18,22 +18,26 @@ namespace { { } {% for attribute in attributes %} - {{ attribute["type"] }} {{ moduleName }}::Get{{ attribute["name"] }}Val() const - { - return {{ attribute["name"] }}; - } +{{ attribute["type"] }} {{ moduleName }}::Get{{ attribute["name"] }}Val() const +{ + return {{ attribute["name"] }}; +} {% endfor %} void {{ moduleName }}::ToByteArray(uint8_t* buff) const { - buff[0] = static_cast(throttle_); - buff[1] = static_cast(throttle_ >> 8); - buff[2] = static_cast(breaks_); + {% for attribute in attributes %} + {%- for byte in range(attribute["bytes"]) %} + buff[{{ byte }}] = static_cast({{ attribute["name"] }} >> {{ byte }}); + {% endfor %} + {% endfor %} } void {{ moduleName }}::FromByteArray(uint8_t* buff) { - throttle_ = static_cast(buff[1]) << 8 | buff[0]; - breaks_ = static_cast(buff[2] & 0x1); + {% for attribute in attributes %} + // TODO: This one is much harder and prone to error + throttle_ = static_cast(buff[1]) << 8 | buff[0]; + {% endfor %} } #ifdef IS_TELEMETRY diff --git a/datamodule/generate.py b/datamodule/generate.py index 50d426e..2e33046 100644 --- a/datamodule/generate.py +++ b/datamodule/generate.py @@ -17,9 +17,15 @@ def main(): for can_message in config["can_messages"]: - cpp_template.render( - moduleName=can_message["name"] - ) + for attribute in can_message["schema"]: + attribute["bytes"] = 2 + + with open(f"{can_message['name']}.cpp", "w") as f: + file = cpp_template.render( + moduleName=can_message["name"], + attributes=can_message["schema"], + ) + f.write(file) if __name__ == "__main__":