class System: def __init__(self, obc_com, sys_bus_com, payload_bus_com, use_single_bus, gpio, auto_power_on = True): self.log = logging.getLogger("system") self._use_single_bus = use_single_bus self.obc_com = obc_com self.sys_bus_com = sys_bus_com self.payload_bus_com = payload_bus_com self.sys_bus = I2CMock('SYS', sys_bus_com) if use_single_bus: self.payload_bus = self.sys_bus else: self.payload_bus = I2CMock('PLD', payload_bus_com) self._setup_devices() self.obc = OBC(SerialPortTerminal(obc_com, gpio)) self.obc.power_off() self.sys_bus.start() self.payload_bus.start() if auto_power_on: self.obc.power_on(clean_state=True) def _setup_devices(self): self.eps = EPSDevice() self.transmitter = TransmitterDevice() self.receiver = ReceiverDevice() self.primary_antenna = AntennaController(PRIMARY_ANTENNA_CONTROLLER_ADDRESS) self.backup_antenna = AntennaController(BACKUP_ANTENNA_CONTROLLER_ADDRESS) self.sys_bus.add_device(self.eps) self.payload_bus.add_device(self.eps) self.sys_bus.add_device(self.transmitter) self.sys_bus.add_device(self.receiver) self.sys_bus.add_device(self.primary_antenna) self.payload_bus.add_device(self.backup_antenna) def close(self): self.sys_bus.stop() if not self._use_single_bus: self.payload_bus.stop() self.obc.close() def restart(self): self.sys_bus.unfreeze() self.sys_bus.unlatch() if not self._use_single_bus: self.payload_bus.unfreeze() self.payload_bus.unlatch() self.obc.reset() self.obc.wait_to_start()
def __init__(self, obc_com, sys_bus_com, payload_bus_com, use_single_bus, gpio, auto_power_on = True): self.log = logging.getLogger("system") self._use_single_bus = use_single_bus self.obc_com = obc_com self.sys_bus_com = sys_bus_com self.payload_bus_com = payload_bus_com self.sys_bus = I2CMock('SYS', sys_bus_com) if use_single_bus: self.payload_bus = self.sys_bus else: self.payload_bus = I2CMock('PLD', payload_bus_com) self._setup_devices() self.obc = OBC(SerialPortTerminal(obc_com, gpio)) self.obc.power_off() self.sys_bus.start() self.payload_bus.start() if auto_power_on: self.obc.power_on(clean_state=True)
try: from obc import OBC, SerialPortTerminal except ImportError: sys.path.append(os.path.join(os.path.dirname(__file__), '..')) from obc import OBC, SerialPortTerminal class DummyGPIO: RESET = 0 def high(self, _): pass def low(self, _): pass class MyPrompt(Prompts): def in_prompt_tokens(self, cli=None): return [(Token.Prompt, 'OBC'), (Token.Prompt, '> ')] obc = OBC(SerialPortTerminal(config.config['OBC_COM'], DummyGPIO())) cfg = Config() shell = InteractiveShellEmbed(config=cfg, user_ns={'obc': obc}, banner2='OBC Terminal') shell.prompts = MyPrompt(shell) shell()
try: from picamera import PiCamera from stream import Stream except ImportError: print("error importing picamera") from obc import OBC config = configparser.ConfigParser() config.read('config.ini') app = Flask(__name__) socketio = SocketIO(app, cors_allowed_origins='*', async_mode="threading") obc = OBC(socketio) CORS(app, resources={r'/*': {"origins": '*'}}) @app.after_request def after_request(response): response.headers.add('Access-Control-Allow-Headers', 'Content-Type, Authorization') response.headers.add('Access-Control-Allow-Methods', 'GET, POST, PATCH, DELETE, OPTIONS') return response download_dir = 'download' # FLASK CONFIG app.config["DEBUG"] = True app.config['SECRET_KEY'] = 'secret!' app.config['SQLALCHEMY_DATABASE_URI'] = config['db']['path'] app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False