|
|
|
|
@ -21,6 +21,7 @@ import threading
|
|
|
|
|
import re
|
|
|
|
|
import serial
|
|
|
|
|
import time
|
|
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
|
|
from enum import Enum, auto
|
|
|
|
|
|
|
|
|
|
@ -42,6 +43,17 @@ class MsgName(Enum):
|
|
|
|
|
def __str__(self):
|
|
|
|
|
return str(self.value)
|
|
|
|
|
|
|
|
|
|
logmsgs = ["LE_NONE - Empty log",
|
|
|
|
|
"LE_POWERUP - Scout startup",
|
|
|
|
|
"LE_PI_BOOT_TIMEOUT - Tried to turn on Pi but did not recieve succesful boot signal",
|
|
|
|
|
"LE_PI_ON - Pi has booted",
|
|
|
|
|
"LE_LOW_VOLT_START_SHUTDOWN - Initiated Pi shutdown due to low supply voltage",
|
|
|
|
|
"LE_PI_SIGNAL_START_SHUTDOWN - Pi started to shut itself down",
|
|
|
|
|
"LE_PI_SHUTDOWN_TIMEOUT - Pi did not signal successful shutdown, so killed power",
|
|
|
|
|
"LE_MAIN5V_DISABLE - Main Pi power turned off",
|
|
|
|
|
"LE_VOLT_GOOD_MAIN5V_ENABLE - Turned Pi power on after voltage raised enough",
|
|
|
|
|
"LE_ALARM_MAIN5V_ENABLE - Turned Pi power on after wakeup alarm was hit"]
|
|
|
|
|
|
|
|
|
|
class ScoutPlugin(shepherd.plugin.Plugin):
|
|
|
|
|
@staticmethod
|
|
|
|
|
def define_config(confdef):
|
|
|
|
|
@ -55,7 +67,7 @@ class ScoutPlugin(shepherd.plugin.Plugin):
|
|
|
|
|
self.plugins = pluginInterface.other_plugins
|
|
|
|
|
self.hooks = pluginInterface.hooks
|
|
|
|
|
|
|
|
|
|
self.msg_handler = tdw.MessageHandler(config.serial_port, 57600)
|
|
|
|
|
self.msg_handler = tdw.MessageHandler(config["serialport"], 57600)
|
|
|
|
|
|
|
|
|
|
self.interface.register_function(self.get_batv)
|
|
|
|
|
self.interface.register_function(self.get_bati)
|
|
|
|
|
@ -66,11 +78,12 @@ class ScoutPlugin(shepherd.plugin.Plugin):
|
|
|
|
|
self.interface.register_function(self.set_pwm2)
|
|
|
|
|
self.interface.register_function(self.set_out1)
|
|
|
|
|
self.interface.register_function(self.set_out2)
|
|
|
|
|
self.interface.register_function(self.test_logs)
|
|
|
|
|
|
|
|
|
|
self.interface.register_function(self.test)
|
|
|
|
|
|
|
|
|
|
def get_batv(self):
|
|
|
|
|
rqst = self.msg_handler.send_request(MsgName.BATV)
|
|
|
|
|
rqst = self.msg_handler.send_request(MsgName.BATV.value)
|
|
|
|
|
if rqst.wait_for_response():
|
|
|
|
|
return rqst.response.arguments[0]
|
|
|
|
|
return None
|
|
|
|
|
@ -123,6 +136,16 @@ class ScoutPlugin(shepherd.plugin.Plugin):
|
|
|
|
|
return cmd.response.arguments[0]
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
def test_logs(self):
|
|
|
|
|
rqst = self.msg_handler.send_request(MsgName.LOG)
|
|
|
|
|
if rqst.wait_for_response():
|
|
|
|
|
for logline in reversed(rqst.response.multipart_args):
|
|
|
|
|
logdate = datetime.fromtimestamp(int(logline[0]))
|
|
|
|
|
batv = float(logline[1])/100.0
|
|
|
|
|
logmessage = logmsgs[int(logline[2])]
|
|
|
|
|
print(F"::{logdate:%Y-%m-%d %H:%M:%S}:: {batv:.2f}V :: {logmessage}")
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
def test(self):
|
|
|
|
|
print("Testing companion board...")
|
|
|
|
|
print(F"Current RTC time is {self.get_time()}")
|
|
|
|
|
|