Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d8623cdcd0 | ||
|
|
9b633e5966 | ||
|
|
7a9fa12c3b | ||
|
|
ae26ad9b51 |
No files matched your search
+26
-17
@@ -4,9 +4,12 @@ on:
|
|||||||
push:
|
push:
|
||||||
pull_request:
|
pull_request:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
env:
|
tag:
|
||||||
rust_version: "1.82.0"
|
description: 'Tag to force the cross build on'
|
||||||
|
required: false
|
||||||
|
type: string
|
||||||
|
default: ''
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
pre_job:
|
pre_job:
|
||||||
@@ -31,22 +34,22 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-22.04, windows-2022, macos-13, macos-14] # macos-14+ is arm64
|
os: [ubuntu-22.04, windows-2022, macos-12, macos-14] # macos-14+ is arm64
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
name: Checkout onto ${{ runner.os }}
|
name: Checkout onto ${{ runner.os }}
|
||||||
- if: runner.os == 'Linux'
|
- if: runner.os == 'Linux'
|
||||||
name: apt install linux deps
|
name: apt install gstreamer
|
||||||
run: |
|
run: |
|
||||||
sudo apt update
|
sudo apt update
|
||||||
sudo apt install -y aptitude
|
sudo apt install -y aptitude
|
||||||
sudo aptitude install -y libgstrtspserver-1.0-dev libgstreamer1.0-dev libgtk2.0-dev protobuf-compiler libssl-dev
|
sudo aptitude install -y libgstrtspserver-1.0-dev libgstreamer1.0-dev libgtk2.0-dev protobuf-compiler libssl-dev
|
||||||
- if: runner.os == 'Windows'
|
- if: runner.os == 'Windows'
|
||||||
name: Install Windows deps
|
name: Install Gstreamer
|
||||||
run: |
|
run: |
|
||||||
# Gstreamer
|
# Gstreamer
|
||||||
choco install -y --no-progress gstreamer --version=1.24.2
|
choco install -y --no-progress gstreamer --version=1.20.0
|
||||||
choco install -y --no-progress gstreamer-devel --version=1.24.2
|
choco install -y --no-progress gstreamer-devel --version=1.20.0
|
||||||
$env:GSTREAMER_1_0_ROOT_MSVC_X86_64=$env:SYSTEMDRIVE + '\gstreamer\1.0\msvc_x86_64\'
|
$env:GSTREAMER_1_0_ROOT_MSVC_X86_64=$env:SYSTEMDRIVE + '\gstreamer\1.0\msvc_x86_64\'
|
||||||
# Github runners work on both C or D drive and figuring out which was used is difficult
|
# Github runners work on both C or D drive and figuring out which was used is difficult
|
||||||
if (-not (Test-Path -Path "$env:GSTREAMER_1_0_ROOT_MSVC_X86_64" -PathType Container)) {
|
if (-not (Test-Path -Path "$env:GSTREAMER_1_0_ROOT_MSVC_X86_64" -PathType Container)) {
|
||||||
@@ -74,19 +77,23 @@ jobs:
|
|||||||
$env:OPENSSL_DIR='D:\\Program Files\OpenSSL\'
|
$env:OPENSSL_DIR='D:\\Program Files\OpenSSL\'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Set up pkgconfig for gstreamer
|
||||||
|
$env:PKG_CONFIG_PATH += ';' + $env:GSTREAMER_1_0_ROOT_MSVC_X86_64 + '\lib\pkgconfig'
|
||||||
|
|
||||||
# Set github vars
|
# Set github vars
|
||||||
Add-Content -Path $env:GITHUB_ENV -Value "GSTREAMER_1_0_ROOT_MSVC_X86_64=$env:GSTREAMER_1_0_ROOT_MSVC_X86_64"
|
Add-Content -Path $env:GITHUB_ENV -Value "GSTREAMER_1_0_ROOT_MSVC_X86_64=$env:GSTREAMER_1_0_ROOT_MSVC_X86_64"
|
||||||
Add-Content -Path $env:GITHUB_PATH -Value "$env:GSTREAMER_1_0_ROOT_MSVC_X86_64\bin"
|
Add-Content -Path $env:GITHUB_PATH -Value "$env:GSTREAMER_1_0_ROOT_MSVC_X86_64\bin"
|
||||||
Add-Content -Path $env:GITHUB_PATH -Value "%GSTREAMER_1_0_ROOT_MSVC_X86_64%\bin"
|
Add-Content -Path $env:GITHUB_PATH -Value "%GSTREAMER_1_0_ROOT_MSVC_X86_64%\bin"
|
||||||
Add-Content -Path $env:GITHUB_ENV -Value "OPENSSL_DIR=$env:OPENSSL_DIR"
|
Add-Content -Path $env:GITHUB_ENV -Value "OPENSSL_DIR=$env:OPENSSL_DIR"
|
||||||
|
Add-Content -Path $env:GITHUB_ENV -Value "PKG_CONFIG_PATH=$env:PKG_CONFIG_PATH"
|
||||||
|
|
||||||
# One last check on directories
|
# One last check on directories
|
||||||
dir "$env:GSTREAMER_1_0_ROOT_MSVC_X86_64"
|
dir "$env:GSTREAMER_1_0_ROOT_MSVC_X86_64"
|
||||||
dir "$env:OPENSSL_DIR"
|
dir "$env:OPENSSL_DIR"
|
||||||
- if: runner.os == 'macOS'
|
- if: runner.os == 'macOS'
|
||||||
name: Install macOS deps
|
name: Install Gstreamer on macOS
|
||||||
run: |
|
run: |
|
||||||
curl -L 'https://gstreamer.freedesktop.org/data/pkg/osx/1.24.11/gstreamer-1.0-devel-1.24.11-universal.pkg' -o "$(pwd)/gstreamer-devel.pkg"
|
curl -L 'https://gstreamer.freedesktop.org/data/pkg/osx/1.20.4/gstreamer-1.0-devel-1.20.4-universal.pkg' -o "$(pwd)/gstreamer-devel.pkg"
|
||||||
sudo installer -verbose -pkg "$(pwd)/gstreamer-devel.pkg" -target /
|
sudo installer -verbose -pkg "$(pwd)/gstreamer-devel.pkg" -target /
|
||||||
PKG_CONFIG_PATH="/Library/Frameworks/GStreamer.framework/Versions/1.0/lib/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}"
|
PKG_CONFIG_PATH="/Library/Frameworks/GStreamer.framework/Versions/1.0/lib/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}"
|
||||||
PKG_CONFIG_GSTREAMER_1_0_PREFIX="/Library/Frameworks/GStreamer.framework/Versions/1.0"
|
PKG_CONFIG_GSTREAMER_1_0_PREFIX="/Library/Frameworks/GStreamer.framework/Versions/1.0"
|
||||||
@@ -130,7 +137,7 @@ jobs:
|
|||||||
if: needs.pre_job.outputs.should_skip != 'true'
|
if: needs.pre_job.outputs.should_skip != 'true'
|
||||||
name: cross
|
name: cross
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container: "node:current-bookworm-slim"
|
container: "node:current-bullseye-slim"
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
@@ -157,6 +164,8 @@ jobs:
|
|||||||
pkgconfig: i386-linux-gnu
|
pkgconfig: i386-linux-gnu
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
ref: ${{ github.event.inputs.tag }}
|
||||||
- name: Install basic tools
|
- name: Install basic tools
|
||||||
run: |
|
run: |
|
||||||
apt-get update
|
apt-get update
|
||||||
@@ -181,7 +190,7 @@ jobs:
|
|||||||
echo "${HOME}/.cargo/bin" >> "${GITHUB_PATH}"
|
echo "${HOME}/.cargo/bin" >> "${GITHUB_PATH}"
|
||||||
- name: Install ${{ matrix.arch }} Rust toolchain
|
- name: Install ${{ matrix.arch }} Rust toolchain
|
||||||
run: |
|
run: |
|
||||||
rustup default "${{ env.rust_version }}"
|
rustup default 1.79.0
|
||||||
rustup target add ${TARGET}
|
rustup target add ${TARGET}
|
||||||
env:
|
env:
|
||||||
TARGET: ${{ matrix.target }}
|
TARGET: ${{ matrix.target }}
|
||||||
@@ -217,6 +226,8 @@ jobs:
|
|||||||
SECRET: "${{ secrets.DOCKER_TOKEN }}"
|
SECRET: "${{ secrets.DOCKER_TOKEN }}"
|
||||||
- name: Check out the repo
|
- name: Check out the repo
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
ref: ${{ github.event.inputs.tag }}
|
||||||
if: ${{ steps.vars.outputs.HAS_SECRET_TOKEN }}
|
if: ${{ steps.vars.outputs.HAS_SECRET_TOKEN }}
|
||||||
- name: Convert username to lower case for docker
|
- name: Convert username to lower case for docker
|
||||||
id: string_user
|
id: string_user
|
||||||
@@ -286,9 +297,8 @@ jobs:
|
|||||||
echo "TAGS=${tagstr}" >> "${GITHUB_OUTPUT}"
|
echo "TAGS=${tagstr}" >> "${GITHUB_OUTPUT}"
|
||||||
env:
|
env:
|
||||||
REPO_NAME: ${{ steps.docker_repo.outputs.DOCKER_NWO }}
|
REPO_NAME: ${{ steps.docker_repo.outputs.DOCKER_NWO }}
|
||||||
- name: Install rust
|
- name: Install latest rust
|
||||||
run: |
|
run: |
|
||||||
rustup default "${{ env.rust_version }}"
|
|
||||||
rustup toolchain install stable
|
rustup toolchain install stable
|
||||||
- name: Install toml-cli
|
- name: Install toml-cli
|
||||||
run: |
|
run: |
|
||||||
@@ -346,9 +356,8 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
- name: Install rust
|
- name: Install latest rust
|
||||||
run: |
|
run: |
|
||||||
rustup default "${{ env.rust_version }}"
|
|
||||||
rustup toolchain install stable
|
rustup toolchain install stable
|
||||||
- name: Install toml-cli
|
- name: Install toml-cli
|
||||||
run: |
|
run: |
|
||||||
@@ -366,7 +375,7 @@ jobs:
|
|||||||
- name: Download Macos
|
- name: Download Macos
|
||||||
uses: actions/download-artifact@v4
|
uses: actions/download-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: release-macos-13
|
name: release-macos-12
|
||||||
path: neolink_macos_intel
|
path: neolink_macos_intel
|
||||||
- name: Download Macos arm64
|
- name: Download Macos arm64
|
||||||
uses: actions/download-artifact@v4
|
uses: actions/download-artifact@v4
|
||||||
|
|||||||
@@ -35,13 +35,9 @@ jobs:
|
|||||||
rustup override set nightly
|
rustup override set nightly
|
||||||
- name: Run clippy manually
|
- name: Run clippy manually
|
||||||
run: |
|
run: |
|
||||||
echo "All Features"
|
|
||||||
cargo +nightly clippy --workspace --all-targets --all-features || exit 1
|
cargo +nightly clippy --workspace --all-targets --all-features || exit 1
|
||||||
echo "No Features"
|
|
||||||
cargo +nightly clippy --workspace --all-targets --no-default-features || exit 1
|
cargo +nightly clippy --workspace --all-targets --no-default-features || exit 1
|
||||||
echo "Gstreamer Only"
|
|
||||||
cargo +nightly clippy --workspace --all-targets --no-default-features --features=gstreamer || exit 1
|
cargo +nightly clippy --workspace --all-targets --no-default-features --features=gstreamer || exit 1
|
||||||
echo "Pushnoti Only"
|
|
||||||
cargo +nightly clippy --workspace --all-targets --no-default-features --features=pushnoti || exit 1
|
cargo +nightly clippy --workspace --all-targets --no-default-features --features=pushnoti || exit 1
|
||||||
|
|
||||||
check_fmt:
|
check_fmt:
|
||||||
|
|||||||
+1
-1
@@ -27,4 +27,4 @@
|
|||||||
token.toml
|
token.toml
|
||||||
|
|
||||||
# Debug FCM build
|
# Debug FCM build
|
||||||
crates/fcm-push-listener
|
./crates/fcm-push-listener/
|
||||||
Generated
+22
-3
@@ -1,6 +1,6 @@
|
|||||||
# This file is automatically @generated by Cargo.
|
# This file is automatically @generated by Cargo.
|
||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 4
|
version = 3
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "addr2line"
|
name = "addr2line"
|
||||||
@@ -839,6 +839,25 @@ dependencies = [
|
|||||||
"webpki-roots",
|
"webpki-roots",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fcm-push-listener"
|
||||||
|
version = "3.0.0"
|
||||||
|
dependencies = [
|
||||||
|
"base64 0.21.7",
|
||||||
|
"ece",
|
||||||
|
"log",
|
||||||
|
"prost",
|
||||||
|
"prost-build",
|
||||||
|
"rand",
|
||||||
|
"reqwest",
|
||||||
|
"serde",
|
||||||
|
"serde_with",
|
||||||
|
"tokio",
|
||||||
|
"tokio-rustls 0.23.4",
|
||||||
|
"uuid",
|
||||||
|
"webpki-roots",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fixedbitset"
|
name = "fixedbitset"
|
||||||
version = "0.4.2"
|
version = "0.4.2"
|
||||||
@@ -1876,7 +1895,7 @@ dependencies = [
|
|||||||
"crossbeam-channel",
|
"crossbeam-channel",
|
||||||
"dirs",
|
"dirs",
|
||||||
"env_logger 0.11.3",
|
"env_logger 0.11.3",
|
||||||
"fcm-push-listener",
|
"fcm-push-listener 2.0.3",
|
||||||
"futures",
|
"futures",
|
||||||
"gstreamer",
|
"gstreamer",
|
||||||
"gstreamer-app",
|
"gstreamer-app",
|
||||||
@@ -2320,7 +2339,7 @@ dependencies = [
|
|||||||
"anyhow",
|
"anyhow",
|
||||||
"clap",
|
"clap",
|
||||||
"env_logger 0.10.2",
|
"env_logger 0.10.2",
|
||||||
"fcm-push-listener",
|
"fcm-push-listener 2.0.3",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"log",
|
"log",
|
||||||
"neolink_core",
|
"neolink_core",
|
||||||
|
|||||||
+1
-1
@@ -47,7 +47,7 @@ validator = {version="0.18.1", features = ["derive"] }
|
|||||||
tikv-jemallocator = "0.5"
|
tikv-jemallocator = "0.5"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["gstreamer"]
|
default = ["gstreamer", "pushnoti"]
|
||||||
gstreamer = [
|
gstreamer = [
|
||||||
"dep:gstreamer",
|
"dep:gstreamer",
|
||||||
"dep:gstreamer-app",
|
"dep:gstreamer-app",
|
||||||
|
|||||||
@@ -243,20 +243,6 @@ Status Messages:
|
|||||||
pir status
|
pir status
|
||||||
- `/status/motion` Contains the motion detection alarm status. `on` for motion
|
- `/status/motion` Contains the motion detection alarm status. `on` for motion
|
||||||
and `off` for still, only published when `enable_moton` is true in the config
|
and `off` for still, only published when `enable_moton` is true in the config
|
||||||
- `/status/visitor` Contains the visitor detection status, which occurs when a
|
|
||||||
doorbell is pressed.
|
|
||||||
- `/status/ai` Contains the ai detection status, which occurs when a
|
|
||||||
the camera's internal ai detects something. The value is `person/car/other`
|
|
||||||
- `/status/ai/person` Contains the ai detection status of the last person,
|
|
||||||
which occurs when a the camera's internal ai detects a person.
|
|
||||||
- `/status/ai/car` Contains the ai detection status of the last car, which
|
|
||||||
occurs when a the camera's internal ai detects a car.
|
|
||||||
- `/status/ai/other` Contains the ai detection status from the camera, which
|
|
||||||
occurs when a the camera's internal ai detects something.
|
|
||||||
|
|
||||||
(This is a placeholder until I can fiquire out everything that the camera
|
|
||||||
can detect. If you have list for me please open an issue with it, I don't
|
|
||||||
have a cam with AI to check myself)
|
|
||||||
- `/status/ptz/preset` Sent in reply to a `/query/ptz/preset` an XML encoded
|
- `/status/ptz/preset` Sent in reply to a `/query/ptz/preset` an XML encoded
|
||||||
version of the PTZ presets
|
version of the PTZ presets
|
||||||
- `/status/preview` a base64 encoded camera image updated every 2s. Not
|
- `/status/preview` a base64 encoded camera image updated every 2s. Not
|
||||||
@@ -339,14 +325,6 @@ enable_motion = false # motion detection
|
|||||||
# (limited battery drain since it
|
# (limited battery drain since it
|
||||||
# is a passive listening connection)
|
# is a passive listening connection)
|
||||||
#
|
#
|
||||||
enable_visitor = false # visitor press for doorbell camera
|
|
||||||
# (limited battery drain since it
|
|
||||||
# is a passive listening connection)
|
|
||||||
#
|
|
||||||
enable_ai = false # report detected ai by the camera
|
|
||||||
# (limited battery drain since it
|
|
||||||
# is a passive listening connection)
|
|
||||||
#
|
|
||||||
enable_light = false # flood lights only available on some camera
|
enable_light = false # flood lights only available on some camera
|
||||||
# (limited battery drain since it
|
# (limited battery drain since it
|
||||||
# is a passive listening connection)
|
# is a passive listening connection)
|
||||||
@@ -396,36 +374,6 @@ Available features are:
|
|||||||
- `battery`: This adds a battery level sensor to home assistant
|
- `battery`: This adds a battery level sensor to home assistant
|
||||||
- `siren`: Adds a siren button to home assistant
|
- `siren`: Adds a siren button to home assistant
|
||||||
|
|
||||||
### Extra Camera Settings
|
|
||||||
|
|
||||||
Listed below are extra camera settings:
|
|
||||||
|
|
||||||
```toml
|
|
||||||
[[cameras]]
|
|
||||||
name = "Camera01"
|
|
||||||
username = "admin"
|
|
||||||
password = "password"
|
|
||||||
uid = "ABCDEF0123456789"
|
|
||||||
debug = false # Displays Debug XML messages from camera
|
|
||||||
enabled = true # Enable or Disable the camera
|
|
||||||
update_time = false # When camera connects, force the setting of the camera date/time to now. The default is false
|
|
||||||
print_format = "None" # Type of format that logs are displayed in (None, Human, Xml). The default is None
|
|
||||||
```
|
|
||||||
|
|
||||||
- **Debug:** Will dump the various XMLs from the camera as they are recieved
|
|
||||||
and decrypted. Leave this off unless asked for it to fix an issue.
|
|
||||||
|
|
||||||
- **Enabled:** Useful if you want to remove a camera from rtsp without deleting
|
|
||||||
it from the config
|
|
||||||
|
|
||||||
- **update_time:** Used to FORCE an update on the camera time. Usually it checks
|
|
||||||
if it is needed but this
|
|
||||||
will force it regardless. (Mostly this was introduced to address a specific
|
|
||||||
ssue a user had)
|
|
||||||
|
|
||||||
- **print_format:** Used for adjusting printing of some values mostly, battery
|
|
||||||
messages
|
|
||||||
|
|
||||||
### Pause
|
### Pause
|
||||||
|
|
||||||
To use the pause feature you will need to adjust your config file as such:
|
To use the pause feature you will need to adjust your config file as such:
|
||||||
@@ -477,10 +425,6 @@ after it stops being used.
|
|||||||
Neolink considers it as being used if there is an active stream running, or
|
Neolink considers it as being used if there is an active stream running, or
|
||||||
if there is motion being detected or an mqtt command being run
|
if there is motion being detected or an mqtt command being run
|
||||||
|
|
||||||
[Because google remove the api for the push notifications we cannot
|
|
||||||
reliably use push notifications to wake up, so motion won't wake
|
|
||||||
up neolink anymore]
|
|
||||||
|
|
||||||
You can make neolink stop active streams when there are no rtsp clients using
|
You can make neolink stop active streams when there are no rtsp clients using
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
@@ -491,11 +435,9 @@ You can make neolink stop active streams when there are no rtsp clients using
|
|||||||
Once in the disconnected state. Neolink will stay disconnected until there is a
|
Once in the disconnected state. Neolink will stay disconnected until there is a
|
||||||
new requested activation such as a client connecting or an mqtt command
|
new requested activation such as a client connecting or an mqtt command
|
||||||
|
|
||||||
~Neolink will also wake up on push notifications from the camera. These are usually
|
Neolink will also wake up on push notifications from the camera. These are usually
|
||||||
sent by the camera on motion or PIR alarms. To disable this you can set
|
sent by the camera on motion or PIR alarms. To disable this you can set
|
||||||
`push_notifications = false` in the `[[cameras]]` config~
|
`push_notifications = false` in the `[[cameras]]` config
|
||||||
|
|
||||||
[Google removed the apis we were using for push notifications]
|
|
||||||
|
|
||||||
### Docker
|
### Docker
|
||||||
|
|
||||||
|
|||||||
@@ -90,8 +90,10 @@ fn bc_modern_msg<'a>(
|
|||||||
E::add_context(input, ctx, E::from_error_kind(input, kind))
|
E::add_context(input, ctx, E::from_error_kind(input, kind))
|
||||||
}
|
}
|
||||||
|
|
||||||
// If missing payload_offset treat all as payload
|
let ext_len = match header.payload_offset {
|
||||||
let ext_len = header.payload_offset.unwrap_or_default();
|
Some(off) => off,
|
||||||
|
_ => 0, // If missing payload_offset treat all as payload
|
||||||
|
};
|
||||||
|
|
||||||
let (buf, ext_buf) = take(ext_len)(buf)?;
|
let (buf, ext_buf) = take(ext_len)(buf)?;
|
||||||
let payload_len = header.body_len - ext_len;
|
let payload_len = header.body_len - ext_len;
|
||||||
|
|||||||
@@ -192,11 +192,8 @@ pub struct BcMeta {
|
|||||||
pub stream_type: u8,
|
pub stream_type: u8,
|
||||||
/// On modern messages this is the response code
|
/// On modern messages this is the response code
|
||||||
/// When sending a command it is set to `0`. The reply from the camera can be
|
/// When sending a command it is set to `0`. The reply from the camera can be
|
||||||
///
|
|
||||||
/// - `200` for OK
|
/// - `200` for OK
|
||||||
///
|
|
||||||
/// - `400` for bad request
|
/// - `400` for bad request
|
||||||
///
|
|
||||||
/// A malformed packet will return a `400` code
|
/// A malformed packet will return a `400` code
|
||||||
pub response_code: u16,
|
pub response_code: u16,
|
||||||
/// A message ID is used to match replies with requests. The camera will parrot back
|
/// A message ID is used to match replies with requests. The camera will parrot back
|
||||||
@@ -216,6 +213,14 @@ pub struct BcMeta {
|
|||||||
pub class: u16,
|
pub class: u16,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The components of the Baichuan header that must be filled out after the body is serialized, or
|
||||||
|
/// is needed for the deserialization of the body (strictly part of the wire format of the message)
|
||||||
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
|
pub(super) struct BcSendInfo {
|
||||||
|
pub body_len: u32,
|
||||||
|
pub payload_offset: Option<u32>,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) struct BcContext {
|
pub(crate) struct BcContext {
|
||||||
pub(crate) credentials: Credentials,
|
pub(crate) credentials: Credentials,
|
||||||
|
|||||||
@@ -633,15 +633,11 @@ pub struct AlarmEvent {
|
|||||||
/// The channel the event occured on. Usually zero unless from an NVR
|
/// The channel the event occured on. Usually zero unless from an NVR
|
||||||
#[serde(rename = "channelId")]
|
#[serde(rename = "channelId")]
|
||||||
pub channel_id: u8,
|
pub channel_id: u8,
|
||||||
/// Motion status. Known values are `"MD"` or `"none"` or `"visitor"`
|
/// Motion status. Known values are `"MD"` or `"none"`
|
||||||
pub status: String,
|
pub status: String,
|
||||||
/// AI status. Known values are `"people"` or `"none"`
|
/// AI status. Known values are `"people"` or `"none"`
|
||||||
#[serde(
|
#[serde(rename = "AItype", skip_serializing_if = "Option::is_none")]
|
||||||
rename = "AItype",
|
pub ai_type: Option<String>,
|
||||||
default = "ai_type_default",
|
|
||||||
skip_serializing_if = "ai_type_skip"
|
|
||||||
)]
|
|
||||||
pub ai_type: String,
|
|
||||||
/// The recording status. Known values `0` or `1`
|
/// The recording status. Known values `0` or `1`
|
||||||
pub recording: i32,
|
pub recording: i32,
|
||||||
/// The timestamp associated with the recording. `0` if not recording
|
/// The timestamp associated with the recording. `0` if not recording
|
||||||
@@ -649,13 +645,6 @@ pub struct AlarmEvent {
|
|||||||
pub timeStamp: i32,
|
pub timeStamp: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ai_type_default() -> String {
|
|
||||||
"none".to_string()
|
|
||||||
}
|
|
||||||
fn ai_type_skip(value: &String) -> bool {
|
|
||||||
value == "none"
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The Ptz messages used to move the camera
|
/// The Ptz messages used to move the camera
|
||||||
#[derive(PartialEq, Default, Debug, Deserialize, Serialize)]
|
#[derive(PartialEq, Default, Debug, Deserialize, Serialize)]
|
||||||
pub struct PtzControl {
|
pub struct PtzControl {
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ pub use credentials::*;
|
|||||||
pub use errors::Error;
|
pub use errors::Error;
|
||||||
pub use ledstate::LightState;
|
pub use ledstate::LightState;
|
||||||
pub use login::MaxEncryption;
|
pub use login::MaxEncryption;
|
||||||
pub use motion::{AiKind, MotionData, MotionEvents};
|
pub use motion::{MotionData, MotionStatus};
|
||||||
pub use pirstate::PirState;
|
pub use pirstate::PirState;
|
||||||
pub use ptz::Direction;
|
pub use ptz::Direction;
|
||||||
pub use pushinfo::PhoneType;
|
pub use pushinfo::PhoneType;
|
||||||
|
|||||||
@@ -20,9 +20,9 @@ pub struct BcStream<'a> {
|
|||||||
rx: &'a mut ReceiverStream<Result<Bc>>,
|
rx: &'a mut ReceiverStream<Result<Bc>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Unpin for BcStream<'_> {}
|
impl<'a> Unpin for BcStream<'a> {}
|
||||||
|
|
||||||
impl Stream for BcStream<'_> {
|
impl<'a> Stream for BcStream<'a> {
|
||||||
type Item = Result<Bc>;
|
type Item = Result<Bc>;
|
||||||
|
|
||||||
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Result<Bc>>> {
|
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Result<Bc>>> {
|
||||||
|
|||||||
@@ -5,46 +5,25 @@ use tokio::sync::mpsc::{channel, error::TryRecvError, Receiver};
|
|||||||
use tokio::task::JoinSet;
|
use tokio::task::JoinSet;
|
||||||
use tokio_util::sync::CancellationToken;
|
use tokio_util::sync::CancellationToken;
|
||||||
|
|
||||||
/// Motion Events that the callback can send
|
/// Motion Status that the callback can send
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
pub enum MotionEvents {
|
pub enum MotionStatus {
|
||||||
/// Sent when motion is first detected
|
/// Sent when motion is first detected
|
||||||
Start(Instant),
|
Start(Instant),
|
||||||
/// Sent when motion stops
|
/// Sent when motion stops
|
||||||
Stop(Instant),
|
Stop(Instant),
|
||||||
/// Sent when a doorbell is pressed
|
|
||||||
Vistor(Instant),
|
|
||||||
/// Sent when an AI is recieved
|
|
||||||
Ai(Instant, AiKind),
|
|
||||||
/// Sent when an Alarm about something other than motion was received
|
/// Sent when an Alarm about something other than motion was received
|
||||||
NoChange(Instant),
|
NoChange(Instant),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
|
||||||
/// The kinds of objects the AI can detect
|
|
||||||
pub enum AiKind {
|
|
||||||
/// A person
|
|
||||||
Person,
|
|
||||||
/// A car
|
|
||||||
Car,
|
|
||||||
/// Something else, open a PR to fix with actual thing
|
|
||||||
Other,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A handle on current motion related events comming from the camera
|
/// A handle on current motion related events comming from the camera
|
||||||
///
|
///
|
||||||
/// When this object is dropped the motion events are stopped
|
/// When this object is dropped the motion events are stopped
|
||||||
pub struct MotionData {
|
pub struct MotionData {
|
||||||
handle: JoinSet<Result<()>>,
|
handle: JoinSet<Result<()>>,
|
||||||
cancel: CancellationToken,
|
cancel: CancellationToken,
|
||||||
rx: Receiver<Result<MotionEvents>>,
|
rx: Receiver<Result<MotionStatus>>,
|
||||||
history: MotionHistory,
|
last_update: MotionStatus,
|
||||||
}
|
|
||||||
|
|
||||||
pub struct MotionHistory {
|
|
||||||
motion: MotionEvents,
|
|
||||||
visitor: MotionEvents,
|
|
||||||
ai: MotionEvents,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MotionData {
|
impl MotionData {
|
||||||
@@ -54,10 +33,10 @@ impl MotionData {
|
|||||||
/// An error is raised if the motion connection to the camera is dropped
|
/// An error is raised if the motion connection to the camera is dropped
|
||||||
pub fn motion_detected(&mut self) -> Result<Option<bool>> {
|
pub fn motion_detected(&mut self) -> Result<Option<bool>> {
|
||||||
self.consume_motion_events()?;
|
self.consume_motion_events()?;
|
||||||
Ok(match &self.history.motion {
|
Ok(match &self.last_update {
|
||||||
MotionEvents::Start(_) => Some(true),
|
MotionStatus::Start(_) => Some(true),
|
||||||
MotionEvents::Stop(_) => Some(false),
|
MotionStatus::Stop(_) => Some(false),
|
||||||
_ => None,
|
MotionStatus::NoChange(_) => None,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,64 +46,44 @@ impl MotionData {
|
|||||||
/// An error is raised if the motion connection to the camera is dropped
|
/// An error is raised if the motion connection to the camera is dropped
|
||||||
pub fn motion_detected_within(&mut self, duration: Duration) -> Result<Option<bool>> {
|
pub fn motion_detected_within(&mut self, duration: Duration) -> Result<Option<bool>> {
|
||||||
self.consume_motion_events()?;
|
self.consume_motion_events()?;
|
||||||
Ok(match &self.history.motion {
|
Ok(match &self.last_update {
|
||||||
MotionEvents::Start(_) => Some(true),
|
MotionStatus::Start(_) => Some(true),
|
||||||
MotionEvents::Stop(time) => Some((Instant::now() - *time) < duration),
|
MotionStatus::Stop(time) => Some((Instant::now() - *time) < duration),
|
||||||
_ => None,
|
MotionStatus::NoChange(_) => None,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Consume all the motion events on the queue and update the history
|
/// Consume the motion events diretly
|
||||||
///
|
///
|
||||||
/// An error is raised if the motion connection to the camera is dropped
|
/// An error is raised if the motion connection to the camera is dropped
|
||||||
pub fn consume_motion_events(&mut self) -> Result<()> {
|
pub fn consume_motion_events(&mut self) -> Result<Vec<MotionStatus>> {
|
||||||
while self.try_recv()?.is_some() {
|
let mut results: Vec<MotionStatus> = vec![];
|
||||||
// Tight loop....
|
loop {
|
||||||
// Should not be many of such messages in the queue though
|
match self.rx.try_recv() {
|
||||||
|
Ok(motion) => results.push(motion?),
|
||||||
|
Err(TryRecvError::Empty) => break,
|
||||||
|
Err(e) => return Err(Error::from(e)),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
if let Some(last) = results.last() {
|
||||||
}
|
self.last_update = *last;
|
||||||
|
|
||||||
fn update_history(&mut self, latest_event: &MotionEvents) {
|
|
||||||
match latest_event {
|
|
||||||
MotionEvents::Start(_) => {
|
|
||||||
self.history.motion = *latest_event;
|
|
||||||
}
|
|
||||||
MotionEvents::Stop(_) => {
|
|
||||||
self.history.motion = *latest_event;
|
|
||||||
}
|
|
||||||
MotionEvents::Vistor(_) => {
|
|
||||||
self.history.visitor = *latest_event;
|
|
||||||
}
|
|
||||||
MotionEvents::Ai(_, _) => {
|
|
||||||
self.history.ai = *latest_event;
|
|
||||||
}
|
|
||||||
MotionEvents::NoChange(_) => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Try to recv a new motion event on the pipeline
|
|
||||||
pub fn try_recv(&mut self) -> Result<Option<MotionEvents>> {
|
|
||||||
match self.rx.try_recv() {
|
|
||||||
Ok(motion) => {
|
|
||||||
let motion = motion?;
|
|
||||||
self.update_history(&motion);
|
|
||||||
Ok(Some(motion))
|
|
||||||
}
|
|
||||||
Err(TryRecvError::Empty) => Ok(None),
|
|
||||||
Err(e) => Err(Error::from(e)),
|
|
||||||
}
|
}
|
||||||
|
Ok(results)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Await a new motion event
|
/// Await a new motion event
|
||||||
pub async fn recv(&mut self) -> Result<Option<MotionEvents>> {
|
///
|
||||||
match self.rx.recv().await {
|
///
|
||||||
Some(motion) => {
|
pub async fn next_motion(&mut self) -> Result<MotionStatus> {
|
||||||
let motion = motion?;
|
let motions = self.consume_motion_events()?;
|
||||||
self.update_history(&motion);
|
if let Some(last) = motions.last() {
|
||||||
Ok(Some(motion))
|
Ok(*last)
|
||||||
}
|
} else if let Some(moition) = self.rx.recv().await {
|
||||||
None => Ok(None),
|
let moition = moition?;
|
||||||
|
self.last_update = moition;
|
||||||
|
Ok(moition)
|
||||||
|
} else {
|
||||||
|
Err(Error::Other("Motion dropped"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,10 +91,10 @@ impl MotionData {
|
|||||||
///
|
///
|
||||||
/// It must be stopped for at least the given duration
|
/// It must be stopped for at least the given duration
|
||||||
pub async fn await_stop(&mut self, duration: Duration) -> Result<()> {
|
pub async fn await_stop(&mut self, duration: Duration) -> Result<()> {
|
||||||
self.consume_motion_events()?;
|
let motions = self.consume_motion_events()?;
|
||||||
let mut last_motion = self.history.motion;
|
let mut last_motion = motions.last().copied();
|
||||||
loop {
|
loop {
|
||||||
if let MotionEvents::Stop(time) = last_motion {
|
if let Some(MotionStatus::Stop(time)) = last_motion {
|
||||||
// In stop state
|
// In stop state
|
||||||
if duration.is_zero() || (Instant::now() - time) > duration {
|
if duration.is_zero() || (Instant::now() - time) > duration {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
@@ -146,37 +105,22 @@ impl MotionData {
|
|||||||
_ = tokio::time::sleep(remaining_sleep) => {None},
|
_ = tokio::time::sleep(remaining_sleep) => {None},
|
||||||
v = async {
|
v = async {
|
||||||
loop {
|
loop {
|
||||||
match self.recv().await {
|
match self.next_motion().await {
|
||||||
n @ Ok(Some(MotionEvents::Start(_))) => {return n;},
|
n @ Ok(MotionStatus::Start(_)) => {return n;},
|
||||||
n @ Ok(None) => {return n;} // End of data
|
|
||||||
n @ Err(_) => {return n;},
|
n @ Err(_) => {return n;},
|
||||||
_ => {continue;}
|
_ => {continue;}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} => {Some(v)}
|
} => {Some(v)}
|
||||||
};
|
};
|
||||||
match result {
|
if let Some(v) = result {
|
||||||
Some(Ok(None)) => {
|
v?;
|
||||||
// Camera has dropped motion
|
} else {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
|
||||||
Some(Ok(Some(_))) => {
|
|
||||||
// continue to next data
|
|
||||||
}
|
|
||||||
Some(Err(e)) => return Err(e),
|
|
||||||
None => {
|
|
||||||
// Timeout occured motion stopped
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(next_motion) = self.recv().await? {
|
last_motion = Some(self.next_motion().await?);
|
||||||
last_motion = next_motion;
|
|
||||||
} else {
|
|
||||||
// Camera had dropped motion
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,10 +128,10 @@ impl MotionData {
|
|||||||
///
|
///
|
||||||
/// The motion must have a minimum duration as given
|
/// The motion must have a minimum duration as given
|
||||||
pub async fn await_start(&mut self, duration: Duration) -> Result<()> {
|
pub async fn await_start(&mut self, duration: Duration) -> Result<()> {
|
||||||
self.consume_motion_events()?;
|
let motions = self.consume_motion_events()?;
|
||||||
let mut last_motion = self.history.motion;
|
let mut last_motion = motions.last().copied();
|
||||||
loop {
|
loop {
|
||||||
if let MotionEvents::Start(time) = last_motion {
|
if let Some(MotionStatus::Start(time)) = last_motion {
|
||||||
// In start state
|
// In start state
|
||||||
if duration.is_zero() || (Instant::now() - time) > duration {
|
if duration.is_zero() || (Instant::now() - time) > duration {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
@@ -197,37 +141,22 @@ impl MotionData {
|
|||||||
_ = tokio::time::sleep(duration - (Instant::now() - time)) => {None},
|
_ = tokio::time::sleep(duration - (Instant::now() - time)) => {None},
|
||||||
v = async {
|
v = async {
|
||||||
loop {
|
loop {
|
||||||
match self.recv().await {
|
match self.next_motion().await {
|
||||||
n @ Ok(Some(MotionEvents::Stop(_))) => {return n;},
|
n @ Ok(MotionStatus::Stop(_)) => {return n;},
|
||||||
n @ Ok(None) => {return n;} // End of data
|
|
||||||
n @ Err(_) => {return n;},
|
n @ Err(_) => {return n;},
|
||||||
_ => {continue;}
|
_ => {continue;}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} => {Some(v)}
|
} => {Some(v)}
|
||||||
};
|
};
|
||||||
match result {
|
if let Some(v) = result {
|
||||||
Some(Ok(None)) => {
|
v?;
|
||||||
// Camera has dropped motion
|
} else {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
|
||||||
Some(Ok(Some(_))) => {
|
|
||||||
// conitnue to next data
|
|
||||||
}
|
|
||||||
Some(Err(e)) => return Err(e),
|
|
||||||
None => {
|
|
||||||
// Timeout occured motion started
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(next_motion) = self.recv().await? {
|
last_motion = Some(self.next_motion().await?);
|
||||||
last_motion = next_motion;
|
|
||||||
} else {
|
|
||||||
// Camera had dropped motion
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -296,7 +225,7 @@ impl BcCamera {
|
|||||||
loop {
|
loop {
|
||||||
tokio::task::yield_now().await;
|
tokio::task::yield_now().await;
|
||||||
let msg = sub.recv().await;
|
let msg = sub.recv().await;
|
||||||
let status_list = match msg {
|
let status = match msg {
|
||||||
Ok(motion_msg) => {
|
Ok(motion_msg) => {
|
||||||
if let BcBody::ModernMsg(ModernMsg {
|
if let BcBody::ModernMsg(ModernMsg {
|
||||||
payload:
|
payload:
|
||||||
@@ -307,51 +236,36 @@ impl BcCamera {
|
|||||||
..
|
..
|
||||||
}) = motion_msg.body
|
}) = motion_msg.body
|
||||||
{
|
{
|
||||||
let mut result = vec![];
|
let mut result = MotionStatus::NoChange(Instant::now());
|
||||||
for alarm_event in &alarm_event_list.alarm_events {
|
for alarm_event in &alarm_event_list.alarm_events {
|
||||||
if alarm_event.channel_id == channel_id {
|
if alarm_event.channel_id == channel_id {
|
||||||
if alarm_event.status == "visitor" {
|
if alarm_event.status != "none"
|
||||||
result.push(MotionEvents::Vistor(Instant::now()));
|
|| alarm_event
|
||||||
} else if alarm_event.status == "MD" {
|
.ai_type
|
||||||
result.push(MotionEvents::Start(Instant::now()));
|
.as_ref()
|
||||||
} else if alarm_event.ai_type != "none" {
|
.map(|ai_type| ai_type != "none")
|
||||||
result.push(MotionEvents::Ai(Instant::now(),
|
.unwrap_or(false)
|
||||||
match alarm_event.ai_type.as_ref() {
|
{
|
||||||
"person" | "people" | "human" => AiKind::Person,
|
result = MotionStatus::Start(Instant::now());
|
||||||
"car" | "vehicle" => AiKind::Car,
|
break;
|
||||||
_ => AiKind::Other,
|
|
||||||
}
|
|
||||||
));
|
|
||||||
} else {
|
} else {
|
||||||
result.push(MotionEvents::Stop(Instant::now()));
|
result = MotionStatus::Stop(Instant::now());
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(result)
|
Ok(result)
|
||||||
} else {
|
} else {
|
||||||
Ok(vec![])
|
Ok(MotionStatus::NoChange(Instant::now()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// On connection drop we stop
|
// On connection drop we stop
|
||||||
Err(e) => Err(e),
|
Err(e) => Err(e),
|
||||||
};
|
};
|
||||||
|
|
||||||
match status_list {
|
if tx.send(status).await.is_err() {
|
||||||
Ok(mut status_list) => {
|
// Motion reciever has been dropped
|
||||||
for status in status_list.drain(..) {
|
break;
|
||||||
if tx.send(Ok(status)).await.is_err() {
|
|
||||||
// Motion reciever has been dropped
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Err(e) => {
|
|
||||||
// Err from camera
|
|
||||||
if tx.send(Err(e)).await.is_err() {
|
|
||||||
// Motion reciever has been dropped
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -363,11 +277,7 @@ impl BcCamera {
|
|||||||
handle: set,
|
handle: set,
|
||||||
cancel,
|
cancel,
|
||||||
rx,
|
rx,
|
||||||
history: MotionHistory {
|
last_update: MotionStatus::NoChange(Instant::now()),
|
||||||
motion: MotionEvents::NoChange(Instant::now()),
|
|
||||||
visitor: MotionEvents::NoChange(Instant::now()),
|
|
||||||
ai: MotionEvents::NoChange(Instant::now()),
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -214,7 +214,7 @@ impl ToSocketAddrsOrUid for SocketAddrV6 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToSocketAddrsOrUid for &'_ [SocketAddr] {
|
impl<'a> ToSocketAddrsOrUid for &'a [SocketAddr] {
|
||||||
type UidIter = std::vec::IntoIter<SocketAddrOrUid>;
|
type UidIter = std::vec::IntoIter<SocketAddrOrUid>;
|
||||||
|
|
||||||
fn to_socket_addrs_or_uid(&self) -> Result<Self::UidIter, Error> {
|
fn to_socket_addrs_or_uid(&self) -> Result<Self::UidIter, Error> {
|
||||||
|
|||||||
@@ -34,6 +34,15 @@ impl Decoder for BcUdpCodex {
|
|||||||
type Item = BcUdp;
|
type Item = BcUdp;
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
|
|
||||||
|
/// Since frames can cross EOF boundaries we overload this so it doesn't error if
|
||||||
|
/// there are bytes left on the stream
|
||||||
|
// fn decode_eof(&mut self, buf: &mut BytesMut) -> Result<Option<Self::Item>> {
|
||||||
|
// match self.decode(buf)? {
|
||||||
|
// Some(frame) => Ok(Some(frame)),
|
||||||
|
// None => Ok(None),
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
fn decode(&mut self, src: &mut BytesMut) -> Result<Option<Self::Item>> {
|
fn decode(&mut self, src: &mut BytesMut) -> Result<Option<Self::Item>> {
|
||||||
log::trace!("Decoding:");
|
log::trace!("Decoding:");
|
||||||
if src.is_empty() {
|
if src.is_empty() {
|
||||||
|
|||||||
@@ -53,6 +53,14 @@ async fn main() -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_local_ip() -> Result<std::net::IpAddr> {
|
||||||
|
get_if_addrs::get_if_addrs()?
|
||||||
|
.iter()
|
||||||
|
.find(|i| !i.is_loopback() && matches!(i.addr, get_if_addrs::IfAddr::V4(_)))
|
||||||
|
.map(|iface| Ok(iface.ip()))
|
||||||
|
.unwrap_or_else(|| Err(anyhow!("No Local Ip Address Found")))
|
||||||
|
}
|
||||||
|
|
||||||
async fn cam_tasks(name: &str, camera: BcCamera, addr: SocketAddr) -> Result<()> {
|
async fn cam_tasks(name: &str, camera: BcCamera, addr: SocketAddr) -> Result<()> {
|
||||||
let support = camera.get_support().await?;
|
let support = camera.get_support().await?;
|
||||||
if support.email.is_some_and(|v| v > 0) {
|
if support.email.is_some_and(|v| v > 0) {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ edition = "2021"
|
|||||||
anyhow = "1.0.71"
|
anyhow = "1.0.71"
|
||||||
clap = { version = "4.2.2", features = ["derive", "cargo"] }
|
clap = { version = "4.2.2", features = ["derive", "cargo"] }
|
||||||
env_logger = "0.10.0"
|
env_logger = "0.10.0"
|
||||||
|
# fcm-push-listener = { path = "../fcm-push-listener" }
|
||||||
fcm-push-listener = { version = "2.0.3" }
|
fcm-push-listener = { version = "2.0.3" }
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
log = { version = "0.4.17", features = [ "release_max_level_debug" ] }
|
log = { version = "0.4.17", features = [ "release_max_level_debug" ] }
|
||||||
|
|||||||
+253
-25
@@ -5,24 +5,28 @@
|
|||||||
//! The camera watch is used as an event to be triggered
|
//! The camera watch is used as an event to be triggered
|
||||||
//! whenever the camera is lost/updated
|
//! whenever the camera is lost/updated
|
||||||
use anyhow::{anyhow, Context};
|
use anyhow::{anyhow, Context};
|
||||||
use futures::TryFutureExt;
|
use futures::{stream::FuturesUnordered, FutureExt, StreamExt, TryFutureExt};
|
||||||
use std::sync::{Arc, Weak};
|
use std::sync::{Arc, Weak};
|
||||||
|
#[cfg(feature = "pushnoti")]
|
||||||
|
use tokio::sync::watch::channel as watch;
|
||||||
use tokio::{
|
use tokio::{
|
||||||
sync::{
|
sync::{
|
||||||
mpsc::Sender as MpscSender, oneshot::channel as oneshot, watch::Receiver as WatchReceiver,
|
mpsc::Receiver as MpscReceiver, mpsc::Sender as MpscSender, oneshot::channel as oneshot,
|
||||||
|
watch::Receiver as WatchReceiver,
|
||||||
},
|
},
|
||||||
time::{sleep, Duration},
|
time::{sleep, Duration},
|
||||||
};
|
};
|
||||||
use tokio_util::sync::CancellationToken;
|
use tokio_util::sync::CancellationToken;
|
||||||
|
|
||||||
use super::{AiState, MdState, NeoCamCommand, NeoCamThreadState, Permit, VisitorState};
|
|
||||||
use crate::{config::CameraConfig, AnyResult, Result};
|
|
||||||
use neolink_core::bc_protocol::BcCamera;
|
|
||||||
#[cfg(feature = "gstreamer")]
|
|
||||||
mod gst;
|
|
||||||
|
|
||||||
#[cfg(feature = "pushnoti")]
|
#[cfg(feature = "pushnoti")]
|
||||||
mod pushnoti;
|
use super::PushNoti;
|
||||||
|
use super::{MdState, NeoCamCommand, NeoCamThreadState, Permit, UseCounter};
|
||||||
|
use crate::{config::CameraConfig, AnyResult, Result};
|
||||||
|
use neolink_core::{
|
||||||
|
bc_protocol::{BcCamera, StreamKind},
|
||||||
|
bcmedia::model::BcMedia,
|
||||||
|
};
|
||||||
|
#[cfg(feature = "gstreamer")]
|
||||||
|
|
||||||
/// This instance is the primary interface used throughout the app
|
/// This instance is the primary interface used throughout the app
|
||||||
///
|
///
|
||||||
@@ -229,6 +233,50 @@ impl NeoInstance {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "pushnoti")]
|
||||||
|
pub(crate) async fn uid(&self) -> Result<String> {
|
||||||
|
let (reply_tx, reply_rx) = oneshot();
|
||||||
|
self.camera_control
|
||||||
|
.send(NeoCamCommand::GetUid(reply_tx))
|
||||||
|
.await?;
|
||||||
|
Ok(reply_rx.await?)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "pushnoti")]
|
||||||
|
pub(crate) async fn push_notifications(&self) -> Result<WatchReceiver<Option<PushNoti>>> {
|
||||||
|
let uid = self.uid().await?;
|
||||||
|
let (instance_tx, instance_rx) = oneshot();
|
||||||
|
self.camera_control
|
||||||
|
.send(NeoCamCommand::PushNoti(instance_tx))
|
||||||
|
.await?;
|
||||||
|
let mut source_watch = instance_rx.await?;
|
||||||
|
|
||||||
|
let (fwatch_tx, fwatch_rx) = watch(None);
|
||||||
|
tokio::task::spawn(async move {
|
||||||
|
loop {
|
||||||
|
match source_watch
|
||||||
|
.wait_for(|i| {
|
||||||
|
fwatch_tx.borrow().as_ref() != i.as_ref()
|
||||||
|
&& i.as_ref()
|
||||||
|
.is_some_and(|i| i.message.contains(&format!("\"{uid}\"")))
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(pn) => {
|
||||||
|
log::trace!("Forwarding push notification about {}", uid);
|
||||||
|
let _ = fwatch_tx.send_replace(pn.clone());
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
break Err(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}?;
|
||||||
|
AnyResult::Ok(())
|
||||||
|
});
|
||||||
|
|
||||||
|
Ok(fwatch_rx)
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) async fn motion(&self) -> Result<WatchReceiver<MdState>> {
|
pub(crate) async fn motion(&self) -> Result<WatchReceiver<MdState>> {
|
||||||
let (instance_tx, instance_rx) = oneshot();
|
let (instance_tx, instance_rx) = oneshot();
|
||||||
self.camera_control
|
self.camera_control
|
||||||
@@ -237,22 +285,6 @@ impl NeoInstance {
|
|||||||
Ok(instance_rx.await?)
|
Ok(instance_rx.await?)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn visitor(&self) -> Result<WatchReceiver<VisitorState>> {
|
|
||||||
let (instance_tx, instance_rx) = oneshot();
|
|
||||||
self.camera_control
|
|
||||||
.send(NeoCamCommand::Visitor(instance_tx))
|
|
||||||
.await?;
|
|
||||||
Ok(instance_rx.await?)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) async fn ai(&self) -> Result<WatchReceiver<AiState>> {
|
|
||||||
let (instance_tx, instance_rx) = oneshot();
|
|
||||||
self.camera_control
|
|
||||||
.send(NeoCamCommand::Ai(instance_tx))
|
|
||||||
.await?;
|
|
||||||
Ok(instance_rx.await?)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) async fn config(&self) -> Result<WatchReceiver<CameraConfig>> {
|
pub(crate) async fn config(&self) -> Result<WatchReceiver<CameraConfig>> {
|
||||||
let (instance_tx, instance_rx) = oneshot();
|
let (instance_tx, instance_rx) = oneshot();
|
||||||
self.camera_control
|
self.camera_control
|
||||||
@@ -314,6 +346,202 @@ impl NeoInstance {
|
|||||||
timeout,
|
timeout,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Streams a camera source while not paused
|
||||||
|
pub(crate) async fn stream_while_live(
|
||||||
|
&self,
|
||||||
|
stream: StreamKind,
|
||||||
|
) -> AnyResult<MpscReceiver<BcMedia>> {
|
||||||
|
let config = self.config().await?.borrow().clone();
|
||||||
|
let name = config.name.clone();
|
||||||
|
|
||||||
|
let media_rx = if config.pause.on_motion {
|
||||||
|
let (media_tx, media_rx) = tokio::sync::mpsc::channel(100);
|
||||||
|
let counter = UseCounter::new().await;
|
||||||
|
|
||||||
|
let mut md = self.motion().await?;
|
||||||
|
let mut tasks = FuturesUnordered::new();
|
||||||
|
// Stream for 5s on a new client always
|
||||||
|
// This lets us negotiate the camera stream type
|
||||||
|
let init_permit = counter.create_activated().await?;
|
||||||
|
tokio::spawn(
|
||||||
|
async {
|
||||||
|
tokio::time::sleep(tokio::time::Duration::from_secs(5)).await;
|
||||||
|
drop(init_permit);
|
||||||
|
}
|
||||||
|
.map(|e| {
|
||||||
|
log::debug!("Init permit thread stopped {e:?}");
|
||||||
|
e
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Create the permit for controlling the motion
|
||||||
|
let mut md_permit = {
|
||||||
|
let md_state = md.borrow_and_update().clone();
|
||||||
|
match md_state {
|
||||||
|
MdState::Start(_) => {
|
||||||
|
log::info!("{name}::{stream:?}: Starting with Motion");
|
||||||
|
counter.create_activated().await?
|
||||||
|
}
|
||||||
|
MdState::Stop(_) | MdState::Unknown => {
|
||||||
|
log::info!("{name}::{stream:?}: Waiting with Motion");
|
||||||
|
counter.create_deactivated().await?
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// Now listen to the motion
|
||||||
|
let thread_name = name.clone();
|
||||||
|
tasks.push(tokio::spawn(
|
||||||
|
async move {
|
||||||
|
loop {
|
||||||
|
match md.changed().await {
|
||||||
|
Ok(_) => {
|
||||||
|
let md_state: MdState = md.borrow_and_update().clone();
|
||||||
|
match md_state {
|
||||||
|
MdState::Start(_) => {
|
||||||
|
log::info!("{thread_name}::{stream:?}: Motion Started");
|
||||||
|
md_permit.activate().await?;
|
||||||
|
}
|
||||||
|
MdState::Stop(_) => {
|
||||||
|
log::info!("{thread_name}::{stream:?}: Motion Stopped");
|
||||||
|
md_permit.deactivate().await?;
|
||||||
|
}
|
||||||
|
MdState::Unknown => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
// Use break here so we can define the full type on the async closure
|
||||||
|
break AnyResult::Err(e.into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}?;
|
||||||
|
AnyResult::Ok(())
|
||||||
|
}
|
||||||
|
.map(|e| {
|
||||||
|
log::debug!("Motion thread stopped {e:?}");
|
||||||
|
e
|
||||||
|
}),
|
||||||
|
));
|
||||||
|
|
||||||
|
#[cfg(pushnoti)]
|
||||||
|
{
|
||||||
|
// Creates a permit for controlling based on the PN
|
||||||
|
let pn_permit = counter.create_deactivated().await?;
|
||||||
|
let mut pn = self.push_notifications().await?;
|
||||||
|
pn.borrow_and_update(); // Ignore any PNs that have already been sent before this
|
||||||
|
let thread_name = name.clone();
|
||||||
|
tasks.push(tokio::spawn(
|
||||||
|
async move {
|
||||||
|
loop {
|
||||||
|
let noti: Option<PushNoti> = pn.borrow_and_update().clone();
|
||||||
|
if let Some(noti) = noti {
|
||||||
|
if noti.message.contains("Motion Alert from") {
|
||||||
|
log::info!(
|
||||||
|
"{thread_name}::{stream:?}: Push Notification Recieved"
|
||||||
|
);
|
||||||
|
let mut new_pn_permit = pn_permit.subscribe();
|
||||||
|
new_pn_permit.activate().await?;
|
||||||
|
tokio::spawn(async move {
|
||||||
|
tokio::time::sleep(tokio::time::Duration::from_secs(30))
|
||||||
|
.await;
|
||||||
|
drop(new_pn_permit);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let Err(e) = pn.changed().await {
|
||||||
|
break Err(e);
|
||||||
|
}
|
||||||
|
}?;
|
||||||
|
AnyResult::Ok(())
|
||||||
|
}
|
||||||
|
.map(|e| {
|
||||||
|
log::debug!("PN thread stopped {e:?}");
|
||||||
|
e
|
||||||
|
}),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send the camera when the pemit is active
|
||||||
|
let camera_permit = counter.create_deactivated().await?;
|
||||||
|
let thread_camera = self.clone();
|
||||||
|
tokio::spawn(
|
||||||
|
async move {
|
||||||
|
loop {
|
||||||
|
if let Err(e) = camera_permit.aquired_users().await {
|
||||||
|
break AnyResult::Err(e);
|
||||||
|
}
|
||||||
|
log::debug!("Starting stream");
|
||||||
|
tokio::select! {
|
||||||
|
v = camera_permit.dropped_users() => {
|
||||||
|
log::debug!("Dropped users: {v:?}");
|
||||||
|
v
|
||||||
|
},
|
||||||
|
v = async {
|
||||||
|
log::debug!("Getting stream");
|
||||||
|
let mut stream = thread_camera.stream(stream).await?;
|
||||||
|
log::debug!("Got stream");
|
||||||
|
while let Some(media) = stream.recv().await {
|
||||||
|
media_tx.send(media).await?;
|
||||||
|
}
|
||||||
|
AnyResult::Ok(())
|
||||||
|
} => {
|
||||||
|
log::debug!("Stopped stream: {v:?}");
|
||||||
|
v
|
||||||
|
},
|
||||||
|
v = tasks.next() => {
|
||||||
|
log::debug!("Task failed: {v:?}");
|
||||||
|
Err(anyhow!("Task ended prematurly: {v:?}"))
|
||||||
|
}
|
||||||
|
}?;
|
||||||
|
log::debug!("Pausing stream");
|
||||||
|
}?;
|
||||||
|
drop(counter); // Make sure counter is owned by this thread
|
||||||
|
AnyResult::Ok(())
|
||||||
|
}
|
||||||
|
.map(|e| {
|
||||||
|
log::debug!("Stream thread stopped {e:?}");
|
||||||
|
e
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
Ok(media_rx)
|
||||||
|
} else {
|
||||||
|
self.stream(stream).await
|
||||||
|
}?;
|
||||||
|
|
||||||
|
Ok(media_rx)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Streams a camera source
|
||||||
|
pub(crate) async fn stream(&self, stream: StreamKind) -> AnyResult<MpscReceiver<BcMedia>> {
|
||||||
|
let (media_tx, media_rx) = tokio::sync::mpsc::channel(100);
|
||||||
|
let config = self.config().await?.borrow().clone();
|
||||||
|
let strict = config.strict;
|
||||||
|
let thread_camera = self.clone();
|
||||||
|
tokio::task::spawn(
|
||||||
|
tokio::task::spawn(async move {
|
||||||
|
thread_camera
|
||||||
|
.run_task(move |cam| {
|
||||||
|
let media_tx = media_tx.clone();
|
||||||
|
Box::pin(async move {
|
||||||
|
let mut media_stream = cam.start_video(stream, 0, strict).await?;
|
||||||
|
log::trace!("Camera started");
|
||||||
|
while let Ok(media) = media_stream.get_data().await? {
|
||||||
|
media_tx.send(media).await?;
|
||||||
|
}
|
||||||
|
AnyResult::Ok(())
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
})
|
||||||
|
.and_then(|res| async move {
|
||||||
|
log::debug!("Camera finished streaming: {res:?}");
|
||||||
|
Ok(())
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
Ok(media_rx)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// A task that is run on a camera when the structure is dropped
|
// A task that is run on a camera when the structure is dropped
|
||||||
|
|||||||
@@ -1,207 +0,0 @@
|
|||||||
use super::*;
|
|
||||||
|
|
||||||
use crate::common::UseCounter;
|
|
||||||
use futures::{stream::FuturesUnordered, FutureExt, StreamExt};
|
|
||||||
use neolink_core::{bc_protocol::StreamKind, bcmedia::model::BcMedia};
|
|
||||||
use tokio::sync::mpsc::Receiver as MpscReceiver;
|
|
||||||
|
|
||||||
#[cfg(feature = "pushnoti")]
|
|
||||||
use crate::common::PushNoti;
|
|
||||||
|
|
||||||
impl NeoInstance {
|
|
||||||
/// Streams a camera source while not paused
|
|
||||||
pub(crate) async fn stream_while_live(
|
|
||||||
&self,
|
|
||||||
stream: StreamKind,
|
|
||||||
) -> AnyResult<MpscReceiver<BcMedia>> {
|
|
||||||
let config = self.config().await?.borrow().clone();
|
|
||||||
let name = config.name.clone();
|
|
||||||
|
|
||||||
let media_rx = if config.pause.on_motion {
|
|
||||||
let (media_tx, media_rx) = tokio::sync::mpsc::channel(100);
|
|
||||||
let counter = UseCounter::new().await;
|
|
||||||
|
|
||||||
let mut md = self.motion().await?;
|
|
||||||
let mut tasks = FuturesUnordered::new();
|
|
||||||
// Stream for 5s on a new client always
|
|
||||||
// This lets us negotiate the camera stream type
|
|
||||||
let init_permit = counter.create_activated().await?;
|
|
||||||
tokio::spawn(
|
|
||||||
async {
|
|
||||||
tokio::time::sleep(tokio::time::Duration::from_secs(5)).await;
|
|
||||||
drop(init_permit);
|
|
||||||
}
|
|
||||||
.map(|e| {
|
|
||||||
log::debug!("Init permit thread stopped {e:?}");
|
|
||||||
e
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Create the permit for controlling the motion
|
|
||||||
let mut md_permit = {
|
|
||||||
let md_state = md.borrow_and_update().clone();
|
|
||||||
match md_state {
|
|
||||||
MdState::Start(_) => {
|
|
||||||
log::info!("{name}::{stream:?}: Starting with Motion");
|
|
||||||
counter.create_activated().await?
|
|
||||||
}
|
|
||||||
MdState::Stop(_) | MdState::Unknown => {
|
|
||||||
log::info!("{name}::{stream:?}: Waiting with Motion");
|
|
||||||
counter.create_deactivated().await?
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
// Now listen to the motion
|
|
||||||
let thread_name = name.clone();
|
|
||||||
tasks.push(tokio::spawn(
|
|
||||||
async move {
|
|
||||||
loop {
|
|
||||||
match md.changed().await {
|
|
||||||
Ok(_) => {
|
|
||||||
let md_state: MdState = md.borrow_and_update().clone();
|
|
||||||
match md_state {
|
|
||||||
MdState::Start(_) => {
|
|
||||||
log::info!("{thread_name}::{stream:?}: Motion Started");
|
|
||||||
md_permit.activate().await?;
|
|
||||||
}
|
|
||||||
MdState::Stop(_) => {
|
|
||||||
log::info!("{thread_name}::{stream:?}: Motion Stopped");
|
|
||||||
md_permit.deactivate().await?;
|
|
||||||
}
|
|
||||||
MdState::Unknown => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
// Use break here so we can define the full type on the async closure
|
|
||||||
break AnyResult::Err(e.into());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}?;
|
|
||||||
AnyResult::Ok(())
|
|
||||||
}
|
|
||||||
.map(|e| {
|
|
||||||
log::debug!("Motion thread stopped {e:?}");
|
|
||||||
e
|
|
||||||
}),
|
|
||||||
));
|
|
||||||
|
|
||||||
#[cfg(feature = "pushnoti")]
|
|
||||||
{
|
|
||||||
// Creates a permit for controlling based on the PN
|
|
||||||
let pn_permit = counter.create_deactivated().await?;
|
|
||||||
let mut pn = self.push_notifications().await?;
|
|
||||||
pn.borrow_and_update(); // Ignore any PNs that have already been sent before this
|
|
||||||
let thread_name = name.clone();
|
|
||||||
tasks.push(tokio::spawn(
|
|
||||||
async move {
|
|
||||||
loop {
|
|
||||||
let noti: Option<PushNoti> = pn.borrow_and_update().clone();
|
|
||||||
if let Some(noti) = noti {
|
|
||||||
if noti.message.contains("Motion Alert from") {
|
|
||||||
log::info!(
|
|
||||||
"{thread_name}::{stream:?}: Push Notification Recieved"
|
|
||||||
);
|
|
||||||
let mut new_pn_permit = pn_permit.subscribe();
|
|
||||||
new_pn_permit.activate().await?;
|
|
||||||
tokio::spawn(async move {
|
|
||||||
tokio::time::sleep(tokio::time::Duration::from_secs(30))
|
|
||||||
.await;
|
|
||||||
drop(new_pn_permit);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if let Err(e) = pn.changed().await {
|
|
||||||
break Err(e);
|
|
||||||
}
|
|
||||||
}?;
|
|
||||||
AnyResult::Ok(())
|
|
||||||
}
|
|
||||||
.map(|e| {
|
|
||||||
log::debug!("PN thread stopped {e:?}");
|
|
||||||
e
|
|
||||||
}),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send the camera when the pemit is active
|
|
||||||
let camera_permit = counter.create_deactivated().await?;
|
|
||||||
let thread_camera = self.clone();
|
|
||||||
tokio::spawn(
|
|
||||||
async move {
|
|
||||||
loop {
|
|
||||||
if let Err(e) = camera_permit.aquired_users().await {
|
|
||||||
break AnyResult::Err(e);
|
|
||||||
}
|
|
||||||
log::debug!("Starting stream");
|
|
||||||
tokio::select! {
|
|
||||||
v = camera_permit.dropped_users() => {
|
|
||||||
log::debug!("Dropped users: {v:?}");
|
|
||||||
v
|
|
||||||
},
|
|
||||||
v = async {
|
|
||||||
log::debug!("Getting stream");
|
|
||||||
let mut stream = thread_camera.stream(stream).await?;
|
|
||||||
log::debug!("Got stream");
|
|
||||||
while let Some(media) = stream.recv().await {
|
|
||||||
media_tx.send(media).await?;
|
|
||||||
}
|
|
||||||
AnyResult::Ok(())
|
|
||||||
} => {
|
|
||||||
log::debug!("Stopped stream: {v:?}");
|
|
||||||
v
|
|
||||||
},
|
|
||||||
v = tasks.next() => {
|
|
||||||
log::debug!("Task failed: {v:?}");
|
|
||||||
Err(anyhow!("Task ended prematurly: {v:?}"))
|
|
||||||
}
|
|
||||||
}?;
|
|
||||||
log::debug!("Pausing stream");
|
|
||||||
}?;
|
|
||||||
drop(counter); // Make sure counter is owned by this thread
|
|
||||||
AnyResult::Ok(())
|
|
||||||
}
|
|
||||||
.map(|e| {
|
|
||||||
log::debug!("Stream thread stopped {e:?}");
|
|
||||||
e
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
Ok(media_rx)
|
|
||||||
} else {
|
|
||||||
self.stream(stream).await
|
|
||||||
}?;
|
|
||||||
|
|
||||||
Ok(media_rx)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Streams a camera source
|
|
||||||
pub(crate) async fn stream(&self, stream: StreamKind) -> AnyResult<MpscReceiver<BcMedia>> {
|
|
||||||
let (media_tx, media_rx) = tokio::sync::mpsc::channel(100);
|
|
||||||
let config = self.config().await?.borrow().clone();
|
|
||||||
let strict = config.strict;
|
|
||||||
let thread_camera = self.clone();
|
|
||||||
tokio::task::spawn(
|
|
||||||
tokio::task::spawn(async move {
|
|
||||||
thread_camera
|
|
||||||
.run_task(move |cam| {
|
|
||||||
let media_tx = media_tx.clone();
|
|
||||||
Box::pin(async move {
|
|
||||||
let mut media_stream = cam.start_video(stream, 0, strict).await?;
|
|
||||||
log::trace!("Camera started");
|
|
||||||
while let Ok(media) = media_stream.get_data().await? {
|
|
||||||
media_tx.send(media).await?;
|
|
||||||
}
|
|
||||||
AnyResult::Ok(())
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.await
|
|
||||||
})
|
|
||||||
.and_then(|res| async move {
|
|
||||||
log::debug!("Camera finished streaming: {res:?}");
|
|
||||||
Ok(())
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
Ok(media_rx)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
use super::*;
|
|
||||||
|
|
||||||
use crate::common::PushNoti;
|
|
||||||
use tokio::sync::watch::channel as watch;
|
|
||||||
|
|
||||||
impl NeoInstance {
|
|
||||||
pub(crate) async fn uid(&self) -> Result<String> {
|
|
||||||
let (reply_tx, reply_rx) = oneshot();
|
|
||||||
self.camera_control
|
|
||||||
.send(NeoCamCommand::GetUid(reply_tx))
|
|
||||||
.await?;
|
|
||||||
Ok(reply_rx.await?)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) async fn push_notifications(&self) -> Result<WatchReceiver<Option<PushNoti>>> {
|
|
||||||
let uid = self.uid().await?;
|
|
||||||
let (instance_tx, instance_rx) = oneshot();
|
|
||||||
self.camera_control
|
|
||||||
.send(NeoCamCommand::PushNoti(instance_tx))
|
|
||||||
.await?;
|
|
||||||
let mut source_watch = instance_rx.await?;
|
|
||||||
|
|
||||||
let (fwatch_tx, fwatch_rx) = watch(None);
|
|
||||||
tokio::task::spawn(async move {
|
|
||||||
loop {
|
|
||||||
match source_watch
|
|
||||||
.wait_for(|i| {
|
|
||||||
fwatch_tx.borrow().as_ref() != i.as_ref()
|
|
||||||
&& i.as_ref()
|
|
||||||
.is_some_and(|i| i.message.contains(&format!("\"{uid}\"")))
|
|
||||||
})
|
|
||||||
.await
|
|
||||||
{
|
|
||||||
Ok(pn) => {
|
|
||||||
log::trace!("Forwarding push notification about {}", uid);
|
|
||||||
let _ = fwatch_tx.send_replace(pn.clone());
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
break Err(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}?;
|
|
||||||
AnyResult::Ok(())
|
|
||||||
});
|
|
||||||
|
|
||||||
Ok(fwatch_rx)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+8
-76
@@ -15,7 +15,7 @@ use tokio_util::sync::CancellationToken;
|
|||||||
|
|
||||||
use super::NeoInstance;
|
use super::NeoInstance;
|
||||||
use crate::{AnyResult, Result};
|
use crate::{AnyResult, Result};
|
||||||
use neolink_core::bc_protocol::{AiKind, MotionEvents};
|
use neolink_core::bc_protocol::MotionStatus;
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
@@ -25,26 +25,8 @@ pub(crate) enum MdState {
|
|||||||
Unknown,
|
Unknown,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub(crate) enum VisitorState {
|
|
||||||
Visted(Instant),
|
|
||||||
Unknown,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub(crate) enum AiState {
|
|
||||||
Person(Instant),
|
|
||||||
Car(Instant),
|
|
||||||
Other(Instant),
|
|
||||||
Unknown,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) struct NeoCamMdThread {
|
pub(crate) struct NeoCamMdThread {
|
||||||
md_watcher: Arc<WatchSender<MdState>>,
|
md_watcher: Arc<WatchSender<MdState>>,
|
||||||
visitor_watcher: Arc<WatchSender<VisitorState>>,
|
|
||||||
ai_watcher: Arc<WatchSender<AiState>>,
|
|
||||||
md_request_rx: MpscReceiver<MdRequest>,
|
md_request_rx: MpscReceiver<MdRequest>,
|
||||||
cancel: CancellationToken,
|
cancel: CancellationToken,
|
||||||
instance: NeoInstance,
|
instance: NeoInstance,
|
||||||
@@ -57,17 +39,8 @@ impl NeoCamMdThread {
|
|||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let (md_watcher, _) = watch(MdState::Unknown);
|
let (md_watcher, _) = watch(MdState::Unknown);
|
||||||
let md_watcher = Arc::new(md_watcher);
|
let md_watcher = Arc::new(md_watcher);
|
||||||
|
|
||||||
let (visitor_watcher, _) = watch(VisitorState::Unknown);
|
|
||||||
let visitor_watcher = Arc::new(visitor_watcher);
|
|
||||||
|
|
||||||
let (ai_watcher, _) = watch(AiState::Unknown);
|
|
||||||
let ai_watcher = Arc::new(ai_watcher);
|
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
md_watcher,
|
md_watcher,
|
||||||
visitor_watcher,
|
|
||||||
ai_watcher,
|
|
||||||
md_request_rx,
|
md_request_rx,
|
||||||
cancel: CancellationToken::new(),
|
cancel: CancellationToken::new(),
|
||||||
instance,
|
instance,
|
||||||
@@ -77,8 +50,6 @@ impl NeoCamMdThread {
|
|||||||
pub(crate) async fn run(&mut self) -> Result<()> {
|
pub(crate) async fn run(&mut self) -> Result<()> {
|
||||||
let thread_cancel = self.cancel.clone();
|
let thread_cancel = self.cancel.clone();
|
||||||
let watcher = self.md_watcher.clone();
|
let watcher = self.md_watcher.clone();
|
||||||
let visitor_watcher = self.visitor_watcher.clone();
|
|
||||||
let ai_watcher = self.ai_watcher.clone();
|
|
||||||
let md_instance = self.instance.clone();
|
let md_instance = self.instance.clone();
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
_ = thread_cancel.cancelled() => {
|
_ = thread_cancel.cancelled() => {
|
||||||
@@ -87,21 +58,11 @@ impl NeoCamMdThread {
|
|||||||
v = async {
|
v = async {
|
||||||
while let Some(request) = self.md_request_rx.recv().await {
|
while let Some(request) = self.md_request_rx.recv().await {
|
||||||
match request {
|
match request {
|
||||||
MdRequest::Md {
|
MdRequest::Get {
|
||||||
sender
|
sender
|
||||||
} => {
|
} => {
|
||||||
let _ = sender.send(self.md_watcher.subscribe());
|
let _ = sender.send(self.md_watcher.subscribe());
|
||||||
},
|
},
|
||||||
MdRequest::Visitor {
|
|
||||||
sender
|
|
||||||
} => {
|
|
||||||
let _ = sender.send(self.visitor_watcher.subscribe());
|
|
||||||
},
|
|
||||||
MdRequest::Ai {
|
|
||||||
sender
|
|
||||||
} => {
|
|
||||||
let _ = sender.send(self.ai_watcher.subscribe());
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -110,46 +71,23 @@ impl NeoCamMdThread {
|
|||||||
loop {
|
loop {
|
||||||
let r: AnyResult<()> = md_instance.run_passive_task(|cam| {
|
let r: AnyResult<()> = md_instance.run_passive_task(|cam| {
|
||||||
let watcher = watcher.clone();
|
let watcher = watcher.clone();
|
||||||
let visitor_watcher = visitor_watcher.clone();
|
|
||||||
let ai_watcher = ai_watcher.clone();
|
|
||||||
Box::pin(
|
Box::pin(
|
||||||
async move {
|
async move {
|
||||||
let mut md = cam.listen_on_motion().await.with_context(|| "Error in getting MD listen_on_motion")?;
|
let mut md = cam.listen_on_motion().await.with_context(|| "Error in getting MD listen_on_motion")?;
|
||||||
loop {
|
loop {
|
||||||
let event = md.recv().await.with_context(|| "Error in getting MD next_motion")?.ok_or(anyhow::anyhow!("MD connection was dropped"))?;
|
let event = md.next_motion().await.with_context(|| "Error in getting MD next_motion")?;
|
||||||
match event {
|
match event {
|
||||||
MotionEvents::Start(at) => {
|
MotionStatus::Start(at) => {
|
||||||
watcher.send_replace(
|
watcher.send_replace(
|
||||||
MdState::Start(at.into())
|
MdState::Start(at.into())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
MotionEvents::Stop(at) => {
|
MotionStatus::Stop(at) => {
|
||||||
watcher.send_replace(
|
watcher.send_replace(
|
||||||
MdState::Stop(at.into())
|
MdState::Stop(at.into())
|
||||||
);
|
);
|
||||||
},
|
}
|
||||||
MotionEvents::Vistor(at) => {
|
MotionStatus::NoChange(_) => {},
|
||||||
visitor_watcher.send_replace(
|
|
||||||
VisitorState::Visted(at.into())
|
|
||||||
);
|
|
||||||
},
|
|
||||||
MotionEvents::Ai(at, kind) => {
|
|
||||||
ai_watcher.send_replace(
|
|
||||||
match kind {
|
|
||||||
AiKind::Person => {
|
|
||||||
AiState::Person(at.into())
|
|
||||||
}
|
|
||||||
AiKind::Car => {
|
|
||||||
AiState::Car(at.into())
|
|
||||||
}
|
|
||||||
AiKind::Other => {
|
|
||||||
AiState::Other(at.into())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
);
|
|
||||||
},
|
|
||||||
_ => {},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -172,13 +110,7 @@ impl Drop for NeoCamMdThread {
|
|||||||
|
|
||||||
/// Used to pass messages to the MdThread
|
/// Used to pass messages to the MdThread
|
||||||
pub(crate) enum MdRequest {
|
pub(crate) enum MdRequest {
|
||||||
Md {
|
Get {
|
||||||
sender: OneshotSender<WatchReceiver<MdState>>,
|
sender: OneshotSender<WatchReceiver<MdState>>,
|
||||||
},
|
},
|
||||||
Visitor {
|
|
||||||
sender: OneshotSender<WatchReceiver<VisitorState>>,
|
|
||||||
},
|
|
||||||
Ai {
|
|
||||||
sender: OneshotSender<WatchReceiver<AiState>>,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
+5
-20
@@ -20,21 +20,19 @@ use tokio_stream::wrappers::ReceiverStream;
|
|||||||
use tokio_util::sync::CancellationToken;
|
use tokio_util::sync::CancellationToken;
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
AiState, MdRequest, MdState, NeoCamMdThread, NeoCamThread, NeoCamThreadState, NeoInstance,
|
MdRequest, MdState, NeoCamMdThread, NeoCamThread, NeoCamThreadState, NeoInstance, Permit,
|
||||||
Permit, UseCounter, VisitorState,
|
UseCounter,
|
||||||
};
|
};
|
||||||
#[cfg(feature = "pushnoti")]
|
#[cfg(feature = "pushnoti")]
|
||||||
use super::{PnRequest, PushNoti};
|
use super::{PnRequest, PushNoti};
|
||||||
use crate::{config::CameraConfig, AnyResult, Result};
|
use crate::{config::CameraConfig, AnyResult, Result};
|
||||||
use neolink_core::bc_protocol::BcCamera;
|
use neolink_core::bc_protocol::BcCamera;
|
||||||
|
#[cfg(feature = "gstreamer")]
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub(crate) enum NeoCamCommand {
|
pub(crate) enum NeoCamCommand {
|
||||||
HangUp,
|
HangUp,
|
||||||
Instance(OneshotSender<Result<NeoInstance>>),
|
Instance(OneshotSender<Result<NeoInstance>>),
|
||||||
Motion(OneshotSender<WatchReceiver<MdState>>),
|
Motion(OneshotSender<WatchReceiver<MdState>>),
|
||||||
Visitor(OneshotSender<WatchReceiver<VisitorState>>),
|
|
||||||
Ai(OneshotSender<WatchReceiver<AiState>>),
|
|
||||||
Config(OneshotSender<WatchReceiver<CameraConfig>>),
|
Config(OneshotSender<WatchReceiver<CameraConfig>>),
|
||||||
Disconnect(OneshotSender<()>),
|
Disconnect(OneshotSender<()>),
|
||||||
Connect(OneshotSender<()>),
|
Connect(OneshotSender<()>),
|
||||||
@@ -83,6 +81,7 @@ impl NeoCam {
|
|||||||
// other threads
|
// other threads
|
||||||
let sender_cancel = me.cancel.clone();
|
let sender_cancel = me.cancel.clone();
|
||||||
let mut commander_rx = ReceiverStream::new(commander_rx);
|
let mut commander_rx = ReceiverStream::new(commander_rx);
|
||||||
|
#[cfg(feature = "gstreamer")]
|
||||||
let thread_commander_tx = commander_tx.clone();
|
let thread_commander_tx = commander_tx.clone();
|
||||||
let thread_watch_config_rx = watch_config_rx.clone();
|
let thread_watch_config_rx = watch_config_rx.clone();
|
||||||
#[cfg(feature = "pushnoti")]
|
#[cfg(feature = "pushnoti")]
|
||||||
@@ -111,21 +110,7 @@ impl NeoCam {
|
|||||||
}
|
}
|
||||||
NeoCamCommand::Motion(sender) => {
|
NeoCamCommand::Motion(sender) => {
|
||||||
md_request_tx.send(
|
md_request_tx.send(
|
||||||
MdRequest::Md {
|
MdRequest::Get {
|
||||||
sender,
|
|
||||||
}
|
|
||||||
).await?;
|
|
||||||
},
|
|
||||||
NeoCamCommand::Visitor(sender) => {
|
|
||||||
md_request_tx.send(
|
|
||||||
MdRequest::Visitor {
|
|
||||||
sender,
|
|
||||||
}
|
|
||||||
).await?;
|
|
||||||
},
|
|
||||||
NeoCamCommand::Ai(sender) => {
|
|
||||||
md_request_tx.send(
|
|
||||||
MdRequest::Ai {
|
|
||||||
sender,
|
sender,
|
||||||
}
|
}
|
||||||
).await?;
|
).await?;
|
||||||
|
|||||||
@@ -235,10 +235,6 @@ pub(crate) struct MqttConfig {
|
|||||||
#[serde(default = "default_true")]
|
#[serde(default = "default_true")]
|
||||||
pub(crate) enable_motion: bool,
|
pub(crate) enable_motion: bool,
|
||||||
#[serde(default = "default_true")]
|
#[serde(default = "default_true")]
|
||||||
pub(crate) enable_visitor: bool,
|
|
||||||
#[serde(default = "default_true")]
|
|
||||||
pub(crate) enable_ai: bool,
|
|
||||||
#[serde(default = "default_true")]
|
|
||||||
pub(crate) enable_light: bool,
|
pub(crate) enable_light: bool,
|
||||||
#[serde(default = "default_true")]
|
#[serde(default = "default_true")]
|
||||||
pub(crate) enable_battery: bool,
|
pub(crate) enable_battery: bool,
|
||||||
@@ -307,8 +303,6 @@ const fn default_false() -> bool {
|
|||||||
fn default_mqtt() -> MqttConfig {
|
fn default_mqtt() -> MqttConfig {
|
||||||
MqttConfig {
|
MqttConfig {
|
||||||
enable_motion: true,
|
enable_motion: true,
|
||||||
enable_visitor: true,
|
|
||||||
enable_ai: true,
|
|
||||||
enable_light: true,
|
enable_light: true,
|
||||||
enable_battery: true,
|
enable_battery: true,
|
||||||
battery_update: 2000,
|
battery_update: 2000,
|
||||||
|
|||||||
+9
-75
@@ -77,7 +77,7 @@ mod discovery;
|
|||||||
mod mqttc;
|
mod mqttc;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
common::{AiState, MdState, NeoInstance, NeoReactor, VisitorState},
|
common::{MdState, NeoInstance, NeoReactor},
|
||||||
config::Config,
|
config::Config,
|
||||||
AnyResult,
|
AnyResult,
|
||||||
};
|
};
|
||||||
@@ -303,14 +303,14 @@ async fn listen_on_camera(camera: NeoInstance, mqtt_instance: MqttInstance) -> R
|
|||||||
.await
|
.await
|
||||||
.with_context(|| format!("Failed to publish status for {}", camera_name))?;
|
.with_context(|| format!("Failed to publish status for {}", camera_name))?;
|
||||||
let _drop_message = mqtt_instance.last_will("status", "disconnected").await?;
|
let _drop_message = mqtt_instance.last_will("status", "disconnected").await?;
|
||||||
// mqtt_instance
|
mqtt_instance
|
||||||
// .send_message("status/motion", "unknown", true)
|
.send_message("status/motion", "unknown", true)
|
||||||
// .await
|
.await
|
||||||
// .with_context(|| format!("Failed to publish motion unknown for {}", camera_name))?;
|
.with_context(|| format!("Failed to publish motion unknown for {}", camera_name))?;
|
||||||
// mqtt_instance
|
mqtt_instance
|
||||||
// .send_message("status/notification", "unknown", true)
|
.send_message("status/notification", "unknown", true)
|
||||||
// .await
|
.await
|
||||||
// .with_context(|| format!("Failed to publish push notification unknown for {}", camera_name))?;
|
.with_context(|| format!("Failed to publish push notification unknown for {}", camera_name))?;
|
||||||
let _drop_message2 = mqtt_instance.last_will("status/motion", "unknown").await?;
|
let _drop_message2 = mqtt_instance.last_will("status/motion", "unknown").await?;
|
||||||
|
|
||||||
if let Some(discovery_config) = config.discovery.as_ref() {
|
if let Some(discovery_config) = config.discovery.as_ref() {
|
||||||
@@ -331,12 +331,6 @@ async fn listen_on_camera(camera: NeoInstance, mqtt_instance: MqttInstance) -> R
|
|||||||
let camera_motion = camera.clone();
|
let camera_motion = camera.clone();
|
||||||
let mqtt_motion = mqtt_instance.resubscribe().await?;
|
let mqtt_motion = mqtt_instance.resubscribe().await?;
|
||||||
|
|
||||||
let camera_visitor = camera.clone();
|
|
||||||
let mqtt_visitor = mqtt_instance.resubscribe().await?;
|
|
||||||
|
|
||||||
let camera_ai = camera.clone();
|
|
||||||
let mqtt_ai = mqtt_instance.resubscribe().await?;
|
|
||||||
|
|
||||||
#[cfg(feature = "pushnoti")]
|
#[cfg(feature = "pushnoti")]
|
||||||
let camera_pn = camera.clone();
|
let camera_pn = camera.clone();
|
||||||
#[cfg(feature = "pushnoti")]
|
#[cfg(feature = "pushnoti")]
|
||||||
@@ -482,66 +476,6 @@ async fn listen_on_camera(camera: NeoInstance, mqtt_instance: MqttInstance) -> R
|
|||||||
}?;
|
}?;
|
||||||
}
|
}
|
||||||
}, if config.enable_motion => v,
|
}, if config.enable_motion => v,
|
||||||
// Handle the visitor messages
|
|
||||||
v = async {
|
|
||||||
let mut vis = camera_visitor.visitor().await?;
|
|
||||||
loop {
|
|
||||||
let v = async {
|
|
||||||
vis.changed().await.with_context(|| {
|
|
||||||
format!("{}: ViaStart Watch Dropped", camera_name)
|
|
||||||
})?;
|
|
||||||
vis.wait_for(|state| matches!(state, VisitorState::Visted(_))).await.with_context(|| {
|
|
||||||
format!("{}: ViaStart Watch Dropped", camera_name)
|
|
||||||
})?;
|
|
||||||
mqtt_visitor.send_message("status/visitor", "visitor", true).await.with_context(|| {
|
|
||||||
format!("{}: Failed to publish visitor", camera_name)
|
|
||||||
})?;
|
|
||||||
AnyResult::Ok(())
|
|
||||||
}.await;
|
|
||||||
match v.map_err(|e| e.downcast::<neolink_core::Error>()) {
|
|
||||||
Err(Ok(neolink_core::Error::UnintelligibleReply{..})) => futures::future::pending().await,
|
|
||||||
Ok(()) => AnyResult::Ok(()),
|
|
||||||
Err(Ok(e)) => Err(e.into()),
|
|
||||||
Err(Err(e)) => Err(e),
|
|
||||||
}?;
|
|
||||||
}
|
|
||||||
}, if config.enable_visitor => v,
|
|
||||||
// Handle the ai messages
|
|
||||||
v = async {
|
|
||||||
let mut ai = camera_ai.ai().await?;
|
|
||||||
loop {
|
|
||||||
let v = async {
|
|
||||||
let ai_kind = {
|
|
||||||
ai.changed().await.with_context(|| {
|
|
||||||
format!("{}: AiStart Watch Dropped", camera_name)
|
|
||||||
})?;
|
|
||||||
let ai_state = ai.wait_for(|state| !matches!(state, AiState::Unknown)).await.with_context(|| {
|
|
||||||
format!("{}: AiStart Watch Dropped", camera_name)
|
|
||||||
})?;
|
|
||||||
match &*ai_state {
|
|
||||||
AiState::Person(_) => "person",
|
|
||||||
AiState::Car(_) => "car",
|
|
||||||
AiState::Other(_) => "other",
|
|
||||||
AiState::Unknown => unreachable!(),
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
mqtt_ai.send_message("status/ai", ai_kind, true).await.with_context(|| {
|
|
||||||
format!("{}: Failed to publish ai msg", camera_name)
|
|
||||||
})?;
|
|
||||||
mqtt_ai.send_message(&format!("status/ai/{}", ai_kind), ai_kind, true).await.with_context(|| {
|
|
||||||
format!("{}: Failed to publish ai sub msg", camera_name)
|
|
||||||
})?;
|
|
||||||
AnyResult::Ok(())
|
|
||||||
}.await;
|
|
||||||
match v.map_err(|e| e.downcast::<neolink_core::Error>()) {
|
|
||||||
Err(Ok(neolink_core::Error::UnintelligibleReply{..})) => futures::future::pending().await,
|
|
||||||
Ok(()) => AnyResult::Ok(()),
|
|
||||||
Err(Ok(e)) => Err(e.into()),
|
|
||||||
Err(Err(e)) => Err(e),
|
|
||||||
}?;
|
|
||||||
}
|
|
||||||
}, if config.enable_ai => v,
|
|
||||||
// Handle the SNAP (image preview)
|
// Handle the SNAP (image preview)
|
||||||
v = async {
|
v = async {
|
||||||
let mut wait = IntervalStream::new({
|
let mut wait = IntervalStream::new({
|
||||||
|
|||||||
+2
-2
@@ -122,7 +122,7 @@ struct MqttBackend<'a> {
|
|||||||
cancel: CancellationToken,
|
cancel: CancellationToken,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MqttBackend<'_> {
|
impl<'a> MqttBackend<'a> {
|
||||||
async fn run(&mut self) -> AnyResult<()> {
|
async fn run(&mut self) -> AnyResult<()> {
|
||||||
log::trace!("Run MQTT Server");
|
log::trace!("Run MQTT Server");
|
||||||
let mut mqttoptions = MqttOptions::new(
|
let mut mqttoptions = MqttOptions::new(
|
||||||
@@ -339,7 +339,7 @@ impl MqttBackend<'_> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for MqttBackend<'_> {
|
impl<'a> Drop for MqttBackend<'a> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
self.cancel.cancel();
|
self.cancel.cancel();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user