Skip to content

Commit

Permalink
add opd not fault and adc current pins
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanpdx committed Sep 17, 2023
1 parent b84d140 commit 4c3ae1d
Show file tree
Hide file tree
Showing 9 changed files with 164 additions and 93 deletions.
8 changes: 5 additions & 3 deletions oresat_c3/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 10 additions & 2 deletions oresat_c3/data/oresat_c3.dcf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 10 additions & 2 deletions oresat_c3/data/oresat_c3.eds
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions oresat_c3/services/opd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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

Expand Down
40 changes: 30 additions & 10 deletions oresat_c3/subsystems/opd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)

Expand All @@ -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.'''
Expand Down Expand Up @@ -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
6 changes: 3 additions & 3 deletions oresat_c3/templates/beacon.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{% extends 'base.html' %}
{% extends "base.html" %}

{% block content %}
<button onclick='sendBeacon()'>Send Beacon</button>
<button onclick="sendBeacon()">Send Beacon</button>
<script>
async function sendBeacon() {
writeValue('0x8000','0x01', true);
writeValue("0x8000","0x01", true);
}
</script>
{% endblock %}
Loading

0 comments on commit 4c3ae1d

Please sign in to comment.