import { exec, execSync } from 'child_process'; import { Request, Response } from 'express'; import { writeFile } from 'fs'; import { CameraType } from 'types'; export const PORT = 5000; export const WS_PORT = 5001; export const PUBLIC_FOLDER = '/data/recording'; export const TMP_PUBLIC_FOLDER = '/tmp/recording'; export const FRAMES_ROOT_FOLDER = '/tmp/recording/pics'; export const FRAMEKM_ROOT_FOLDER = '/data/recording/framekm'; export const FRAMEKM_SHORT_ROOT_FOLDER = '/data/recording/framekm_short'; export const FRAMEKM_CUSTOM_ROOT_FOLDER = '/data/recording/framekm_custom'; export const ML_METADATA_ROOT_FOLDER = '/data/recording/ml_metadata'; export const UNPROCESSED_FRAMEKM_ROOT_FOLDER = '/data/recording/unprocessed_framekm'; export const CACHED_OBSERVATIONS_FOLDER = '/data/recording/cached_observations'; export const DB_PATH = '/data/recording/data-logger.v2.0.0.db'; export const CONFIG_PATH = '/opt/dashcam/bin/db-config.json'; export const RAW_DATA_ROOT_FOLDER = '/data/raw'; export const STREAM_REQUEST_FOLDER = __dirname + '/../../../data/recording/request'; export const GPS_ROOT_FOLDER = '/data/recording/gps'; export const CSV_CACHE_FOLDER = '/data/recording/csv'; export const EMMC_CONFIG_DIR = '/data/config'; export const QUARANTINE_METADATA_FOLDER = '/data/recording/quarantine'; export const METADATA_ROOT_FOLDER = '/data/recording/metadata'; export const LANDMARKS_METADATA_ROOT_FOLDER = '/data/recording/landmarks'; export const UNPROCESSED_METADATA_ROOT_FOLDER = '/data/recording/unprocessed_metadata'; export const GPS_LATEST_SAMPLE = __dirname + '/../../../data/recording/gps/latest.log'; export const IMU_ROOT_FOLDER = '/data/recording/imu'; export const DATA_CACHE_MARKER = '/data/.cache'; export const DATA_CACHE_PATH = '/data/cache'; export const LORA_RESPONSE_FOLDER = __dirname + '/../../../data/lorawan'; export const LORA_REQUEST_FOLDER = __dirname + '/../../../tmp/lorawan'; export const BUILD_INFO_PATH = __dirname + '/../../../etc/version.json'; export const NETWORK_BOOT_CONFIG_PATH = __dirname + '/../../../data/wifi.cfg'; export const ACL_TOOL_PATH = '/opt/dashcam/bin/acl'; export const FRAMEKM_CLEANUP_SCRIPT = '/opt/odc-api/cleanup_framekm.sh'; export const DATA_INTEGRITY_SCRIPT = '/opt/odc-api/data_integrity_check.sh'; export const FIRMWARE_UPDATE_MARKER = '/data/recording/update_in_progress'; export const FRAMES_LIST_FOLDER = '/tmp/rgb'; export const ACL_FILES_PATH = '/data'; export const CACHED_CAMERA_CONFIG = '/data/camera.config'; export const HEALTH_MARKER_PATH = '/data/healthy.txt'; export const USB_WRITE_PATH = '/mnt/usb/recording'; export const WIFI_INTERFACE = 'wlp1s0f0'; export const MOTION_MODEL_CURSOR = '/data/mm_cursor.log'; export const ML_SCRIPT_PATH = '/opt/odc-api/python/privacy.py'; export const DEFAULT_MODEL_PATH = '/opt/odc-api/python'; export const MOTION_MODEL_CONFIG = '/data/mm_config.json'; export const PRIVACY_ZONES_CONFIG = '/data/ppz.json'; export const WEBSERVER_LOG_PATH = '/data/recording/odc-api.log'; export const CPU_MEM_LOG_PATH = '/data/recording/cpu-mem-logger.log'; export const EVENTS_LOG_PATH = '/data/events.log'; export const LED_CONFIG_PATH = __dirname + '/../../../tmp/led.json'; export const IMU_CALIBRATOR_PATH = '/opt/dashcam/bin/imucalibrator'; // File containing the camera configuration export const IMAGER_CONFIG_PATH = __dirname + '/../../../opt/camera-bridge/config.json'; export const NEW_IMAGER_CONFIG_PATH = __dirname + '/../../../opt/camera-bridge/config.json'; export const CACHED_RES_CONFIG = '/data/res.config'; // Path that will be used by the App to upload the new firmware image export const UPLOAD_PATH = __dirname + '/../../../data/'; export const ZOO_UPLOADED_PATH = '/data/zoo-uploaded/'; export const ZOO_V2_UPLOADED_PATH = '/data/zoo_v2-uploaded/'; export const DEVICE_INFO_LOG_FILE = __dirname + '/../../../tmp/dump.bin'; export const CRON_CONFIG = '/home/root/cron_config'; export const ML_ROOT_FOLDER = '/data/models'; export const ML_MODEL_PATH = '/opt/object-detection/model.blob'; export const ML_MODELS: Record = { PVC: '/data/recording/models/pvc.onnx', }; export const CRON_EXECUTED_TASKS_PATH = '/home/root/cron_executed'; export const IMAGER_BRIDGE_PATH = __dirname + '/../../../opt/dashcam/bin/bridge.sh'; export const PREVIEW_ROUTE = ':9001/?action=stream'; export const CAMERA_BRIDGE_CONFIG_FILE_OVERRIDE = '/data/camera_bridge_config.json'; export const CAMERA_BRIDGE_CONFIG_FILE_HASH = '/data/camera_bridge_config.hash'; export const GPS_MGA_OFFLINE_FILE = '/data/mgaoffline.ubx'; export const GPS_MGA_OFFLINE_HASH = '/data/mgaoffline.hash'; export const DATA_LOGGER_SERVICE = 'hivemapper-data-logger'; export const FOLDER_PURGER_SERVICE = 'hivemapper-folder-purger'; export const MOTION_MODEL_QUERY_WINDOW_SIZE = 8000; export const LTE_FIRMWARE_ROOT = '/data/lte-firmware/'; export const APP_FIRMWARE_ROOT = '/data/'; export const EXTERNAL_PLUGIN_CONFIG_PATH = '/opt/odc-api/odc-api-plugins.json'; export const EMBEDDINGS_CACHE_DIR = '/data/embeddings-cache'; export const BEEKEEPER_PLUGIN = 'beekeeper-plugin'; export const CAMERA_TYPE: CameraType = CameraType.Bee; export const CMD = { RESTART_CAMERA: 'systemctl restart camera-bridge', START_CAMERA: 'systemctl start camera-bridge', STOP_CAMERA: 'systemctl stop camera-bridge', START_PREVIEW: 'systemctl start camera-preview', STOP_PREVIEW: 'systemctl stop camera-preview', READ_DEVICE_INFO: '/opt/dashcam/bin/eeprom_access.py -r -f /tmp/dump.bin -o 0 -l 30', DEVICE_SSID: 'cat /sys/firmware/devicetree/base/serial-number', DELETE_FIRMWARE_FILES: `rm -rf ${LTE_FIRMWARE_ROOT}*.raucb && rm -rf ${APP_FIRMWARE_ROOT}*.raucb`, }; export const configureOnBoot = async (req: Request, res: Response) => { // If anything needs to be done on boot for HDC-S // Placeholder res.json({ output: 'done', }); }; export const updateFirmware = async (req: Request, res: Response) => { // Execute utility to update the firmware using the image file that was uploaded to /tmp/ try { const output = execSync('mender -install /data/' + req.query.filename, { encoding: 'utf-8', }); res.json({ output, }); } catch (error: any) { res.json({ error: error.stdout || error.stderr }); } }; export const switchToP2P = async (req: Request, res: Response) => { try { writeFile( NETWORK_BOOT_CONFIG_PATH, `P2P, ${req.body.deviceName}`, null, () => { exec(__dirname + '/network/wifi_switch_P2P.sh'); }, ); } catch (e: unknown) { console.log(e); } res.json({ output: 'done', }); }; export const switchToAP = async (req: Request, res: Response) => { try { writeFile(NETWORK_BOOT_CONFIG_PATH, 'AP', null, () => { exec(__dirname + '/network/wifi_switch_AP.sh'); }); } catch (e: unknown) { console.log(e); } res.json({ output: 'done', }); };