-
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.
Merge pull request #4 from DallasFormulaRacing/feature/CAN_Relay
Feature/can relay
- Loading branch information
Showing
10 changed files
with
191 additions
and
8 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
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 |
---|---|---|
|
@@ -23,6 +23,7 @@ class IMutex { | |
virtual void Lock() = 0; | ||
|
||
virtual void Unlock() = 0; | ||
|
||
}; | ||
|
||
} // namespace application | ||
|
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 |
---|---|---|
|
@@ -31,6 +31,4 @@ void MutexCmsisV2::Unlock() { | |
osMutexRelease(mutex_id_); | ||
} | ||
|
||
|
||
|
||
} // namespace application |
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,50 @@ | ||
/* | ||
* can_relay.cpp | ||
* | ||
* Created on: May 16, 2024 | ||
* Author: Nico | ||
*/ | ||
#include "./can_relay.hpp" | ||
namespace application{ | ||
|
||
Can_Relay::Can_Relay(std::shared_ptr<platform::ICan> can_bus, | ||
CircularQueue<DataPayload> queue): | ||
can_bus_(can_bus), | ||
queue_(queue){} | ||
|
||
void Can_Relay::bitSet(float value, uint8_t* byteArray) { | ||
std::memcpy(byteArray, &value, sizeof(float)); | ||
std::reverse(byteArray, byteArray + 4); | ||
} | ||
|
||
void Can_Relay::Generate_Messages(application::DataPayload data){ | ||
|
||
transmission_ended_ = false; | ||
uint8_t row; | ||
uint8_t column; | ||
data.RawRow(message_row); | ||
for(int i = 0; i < 5; i++){//partial send for autocross | ||
row = i/2; //integer division by default floors | ||
column = (i%2) * 4; //the column which the row goes into is essentially sinusoidal | ||
bitSet(message_row[i], &message[row][column]); | ||
} | ||
|
||
} | ||
|
||
|
||
void Can_Relay::Send_Messages(){ | ||
can_bus_->ChangeArbId(0x417); | ||
for(int i = 0; i < 3; i++){ | ||
can_bus_->ChangeArbId(0x417 + i); //each message has a unique ID | ||
can_bus_->Transmit(message[i]); | ||
printf("Sending Message! \n"); | ||
} | ||
} | ||
|
||
void Can_Relay::End_Transmission(bool logging_flag){ | ||
if(!logging_flag && !transmission_ended_){ | ||
can_bus_->Transmit(kEnd_transmission_); | ||
transmission_ended_ = true; | ||
} | ||
} | ||
} |
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,56 @@ | ||
/* | ||
* can_relay.hpp | ||
* | ||
* Created on: May 3, 2024 | ||
* Author: Nico | ||
*/ | ||
#ifndef DFR_LIBRARIES_APPLICATION_RELAY_CAN_RELAY_HPP_ | ||
#define DFR_LIBRARIES_APPLICATION_RELAY_CAN_RELAY_HPP_ | ||
#include <memory> | ||
#include <algorithm> | ||
#include <cstring> | ||
|
||
#include "../../Platform/STM/F4/CAN/bxcan_stmf4.hpp" | ||
#include "../../Platform/Interfaces/igpio.hpp" | ||
#include "../circular_queue.hpp" | ||
#include "../data_payload.hpp" | ||
|
||
#include <bitset> | ||
|
||
namespace application{ | ||
class Can_Relay{ | ||
public: | ||
Can_Relay(std::shared_ptr<platform::ICan> can_bus, | ||
CircularQueue<DataPayload> queue); | ||
//shared pointer to the can bus to relay and reference to the data queue to get the message | ||
//allocate memory | ||
|
||
~Can_Relay(); | ||
|
||
void Generate_Messages(DataPayload data); | ||
|
||
void Send_Messages(); | ||
|
||
void End_Transmission(bool logging_flag); | ||
|
||
void bitSet(float value, uint8_t*); | ||
private: | ||
|
||
std::shared_ptr<platform::ICan> can_bus_; | ||
|
||
CircularQueue<DataPayload>& queue_; | ||
|
||
uint8_t kEnd_transmission_[8] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; | ||
|
||
static constexpr uint8_t messageSize = 29; | ||
|
||
static constexpr uint8_t kRows = 15; | ||
|
||
bool transmission_ended_ = false; | ||
|
||
uint8_t message[kRows][8] = {0}; | ||
|
||
float message_row[messageSize] = {0}; | ||
}; | ||
} | ||
#endif /* DFR_LIBRARIES_APPLICATION_RELAY_CAN_RELAY_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
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
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
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
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