Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions backend_py/run.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# run.py runs the backend, creating a async socketio server and a FastAPI web framework, then
# both are passed into a Server instance to handle logic, and a combination of the two is hosted
# as a uvicorn server, which handles traffic

from src import Server, FeatureSupport
import socketio
from fastapi import FastAPI
Expand Down
7 changes: 7 additions & 0 deletions backend_py/src/routes/cameras.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
"""
camera.py

API endpoints for camera device management and streaming config
Handles listing connected devices, updating stream settings (resolution / fps), setting UVC controls, and dealing with Leader/Follower for stereo cameras
"""

from fastapi import APIRouter, Depends, Request
from ..services import DeviceManager, StreamInfoModel, DeviceNicknameModel, UVCControlModel, DeviceDescriptorModel, DeviceLeaderModel
import logging
Expand Down
7 changes: 7 additions & 0 deletions backend_py/src/routes/lights.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
"""
lights.py

API endpoints for light device management
Handles listing connected lights, setting intensity, and disabling lights
"""

from fastapi import APIRouter, Depends, Request
from typing import List
from ..services import LightManager, Light, DisableLightInfo, SetLightInfo
Expand Down
7 changes: 7 additions & 0 deletions backend_py/src/routes/preferences.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
"""
preferences.py

API endpoints for server perferences
Handles getting and setting preferences
"""

from fastapi import APIRouter, Depends, Request
from typing import Dict
from ..services import PreferencesManager, SavedPreferencesModel
Expand Down
7 changes: 7 additions & 0 deletions backend_py/src/routes/recordings.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
"""
recording.py

API endpoints for accessing video file library
Handles listing recording metadata, downloading / deleting / renaming recordings, and downloading all recordings as ZIP
"""

from fastapi import APIRouter, Depends, Request, HTTPException
from fastapi.responses import FileResponse
from typing import List
Expand Down
7 changes: 7 additions & 0 deletions backend_py/src/routes/system.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
"""
system.py

API endpoints for csystem power control
Handles rebooting / shutting down the system
"""

from fastapi import APIRouter, Request
from ..services import SystemManager

Expand Down
7 changes: 7 additions & 0 deletions backend_py/src/routes/wifi.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
"""
wifi.py

API endpoints for wifi network management
Handles listing available networks, connecting / disconnecting from networks, managing saved networks, and toggling wifi
"""

from fastapi import APIRouter, Depends, Request
from typing import List
from ..services import (
Expand Down
7 changes: 7 additions & 0 deletions backend_py/src/routes/wired.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
"""
wired.py

API endpoints for connected ethernet networks
Handles managing dyanmic / static addresses for ethernet, managing priority (prioritize wifi or ethernet)
"""

from fastapi import APIRouter, Depends, Request
from typing import List
from ..services import (
Expand Down
7 changes: 7 additions & 0 deletions backend_py/src/server.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
"""
server.py

Handles server logic and initializes all the managers (settings, devices, lights, etc)
Starts device monitoring, wifi scan, and starts ttyd (teletypewriter daemon) to run in the background
"""

from ctypes import *
import logging.handlers

Expand Down
2 changes: 1 addition & 1 deletion backend_py/src/services/cameras/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .device_manager import *
from .device_utils import *
from .device import *
from .ehd_controls import *
from .xu_controls import *
from .ehd import *
from .enumeration import *
from .pydantic_schemas import *
Expand Down
20 changes: 18 additions & 2 deletions backend_py/src/services/cameras/device.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
"""
device.py

Base class for camera device management
Handles v4l2 device finding, uvc controls, stream configuration, and device settings management
"""

from ctypes import *
import struct
from dataclasses import dataclass
Expand All @@ -10,7 +17,7 @@
from enum import Enum

from . import v4l2
from . import ehd_controls as xu
from . import xu_controls as xu

from .stream_utils import fourcc2s
from .enumeration import *
Expand All @@ -34,6 +41,16 @@
"PID": 0x6368,
"device_type": DeviceType.STELLARHD_FOLLOWER,
},
"stellarHDPro: Leader": {
"VID": 0xC45,
"PID": 0x6369,
"device_type": DeviceType.STELLARHD_LEADER_PRO,
},
"stellarHDPro: Follower": {
"VID": 0xC45,
"PID": 0x6370,
"device_type": DeviceType.STELLARHD_FOLLOWER_PRO,
},
}


Expand Down Expand Up @@ -230,7 +247,6 @@ def _get_ctrl(self):
def _clear(self):
self._data = b"\x00" * self._size


class Device(events.EventEmitter):

def __init__(self, device_info: DeviceInfo) -> None:
Expand Down
10 changes: 10 additions & 0 deletions backend_py/src/services/cameras/device_manager.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
"""
device_manager.py

Handles functionality of device and montiors for devices
When it finds a new device, it creates a new device object and updates the device list and that devices settings
When it sees a missing device, it removes that device ojbect from the device list
Manages a devices streaming state as well as changes to device name
Manages the leader follower connections
"""

from typing import *
import logging
import event_emitter as events
Expand Down
6 changes: 6 additions & 0 deletions backend_py/src/services/cameras/device_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
"""
device_utils.py

Utility functions for device_manager.py, specifically for finding added devices / removed devices
"""

from typing import List
from .device import Device

Expand Down
15 changes: 11 additions & 4 deletions backend_py/src/services/cameras/ehd.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
"""
ehd.py

Adds additional features to exploreHD devices through extension units (xu) as per UVC protocol
Uses options functionality to set defaults, ranges, and specifies registers for where these features store data
"""

from typing import Dict
from .enumeration import DeviceInfo
from .device import Device, Option, ControlTypeEnum
from .pydantic_schemas import H264Mode
from . import ehd_controls as xu
from . import xu_controls as xu

class EHDDevice(Device):
'''
Expand Down Expand Up @@ -31,7 +38,7 @@ def _get_options(self) -> Dict[str, Option]:
# Standard integer options
options['bitrate'] = Option(
self.cameras[2], '>I', xu.Unit.USR_ID, xu.Selector.USR_H264_CTRL, xu.Command.H264_BITRATE_CTRL, 'Bitrate',
lambda bitrate: int(bitrate * 1000000), # convert to bps from mpbs
lambda bitrate: int(round(bitrate * 1000000)), # convert to bps from mpbs (round for float imprecision)
lambda bitrate: bitrate / 1000000 # convert to mpbs from bps
)

Expand All @@ -45,8 +52,8 @@ def _get_options(self) -> Dict[str, Option]:
# Maybe rename mode to vbr etc.
options['vbr'] = Option(
self.cameras[2], 'B', xu.Unit.USR_ID, xu.Selector.USR_H264_CTRL, xu.Command.H264_MODE_CTRL, 'Variable Bitrate',
lambda mode : H264Mode.MODE_VARIABLE_BITRATE.value if mode else H264Mode.MODE_CONSTANT_BITRATE.value,
lambda mode_value : H264Mode(mode_value) == H264Mode.MODE_VARIABLE_BITRATE)
lambda mode : H264Mode.MODE_VARIABLE_BITRATE.value if mode else H264Mode.MODE_CONSTANT_BITRATE.value,
lambda mode_value : H264Mode(mode_value) == H264Mode.MODE_VARIABLE_BITRATE)

return options

7 changes: 7 additions & 0 deletions backend_py/src/services/cameras/enumeration.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
"""
enumeration.py

Searches the system for cameras using video4linux, create a DeviceInfo based on the camera, and then maps that to the camera's bus_info,
and return a sorted list of device_infos
"""

from dataclasses import dataclass
from . import v4l2
import fcntl
Expand Down
9 changes: 9 additions & 0 deletions backend_py/src/services/cameras/pydantic_schemas.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
"""
pydantic_schemas.py

Defines Pydantic models and Enums for camera and device configs
Includes schemas for streams, controls, device info, and API request/response strutures
"""

from pydantic import BaseModel, Field
from typing import List, Dict, Optional
from enum import Enum, IntEnum
Expand Down Expand Up @@ -56,6 +63,8 @@ class DeviceType(IntEnum):
EXPLOREHD = 0
STELLARHD_LEADER = 1
STELLARHD_FOLLOWER = 2
STELLARHD_LEADER_PRO = 3
STELLARHD_FOLLOWER_PRO = 4


class IntervalModel(BaseModel):
Expand Down
7 changes: 7 additions & 0 deletions backend_py/src/services/cameras/saved_pydantic_schemas.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
"""
saved_pydantic_schemas.py

Defines Pydantic models and Enums for persisting device settings and configs
Includes schemas for serializing device states (streams, controls, nicknames) to JSON, keeping setting across reboots
"""

from pydantic import BaseModel
from typing import List, Optional

Expand Down
7 changes: 7 additions & 0 deletions backend_py/src/services/cameras/settings.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
"""
settings.py

Manages persisting device settings and configs (cameras, lights, etc)
Handles loading and saving device configs to JSON, keeping setting across reboots, and manages background sync of settings
"""

from typing import List, Dict, cast
import threading
import time
Expand Down
Loading