Skip to content

Commit

Permalink
print, debugging messages updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Dylan Donahue committed Jan 9, 2024
1 parent 8689e43 commit 6a953d0
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 90 deletions.
3 changes: 3 additions & 0 deletions Core/Inc/stateMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
#include "analyzer.h"
#include "timer.h"

/* global that can be read for debugging in main */
extern BMSState_t current_state;

#define NUM_FAULTS 8

/**
Expand Down
177 changes: 87 additions & 90 deletions Core/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "analyzer.h"
#include "stateMachine.h"
#include "can_handler.h"
#include <stdio.h>

/* USER CODE END Includes */

Expand All @@ -33,11 +34,11 @@
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */

#ifdef DEBUG_EVERYTHING
#define DEBUG_CHARGING
//#ifdef DEBUG_EVERYTHING
//#define DEBUG_CHARGING
#define DEBUG_STATS
// etc etc
#endif
//#endif
/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
Expand Down Expand Up @@ -80,98 +81,94 @@ static void MX_I2C1_Init(void);

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */

/* the following reroutes printf to uart */
#ifdef __GNUC__
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif

PUTCHAR_PROTOTYPE
{
HAL_UART_Transmit(&huart4, (uint8_t *)&ch, 1, HAL_MAX_DELAY);
return ch;
}

int _write(int file, char* ptr, int len) {
int DataIdx;

for (DataIdx = 0; DataIdx < len; DataIdx++) {
__io_putchar( *ptr++ );
}
return len;
}

#ifdef DEBUG_STATS

const void print_bms_stats(acc_data_t *acc_data)
{
static Timer debug_stat_timer;
static nertimer_t debug_stat_timer;
static const uint16_t PRINT_STAT_WAIT = 500; //ms

if(!debug_stat_timer.isTimerExpired()) return;

Serial.print("Prev Fault: 0x");
Serial.println(stateMachine.previousFault, HEX);
Serial.print("Current: ");
Serial.println((float)(acc_data->pack_current) / 10.0);
Serial.print("Min, Max, Avg Temps: ");
Serial.print(acc_data->min_temp.val);
Serial.print(", ");
Serial.print(acc_data->max_temp.val);
Serial.print(", ");
Serial.println(acc_data->avg_temp);
Serial.print("Min, Max, Avg, Delta Voltages: ");
Serial.print(acc_data->min_voltage.val);
Serial.print(", ");
Serial.print(acc_data->max_voltage.val);
Serial.print(", ");
Serial.print(acc_data->avg_voltage);
Serial.print(", ");
Serial.println(acc_data->delt_voltage);

Serial.print("DCL: ");
Serial.println(acc_data->discharge_limit);

Serial.print("CCL: ");
Serial.println(acc_data->charge_limit);

Serial.print("SoC: ");
Serial.println(acc_data->soc);

Serial.print("Is Balancing?: ");
Serial.println(segment.isBalancing());

Serial.print("State: ");
if (stateMachine.current_state == 0) Serial.println("BOOT");
else if (stateMachine.current_state == 1) Serial.println("READY");
else if (stateMachine.current_state == 2) Serial.println("CHARGING");
else if (stateMachine.current_state == 1) Serial.println("FAULTED");

Serial.println("Raw Cell Voltage:");
for(uint8_t c = 0; c < NUM_CHIPS; c++)
{
for(uint8_t cell = 0; cell < NUM_CELLS_PER_CHIP; cell++)
{
Serial.print(acc_data->chip_data[c].voltage_reading[cell]);
Serial.print("\t");
}
Serial.println();
}

Serial.println("Open Cell Voltage:");
for(uint8_t c = 0; c < NUM_CHIPS; c++)
{
for(uint8_t cell = 0; cell < NUM_CELLS_PER_CHIP; cell++)
{
Serial.print(acc_data->chip_data[c].open_cell_voltage[cell]);
Serial.print("\t");
}
Serial.println();
}

Serial.println("Cell Temps:");
for(uint8_t c = 0; c < NUM_CHIPS; c++)
{
for(uint8_t cell = 17; cell < 28; cell++)
{
Serial.print(acc_data->chip_data[c].thermistor_reading[cell]);
Serial.print("\t");
}
Serial.println();
}

Serial.println("Avg Cell Temps:");
for(uint8_t c = 0; c < NUM_CHIPS; c++)
{
for(uint8_t cell = 17; cell < 28; cell++)
{
Serial.print(acc_data->chip_data[c].thermistor_value[cell]);
Serial.print("\t");
}
Serial.println();
}


debug_stat_timer.startTimer(PRINT_STAT_WAIT);
if(!is_timer_expired(&debug_stat_timer)) return;

//TODO get this from eeprom once implemented
// question - should we read from eeprom here, or do that on loop and store locally?
//printf("Prev Fault: %#x", previousFault);
printf("Current: %f\n", (float)(acc_data->pack_current) / 10.0);
printf("Min, Max, Avg Temps: %ld, %ld, %d\n", acc_data->min_temp.val, acc_data->max_temp.val, acc_data->avg_temp);
printf("Min, Max, Avg, Delta Voltages: %ld, %ld, %d, %d\n", acc_data->min_voltage.val, acc_data->max_voltage.val, acc_data->avg_voltage, acc_data->delt_voltage);
printf("DCL: %d\n", acc_data->discharge_limit);
printf("CCL: %d\n", acc_data->charge_limit);
printf("SoC: %d\n", acc_data->soc);
printf("Is Balancing?: %d\n", segment_is_balancing());
printf("State: ");
if (current_state == 0) printf("BOOT\n");
else if (current_state == 1) printf("READY\n");
else if (current_state == 2) printf("CHARGING\n");
else if (current_state == 1) printf("FAULTED\n");
printf("Raw Cell Voltage:\n");
for(uint8_t c = 0; c < NUM_CHIPS; c++)
{
for(uint8_t cell = 0; cell < NUM_CELLS_PER_CHIP; cell++)
{
printf("%d\t", acc_data->chip_data[c].voltage_reading[cell]);
}
printf("\n");
}

printf("Open Cell Voltage:\n");
for(uint8_t c = 0; c < NUM_CHIPS; c++)
{
for(uint8_t cell = 0; cell < NUM_CELLS_PER_CHIP; cell++)
{
printf("%d\t", acc_data->chip_data[c].open_cell_voltage[cell]);
}
printf("\n");
}

printf("Cell Temps:\n");
for(uint8_t c = 0; c < NUM_CHIPS; c++)
{
for(uint8_t cell = 17; cell < 28; cell++)
{
printf("%d\t", acc_data->chip_data[c].thermistor_reading[cell]);
}
printf("\n");
}

printf("Avg Cell Temps:\n");
for(uint8_t c = 0; c < NUM_CHIPS; c++)
{
for(uint8_t cell = 17; cell < 28; cell++)
{
printf("%d\t", acc_data->chip_data[c].thermistor_value[cell]);
}
printf("\n");
}

start_timer(&debug_stat_timer, PRINT_STAT_WAIT);
}


Expand Down Expand Up @@ -249,7 +246,7 @@ int main(void)


#ifdef DEBUG_STATS
print_bms_stats(analyzer.bmsdata);
print_bms_stats(acc_data);
#endif
//delay(10); // not sure if we need this in, it was in before
}
Expand Down

0 comments on commit 6a953d0

Please sign in to comment.