Skip to content
Snippets Groups Projects
Commit 284fcc06 authored by Fernando Herrero's avatar Fernando Herrero
Browse files

Add alarm iteration for thread starting (lost on old commit)

Add some capacity data short int casts
Fix BatteryStatus error bit number
parent 5496e6ef
No related branches found
No related tags found
No related merge requests found
......@@ -61,6 +61,7 @@ void *CBattery_Monitor::battery_monitor_thread(void *param)
CBattery_Monitor *battery=(CBattery_Monitor *)param;
short int data[21];
bool end=false;
std::list<TAlarm>::iterator iterator;
while(!end)
{
......@@ -70,7 +71,7 @@ void *CBattery_Monitor::battery_monitor_thread(void *param)
else
{
/* get the data from the battery */
battery->bat_mon->read_registers(0x20,(unsigned char *)data,38);
battery->bat_mon->read_registers(0x20,(unsigned char *)data,42);
/* convert the data */
battery->info.temperature=data[0]/10.0-273.15;
battery->info.battery_voltage=data[1]/1000.0;
......@@ -79,20 +80,44 @@ void *CBattery_Monitor::battery_monitor_thread(void *param)
battery->info.relative_state_of_charge=data[4];
battery->info.absolute_state_of_charge=data[5];
battery->info.remaining_capacity=data[6]/1000.0;
battery->info.full_charge_capacity=data[7]/1000.0;
battery->info.full_charge_capacity=((unsigned short int)data[7])/1000.0;
battery->info.run_time_to_empty=data[8];
battery->info.avg_time_to_empty=data[9];
battery->info.avg_time_to_full=data[10];
battery->info.charging_current=data[11]/1000.0;
battery->info.charging_voltage=data[12]/1000.0;
(*((unsigned short int *)&battery->info.status))=data[13];
battery->info.design_capacity=data[14]/1000.0;
battery->info.design_capacity=((unsigned short int)data[14])/1000.0;
battery->info.design_voltage=data[15]/1000.0;
// pack status ignored
battery->info.cell4_voltage=data[17]/1000.0;
battery->info.cell3_voltage=data[18]/1000.0;
battery->info.cell2_voltage=data[19]/1000.0;
battery->info.cell1_voltage=data[20]/1000.0;
bool active_alarm=false;
for(iterator=battery->alarms.begin();iterator!=battery->alarms.end();iterator++)
{
if(iterator->condition_function(&battery->info))
{
active_alarm=true;
if(!battery->event_server->event_is_set(iterator->event_id))
battery->event_server->set_event(iterator->event_id);
// start the thread sound
battery->current_alarm=iterator;
if(battery->sound_enabled)
{
/* start the thread only once */
if(battery->thread_server->get_thread_state(battery->battery_sound_thread_id)==attached)
battery->thread_server->start_thread(battery->battery_sound_thread_id);
}
break;
}
}
if(!active_alarm)
battery->disable_alarm_sound();
}
}catch(CException &e){
std::cout << e.what() << std::endl;
......
......@@ -9,7 +9,7 @@
typedef struct
{
unsigned short int error:3;
unsigned short int error:4;
unsigned short int fully_discharged:1;
unsigned short int fully_charged:1;
unsigned short int discharging:1;
......
......@@ -6,7 +6,7 @@
#include <linux/kd.h>
#include <signal.h>
std::string battery_dev="A900WSG1";
std::string battery_dev="A600eB1Y";
bool condition1(TBatteryInfo *info)
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment