From a028a30dc611fe51a9a992c94510431449c1d5fd Mon Sep 17 00:00:00 2001 From: courtenayhuffman Date: Sun, 12 Sep 2021 17:34:17 -0700 Subject: [PATCH 01/10] updated DAC voltages for driver change --- .../phantom_drivers/bms/source/bms_slaves.c | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/TestBoardFirmware/phantom_drivers/bms/source/bms_slaves.c b/TestBoardFirmware/phantom_drivers/bms/source/bms_slaves.c index 91c2890e..eafceaad 100644 --- a/TestBoardFirmware/phantom_drivers/bms/source/bms_slaves.c +++ b/TestBoardFirmware/phantom_drivers/bms/source/bms_slaves.c @@ -18,25 +18,24 @@ // #include "os_timer.h" // BMS Slave specific definitions, not accessed outside bms_slaves.c -#define VOLTAGE_STEP 0.04 -#define DEFAULT_VOLTAGE 84 -#define DEFAULT_TEMPERATURE 25 +#define VOLTAGE_STEP 0.04 //not used +#define DEFAULT_VOLTAGE 840 +#define DEFAULT_TEMPERATURE 250 //not used #define NUMBER_OF_TEMPERATURE_READINGS 16 #define TRANSFER_GROUP 2 -// THESE VALUES NEED TO BE CHECKED - all must be an INT -#define TEMP_MAX_VOLT 113 // 1.131 == 55 degrees -#define TEMP_MIN_VOLT 268 // 2.682 = 0 degrees -#define TEMP_HIGH_VOLT 67 //66.83 // 0.6683 = 76 degrees -#define TEMP_LOW_VOLT 270 // 2.70 = 0 degrees -#define VOLT_MIN 76 // 0.7608 * 100 -#define VOLT_MAX 100 // 0.9985 * 100 +#define TEMP_MAX_VOLT 1131 // 1.131 == 55 degrees +#define TEMP_MIN_VOLT 2682 // 2.682 = 0 degrees +#define TEMP_HIGH_VOLT 668 //66.83 // 0.6683 = 76 degrees // not used +#define TEMP_LOW_VOLT 2700 // 2.70 = 0 degrees // not used +#define VOLT_MIN 761 // 0.7608 * 100 +#define VOLT_MAX 999 // 0.9985 * 100 // CHANGE THIS VALUE TO -#define VOLT_TEST 0 //102 = 84.5 +#define VOLT_TEST 0 //102 = 84.5 // wtf is this -//const uint8_t[] BMS_FAULT_LUT = { } +//const uint8_t[] BMS_FAULT_LUT = { } //wtf is this typedef struct { From 89182388f602cd7b73abb5662a51ea2c27325c3c Mon Sep 17 00:00:00 2001 From: courtenayhuffman Date: Sun, 12 Sep 2021 19:04:34 -0700 Subject: [PATCH 02/10] clean up old code --- .../phantom_drivers/bms/source/bms_slaves.c | 60 ++++--------------- 1 file changed, 11 insertions(+), 49 deletions(-) diff --git a/TestBoardFirmware/phantom_drivers/bms/source/bms_slaves.c b/TestBoardFirmware/phantom_drivers/bms/source/bms_slaves.c index eafceaad..77fdebaf 100644 --- a/TestBoardFirmware/phantom_drivers/bms/source/bms_slaves.c +++ b/TestBoardFirmware/phantom_drivers/bms/source/bms_slaves.c @@ -3,6 +3,7 @@ * * Created on: Oct 25, 2020 * Author: Mahmoud Ahmed + * Further Development and Refactoring: Courtenay Huffman */ #include "bms_slaves.h" #include "stdlib.h" @@ -14,14 +15,10 @@ #include "gio.h" #include "het.h" -// #include "FreeRTOS.h" -// #include "os_timer.h" - -// BMS Slave specific definitions, not accessed outside bms_slaves.c #define VOLTAGE_STEP 0.04 //not used #define DEFAULT_VOLTAGE 840 #define DEFAULT_TEMPERATURE 250 //not used -#define NUMBER_OF_TEMPERATURE_READINGS 16 +#define NUMBER_OF_TEMPERATURE_READINGS 16 //enough for 2 slaves #define TRANSFER_GROUP 2 @@ -31,17 +28,12 @@ #define TEMP_LOW_VOLT 2700 // 2.70 = 0 degrees // not used #define VOLT_MIN 761 // 0.7608 * 100 #define VOLT_MAX 999 // 0.9985 * 100 - -// CHANGE THIS VALUE TO #define VOLT_TEST 0 //102 = 84.5 // wtf is this -//const uint8_t[] BMS_FAULT_LUT = { } //wtf is this - - typedef struct { float bmsSlaveVoltage; float bmsSlaveTemperatures[NUMBER_OF_TEMPERATURE_READINGS]; -} BMSSlave_t; // BMSSlave_t is like double or int +} BMSSlave_t; // Static Global Variables static BMSSlave_t *bmsStruct; @@ -124,14 +116,9 @@ void bms_slaves_init(){ // Send a constant 3.8V static void normal_bms_operation(){ - - // set_bms_voltage and temp at normal levels - UARTprintf("Normal BMS Operation\n\r"); - MCP48FV_Set_Value_Single(VOLT_TEST, DAC_SIZE_BMS, 0, 2); uint8_t pinSelect = 0; - //setting temp on each of the 16 pins for( ; pinSelect <= 00001111; pinSelect++){ temperature_mux(pinSelect); MCP48FV_Set_Value_Single(bmsStruct->bmsSlaveTemperatures[pinSelect], DAC_SIZE_BMS, 1, TRANSFER_GROUP); @@ -139,83 +126,58 @@ static void normal_bms_operation(){ } static void under_voltage_test() { - - //send a voltage under the opperating region (3.2-4.2) - //send 2.7V for more than 3 seconds MCP48FV_Set_Value_Single(VOLT_MIN, DAC_SIZE_BMS, 0, TRANSFER_GROUP); uint8_t pinSelect = 0; - for( ; pinSelect <= 00001111; pinSelect++){// for loop - iterate over each pin + for( ; pinSelect <= 00001111; pinSelect++){ temperature_mux(pinSelect); - // set the DAC MCP48FV_Set_Value_Single(bmsStruct->bmsSlaveTemperatures[pinSelect], DAC_SIZE_BMS, 1, TRANSFER_GROUP); } } static void over_voltage_test(){ - - //send a voltage over the opperating region (3.2-4.2) - //send 4.7V for more than 3 seconds MCP48FV_Set_Value_Single(VOLT_MAX, DAC_SIZE_BMS, 0, TRANSFER_GROUP); uint8_t pinSelect = 0; - for( ; pinSelect <= 00001111; pinSelect++){// for loop - iterate over each pin + for( ; pinSelect <= 00001111; pinSelect++){ temperature_mux(pinSelect); - // set the DAC MCP48FV_Set_Value_Single(bmsStruct->bmsSlaveTemperatures[pinSelect], DAC_SIZE_BMS, 1, TRANSFER_GROUP); } } static void under_temperature_test(){ - - //send a temperature voltage over the opperating region (55 degrees C) - //send 60 C for more than 3 seconds - MCP48FV_Set_Value_Single((VOLT_MAX + VOLT_MIN)*0.5, DAC_SIZE_BMS, 0, TRANSFER_GROUP); uint8_t pinSelect = 0; - for( ; pinSelect <= 0b00001111; pinSelect++){// for loop - iterate over each pin + for( ; pinSelect <= 0b00001111; pinSelect++){ temperature_mux(pinSelect); - // set the DAC MCP48FV_Set_Value_Single(bmsTempLow->bmsSlaveTemperatures[pinSelect], DAC_SIZE_BMS, 1, TRANSFER_GROUP); } } static void over_temperature_test(){ - - //send a temperature voltage over the opperating region (55 degrees C) - //send 60 C for more than 3 seconds - MCP48FV_Set_Value_Single((VOLT_MAX + VOLT_MIN)*0.5, DAC_SIZE_BMS, 0, TRANSFER_GROUP); uint8_t pinSelect = 0; - for( ; pinSelect <= 0b00001111; pinSelect++){// for loop - iterate over each pin + for( ; pinSelect <= 0b00001111; pinSelect++){ temperature_mux(pinSelect); - // set the DAC MCP48FV_Set_Value_Single(bmsTempHigh->bmsSlaveTemperatures[pinSelect], DAC_SIZE_BMS, 1, TRANSFER_GROUP); } } static void communication_loss_test(){ - - // send nothing - // "what is timing out of messages" - MCP48FV_Set_Value_Single(0, DAC_SIZE_BMS, 0, TRANSFER_GROUP); uint8_t pinSelect = 0; - for( ; pinSelect <= 00001111; pinSelect++){// for loop - iterate over each pin - temperature_mux(pinSelect); - // set the DAC - MCP48FV_Set_Value_Single(0, DAC_SIZE_BMS, 1, TRANSFER_GROUP); - } + for( ; pinSelect <= 00001111; pinSelect++){ + temperature_mux(pinSelect); + MCP48FV_Set_Value_Single(0, DAC_SIZE_BMS, 1, TRANSFER_GROUP); + } return; } // *****temperature mux function (loop)***** static void temperature_mux(uint8_t pinSelect){ - - // set the different mux pins if (0b00000001 & pinSelect){ gioSetBit(THERMISTOR_MUX_HET_PORT, THERMISTOR_MUX_PIN_0, 1); } else { From 22b2938a42bcd1ff7e94f5d191cdffe5f849ecfd Mon Sep 17 00:00:00 2001 From: courtenayhuffman Date: Sun, 12 Sep 2021 19:44:37 -0700 Subject: [PATCH 03/10] clean up more code --- .../phantom_drivers/bms/source/bms_slaves.c | 34 ++++++------------- 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/TestBoardFirmware/phantom_drivers/bms/source/bms_slaves.c b/TestBoardFirmware/phantom_drivers/bms/source/bms_slaves.c index 77fdebaf..95bbdeb9 100644 --- a/TestBoardFirmware/phantom_drivers/bms/source/bms_slaves.c +++ b/TestBoardFirmware/phantom_drivers/bms/source/bms_slaves.c @@ -17,18 +17,17 @@ #define VOLTAGE_STEP 0.04 //not used #define DEFAULT_VOLTAGE 840 -#define DEFAULT_TEMPERATURE 250 //not used -#define NUMBER_OF_TEMPERATURE_READINGS 16 //enough for 2 slaves +#define NUMBER_OF_TEMPERATURE_READINGS 16 // represents 2 slaves #define TRANSFER_GROUP 2 -#define TEMP_MAX_VOLT 1131 // 1.131 == 55 degrees -#define TEMP_MIN_VOLT 2682 // 2.682 = 0 degrees -#define TEMP_HIGH_VOLT 668 //66.83 // 0.6683 = 76 degrees // not used -#define TEMP_LOW_VOLT 2700 // 2.70 = 0 degrees // not used -#define VOLT_MIN 761 // 0.7608 * 100 -#define VOLT_MAX 999 // 0.9985 * 100 -#define VOLT_TEST 0 //102 = 84.5 // wtf is this +#define TEMP_MAX_VOLT 1131 // 55 degrees +#define TEMP_MIN_VOLT 2682 // 0 degrees +#define TEMP_HIGH_VOLT 668 // 76 degrees // not used +#define TEMP_LOW_VOLT 2700 // 0 degrees // not used +#define VOLT_MIN 761 +#define VOLT_MAX 999 +#define VOLT_TEST 0 // 84.5 - wtf is this typedef struct { float bmsSlaveVoltage; @@ -96,24 +95,11 @@ void bms_slaves_init(){ for(i = 0; i < NUMBER_OF_TEMPERATURE_READINGS; i++) { bmsStruct->bmsSlaveTemperatures[i] = (TEMP_MAX_VOLT + TEMP_MIN_VOLT)*0.5; } - - bmsTempHigh->bmsSlaveVoltage = DEFAULT_VOLTAGE; - uint8_t j; - for(j=0; j < NUMBER_OF_TEMPERATURE_READINGS; j++) { - bmsTempHigh->bmsSlaveTemperatures[j] = (TEMP_MAX_VOLT + TEMP_MIN_VOLT)*0.5; - } - bmsTempHigh->bmsSlaveTemperatures[0] = TEMP_MAX_VOLT*1.5; - - bmsTempLow->bmsSlaveVoltage = DEFAULT_VOLTAGE; - uint8_t k; - for(k = 0; j < NUMBER_OF_TEMPERATURE_READINGS; j++) { - bmsTempLow->bmsSlaveTemperatures[j] =(TEMP_MAX_VOLT + TEMP_MIN_VOLT)*0.5; - } - bmsTempLow->bmsSlaveTemperatures[0] = 0; UARTprintf("BMS Initialization Complete"); - } + + // Send a constant 3.8V static void normal_bms_operation(){ MCP48FV_Set_Value_Single(VOLT_TEST, DAC_SIZE_BMS, 0, 2); From dd2e8b998734b1941eb5afe41dbd32fd310ff8d9 Mon Sep 17 00:00:00 2001 From: courtenayhuffman Date: Tue, 14 Sep 2021 01:52:54 -0700 Subject: [PATCH 04/10] major refactor --- .../phantom_drivers/bms/source/bms_slaves.c | 101 +++++++++--------- 1 file changed, 50 insertions(+), 51 deletions(-) diff --git a/TestBoardFirmware/phantom_drivers/bms/source/bms_slaves.c b/TestBoardFirmware/phantom_drivers/bms/source/bms_slaves.c index 95bbdeb9..b1dd5fcb 100644 --- a/TestBoardFirmware/phantom_drivers/bms/source/bms_slaves.c +++ b/TestBoardFirmware/phantom_drivers/bms/source/bms_slaves.c @@ -15,19 +15,17 @@ #include "gio.h" #include "het.h" -#define VOLTAGE_STEP 0.04 //not used -#define DEFAULT_VOLTAGE 840 +#define VOLTAGE_STEP 0.04 +#define DEFAULT_VOLTAGE 840 //this should probably be the max? probably 72V +#define DEFAULT_TEMP 2064 // 23 degrees #define NUMBER_OF_TEMPERATURE_READINGS 16 // represents 2 slaves #define TRANSFER_GROUP 2 -#define TEMP_MAX_VOLT 1131 // 55 degrees -#define TEMP_MIN_VOLT 2682 // 0 degrees -#define TEMP_HIGH_VOLT 668 // 76 degrees // not used -#define TEMP_LOW_VOLT 2700 // 0 degrees // not used -#define VOLT_MIN 761 -#define VOLT_MAX 999 -#define VOLT_TEST 0 // 84.5 - wtf is this +#define TEMP_MAX_VOLT 1106 // 55 degrees +#define TEMP_MIN_VOLT 2705 // 0 degrees +#define VOLT_MIN 761 // this should probably be 48V +#define VOLT_MAX 999 // probably 84V typedef struct { float bmsSlaveVoltage; @@ -35,9 +33,9 @@ typedef struct { } BMSSlave_t; // Static Global Variables -static BMSSlave_t *bmsStruct; -static BMSSlave_t *bmsTempHigh; -static BMSSlave_t *bmsTempLow; +static BMSSlave_t *bmsSlaveData; +static BMSSlave_t *bmsSlaveData_HIGH; +static BMSSlave_t *bmsSlaveData_LOW; // Static function definitions static void normal_bms_operation(); @@ -86,83 +84,84 @@ Result_t bms_slaves_process(uint8_t state) return SUCCESS; } -void bms_slaves_init(){ +void bms_slaves_init(){ gioSetBit(HV_ACTIVE_PORT, HV_ACTIVE_PIN, 1); - bmsStruct->bmsSlaveVoltage = DEFAULT_VOLTAGE; + bmsSlaveData->bmsSlaveVoltage = DEFAULT_VOLTAGE; uint8_t i; for(i = 0; i < NUMBER_OF_TEMPERATURE_READINGS; i++) { - bmsStruct->bmsSlaveTemperatures[i] = (TEMP_MAX_VOLT + TEMP_MIN_VOLT)*0.5; + bmsSlaveData->bmsSlaveTemperatures[i] = DEFAULT_TEMP; + } + + bmsSlaveData_HIGH->bmsSlaveVoltage = VOLT_MAX; + for(i = 0; i < NUMBER_OF_TEMPERATURE_READINGS; i++) { + bmsSlaveData_HIGH->bmsSlaveTemperatures[i] = TEMP_MAX_VOLT; } - UARTprintf("BMS Initialization Complete"); -} + bmsSlaveData_LOW->bmsSlaveVoltage = VOLT_MIN; + for(i = 0; i < NUMBER_OF_TEMPERATURE_READINGS; i++) { + bmsSlaveData_LOW->bmsSlaveTemperatures[i] = TEMP_MIN_VOLT; + } + //make these a normal bms values? + set_voltage(0); + set_temperature(0); + + UARTprintf("BMS Initialization Complete"); +} // Send a constant 3.8V static void normal_bms_operation(){ - MCP48FV_Set_Value_Single(VOLT_TEST, DAC_SIZE_BMS, 0, 2); + set_voltage(bmsSlaveData->bmsSlaveVoltage); + set_temperature(bmsSlaveData->bmsSlaveTemperatures); - uint8_t pinSelect = 0; - for( ; pinSelect <= 00001111; pinSelect++){ - temperature_mux(pinSelect); - MCP48FV_Set_Value_Single(bmsStruct->bmsSlaveTemperatures[pinSelect], DAC_SIZE_BMS, 1, TRANSFER_GROUP); - } } static void under_voltage_test() { - MCP48FV_Set_Value_Single(VOLT_MIN, DAC_SIZE_BMS, 0, TRANSFER_GROUP); + set_voltage(bmsSlaveData_LOW->bmsSlaveVoltage); + set_temperature(bmsSlaveData->bmsSlaveTemperatures); - uint8_t pinSelect = 0; - for( ; pinSelect <= 00001111; pinSelect++){ - temperature_mux(pinSelect); - MCP48FV_Set_Value_Single(bmsStruct->bmsSlaveTemperatures[pinSelect], DAC_SIZE_BMS, 1, TRANSFER_GROUP); - } } static void over_voltage_test(){ - MCP48FV_Set_Value_Single(VOLT_MAX, DAC_SIZE_BMS, 0, TRANSFER_GROUP); + set_voltage(bmsSlaveData_HIGH->bmsSlaveVoltage); + set_temperature(bmsSlaveData->bmsSlaveTemperatures); - uint8_t pinSelect = 0; - for( ; pinSelect <= 00001111; pinSelect++){ - temperature_mux(pinSelect); - MCP48FV_Set_Value_Single(bmsStruct->bmsSlaveTemperatures[pinSelect], DAC_SIZE_BMS, 1, TRANSFER_GROUP); - } } static void under_temperature_test(){ - MCP48FV_Set_Value_Single((VOLT_MAX + VOLT_MIN)*0.5, DAC_SIZE_BMS, 0, TRANSFER_GROUP); + set_voltage(bmsSlaveData->bmsSlaveVoltage); + set_temperature(bmsSlaveData_LOW->bmsSlaveTemperatures); - uint8_t pinSelect = 0; - for( ; pinSelect <= 0b00001111; pinSelect++){ - temperature_mux(pinSelect); - MCP48FV_Set_Value_Single(bmsTempLow->bmsSlaveTemperatures[pinSelect], DAC_SIZE_BMS, 1, TRANSFER_GROUP); - } } static void over_temperature_test(){ - MCP48FV_Set_Value_Single((VOLT_MAX + VOLT_MIN)*0.5, DAC_SIZE_BMS, 0, TRANSFER_GROUP); + set_voltage(bmsSlaveData->bmsSlaveVoltage); + set_temperature(bmsSlaveData_HIGH->bmsSlaveTemperatures); - uint8_t pinSelect = 0; - for( ; pinSelect <= 0b00001111; pinSelect++){ - temperature_mux(pinSelect); - MCP48FV_Set_Value_Single(bmsTempHigh->bmsSlaveTemperatures[pinSelect], DAC_SIZE_BMS, 1, TRANSFER_GROUP); - } } static void communication_loss_test(){ - MCP48FV_Set_Value_Single(0, DAC_SIZE_BMS, 0, TRANSFER_GROUP); + set_voltage(0); + set_temperature(0); + + return; +} +// internal BMS Slave functions +static void set_temperature(float temparray[]){ uint8_t pinSelect = 0; for( ; pinSelect <= 00001111; pinSelect++){ temperature_mux(pinSelect); - MCP48FV_Set_Value_Single(0, DAC_SIZE_BMS, 1, TRANSFER_GROUP); + MCP48FV_Set_Value_Single(temparray[pinSelect], DAC_SIZE_BMS, 1, TRANSFER_GROUP); } - return; } -// *****temperature mux function (loop)***** +static void set_voltage(float voltage){ + MCP48FV_Set_Value_Single(voltage, DAC_SIZE_BMS, 0, TRANSFER_GROUP); +} + static void temperature_mux(uint8_t pinSelect){ if (0b00000001 & pinSelect){ gioSetBit(THERMISTOR_MUX_HET_PORT, THERMISTOR_MUX_PIN_0, 1); From 316c5464fa315270d430cf39df23cc42ff55a629 Mon Sep 17 00:00:00 2001 From: courtenayhuffman Date: Sat, 18 Sep 2021 16:53:31 -0700 Subject: [PATCH 05/10] review values --- .../phantom_drivers/bms/include/bms_slaves.h | 2 -- .../phantom_drivers/bms/source/bms_slaves.c | 26 +++++-------------- 2 files changed, 7 insertions(+), 21 deletions(-) diff --git a/TestBoardFirmware/phantom_drivers/bms/include/bms_slaves.h b/TestBoardFirmware/phantom_drivers/bms/include/bms_slaves.h index 4ef2c056..34fbb938 100644 --- a/TestBoardFirmware/phantom_drivers/bms/include/bms_slaves.h +++ b/TestBoardFirmware/phantom_drivers/bms/include/bms_slaves.h @@ -21,8 +21,6 @@ enum UNDER_VOLTAGE_FAULT, OVER_TEMPERATURE_FAULT, UNDER_TEMPERATURE_FAULT, - WEIRD_SENSOR_READINGS_VOLTAGE, - WEIRD_SENSOR_READINGS_TEMPERATURE, COMMUNICATION_LOSS, }; diff --git a/TestBoardFirmware/phantom_drivers/bms/source/bms_slaves.c b/TestBoardFirmware/phantom_drivers/bms/source/bms_slaves.c index b1dd5fcb..9e4c2ba1 100644 --- a/TestBoardFirmware/phantom_drivers/bms/source/bms_slaves.c +++ b/TestBoardFirmware/phantom_drivers/bms/source/bms_slaves.c @@ -16,7 +16,7 @@ #include "het.h" #define VOLTAGE_STEP 0.04 -#define DEFAULT_VOLTAGE 840 //this should probably be the max? probably 72V +#define DEFAULT_VOLTAGE 840 #define DEFAULT_TEMP 2064 // 23 degrees #define NUMBER_OF_TEMPERATURE_READINGS 16 // represents 2 slaves @@ -24,8 +24,8 @@ #define TEMP_MAX_VOLT 1106 // 55 degrees #define TEMP_MIN_VOLT 2705 // 0 degrees -#define VOLT_MIN 761 // this should probably be 48V -#define VOLT_MAX 999 // probably 84V +#define VOLT_MIN 761 +#define VOLT_MAX 999 typedef struct { float bmsSlaveVoltage; @@ -43,10 +43,10 @@ static void over_voltage_test(); static void under_voltage_test(); static void over_temperature_test(); static void under_temperature_test(); -//static void weird_sensor_readings_voltage_test(); -//static void weird_sensor_readings_temperature_test(); static void communication_loss_test(); static void temperature_mux(uint8_t pinSelect); +static void set_temperature(float temparray[]); +static void set_voltage(float voltage); Result_t bms_slaves_process(uint8_t state) { @@ -70,12 +70,6 @@ Result_t bms_slaves_process(uint8_t state) case UNDER_TEMPERATURE_FAULT: under_temperature_test(); break; - case WEIRD_SENSOR_READINGS_VOLTAGE: - //weird_sensor_readings_voltage_test(); - break; - case WEIRD_SENSOR_READINGS_TEMPERATURE: - //weird_sensor_readings_temperature_test(); - break; case COMMUNICATION_LOSS: communication_loss_test(); break; @@ -104,14 +98,12 @@ void bms_slaves_init(){ bmsSlaveData_LOW->bmsSlaveTemperatures[i] = TEMP_MIN_VOLT; } - //make these a normal bms values? - set_voltage(0); - set_temperature(0); + set_voltage(bmsSlaveData->bmsSlaveVoltage); + set_temperature(bmsSlaveData->bmsSlaveTemperatures); UARTprintf("BMS Initialization Complete"); } -// Send a constant 3.8V static void normal_bms_operation(){ set_voltage(bmsSlaveData->bmsSlaveVoltage); set_temperature(bmsSlaveData->bmsSlaveTemperatures); @@ -133,20 +125,16 @@ static void over_voltage_test(){ static void under_temperature_test(){ set_voltage(bmsSlaveData->bmsSlaveVoltage); set_temperature(bmsSlaveData_LOW->bmsSlaveTemperatures); - } static void over_temperature_test(){ set_voltage(bmsSlaveData->bmsSlaveVoltage); set_temperature(bmsSlaveData_HIGH->bmsSlaveTemperatures); - } static void communication_loss_test(){ set_voltage(0); set_temperature(0); - - return; } // internal BMS Slave functions From 399bf179d370f5fe39bc2c2ded9b04678a5146de Mon Sep 17 00:00:00 2001 From: courtenayhuffman Date: Sat, 18 Sep 2021 17:12:41 -0700 Subject: [PATCH 06/10] integrate BMS slave tests to GUI --- TestBoardGUI/ui/testcases.json | 80 +++++++++++++++------------------- 1 file changed, 35 insertions(+), 45 deletions(-) diff --git a/TestBoardGUI/ui/testcases.json b/TestBoardGUI/ui/testcases.json index d36ae004..64436db9 100644 --- a/TestBoardGUI/ui/testcases.json +++ b/TestBoardGUI/ui/testcases.json @@ -272,27 +272,32 @@ { "Case": "Test 1: Alive Signal", "Repeat": "", - "Description": "Send an intermittent pulse (like a watchdog) to check that the device is functioning with the correct rate" + "Description": "Send an intermittent pulse (like a watchdog) to check that the device is functioning with the correct rate", + "enum": "0" }, { "Case": "Test 2: Dead Signal", "Repeat": "", - "Description": "Send no signal or constant signal (depends on what is defined as dead signal)" + "Description": "Send no signal or constant signal (depends on what is defined as dead signal)", + "enum": "0" }, { "Case": "Test 3: Alive at Wrong Rate", "Repeat": "", - "Description": "Send an intermittent pulse to check that the device is functioning with the wrong rate" + "Description": "Send an intermittent pulse to check that the device is functioning with the wrong rate", + "enum": "0" }, { "Case": "Test 4: No Signal", "Repeat": "", - "Description": "Check how the communication works when other devices don't get a signal" + "Description": "Check how the communication works when other devices don't get a signal", + "enum": "0" }, { "Case": "Test 5: Send Garbage", "Repeat": "", - "Description": "Determine how the FW reacts when noise is sent" + "Description": "Determine how the FW reacts when noise is sent", + "enum": "0" } ] }, @@ -301,81 +306,66 @@ { "Case": "Test 1: Configuration Test", "Repeat": "", - "Description": "Verify Master (BMS as mibspi3)-Slave (ADC as mibspi1) communication is established." + "Description": "Verify Master (BMS as mibspi3)-Slave (ADC as mibspi1) communication is established.", + "enum": "0" }, { "Case": "Test 2: Simulate and Send Test_Data_Set_1", "Repeat": "", - "Description": "Verify Master's (BMS as mibspi3) receival and response of Slave's (ADC as mibspi1) Test_Data_Set_1" + "Description": "Verify Master's (BMS as mibspi3) receival and response of Slave's (ADC as mibspi1) Test_Data_Set_1", + "enum": "0" }, { "Case": "Test 3: Don't Send Anything", "Repeat": "", - "Description": "" + "Description": "", + "enum": "0" }, { "Case": "Test 4: Send Garbage", "Repeat": "", - "Description": "" + "Description": "", + "enum": "0" } ] }, { "BMS Slave Voltages & Temperatures": [ { - "Case": "Test 1: Minor Voltage Fault", + "Case": "Test 1: Normal Slave Operation", "Repeat": "", - "Description": "Check BMS's response to a minor voltage fault" + "Description": "Check for condition of no response, sensor unplugged, etc.", + "enum": "0" }, { - "Case": "Test 2: Minor Temperature Fault", + "Case": "Test 1: Over-Voltage Fault", "Repeat": "", - "Description": "Check BMS's response to a minor temperature fault" + "Description": "Check BMS's response to a minor voltage fault", + "enum": "1" }, { - "Case": "Test 3: Major Voltage Fault", + "Case": "Test 2: Under-voltage Fault", "Repeat": "", - "Description": "Check BMS's response to a major voltage fault" + "Description": "Check BMS's response to a minor temperature fault", + "enum": "2" }, { - "Case": "Test 4: Major Temperature Fault", + "Case": "Test 3: Over-Temperature Fault", "Repeat": "", - "Description": "Check BMS's response to a major temperature fault" + "Description": "Check BMS's response to a major voltage fault", + "enum": "3" }, { - "Case": "Test 5: Weird Sensor Readings", + "Case": "Test 4: Under-Temperature Fault", "Repeat": "", - "Description": "Check BMS's response to getting temperature or voltage readings that don't make sense" + "Description": "Check BMS's response to a major temperature fault", + "enum": "4" }, { "Case": "Test 6: Communication Loss", "Repeat": "", - "Description": "Check how BMS reacts to messages timing out repeatedly" - }, - { - "Case": "Test 7: Garbage over CLI UART", - "Repeat": "", - "Description": "See how BMS reacts when its command line interface is overloaded with garbage" - }, - { - "Case": "Test 8: Correct Message Overload on CLI UART", - "Repeat": "", - "Description": "See how BMS reacts when it gets a lot of proper CLI commands in a short period of time" - }, - { - "Case": "Test 9: Balance Test", - "Repeat": "", - "Description": "See if BMS balancing algorithm balances the correct cells and also make sure BMS only balances during charging state" - }, - { - "Case": "Test 10: State of Charge Test", - "Repeat": "", - "Description": "See if BMS smoothly estimates the state of charge" - }, - { - "Case": "Test 11: Blown Parallel Fuse Test", - "Repeat": "", - "Description": "See if BMS can detect that a fuse has blown in a parallel stack" + "Description": "Check how BMS reacts to messages timing out repeatedly", + "enum": "5" } ] } From d7c4b86ee8c39664535ae5c14721e6bffa76e0d2 Mon Sep 17 00:00:00 2001 From: courtenayhuffman Date: Sat, 18 Sep 2021 18:13:19 -0700 Subject: [PATCH 07/10] make json strings consistent --- TestBoardGUI/tests/bms_test.py | 17 +++++++---------- TestBoardGUI/ui/testcases.json | 6 +++--- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/TestBoardGUI/tests/bms_test.py b/TestBoardGUI/tests/bms_test.py index ca8b53ca..cedd0cc1 100644 --- a/TestBoardGUI/tests/bms_test.py +++ b/TestBoardGUI/tests/bms_test.py @@ -12,25 +12,22 @@ from PySide2.QtCore import (QFile, QObject, Signal, Slot, Qt) - -# Constants to be changed based on Launchpad Settings -PORT = "COM8" BAUDRATE = 9600 TIMEOUT = 0.1 #Example of Tests to be chosen by UI -selectedTest_example = [{'Test Name': 'BMS_SLAVES', -'Test Case': 'y', -'Repeat': None, -'Test Index': None, 'Enum': 1}] +# selectedTest_example = [{'Test Name': 'BMS_SLAVES', +# 'Test Case': 'y', +# 'Repeat': None, +# 'Test Index': None, 'Enum': 1}] #{'Test Name': 'thermistor_exp', 'Test Case': 'v', 'Repeat': None, 'Test Index': None, 'Enum': 0}] # Dictionary object of BMS in normal state normal_bms = { "Mode": "BMS", - "BMS/VCU CAN": 0, - "Thermistor Expansion": 0, + "COMMUNICATIONS": 0, + "THERMISTOR_EXPANSION": 0, "BMS_SLAVES": 0, "repeat": 1 } @@ -42,7 +39,7 @@ def build_json(selectedTest): counter = 0 for x in selectedTest: - selectedJson.update({selectedTest_example[counter].get('Test Name'): selectedTest_example[counter].get('Enum')}) + selectedJson.update({selectedTest_example[counter].get('Test Name'): selectedTest_example[counter].get('enum')}) counter += 1 jsonStr = json.dumps(selectedJson, indent="\t") diff --git a/TestBoardGUI/ui/testcases.json b/TestBoardGUI/ui/testcases.json index 9e4fbe04..2215bb18 100644 --- a/TestBoardGUI/ui/testcases.json +++ b/TestBoardGUI/ui/testcases.json @@ -319,7 +319,7 @@ ], "BMS": [ { - "BMS/VCU CAN": [ + "COMMUNICATIONS": [ { "Case": "Test 1: Alive Signal", "Repeat": "", @@ -353,7 +353,7 @@ ] }, { - "Thermistor Expansion": [ + "THERMISTOR_EXPANSION": [ { "Case": "Test 1: Configuration Test", "Repeat": "", @@ -381,7 +381,7 @@ ] }, { - "BMS Slave Voltages & Temperatures": [ + "BMS_SLAVES": [ { "Case": "Test 1: Normal Slave Operation", "Repeat": "", From 78a0a3843cfb4ede12bac8c5716c067e6f4f3491 Mon Sep 17 00:00:00 2001 From: courtenayhuffman Date: Sat, 18 Sep 2021 18:23:05 -0700 Subject: [PATCH 08/10] refactor BMS gui uart messaging --- TestBoardGUI/tests/bms_test.py | 85 +++++++--------------------------- TestBoardGUI/ui/mainwindow.py | 2 +- 2 files changed, 19 insertions(+), 68 deletions(-) diff --git a/TestBoardGUI/tests/bms_test.py b/TestBoardGUI/tests/bms_test.py index cedd0cc1..e004e35c 100644 --- a/TestBoardGUI/tests/bms_test.py +++ b/TestBoardGUI/tests/bms_test.py @@ -12,9 +12,6 @@ from PySide2.QtCore import (QFile, QObject, Signal, Slot, Qt) -BAUDRATE = 9600 -TIMEOUT = 0.1 - #Example of Tests to be chosen by UI # selectedTest_example = [{'Test Name': 'BMS_SLAVES', # 'Test Case': 'y', @@ -33,79 +30,33 @@ } # Build Test Information to be Sent to Launchpad -def build_json(selectedTest): - +def build_json(info): + + selectedTests = info[0] + portNumber = info[1] selectedJson = copy.deepcopy(normal_bms) counter = 0 - for x in selectedTest: - selectedJson.update({selectedTest_example[counter].get('Test Name'): selectedTest_example[counter].get('enum')}) + for x in selectedTests: + selectedJson.update({selectedTests[counter].get('Test Name'): selectedTests[counter].get('enum')}) counter += 1 jsonStr = json.dumps(selectedJson, indent="\t") + # used for debugging purposes + length = len(jsonStr) + bytelength = len(bytes(jsonStr, encoding = 'utf8')) + # print(jsonStr) - return jsonStr - -# Encode and Send Test Information to Launchpad, Receive Response -def send_and_receive(selectedJson, serialPort): - - # print(bytes(selectedJson, 'utf-8')) - - # Encode Test Information and Send it to Launchpad - print(len(bytes(selectedJson, 'utf-8'))) - serialPort.write(bytes(selectedJson, 'utf-8')) - - # Wait 50 milliseconds for a response - time.sleep(.05) - + launchpad= serial.Serial(port = portNumber, baudrate = 9600, bytesize = serial.EIGHTBITS, stopbits = serial.STOPBITS_TWO, timeout = 10) + launchpad.write(bytes("BMS", encoding='utf8')) + time.sleep(2) + launchpad.write(bytes(jsonStr, encoding='utf8')) + result = launchpad.read(size=50) + launchpad.close() - # Read the most recent line of the Serial, return it as bytes - receivedData = serialPort.read_until(expected='}') - # receivedData = serialPort.read_all() + return result - return receivedData - -# Receive Response from Launchpad containing Test Results -@Slot(list) -def main(info): - selectedTests = info[0] - portNumber = info[1] - - # Initalize Serial - serialPort = serial.Serial(port = portNumber, baudrate = BAUDRATE, timeout = TIMEOUT, stopbits = serial.STOPBITS_TWO) - - # Prepare Test Infomation - selectedJson = build_json(selectedTests) - - # Prepare Launchpad to Receive BMS test Information - serialPort.write(bytes('BMS', 'utf-8')) - time.sleep(1) - print(serialPort.read_until(expected='}')) - # assert False - - # Repeatedly Send Test Info to Launchpad until Test Results are Received - data = '' - while data == '': - data = send_and_receive(selectedJson, serialPort) - #data = send_and_receive(json.dumps(normal_bms, indent="\t"), serialPort) - - # Close Serial - serialPort.close() - - return data # Test Function for PyTest Use, Passed: Test Results match Normal BMS State, Failed: Test Results do not match Normal BMS State def test_bms_json(): - - # Compare Test Results to Normal BMS State - # assert bytes(json.dumps(normal_bms, indent="\t"), 'utf-8') == main() - temp_byte = bytes(json.dumps(normal_bms, indent="\t"), 'utf-8') - temp_main = main() - # with open("tempB.bin", "wb") as file: - # file.write(temp_byte) - # with open("tempM.bin", "wb") as file: - # file.write(temp_main) - print(temp_byte) - print(temp_main) - assert temp_byte == temp_main - #assert bytes(json.dumps(normal_bms, indent="\t"), 'utf-8') == main() \ No newline at end of file + assert build_json() == True \ No newline at end of file diff --git a/TestBoardGUI/ui/mainwindow.py b/TestBoardGUI/ui/mainwindow.py index 0b4581b8..bb2e230c 100644 --- a/TestBoardGUI/ui/mainwindow.py +++ b/TestBoardGUI/ui/mainwindow.py @@ -247,7 +247,7 @@ def get_results(self, info: list): if self.device == 'VCU': result = vcu_test.build_json(info) elif self.device == 'BMS': - result = bms_test.main(info) + result = bms_test.build_json(info) # Add test status to the selected tests # WIP: change this part after firmware handles From 283b6429b14f06aed9a7f0ccd2519ad17b90856e Mon Sep 17 00:00:00 2001 From: courtenayhuffman Date: Sat, 18 Sep 2021 18:44:46 -0700 Subject: [PATCH 09/10] integrate BMS uart into firmware --- TestBoardFirmware/main.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/TestBoardFirmware/main.c b/TestBoardFirmware/main.c index 5a502a39..cf2e138c 100644 --- a/TestBoardFirmware/main.c +++ b/TestBoardFirmware/main.c @@ -67,9 +67,14 @@ static Result_t res; } UARTprintf("Mode detected: "); - //++ Added by jay pacamarra for debugging :) - sciReceive(PC_UART, 173, (unsigned char *)&UARTBuffer); - //++ Added by jay pacamarra for debugging :) + if(testBoardState.testMode == VCU_MODE){ + //++ Added by jay pacamarra for debugging :) + sciReceive(PC_UART, 173, (unsigned char *)&UARTBuffer); + //++ Added by jay pacamarra for debugging :) + } + else if (testBoardState.testMode == BMS_MODE){ + sciReceive(PC_UART, 102, (unsigned char *)&UARTBuffer); + } //* test code *// // setPeripheralTestCases(&testBoardState, JSONHandler(UARTBuffer)); From 5c7c45f93689b9ed0888bff3bdb6c7f57b60a712 Mon Sep 17 00:00:00 2001 From: courtenayhuffman Date: Sat, 18 Sep 2021 18:50:49 -0700 Subject: [PATCH 10/10] check testmode before setting peripheral state --- TestBoardFirmware/main.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/TestBoardFirmware/main.c b/TestBoardFirmware/main.c index cf2e138c..7e78428d 100644 --- a/TestBoardFirmware/main.c +++ b/TestBoardFirmware/main.c @@ -185,32 +185,32 @@ static json_t * JSONHandler(unsigned char *jsonstring){ static void setPeripheralTestCases(TestBoardState_t *stateptr, json_t* json){ #ifdef GUI_MODE - + if (testBoardState.testMode == VCU_MODE){ //VCU Tests - json_t * appsProperty = json_getProperty(json, "APPS"); - stateptr->peripheralStateArray[APPS] = (uint8_t) json_getInteger(appsProperty); - json_t * bseProperty = json_getProperty(json, "BSE"); - stateptr->peripheralStateArray[BSE] = (uint8_t) json_getInteger(bseProperty); - json_t * hv_vsProperty = json_getProperty(json, "HV_VOLTAGE_SENSOR"); - stateptr->peripheralStateArray[HV_VS] = (uint8_t) json_getInteger(hv_vsProperty); - - stateptr->peripheralStateArray[TSAL] = 0; + json_t * appsProperty = json_getProperty(json, "APPS"); + stateptr->peripheralStateArray[APPS] = (uint8_t) json_getInteger(appsProperty); + json_t * bseProperty = json_getProperty(json, "BSE"); + stateptr->peripheralStateArray[BSE] = (uint8_t) json_getInteger(bseProperty); + json_t * hv_vsProperty = json_getProperty(json, "HV_VOLTAGE_SENSOR"); + stateptr->peripheralStateArray[HV_VS] = (uint8_t) json_getInteger(hv_vsProperty); - stateptr->peripheralStateArray[IMD] = 0; + stateptr->peripheralStateArray[TSAL] = 0; - stateptr->peripheralStateArray[LV] = 0; + stateptr->peripheralStateArray[IMD] = 0; - stateptr->peripheralStateArray[VCU_COMMUNICATIONS] = 0; + stateptr->peripheralStateArray[LV] = 0; + stateptr->peripheralStateArray[VCU_COMMUNICATIONS] = 0; + } else if (testBoardState.testMode == BMS_MODE){ + // BMS Tests + // Check mode of testboard before setting test cases - Jay Pacamarra >:( + json_t * bmsProperty = json_getProperty(json, "BMS_SLAVES"); + stateptr->peripheralStateArray[BMS_SLAVES] = (uint8_t) json_getInteger(bmsProperty); - //BMS Tests - //Check mode of testboard before setting test cases - Jay Pacamarra >:( -// json_t * bmsProperty = json_getProperty(json, "BMS_SLAVES"); -// stateptr->peripheralStateArray[BMS_SLAVES] = (uint8_t) json_getInteger(bmsProperty); + stateptr->peripheralStateArray[THERMISTOR_EXPANSION] = 0; - //stateptr->peripheralStateArray[THERMISTOR_EXPANSION] = 0; - - //stateptr->peripheralStateArray[BMS_COMMUNICATIONS] = 0; + stateptr->peripheralStateArray[BMS_COMMUNICATIONS] = 0; + } #endif