From 4c3ae1ddb9a748f0a092445d22d5b1c5a406e218 Mon Sep 17 00:00:00 2001 From: ryanpdx Date: Sun, 17 Sep 2023 08:25:31 -0700 Subject: [PATCH] add opd not fault and adc current pins --- oresat_c3/__main__.py | 8 +- oresat_c3/data/oresat_c3.dcf | 12 ++- oresat_c3/data/oresat_c3.eds | 12 ++- oresat_c3/services/opd.py | 13 ++++ oresat_c3/subsystems/opd.py | 40 +++++++--- oresat_c3/templates/beacon.html | 6 +- oresat_c3/templates/opd.html | 126 ++++++++++++++++++-------------- oresat_c3/templates/state.html | 38 +++++----- tests/subsystems/test_opd.py | 2 +- 9 files changed, 164 insertions(+), 93 deletions(-) diff --git a/oresat_c3/__main__.py b/oresat_c3/__main__.py index 15ec32f..832c40e 100644 --- a/oresat_c3/__main__.py +++ b/oresat_c3/__main__.py @@ -37,12 +37,14 @@ def main(): app.node.od['Manufacturer software version'].value = __version__ - # TODO get from OD i2c_bus_num = 2 - opd_enable_pin = 20 + opd_not_enable_pin = 116 + opd_not_fault_pin = 115 + opd_adc_current_pin = 2 fram_i2c_addr = 0x50 - opd = Opd(opd_enable_pin, i2c_bus_num, mock=mock_opd) + opd = Opd(opd_not_enable_pin, opd_not_fault_pin, opd_adc_current_pin, i2c_bus_num, + mock=mock_opd) fram = Fram(i2c_bus_num, fram_i2c_addr, mock=mock_fram) app.add_service(StateService(fram)) # add state first to restore state from F-RAM diff --git a/oresat_c3/data/oresat_c3.dcf b/oresat_c3/data/oresat_c3.dcf index c478d8a..a9e6f03 100644 --- a/oresat_c3/data/oresat_c3.dcf +++ b/oresat_c3/data/oresat_c3.dcf @@ -13862,14 +13862,14 @@ DefaultValue=0 [8001] ParameterName=Test OPD ObjectType=0x09 -SubNumber=6 +SubNumber=7 [8001sub0] ParameterName=Highest sub-index supported ObjectType=0x07 DataType=0x0005 AccessType=const -DefaultValue=0x05 +DefaultValue=0x06 [8001sub1] ParameterName=Enable System @@ -13907,6 +13907,14 @@ DataType=0x0001 AccessType=wo DefaultValue=0 +;OPD circuit has a fault +[8001sub6] +ParameterName=Fault +ObjectType=0x07 +DataType=0x0001 +AccessType=ro +DefaultValue=0 + [ManufacturerObjects] SupportedObjects=16 1=0x2000 diff --git a/oresat_c3/data/oresat_c3.eds b/oresat_c3/data/oresat_c3.eds index 5046f74..1019706 100644 --- a/oresat_c3/data/oresat_c3.eds +++ b/oresat_c3/data/oresat_c3.eds @@ -13852,14 +13852,14 @@ DefaultValue=0 [8001] ParameterName=Test OPD ObjectType=0x09 -SubNumber=6 +SubNumber=7 [8001sub0] ParameterName=Highest sub-index supported ObjectType=0x07 DataType=0x0005 AccessType=const -DefaultValue=0x05 +DefaultValue=0x06 [8001sub1] ParameterName=Enable System @@ -13897,6 +13897,14 @@ DataType=0x0001 AccessType=wo DefaultValue=0 +;OPD circuit has a fault +[8001sub6] +ParameterName=Fault +ObjectType=0x07 +DataType=0x0001 +AccessType=ro +DefaultValue=0 + [ManufacturerObjects] SupportedObjects=16 1=0x2000 diff --git a/oresat_c3/services/opd.py b/oresat_c3/services/opd.py index 22cd2c8..036520c 100644 --- a/oresat_c3/services/opd.py +++ b/oresat_c3/services/opd.py @@ -46,6 +46,8 @@ def on_start(self): self._flight_mode_obj = self.node.od[0x3007][0x2] + self.node.add_sdo_read_callback(0x7000, self._on_read_current) + self.node.od[0x8001][0x2].value = '{}' self.node.add_sdo_read_callback(0x8001, self._on_read) self.node.add_sdo_write_callback(0x8001, self._on_write) @@ -54,6 +56,15 @@ def on_stop(self): self.opd.stop_loop = True + def _on_read_current(self, index: int, subindex: int): + + value = None + + if subindex == 0x6: + value = self.opd.current + + return value + def _on_read(self, index: int, subindex: int): value = None @@ -67,6 +78,8 @@ def _on_read(self, index: int, subindex: int): value = self.cur_node.value elif subindex == 0x4: value = self.opd[self.cur_node].status.value + elif subindex == 0x6: + value = self.opd.has_fault return value diff --git a/oresat_c3/subsystems/opd.py b/oresat_c3/subsystems/opd.py index e0cb7f2..4dd678c 100644 --- a/oresat_c3/subsystems/opd.py +++ b/oresat_c3/subsystems/opd.py @@ -7,7 +7,7 @@ from enum import IntEnum from time import sleep -from olaf import logger, GPIO +from olaf import logger, Gpio, Adc, GPIO_IN from ..drivers.max7310 import Max7310, Max7310Error @@ -90,7 +90,7 @@ def __init__(self, bus: int, node_id: OpdNodeId, mock: bool = False): ''' Parameters ---------- - enable_pin: int + not_enable_pin: int Pin that enable the OPD subsystem. bus: int The I2C bus. @@ -408,20 +408,28 @@ class Opd: _SYS_RESET_DELAY_S = 10 _RESET_ATTEMPTS = 3 - def __init__(self, enable_pin: int, bus: int, mock: bool = False): + def __init__(self, not_enable_pin: int, not_fault_pin: int, current_pin: int, bus: int, + mock: bool = False): ''' Parameters ---------- - enable_pin: int - Pin that enable the OPD subsystem. + not_enable_pin: int + Output pin that enables/disables the OPD subsystem. + not_fault_pin: int + Input pin for faults. + current_pin: int + ADC pin number to get OPD current. bus: int The I2C bus. mock: bool Mock the OPD subsystem. ''' - self._gpio = GPIO(enable_pin, mock) - self._gpio.high() # make sure OPD disable initially + self._not_enable_pin = Gpio(not_enable_pin, mock) + self._not_fault_pin = Gpio(not_fault_pin, mock, mode=GPIO_IN) + self._not_fault_pin._mock_value = 1 # fix default for mocking + self._adc = Adc(current_pin, mock) + self._not_enable_pin.high() # make sure OPD disable initially self._nodes = {} for node_id in list(OpdNodeId): @@ -457,7 +465,7 @@ def enable(self): return # already enabled logger.info('starting OPD subsystem') - self._gpio.low() + self._not_enable_pin.low() self.scan(True) @@ -470,7 +478,7 @@ def disable(self): if node.status != OpdNodeState.NOT_FOUND: node.disable() - self._gpio.high() + self._not_enable_pin.high() def reset(self): '''Restart the OPD subsystem with a delay between stop and start.''' @@ -580,4 +588,16 @@ def is_subsystem_dead(self) -> bool: def is_subsystem_enabled(self) -> bool: '''bool: OPD is enabled or not.''' - return not self._gpio.is_high + return not self._not_enable_pin.is_high + + @property + def has_fault(self) -> bool: + '''bool: OPD circuit has a fault.''' + + return not self._not_fault_pin.is_high + + @property + def current(self) -> int: + '''int: OPD current.''' + + return self._adc.value diff --git a/oresat_c3/templates/beacon.html b/oresat_c3/templates/beacon.html index 2b1fff6..670c5a5 100644 --- a/oresat_c3/templates/beacon.html +++ b/oresat_c3/templates/beacon.html @@ -1,10 +1,10 @@ -{% extends 'base.html' %} +{% extends "base.html" %} {% block content %} - + {% endblock %} diff --git a/oresat_c3/templates/opd.html b/oresat_c3/templates/opd.html index bbdd7dd..f1d4356 100644 --- a/oresat_c3/templates/opd.html +++ b/oresat_c3/templates/opd.html @@ -1,4 +1,4 @@ -{% extends 'base.html' %} +{% extends "base.html" %} {% block content %} - OPD Subsystem: - ENABLED - - + Status: + ENABLED +
+ Scan: +
-
- + Fault: + NO_FAULT +
+ Current: + 0.000 mA +
+
+
+
@@ -39,30 +47,30 @@
Card