Commit a0b4929e authored by Sergi Hernandez's avatar Sergi Hernandez
Browse files

Changed the way the data is read from the SMBus. Instead of reading all data...

Changed the way the data is read from the SMBus. Instead of reading all data all in one burst, successive reads are delayed in time. This way the charger can receive the voltage and current values form the battery.
Completed the PC driver to get the fuel gauging data.
parent cca6cf66
......@@ -2,6 +2,7 @@
#include "../../../stm32_code/include/dyn_battery.h"
#include "exceptions.h"
#include "battery_charger_exceptions.h"
#include <iostream>
CBattery_Charger::CBattery_Charger(std::string& battery_id,unsigned char bus_id,int baudrate,unsigned char dev_id)
{
......@@ -154,6 +155,122 @@ bool CBattery_Charger::is_charger_enabled(void)
return false;
}
/* fuel gauge functions */
double CBattery_Charger::get_battery_temperature(void)
{
}
double CBattery_Charger::get_battery_voltage(void)
{
}
double CBattery_Charger::get_battery_current(void)
{
}
double CBattery_Charger::get_battery_avg_current(void)
{
}
unsigned char CBattery_Charger::get_battery_relative_soc(void)
{
}
unsigned char CBattery_Charger::get_battery_absolute_soc(void)
{
}
double CBattery_Charger::get_battery_remaining_capacity(void)
{
}
double CBattery_Charger::get_battery_full_charge_capacity(void)
{
}
unsigned int CBattery_Charger::get_battery_run_time_to_empty(void)
{
}
unsigned int CBattery_Charger::get_battery_avg_time_to_empty(void)
{
}
unsigned int CBattery_Charger::get_battery_avg_time_to_full(void)
{
}
unsigned short int CBattery_Charger::get_battery_status(void)
{
}
double CBattery_Charger::get_battery_design_capacity(void)
{
}
double CBattery_Charger::get_battery_design_voltage(void)
{
}
double CBattery_Charger::get_battery_cell1_voltage(void)
{
}
double CBattery_Charger::get_battery_cell2_voltage(void)
{
}
double CBattery_Charger::get_battery_cell3_voltage(void)
{
}
double CBattery_Charger::get_battery_cell4_voltage(void)
{
}
void CBattery_Charger::get_battery_all_data(TBatteryInfo *info)
{
unsigned char data[34];
this->dyn_device->read_registers(BATTERY_TEMPERATURE_L,data,34);
/* convert data */
info->temperature=(data[0]+(data[1]<<8))*0.1-273.15;
info->battery_voltage=((short int)(data[2]+(data[3]<<8)))/1000.0;
info->battery_current=((short int)(data[4]+(data[5]<<8)))/1000.0;
info->battery_avg_current=((short int)(data[6]+(data[7]<<8)))/1000.0;
info->relative_soc=data[8];
info->absolute_soc=data[9];
info->remaining_capacity=(data[10]+(data[11]<<8))/1000.0;
info->full_charge_capacity=(data[12]+(data[13]<<8))/1000.0;
info->run_time_empty=(data[14]+(data[15]<<8));
info->avg_time_empty=(data[16]+(data[17]<<8));
info->avg_time_full=(data[18]+(data[19]<<8));
info->battery_status=(data[20]+(data[21]<<8));
info->design_capacity=(data[22]+(data[23]<<8))/1000.0;
info->design_voltage=(data[24]+(data[25]<<8))/1000.0;
info->cell1_voltage=(data[26]+(data[27]<<8))/1000.0;
info->cell2_voltage=(data[28]+(data[29]<<8))/1000.0;
info->cell3_voltage=(data[30]+(data[31]<<8))/1000.0;
info->cell4_voltage=(data[32]+(data[33]<<8))/1000.0;
}
CBattery_Charger::~CBattery_Charger()
{
......
......@@ -6,6 +6,27 @@
#include "threadserver.h"
#include "eventserver.h"
typedef struct{
double temperature;
double battery_voltage;
double battery_current;
double battery_avg_current;
unsigned char relative_soc;
unsigned char absolute_soc;
double remaining_capacity;
double full_charge_capacity;
unsigned int run_time_empty;
unsigned int avg_time_empty;
unsigned int avg_time_full;
unsigned short int battery_status;
double design_capacity;
double design_voltage;
double cell1_voltage;
double cell2_voltage;
double cell3_voltage;
double cell4_voltage;
}TBatteryInfo;
class CBattery_Charger
{
private:
......@@ -28,6 +49,25 @@ class CBattery_Charger
bool is_battery_present(void);
bool is_charger_enabled(void);
/* fuel gauge functions */
double get_battery_temperature(void);
double get_battery_voltage(void);
double get_battery_current(void);
double get_battery_avg_current(void);
unsigned char get_battery_relative_soc(void);
unsigned char get_battery_absolute_soc(void);
double get_battery_remaining_capacity(void);
double get_battery_full_charge_capacity(void);
unsigned int get_battery_run_time_to_empty(void);
unsigned int get_battery_avg_time_to_empty(void);
unsigned int get_battery_avg_time_to_full(void);
unsigned short int get_battery_status(void);
double get_battery_design_capacity(void);
double get_battery_design_voltage(void);
double get_battery_cell1_voltage(void);
double get_battery_cell2_voltage(void);
double get_battery_cell3_voltage(void);
double get_battery_cell4_voltage(void);
void get_battery_all_data(TBatteryInfo *info);
~CBattery_Charger();
};
......
......@@ -8,6 +8,7 @@ std::string battery_serial="A401293W";
int main(int argc, char *argv[])
{
double voltage,current;
TBatteryInfo info;
int i=0;
try{
......@@ -22,6 +23,25 @@ int main(int argc, char *argv[])
std::cout << "Input current: " << current << " A" << std::endl;
battery.get_charger_output(&voltage,&current);
std::cout << "Actual Voltage: " << voltage << " V, Actual Current: " << current << " A" << std::endl;
battery.get_battery_all_data(&info);
std::cout << "Battery temperature: " << info.temperature << " ºC" << std::endl;
std::cout << "Battery voltage: " << info.battery_voltage << " V" << std::endl;
std::cout << "Battery current: " << info.battery_current << " A" << std::endl;
std::cout << "Battery average current: " << info.battery_avg_current << " A" << std::endl;
std::cout << "Battery relative state of charge: " << (int)info.relative_soc << " %" << std::endl;
std::cout << "Battery absolute state of charge: " << (int)info.absolute_soc << " %" << std::endl;
std::cout << "Battery remaining capacity: " << info.remaining_capacity << " Ah" << std::endl;
std::cout << "Battery full charge capacity: " << info.full_charge_capacity << " Ah" << std::endl;
std::cout << "Battery run time to empty: " << info.run_time_empty << " min" << std::endl;
std::cout << "Battery average time to empty: " << info.avg_time_empty << " min" << std::endl;
std::cout << "Battery average time to full: " << info.avg_time_full << " min" << std::endl;
std::cout << "Battery design capacity: " << info.design_capacity << " Ah" << std::endl;
std::cout << "Battery design voltage: " << info.design_voltage << " V" << std::endl;
std::cout << "Battery cell1 voltage: " << info.cell1_voltage << " V" << std::endl;
std::cout << "Battery cell2 voltage: " << info.cell2_voltage << " V" << std::endl;
std::cout << "Battery cell3 voltage: " << info.cell3_voltage << " V" << std::endl;
std::cout << "Battery cell4 voltage: " << info.cell4_voltage << " V" << std::endl;
sleep(1);
}
}catch(CException &e){
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment