Skip to content

Commit

Permalink
Add Bugfix / Diagnose / Version
Browse files Browse the repository at this point in the history
Bugfix: reset Flag when message received.
Diagnose: Function to read debug information.
Version: Function to read lib version.
  • Loading branch information
designer2k2 committed Jul 7, 2021
1 parent b3d0e48 commit 679219f
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 5 deletions.
19 changes: 18 additions & 1 deletion examples/EMUcanAdvancedTest/EMUcanAdvancedTest.ino
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ void setup() {
//Call this in the setup to init the lib:
emucan.begin(CAN_500KBPS, MCP_8MHZ);

Serial.print("EMUCAN_LIB_VERSION: ");
Serial.println(EMUCAN_LIB_VERSION);

//Setup the Callback to receive every CAN Message:
ReturnAllFramesFunction LetMeHaveIt = specialframefunction;
emucan.ReturnAllFrames(LetMeHaveIt);
Expand Down Expand Up @@ -52,7 +55,21 @@ void loop() {
}
//Stop sending all frames after 1 second, this spams the serial
emucan.ReturnAllFramesStop();

//Check RX/TX CAN error counts:
Serial.print("RX error count: ");
Serial.println(emucan.CanErrorCounter(false));
Serial.print("TX error count: ");
Serial.println(emucan.CanErrorCounter(true));

//retreive the mcp2515 object for direct access
MCP2515 mcp = *emucan.getMcp2515();
//call the getErrorFlags function from the mcp2515 lib:
uint8_t eflg = mcp.getErrorFlags();
Serial.print("eflg register:");
Serial.println(eflg);
}

}

// self defined function to handle all frames:
Expand All @@ -71,4 +88,4 @@ void specialframefunction(const struct can_frame *frame) {

//Toggle the onboard LED for show:
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
}
}
2 changes: 1 addition & 1 deletion keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ emu_data LITERAL1
EMUcan_FRESH LITERAL1
EMUcan_RECEIVED_WITHIN_LAST_SECOND LITERAL1
EMUcan_RECEIVED_NOTHING_WITHIN_LAST_SECOND LITERAL1
ReturnAllFramesFunction LITERAL1
ReturnAllFramesFunction LITERAL1
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"type": "git",
"url": "https://github.com/designer2k2/EMUcan"
},
"version": "1.0.2",
"version": "1.0.3",
"license": "GPL-3.0-only",
"frameworks": "arduino",
"platforms": "*",
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=EMUcan
version=1.0.2
version=1.0.3
author=Stephan M. <designer2k2@gmail.com>
maintainer=Stephan M. <designer2k2@gmail.com>
sentence=ECUMaster EMU CAN Stream Reader Arduino Library
Expand Down
16 changes: 16 additions & 0 deletions src/EMUcan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ void EMUcan::begin(const CAN_SPEED canSpeed, CAN_CLOCK canClock) {

bool EMUcan::checkEMUcan() {
if (mcp2515->readMessage(&canMsg) == MCP2515::ERROR_OK) {
//Clear RX1OVR Flag:
mcp2515->clearRXnOVR();
//Check if Message is within Range of 0-7 from base:
if ( canMsg.can_id >= _EMUbase && canMsg.can_id <= _EMUbase + 7) {
//So messages here should be decoded!
Expand Down Expand Up @@ -192,3 +194,17 @@ void EMUcan::ReturnAllFrames (ReturnAllFramesFunction response) {
void EMUcan::ReturnAllFramesStop() {
_returnexists = false;
}

bool EMUcan::CanCheckError() {
return mcp2515->checkError();
}

uint8_t EMUcan::CanErrorCounter(bool RXorTX)
{
if (RXorTX == false) {
return mcp2515->errorCountRX();
}
else {
return mcp2515->errorCountTX();
}
}
6 changes: 5 additions & 1 deletion src/EMUcan.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

#include <mcp2515.h>

#define EMUCAN_LIB_VERSION (F("1.0.3"))

// Available data
struct emu_data_t {
uint16_t RPM; //RPM
Expand Down Expand Up @@ -94,7 +96,9 @@ class EMUcan {
void begin(const CAN_SPEED canSpeed, const CAN_CLOCK canClock);
bool checkEMUcan();
bool sendFrame(const struct can_frame *);

bool CanCheckError();
uint8_t CanErrorCounter(bool RXorTX);

// Data
struct emu_data_t emu_data;

Expand Down

0 comments on commit 679219f

Please sign in to comment.