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

To fix #20 make all CAN handlers fire every time #21

Merged
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
6 changes: 3 additions & 3 deletions include/canhardware.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@
class CanCallback
{
public:
virtual bool HandleRx(uint32_t canId, uint32_t data[2], uint8_t dlc) = 0;
virtual void HandleRx(uint32_t canId, uint32_t data[2], uint8_t dlc) = 0;
virtual void HandleClear() = 0;
};

class FunctionPointerCallback: public CanCallback
{
public:
FunctionPointerCallback(bool (*r)(uint32_t, uint32_t*, uint8_t), void (*c)()) : recv(r), clear(c) { };
bool HandleRx(uint32_t canId, uint32_t data[2], uint8_t dlc) { return recv(canId, data, dlc); }
void HandleClear() { clear(); }
void HandleRx(uint32_t canId, uint32_t data[2], uint8_t dlc) override { recv(canId, data, dlc); }
void HandleClear() override { clear(); }

private:
bool (*recv)(uint32_t, uint32_t*, uint8_t);
Expand Down
4 changes: 2 additions & 2 deletions include/canmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ class CanMap: CanCallback

CanMap(CanHardware* hw, bool loadFromFlash = true);
CanHardware* GetHardware() { return canHardware; }
void HandleClear();
bool HandleRx(uint32_t canId, uint32_t data[2], uint8_t dlc);
void HandleClear() override;
void HandleRx(uint32_t canId, uint32_t data[2], uint8_t dlc) override;
void Clear();
void SendAll();
int AddSend(Param::PARAM_NUM param, uint32_t canId, uint8_t offsetBits, int8_t length, float gain);
Expand Down
4 changes: 2 additions & 2 deletions include/canobd2.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class CanObd2: CanCallback
public:
/** Default constructor */
CanObd2(CanHardware* hw);
void HandleClear();
bool HandleRx(uint32_t canId, uint32_t data[2], uint8_t dlc);
void HandleClear() override;
void HandleRx(uint32_t canId, uint32_t data[2], uint8_t dlc) override;
void SetNodeId(uint8_t id);

private:
Expand Down
2 changes: 1 addition & 1 deletion include/cansdo.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class CanSdo: CanCallback, public IPutChar
/** Default constructor */
CanSdo(CanHardware* hw, CanMap* cm = 0);
void HandleClear();
bool HandleRx(uint32_t canId, uint32_t data[2], uint8_t dlc);
void HandleRx(uint32_t canId, uint32_t data[2], uint8_t dlc) override;
void SDOWrite(uint8_t nodeId, uint16_t index, uint8_t subIndex, uint32_t data);
void SDORead(uint8_t nodeId, uint16_t index, uint8_t subIndex);
bool SDOReadReply(uint32_t& data);
Expand Down
7 changes: 3 additions & 4 deletions src/canhardware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
class NullCallback: public CanCallback
{
public:
bool HandleRx(uint32_t, uint32_t*, uint8_t) { return false; }
void HandleClear() { }
void HandleRx(uint32_t, uint32_t*, uint8_t) override {}
void HandleClear() override { }
};


Expand Down Expand Up @@ -96,7 +96,6 @@ void CanHardware::HandleRx(uint32_t canId, uint32_t data[2], uint8_t dlc)
{
for (int i = 0; i < nextCallbackIndex; i++)
{
if (recvCallback[i]->HandleRx(canId, data, dlc))
break;
recvCallback[i]->HandleRx(canId, data, dlc);
}
}
7 changes: 2 additions & 5 deletions src/canmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ void CanMap::HandleClear()
}
}

bool CanMap::HandleRx(uint32_t canId, uint32_t data[2], uint8_t)
void CanMap::HandleRx(uint32_t canId, uint32_t data[2], uint8_t)
{
if (isSaving) return false; //Only handle mapped messages when not currently saving to flash
if (isSaving) return; //Only handle mapped messages when not currently saving to flash

CANIDMAP *recvMap = FindById(canRecvMap, canId);

Expand Down Expand Up @@ -162,10 +162,7 @@ bool CanMap::HandleRx(uint32_t canId, uint32_t data[2], uint8_t)
else
Param::SetFloat((Param::PARAM_NUM)curPos->mapParam, val);
}
return true;
}

return false;
}

/** \brief Clear all defined messages
Expand Down
4 changes: 1 addition & 3 deletions src/canobd2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,12 @@ void CanObd2::HandleClear()
canHardware->RegisterUserMessage(OBD2_PID_REQUEST + nodeId); // ECU specific address
}

bool CanObd2::HandleRx(uint32_t canId, uint32_t data[2], uint8_t)
void CanObd2::HandleRx(uint32_t canId, uint32_t data[2], uint8_t)
{
if ((canId == OBD2_PID_REQUEST) || (canId == (OBD2_PID_REQUEST + nodeId))) //OBD2 request
{
ProcessOBD2(data);
return true;
}
return false;
}

void CanObd2::SetNodeId(uint8_t id)
Expand Down
5 changes: 1 addition & 4 deletions src/cansdo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,17 @@ void CanSdo::HandleClear()
canHardware->RegisterUserMessage(SDO_REP_ID_BASE + remoteNodeId);
}

bool CanSdo::HandleRx(uint32_t canId, uint32_t data[2], uint8_t)
void CanSdo::HandleRx(uint32_t canId, uint32_t data[2], uint8_t)
{
if (canId == (SDO_REQ_ID_BASE + nodeId)) //SDO request
{
ProcessSDO(data);
return true;
}
else if (canId == (SDO_REP_ID_BASE + remoteNodeId))
{
sdoReplyValid = (data[0] & 0xFF) != SDO_ABORT;
sdoReplyData = data[1];
return true;
}
return false;
}

void CanSdo::SDOWrite(uint8_t nodeId, uint16_t index, uint8_t subIndex, uint32_t data)
Expand Down