Skip to content

Commit

Permalink
Power/PCTLv2: added parameter to wakeup from emergency mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
rasmartins committed Jun 30, 2016
1 parent dba3543 commit 39db11c
Showing 1 changed file with 32 additions and 5 deletions.
37 changes: 32 additions & 5 deletions src/Power/PCTLv2/Task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ namespace Power
std::vector<uint8_t> chn_eme_state;
//! Minimum operating voltage.
double vol_min;
//! Wake-up voltage.
double vol_wup;
//! LED names.
std::vector<std::string> leds;
};
Expand Down Expand Up @@ -188,6 +190,11 @@ namespace Power
.maximumValue("25")
.description("Once this value is hit the system will enter emergency mode");

param("Wakeup Operating Voltage", m_args.vol_wup)
.units(Units::Volt)
.defaultValue("24")
.description("Minimum voltage required to leave emergency mode, should be greater than the minimum operating voltage");

param("Watchdog Timeout", m_args.wdog_tout)
.units(Units::Second)
.defaultValue("2.0")
Expand Down Expand Up @@ -364,18 +371,17 @@ namespace Power
{
m_proto.requestVersion();

updateEEPROM();

std::map<unsigned, PowerChannel*>::const_iterator itr = m_channels.begin();
for ( ; itr != m_channels.end(); ++itr)
setPowerChannelState(itr->second->id, itr->second->state.state);
}

//! Update EEPROM data.
void
updateEEPROM(void)
updateEEPROM(bool version_pre24)
{
uint16_t vol_min = (uint16_t)Math::round(m_args.vol_min * 1000);
uint16_t vol_wup = (uint16_t)Math::round(m_args.vol_wup * 1000);
uint16_t vol_cnv = (uint16_t)Math::round(m_args.adc_factors[0][0] * 100.0);
uint8_t cmd[] =
{
Expand All @@ -388,12 +394,27 @@ namespace Power
(uint8_t)(vol_min >> 8),
(uint8_t)(vol_min),
(uint8_t)(vol_cnv >> 8),
(uint8_t)(vol_cnv)
(uint8_t)(vol_cnv),
(uint8_t)(vol_wup >> 8),
(uint8_t)(vol_wup),
};

m_proto.sendCommand(CMD_EEPROM, cmd, sizeof(cmd));
// Firmware version prior to 2.4.0 did not have a parameter for nominal voltage.
if (version_pre24)
{
debug("sending pre v2.4 EEPROM data");
cmd[1] -= 2;
m_proto.sendCommand(CMD_EEPROM, cmd, sizeof(cmd) - 2);
}
else
{
m_proto.sendCommand(CMD_EEPROM, cmd, sizeof(cmd));
}

if (!waitForCommand(CMD_EEPROM, 100))
err(DTR("failed to update EEPROM"));
else
debug("updated EEPROM");
}

//! Process data from ADCs
Expand Down Expand Up @@ -502,7 +523,13 @@ namespace Power
void
onVersion(unsigned major, unsigned minor, unsigned patch)
{
bool version_pre24 = false;

inf(DTR("firmware version %u.%u.%u"), major, minor, patch);
if (major <= 2 && minor <= 3)
version_pre24 = true;

updateEEPROM(version_pre24);
}

//! Wait for command.
Expand Down

0 comments on commit 39db11c

Please sign in to comment.