Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge branch core-anup into test #2

Merged
merged 19 commits into from
Apr 25, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
cleaned up some things
  • Loading branch information
abagali1 committed Apr 18, 2019
commit 88291f64635dd980ab840f5ef6eca5a7f13afb69
28 changes: 13 additions & 15 deletions core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from submodules import eeprom

config = None # Prevents IDE from throwing errors about not finding `config`
STARTUP_THRESHOLD = 65 #FIXME ADD ACTUAL VALUE(AMOUNT OF VOLTS REQUIRED TO STARTUP)
logger = logging.getLogger("ROOT")


Expand Down Expand Up @@ -82,15 +81,14 @@ def enter_emergency_mode(reason: str = '') -> None:
getattr(module, 'enter_emergency_mode')()



def check_first_boot(): #TODO: IF EMPROM SAYS FIRST BOOT WAIT 30 MINUTES ELSE CONTINUE
def check_first_boot(): # TODO: IF EMPROM SAYS FIRST BOOT WAIT 30 MINUTES ELSE CONTINUE
if eeprom.get("FIRST_BOOT") is None or eeprom.get("FIRST_BOOT") == True:
eeprom.add("FIRST BOOT", True)
eeprom.add("FIRST BOOT", True) #FIXME eeprom stuff
time.sleep(1800)


def cold_start(): #TODO WAIT UNTIL POWER THRESHOLD IS REACHED
while(eps.get_bcr1_volts() < STARTUP_THRESHOLD):
def cold_start(): # TODO WAIT UNTIL POWER THRESHOLD IS REACHED
while eps.get_bcr1_volts() < power.STARTUP:
continue


Expand Down Expand Up @@ -131,7 +129,6 @@ def start():
submodules.append(level_c)
logger.debug(submodules)


# Trigger module start
for module in submodules[0]:
logger.debug(f'Starting level A module {module}')
Expand All @@ -141,26 +138,27 @@ def start():
for module in submodules[1]:
logger.debug(f'Starting level B module {module}')
if hasattr(module, 'start'):
getattr(module,'start')()
getattr(module, 'start')()
cold_start()
for module in submodules[2]:
logger.debug(f'Starting level C module {module}')
if hasattr(module,'start'):
getattr(module,'start')
if hasattr(module, 'start'):
getattr(module, 'start')

enter_normal_mode() # Enter normal mode
logger.debug("Entering main loop")

# MAIN LOOP
while True:
if(eps.get_bcr1_volts() >= NORMAL_THRESHOLD):
if eps.get_bcr1_volts() >= power.NORMAL:
enter_normal_mode()
elif(eps.get_bcr1_volts() < NORMAL_THRESHOLD):
if(eps.get_bcr1_volts() > LOW_THRESHOLD):
elif eps.get_bcr1_volts() < power.NORMAL:
if eps.get_bcr1_volts() > power.LOW:
enter_low_power_mode()
if(eps.get_bcr1_volts() < LOW_THRESHOLD):
if eps.get_bcr1_volts() < power.LOW:
enter_emergency_mode()
#TODO: ADD MORE CASES
# TODO: ADD MORE CASES


current_mode = mode.NORMAL # Default power mode
submodules = [] # List of all active modules
4 changes: 3 additions & 1 deletion core/power.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
pass
STARTUP = 0
NORMAL = 0
LOW = 0
27 changes: 15 additions & 12 deletions submodules/eps.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from smbus2 import SMBusWrapper

from helpers.threadhandler import ThreadHandler
from core import mode
from functools import partial

# Initialize global variables
Expand All @@ -13,7 +14,9 @@
'antenna': 5, 'a': 6, 'b': 7, 'c': 8, 'd': 9, 'e': 10}


def pin_on(device_name):
def pin_on(device_name) -> bool:
if state != mode.NORMAL:
return False
with SMBusWrapper(1) as bus:
PDM_val = [epsdict[device_name]]

Expand All @@ -32,14 +35,14 @@ def pin_on(device_name):
return False


def reboot_device(device_name, sleeptime):
def reboot_device(device_name, sleeptime) -> None:
pin_off(device_name)
time.sleep(sleeptime)
pin_on(device_name)
time.sleep(sleeptime)


def pin_off(device_name):
def pin_off(device_name) -> bool:
with SMBusWrapper(1) as bus:
PDM_val = [epsdict[device_name]]

Expand All @@ -49,9 +52,9 @@ def pin_off(device_name):
else:
bus.write_i2c_block_data(address, 0x13, PDM_val)

if get_PDM_status(device_name) == 0: # PDM is OFF #FIXME WHY EQUAL TO 1 INSTEAD OF 0
if get_PDM_status(device_name) == 0: # PDM is OFF
logger.debug("Pin communication successful. \
Pin is now OFF.") # FIXME same things as pin_off
Pin is now OFF.")
else:
logger.error("Pin communication unsuccessful")
return False
Expand All @@ -64,7 +67,7 @@ def get_PDM_status(device_name):
return bus.read_byte(address) # RETURNS A BYTE, NOT A BIT. OK?


def is_module_on(device_name):
def is_module_on(device_name) -> bool:
with SMBusWrapper(1) as bus:
PDM_val = [epsdict[device_name]]
if get_PDM_status(device_name).equals(0):
Expand Down Expand Up @@ -113,16 +116,16 @@ def get_board_telem(data):
return bus.read_byte(address)


def led_on_off():
looptime = 20 # change me - was 30
def led_on_off() -> None:
looptime = 20 #FIXME: Was 30
while True:
pin_on('aprs')
time.sleep(looptime)
pin_off('aprs')
time.sleep(looptime)


def board_check():
def board_check() -> None:
while True:
logger.debug(get_board_telem(0x23))
time.sleep(7)
Expand Down Expand Up @@ -156,14 +159,14 @@ def start():
# TODO: Update these methods. Currently only holds placeholder methods.
def enter_normal_mode():
global state
state = 'NORMAL'
state = mode.NORMAL


def enter_low_power_mode():
global state
state = 'LOW'
state = mode.LOW_POWER


def enter_emergency_mode():
global state
state = 'EMERGENCY'
state = mode.EMERGENCY