-
Notifications
You must be signed in to change notification settings - Fork 3
Gabriel edits #23
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
Open
reality95
wants to merge
17
commits into
master
Choose a base branch
from
gabriel_edits
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Gabriel edits #23
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
233f6e6
first draft
reality95 ae434af
finished testing
reality95 6a3e739
changed names
reality95 7a52116
replaced array size from INVALID_NAME to number
reality95 37e4314
deleted _T
reality95 35a5d3f
added get_message_type
reality95 07a16eb
removed uints and old template names
reality95 277f84b
separed send with period
reality95 1197aa3
fixed empty lines
reality95 b7c6042
change get_msg_len to get_num_msg_types
reality95 542a868
replace ID with Name
reality95 661c705
added deletion of objects
reality95 749390f
replaced CAN with TestCAN
reality95 fea0483
added get_input method
reality95 6be3c84
added some comments
reality95 fd3ba31
added gitignore to ignore the source files
reality95 978ba65
fixed the linking issue related to read_frame
reality95 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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,10 @@ | ||
| import os | ||
|
|
||
|
|
||
| def write(env, computers, input_path, output_path, testing): | ||
| os.makedirs(output_path, exist_ok=True) | ||
| template = env.get_template(str(input_path)) | ||
| for computer in computers: | ||
| f_path = os.path.join(output_path, 'canlib_{}.cpp'.format(computer.name)) | ||
| with open(f_path, 'w') as f: | ||
| f.write(template.render(computer=computer, testing=testing)) | ||
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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,11 @@ | ||
| import os | ||
|
|
||
|
|
||
| def write(env, computers, input_path, output_path, testing): | ||
| os.makedirs(output_path, exist_ok=True) | ||
| template = env.get_template(str(input_path)) | ||
|
|
||
| for computer in computers: | ||
| f_path = os.path.join(output_path, 'canlib_{}.hpp'.format(computer.name)) | ||
| with open(f_path, 'w') as f: | ||
| f.write(template.render(computer=computer, testing=testing)) |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,68 @@ | ||
| {%- macro key_type(num_bits) -%} uint{{ (((num_bits / 8) | round(method='ceil')) * 8) | int }}_t {%- endmacro -%} | ||
|
|
||
| {%- macro last_sent_def(bus, msg, msg_name) -%} | ||
| {%- if msg.frame is defined -%} | ||
| {% for sub_frame in msg.frame -%} | ||
| {{ last_sent_def(bus, sub_frame, msg_name + '::' + sub_frame.name) }} | ||
reality95 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| {%- endfor %} | ||
| {%- else -%} | ||
| Clock::time_point {{msg_name}}::last_sent_; | ||
| {%- endif %} | ||
| {%- endmacro -%} | ||
|
|
||
| #include "static.hpp" | ||
| #include "bus.hpp" | ||
| #include "structs.hpp" | ||
| #include "pack_unpack.hpp" | ||
|
|
||
| namespace CANlib { | ||
|
|
||
| extern const std::pair<uint32_t, uint32_t>* frame_id_range[{{ get_len(can) }}]; | ||
| extern const uint32_t* frame_len[{{ get_len(can) }}]; | ||
| extern const uint32_t* keys[{{ get_len(can) }}]; | ||
| extern const size_t can_size[{{ get_len(can) }}]; | ||
| extern Message** messages[{{ get_len(can) }}]; | ||
|
|
||
| {% for bus in can.bus %} | ||
| {{ last_sent_def(bus, bus, bus.name) }} | ||
| {% endfor %} | ||
|
|
||
| } | ||
|
|
||
| using namespace CANlib; | ||
|
|
||
| static uint32_t identify_internal(const uint32_t key, const Frame& frame, int l, int r, int bus_idx) { | ||
| for (int i = l;i <= r;++i) { | ||
| if (keys[bus_idx][i] == key) { | ||
| int left_bound = frame_id_range[bus_idx][i].first; | ||
| int right_bound = frame_id_range[bus_idx][i].second; | ||
| // If this is a frame search inside the frame, otherwise return the index of the message | ||
| if (left_bound <= right_bound) { | ||
| uint64_t bitstring; | ||
| to_bitstring((uint8_t*)frame.data, &bitstring); | ||
| return identify_internal(EXTRACT(bitstring, left_bound, right_bound), frame, i + 1, i + 1 + frame_len[bus_idx][i], bus_idx); | ||
| } else { | ||
| return i; | ||
| } | ||
| } | ||
| } | ||
| return 0; | ||
| } | ||
|
|
||
|
|
||
| uint32_t CANlib::identify(AbstractBus bus, const Frame& frame) { | ||
| const int bus_idx = static_cast<int>(bus); | ||
| return identify_internal(frame.id, frame, 1, can_size[bus_idx] - 1, bus_idx); | ||
| } | ||
|
|
||
| void CANlib::handle_frame(AbstractBus bus_name, const Frame& frame) { | ||
| if (bus_name == AbstractBus::INVALID_NAME) { | ||
| return; | ||
reality95 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| uint32_t message_idx = identify(bus_name, frame); | ||
| uint32_t bus_idx = static_cast<int>(bus_name); | ||
| if (message_idx > 0) { | ||
| messages[bus_idx][message_idx]->pack(frame); | ||
| } | ||
| } | ||
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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,40 @@ | ||
| {%- set ns = namespace(first_frame=true) -%} | ||
|
|
||
| {%- macro enum_name(msg, msg_name=msg.name) -%} | ||
| {%- if msg.frame is defined -%} | ||
| {% for sub_frame in msg.frame -%} | ||
| {{ enum_name(sub_frame, msg_name + '_' + sub_frame.name) }} | ||
| {%- endfor -%} | ||
| {%- else %} | ||
| {{ msg_name }}, | ||
| {%- endif -%} | ||
| {%- endmacro -%} | ||
| #pragma once | ||
|
|
||
| #include "static.hpp" | ||
|
|
||
| namespace CANlib { | ||
|
|
||
| enum class AbstractBus { | ||
| {%- for bus in can.bus %} | ||
| {{ bus.name }}, | ||
| {%- endfor %} | ||
| INVALID_NAME, | ||
| }; | ||
|
|
||
| uint32_t identify(AbstractBus, const Frame&); | ||
| void handle_frame(AbstractBus, const Frame&); | ||
|
|
||
| {% for bus in can.bus %} | ||
| namespace {{bus.name}} { | ||
| {%- set ns.first_frame = true %} | ||
| enum class MessageType { | ||
| UNKNOWN_MSG = 0, | ||
| {%- for msg in bus.frame -%} | ||
| {{- enum_name(msg) }} | ||
| {%- endfor %} | ||
| }; | ||
| } // {{bus.name}} | ||
| {% endfor -%} | ||
|
|
||
| } // CANlib |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.