Laelaps  2.3.5
RoadNarrows Robotics Small Outdoor Mobile Robot Project
laelaps::LaeWd Class Reference

#include <laeWd.h>

Public Member Functions

 LaeWd (LaeI2C &i2cBus, uint_t addr=LaeI2CAddrArduino)
 Initialization constructor. More...
 
virtual ~LaeWd ()
 Destructor.
 
virtual void sync ()
 Synchronize watchdog state with subprocessor state.
 
virtual int configure (const LaeDesc &desc)
 Configure watchdog from product description. More...
 
virtual int configure (const LaeTunes &tunes)
 Configure watchdog from tunable parameters. More...
 
virtual int reload (const LaeTunes &tunes)
 Reload with new configuration. More...
 
virtual void exec ()
 Execute cycle to pet/read/update Watchdog sub-processor.
 
virtual int cmdPetTheDog ()
 Pet the watchdog command. More...
 
virtual int cmdGetFwVersion (uint_t &uVerNum)
 Get the firmware version command. More...
 
virtual int cmdSetBatterySoC (uint_t uBatterySoC)
 Set battery's state of charge state command. More...
 
virtual int cmdSetAlarms (uint_t uAlarms)
 Set (clear) alarms command. More...
 
virtual int cmdSetRgbLed (uint_t red, uint_t green, uint_t blue)
 Set the LED RGB color command. More...
 
virtual int cmdResetRgbLed ()
 Reset the LED RGB color to state defaults. More...
 
virtual int cmdConfigDPin (uint_t pin, uint_t dir)
 Configure a digital pin command. More...
 
virtual int cmdReadDPin (uint_t pin, uint_t &val)
 Read the value of a digital pin command. More...
 
virtual int cmdWriteDPin (uint_t pin, uint_t val)
 Write a value to a digital pin command. More...
 
virtual int cmdReadAPin (uint_t pin, uint_t &val)
 Read the value of an analog pin command. More...
 
virtual int cmdWriteAPin (uint_t pin, uint_t val)
 Write the value to an analog pin command. More...
 
virtual int cmdEnableMotorCtlrs (bool bEnable)
 Enable/disable power in to motor controllers. More...
 
virtual int cmdEnableAuxPort5V (bool bEnable)
 Enable/disable regulated 5 volt auxilliary port power out. More...
 
virtual int cmdEnableAuxPortBatt (bool bEnable)
 Enable/disable battery auxilliary port power out. More...
 
virtual int cmdReadEnables (bool &bMotorCtlrEn, bool &bAuxPort5vEn, bool &bAuxPortBattEn)
 Read enable lines. More...
 
virtual int cmdReadVoltages (double &fJackV, double &fBattV)
 Read sensed voltages. More...
 
virtual int cmdTest (uint_t &uSeqNum, uint_t &uOpState, uint_t &uAlarms, uint_t &uLedIndex)
 Test the firmware state command. More...
 
virtual int cmdConfigOperation (unsigned long uTimeout)
 Configure firmware operation. More...
 
uint_t getI2CAddr ()
 Get watchdog's I2C address. More...
 
uint_t getFwVersion ()
 Get previously read firmware version. More...
 
bool isCharging ()
 Test if battery is charging. More...
 

Static Public Member Functions

static int enableMotorCtlrs (void *pArg, bool bEnable)
 Enable/disable power in to motor controllers. More...
 

Protected Member Functions

void lock ()
 Lock the shared resource. More...
 
void unlock ()
 Unlock the shared resource. More...
 
uint_t determineAlarms ()
 Determine watchdog alarm state. More...
 

Protected Attributes

LaeI2Cm_i2cBus
 bound I2C bus instance
 
uint_t m_addrSubProc
 I2C sub-processor address.
 
uint_t m_uFwVer
 firmware version number
 
ulong_t m_uWatchdogTimeout
 watchdog timeout (msec)
 
bool m_bBatteryIsCharging
 battery is [not] charging
 
double m_fBatteryVoltage
 sensed battery voltage
 
double m_fJackVoltage
 sensed power supply jack voltage
 
uint_t m_uBatterySoC
 battery state of charge
 
uint_t m_uAlarms
 alarms
 
bool m_bMotorCtlrEn
 motor controller enable
 
bool m_bAuxPortBattEn
 battery auxilliary port enable
 
bool m_bAuxPort5vEn
 5 volt auxilliary port enable
 
rnr::chronos::Time m_timeMotorCtlrs
 motor controller up time
 
pthread_mutex_t m_mutex
 mutex
 

Detailed Description

WatchDog sub-processor interface class.

Definition at line 85 of file laeWd.h.

Constructor & Destructor Documentation

LaeWd::LaeWd ( LaeI2C i2cBus,
uint_t  addr = LaeI2CAddrArduino 
)

Initialization constructor.

Parameters
i2cbusBound open I2C bus instance.
addrArduino I2C address.

Definition at line 113 of file laeWd.cxx.

References FWVER_UNKNOWN, laelaps::LaeWdArgAlarmNone, laelaps::LaeWdArgBattSoCMax, laelaps::LaeWdTimeoutDft, laelaps::LaeDbEnable::m_bAuxPort5v, m_bAuxPort5vEn, laelaps::LaeDbEnable::m_bAuxPortBatt, m_bAuxPortBattEn, laelaps::LaeDbEnergy::m_bBatteryIsCharging, m_bBatteryIsCharging, laelaps::LaeDbEnable::m_bMotorCtlr, m_bMotorCtlrEn, laelaps::LaeDb::m_enable, laelaps::LaeDb::m_energy, m_fBatteryVoltage, laelaps::LaeDbEnergy::m_fJackVoltage, m_fJackVoltage, m_mutex, m_uAlarms, m_uBatterySoC, m_uFwVer, m_uWatchdogTimeout, and laelaps::RtDb.

113  :
114  m_i2cBus(i2cBus), m_addrSubProc(addr)
115 {
116  // shadow values
119  m_bBatteryIsCharging = false;
120  m_fBatteryVoltage = 0.0;
121  m_fJackVoltage = 0.0;
124  m_bMotorCtlrEn = false;
125  m_bAuxPortBattEn = false;
126  m_bAuxPort5vEn = false;
127 
133 
134  pthread_mutex_init(&m_mutex, NULL);
135 }
const unsigned long LaeWdTimeoutDft
watchdog timeout default
Definition: laeWatchDog.h:83
ulong_t m_uWatchdogTimeout
watchdog timeout (msec)
Definition: laeWd.h:393
uint_t m_uAlarms
alarms
Definition: laeWd.h:398
uint_t m_uBatterySoC
battery state of charge
Definition: laeWd.h:397
bool m_bBatteryIsCharging
battery is [not] charging
Definition: laeWd.h:394
bool m_bMotorCtlrEn
motor controller enable
Definition: laeWd.h:399
double m_fJackVoltage
sensed power supply jack voltage
Definition: laeWd.h:396
const unsigned int LaeWdArgBattSoCMax
100% charge
Definition: laeWatchDog.h:91
bool m_bBatteryIsCharging
batteries are [not] being charged
Definition: laeDb.h:199
uint_t m_uFwVer
firmware version number
Definition: laeWd.h:390
LaeDb RtDb
The real-time database.
Definition: laeDb.h:244
pthread_mutex_t m_mutex
mutex
Definition: laeWd.h:407
bool m_bAuxPortBatt
battery auxilliary port [not] enabled
Definition: laeDb.h:122
LaeI2C & m_i2cBus
bound I2C bus instance
Definition: laeWd.h:388
const unsigned int LaeWdArgAlarmNone
no/clear alarms
Definition: laeWatchDog.h:96
bool m_bAuxPortBattEn
battery auxilliary port enable
Definition: laeWd.h:400
LaeDbEnable m_enable
key gpio state data
Definition: laeDb.h:230
double m_fBatteryVoltage
sensed battery voltage
Definition: laeWd.h:395
LaeDbEnergy m_energy
battery and energy data
Definition: laeDb.h:237
double m_fJackVoltage
sensed power supply jack voltage
Definition: laeDb.h:200
bool m_bAuxPort5vEn
5 volt auxilliary port enable
Definition: laeWd.h:401
bool m_bMotorCtlr
motor controller [not] enabled
Definition: laeDb.h:121
uint_t m_addrSubProc
I2C sub-processor address.
Definition: laeWd.h:389
static uint_t FWVER_UNKNOWN
unknown firmware version
Definition: laeWd.cxx:103
bool m_bAuxPort5v
5 volt auxilliary port [not] enabled
Definition: laeDb.h:123

Member Function Documentation

int LaeWd::cmdConfigDPin ( uint_t  pin,
uint_t  dir 
)
virtual

Configure a digital pin command.

Note
Deprecated in robot v2.2+ since there now exist an accessory subprocessor to support various gpio.
Parameters
pinDigital pin number.
dirPin direction. 0 == input, 1 == output.
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Definition at line 396 of file laeWd.cxx.

References FWVER_UNKNOWN, laelaps::LAE_ECODE_BAD_VAL, laelaps::LAE_ECODE_IO, laelaps::LAE_OK, laelaps::LaeWdArgDPinDirIn, laelaps::LaeWdArgDPinDirOut, laelaps::LaeWdArgDPinNumWMax, laelaps::LaeWdArgDPinNumWMin, laelaps::LaeWdCmdIdConfigDPin, laelaps::LaeWdMaxCmdLen, lock(), m_addrSubProc, m_i2cBus, m_uFwVer, unlock(), and laelaps::LaeI2C::write().

Referenced by laelaps::LaeRobot::configDigitalPin().

397 {
398  byte_t cmd[LaeWdMaxCmdLen];
399  size_t lenCmd = 0;
400  int n;
401  int rc;
402 
403  lock();
404 
405  // unknown firmware version
406  if( m_uFwVer == FWVER_UNKNOWN )
407  {
408  rc = LAE_OK;
409  }
410 
411  // deprecated
412  else if( m_uFwVer >= 3 )
413  {
414  rc = LAE_OK;
415  }
416 
417  // supported
418  else
419  {
420  if( (pin < LaeWdArgDPinNumWMin) || (pin > LaeWdArgDPinNumWMax) )
421  {
422  LOGERROR("Pin %u: Out-of-range.", pin);
423  rc = -LAE_ECODE_BAD_VAL;
424  }
425 
426  else
427  {
428  dir = dir > 0? LaeWdArgDPinDirOut: LaeWdArgDPinDirIn;
429 
430  cmd[lenCmd++] = LaeWdCmdIdConfigDPin;
431  cmd[lenCmd++] = (byte_t)pin;
432  cmd[lenCmd++] = (byte_t)dir;
433 
434  n = m_i2cBus.write(m_addrSubProc, cmd, lenCmd);
435 
436  rc = (n == (int)lenCmd)? LAE_OK: -LAE_ECODE_IO;
437  }
438  }
439 
440  unlock();
441 
442  return rc;
443 }
void lock()
Lock the shared resource.
Definition: laeWd.h:418
static const int LAE_ECODE_IO
I/O error.
Definition: laelaps.h:98
uint_t m_uFwVer
firmware version number
Definition: laeWd.h:390
const byte_t LaeWdArgDPinDirIn
input
Definition: laeWatchDog.h:120
LaeI2C & m_i2cBus
bound I2C bus instance
Definition: laeWd.h:388
void unlock()
Unlock the shared resource.
Definition: laeWd.h:429
virtual int write(uint_t addr, const byte_t buf[], size_t len)
Write to an I2C slave endpoint device.
Definition: laeI2C.cxx:194
const byte_t LaeWdCmdIdConfigDPin
command id
Definition: laeWatchDog.h:278
const byte_t LaeWdArgDPinNumWMax
max write/modify pin number
Definition: laeWatchDog.h:117
const byte_t LaeWdArgDPinNumWMin
min write/modify pin number
Definition: laeWatchDog.h:116
static const int LAE_ECODE_BAD_VAL
bad value general error
Definition: laelaps.h:76
uint_t m_addrSubProc
I2C sub-processor address.
Definition: laeWd.h:389
static uint_t FWVER_UNKNOWN
unknown firmware version
Definition: laeWd.cxx:103
const byte_t LaeWdArgDPinDirOut
output
Definition: laeWatchDog.h:121
const int LaeWdMaxCmdLen
maximum command length
Definition: laeWatchDog.h:167
static const int LAE_OK
not an error, success
Definition: laelaps.h:71
int LaeWd::cmdConfigOperation ( unsigned long  uTimeout)
virtual

Configure firmware operation.

Parameters
uTimeoutWatchdog timeout (msec).
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Definition at line 1028 of file laeWd.cxx.

References laelaps::LAE_ECODE_IO, laelaps::LAE_OK, laelaps::LaeWdCmdIdConfigFw, laelaps::LaeWdMaxCmdLen, laelaps::LaeWdTimeoutDft, lock(), m_addrSubProc, laelaps::LaeDb::m_config, laelaps::LaeDbConfig::m_fWatchDogTimeout, m_i2cBus, m_uFwVer, m_uWatchdogTimeout, laelaps::RtDb, unlock(), and laelaps::LaeI2C::write().

Referenced by configure(), and sync().

1029 {
1030  byte_t cmd[LaeWdMaxCmdLen];
1031  size_t lenCmd = 0;
1032  int n;
1033  int rc;
1034 
1035  lock();
1036 
1037  // no support in older versions
1038  if( m_uFwVer < 3 )
1039  {
1041  rc = LAE_OK;
1042  }
1043 
1044  else
1045  {
1046  cmd[lenCmd++] = LaeWdCmdIdConfigFw;
1047  cmd[lenCmd++] = (byte_t)((uTimeout >> 8) & 0xff);
1048  cmd[lenCmd++] = (byte_t)(uTimeout & 0xff);
1049 
1050  n = m_i2cBus.write(m_addrSubProc, cmd, lenCmd);
1051 
1052  if( n == (int)lenCmd )
1053  {
1054  m_uWatchdogTimeout = uTimeout;
1055  rc = LAE_OK;
1056  }
1057  else
1058  {
1059  rc = -LAE_ECODE_IO;
1060  }
1061  }
1062 
1063  if( rc == LAE_OK )
1064  {
1066  }
1067 
1068  unlock();
1069 
1070  return rc;
1071 }
const unsigned long LaeWdTimeoutDft
watchdog timeout default
Definition: laeWatchDog.h:83
ulong_t m_uWatchdogTimeout
watchdog timeout (msec)
Definition: laeWd.h:393
void lock()
Lock the shared resource.
Definition: laeWd.h:418
static const int LAE_ECODE_IO
I/O error.
Definition: laelaps.h:98
uint_t m_uFwVer
firmware version number
Definition: laeWd.h:390
LaeDb RtDb
The real-time database.
Definition: laeDb.h:244
LaeI2C & m_i2cBus
bound I2C bus instance
Definition: laeWd.h:388
double m_fWatchDogTimeout
watchdog timeout (seconds)
Definition: laeDb.h:98
const byte_t LaeWdCmdIdConfigFw
command id
Definition: laeWatchDog.h:471
void unlock()
Unlock the shared resource.
Definition: laeWd.h:429
virtual int write(uint_t addr, const byte_t buf[], size_t len)
Write to an I2C slave endpoint device.
Definition: laeI2C.cxx:194
uint_t m_addrSubProc
I2C sub-processor address.
Definition: laeWd.h:389
LaeDbConfig m_config
configuration data
Definition: laeDb.h:228
const int LaeWdMaxCmdLen
maximum command length
Definition: laeWatchDog.h:167
static const int LAE_OK
not an error, success
Definition: laelaps.h:71
int LaeWd::cmdEnableAuxPort5V ( bool  bEnable)
virtual

Enable/disable regulated 5 volt auxilliary port power out.

Parameters
bEnableDisable (false) or enable (true).
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Definition at line 759 of file laeWd.cxx.

References laelaps::LAE_ECODE_IO, laelaps::LAE_OK, laelaps::LaeWdArgAuxPort5V, laelaps::LaeWdArgDPinValHigh, laelaps::LaeWdArgDPinValLow, laelaps::LaeWdCmdIdEnableAuxPort, laelaps::LaeWdMaxCmdLen, lock(), m_addrSubProc, laelaps::LaeDbEnable::m_bAuxPort5v, m_bAuxPort5vEn, laelaps::LaeDb::m_enable, m_i2cBus, m_uFwVer, laelaps::RtDb, unlock(), and laelaps::LaeI2C::write().

Referenced by laelaps::LaeRobot::setAuxPower(), sync(), and Laelaps.WatchDog.WatchDog::sync().

760 {
761  byte_t cmd[LaeWdMaxCmdLen];
762  size_t lenCmd = 0;
763  int n;
764  int rc;
765 
766  lock();
767 
768  // old versions had no hardware control to enable power - always enabled
769  if( m_uFwVer < 2 )
770  {
771  bEnable = true;
772  rc = LAE_OK;
773  }
774 
775  // new versions control out-power to deck auxilliary ports
776  else
777  {
778  cmd[lenCmd++] = LaeWdCmdIdEnableAuxPort;
779  cmd[lenCmd++] = LaeWdArgAuxPort5V;
780  cmd[lenCmd++] = bEnable? LaeWdArgDPinValHigh: LaeWdArgDPinValLow;
781 
782  // enable/disable aux port
783  n = m_i2cBus.write(m_addrSubProc, cmd, lenCmd);
784 
785  rc = (n == (int)lenCmd)? LAE_OK: -LAE_ECODE_IO;
786  }
787 
788  if( rc == LAE_OK )
789  {
790  if( m_bAuxPort5vEn != bEnable )
791  {
792  LOGDIAG2("%s 5V aux port.", (bEnable? "Enabled": "Disabled"));
793  }
794  m_bAuxPort5vEn = bEnable;
796  }
797 
798  else
799  {
800  LOGERROR("Failed to %s 5V aux port.", (bEnable? "enable": "disable"));
801  }
802 
803  unlock();
804 
805  return rc;
806 }
void lock()
Lock the shared resource.
Definition: laeWd.h:418
static const int LAE_ECODE_IO
I/O error.
Definition: laelaps.h:98
uint_t m_uFwVer
firmware version number
Definition: laeWd.h:390
LaeDb RtDb
The real-time database.
Definition: laeDb.h:244
const byte_t LaeWdArgDPinValHigh
pin is high (Vcc)
Definition: laeWatchDog.h:124
LaeI2C & m_i2cBus
bound I2C bus instance
Definition: laeWd.h:388
void unlock()
Unlock the shared resource.
Definition: laeWd.h:429
LaeDbEnable m_enable
key gpio state data
Definition: laeDb.h:230
virtual int write(uint_t addr, const byte_t buf[], size_t len)
Write to an I2C slave endpoint device.
Definition: laeI2C.cxx:194
const byte_t LaeWdArgAuxPort5V
regulated 5 volt auxilliary port
Definition: laeWatchDog.h:386
bool m_bAuxPort5vEn
5 volt auxilliary port enable
Definition: laeWd.h:401
uint_t m_addrSubProc
I2C sub-processor address.
Definition: laeWd.h:389
const byte_t LaeWdCmdIdEnableAuxPort
command id
Definition: laeWatchDog.h:381
bool m_bAuxPort5v
5 volt auxilliary port [not] enabled
Definition: laeDb.h:123
const int LaeWdMaxCmdLen
maximum command length
Definition: laeWatchDog.h:167
static const int LAE_OK
not an error, success
Definition: laelaps.h:71
const byte_t LaeWdArgDPinValLow
pin is low (0V)
Definition: laeWatchDog.h:123
int LaeWd::cmdEnableAuxPortBatt ( bool  bEnable)
virtual

Enable/disable battery auxilliary port power out.

Parameters
bEnableDisable (false) or enable (true).
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Definition at line 808 of file laeWd.cxx.

References laelaps::LAE_ECODE_IO, laelaps::LAE_OK, laelaps::LaeWdArgAuxPortBatt, laelaps::LaeWdArgDPinValHigh, laelaps::LaeWdArgDPinValLow, laelaps::LaeWdCmdIdEnableAuxPort, laelaps::LaeWdMaxCmdLen, lock(), m_addrSubProc, laelaps::LaeDbEnable::m_bAuxPortBatt, m_bAuxPortBattEn, laelaps::LaeDb::m_enable, m_i2cBus, m_uFwVer, laelaps::RtDb, unlock(), and laelaps::LaeI2C::write().

Referenced by laelaps::LaeRobot::setAuxPower(), sync(), and Laelaps.WatchDog.WatchDog::sync().

809 {
810  byte_t cmd[LaeWdMaxCmdLen];
811  size_t lenCmd = 0;
812  int n;
813  int rc;
814 
815  lock();
816 
817  // old versions had no hardware control to enable power - always enabled
818  if( m_uFwVer < 2 )
819  {
820  bEnable = true;
821  rc = LAE_OK;
822  }
823 
824  // new versions control out-power to deck auxilliary ports
825  else
826  {
827  cmd[lenCmd++] = LaeWdCmdIdEnableAuxPort;
828  cmd[lenCmd++] = LaeWdArgAuxPortBatt;
829  cmd[lenCmd++] = bEnable? LaeWdArgDPinValHigh: LaeWdArgDPinValLow;
830 
831  // enable/disable aux port
832  n = m_i2cBus.write(m_addrSubProc, cmd, lenCmd);
833 
834  rc = (n == (int)lenCmd)? LAE_OK: -LAE_ECODE_IO;
835  }
836 
837  if( rc == LAE_OK )
838  {
839  if( m_bAuxPortBattEn != bEnable )
840  {
841  LOGDIAG2("%s battery aux port.", (bEnable? "Enabled": "Disabled"));
842  }
843  m_bAuxPortBattEn = bEnable;
845  }
846 
847  else
848  {
849  LOGERROR("Failed to %s battery aux port.", (bEnable? "enable": "disable"));
850  }
851 
852  unlock();
853 
854  return rc;
855 }
void lock()
Lock the shared resource.
Definition: laeWd.h:418
static const int LAE_ECODE_IO
I/O error.
Definition: laelaps.h:98
uint_t m_uFwVer
firmware version number
Definition: laeWd.h:390
LaeDb RtDb
The real-time database.
Definition: laeDb.h:244
const byte_t LaeWdArgDPinValHigh
pin is high (Vcc)
Definition: laeWatchDog.h:124
bool m_bAuxPortBatt
battery auxilliary port [not] enabled
Definition: laeDb.h:122
LaeI2C & m_i2cBus
bound I2C bus instance
Definition: laeWd.h:388
void unlock()
Unlock the shared resource.
Definition: laeWd.h:429
bool m_bAuxPortBattEn
battery auxilliary port enable
Definition: laeWd.h:400
LaeDbEnable m_enable
key gpio state data
Definition: laeDb.h:230
virtual int write(uint_t addr, const byte_t buf[], size_t len)
Write to an I2C slave endpoint device.
Definition: laeI2C.cxx:194
const byte_t LaeWdArgAuxPortBatt
battery auxlliary port
Definition: laeWatchDog.h:385
uint_t m_addrSubProc
I2C sub-processor address.
Definition: laeWd.h:389
const byte_t LaeWdCmdIdEnableAuxPort
command id
Definition: laeWatchDog.h:381
const int LaeWdMaxCmdLen
maximum command length
Definition: laeWatchDog.h:167
static const int LAE_OK
not an error, success
Definition: laelaps.h:71
const byte_t LaeWdArgDPinValLow
pin is low (0V)
Definition: laeWatchDog.h:123
int LaeWd::cmdEnableMotorCtlrs ( bool  bEnable)
virtual

Enable/disable power in to motor controllers.

Parameters
bEnableDisable (false) or enable (true).
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Definition at line 668 of file laeWd.cxx.

References laelaps::LAE_ECODE_IO, laelaps::LAE_OK, laelaps::LaeWdArgDPinValHigh, laelaps::LaeWdArgDPinValLow, laelaps::LaeWdArgPass, laelaps::LaeWdCmdIdEnableMotorCtlrs, laelaps::LaeWdMaxCmdLen, laelaps::LaeWdMaxRspLen, laelaps::LaeWdRspLenEnableMotorCtlrs, lock(), m_addrSubProc, laelaps::LaeDbEnable::m_bMotorCtlr, m_bMotorCtlrEn, laelaps::LaeDb::m_enable, m_i2cBus, m_timeMotorCtlrs, m_uFwVer, laelaps::RtDb, TMc, unlock(), and laelaps::LaeI2C::write_read().

Referenced by sync(), and Laelaps.WatchDog.WatchDog::sync().

669 {
670  byte_t cmd[LaeWdMaxCmdLen];
671  byte_t rsp[LaeWdMaxRspLen];
672  size_t lenCmd = 0;
673  size_t lenRsp = LaeWdRspLenEnableMotorCtlrs;
674  bool bPass;
675  int nTries;
676  int nMaxTries = 3;
677  int rc;
678 
679  lock();
680 
681  // old versions had no hardware control to enable power - always enabled
682  if( m_uFwVer < 2 )
683  {
684  bEnable = true;
685  rc = LAE_OK;
686  }
687 
688  // new versions control in-power to motor controllers
689  else
690  {
691  cmd[lenCmd++] = LaeWdCmdIdEnableMotorCtlrs;
692  cmd[lenCmd++] = bEnable? LaeWdArgDPinValHigh: LaeWdArgDPinValLow;
693 
694  // really try to set the motor controller power-in state
695  for(nTries = 0, bPass = false; (nTries < nMaxTries) && !bPass; ++nTries)
696  {
697  rc = m_i2cBus.write_read(m_addrSubProc, cmd, lenCmd, rsp, lenRsp, 5000);
698 
699  if( (rc == LAE_OK) && (rsp[0] == LaeWdArgPass) )
700  {
701  bPass = true;
702  }
703  else
704  {
705  usleep(50);
706  }
707  }
708 
709  // pass
710  if( bPass )
711  {
712  // give time for motor controllers to power up
713  if( bEnable )
714  {
715  usleep(TMc);
716  }
717 
718  rc = LAE_OK;
719  }
720 
721  // fail
722  else
723  {
724  rc = -LAE_ECODE_IO;
725  }
726  }
727 
728  if( rc == LAE_OK )
729  {
730  // disable to enable
731  if( !m_bMotorCtlrEn && bEnable)
732  {
733  LOGDIAG1("Enabled motor controllers.");
734  m_timeMotorCtlrs.markNow();
735  }
736 
737  // enable to disable
738  else if( m_bMotorCtlrEn && !bEnable )
739  {
740  double t = m_timeMotorCtlrs.now();
741  LOGDIAG1("Motor controllers disabled: Uptime: %.4lfs.",
742  t - m_timeMotorCtlrs.t());
743  }
744 
745  m_bMotorCtlrEn = bEnable;
747  }
748 
749  else
750  {
751  LOGERROR("Failed to %s motor controllers.", (bEnable? "enable": "disable"));
752  }
753 
754  unlock();
755 
756  return rc;
757 }
static long TMc
motor controller power up wait time (usec)
Definition: laeWd.cxx:106
void lock()
Lock the shared resource.
Definition: laeWd.h:418
virtual int write_read(uint_t addr, const byte_t wbuf[], size_t wlen, byte_t rbuf[], size_t rlen, long usec=0)
Perform a write/read transaction to/from an I2C slave endpoint device.
Definition: laeI2C.cxx:249
bool m_bMotorCtlrEn
motor controller enable
Definition: laeWd.h:399
const byte_t LaeWdCmdIdEnableMotorCtlrs
command id
Definition: laeWatchDog.h:365
static const int LAE_ECODE_IO
I/O error.
Definition: laelaps.h:98
const byte_t LaeWdRspLenEnableMotorCtlrs
response length (bytes)
Definition: laeWatchDog.h:367
uint_t m_uFwVer
firmware version number
Definition: laeWd.h:390
LaeDb RtDb
The real-time database.
Definition: laeDb.h:244
const byte_t LaeWdArgDPinValHigh
pin is high (Vcc)
Definition: laeWatchDog.h:124
LaeI2C & m_i2cBus
bound I2C bus instance
Definition: laeWd.h:388
void unlock()
Unlock the shared resource.
Definition: laeWd.h:429
LaeDbEnable m_enable
key gpio state data
Definition: laeDb.h:230
rnr::chronos::Time m_timeMotorCtlrs
motor controller up time
Definition: laeWd.h:404
bool m_bMotorCtlr
motor controller [not] enabled
Definition: laeDb.h:121
uint_t m_addrSubProc
I2C sub-processor address.
Definition: laeWd.h:389
const byte_t LaeWdArgPass
command success response
Definition: laeWatchDog.h:78
const int LaeWdMaxRspLen
maximum response length
Definition: laeWatchDog.h:168
const int LaeWdMaxCmdLen
maximum command length
Definition: laeWatchDog.h:167
static const int LAE_OK
not an error, success
Definition: laelaps.h:71
const byte_t LaeWdArgDPinValLow
pin is low (0V)
Definition: laeWatchDog.h:123
int LaeWd::cmdGetFwVersion ( uint_t &  uVerNum)
virtual

Get the firmware version command.

Parameters
[out]uVerNumFirmware version number.
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Definition at line 263 of file laeWd.cxx.

References laelaps::LAE_OK, laelaps::LaeWdCmdIdGetVersion, laelaps::LaeWdMaxCmdLen, laelaps::LaeWdMaxRspLen, laelaps::LaeWdRspLenGetVersion, lock(), m_addrSubProc, m_i2cBus, laelaps::LaeDb::m_product, m_uFwVer, laelaps::LaeDbProduct::m_uWatchDogFwVer, laelaps::RtDb, TStd, unlock(), and laelaps::LaeI2C::write_read().

Referenced by laelaps::LaeRobot::connWatchDog(), sync(), and Laelaps.WatchDog.WatchDog::sync().

264 {
265  byte_t cmd[LaeWdMaxCmdLen];
266  byte_t rsp[LaeWdMaxRspLen];
267  size_t lenCmd = 0;
268  size_t lenRsp = LaeWdRspLenGetVersion;
269  int rc;
270 
271  lock();
272 
273  cmd[lenCmd++] = LaeWdCmdIdGetVersion;
274 
275  rc = m_i2cBus.write_read(m_addrSubProc, cmd, lenCmd, rsp, lenRsp, TStd);
276 
277  if( rc == LAE_OK )
278  {
279  uVerNum = (uint_t)rsp[0];
280  m_uFwVer = uVerNum;
282  }
283 
284  unlock();
285 
286  return rc;
287 }
void lock()
Lock the shared resource.
Definition: laeWd.h:418
LaeDbProduct m_product
product data
Definition: laeDb.h:227
virtual int write_read(uint_t addr, const byte_t wbuf[], size_t wlen, byte_t rbuf[], size_t rlen, long usec=0)
Perform a write/read transaction to/from an I2C slave endpoint device.
Definition: laeI2C.cxx:249
static long TStd
standard wait time between write_read (usec)
Definition: laeWd.cxx:105
uint_t m_uFwVer
firmware version number
Definition: laeWd.h:390
LaeDb RtDb
The real-time database.
Definition: laeDb.h:244
const byte_t LaeWdCmdIdGetVersion
command id
Definition: laeWatchDog.h:200
LaeI2C & m_i2cBus
bound I2C bus instance
Definition: laeWd.h:388
const byte_t LaeWdRspLenGetVersion
response length (bytes)
Definition: laeWatchDog.h:202
void unlock()
Unlock the shared resource.
Definition: laeWd.h:429
uint_t m_uWatchDogFwVer
watchdog sub-processor firmware version
Definition: laeDb.h:84
uint_t m_addrSubProc
I2C sub-processor address.
Definition: laeWd.h:389
const int LaeWdMaxRspLen
maximum response length
Definition: laeWatchDog.h:168
const int LaeWdMaxCmdLen
maximum command length
Definition: laeWatchDog.h:167
static const int LAE_OK
not an error, success
Definition: laelaps.h:71
int LaeWd::cmdPetTheDog ( )
virtual

Pet the watchdog command.

Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Definition at line 215 of file laeWd.cxx.

References FWVER_UNKNOWN, laelaps::LAE_ECODE_IO, laelaps::LAE_OK, laelaps::LaeWdArgDPinValHigh, laelaps::LaeWdCmdIdPetDog, laelaps::LaeWdMaxCmdLen, laelaps::LaeWdMaxRspLen, laelaps::LaeWdRspLenPetDog_2, lock(), m_addrSubProc, laelaps::LaeDbEnergy::m_bBatteryIsCharging, m_bBatteryIsCharging, laelaps::LaeDb::m_energy, m_i2cBus, m_uFwVer, laelaps::RtDb, TStd, unlock(), laelaps::LaeI2C::write(), and laelaps::LaeI2C::write_read().

Referenced by exec(), sync(), and Laelaps.WatchDog.WatchDog::sync().

216 {
217  byte_t cmd[LaeWdMaxCmdLen];
218  byte_t rsp[LaeWdMaxRspLen];
219  size_t lenCmd = 0;
220  size_t lenRsp;
221  bool bBatteryIsCharging;
222  int n;
223  int rc;
224 
225  lock();
226 
227  cmd[lenCmd++] = LaeWdCmdIdPetDog;
228 
229  // unknown version
230  if( m_uFwVer == FWVER_UNKNOWN )
231  {
232  rc = LAE_OK;
233  }
234 
235  // version 1
236  else if( m_uFwVer <= 1 )
237  {
238  n = m_i2cBus.write(m_addrSubProc, cmd, lenCmd);
239 
240  rc = (n == (int)lenCmd)? LAE_OK: -LAE_ECODE_IO;
241  }
242 
243  // versions 2+
244  else
245  {
246  lenRsp = LaeWdRspLenPetDog_2;
247 
248  rc = m_i2cBus.write_read(m_addrSubProc, cmd, lenCmd, rsp, lenRsp, TStd);
249 
250  if( rc == LAE_OK )
251  {
252  bBatteryIsCharging = rsp[0] == LaeWdArgDPinValHigh? true: false;
253  m_bBatteryIsCharging = bBatteryIsCharging;
255  }
256  }
257 
258  unlock();
259 
260  return rc;
261 }
void lock()
Lock the shared resource.
Definition: laeWd.h:418
virtual int write_read(uint_t addr, const byte_t wbuf[], size_t wlen, byte_t rbuf[], size_t rlen, long usec=0)
Perform a write/read transaction to/from an I2C slave endpoint device.
Definition: laeI2C.cxx:249
bool m_bBatteryIsCharging
battery is [not] charging
Definition: laeWd.h:394
static long TStd
standard wait time between write_read (usec)
Definition: laeWd.cxx:105
static const int LAE_ECODE_IO
I/O error.
Definition: laelaps.h:98
bool m_bBatteryIsCharging
batteries are [not] being charged
Definition: laeDb.h:199
uint_t m_uFwVer
firmware version number
Definition: laeWd.h:390
LaeDb RtDb
The real-time database.
Definition: laeDb.h:244
const byte_t LaeWdArgDPinValHigh
pin is high (Vcc)
Definition: laeWatchDog.h:124
LaeI2C & m_i2cBus
bound I2C bus instance
Definition: laeWd.h:388
void unlock()
Unlock the shared resource.
Definition: laeWd.h:429
virtual int write(uint_t addr, const byte_t buf[], size_t len)
Write to an I2C slave endpoint device.
Definition: laeI2C.cxx:194
LaeDbEnergy m_energy
battery and energy data
Definition: laeDb.h:237
const byte_t LaeWdCmdIdPetDog
command id
Definition: laeWatchDog.h:184
uint_t m_addrSubProc
I2C sub-processor address.
Definition: laeWd.h:389
const byte_t LaeWdRspLenPetDog_2
v2 response length (bytes)
Definition: laeWatchDog.h:187
static uint_t FWVER_UNKNOWN
unknown firmware version
Definition: laeWd.cxx:103
const int LaeWdMaxRspLen
maximum response length
Definition: laeWatchDog.h:168
const int LaeWdMaxCmdLen
maximum command length
Definition: laeWatchDog.h:167
static const int LAE_OK
not an error, success
Definition: laelaps.h:71
int LaeWd::cmdReadAPin ( uint_t  pin,
uint_t &  val 
)
virtual

Read the value of an analog pin command.

Note
Deprecated in robot v2.2+ since there now exist an accessory subprocessor to support various gpio.
Parameters
pinAnalog pin number.
[out]valAnalog 10-bit value [0-1023].
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Definition at line 555 of file laeWd.cxx.

References FWVER_UNKNOWN, laelaps::LAE_ECODE_BAD_VAL, laelaps::LAE_OK, laelaps::LaeWdArgAInPinNumMax, laelaps::LaeWdArgAInPinNumMin, laelaps::LaeWdCmdIdReadAPin, laelaps::LaeWdMaxCmdLen, laelaps::LaeWdMaxRspLen, laelaps::LaeWdRspLenReadAPin, lock(), m_addrSubProc, m_i2cBus, m_uFwVer, TStd, unlock(), WD_DBG_BUF, and laelaps::LaeI2C::write_read().

Referenced by laelaps::LaeRobot::readAnalogPin().

556 {
557  byte_t cmd[LaeWdMaxCmdLen];
558  byte_t rsp[LaeWdMaxRspLen];
559  size_t lenCmd = 0;
560  size_t lenRsp = LaeWdRspLenReadAPin;
561  int rc;
562 
563  lock();
564 
565  // unknown firmware version
566  if( m_uFwVer == FWVER_UNKNOWN )
567  {
568  val = 0;
569  rc = LAE_OK;
570  }
571 
572  // deprecated
573  else if( m_uFwVer >= 3 )
574  {
575  val = 0;
576  rc = LAE_OK;
577  }
578 
579  // supported
580  else
581  {
582  if( (pin < LaeWdArgAInPinNumMin) || (pin > LaeWdArgAInPinNumMax) )
583  {
584  LOGERROR("Pin %u: Out-of-range.", pin);
585  rc = -LAE_ECODE_BAD_VAL;
586  }
587 
588  else
589  {
590  cmd[lenCmd++] = LaeWdCmdIdReadAPin;
591  cmd[lenCmd++] = (byte_t)pin;
592 
593  rc = m_i2cBus.write_read(m_addrSubProc, cmd, lenCmd, rsp, lenRsp, TStd);
594 
595  if( rc == LAE_OK )
596  {
597  if( (uint_t)rsp[0] != pin )
598  {
599  WD_DBG_BUF(LaeWdCmdIdReadAPin, rsp, n, "pin=%d rsp=", pin);
600  LOGERROR("Response pin %u != pin %u.", (uint_t)rsp[0], pin);
601  rc = -LAE_ECODE_BAD_VAL;
602  }
603  else
604  {
605  val = (uint_t)((((uint_t)rsp[1]) << 8) | (((uint_t)rsp[2]) & 0xff));
606  }
607  }
608  }
609  }
610 
611  unlock();
612 
613  return rc;
614 }
void lock()
Lock the shared resource.
Definition: laeWd.h:418
#define WD_DBG_BUF(cmd, buf, len, fmt,...)
< debug switch
Definition: laeWd.cxx:96
virtual int write_read(uint_t addr, const byte_t wbuf[], size_t wlen, byte_t rbuf[], size_t rlen, long usec=0)
Perform a write/read transaction to/from an I2C slave endpoint device.
Definition: laeI2C.cxx:249
static long TStd
standard wait time between write_read (usec)
Definition: laeWd.cxx:105
const byte_t LaeWdArgAInPinNumMax
analog input max pin number
Definition: laeWatchDog.h:130
uint_t m_uFwVer
firmware version number
Definition: laeWd.h:390
LaeI2C & m_i2cBus
bound I2C bus instance
Definition: laeWd.h:388
void unlock()
Unlock the shared resource.
Definition: laeWd.h:429
static const int LAE_ECODE_BAD_VAL
bad value general error
Definition: laelaps.h:76
uint_t m_addrSubProc
I2C sub-processor address.
Definition: laeWd.h:389
const byte_t LaeWdCmdIdReadAPin
command id
Definition: laeWatchDog.h:333
static uint_t FWVER_UNKNOWN
unknown firmware version
Definition: laeWd.cxx:103
const int LaeWdMaxRspLen
maximum response length
Definition: laeWatchDog.h:168
const int LaeWdMaxCmdLen
maximum command length
Definition: laeWatchDog.h:167
const byte_t LaeWdArgAInPinNumMin
analog input min pin number
Definition: laeWatchDog.h:129
const byte_t LaeWdRspLenReadAPin
response length (bytes)
Definition: laeWatchDog.h:335
static const int LAE_OK
not an error, success
Definition: laelaps.h:71
int LaeWd::cmdReadDPin ( uint_t  pin,
uint_t &  val 
)
virtual

Read the value of a digital pin command.

Note
Deprecated in robot v2.2+ since there now exist an accessory subprocessor to support various gpio.
Parameters
pinDigital pin number.
[out]valDigital pin low (0) or high (1) value.
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Definition at line 445 of file laeWd.cxx.

References FWVER_UNKNOWN, laelaps::LAE_ECODE_BAD_VAL, laelaps::LAE_OK, laelaps::LaeWdArgDPinNumMax, laelaps::LaeWdArgDPinNumMin, laelaps::LaeWdCmdIdReadDPin, laelaps::LaeWdMaxCmdLen, laelaps::LaeWdMaxRspLen, laelaps::LaeWdRspLenReadDPin, lock(), m_addrSubProc, m_i2cBus, m_uFwVer, TStd, unlock(), WD_DBG_BUF, and laelaps::LaeI2C::write_read().

Referenced by laelaps::LaeRobot::readDigitalPin().

446 {
447  byte_t cmd[LaeWdMaxCmdLen];
448  byte_t rsp[LaeWdMaxRspLen];
449  size_t lenCmd = 0;
450  size_t lenRsp = LaeWdRspLenReadDPin;
451  int rc;
452 
453  lock();
454 
455  // unknown firmware version
456  if( m_uFwVer == FWVER_UNKNOWN )
457  {
458  val = 0;
459  rc = LAE_OK;
460  }
461 
462  // deprecated
463  else if( m_uFwVer >= 3 )
464  {
465  val = 0;
466  rc = LAE_OK;
467  }
468 
469  // supported
470  else
471  {
472  if( (pin < LaeWdArgDPinNumMin) || (pin > LaeWdArgDPinNumMax) )
473  {
474  LOGERROR("Pin %u: Out-of-range.", pin);
475  rc = -LAE_ECODE_BAD_VAL;
476  }
477 
478  else
479  {
480  cmd[lenCmd++] = LaeWdCmdIdReadDPin;
481  cmd[lenCmd++] = (byte_t)pin;
482 
483  rc = m_i2cBus.write_read(m_addrSubProc, cmd, lenCmd, rsp, lenRsp, TStd);
484 
485  if( rc == LAE_OK )
486  {
487  if( (uint_t)rsp[0] != pin )
488  {
489  WD_DBG_BUF(LaeWdCmdIdReadDPin, rsp, n, "pin=%d rsp=", pin);
490  LOGERROR("Response pin %u != pin %u.", (uint_t)rsp[0], pin);
491  rc = -LAE_ECODE_BAD_VAL;
492  }
493  else
494  {
495  val = (uint_t)rsp[1];
496  }
497  }
498  }
499  }
500 
501  unlock();
502 
503  return rc;
504 }
void lock()
Lock the shared resource.
Definition: laeWd.h:418
#define WD_DBG_BUF(cmd, buf, len, fmt,...)
< debug switch
Definition: laeWd.cxx:96
const byte_t LaeWdArgDPinNumMin
min pin number
Definition: laeWatchDog.h:115
virtual int write_read(uint_t addr, const byte_t wbuf[], size_t wlen, byte_t rbuf[], size_t rlen, long usec=0)
Perform a write/read transaction to/from an I2C slave endpoint device.
Definition: laeI2C.cxx:249
static long TStd
standard wait time between write_read (usec)
Definition: laeWd.cxx:105
const byte_t LaeWdArgDPinNumMax
max pin number
Definition: laeWatchDog.h:118
uint_t m_uFwVer
firmware version number
Definition: laeWd.h:390
LaeI2C & m_i2cBus
bound I2C bus instance
Definition: laeWd.h:388
void unlock()
Unlock the shared resource.
Definition: laeWd.h:429
const byte_t LaeWdRspLenReadDPin
response length (bytes)
Definition: laeWatchDog.h:298
static const int LAE_ECODE_BAD_VAL
bad value general error
Definition: laelaps.h:76
uint_t m_addrSubProc
I2C sub-processor address.
Definition: laeWd.h:389
const byte_t LaeWdCmdIdReadDPin
command id
Definition: laeWatchDog.h:296
static uint_t FWVER_UNKNOWN
unknown firmware version
Definition: laeWd.cxx:103
const int LaeWdMaxRspLen
maximum response length
Definition: laeWatchDog.h:168
const int LaeWdMaxCmdLen
maximum command length
Definition: laeWatchDog.h:167
static const int LAE_OK
not an error, success
Definition: laelaps.h:71
int LaeWd::cmdReadEnables ( bool &  bMotorCtlrEn,
bool &  bAuxPort5vEn,
bool &  bAuxPortBattEn 
)
virtual

Read enable lines.

Parameters
[out]bMotorCtlrEnMotor controllers enable.
[out]bAuxPort5vEnAuxilliary port 5v out enable.
[out]bAuxPortBattEnAuxilliary port battery out enable.
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Definition at line 857 of file laeWd.cxx.

References laelaps::LAE_OK, laelaps::LaeWdCmdIdReadEnables, laelaps::LaeWdMaxCmdLen, laelaps::LaeWdMaxRspLen, laelaps::LaeWdRspLenReadEnables, lock(), m_addrSubProc, laelaps::LaeDbEnable::m_bAuxPort5v, m_bAuxPort5vEn, laelaps::LaeDbEnable::m_bAuxPortBatt, m_bAuxPortBattEn, laelaps::LaeDbEnable::m_bMotorCtlr, m_bMotorCtlrEn, laelaps::LaeDb::m_enable, m_i2cBus, m_timeMotorCtlrs, m_uFwVer, laelaps::RtDb, TStd, unlock(), and laelaps::LaeI2C::write_read().

Referenced by exec().

860 {
861  byte_t cmd[LaeWdMaxCmdLen];
862  byte_t rsp[LaeWdMaxRspLen];
863  size_t lenCmd = 0;
864  size_t lenRsp = LaeWdRspLenReadEnables;
865  int rc;
866 
867  lock();
868 
869  // old versions had no hardware control to enable power - always enabled
870  if( m_uFwVer < 2 )
871  {
872  // return values
873  bMotorCtlrEn = true;
874  bAuxPort5vEn = true;
875  bAuxPortBattEn = true;
876  rc = LAE_OK;
877  }
878 
879  // new versions control power enable lines
880  else
881  {
882  cmd[lenCmd++] = LaeWdCmdIdReadEnables;
883 
884  rc = m_i2cBus.write_read(m_addrSubProc, cmd, lenCmd, rsp, lenRsp, TStd);
885 
886  if( rc == LAE_OK )
887  {
888  // return values
889  bMotorCtlrEn = rsp[0] > 0? true: false;
890  bAuxPort5vEn = rsp[1] > 0? true: false;
891  bAuxPortBattEn = rsp[2] > 0? true: false;
892  }
893  }
894 
895  if( rc == LAE_OK )
896  {
897  // disable to enable
898  if( !m_bMotorCtlrEn && bMotorCtlrEn )
899  {
900  LOGDIAG1("Motor controllers enabled.");
901  m_timeMotorCtlrs.markNow();
902  }
903 
904  // enable to disable
905  else if( m_bMotorCtlrEn && !bMotorCtlrEn )
906  {
907  double t = m_timeMotorCtlrs.now();
908  LOGDIAG1("Motor controllers disabled: Uptime: %.4lfs.",
909  t - m_timeMotorCtlrs.t());
910  }
911 
912  // shadow
913  m_bMotorCtlrEn = bMotorCtlrEn;
914  m_bAuxPort5vEn = bAuxPort5vEn;
915  m_bAuxPortBattEn = bAuxPortBattEn;
916 
917  // real-time db
921  }
922 
923  else
924  {
925  LOGERROR("Failed to read enable lines.");
926  }
927 
928  unlock();
929 
930  return rc;
931 }
void lock()
Lock the shared resource.
Definition: laeWd.h:418
virtual int write_read(uint_t addr, const byte_t wbuf[], size_t wlen, byte_t rbuf[], size_t rlen, long usec=0)
Perform a write/read transaction to/from an I2C slave endpoint device.
Definition: laeI2C.cxx:249
static long TStd
standard wait time between write_read (usec)
Definition: laeWd.cxx:105
bool m_bMotorCtlrEn
motor controller enable
Definition: laeWd.h:399
uint_t m_uFwVer
firmware version number
Definition: laeWd.h:390
LaeDb RtDb
The real-time database.
Definition: laeDb.h:244
bool m_bAuxPortBatt
battery auxilliary port [not] enabled
Definition: laeDb.h:122
LaeI2C & m_i2cBus
bound I2C bus instance
Definition: laeWd.h:388
void unlock()
Unlock the shared resource.
Definition: laeWd.h:429
bool m_bAuxPortBattEn
battery auxilliary port enable
Definition: laeWd.h:400
LaeDbEnable m_enable
key gpio state data
Definition: laeDb.h:230
rnr::chronos::Time m_timeMotorCtlrs
motor controller up time
Definition: laeWd.h:404
bool m_bAuxPort5vEn
5 volt auxilliary port enable
Definition: laeWd.h:401
bool m_bMotorCtlr
motor controller [not] enabled
Definition: laeDb.h:121
uint_t m_addrSubProc
I2C sub-processor address.
Definition: laeWd.h:389
bool m_bAuxPort5v
5 volt auxilliary port [not] enabled
Definition: laeDb.h:123
const int LaeWdMaxRspLen
maximum response length
Definition: laeWatchDog.h:168
const byte_t LaeWdCmdIdReadEnables
command id
Definition: laeWatchDog.h:401
const byte_t LaeWdRspLenReadEnables
response length (bytes)
Definition: laeWatchDog.h:403
const int LaeWdMaxCmdLen
maximum command length
Definition: laeWatchDog.h:167
static const int LAE_OK
not an error, success
Definition: laelaps.h:71
int LaeWd::cmdReadVoltages ( double &  fJackV,
double &  fBattV 
)
virtual

Read sensed voltages.

Parameters
[out]fJackVSensed charging jack input voltage.
[out]fBattVSensed battery output voltage.
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Definition at line 933 of file laeWd.cxx.

References laelaps::LAE_OK, laelaps::LaeWdArgVScale, laelaps::LaeWdCmdIdReadVolts, laelaps::LaeWdMaxCmdLen, laelaps::LaeWdMaxRspLen, laelaps::LaeWdRspLenReadVolts, lock(), m_addrSubProc, laelaps::LaeDb::m_energy, laelaps::LaeDbEnergy::m_fBatteryVoltage, m_fBatteryVoltage, laelaps::LaeDbEnergy::m_fJackVoltage, m_fJackVoltage, m_i2cBus, m_uFwVer, laelaps::RtDb, TStd, unlock(), and laelaps::LaeI2C::write_read().

Referenced by exec(), and sync().

934 {
935  byte_t cmd[LaeWdMaxCmdLen];
936  byte_t rsp[LaeWdMaxRspLen];
937  size_t lenCmd = 0;
938  size_t lenRsp = LaeWdRspLenReadVolts;
939  int rc;
940 
941  lock();
942 
943  // old versions had no hardware to sense voltages
944  if( m_uFwVer < 2 )
945  {
946  fJackV = 0.0;
947  fBattV = 0.0;
948  rc = LAE_OK;
949  }
950 
951  // new versions can sense input jack and battery output voltages
952  else
953  {
954  cmd[lenCmd++] = LaeWdCmdIdReadVolts;
955 
956  rc = m_i2cBus.write_read(m_addrSubProc, cmd, lenCmd, rsp, lenRsp, TStd);
957 
958  if( rc == LAE_OK )
959  {
960  fJackV = (double)(rsp[0]) * LaeWdArgVScale;
961  fBattV = (double)(rsp[1]) * LaeWdArgVScale;
962  }
963  }
964 
965  if( rc == LAE_OK )
966  {
967  m_fBatteryVoltage = fBattV;
968  m_fJackVoltage = fJackV;
969 
972  }
973 
974  else
975  {
976  LOGERROR("Failed to read voltages.");
977  }
978 
979  unlock();
980 
981  return rc;
982 }
const byte_t LaeWdCmdIdReadVolts
command id
Definition: laeWatchDog.h:425
void lock()
Lock the shared resource.
Definition: laeWd.h:418
virtual int write_read(uint_t addr, const byte_t wbuf[], size_t wlen, byte_t rbuf[], size_t rlen, long usec=0)
Perform a write/read transaction to/from an I2C slave endpoint device.
Definition: laeI2C.cxx:249
static long TStd
standard wait time between write_read (usec)
Definition: laeWd.cxx:105
double m_fJackVoltage
sensed power supply jack voltage
Definition: laeWd.h:396
const float LaeWdArgVScale
voltage scaler
Definition: laeWatchDog.h:430
double m_fBatteryVoltage
sensed battery subsystem voltage (V)
Definition: laeDb.h:201
uint_t m_uFwVer
firmware version number
Definition: laeWd.h:390
LaeDb RtDb
The real-time database.
Definition: laeDb.h:244
LaeI2C & m_i2cBus
bound I2C bus instance
Definition: laeWd.h:388
void unlock()
Unlock the shared resource.
Definition: laeWd.h:429
double m_fBatteryVoltage
sensed battery voltage
Definition: laeWd.h:395
LaeDbEnergy m_energy
battery and energy data
Definition: laeDb.h:237
double m_fJackVoltage
sensed power supply jack voltage
Definition: laeDb.h:200
uint_t m_addrSubProc
I2C sub-processor address.
Definition: laeWd.h:389
const int LaeWdMaxRspLen
maximum response length
Definition: laeWatchDog.h:168
const int LaeWdMaxCmdLen
maximum command length
Definition: laeWatchDog.h:167
const byte_t LaeWdRspLenReadVolts
response length (bytes)
Definition: laeWatchDog.h:427
static const int LAE_OK
not an error, success
Definition: laelaps.h:71
int LaeWd::cmdResetRgbLed ( )
virtual

Reset the LED RGB color to state defaults.

Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Definition at line 376 of file laeWd.cxx.

References laelaps::LAE_ECODE_IO, laelaps::LAE_OK, laelaps::LaeWdCmdIdResetRgbLed, laelaps::LaeWdMaxCmdLen, lock(), m_addrSubProc, m_i2cBus, unlock(), and laelaps::LaeI2C::write().

Referenced by sync(), and Laelaps.WatchDog.WatchDog::sync().

377 {
378  byte_t cmd[LaeWdMaxCmdLen];
379  size_t lenCmd = 0;
380  int n;
381  int rc;
382 
383  lock();
384 
385  cmd[lenCmd++] = LaeWdCmdIdResetRgbLed;
386 
387  n = m_i2cBus.write(m_addrSubProc, cmd, lenCmd);
388 
389  rc = (n == (int)lenCmd)? LAE_OK: -LAE_ECODE_IO;
390 
391  unlock();
392 
393  return rc;
394 }
void lock()
Lock the shared resource.
Definition: laeWd.h:418
static const int LAE_ECODE_IO
I/O error.
Definition: laelaps.h:98
LaeI2C & m_i2cBus
bound I2C bus instance
Definition: laeWd.h:388
void unlock()
Unlock the shared resource.
Definition: laeWd.h:429
virtual int write(uint_t addr, const byte_t buf[], size_t len)
Write to an I2C slave endpoint device.
Definition: laeI2C.cxx:194
uint_t m_addrSubProc
I2C sub-processor address.
Definition: laeWd.h:389
const byte_t LaeWdCmdIdResetRgbLed
command id
Definition: laeWatchDog.h:260
const int LaeWdMaxCmdLen
maximum command length
Definition: laeWatchDog.h:167
static const int LAE_OK
not an error, success
Definition: laelaps.h:71
int LaeWd::cmdSetAlarms ( uint_t  uAlarms)
virtual

Set (clear) alarms command.

Parameters
uAlarmsBit-or'ed alarm state.
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Definition at line 323 of file laeWd.cxx.

References laelaps::LAE_ECODE_IO, laelaps::LAE_OK, laelaps::LaeWdCmdIdSetAlarms, laelaps::LaeWdMaxCmdLen, lock(), m_addrSubProc, m_i2cBus, m_uAlarms, unlock(), and laelaps::LaeI2C::write().

Referenced by exec(), sync(), and Laelaps.WatchDog.WatchDog::sync().

324 {
325  byte_t cmd[LaeWdMaxCmdLen];
326  size_t lenCmd = 0;
327  int n;
328  int rc;
329 
330  lock();
331 
332  cmd[lenCmd++] = LaeWdCmdIdSetAlarms;
333  cmd[lenCmd++] = (byte_t)((uAlarms >> 8) & 0xff);
334  cmd[lenCmd++] = (byte_t)(uAlarms & 0xff);
335 
336  n = m_i2cBus.write(m_addrSubProc, cmd, lenCmd);
337 
338  if( n == (int)lenCmd )
339  {
340  m_uAlarms = uAlarms;
341  rc = LAE_OK;
342  }
343  else
344  {
345  rc = -LAE_ECODE_IO;
346  }
347 
348  unlock();
349 
350  return rc;
351 }
void lock()
Lock the shared resource.
Definition: laeWd.h:418
uint_t m_uAlarms
alarms
Definition: laeWd.h:398
static const int LAE_ECODE_IO
I/O error.
Definition: laelaps.h:98
LaeI2C & m_i2cBus
bound I2C bus instance
Definition: laeWd.h:388
void unlock()
Unlock the shared resource.
Definition: laeWd.h:429
virtual int write(uint_t addr, const byte_t buf[], size_t len)
Write to an I2C slave endpoint device.
Definition: laeI2C.cxx:194
const byte_t LaeWdCmdIdSetAlarms
command id
Definition: laeWatchDog.h:231
uint_t m_addrSubProc
I2C sub-processor address.
Definition: laeWd.h:389
const int LaeWdMaxCmdLen
maximum command length
Definition: laeWatchDog.h:167
static const int LAE_OK
not an error, success
Definition: laelaps.h:71
int LaeWd::cmdSetBatterySoC ( uint_t  uBatterySoC)
virtual

Set battery's state of charge state command.

Parameters
uBatterySoCBattery state of charge as a percent [0-100].
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Definition at line 289 of file laeWd.cxx.

References laelaps::LAE_ECODE_IO, laelaps::LAE_OK, laelaps::LaeWdArgBattSoCMax, laelaps::LaeWdCmdIdSetBattCharge, laelaps::LaeWdMaxCmdLen, lock(), m_addrSubProc, m_i2cBus, m_uBatterySoC, unlock(), and laelaps::LaeI2C::write().

Referenced by exec(), sync(), and Laelaps.WatchDog.WatchDog::sync().

290 {
291  byte_t cmd[LaeWdMaxCmdLen];
292  size_t lenCmd = 0;
293  int n;
294  int rc;
295 
296  lock();
297 
298  if( uBatterySoC > LaeWdArgBattSoCMax )
299  {
300  uBatterySoC = LaeWdArgBattSoCMax;
301  }
302 
303  cmd[lenCmd++] = LaeWdCmdIdSetBattCharge;
304  cmd[lenCmd++] = (byte_t)uBatterySoC;
305 
306  n = m_i2cBus.write(m_addrSubProc, cmd, lenCmd);
307 
308  if( n == (int)lenCmd )
309  {
310  m_uBatterySoC = uBatterySoC;
311  rc = LAE_OK;
312  }
313  else
314  {
315  rc = -LAE_ECODE_IO;
316  }
317 
318  unlock();
319 
320  return rc;
321 }
void lock()
Lock the shared resource.
Definition: laeWd.h:418
uint_t m_uBatterySoC
battery state of charge
Definition: laeWd.h:397
static const int LAE_ECODE_IO
I/O error.
Definition: laelaps.h:98
const unsigned int LaeWdArgBattSoCMax
100% charge
Definition: laeWatchDog.h:91
LaeI2C & m_i2cBus
bound I2C bus instance
Definition: laeWd.h:388
const byte_t LaeWdCmdIdSetBattCharge
command id
Definition: laeWatchDog.h:215
void unlock()
Unlock the shared resource.
Definition: laeWd.h:429
virtual int write(uint_t addr, const byte_t buf[], size_t len)
Write to an I2C slave endpoint device.
Definition: laeI2C.cxx:194
uint_t m_addrSubProc
I2C sub-processor address.
Definition: laeWd.h:389
const int LaeWdMaxCmdLen
maximum command length
Definition: laeWatchDog.h:167
static const int LAE_OK
not an error, success
Definition: laelaps.h:71
int LaeWd::cmdSetRgbLed ( uint_t  red,
uint_t  green,
uint_t  blue 
)
virtual

Set the LED RGB color command.

Parameters
redRed component [0-255].
greenGreen component [0-255].
blueBlue component [0-255].
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Definition at line 353 of file laeWd.cxx.

References laelaps::LAE_ECODE_IO, laelaps::LAE_OK, laelaps::LaeWdCmdIdSetRgbLed, laelaps::LaeWdMaxCmdLen, lock(), m_addrSubProc, m_i2cBus, unlock(), and laelaps::LaeI2C::write().

354 {
355  byte_t cmd[LaeWdMaxCmdLen];
356  size_t lenCmd = 0;
357  int n;
358  int rc;
359 
360  lock();
361 
362  cmd[lenCmd++] = LaeWdCmdIdSetRgbLed;
363  cmd[lenCmd++] = (byte_t)red;
364  cmd[lenCmd++] = (byte_t)green;
365  cmd[lenCmd++] = (byte_t)blue;
366 
367  n = m_i2cBus.write(m_addrSubProc, cmd, lenCmd);
368 
369  rc = (n == (int)lenCmd)? LAE_OK: -LAE_ECODE_IO;
370 
371  unlock();
372 
373  return rc;
374 }
void lock()
Lock the shared resource.
Definition: laeWd.h:418
const byte_t LaeWdCmdIdSetRgbLed
command id
Definition: laeWatchDog.h:248
static const int LAE_ECODE_IO
I/O error.
Definition: laelaps.h:98
LaeI2C & m_i2cBus
bound I2C bus instance
Definition: laeWd.h:388
void unlock()
Unlock the shared resource.
Definition: laeWd.h:429
virtual int write(uint_t addr, const byte_t buf[], size_t len)
Write to an I2C slave endpoint device.
Definition: laeI2C.cxx:194
uint_t m_addrSubProc
I2C sub-processor address.
Definition: laeWd.h:389
const int LaeWdMaxCmdLen
maximum command length
Definition: laeWatchDog.h:167
static const int LAE_OK
not an error, success
Definition: laelaps.h:71
int LaeWd::cmdTest ( uint_t &  uSeqNum,
uint_t &  uOpState,
uint_t &  uAlarms,
uint_t &  uLedIndex 
)
virtual

Test the firmware state command.

Parameters
[out]uSeqNumThis command's sequence number modulo 256.
[out]uOpStateFirmware's operational state.
[out]uAlarmsFirmware's view of alarms.
[out]uLedIndexFirmware's current LED pattern index.
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Definition at line 984 of file laeWd.cxx.

References FWVER_UNKNOWN, laelaps::LAE_OK, laelaps::LaeWdCmdIdTest, laelaps::LaeWdMaxCmdLen, laelaps::LaeWdMaxRspLen, laelaps::LaeWdRspLenTest, lock(), m_addrSubProc, m_i2cBus, m_uFwVer, TStd, unlock(), and laelaps::LaeI2C::write_read().

988 {
989  byte_t cmd[LaeWdMaxCmdLen];
990  byte_t rsp[LaeWdMaxRspLen];
991  size_t lenCmd = 0;
992  size_t lenRsp = LaeWdRspLenTest;
993  int rc;
994 
995  lock();
996 
997  // old versions had a test command - deprecated
998  if( (m_uFwVer != FWVER_UNKNOWN) && (m_uFwVer < 3) )
999  {
1000  cmd[lenCmd++] = LaeWdCmdIdTest;
1001 
1002  rc = m_i2cBus.write_read(m_addrSubProc, cmd, lenCmd, rsp, lenRsp, TStd);
1003 
1004  if( rc == LAE_OK )
1005  {
1006  uSeqNum = (uint_t)rsp[0];
1007  uOpState = (uint_t)rsp[1];
1008  uAlarms = (uint_t)((((uint_t)rsp[2]) << 8) | (((uint_t)rsp[3]) & 0xff));
1009  uLedIndex = (uint_t)rsp[4];
1010  }
1011  }
1012 
1013  // deprecated
1014  else
1015  {
1016  uSeqNum = 0;
1017  uOpState = 0;
1018  uAlarms = 0;
1019  uLedIndex = 0;
1020  rc = LAE_OK;
1021  }
1022 
1023  unlock();
1024 
1025  return rc;
1026 }
void lock()
Lock the shared resource.
Definition: laeWd.h:418
virtual int write_read(uint_t addr, const byte_t wbuf[], size_t wlen, byte_t rbuf[], size_t rlen, long usec=0)
Perform a write/read transaction to/from an I2C slave endpoint device.
Definition: laeI2C.cxx:249
static long TStd
standard wait time between write_read (usec)
Definition: laeWd.cxx:105
const byte_t LaeWdCmdIdTest
command id
Definition: laeWatchDog.h:450
uint_t m_uFwVer
firmware version number
Definition: laeWd.h:390
const byte_t LaeWdRspLenTest
v1 response length (bytes)
Definition: laeWatchDog.h:452
LaeI2C & m_i2cBus
bound I2C bus instance
Definition: laeWd.h:388
void unlock()
Unlock the shared resource.
Definition: laeWd.h:429
uint_t m_addrSubProc
I2C sub-processor address.
Definition: laeWd.h:389
static uint_t FWVER_UNKNOWN
unknown firmware version
Definition: laeWd.cxx:103
const int LaeWdMaxRspLen
maximum response length
Definition: laeWatchDog.h:168
const int LaeWdMaxCmdLen
maximum command length
Definition: laeWatchDog.h:167
static const int LAE_OK
not an error, success
Definition: laelaps.h:71
int LaeWd::cmdWriteAPin ( uint_t  pin,
uint_t  val 
)
virtual

Write the value to an analog pin command.

Note
Deprecated in robot v2.2+ since there now exist an accessory subprocessor to support various gpio.
Parameters
pinAnalog pin number.
valAnalog 10-bit value [0-1023].
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Definition at line 616 of file laeWd.cxx.

References FWVER_UNKNOWN, laelaps::LAE_ECODE_BAD_VAL, laelaps::LAE_ECODE_IO, laelaps::LAE_OK, laelaps::LaeWdArgAOutPinNumMax, laelaps::LaeWdArgAOutPinNumMin, laelaps::LaeWdArgAOutPinValMax, laelaps::LaeWdCmdIdWriteAPin, laelaps::LaeWdMaxCmdLen, lock(), m_addrSubProc, m_i2cBus, m_uFwVer, unlock(), and laelaps::LaeI2C::write().

617 {
618  byte_t cmd[LaeWdMaxCmdLen];
619  size_t lenCmd = 0;
620  int n;
621  int rc;
622 
623  lock();
624 
625  // unknown firmware version
626  if( m_uFwVer == FWVER_UNKNOWN )
627  {
628  rc = LAE_OK;
629  }
630 
631  // deprecated
632  else if( m_uFwVer >= 3 )
633  {
634  rc = LAE_OK;
635  }
636 
637  // supported
638  else
639  {
640  if( (pin < LaeWdArgAOutPinNumMin) || (pin > LaeWdArgAOutPinNumMax) )
641  {
642  LOGERROR("Pin %u: Out-of-range.", pin);
643  rc = -LAE_ECODE_BAD_VAL;
644  }
645 
646  else
647  {
648  if( val > LaeWdArgAOutPinValMax )
649  {
650  val = LaeWdArgAOutPinValMax;
651  }
652 
653  cmd[lenCmd++] = LaeWdCmdIdWriteAPin;
654  cmd[lenCmd++] = (byte_t)pin;
655  cmd[lenCmd++] = (byte_t)val;
656 
657  n = m_i2cBus.write(m_addrSubProc, cmd, lenCmd);
658 
659  rc = (n == (int)lenCmd)? LAE_OK: -LAE_ECODE_IO;
660  }
661  }
662 
663  unlock();
664 
665  return rc;
666 }
void lock()
Lock the shared resource.
Definition: laeWd.h:418
const int LaeWdArgAOutPinValMax
analog output maximum value
Definition: laeWatchDog.h:139
const byte_t LaeWdArgAOutPinNumMin
analog output min pin number
Definition: laeWatchDog.h:135
static const int LAE_ECODE_IO
I/O error.
Definition: laelaps.h:98
uint_t m_uFwVer
firmware version number
Definition: laeWd.h:390
LaeI2C & m_i2cBus
bound I2C bus instance
Definition: laeWd.h:388
void unlock()
Unlock the shared resource.
Definition: laeWd.h:429
virtual int write(uint_t addr, const byte_t buf[], size_t len)
Write to an I2C slave endpoint device.
Definition: laeI2C.cxx:194
const byte_t LaeWdArgAOutPinNumMax
analog output max pin number
Definition: laeWatchDog.h:136
const byte_t LaeWdCmdIdWriteAPin
command id
Definition: laeWatchDog.h:349
static const int LAE_ECODE_BAD_VAL
bad value general error
Definition: laelaps.h:76
uint_t m_addrSubProc
I2C sub-processor address.
Definition: laeWd.h:389
static uint_t FWVER_UNKNOWN
unknown firmware version
Definition: laeWd.cxx:103
const int LaeWdMaxCmdLen
maximum command length
Definition: laeWatchDog.h:167
static const int LAE_OK
not an error, success
Definition: laelaps.h:71
int LaeWd::cmdWriteDPin ( uint_t  pin,
uint_t  val 
)
virtual

Write a value to a digital pin command.

Note
Deprecated in robot v2.2+ since there now exist an accessory subprocessor to support various gpio.
Parameters
pinDigital pin number.
valDigital pin low (0) or high (1) value.
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Definition at line 506 of file laeWd.cxx.

References FWVER_UNKNOWN, laelaps::LAE_ECODE_BAD_VAL, laelaps::LAE_ECODE_IO, laelaps::LAE_OK, laelaps::LaeWdArgDPinNumWMax, laelaps::LaeWdArgDPinNumWMin, laelaps::LaeWdArgDPinValHigh, laelaps::LaeWdArgDPinValLow, laelaps::LaeWdCmdIdWriteDPin, laelaps::LaeWdMaxCmdLen, lock(), m_addrSubProc, m_i2cBus, m_uFwVer, unlock(), and laelaps::LaeI2C::write().

Referenced by laelaps::LaeRobot::writeDigitalPin().

507 {
508  byte_t cmd[LaeWdMaxCmdLen];
509  size_t lenCmd = 0;
510  int n;
511  int rc;
512 
513  lock();
514 
515  // unknown firmware version
516  if( m_uFwVer == FWVER_UNKNOWN )
517  {
518  rc = LAE_OK;
519  }
520 
521  // deprecated
522  else if( m_uFwVer >= 3 )
523  {
524  rc = LAE_OK;
525  }
526 
527  // supported
528  else
529  {
530  if( (pin < LaeWdArgDPinNumWMin) || (pin > LaeWdArgDPinNumWMax) )
531  {
532  LOGERROR("Pin %u: Out-of-range.", pin);
533  rc = -LAE_ECODE_BAD_VAL;
534  }
535 
536  else
537  {
538  val = val > 0? LaeWdArgDPinValHigh: LaeWdArgDPinValLow;
539 
540  cmd[lenCmd++] = LaeWdCmdIdWriteDPin;
541  cmd[lenCmd++] = (byte_t)pin;
542  cmd[lenCmd++] = (byte_t)val;
543 
544  n = m_i2cBus.write(m_addrSubProc, cmd, lenCmd);
545 
546  rc = (n == (int)lenCmd)? LAE_OK: -LAE_ECODE_IO;
547  }
548  }
549 
550  unlock();
551 
552  return rc;
553 }
void lock()
Lock the shared resource.
Definition: laeWd.h:418
static const int LAE_ECODE_IO
I/O error.
Definition: laelaps.h:98
uint_t m_uFwVer
firmware version number
Definition: laeWd.h:390
const byte_t LaeWdArgDPinValHigh
pin is high (Vcc)
Definition: laeWatchDog.h:124
LaeI2C & m_i2cBus
bound I2C bus instance
Definition: laeWd.h:388
void unlock()
Unlock the shared resource.
Definition: laeWd.h:429
virtual int write(uint_t addr, const byte_t buf[], size_t len)
Write to an I2C slave endpoint device.
Definition: laeI2C.cxx:194
const byte_t LaeWdCmdIdWriteDPin
command id
Definition: laeWatchDog.h:314
const byte_t LaeWdArgDPinNumWMax
max write/modify pin number
Definition: laeWatchDog.h:117
const byte_t LaeWdArgDPinNumWMin
min write/modify pin number
Definition: laeWatchDog.h:116
static const int LAE_ECODE_BAD_VAL
bad value general error
Definition: laelaps.h:76
uint_t m_addrSubProc
I2C sub-processor address.
Definition: laeWd.h:389
static uint_t FWVER_UNKNOWN
unknown firmware version
Definition: laeWd.cxx:103
const int LaeWdMaxCmdLen
maximum command length
Definition: laeWatchDog.h:167
static const int LAE_OK
not an error, success
Definition: laelaps.h:71
const byte_t LaeWdArgDPinValLow
pin is low (0V)
Definition: laeWatchDog.h:123
int LaeWd::configure ( const LaeDesc desc)
virtual

Configure watchdog from product description.

Call after connection is opened.

Parameters
descProduct description.
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Definition at line 159 of file laeWd.cxx.

References laelaps::LAE_OK.

Referenced by laelaps::LaeRobot::configForOperation(), and reload().

160 {
161  return LAE_OK;
162 }
static const int LAE_OK
not an error, success
Definition: laelaps.h:71
int LaeWd::configure ( const LaeTunes tunes)
virtual

Configure watchdog from tunable parameters.

Call after connection is opened.

Parameters
tunesLaelaps tuning parameters.
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Definition at line 164 of file laeWd.cxx.

References cmdConfigOperation(), laelaps::LaeTunes::getWatchDogTimeout(), and laelaps::LAE_OK.

165 {
166  unsigned long uTimeout;
167  int rc;
168 
169  // convert to milliseconds
170  uTimeout = (unsigned long)(tunes.getWatchDogTimeout() * 1000.0);
171 
172  rc = cmdConfigOperation(uTimeout);
173 
174  if( rc == LAE_OK )
175  {
176  LOGDIAG2("Tuned WatchDog.");
177  }
178 
179  return rc;
180 }
double getWatchDogTimeout() const
Get watchdog timeout (seconds).
Definition: laeTune.cxx:334
virtual int cmdConfigOperation(unsigned long uTimeout)
Configure firmware operation.
Definition: laeWd.cxx:1028
static const int LAE_OK
not an error, success
Definition: laelaps.h:71
uint_t LaeWd::determineAlarms ( )
protected

Determine watchdog alarm state.

The current real-time database alarm state is used for the determination.

Returns
Watchdog alarm state.

Definition at line 1073 of file laeWd.cxx.

References laelaps::LAE_ALARM_BATT, laelaps::LAE_ALARM_ESTOP, laelaps::LAE_ALARM_TEMP, laelaps::LaeWdArgAlarmBatt, laelaps::LaeWdArgAlarmBattCrit, laelaps::LaeWdArgAlarmCrit, laelaps::LaeWdArgAlarmEStop, laelaps::LaeWdArgAlarmGen, laelaps::LaeWdArgAlarmNone, laelaps::LaeWdArgAlarmTemp, laelaps::LaeDb::m_alarms, laelaps::LaeDbAlarms::m_battery, laelaps::LaeAlarmInfo::m_bIsCritical, laelaps::LaeDbAlarms::m_system, laelaps::LaeAlarmInfo::m_uAlarms, and laelaps::RtDb.

Referenced by exec(), and unlock().

1074 {
1075  uint_t uAlarms = LaeWdArgAlarmNone;
1076 
1077  //
1078  // Alarms.
1079  //
1081  {
1082  uAlarms |= LaeWdArgAlarmBatt;
1083  }
1085  {
1086  uAlarms |= LaeWdArgAlarmTemp;
1087  }
1089  {
1090  uAlarms |= LaeWdArgAlarmEStop;
1091  }
1092  if( RtDb.m_alarms.m_system.m_uAlarms & ~uAlarms )
1093  {
1094  uAlarms |= LaeWdArgAlarmGen;
1095  }
1096 
1097  //
1098  // Critical.
1099  //
1101  (uAlarms & ~((uint_t)LaeWdArgAlarmBatt)) )
1102  {
1103  uAlarms |= LaeWdArgAlarmCrit;
1104  }
1106  {
1107  uAlarms |= LaeWdArgAlarmBattCrit;
1108  }
1109 
1110  return uAlarms;
1111 }
const unsigned int LaeWdArgAlarmCrit
crit alarm modifier
Definition: laeWatchDog.h:102
const unsigned int LaeWdArgAlarmEStop
emergency stop
Definition: laeWatchDog.h:100
LaeAlarmInfo m_battery
battery subsystem alarm state
Definition: laeDb.h:213
LaeDb RtDb
The real-time database.
Definition: laeDb.h:244
LaeAlarmInfo m_system
system alarm summary state
Definition: laeDb.h:212
bool m_bIsCritical
is [not] critical alarm
Definition: laeAlarms.h:159
const unsigned int LaeWdArgAlarmBatt
battery low alarm
Definition: laeWatchDog.h:98
const unsigned int LaeWdArgAlarmNone
no/clear alarms
Definition: laeWatchDog.h:96
const unsigned int LaeWdArgAlarmBattCrit
batt crit modifier
Definition: laeWatchDog.h:101
static const u32_t LAE_ALARM_TEMP
temperature alarm
Definition: laeAlarms.h:82
u32_t m_uAlarms
alarm or&#39;ed bits
Definition: laeAlarms.h:160
static const u32_t LAE_ALARM_ESTOP
emergency stop
Definition: laeAlarms.h:80
static const u32_t LAE_ALARM_BATT
battery low alarm
Definition: laeAlarms.h:81
const unsigned int LaeWdArgAlarmTemp
temperature alarm
Definition: laeWatchDog.h:99
LaeDbAlarms m_alarms
alarm state data
Definition: laeDb.h:238
const unsigned int LaeWdArgAlarmGen
general alarm
Definition: laeWatchDog.h:97
int LaeWd::enableMotorCtlrs ( void *  pArg,
bool  bEnable 
)
static

Enable/disable power in to motor controllers.

Parameters
pArgRecast pointer to this class instance.
bEnableDisable (false) or enable (true).
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Definition at line 1117 of file laeWd.cxx.

Referenced by laelaps::LaeRobot::connMotorControllers().

1118 {
1119  return ((LaeWd *)pArg)->cmdEnableMotorCtlrs(bEnable);
1120 }
uint_t laelaps::LaeWd::getFwVersion ( )
inline

Get previously read firmware version.

Returns
Firmware version number.

Definition at line 371 of file laeWd.h.

References m_uFwVer.

372  {
373  return m_uFwVer;
374  }
uint_t m_uFwVer
firmware version number
Definition: laeWd.h:390
uint_t laelaps::LaeWd::getI2CAddr ( )
inline

Get watchdog's I2C address.

Returns
7-bit address.

Definition at line 361 of file laeWd.h.

References m_addrSubProc.

362  {
363  return m_addrSubProc;
364  }
uint_t m_addrSubProc
I2C sub-processor address.
Definition: laeWd.h:389
bool laelaps::LaeWd::isCharging ( )
inline

Test if battery is charging.

Returns
Returns true or false.

Definition at line 381 of file laeWd.h.

References m_bBatteryIsCharging.

382  {
383  return m_bBatteryIsCharging;
384  }
bool m_bBatteryIsCharging
battery is [not] charging
Definition: laeWd.h:394
void laelaps::LaeWd::lock ( )
inlineprotected

Lock the shared resource.

The lock()/unlock() primitives provide a safe threading. registered vServo data.

Context:
Any.

Definition at line 418 of file laeWd.h.

Referenced by cmdConfigDPin(), cmdConfigOperation(), cmdEnableAuxPort5V(), cmdEnableAuxPortBatt(), cmdEnableMotorCtlrs(), cmdGetFwVersion(), cmdPetTheDog(), cmdReadAPin(), cmdReadDPin(), cmdReadEnables(), cmdReadVoltages(), cmdResetRgbLed(), cmdSetAlarms(), cmdSetBatterySoC(), cmdSetRgbLed(), cmdTest(), cmdWriteAPin(), and cmdWriteDPin().

419  {
420  pthread_mutex_lock(&m_mutex);
421  }
pthread_mutex_t m_mutex
mutex
Definition: laeWd.h:407
int LaeWd::reload ( const LaeTunes tunes)
virtual

Reload with new configuration.

Parameters
tunesLaelaps tuning parameters.
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Definition at line 182 of file laeWd.cxx.

References configure().

Referenced by laelaps::LaeThreadWd::reload().

183 {
184  LOGDIAG2("Reloading WatchDog tuning parameters...");
185  return configure(tunes);
186 }
virtual int configure(const LaeDesc &desc)
Configure watchdog from product description.
Definition: laeWd.cxx:159
void laelaps::LaeWd::unlock ( )
inlineprotected

The documentation for this class was generated from the following files: