Skip to content
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

Fixed FOME CAN data bus selection #275

Merged
merged 2 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions firmware/controllers/can/can_dash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1293,14 +1293,16 @@ void canDashboardAim(CanCycle cycle) {
return;
}

transmitStruct<Aim5f0>(0x5f0, false);
transmitStruct<Aim5f1>(0x5f1, false);
transmitStruct<Aim5f2>(0x5f2, false);
transmitStruct<Aim5f3>(0x5f3, false);
transmitStruct<Aim5f4>(0x5f4, false);
transmitStruct<Aim5f5>(0x5f5, false);
transmitStruct<Aim5f6>(0x5f6, false);
transmitStruct<Aim5f7>(0x5f7, false);
auto canChannel = engineConfiguration->canBroadcastUseChannelTwo;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is not "canChannel" a less than ideal name for "use second channel"? also what if soon more than two buses would be supported? A few of stm32f7 have three CAN buses.

Copy link
Contributor Author

@Krakert Krakert Oct 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now canBroadcastUseChannelTwo is a Bool, CAN 2 is a true / 1 so when more CAN buses are added we can switch to a int which keeps the logic the same.
0 -> CAN1
1 -> CAN2
2 -> CAN3

Copy link
Contributor

@rusefillc rusefillc Oct 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So why not "size_t busIndex = engineConfiguration->canBroadcastUseChannelTwo;" to keep the... technical debt most localized?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea, that was going to be my next comment, we should really be doing size_t busIndex = engineConfiguration->canBroadcastUseChannelTwo ? 1 : 0


transmitStruct<Aim5f0>(0x5f0, false, canChannel);
transmitStruct<Aim5f1>(0x5f1, false, canChannel);
transmitStruct<Aim5f2>(0x5f2, false, canChannel);
transmitStruct<Aim5f3>(0x5f3, false, canChannel);
transmitStruct<Aim5f4>(0x5f4, false, canChannel);
transmitStruct<Aim5f5>(0x5f5, false, canChannel);
transmitStruct<Aim5f6>(0x5f6, false, canChannel);
transmitStruct<Aim5f7>(0x5f7, false, canChannel);

// there are more, but less important for us
// transmitStruct<Aim5f8>(0x5f8, false);
Expand Down
23 changes: 12 additions & 11 deletions firmware/controllers/can/can_verbose.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,17 +216,18 @@ static void populateFrame(Odometry& msg) {
void sendCanVerbose() {
auto base = engineConfiguration->verboseCanBaseAddress;
auto isExt = engineConfiguration->rusefiVerbose29b;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

omg the tabs! 😆

transmitStruct<Status> (base + 0, isExt);
transmitStruct<Speeds> (base + 1, isExt);
transmitStruct<PedalAndTps> (base + CAN_PEDAL_TPS_OFFSET, isExt);
transmitStruct<Sensors1> (base + CAN_SENSOR_1_OFFSET, isExt);
transmitStruct<Sensors2> (base + 4, isExt);
transmitStruct<Fueling> (base + 5, isExt);
transmitStruct<Fueling2> (base + 6, isExt);
transmitStruct<Fueling3> (base + 7, isExt);
transmitStruct<Cams> (base + 8, isExt);
transmitStruct<Odometry> (base + 9, isExt);
auto canChannel = engineConfiguration->canBroadcastUseChannelTwo;

transmitStruct<Status> (base + 0, isExt, canChannel);
transmitStruct<Speeds> (base + 1, isExt, canChannel);
transmitStruct<PedalAndTps> (base + CAN_PEDAL_TPS_OFFSET, isExt, canChannel);
transmitStruct<Sensors1> (base + CAN_SENSOR_1_OFFSET, isExt, canChannel);
transmitStruct<Sensors2> (base + 4, isExt, canChannel);
transmitStruct<Fueling> (base + 5, isExt, canChannel);
transmitStruct<Fueling2> (base + 6, isExt, canChannel);
transmitStruct<Fueling3> (base + 7, isExt, canChannel);
transmitStruct<Cams> (base + 8, isExt, canChannel);
transmitStruct<Odometry> (base + 9, isExt, canChannel);
}

#endif // EFI_CAN_SUPPORT
6 changes: 3 additions & 3 deletions firmware/hw_layer/drivers/can/can_msg_tx.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class CanTxTyped final : public CanTxMessage
#endif // EFI_CAN_SUPPORT

public:
explicit CanTxTyped(uint32_t id, bool isExtended) : CanTxMessage(id, sizeof(TData), isExtended) { }
explicit CanTxTyped(uint32_t id, bool isExtended, bool canChannel) : CanTxMessage(id, sizeof(TData), canChannel, isExtended) { }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bool to size_t conversion heh?


#if EFI_CAN_SUPPORT
/**
Expand All @@ -112,9 +112,9 @@ class CanTxTyped final : public CanTxMessage
};

template <typename TData>
void transmitStruct(uint32_t id, bool isExtended)
void transmitStruct(uint32_t id, bool isExtended, bool canChannel)
{
CanTxTyped<TData> frame(id, isExtended);
CanTxTyped<TData> frame(id, isExtended, canChannel);
// Destruction of an instance of CanTxMessage will transmit the message over the wire.
// see CanTxMessage::~CanTxMessage()
populateFrame(frame.get());
Expand Down
Loading