Skip to content
This repository has been archived by the owner on Jun 18, 2024. It is now read-only.

Commit

Permalink
fixing stupid errors from prev
Browse files Browse the repository at this point in the history
  • Loading branch information
dyldonahue committed Jul 15, 2023
1 parent 662d526 commit 06eaca9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 33 deletions.
16 changes: 9 additions & 7 deletions shepherd_bms/include/eepromdirectory.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,7 @@ int eepromGetIndex(char *key);
*/
char *eepromGetKey(int index);

/**
* @brief logs fault code in eeprom
*
*
* @param fault_code
*/
void logFault(uint32_t fault_code);


/**
* @brief fills passed data pointer with data from eeprom
Expand All @@ -75,6 +69,14 @@ void eepromReadData(uint8_t index, void *data);
void eepromWriteData(char *key, void *data);

void eepromWriteData(uint8_t index, void *data);

/**
* @brief logs fault code in eeprom
*
*
* @param fault_code
*/
void logFault(uint32_t fault_code);
/**
* @brief reads all stored faults from eeprom
*
Expand Down
56 changes: 30 additions & 26 deletions shepherd_bms/src/eepromdirectory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,28 +51,7 @@ char* eepromGetKey(int index)
return NULL;
}

void logFault(uint32_t fault_code)
{
/* the most recent index is stored in the first byte of the fault partition */
uint8_t index = EEPROM.read(eepromGetIndex(const_cast<char*>("FAULTS"))); // TODO will need update with new eeprom driver

uint8_t startIndex = eeprom_data[eepromGetIndex(const_cast<char*>("FAULTS"))].offset;
uint8_t size = eeprom_data[eepromGetIndex(const_cast<char*>("FAULTS"))].size;

/* if the index is at the end of the partition, wrap around (currently store 5 faults, so max = 5 + offset) */
if (index == size + startIndex - 3)
{
/* first byte of partition is the index of the most recent fault, faults begin at second byte */
index = startIndex + 1;
}
else
{
index++;
}

/* write the fault code to the new index */
EEPROM.put(index, fault_code); // TODO will need update with new eeprom driver
}

void eepromReadData(char *key, void *data)
{
Expand Down Expand Up @@ -101,10 +80,35 @@ void eepromWriteData(uint8_t index, void *data)
EEPROM.put(index, data); // TODO will need update with new eeprom driver
}

void logFault(uint32_t *fault_code)
{
/* the most recent index is stored in the first byte of the fault partition */
uint8_t* index;
eepromReadData("FAULTS", index);

uint8_t startIndex = eeprom_data[eepromGetIndex(const_cast<char*>("FAULTS"))].offset;
uint8_t size = eeprom_data[eepromGetIndex(const_cast<char*>("FAULTS"))].size;

/* if the index is at the end of the partition, wrap around (currently store 5 faults, so max = 5 + offset) */
if (*index == size + startIndex - 3)
{
/* first byte of partition is the index of the most recent fault, faults begin at second byte */
*index = startIndex + 1;
}
else
{
*index += 4;
}

/* write the fault code to the new index */
eepromWriteData(*index, fault_code);
}

void getFaults()
{
/* the most recent index is stored in the first byte of the fault partition */
uint8_t index = EEPROM.read(eepromGetIndex(const_cast<char*>("FAULTS"))); // TODO will need update with new eeprom driver
uint8_t* index;
eepromReadData("FAULTS", index);

uint8_t startIndex = eeprom_data[eepromGetIndex(const_cast<char*>("FAULTS"))].offset;
uint8_t size = eeprom_data[eepromGetIndex(const_cast<char*>("FAULTS"))].size;
Expand All @@ -114,20 +118,20 @@ void getFaults()
int currIter = 0;
while (currIter < NUM_EEPROM_FAULTS)
{
eepromReadData(index, &eeprom_faults[currIter]);
eepromReadData(*index, &eeprom_faults[currIter]);
currIter++;

/* if the index is at the end of the partition, wrap around (5 faults * 4 bytes per fault + offset - 3 for start of fault) */
if (index == size + startIndex - 3)
if (*index == size + startIndex - 3)
{
/* first byte of partition is the index of the most recent fault, faults begin at second byte */
index = startIndex + 1;
*index = startIndex + 1;
}

else
{
/* 4 bytes per fault */
index += 4;
*index += 4;
}
}

Expand Down

0 comments on commit 06eaca9

Please sign in to comment.