77 _WDErrMsgOpen = 
'No open I2C bus device.'    94     self.
m_addr   = LaeI2CAddrArduino
   100         'battery_is_charging':
False,
   101         'battery_soc':        LaeWdArgBattChargeMax,
   102         'alarms':             LaeWdArgAlarmNone,
   103         'rgb':                {
'override': 
False, 
'red':0, 
'green':0, 
'blue':0},
   106         'enables':            {
'motor_ctlr_en': 
False,
   107                                'aux_port_batt_en': 
False,
   108                                'aux_port_5v_en': 
False},
   109         'voltages':           {
'jack': 0.0, 
'batt': 0.0} }
   111     for pin 
in range(LaeWdArgDPinNumMin, LaeWdArgDPinNumMax+1):
   112       self.
m_fw[
'digital'][pin] = {
'dir': LaeWdArgDPinDirIn, 
'val': 0}
   114     for pin 
in range(LaeWdArgAInPinNumMin, LaeWdArgAInPinNumMax+1):
   115       self.
m_fw[
'analog'][pin] = {
'dir': LaeWdArgDPinDirIn, 
'val': 0}
   137       self.
m_i2c = i2c.i2c()
   138       self.m_i2c.open(devName)
   139     except i2c.I2CException, inst:
   153     if self.
m_i2c is None:
   155     elif not self.m_i2c.is_open():
   167     if self.
m_i2c is None:
   170       return self.m_i2c.is_open()
   201     cmdId = LaeWdCmdIdPetDog
   203     key = 
'battery_is_charging'   204     ret = {
'rc': WDRcOk, key: self.
m_fw[key]}
   215     if self.
m_fw[
'version'] <= 1:
   217         self.m_i2c.write(self.
m_addr, cmd)
   218       except i2c.I2CException, inst:
   219         self.
printError(
"CmdId %d" % (cmdId), inst.message)
   222       rspLen = LaeWdRspLenPetDog_2
   224         rsp = self.m_i2c.write_read(self.
m_addr, cmd, rspLen)
   225       except i2c.I2CException, inst:
   226         self.
printError(
"CmdId %d" % (cmdId), inst.message)
   229         if len(rsp) == rspLen:
   231             self.
m_fw[key] = 
True   233             self.
m_fw[key] = 
False   234           ret[key] = self.
m_fw[key]
   244     cmdId   = LaeWdCmdIdGetVersion
   245     rspLen  = LaeWdRspLenGetVersion
   248     ret = {
'rc': WDRcOk, key: self.
m_fw[key]}
   260       rsp = self.m_i2c.write_read(self.
m_addr, cmd, rspLen)
   261     except i2c.I2CException, inst:
   262       self.
printError(
"CmdId %d" % (cmdId), inst.message)
   265       if len(rsp) == rspLen:
   266         self.
m_fw[key] = ord(rsp[0])
   267         ret[key] = self.
m_fw[key]
   279     cmdId = LaeWdCmdIdSetAlarms
   282     ret = {
'rc': WDRcOk, key: self.
m_fw[key]}
   290     if soc < LaeWdArgBattChargeMin:
   291       soc = LaeWdArgBattChargeMin
   292     elif soc > LaeWdArgBattChargeMax:
   293       soc = LaeWdArgBattChargeMax
   297     cmd = [chr(cmdId), chr(soc)]
   301       self.m_i2c.write(self.
m_addr, cmd)
   302     except i2c.I2CException, inst:
   303       self.
printError(
"CmdId %d" % (cmdId), inst.message)
   307       ret[key] = self.
m_fw[key]
   319     cmdId = LaeWdCmdIdSetAlarms
   322     ret = {
'rc': WDRcOk, key: self.
m_fw[key]}
   330     alarms &= LaeWdArgAlarmMask
   332     b1  = chr(((alarms >> 8) & 0xff))
   333     b2  = chr(((alarms) & 0xff))
   334     cmd = [chr(cmdId), b1, b2]
   338       self.m_i2c.write(self.
m_addr, cmd)
   339     except i2c.I2CException, inst:
   340       self.
printError(
"CmdId %d" % (cmdId), inst.message)
   343       self.
m_fw[key] = alarms
   344       ret[key] = self.
m_fw[key]
   358     cmdId = LaeWdCmdIdSetRgbLed
   361     ret = {
'rc': WDRcOk, key: self.
m_fw[key]}
   376     cmd = [chr(cmdId), b1, b2, b3]
   380       self.m_i2c.write(self.
m_addr, cmd)
   381     except i2c.I2CException, inst:
   382       self.
printError(
"CmdId %d" % (cmdId), inst.message)
   385       self.
m_fw[key][
'override']  = 
True   386       self.
m_fw[key][
'red']       = red
   387       self.
m_fw[key][
'green']     = green
   388       self.
m_fw[key][
'blue']      = blue
   389       ret[key] = self.
m_fw[key]
   399     cmdId = LaeWdCmdIdResetRgbLed
   402     ret = {
'rc': WDRcOk, key: self.
m_fw[key]}
   414       self.m_i2c.write(self.
m_addr, cmd)
   415     except i2c.I2CException, inst:
   416       self.
printError(
"CmdId %d" % (cmdId), inst.message)
   419       self.
m_fw[key][
'override'] = 
False   420       ret[key] = self.
m_fw[key]
   433     cmdId = LaeWdCmdIdConfigDPin
   436     ret = {
'rc': WDRcOk, key: {}}
   438     if (pin < LaeWdArgDPinNumWMin) 
or (pin > LaeWdArgDPinNumWMax):
   439       self.
printError(
"CmdId %d" % (cmdId), 
"Pin %d invalid" % (pin))
   443     ret[key] = self.
m_fw[key][pin]
   452       direction = LaeWdArgDPinDirOut
   454       direction = LaeWdArgDPinDirIn
   458     cmd = [chr(cmdId), b1, b2]
   462       self.m_i2c.write(self.
m_addr, cmd)
   463     except i2c.I2CException, inst:
   464       self.
printError(
"CmdId %d" % (cmdId), inst.message)
   467       self.
m_fw[key][pin][
'dir'] = direction
   468       ret[key] = self.
m_fw[key][pin]
   480     cmdId  = LaeWdCmdIdReadDPin
   481     rspLen = LaeWdRspLenReadDPin
   484     ret = {
'rc': WDRcOk, key: {}}
   486     if (pin < LaeWdArgDPinNumMin) 
or (pin > LaeWdArgDPinNumMax):
   487       self.
printError(
"CmdId %d" % (cmdId), 
"Pin %d invalid" % (pin))
   491     ret[key] = self.
m_fw[key][pin]
   500     cmd = [chr(cmdId), b1]
   504       rsp = self.m_i2c.write_read(self.
m_addr, cmd, rspLen)
   505     except i2c.I2CException, inst:
   506       self.
printError(
"CmdId %d" % (cmdId), inst.message)
   509       if len(rsp) == rspLen:
   510         self.
m_fw[key][pin][
'val'] = ord(rsp[1])
   511         ret[key] = self.
m_fw[key][pin]
   524     cmdId = LaeWdCmdIdWriteDPin
   527     ret = {
'rc': WDRcOk, key: {}}
   529     if (pin < LaeWdArgDPinNumWMin) 
or (pin > LaeWdArgDPinNumWMax):
   530       self.
printError(
"CmdId %d" % (cmdId), 
"Pin %d invalid" % (pin))
   534     ret[key] = self.
m_fw[key][pin]
   543       val = LaeWdArgDPinValHigh
   545       val = LaeWdArgDPinValLow
   549     cmd = [chr(cmdId), b1, b2]
   553       self.m_i2c.write(self.
m_addr, cmd)
   554     except i2c.I2CException, inst:
   555       self.
printError(
"CmdId %d" % (cmdId), inst.message)
   558       self.
m_fw[key][pin][
'val'] = val
   559       ret[key] = self.
m_fw[key][pin]
   572     cmdId  = LaeWdCmdIdReadAPin
   573     rspLen = LaeWdRspLenReadAPin
   576     ret = {
'rc': WDRcOk, key: {}}
   578     if (pin < LaeWdArgAInPinNumMin) 
or (pin > LaeWdArgAInPinNumMax):
   579       self.
printError(
"CmdId %d" % (cmdId), 
"Pin %d invalid" % (pin))
   583     ret[key] = self.
m_fw[key][pin]
   592     cmd = [chr(cmdId), b1]
   596       rsp = self.m_i2c.write_read(self.
m_addr, cmd, rspLen)
   597     except i2c.I2CException, inst:
   598       self.
printError(
"CmdId %d" % (cmdId), inst.message)
   601       if len(rsp) == rspLen:
   605         self.
m_fw[key][pin][
'fal'] = val
   606         ret[key] = self.
m_fw[key][pin]
   618     cmdId  = LaeWdCmdIdEnableMotorCtlrs
   619     rspLen = LaeWdRspLenEnableMotorCtlrs
   622     subkey  = 
'motor_ctlr_en'   623     ret     = {
'rc': WDRcOk, subkey: self.
m_fw[key][subkey]}
   632     if self.
m_fw[
'version'] == 0:
   635     elif self.
m_fw[
'version'] == 1:
   636       self.
m_fw[key][subkey] = 
True   637       ret[subkey] = self.
m_fw[key][subkey]
   641       val = LaeWdArgDPinValHigh
   643       val = LaeWdArgDPinValLow
   646     cmd = [chr(cmdId), b1]
   650       rsp = self.m_i2c.write_read(self.
m_addr, cmd, rspLen)
   651     except i2c.I2CException, inst:
   652       self.
printError(
"CmdId %d" % (cmdId), inst.message)
   655       if (len(rsp) == rspLen) 
and (ord(rsp[0]) == LaeWdArgPass):
   656         self.
m_fw[key][subkey] = enable
   657         ret[subkey] = self.
m_fw[key][subkey]
   669     cmdId  = LaeWdCmdIdEnableAuxPort
   672     subkey  = 
'aux_port_5v_en'   673     ret     = {
'rc': WDRcOk, subkey: self.
m_fw[key][subkey]}
   682     if self.
m_fw[
'version'] == 0:
   685     elif self.
m_fw[
'version'] == 1:
   686       self.
m_fw[key][subkey] = 
True   687       ret[subkey] = self.
m_fw[key][subkey]
   691       val = LaeWdArgDPinValHigh
   693       val = LaeWdArgDPinValLow
   695     b1  = chr(LaeWdArgAuxPort5V)
   697     cmd = [chr(cmdId), b1, b2]
   701       self.m_i2c.write(self.
m_addr, cmd)
   702     except i2c.I2CException, inst:
   703       self.
printError(
"CmdId %d" % (cmdId), inst.message)
   706       self.
m_fw[key][subkey] = enable
   707       ret[subkey] = self.
m_fw[key][subkey]
   719     cmdId  = LaeWdCmdIdEnableAuxPort
   722     subkey  = 
'aux_port_batt_en'   723     ret     = {
'rc': WDRcOk, subkey: self.
m_fw[key][subkey]}
   732     if self.
m_fw[
'version'] == 0:
   735     elif self.
m_fw[
'version'] == 1:
   736       self.
m_fw[key][subkey] = 
True   737       ret[subkey] = self.
m_fw[key][subkey]
   741       val = LaeWdArgDPinValHigh
   743       val = LaeWdArgDPinValLow
   745     b1  = chr(LaeWdArgAuxPortBatt)
   747     cmd = [chr(cmdId), b1, b2]
   751       self.m_i2c.write(self.
m_addr, cmd)
   752     except i2c.I2CException, inst:
   753       self.
printError(
"CmdId %d" % (cmdId), inst.message)
   756       self.
m_fw[key][subkey] = enable
   757       ret[subkey] = self.
m_fw[key][subkey]
   767     cmdId  = LaeWdCmdIdReadEnables
   768     rspLen = LaeWdRspLenReadEnables
   771     ret = {
'rc': WDRcOk, key: self.
m_fw[key]}
   780     if self.
m_fw[
'version'] < 2:
   787       rsp = self.m_i2c.write_read(self.
m_addr, cmd, rspLen)
   788     except i2c.I2CException, inst:
   789       self.
printError(
"CmdId %d" % (cmdId), inst.message)
   792       if len(rsp) == rspLen:
   797         self.
m_fw[key][
'motor_ctlr_en'] = 
True   799         self.
m_fw[key][
'motor_ctlr_en'] = 
False   801         self.
m_fw[key][
'aux_port_batt_en'] = 
True   803         self.
m_fw[key][
'aux_port_batt_en'] = 
False   805         self.
m_fw[key][
'aux_port_5v_en'] = 
True   807         self.
m_fw[key][
'aux_port_5v_en'] = 
False   808       ret[key] = self.
m_fw[key]
   818     cmdId  = LaeWdCmdIdReadVolts
   819     rspLen = LaeWdRspLenReadVolts
   822     ret = {
'rc': WDRcOk, key: self.
m_fw[key]}
   831     if self.
m_fw[
'version'] < 2:
   838       rsp = self.m_i2c.write_read(self.
m_addr, cmd, rspLen)
   839     except i2c.I2CException, inst:
   840       self.
printError(
"CmdId %d" % (cmdId), inst.message)
   843       if len(rsp) == rspLen:
   846       self.
m_fw[key][
'jack'] = val0 * LaeWdargVScale
   847       self.
m_fw[key][
'batt'] = val1 * LaeWdargVScale
   848       ret[key] = self.
m_fw[key]
   860       print >>sys.stderr, 
"Error: WatchDog: {0}".format(emsg1)
   862       print >>sys.stderr, 
"Error: WatchDog: {0}: {1}".format(emsg1, emsg2)
 def cmdGetFwVersion(self)
Execute command to get the firmware version. 
def cmdSetRgbLed(self, red, green, blue)
Execute command to set the RGB LED. 
def cmdEnableAuxPortBatt(self, enable)
Execute command to enable/disable battery output to aux. 
def isOpen(self)
Test if the open/attached I2C bus device is open. 
def cmdPetTheDog(self)
Execute command to pet the watchdog. 
def open(self, devName)
Open the I2C bus device. 
def printError(self, emsg1, emsg2=None)
Print error to stderr. 
def cmdReadAPin(self, pin)
Execute command to read an analog I/O pin. 
def cmdEnableAuxPort5V(self, enable)
Execute command to enable/disable regulated 5V output to aux. 
def cmdEnableMotorCtlrs(self, enable)
Execute command to enable/disable power to motor controllers. 
def cmdSetBatterySoC(self, soc)
Execute command to set the battery state of charge. 
def cmdResetRgbLed(self)
Reset the RGB LED to state defaults. 
def cmdReadVoltages(self)
Execute command to read sensed voltages. 
def cmdConfigDPin(self, pin, direction)
Execute command to configure a digital I/O pin. 
def sync(self)
Synchronize watchdog state with the subprocessor state. 
Laelaps WatchDog Interface Class. 
def __init__(self)
Constructor. 
def cmdWriteDPin(self, pin, val)
Execute command to wite a value to a digital I/O pin. 
def getShadow(self)
Get the shadowed subprocessor value. 
def cmdReadDPin(self, pin)
Execute command to read a digital I/O pin's value. 
def cmdSetAlarms(self, alarms)
Execute command to set/clear alarms. 
def attach(self, i2cbus)
Attach the open I2C object. 
def close(self)
Close the I2C bus device. 
def cmdReadEnables(self)
Execute command to read enable lines.