Skip to content
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
2 changes: 2 additions & 0 deletions include/errormessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class ErrorMessage
static void PrintAllErrors();
static void PrintNewErrors();
static ERROR_MESSAGE_NUM GetLastError();
static ERROR_MESSAGE_NUM GetErrorNum(uint8_t index);
static uint32_t GetErrorTime(uint8_t index);
protected:
private:
static void PrintError(uint32_t time, ERROR_MESSAGE_NUM err);
Expand Down
30 changes: 30 additions & 0 deletions src/cansdo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
#include "cansdo.h"
#include "my_math.h"
#include "errormessage.h"

#define SDO_REQ_ID_BASE 0x600U
#define SDO_REP_ID_BASE 0x580U
Expand All @@ -28,6 +29,9 @@
#define SDO_INDEX_MAP_RX 0x3001
#define SDO_INDEX_MAP_RD 0x3100
#define SDO_INDEX_STRINGS 0x5001
#define SDO_INDEX_ERROR_NUM 0x5002
#define SDO_INDEX_ERROR_TIME 0x5003


#define PRINT_BUF_ENQUEUE(c) printBuffer[(printByteIn++) & (sizeof(printBuffer) - 1)] = c
#define PRINT_BUF_DEQUEUE() printBuffer[(printByteOut++) & (sizeof(printBuffer) - 1)]
Expand Down Expand Up @@ -196,6 +200,32 @@ void CanSdo::ProcessSDO(uint32_t data[2])
{
ReadOrDeleteCanMap(sdo);
}
else if (sdo->index == SDO_INDEX_ERROR_NUM)
{
if (sdo->cmd == SDO_READ)
{
sdo->data = ErrorMessage::GetErrorNum(sdo->subIndex);
sdo->cmd = SDO_READ_REPLY;
}
else
{
sdo->cmd = SDO_ABORT;
sdo->data = SDO_ERR_INVIDX;
}
}
else if (sdo->index == SDO_INDEX_ERROR_TIME)
{
if (sdo->cmd == SDO_READ)
{
sdo->data = ErrorMessage::GetErrorTime(sdo->subIndex);
sdo->cmd = SDO_READ_REPLY;
}
else
{
sdo->cmd = SDO_ABORT;
sdo->data = SDO_ERR_INVIDX;
}
}
else
{
if (!ProcessSpecialSDOObjects(sdo))
Expand Down
21 changes: 21 additions & 0 deletions src/errormessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,27 @@ ERROR_MESSAGE_NUM ErrorMessage::GetLastError()
return lastError;
}

ERROR_MESSAGE_NUM ErrorMessage::GetErrorNum(uint8_t index)
{
if (index < ERROR_BUF_SIZE)
{
if (errorBuffer[index].time > 0)
return errorBuffer[index].msg;
}

return ERROR_NONE;
}

uint32_t ErrorMessage::GetErrorTime(uint8_t index)
{
if (index < ERROR_BUF_SIZE)
{
return errorBuffer[index].time;
}

return 0;
}

/** Print all errors currently in error memory */
void ErrorMessage::PrintAllErrors()
{
Expand Down