-
Notifications
You must be signed in to change notification settings - Fork 0
Check new CANDecoder implementation #1
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
dhruv-aron
wants to merge
8
commits into
main
Choose a base branch
from
FW-228/candecoder
base: main
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
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8ba2d5e
add code to read CAN messages every 1s
bquan0 8f9e659
add canBus.begin()
bquan0 0774d52
working read example
bquan0 314c242
add submodule with canmanager
bquan0 16e72ea
First (untested) version of new CANDecoder class for testing purposes
dhruv-aron 06ccd48
Updated CANDecoder implementation based on new CANManager implementat…
dhruv-aron d786f5d
working tested canmanager & candecoder code
bquan0 821855e
clean up code, add comments
bquan0 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| [submodule "embedded-pio"] | ||
| path = embedded-pio | ||
| url = git@github.com:badgerloop-software/embedded-pio.git |
Submodule embedded-pio
added at
ce0f7c
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,16 @@ | ||
| #include "canmanager.h" | ||
|
|
||
| class CANDecoder : public CANManager { | ||
| public: | ||
|
|
||
| CANDecoder(CAN_TypeDef* canPort, CAN_PINS pins, int frequency = DEFAULT_CAN_FREQ); | ||
|
|
||
| /* Reads input message and does any logic handling needed | ||
| * Intended to be implemented by class extension per board | ||
| */ | ||
| void readHandler(CAN_message_t msg); | ||
|
|
||
| /* Send all of this board's message over CAN | ||
| */ | ||
| void sendSignal(); | ||
| }; |
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,63 @@ | ||
| #include "candecoder.h" | ||
|
|
||
| #define IS_FIRST_CAN false | ||
|
|
||
| #if IS_FIRST_CAN | ||
| #define RECEIVE_BASE_ID 0x000 | ||
| #define SEND_BASE_ID 0x100 | ||
| #define INT8_VAL 16 | ||
| #define INT16_VAL 30271 | ||
| #define FLOAT_VAL 9.8 | ||
| #define BOOL_VAL true | ||
| #else | ||
| #define RECEIVE_BASE_ID 0x100 | ||
| #define SEND_BASE_ID 0x000 | ||
| #define INT8_VAL 234 | ||
| #define INT16_VAL 57219 | ||
| #define FLOAT_VAL 8.6 | ||
| #define BOOL_VAL false | ||
| #endif | ||
|
|
||
| uint8_t int8Received; | ||
| uint16_t int16Received; | ||
| float floatReceived; | ||
| bool boolReceived; | ||
|
|
||
| int numMessagesReceived[4] = {0,0,0,0}; | ||
|
|
||
| CANDecoder::CANDecoder(CAN_TypeDef* canPort, CAN_PINS pins, int frequency) : CANManager(canPort, pins, frequency){}; | ||
|
|
||
| void CANDecoder::readHandler(CAN_message_t msg) { | ||
| switch (msg.id) { | ||
| case (RECEIVE_BASE_ID + 0): | ||
| int8Received = *(int8_t*)msg.buf; | ||
| numMessagesReceived[0]++; | ||
| break; | ||
| case (RECEIVE_BASE_ID + 1): | ||
| int16Received = *(int16_t*)msg.buf; | ||
| numMessagesReceived[1]++; | ||
| break; | ||
| case (RECEIVE_BASE_ID + 2): | ||
| floatReceived = *(float*)msg.buf; | ||
| numMessagesReceived[2]++; | ||
| break; | ||
| case (RECEIVE_BASE_ID + 3): | ||
| boolReceived = *(bool*)msg.buf; | ||
| numMessagesReceived[3]++; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| void CANDecoder::sendSignal() { | ||
| uint8_t test8int = INT8_VAL; | ||
| this->sendMessage(SEND_BASE_ID + 0, (void*)&test8int, sizeof(test8int)); | ||
|
|
||
| uint16_t test16int = INT16_VAL; | ||
| this->sendMessage(SEND_BASE_ID + 1, (void*)&test16int, sizeof(test16int)); | ||
|
|
||
| float testFloat = FLOAT_VAL; | ||
| this->sendMessage(SEND_BASE_ID + 2, (void*)&testFloat, sizeof(testFloat)); | ||
|
|
||
| bool testBoolean = BOOL_VAL; | ||
| this->sendMessage(SEND_BASE_ID + 3, (void*)&testBoolean, sizeof(testBoolean)); | ||
| } |
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 |
|---|---|---|
| @@ -1,18 +1,34 @@ | ||
| #include <Arduino.h> | ||
| #include "STM32_CAN.h" | ||
| #include "candecoder.h" | ||
|
|
||
| // put function declarations here: | ||
| int myFunction(int, int); | ||
| CANDecoder candecoder(CAN1, ALT_2, 500000); | ||
|
|
||
| extern uint8_t int8Received; | ||
| extern uint16_t int16Received; | ||
| extern float floatReceived; | ||
| extern bool boolReceived; | ||
|
|
||
| extern int numMessagesReceived[4]; | ||
|
|
||
| int counter = 0; | ||
|
|
||
| void setup() { | ||
| // put your setup code here, to run once: | ||
| int result = myFunction(2, 3); | ||
| Serial.begin(9600); | ||
| } | ||
|
|
||
| void loop() { | ||
| // put your main code here, to run repeatedly: | ||
| } | ||
| candecoder.sendSignal(); | ||
| candecoder.runQueue(50); // 50ms, so 20 sets of messages sent per second | ||
| counter++; | ||
|
|
||
| // put function definitions here: | ||
| int myFunction(int x, int y) { | ||
| return x + y; | ||
| // print out debug info every second (instead of every 50ms) | ||
| if (counter > 20) { | ||
| counter = 0; | ||
| Serial.println(int8Received); | ||
| Serial.println(int16Received); | ||
| Serial.println(floatReceived); | ||
| Serial.println(boolReceived); | ||
| printf("%d | %d | %d | %d\n\n", numMessagesReceived[0], numMessagesReceived[1], numMessagesReceived[2], numMessagesReceived[3]); | ||
| } | ||
| } | ||
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.