Cell voltages fork (SoC)
Dependencies: CUER_CAN CUER_DS1820 LTC2943 LTC6804 mbed PowerControl
Diff: main.cpp
- Revision:
- 66:c884fba9eaea
- Parent:
- 65:95f21910cf9d
--- a/main.cpp Tue Sep 12 01:29:12 2017 +0000 +++ b/main.cpp Sat Sep 16 01:10:01 2017 +0000 @@ -204,8 +204,11 @@ can_send(msg); if (DEBUG) printf("Sent Battery voltage %d and current %f with id %d \r\n",decodeBatteryVoltage(msg),decodeBatteryCurrent(msg),msg.id); - //Extended battery pack status - msg = createExtendedBatteryPackStatus(status); + msg = createBatteryPower(measurements.battery_voltage,measurements.battery_current); + can_send(msg); + + //Battery pack status + msg = createBatteryPackStatus(status); can_send(msg); if (DEBUG) printf("Sent battery pack status with value %d \r\n", status); @@ -236,7 +239,7 @@ // Get a pointer to the start address for the data stored in the eeprom i2c_page_read(0x0000, 4, start_address_array1); - if (DEBUG) printf("\r\n\ Start address (%d,%d) \r\n \r\n", start_address_array1[0], start_address_array1[1]); + if (DEBUG) printf("\r\n Start address (%d,%d) \r\n \r\n", start_address_array1[0], start_address_array1[1]); wait_ms(10); i2c_page_read(0x0004, 4, start_address_array2); @@ -507,12 +510,8 @@ if(measurements.max_cell_voltage.voltage > MAX_CELL_VOLTAGE) { status = status | CELL_OVER_VOLTAGE; } - if(measurements.max_cell_voltage.voltage > MAX_CELL_CHARGE_VOLTAGE) { - status = status | CELL_OVER_CHARGE_VOLTAGE; - } if (measurements.min_cell_voltage.voltage < MIN_CELL_VOLTAGE) { status = status | CELL_UNDER_VOLTAGE; - //printf(" \r\n \r\n \r\n Min cell in check MEASUREMENTS is voltage is %d \r\n", measurements.min_cell_voltage.voltage); } if (maxTemp.temperature > MAX_CELL_CHARGE_TEMPERATURE && (temp_measurements_timer.read() > initial_temperature_delay || temperature_measurements_received)) { status = status | CELL_OVER_CHARGE_TEMPERATURE; @@ -532,6 +531,18 @@ if (fabs(measurements.battery_current) > OVERCURRENT_THRESHOLD) { status = status | OVERCURRENT_ERROR; } + if(measurements.max_cell_voltage.voltage > MAX_CELL_CHARGE_VOLTAGE) { + status = status | CELL_OVER_CHARGE_VOLTAGE; + } + if(measurements.max_cell_voltage.voltage > MAX_CELL_SAFE_VOLTAGE) { + status = status | CELL_DANGEROUSLY_OVER_VOLTAGE; + } + if (measurements.min_cell_voltage.voltage < MIN_CELL_VOLTAGE) { + status = status | CELL_DANGEROUSLY_UNDER_VOLTAGE; + } + if (maxTemp.temperature > MAX_CELL_SAFE_TEMPERATURE && (temp_measurements_timer.read() > initial_temperature_delay || temperature_measurements_received)) { + status = status | CELL_DANGEROUSLY_OVER_TEMPERATURE; + } /* @TODO also include errors for: @@ -725,12 +736,10 @@ //Import the data from the buffer into a non-volatile, more usable format CAN_Data can_data[CAN_BUFFER_SIZE]; //container for all of the raw data CANMessage msgArray[CAN_BUFFER_SIZE]; //Same as above but some functions take message as their parameter - int received_CAN_IDs[CAN_BUFFER_SIZE]; //needed to keep track of which IDs we've received so far for (int i = 0; i<CAN_BUFFER_SIZE; ++i) { safe_to_write[i] = false; can_data[i].importCANData(buffer[i]); - received_CAN_IDs[i] = buffer[i].id; msgArray[i] = buffer[i]; safe_to_write[i] = true; //printf("Id recieved %d \r\n", buffer[i].id); @@ -782,6 +791,16 @@ minTemp.temperature,minTemp.ID,maxTemp.temperature,maxTemp.ID); } +bool can_send(CANMessage msg) { + Timer t; + CAN_data_sent = false; + t.start(); + can.write(msg); + while(!CAN_data_sent && t.read_ms() < CAN_TIMEOUT_MS); + if (t.read_ms() > CAN_TIMEOUT_MS) return false; + else return true; +} + /*void test_read_CAN_buffer() { //Import the data from the buffer into a non-volatile, more usable format @@ -849,7 +868,7 @@ } if(msgArray[i].id == BMS_BASE_ID + BATTERY_STATUS_ID) - status = decodeExtendedBatteryPackStatus(msgArray[i]); + status = decodeBatteryPackStatus(msgArray[i]); if(msgArray[i].id == BMS_BASE_ID) if (DEBUG) printf("BMS Heartbeat Recieved \r\n"); @@ -877,34 +896,6 @@ if (DEBUG) printf("Status value is: %d \r\n", status); } */ -void test_CAN_send() -{ - CANMessage msg; - char value = 142; - msg = CANMessage(1, &value,1); - if(can_send(msg)) - if (DEBUG) printf("Succesfully sent %d \r\n", value); - else - if (DEBUG) printf("Sending Failed \r\n"); -} - -void test_CAN_read() -{ - CANMessage msg; - if(can.read(msg)) - if (DEBUG) printf("Successfully recieved %d \r\n", msg.data[0]); - else - if (DEBUG) printf("Reading Failed \r\n"); -} - -bool can_send(CANMessage msg) { - Timer t; - CAN_data_sent = false; - t.start(); - can.write(msg); - while(!CAN_data_sent && t.read_ms() < CAN_TIMEOUT_MS); - if (t.read_ms() > CAN_TIMEOUT_MS) return false; - else return true; -} +