Deps and logs
Use quick_xml instead of yaserde Use thiserror instead of err_derive Update deps to latest (except fcm), fcm will need to wait for reolink to update their fcm apis first in their app
This commit is contained in:
35 files changed
+1419
-1735
No files matched your search
File renamed without changes.
@@ -17,8 +17,8 @@ jobs:
|
|||||||
uses: fkirc/skip-duplicate-actions@v5
|
uses: fkirc/skip-duplicate-actions@v5
|
||||||
with:
|
with:
|
||||||
# All of these options are optional, so you can remove them if you are happy with the defaults
|
# All of these options are optional, so you can remove them if you are happy with the defaults
|
||||||
concurrent_skipping: 'same_content_newer'
|
concurrent_skipping: "same_content_newer"
|
||||||
skip_after_successful_duplicate: 'false'
|
skip_after_successful_duplicate: "false"
|
||||||
|
|
||||||
native:
|
native:
|
||||||
needs: pre_job
|
needs: pre_job
|
||||||
@@ -190,9 +190,9 @@ jobs:
|
|||||||
id: vars
|
id: vars
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
unset HAS_SECRET
|
unset HAS_SECRET
|
||||||
if [ -n $SECRET ]; then HAS_SECRET='true' ; fi
|
if [ -n $SECRET ]; then HAS_SECRET='true' ; fi
|
||||||
echo "HAS_SECRET_TOKEN=${HAS_SECRET}" >> $GITHUB_OUTPUT
|
echo "HAS_SECRET_TOKEN=${HAS_SECRET}" >> $GITHUB_OUTPUT
|
||||||
env:
|
env:
|
||||||
SECRET: "${{ secrets.DOCKER_TOKEN }}"
|
SECRET: "${{ secrets.DOCKER_TOKEN }}"
|
||||||
- name: Check out the repo
|
- name: Check out the repo
|
||||||
@@ -268,7 +268,7 @@ jobs:
|
|||||||
REPO_NAME: ${{ steps.docker_repo.outputs.DOCKER_NWO }}
|
REPO_NAME: ${{ steps.docker_repo.outputs.DOCKER_NWO }}
|
||||||
- name: Install latest rust
|
- name: Install latest rust
|
||||||
run: |
|
run: |
|
||||||
rustup toolchain install stable
|
rustup toolchain install stable
|
||||||
- name: Install toml-cli
|
- name: Install toml-cli
|
||||||
run: |
|
run: |
|
||||||
cargo install toml-cli
|
cargo install toml-cli
|
||||||
@@ -327,7 +327,7 @@ jobs:
|
|||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
- name: Install latest rust
|
- name: Install latest rust
|
||||||
run: |
|
run: |
|
||||||
rustup toolchain install stable
|
rustup toolchain install stable
|
||||||
- name: Install toml-cli
|
- name: Install toml-cli
|
||||||
run: |
|
run: |
|
||||||
cargo install toml-cli
|
cargo install toml-cli
|
||||||
@@ -401,4 +401,4 @@ jobs:
|
|||||||
body: |
|
body: |
|
||||||
Neolink Release ${{steps.toml.outputs.version}}
|
Neolink Release ${{steps.toml.outputs.version}}
|
||||||
draft: true
|
draft: true
|
||||||
prerelease: ${{ contains(github.ref_name, 'rc') }}
|
prerelease: ${{ contains(github.ref_name, 'rc') }}
|
||||||
Generated
+681
-901
File diff suppressed because it is too large.
Load diff
+14
-14
@@ -14,35 +14,35 @@ members = [
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0.70"
|
anyhow = "1.0.70"
|
||||||
async-stream = "0.3.5"
|
async-stream = "0.3.5"
|
||||||
base64 = "0.21.2"
|
base64 = "0.22.0"
|
||||||
byte-slice-cast = "1.2.2"
|
byte-slice-cast = "1.2.2"
|
||||||
|
bytes = "1.6.0"
|
||||||
clap = { version = "4.2.2", features = ["derive", "cargo"] }
|
clap = { version = "4.2.2", features = ["derive", "cargo"] }
|
||||||
console-subscriber = "0.2.0"
|
|
||||||
crossbeam-channel = "0.5.8"
|
crossbeam-channel = "0.5.8"
|
||||||
dirs = "5.0.1"
|
dirs = "5.0.1"
|
||||||
env_logger = "0.10.0"
|
env_logger = "0.11.3"
|
||||||
fcm-push-listener = "2.0.1"
|
fcm-push-listener = "2.0.3"
|
||||||
futures = "0.3.28"
|
futures = "0.3.28"
|
||||||
gstreamer = "0.21.0"
|
gstreamer = "0.22.3"
|
||||||
gstreamer-app = { version = "0.21.0", features = ["v1_18"] }
|
gstreamer-app = { version = "0.22.0", features = ["v1_18"] }
|
||||||
gstreamer-rtsp = { version = "0.21.0", features = ["v1_18"] }
|
gstreamer-rtsp = { version = "0.22.0", features = ["v1_18"] }
|
||||||
gstreamer-rtsp-server = { version = "0.21.0", features = ["v1_18"] }
|
gstreamer-rtsp-server = { version = "0.22.0", features = ["v1_18"] }
|
||||||
heck = "0.4.1"
|
heck = "0.5.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" ] }
|
||||||
md5 = "0.7.0"
|
md5 = "0.7.0"
|
||||||
neolink_core = { path = "crates/core", version = "0.6.3-rc.2" }
|
neolink_core = { path = "crates/core", version = "0.6.3-rc.2" }
|
||||||
|
once_cell = "1.19.0"
|
||||||
|
quick-xml = { version = "0.31.0", features = ["serialize"] }
|
||||||
regex = "1.7.3"
|
regex = "1.7.3"
|
||||||
rumqttc = "0.22.0"
|
rumqttc = "0.24.0"
|
||||||
serde = { version = "1.0.160", features = ["derive"] }
|
serde = { version = "1.0.160", features = ["derive"] }
|
||||||
serde_json = "1.0.96"
|
serde_json = "1.0.96"
|
||||||
tokio = { version = "1.27.0", features = ["rt-multi-thread", "macros", "io-util", "tracing"] }
|
tokio = { version = "1.27.0", features = ["rt-multi-thread", "macros", "io-util", "tracing"] }
|
||||||
tokio-stream = "0.1.12"
|
tokio-stream = "0.1.12"
|
||||||
tokio-util = { version = "0.7.7", features = ["full", "tracing"] }
|
tokio-util = { version = "0.7.7", features = ["full", "tracing"] }
|
||||||
toml = "0.8.2"
|
toml = "0.8.2"
|
||||||
validator = "0.16.0"
|
validator = "0.17.0"
|
||||||
validator_derive = "0.16.0"
|
validator_derive = "0.17.0"
|
||||||
yaserde = "0.8.0"
|
|
||||||
|
|
||||||
[target.'cfg(not(target_env = "msvc"))'.dependencies]
|
[target.'cfg(not(target_env = "msvc"))'.dependencies]
|
||||||
tikv-jemallocator = "0.5"
|
tikv-jemallocator = "0.5"
|
||||||
@@ -63,9 +63,18 @@ fn platform_cfg() {
|
|||||||
let gstreamer_dir = env::var_os("GSTREAMER_1_0_ROOT_MACOSX")
|
let gstreamer_dir = env::var_os("GSTREAMER_1_0_ROOT_MACOSX")
|
||||||
.and_then(|x| x.into_string().ok())
|
.and_then(|x| x.into_string().ok())
|
||||||
.unwrap_or_else(|| r"/Library/Frameworks/GStreamer.framework/Versions/1.0".to_string());
|
.unwrap_or_else(|| r"/Library/Frameworks/GStreamer.framework/Versions/1.0".to_string());
|
||||||
|
let openssl_dir = env::var_os("OPENSSL_1_1_ROOT_MACOSX")
|
||||||
|
.and_then(|x| x.into_string().ok())
|
||||||
|
.unwrap_or_else(|| r"/usr/local/opt/openssl@1.1".to_string());
|
||||||
|
|
||||||
println!(r"cargo:rustc-link-search=native={}/lib", gstreamer_dir);
|
println!(
|
||||||
println!(r"cargo:rustc-link-arg=-Wl,-rpath,{}/lib", gstreamer_dir);
|
r"cargo:rustc-link-search=native={}/lib;{}/lib",
|
||||||
|
gstreamer_dir, openssl_dir
|
||||||
|
);
|
||||||
|
println!(
|
||||||
|
r"cargo:rustc-link-arg=-Wl,-rpath,{}/lib;{}/lib/",
|
||||||
|
gstreamer_dir, openssl_dir
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(not(target_os = "macos"), not(target_os = "windows")))]
|
#[cfg(all(not(target_os = "macos"), not(target_os = "windows")))]
|
||||||
|
|||||||
@@ -13,23 +13,22 @@ cfb-mode = "0.8.2"
|
|||||||
cookie-factory = "0.3.2"
|
cookie-factory = "0.3.2"
|
||||||
crc32fast = "1.3.2"
|
crc32fast = "1.3.2"
|
||||||
crossbeam-channel = "0.5.8"
|
crossbeam-channel = "0.5.8"
|
||||||
delegate = "0.10.0"
|
delegate = "0.12.0"
|
||||||
err-derive = "0.3.1"
|
|
||||||
futures = "0.3.28"
|
futures = "0.3.28"
|
||||||
get_if_addrs = "0.5.3"
|
get_if_addrs = "0.5.3"
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
log = "0.4.17"
|
log = "0.4.17"
|
||||||
md5 = "0.7.0"
|
md5 = "0.7.0"
|
||||||
nom = { version = "7.1.3", features = ["alloc"] }
|
nom = { version = "7.1.3", features = ["alloc"] }
|
||||||
|
quick-xml = { version = "0.31.0", features = ["serialize"] }
|
||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
regex = "1.7.3"
|
regex = "1.7.3"
|
||||||
serde = { version = "1.0.106", features = ["derive"] }
|
serde = { version = "1.0.106", features = ["derive"] }
|
||||||
|
thiserror = "1.0.58"
|
||||||
time = { version = "0.3.20" , features = [ "macros", "parsing", "local-offset" ]}
|
time = { version = "0.3.20" , features = [ "macros", "parsing", "local-offset" ]}
|
||||||
tokio = { version = "1.27.0", features = ["full"] }
|
tokio = { version = "1.27.0", features = ["full"] }
|
||||||
tokio-stream = { version = "0.1.12", features = ["sync", "time", "net"] }
|
tokio-stream = { version = "0.1.12", features = ["sync", "time", "net"] }
|
||||||
tokio-util = { version = "0.7.7", features = ["full", "tracing"] }
|
tokio-util = { version = "0.7.7", features = ["full", "tracing"] }
|
||||||
yaserde = "0.8.0"
|
|
||||||
yaserde_derive = "0.8.0"
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
assert_matches = "1.5.0"
|
assert_matches = "1.5.0"
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
use super::model::*;
|
use super::model::*;
|
||||||
use super::xml::{BcPayloads, BcXml};
|
|
||||||
use super::xml_crypto;
|
use super::xml_crypto;
|
||||||
use crate::Error;
|
use crate::Error;
|
||||||
use bytes::{Buf, BytesMut};
|
use bytes::{Buf, BytesMut};
|
||||||
@@ -84,10 +83,10 @@ fn bc_modern_msg<'a>(
|
|||||||
Err,
|
Err,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn make_error<I, E: ParseError<I>>(input: I, ctx: &'static str, kind: ErrorKind) -> E
|
fn make_error<I, E>(input: I, ctx: &'static str, kind: ErrorKind) -> E
|
||||||
where
|
where
|
||||||
I: std::marker::Copy,
|
I: std::marker::Copy,
|
||||||
E: ContextError<I>,
|
E: ParseError<I> + ContextError<I>,
|
||||||
{
|
{
|
||||||
E::add_context(input, ctx, E::from_error_kind(input, kind))
|
E::add_context(input, ctx, E::from_error_kind(input, kind))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
use super::model::*;
|
use super::model::*;
|
||||||
use super::xml::BcPayloads;
|
|
||||||
use super::xml_crypto;
|
use super::xml_crypto;
|
||||||
use cookie_factory::bytes::*;
|
use cookie_factory::bytes::*;
|
||||||
use cookie_factory::sequence::tuple;
|
use cookie_factory::sequence::tuple;
|
||||||
@@ -79,7 +78,7 @@ fn bc_ext<W: Write>(
|
|||||||
xml: &Extension,
|
xml: &Extension,
|
||||||
encryption_protocol: &EncryptionProtocol,
|
encryption_protocol: &EncryptionProtocol,
|
||||||
) -> impl SerializeFn<W> {
|
) -> impl SerializeFn<W> {
|
||||||
let xml_bytes = xml.serialize(vec![]).unwrap();
|
let xml_bytes = xml.serialize(bytes::BytesMut::new()).unwrap();
|
||||||
let enc_bytes = xml_crypto::encrypt(enc_offset, &xml_bytes, encryption_protocol);
|
let enc_bytes = xml_crypto::encrypt(enc_offset, &xml_bytes, encryption_protocol);
|
||||||
slice(enc_bytes)
|
slice(enc_bytes)
|
||||||
}
|
}
|
||||||
@@ -91,7 +90,7 @@ fn bc_payload<W: Write>(
|
|||||||
) -> impl SerializeFn<W> {
|
) -> impl SerializeFn<W> {
|
||||||
let payload_bytes = match payload {
|
let payload_bytes = match payload {
|
||||||
BcPayloads::BcXml(x) => {
|
BcPayloads::BcXml(x) => {
|
||||||
let xml_bytes = x.serialize(vec![]).unwrap();
|
let xml_bytes = x.serialize(bytes::BytesMut::new()).unwrap();
|
||||||
xml_crypto::encrypt(enc_offset, &xml_bytes, encryption_protocol)
|
xml_crypto::encrypt(enc_offset, &xml_bytes, encryption_protocol)
|
||||||
}
|
}
|
||||||
BcPayloads::Binary(x) => x.to_owned(),
|
BcPayloads::Binary(x) => x.to_owned(),
|
||||||
|
|||||||
+318
-331
File diff suppressed because it is too large.
Load diff
@@ -54,8 +54,9 @@ impl BcCamera {
|
|||||||
/// Populate ability list of the camera
|
/// Populate ability list of the camera
|
||||||
pub async fn polulate_abilities(&self) -> Result<()> {
|
pub async fn polulate_abilities(&self) -> Result<()> {
|
||||||
let info = self.get_abilityinfo().await?;
|
let info = self.get_abilityinfo().await?;
|
||||||
let info_res = yaserde::ser::serialize_with_writer(&info, vec![], &Default::default());
|
let mut ser_buf = bytes::BytesMut::new();
|
||||||
if let Ok(Ok(info_str)) = info_res.map(String::from_utf8) {
|
let info_res = quick_xml::se::to_writer(&mut ser_buf, &info).map(|_| ser_buf);
|
||||||
|
if let Ok(Ok(info_str)) = info_res.map(|b| std::str::from_utf8(&b).map(|a| a.to_owned())) {
|
||||||
debug!("Abilities: {}", info_str);
|
debug!("Abilities: {}", info_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -57,14 +57,13 @@ impl BcCamera {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
PrintFormat::Xml => {
|
PrintFormat::Xml => {
|
||||||
let bat_ser = String::from_utf8(
|
let bat_ser = String::from_utf8({
|
||||||
yaserde::ser::serialize_with_writer(
|
let mut ser_buf = bytes::BytesMut::new();
|
||||||
battery,
|
let parsed =
|
||||||
vec![],
|
quick_xml::se::to_writer(&mut ser_buf, &battery)
|
||||||
&Default::default(),
|
.map(|_| ser_buf);
|
||||||
)
|
parsed.expect("Could not serialise data").to_vec()
|
||||||
.expect("Should Ser the struct"),
|
})
|
||||||
)
|
|
||||||
.expect("Should be UTF8");
|
.expect("Should be UTF8");
|
||||||
println!("{}", bat_ser);
|
println!("{}", bat_ser);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -350,28 +350,21 @@ impl Discoverer {
|
|||||||
let port = self.local_addr().port();
|
let port = self.local_addr().port();
|
||||||
let msg = UdpDiscovery {
|
let msg = UdpDiscovery {
|
||||||
tid,
|
tid,
|
||||||
payload: UdpXml {
|
payload: UdpXml::C2dC(C2dC {
|
||||||
c2d_c: Some(C2dC {
|
uid: uid.to_string(),
|
||||||
uid: uid.to_string(),
|
cli: ClientList { port: port as u32 },
|
||||||
cli: ClientList { port: port as u32 },
|
cid: client_id,
|
||||||
cid: client_id,
|
mtu: MTU,
|
||||||
mtu: MTU,
|
debug: false,
|
||||||
debug: false,
|
os: "MAC".to_string(),
|
||||||
os: "MAC".to_string(),
|
}),
|
||||||
}),
|
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let (camera_address, camera_id) = self
|
let (camera_address, camera_id) = self
|
||||||
.retry_send(msg, addr, |bc, addr| match bc {
|
.retry_send(msg, addr, |bc, addr| match bc {
|
||||||
UdpDiscovery {
|
UdpDiscovery {
|
||||||
tid: _,
|
tid: _,
|
||||||
payload:
|
payload: UdpXml::D2cCr(D2cCr { did, cid, .. }),
|
||||||
UdpXml {
|
|
||||||
d2c_c_r: Some(D2cCr { did, cid, .. }),
|
|
||||||
..
|
|
||||||
},
|
|
||||||
} if cid == client_id => Some((addr, did)),
|
} if cid == client_id => Some((addr, did)),
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
@@ -422,24 +415,17 @@ impl Discoverer {
|
|||||||
async fn uid_lookup(&self, uid: &str, addr: SocketAddr) -> Result<UidLookupResults> {
|
async fn uid_lookup(&self, uid: &str, addr: SocketAddr) -> Result<UidLookupResults> {
|
||||||
let msg = UdpDiscovery {
|
let msg = UdpDiscovery {
|
||||||
tid: 0,
|
tid: 0,
|
||||||
payload: UdpXml {
|
payload: UdpXml::C2mQ(C2mQ {
|
||||||
c2m_q: Some(C2mQ {
|
uid: uid.to_string(),
|
||||||
uid: uid.to_string(),
|
os: "MAC".to_string(),
|
||||||
os: "MAC".to_string(),
|
}),
|
||||||
}),
|
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
trace!("Sending look up {:?}", msg);
|
trace!("Sending look up {:?}", msg);
|
||||||
let (packet, _) = self
|
let (packet, _) = self
|
||||||
.retry_send(msg, addr, |bc, addr| match bc {
|
.retry_send(msg, addr, |bc, addr| match bc {
|
||||||
UdpDiscovery {
|
UdpDiscovery {
|
||||||
tid: _,
|
tid: _,
|
||||||
payload:
|
payload: UdpXml::M2cQr(m2c_q_r),
|
||||||
UdpXml {
|
|
||||||
m2c_q_r: Some(m2c_q_r),
|
|
||||||
..
|
|
||||||
},
|
|
||||||
} if valid_addr(&m2c_q_r.reg) => Some((m2c_q_r, addr)),
|
} if valid_addr(&m2c_q_r.reg) => Some((m2c_q_r, addr)),
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
@@ -469,28 +455,27 @@ impl Discoverer {
|
|||||||
|
|
||||||
let msg = UdpDiscovery {
|
let msg = UdpDiscovery {
|
||||||
tid,
|
tid,
|
||||||
payload: UdpXml {
|
payload: UdpXml::C2rC(C2rC {
|
||||||
c2r_c: Some(C2rC {
|
uid: uid.to_string(),
|
||||||
uid: uid.to_string(),
|
cli: IpPort {
|
||||||
cli: IpPort {
|
ip: local_ip.to_string(),
|
||||||
ip: local_ip.to_string(),
|
port: local_port,
|
||||||
port: local_port,
|
},
|
||||||
},
|
relay: IpPort {
|
||||||
relay: IpPort {
|
ip: lookup.relay.ip().to_string(),
|
||||||
ip: lookup.relay.ip().to_string(),
|
port: lookup.relay.port(),
|
||||||
port: lookup.relay.port(),
|
},
|
||||||
},
|
cid: client_id,
|
||||||
cid: client_id,
|
family: local_family,
|
||||||
family: local_family,
|
debug: false,
|
||||||
debug: false,
|
os: "MAC".to_string(),
|
||||||
os: "MAC".to_string(),
|
revision: Some(3),
|
||||||
revision: Some(3),
|
}),
|
||||||
}),
|
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
trace!("Registering: {:?}", msg.payload.c2r_c);
|
if let UdpXml::C2rC(ref c2r_c) = msg.payload {
|
||||||
|
trace!("Registering: {:?}", c2r_c);
|
||||||
|
}
|
||||||
|
|
||||||
// Send and await acceptance
|
// Send and await acceptance
|
||||||
let (sid, dev, dmap, relay) = self
|
let (sid, dev, dmap, relay) = self
|
||||||
@@ -500,18 +485,14 @@ impl Discoverer {
|
|||||||
UdpDiscovery {
|
UdpDiscovery {
|
||||||
tid: _,
|
tid: _,
|
||||||
payload:
|
payload:
|
||||||
UdpXml {
|
UdpXml::R2cCr(R2cCr {
|
||||||
r2c_c_r:
|
dmap,
|
||||||
Some(R2cCr {
|
dev,
|
||||||
dmap,
|
relay,
|
||||||
dev,
|
sid,
|
||||||
relay,
|
rsp,
|
||||||
sid,
|
|
||||||
rsp,
|
|
||||||
..
|
|
||||||
}),
|
|
||||||
..
|
..
|
||||||
},
|
}),
|
||||||
} if (dev.as_ref().map(valid_addr).unwrap_or(false)
|
} if (dev.as_ref().map(valid_addr).unwrap_or(false)
|
||||||
|| dmap.as_ref().map(valid_addr).unwrap_or(false)
|
|| dmap.as_ref().map(valid_addr).unwrap_or(false)
|
||||||
|| relay.as_ref().map(valid_addr).unwrap_or(false))
|
|| relay.as_ref().map(valid_addr).unwrap_or(false))
|
||||||
@@ -553,17 +534,13 @@ impl Discoverer {
|
|||||||
UdpDiscovery {
|
UdpDiscovery {
|
||||||
tid: _,
|
tid: _,
|
||||||
payload:
|
payload:
|
||||||
UdpXml {
|
UdpXml::R2cCr(R2cCr {
|
||||||
r2c_c_r:
|
dev,
|
||||||
Some(R2cCr {
|
dmap,
|
||||||
dev,
|
relay,
|
||||||
dmap,
|
rsp,
|
||||||
relay,
|
|
||||||
rsp,
|
|
||||||
..
|
|
||||||
}),
|
|
||||||
..
|
..
|
||||||
},
|
}),
|
||||||
} if (dev.as_ref().map(valid_addr).unwrap_or(false)
|
} if (dev.as_ref().map(valid_addr).unwrap_or(false)
|
||||||
|| dmap.as_ref().map(valid_addr).unwrap_or(false)
|
|| dmap.as_ref().map(valid_addr).unwrap_or(false)
|
||||||
|| relay.as_ref().map(valid_addr).unwrap_or(false))
|
|| relay.as_ref().map(valid_addr).unwrap_or(false))
|
||||||
@@ -598,17 +575,13 @@ impl Discoverer {
|
|||||||
UdpDiscovery {
|
UdpDiscovery {
|
||||||
tid,
|
tid,
|
||||||
payload:
|
payload:
|
||||||
UdpXml {
|
UdpXml::D2cT(D2cT {
|
||||||
d2c_t:
|
sid,
|
||||||
Some(D2cT {
|
cid,
|
||||||
sid,
|
did,
|
||||||
cid,
|
conn,
|
||||||
did,
|
|
||||||
conn,
|
|
||||||
..
|
|
||||||
}),
|
|
||||||
..
|
..
|
||||||
},
|
}),
|
||||||
},
|
},
|
||||||
RegisterResult {
|
RegisterResult {
|
||||||
dmap: register_dmap,
|
dmap: register_dmap,
|
||||||
@@ -632,16 +605,13 @@ impl Discoverer {
|
|||||||
|
|
||||||
let msg = UdpDiscovery {
|
let msg = UdpDiscovery {
|
||||||
tid: local_tid,
|
tid: local_tid,
|
||||||
payload: UdpXml {
|
payload: UdpXml::C2dA(C2dA {
|
||||||
c2d_a: Some(C2dA {
|
sid: register_result.sid,
|
||||||
sid: register_result.sid,
|
conn: "local".to_string(),
|
||||||
conn: "local".to_string(),
|
cid: register_result.client_id,
|
||||||
cid: register_result.client_id,
|
did: local_did,
|
||||||
did: local_did,
|
mtu: MTU,
|
||||||
mtu: MTU,
|
}),
|
||||||
}),
|
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let permit = self
|
let permit = self
|
||||||
@@ -657,17 +627,13 @@ impl Discoverer {
|
|||||||
UdpDiscovery {
|
UdpDiscovery {
|
||||||
tid: _,
|
tid: _,
|
||||||
payload:
|
payload:
|
||||||
UdpXml {
|
UdpXml::D2cCfm(D2cCfm {
|
||||||
d2c_cfm:
|
sid,
|
||||||
Some(D2cCfm {
|
cid,
|
||||||
sid,
|
did,
|
||||||
cid,
|
conn,
|
||||||
did,
|
|
||||||
conn,
|
|
||||||
..
|
|
||||||
}),
|
|
||||||
..
|
..
|
||||||
},
|
}),
|
||||||
} if sid == register_result.sid
|
} if sid == register_result.sid
|
||||||
&& did == local_did
|
&& did == local_did
|
||||||
&& cid == register_result.client_id
|
&& cid == register_result.client_id
|
||||||
@@ -690,16 +656,13 @@ impl Discoverer {
|
|||||||
// Confirm local to register
|
// Confirm local to register
|
||||||
let msg = UdpDiscovery {
|
let msg = UdpDiscovery {
|
||||||
tid: 0,
|
tid: 0,
|
||||||
payload: UdpXml {
|
payload: UdpXml::C2rCfm(C2rCfm {
|
||||||
c2r_cfm: Some(C2rCfm {
|
sid: result.sid,
|
||||||
sid: result.sid,
|
cid: result.client_id,
|
||||||
cid: result.client_id,
|
did: result.camera_id,
|
||||||
did: result.camera_id,
|
rsp: 0,
|
||||||
rsp: 0,
|
conn: "local".to_string(),
|
||||||
conn: "local".to_string(),
|
}),
|
||||||
}),
|
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
self.send_and_forget(msg, register_result.reg).await?;
|
self.send_and_forget(msg, register_result.reg).await?;
|
||||||
@@ -723,17 +686,13 @@ impl Discoverer {
|
|||||||
UdpDiscovery {
|
UdpDiscovery {
|
||||||
tid,
|
tid,
|
||||||
payload:
|
payload:
|
||||||
UdpXml {
|
UdpXml::D2cT(D2cT {
|
||||||
d2c_t:
|
sid,
|
||||||
Some(D2cT {
|
cid,
|
||||||
sid,
|
did,
|
||||||
cid,
|
conn,
|
||||||
did,
|
|
||||||
conn,
|
|
||||||
..
|
|
||||||
}),
|
|
||||||
..
|
..
|
||||||
},
|
}),
|
||||||
},
|
},
|
||||||
RegisterResult {
|
RegisterResult {
|
||||||
dmap: register_dmap,
|
dmap: register_dmap,
|
||||||
@@ -757,16 +716,13 @@ impl Discoverer {
|
|||||||
|
|
||||||
let msg = UdpDiscovery {
|
let msg = UdpDiscovery {
|
||||||
tid: local_tid,
|
tid: local_tid,
|
||||||
payload: UdpXml {
|
payload: UdpXml::C2dA(C2dA {
|
||||||
c2d_a: Some(C2dA {
|
sid: register_result.sid,
|
||||||
sid: register_result.sid,
|
conn: "map".to_string(),
|
||||||
conn: "map".to_string(),
|
cid: register_result.client_id,
|
||||||
cid: register_result.client_id,
|
did: local_did,
|
||||||
did: local_did,
|
mtu: MTU,
|
||||||
mtu: MTU,
|
}),
|
||||||
}),
|
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let permit = self
|
let permit = self
|
||||||
@@ -782,17 +738,13 @@ impl Discoverer {
|
|||||||
UdpDiscovery {
|
UdpDiscovery {
|
||||||
tid: _,
|
tid: _,
|
||||||
payload:
|
payload:
|
||||||
UdpXml {
|
UdpXml::D2cCfm(D2cCfm {
|
||||||
d2c_cfm:
|
sid,
|
||||||
Some(D2cCfm {
|
cid,
|
||||||
sid,
|
did,
|
||||||
cid,
|
conn,
|
||||||
did,
|
|
||||||
conn,
|
|
||||||
..
|
|
||||||
}),
|
|
||||||
..
|
..
|
||||||
},
|
}),
|
||||||
} if sid == register_result.sid
|
} if sid == register_result.sid
|
||||||
&& did == local_did
|
&& did == local_did
|
||||||
&& cid == register_result.client_id
|
&& cid == register_result.client_id
|
||||||
@@ -815,16 +767,13 @@ impl Discoverer {
|
|||||||
// Confirm map to register
|
// Confirm map to register
|
||||||
let msg = UdpDiscovery {
|
let msg = UdpDiscovery {
|
||||||
tid: 0,
|
tid: 0,
|
||||||
payload: UdpXml {
|
payload: UdpXml::C2rCfm(C2rCfm {
|
||||||
c2r_cfm: Some(C2rCfm {
|
sid: result.sid,
|
||||||
sid: result.sid,
|
cid: result.client_id,
|
||||||
cid: result.client_id,
|
did: result.camera_id,
|
||||||
did: result.camera_id,
|
rsp: 0,
|
||||||
rsp: 0,
|
conn: "map".to_string(),
|
||||||
conn: "map".to_string(),
|
}),
|
||||||
}),
|
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
self.send_and_forget(msg, register_result.reg).await?;
|
self.send_and_forget(msg, register_result.reg).await?;
|
||||||
@@ -845,26 +794,19 @@ impl Discoverer {
|
|||||||
let dev_addr = register_result.dev.ok_or(Error::NoDev)?;
|
let dev_addr = register_result.dev.ok_or(Error::NoDev)?;
|
||||||
let msg = UdpDiscovery {
|
let msg = UdpDiscovery {
|
||||||
tid,
|
tid,
|
||||||
payload: UdpXml {
|
payload: UdpXml::C2dT(C2dT {
|
||||||
c2d_t: Some(C2dT {
|
sid: register_result.sid,
|
||||||
sid: register_result.sid,
|
cid: register_result.client_id,
|
||||||
cid: register_result.client_id,
|
mtu: MTU,
|
||||||
mtu: MTU,
|
conn: "local".to_string(),
|
||||||
conn: "local".to_string(),
|
}),
|
||||||
}),
|
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let (final_addr, local_did) = self
|
let (final_addr, local_did) = self
|
||||||
.retry_send(msg, dev_addr, |bc, addr| match bc {
|
.retry_send(msg, dev_addr, |bc, addr| match bc {
|
||||||
UdpDiscovery {
|
UdpDiscovery {
|
||||||
tid: _,
|
tid: _,
|
||||||
payload:
|
payload: UdpXml::D2cCfm(D2cCfm { cid, did, sid, .. }),
|
||||||
UdpXml {
|
|
||||||
d2c_cfm: Some(D2cCfm { cid, did, sid, .. }),
|
|
||||||
..
|
|
||||||
},
|
|
||||||
} if cid == register_result.client_id && sid == register_result.sid => {
|
} if cid == register_result.client_id && sid == register_result.sid => {
|
||||||
Some((addr, did))
|
Some((addr, did))
|
||||||
}
|
}
|
||||||
@@ -888,16 +830,13 @@ impl Discoverer {
|
|||||||
// Confirm local to register
|
// Confirm local to register
|
||||||
let msg = UdpDiscovery {
|
let msg = UdpDiscovery {
|
||||||
tid: 0,
|
tid: 0,
|
||||||
payload: UdpXml {
|
payload: UdpXml::C2rCfm(C2rCfm {
|
||||||
c2r_cfm: Some(C2rCfm {
|
sid: result.sid,
|
||||||
sid: result.sid,
|
cid: result.client_id,
|
||||||
cid: result.client_id,
|
did: result.camera_id,
|
||||||
did: result.camera_id,
|
conn: "local".to_string(),
|
||||||
conn: "local".to_string(),
|
rsp: 0,
|
||||||
rsp: 0,
|
}),
|
||||||
}),
|
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
self.send_and_forget(msg, register_result.reg).await?;
|
self.send_and_forget(msg, register_result.reg).await?;
|
||||||
@@ -918,15 +857,12 @@ impl Discoverer {
|
|||||||
let relay_addr = register_result.relay.ok_or(Error::NoDev)?;
|
let relay_addr = register_result.relay.ok_or(Error::NoDev)?;
|
||||||
let msg = UdpDiscovery {
|
let msg = UdpDiscovery {
|
||||||
tid,
|
tid,
|
||||||
payload: UdpXml {
|
payload: UdpXml::C2dT(C2dT {
|
||||||
c2d_t: Some(C2dT {
|
sid: register_result.sid,
|
||||||
sid: register_result.sid,
|
cid: register_result.client_id,
|
||||||
cid: register_result.client_id,
|
mtu: MTU,
|
||||||
mtu: MTU,
|
conn: "relay".to_string(),
|
||||||
conn: "relay".to_string(),
|
}),
|
||||||
}),
|
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let permit = self
|
let permit = self
|
||||||
@@ -940,17 +876,13 @@ impl Discoverer {
|
|||||||
UdpDiscovery {
|
UdpDiscovery {
|
||||||
tid: _,
|
tid: _,
|
||||||
payload:
|
payload:
|
||||||
UdpXml {
|
UdpXml::D2cCfm(D2cCfm {
|
||||||
d2c_cfm:
|
cid,
|
||||||
Some(D2cCfm {
|
did,
|
||||||
cid,
|
sid,
|
||||||
did,
|
conn,
|
||||||
sid,
|
|
||||||
conn,
|
|
||||||
..
|
|
||||||
}),
|
|
||||||
..
|
..
|
||||||
},
|
}),
|
||||||
} if cid == register_result.client_id
|
} if cid == register_result.client_id
|
||||||
&& sid == register_result.sid
|
&& sid == register_result.sid
|
||||||
&& &conn == "relay" =>
|
&& &conn == "relay" =>
|
||||||
@@ -971,16 +903,13 @@ impl Discoverer {
|
|||||||
// Confirm relay to register
|
// Confirm relay to register
|
||||||
let msg = UdpDiscovery {
|
let msg = UdpDiscovery {
|
||||||
tid: 0,
|
tid: 0,
|
||||||
payload: UdpXml {
|
payload: UdpXml::C2rCfm(C2rCfm {
|
||||||
c2r_cfm: Some(C2rCfm {
|
sid: result.sid,
|
||||||
sid: result.sid,
|
cid: result.client_id,
|
||||||
cid: result.client_id,
|
did: result.camera_id,
|
||||||
did: result.camera_id,
|
conn: "relay".to_string(),
|
||||||
conn: "relay".to_string(),
|
rsp: 0,
|
||||||
rsp: 0,
|
}),
|
||||||
}),
|
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
self.send_and_forget(msg, register_result.reg).await?;
|
self.send_and_forget(msg, register_result.reg).await?;
|
||||||
@@ -1009,13 +938,10 @@ impl Discoverer {
|
|||||||
interval.tick().await;
|
interval.tick().await;
|
||||||
let msg = BcUdp::Discovery(UdpDiscovery {
|
let msg = BcUdp::Discovery(UdpDiscovery {
|
||||||
tid,
|
tid,
|
||||||
payload: UdpXml {
|
payload: UdpXml::C2dHb(C2dHb {
|
||||||
c2d_hb: Some(C2dHb {
|
|
||||||
cid: client_id,
|
cid: client_id,
|
||||||
did: camera_id,
|
did: camera_id,
|
||||||
}),
|
}),
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
if sender.send((msg, addr)).await.is_err() {
|
if sender.send((msg, addr)).await.is_err() {
|
||||||
break Result::Ok(());
|
break Result::Ok(());
|
||||||
@@ -1044,14 +970,11 @@ impl Discoverer {
|
|||||||
interval.tick().await;
|
interval.tick().await;
|
||||||
let msg = BcUdp::Discovery(UdpDiscovery {
|
let msg = BcUdp::Discovery(UdpDiscovery {
|
||||||
tid,
|
tid,
|
||||||
payload: UdpXml {
|
payload: UdpXml::C2rHb(C2rHb {
|
||||||
c2r_hb: Some(C2rHb {
|
|
||||||
sid,
|
sid,
|
||||||
cid: client_id,
|
cid: client_id,
|
||||||
did: camera_id,
|
did: camera_id,
|
||||||
}),
|
}),
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
if sender.send((msg, addr)).await.is_err() {
|
if sender.send((msg, addr)).await.is_err() {
|
||||||
break Result::Ok(());
|
break Result::Ok(());
|
||||||
@@ -1167,7 +1090,7 @@ impl Discovery {
|
|||||||
) -> Result<DiscoveryResult> {
|
) -> Result<DiscoveryResult> {
|
||||||
let mut dests = get_broadcasts(&[2015, 2018])?;
|
let mut dests = get_broadcasts(&[2015, 2018])?;
|
||||||
if let Some(mut optional_addrs) = optional_addrs.take() {
|
if let Some(mut optional_addrs) = optional_addrs.take() {
|
||||||
trace!("Also sending to {:?}", optional_addrs);
|
debug!("Also sending to {:?}", optional_addrs);
|
||||||
dests.append(&mut optional_addrs);
|
dests.append(&mut optional_addrs);
|
||||||
}
|
}
|
||||||
let discoverer_ref = &self.discoverer;
|
let discoverer_ref = &self.discoverer;
|
||||||
|
|||||||
@@ -384,13 +384,10 @@ impl UdpPayloadInner {
|
|||||||
let mut rng = thread_rng();
|
let mut rng = thread_rng();
|
||||||
(rng.gen::<u8>()) as u32
|
(rng.gen::<u8>()) as u32
|
||||||
},
|
},
|
||||||
payload: UdpXml {
|
payload: UdpXml::C2dHb(C2dHb {
|
||||||
c2d_hb: Some(C2dHb {
|
|
||||||
cid: thread_client_id,
|
cid: thread_client_id,
|
||||||
did: thread_camera_id,
|
did: thread_camera_id,
|
||||||
}),
|
}),
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
let _ = tokio::time::timeout(tokio::time::Duration::from_millis(250), inner.send((msg, thread_camera_addr))).await;
|
let _ = tokio::time::timeout(tokio::time::Duration::from_millis(250), inner.send((msg, thread_camera_addr))).await;
|
||||||
}
|
}
|
||||||
@@ -449,13 +446,10 @@ impl UdpPayloadInner {
|
|||||||
let mut rng = thread_rng();
|
let mut rng = thread_rng();
|
||||||
(rng.gen::<u8>()) as u32
|
(rng.gen::<u8>()) as u32
|
||||||
},
|
},
|
||||||
payload: UdpXml {
|
payload: UdpXml::C2dHb(C2dHb {
|
||||||
c2d_hb: Some(C2dHb {
|
|
||||||
cid: thread_client_id,
|
cid: thread_client_id,
|
||||||
did: thread_camera_id,
|
did: thread_camera_id,
|
||||||
}),
|
}),
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
if thread_sender.send(msg).await.is_err() {
|
if thread_sender.send(msg).await.is_err() {
|
||||||
break Result::Ok(());
|
break Result::Ok(());
|
||||||
|
|||||||
@@ -1,33 +1,33 @@
|
|||||||
use super::bc::model::Bc;
|
use super::bc::model::Bc;
|
||||||
use crate::NomErrorType;
|
use crate::NomErrorType;
|
||||||
use err_derive::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
/// This is the primary error type of the library
|
/// This is the primary error type of the library
|
||||||
#[derive(Debug, Error, Clone)]
|
#[derive(Debug, Error, Clone)]
|
||||||
#[allow(clippy::large_enum_variant)]
|
#[allow(clippy::large_enum_variant)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
/// Underlying IO errors
|
/// Underlying IO errors
|
||||||
#[error(display = "IO Error: {:?}", _0)]
|
#[error("IO Error: {:?}", _0)]
|
||||||
Io(#[error(source)] std::sync::Arc<std::io::Error>),
|
Io(#[from] std::sync::Arc<std::io::Error>),
|
||||||
|
|
||||||
/// Raised when fails to parse time from the camera
|
/// Raised when fails to parse time from the camera
|
||||||
#[error(display = "Error in time coversion: {:?}", _0)]
|
#[error("Error in time coversion: {:?}", _0)]
|
||||||
TimeRange(#[error(source)] time::error::ComponentRange),
|
TimeRange(#[from] time::error::ComponentRange),
|
||||||
|
|
||||||
/// Raised when fails to parse time from the camera
|
/// Raised when fails to parse time from the camera
|
||||||
#[error(display = "Error in time parsing")]
|
#[error("Error in time parsing")]
|
||||||
TimeParse,
|
TimeParse,
|
||||||
|
|
||||||
/// Raised when fails to parse time from the camera
|
/// Raised when fails to parse time from the camera
|
||||||
#[error(display = "Error in try from NonZeroInt")]
|
#[error("Error in try from NonZeroInt")]
|
||||||
TryFromInt(#[error(source)] std::num::TryFromIntError),
|
TryFromInt(#[from] std::num::TryFromIntError),
|
||||||
|
|
||||||
/// /// Raised when fails to parse time from the camera
|
/// /// Raised when fails to parse time from the camera
|
||||||
#[error(display = "Error in time conversion")]
|
#[error("Error in time conversion")]
|
||||||
TimeTryFrom(#[error(source)] time::error::TryFromParsed),
|
TimeTryFrom(#[from] time::error::TryFromParsed),
|
||||||
|
|
||||||
/// Raised when a Bc reply was not understood
|
/// Raised when a Bc reply was not understood
|
||||||
#[error(display = "Communication error")]
|
#[error("Communication error")]
|
||||||
UnintelligibleReply {
|
UnintelligibleReply {
|
||||||
/// The Bc packet that was not understood
|
/// The Bc packet that was not understood
|
||||||
reply: std::sync::Arc<Box<Bc>>,
|
reply: std::sync::Arc<Box<Bc>>,
|
||||||
@@ -36,140 +36,135 @@ pub enum Error {
|
|||||||
},
|
},
|
||||||
|
|
||||||
/// Raised when the camera responds with a status code over than OK
|
/// Raised when the camera responds with a status code over than OK
|
||||||
#[error(display = "Camera responded with Service Unavaliable: {}", _0)]
|
#[error("Camera responded with Service Unavaliable: {}", _0)]
|
||||||
CameraServiceUnavaliable(u16),
|
CameraServiceUnavaliable(u16),
|
||||||
|
|
||||||
/// Raised when the camera responds with a status code over than OK during login
|
/// Raised when the camera responds with a status code over than OK during login
|
||||||
#[error(display = "Camera responded with Err during login")]
|
#[error("Camera responded with Err during login")]
|
||||||
CameraLoginFail,
|
CameraLoginFail,
|
||||||
|
|
||||||
/// Raised when a connection is dropped.
|
/// Raised when a connection is dropped.
|
||||||
#[error(display = "Dropped connection")]
|
#[error("Dropped connection")]
|
||||||
DroppedConnection,
|
DroppedConnection,
|
||||||
|
|
||||||
/// Raised when a connection is dropped during a tokio mpsc TryRecv event
|
/// Raised when a connection is dropped during a tokio mpsc TryRecv event
|
||||||
#[error(display = "Dropped connection (TryRecv)")]
|
#[error("Dropped connection (TryRecv)")]
|
||||||
DroppedConnectionTry(#[error(source)] tokio::sync::mpsc::error::TryRecvError),
|
DroppedConnectionTry(#[from] tokio::sync::mpsc::error::TryRecvError),
|
||||||
|
|
||||||
/// Raised when a connection is dropped during a TryRecv event
|
/// Raised when a connection is dropped during a TryRecv event
|
||||||
#[error(display = "Dropped connection (Broadcast TryRecv)")]
|
#[error("Dropped connection (Broadcast TryRecv)")]
|
||||||
BroadcastDroppedConnectionTry(#[error(source)] tokio::sync::broadcast::error::TryRecvError),
|
BroadcastDroppedConnectionTry(#[from] tokio::sync::broadcast::error::TryRecvError),
|
||||||
|
|
||||||
/// Raised when a connection is dropped during a TryRecv event
|
/// Raised when a connection is dropped during a TryRecv event
|
||||||
#[error(display = "Send Error")]
|
#[error("Send Error")]
|
||||||
TokioBcSendError,
|
TokioBcSendError,
|
||||||
|
|
||||||
/// Raised when the TIMEOUT is reach
|
/// Raised when the TIMEOUT is reach
|
||||||
#[error(display = "Timeout")]
|
#[error("Timeout")]
|
||||||
Timeout(#[error(source)] std::sync::Arc<tokio::time::error::Elapsed>),
|
Timeout(#[from] std::sync::Arc<tokio::time::error::Elapsed>),
|
||||||
|
|
||||||
/// Raised when a timeout fails in a non standard way such as timeout during shutdown
|
/// Raised when a timeout fails in a non standard way such as timeout during shutdown
|
||||||
#[error(display = "TimeoutError")]
|
#[error("TimeoutError")]
|
||||||
TimeoutError(#[error(source)] tokio::time::error::Error),
|
TimeoutError(#[from] tokio::time::error::Error),
|
||||||
|
|
||||||
/// Raised when connection is dropped because the timeout is reach
|
/// Raised when connection is dropped because the timeout is reach
|
||||||
#[error(display = "Dropped connection (Timeout)")]
|
#[error("Dropped connection (Timeout)")]
|
||||||
TimeoutDisconnected,
|
TimeoutDisconnected,
|
||||||
|
|
||||||
/// Raised when a camera cannot be connected to ay any of the given addresses
|
/// Raised when a camera cannot be connected to ay any of the given addresses
|
||||||
#[error(display = "Cannot contact camera at given address")]
|
#[error("Cannot contact camera at given address")]
|
||||||
CannotInitCamera,
|
CannotInitCamera,
|
||||||
|
|
||||||
/// Raised when failed to login to the camera
|
/// Raised when failed to login to the camera
|
||||||
#[error(display = "Credential error")]
|
#[error("Credential error")]
|
||||||
AuthFailed,
|
AuthFailed,
|
||||||
|
|
||||||
/// Raised when the given camera url could not be resolved
|
/// Raised when the given camera url could not be resolved
|
||||||
#[error(display = "Failed to translate camera address")]
|
#[error("Failed to translate camera address")]
|
||||||
AddrResolutionError,
|
AddrResolutionError,
|
||||||
|
|
||||||
/// Raised non adpcm data is sent to the talk command
|
/// Raised non adpcm data is sent to the talk command
|
||||||
#[error(display = "Talk data is not ADPCM")]
|
#[error("Talk data is not ADPCM")]
|
||||||
UnknownTalkEncoding,
|
UnknownTalkEncoding,
|
||||||
|
|
||||||
/// Raised when dicovery times out waiting for a reply
|
/// Raised when dicovery times out waiting for a reply
|
||||||
#[error(display = "Timed out while waiting for camera reply")]
|
#[error("Timed out while waiting for camera reply")]
|
||||||
DiscoveryTimeout,
|
DiscoveryTimeout,
|
||||||
|
|
||||||
/// Raised during a (de)seralisation error
|
/// Raised during a (de)seralisation error
|
||||||
#[error(display = "Cookie GenError")]
|
#[error("Cookie GenError")]
|
||||||
GenError(#[error(source)] std::sync::Arc<cookie_factory::GenError>),
|
GenError(#[from] std::sync::Arc<cookie_factory::GenError>),
|
||||||
|
|
||||||
/// Raised when a connection is subscrbed to more than once for msg_num
|
/// Raised when a connection is subscrbed to more than once for msg_num
|
||||||
#[error(display = "Simultaneous subscription, {:?}", _0)]
|
#[error("Simultaneous subscription, {msg_num:?}")]
|
||||||
SimultaneousSubscription {
|
SimultaneousSubscription {
|
||||||
/// The message number that was subscribed to
|
/// The message number that was subscribed to
|
||||||
msg_num: Option<u16>,
|
msg_num: Option<u16>,
|
||||||
},
|
},
|
||||||
|
|
||||||
/// Raised when a connection is subscrbed to more than once for msg_id
|
/// Raised when a connection is subscrbed to more than once for msg_id
|
||||||
#[error(display = "Simultaneous subscription, {}", _0)]
|
#[error("Simultaneous subscription, {msg_id}")]
|
||||||
SimultaneousSubscriptionId {
|
SimultaneousSubscriptionId {
|
||||||
/// The message number that was subscribed to
|
/// The message number that was subscribed to
|
||||||
msg_id: u32,
|
msg_id: u32,
|
||||||
},
|
},
|
||||||
|
|
||||||
/// Raised when a new encyrption byte is observed
|
/// Raised when a new encyrption byte is observed
|
||||||
#[error(display = "Unknown encryption: {:x?}", _0)]
|
#[error("Unknown encryption: {0:x?}")]
|
||||||
UnknownEncryption(usize),
|
UnknownEncryption(usize),
|
||||||
|
|
||||||
/// Raised when the camera cannot be found
|
/// Raised when the camera cannot be found
|
||||||
#[error(display = "Camera Not Findable")]
|
#[error("Camera Not Findable")]
|
||||||
ConnectionUnavaliable,
|
ConnectionUnavaliable,
|
||||||
|
|
||||||
/// Raised when the subscription id dropped too soon
|
/// Raised when the subscription id dropped too soon
|
||||||
#[error(display = "Dropped Subscriber")]
|
#[error("Dropped Subscriber")]
|
||||||
DroppedSubscriber,
|
DroppedSubscriber,
|
||||||
|
|
||||||
/// Raised when a unknown connection ID attempts to connect with us over UDP
|
/// Raised when a unknown connection ID attempts to connect with us over UDP
|
||||||
#[error(display = "Connection with unknown connectionID: {:?}", _0)]
|
#[error("Connection with unknown connectionID: {0:?}")]
|
||||||
UnknownConnectionId(i32),
|
UnknownConnectionId(i32),
|
||||||
|
|
||||||
/// Raised when a unknown SocketAddr attempts to connect with us over UDP
|
/// Raised when a unknown SocketAddr attempts to connect with us over UDP
|
||||||
#[error(display = "Connection from unknown source: {:?}", _0)]
|
#[error("Connection from unknown source: {0:?}")]
|
||||||
UnknownSource(std::net::SocketAddr),
|
UnknownSource(std::net::SocketAddr),
|
||||||
|
|
||||||
/// Raised when the IP/Hostname cannot be understood
|
/// Raised when the IP/Hostname cannot be understood
|
||||||
#[error(display = "Could not parse as IP")]
|
#[error("Could not parse as IP")]
|
||||||
AddrParseError(#[error(source)] std::net::AddrParseError),
|
AddrParseError(#[from] std::net::AddrParseError),
|
||||||
|
|
||||||
/// Raised when a relay connection is not possible
|
/// Raised when a relay connection is not possible
|
||||||
/// usually happens if the camera has not contacted reolink yet
|
/// usually happens if the camera has not contacted reolink yet
|
||||||
#[error(display = "Cannot perform relay connection with this camera")]
|
#[error("Cannot perform relay connection with this camera")]
|
||||||
NoDmap,
|
NoDmap,
|
||||||
|
|
||||||
/// Raised when a dev connection is not possible
|
/// Raised when a dev connection is not possible
|
||||||
/// usually happens if the camera has not contacted reolink yet
|
/// usually happens if the camera has not contacted reolink yet
|
||||||
#[error(display = "Cannot perform lookup with this camera against reolink servers")]
|
#[error("Cannot perform lookup with this camera against reolink servers")]
|
||||||
NoDev,
|
NoDev,
|
||||||
|
|
||||||
/// Raised when a discovery fails to be accepted by the register
|
/// Raised when a discovery fails to be accepted by the register
|
||||||
#[error(display = "Register refuses to accept us")]
|
#[error("Register refuses to accept us")]
|
||||||
RegisterError,
|
RegisterError,
|
||||||
|
|
||||||
/// Raised when a the relay terminates the connection by sending a R2C_DISC
|
/// Raised when a the relay terminates the connection by sending a R2C_DISC
|
||||||
#[error(display = "Relay terminated the connection")]
|
#[error("Relay terminated the connection")]
|
||||||
RelayTerminate,
|
RelayTerminate,
|
||||||
|
|
||||||
/// Raised when a the camera terminates the connection by sending a D2C_DISC
|
/// Raised when a the camera terminates the connection by sending a D2C_DISC
|
||||||
#[error(display = "Camera terminated the connection")]
|
#[error("Camera terminated the connection")]
|
||||||
CameraTerminate,
|
CameraTerminate,
|
||||||
|
|
||||||
/// Raised when the stream is not enough to complete a message
|
/// Raised when the stream is not enough to complete a message
|
||||||
#[error(display = "Nom Parsing incomplete: {}", _0)]
|
#[error("Nom Parsing incomplete: {0}")]
|
||||||
NomIncomplete(usize),
|
NomIncomplete(usize),
|
||||||
|
|
||||||
/// Raised when a stream cannot be decoded
|
/// Raised when a stream cannot be decoded
|
||||||
#[error(display = "Nom Parsing error: {}", _0)]
|
#[error("Nom Parsing error: {0}")]
|
||||||
NomError(String),
|
NomError(String),
|
||||||
|
|
||||||
/// Raised when a camera/user lacks an ability
|
/// Raised when a camera/user lacks an ability
|
||||||
#[error(
|
#[error("Missing ability: {name} with {requested} permission has only {actual}")]
|
||||||
display = "Missing ability: {} with {} permission has only {}",
|
|
||||||
name,
|
|
||||||
requested,
|
|
||||||
actual
|
|
||||||
)]
|
|
||||||
MissingAbility {
|
MissingAbility {
|
||||||
/// Name of the ability
|
/// Name of the ability
|
||||||
name: String,
|
name: String,
|
||||||
@@ -180,15 +175,15 @@ pub enum Error {
|
|||||||
},
|
},
|
||||||
|
|
||||||
/// Raised when a thread panics
|
/// Raised when a thread panics
|
||||||
#[error(display = "Thread panicked")]
|
#[error("Thread panicked")]
|
||||||
JoinError(#[error(source)] std::sync::Arc<tokio::task::JoinError>),
|
JoinError(#[from] std::sync::Arc<tokio::task::JoinError>),
|
||||||
|
|
||||||
/// A generic catch all error
|
/// A generic catch all error
|
||||||
#[error(display = "Other error: {}", _0)]
|
#[error("Other error: {0}")]
|
||||||
Other(&'static str),
|
Other(&'static str),
|
||||||
|
|
||||||
/// A generic catch all error
|
/// A generic catch all error
|
||||||
#[error(display = "Other error: {}", _0)]
|
#[error("Other error: {0}")]
|
||||||
OtherString(String),
|
OtherString(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ impl Decoder for BcMediaCodex {
|
|||||||
|
|
||||||
fn decode(&mut self, src: &mut BytesMut) -> Result<Option<Self::Item>> {
|
fn decode(&mut self, src: &mut BytesMut) -> Result<Option<Self::Item>> {
|
||||||
loop {
|
loop {
|
||||||
match { BcMedia::deserialize(src) } {
|
match BcMedia::deserialize(src) {
|
||||||
Ok(bc) => {
|
Ok(bc) => {
|
||||||
if self.amount_skipped > 0 {
|
if self.amount_skipped > 0 {
|
||||||
debug!("Amount skipped to restore stream: {}", self.amount_skipped);
|
debug!("Amount skipped to restore stream: {}", self.amount_skipped);
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
use super::model::BcMediaIframe;
|
|
||||||
use super::model::*;
|
use super::model::*;
|
||||||
use crate::Error;
|
use crate::Error;
|
||||||
use bytes::{Buf, BytesMut};
|
use bytes::{Buf, BytesMut};
|
||||||
|
|||||||
@@ -48,20 +48,16 @@ impl Decoder for BcUdpCodex {
|
|||||||
if src.is_empty() {
|
if src.is_empty() {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
}
|
}
|
||||||
match { BcUdp::deserialize(src) } {
|
match BcUdp::deserialize(src) {
|
||||||
Ok(BcUdp::Discovery(UdpDiscovery {
|
Ok(BcUdp::Discovery(UdpDiscovery {
|
||||||
payload: UdpXml {
|
payload: UdpXml::R2cDisc(_),
|
||||||
r2c_disc: Some(_), ..
|
|
||||||
},
|
|
||||||
..
|
..
|
||||||
})) => {
|
})) => {
|
||||||
log::trace!(" Decoding: Relay terminate");
|
log::trace!(" Decoding: Relay terminate");
|
||||||
Err(Error::RelayTerminate)
|
Err(Error::RelayTerminate)
|
||||||
}
|
}
|
||||||
Ok(BcUdp::Discovery(UdpDiscovery {
|
Ok(BcUdp::Discovery(UdpDiscovery {
|
||||||
payload: UdpXml {
|
payload: UdpXml::D2cDisc(_),
|
||||||
d2c_disc: Some(_), ..
|
|
||||||
},
|
|
||||||
..
|
..
|
||||||
})) => {
|
})) => {
|
||||||
log::trace!(" Decoding:Camera terminate");
|
log::trace!(" Decoding:Camera terminate");
|
||||||
|
|||||||
@@ -11,10 +11,10 @@ use nom::{
|
|||||||
|
|
||||||
type IResult<I, O, E = nom::error::VerboseError<I>> = Result<(I, O), nom::Err<E>>;
|
type IResult<I, O, E = nom::error::VerboseError<I>> = Result<(I, O), nom::Err<E>>;
|
||||||
|
|
||||||
fn make_error<I, E: ParseError<I>>(input: I, ctx: &'static str, kind: ErrorKind) -> E
|
fn make_error<I, E>(input: I, ctx: &'static str, kind: ErrorKind) -> E
|
||||||
where
|
where
|
||||||
I: std::marker::Copy,
|
I: std::marker::Copy,
|
||||||
E: ContextError<I>,
|
E: ContextError<I> + ParseError<I>,
|
||||||
{
|
{
|
||||||
E::add_context(input, ctx, E::from_error_kind(input, kind))
|
E::add_context(input, ctx, E::from_error_kind(input, kind))
|
||||||
}
|
}
|
||||||
@@ -164,13 +164,10 @@ mod tests {
|
|||||||
e,
|
e,
|
||||||
Ok(BcUdp::Discovery(UdpDiscovery {
|
Ok(BcUdp::Discovery(UdpDiscovery {
|
||||||
tid: 96,
|
tid: 96,
|
||||||
payload: UdpXml {
|
payload: UdpXml::C2dDisc(C2dDisc {
|
||||||
c2d_disc: Some(C2dDisc {
|
cid: 82000,
|
||||||
cid: 82000,
|
did: 80,
|
||||||
did: 80,
|
}),
|
||||||
}),
|
|
||||||
..
|
|
||||||
},
|
|
||||||
}))
|
}))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -187,15 +184,12 @@ mod tests {
|
|||||||
e,
|
e,
|
||||||
Ok(BcUdp::Discovery(UdpDiscovery {
|
Ok(BcUdp::Discovery(UdpDiscovery {
|
||||||
tid: 113,
|
tid: 113,
|
||||||
payload: UdpXml {
|
payload: UdpXml::D2cT(D2cT {
|
||||||
d2c_t: Some(D2cT {
|
|
||||||
sid: 62098713,
|
sid: 62098713,
|
||||||
conn: conn_str,
|
conn: conn_str,
|
||||||
cid: 82001,
|
cid: 82001,
|
||||||
did: 96,
|
did: 96,
|
||||||
}),
|
}),
|
||||||
..
|
|
||||||
},
|
|
||||||
})) if &conn_str == "local"
|
})) if &conn_str == "local"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -212,15 +206,12 @@ mod tests {
|
|||||||
e,
|
e,
|
||||||
Ok(BcUdp::Discovery(UdpDiscovery {
|
Ok(BcUdp::Discovery(UdpDiscovery {
|
||||||
tid: 1101,
|
tid: 1101,
|
||||||
payload: UdpXml {
|
payload: UdpXml::C2dT(C2dT {
|
||||||
c2d_t: Some(C2dT {
|
|
||||||
sid: 62098713,
|
sid: 62098713,
|
||||||
conn: conn_str,
|
conn: conn_str,
|
||||||
cid: 82001,
|
cid: 82001,
|
||||||
mtu: 1350,
|
mtu: 1350,
|
||||||
}),
|
}),
|
||||||
..
|
|
||||||
},
|
|
||||||
})) if &conn_str == "local"
|
})) if &conn_str == "local"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -237,8 +228,7 @@ mod tests {
|
|||||||
e,
|
e,
|
||||||
Ok(BcUdp::Discovery(UdpDiscovery {
|
Ok(BcUdp::Discovery(UdpDiscovery {
|
||||||
tid: 1101,
|
tid: 1101,
|
||||||
payload: UdpXml {
|
payload: UdpXml::D2cCfm(D2cCfm {
|
||||||
d2c_cfm: Some(D2cCfm {
|
|
||||||
sid: 62098713,
|
sid: 62098713,
|
||||||
conn: conn_str,
|
conn: conn_str,
|
||||||
rsp: 0,
|
rsp: 0,
|
||||||
@@ -246,8 +236,6 @@ mod tests {
|
|||||||
did: 96,
|
did: 96,
|
||||||
time_r: 0,
|
time_r: 0,
|
||||||
}),
|
}),
|
||||||
..
|
|
||||||
},
|
|
||||||
})) if &conn_str == "local"
|
})) if &conn_str == "local"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use super::{crc::calc_crc, model::*, xml_crypto::encrypt};
|
use super::{crc::calc_crc, model::*, xml_crypto::encrypt};
|
||||||
use crate::Error;
|
use crate::Error;
|
||||||
|
use bytes::BytesMut;
|
||||||
use cookie_factory::bytes::*;
|
use cookie_factory::bytes::*;
|
||||||
use cookie_factory::sequence::tuple;
|
use cookie_factory::sequence::tuple;
|
||||||
use cookie_factory::SerializeFn;
|
use cookie_factory::SerializeFn;
|
||||||
@@ -10,7 +11,10 @@ impl BcUdp {
|
|||||||
pub(crate) fn serialize<W: Write>(&self, buf: W) -> Result<W, Error> {
|
pub(crate) fn serialize<W: Write>(&self, buf: W) -> Result<W, Error> {
|
||||||
let (buf, _) = match &self {
|
let (buf, _) = match &self {
|
||||||
BcUdp::Discovery(payload) => {
|
BcUdp::Discovery(payload) => {
|
||||||
let xml_payload = encrypt(payload.tid, &payload.payload.serialize(vec![]).unwrap());
|
let xml_payload = encrypt(
|
||||||
|
payload.tid,
|
||||||
|
&payload.payload.serialize(BytesMut::new()).unwrap(),
|
||||||
|
);
|
||||||
gen(bcudp_disc(payload, &xml_payload), buf)?
|
gen(bcudp_disc(payload, &xml_payload), buf)?
|
||||||
}
|
}
|
||||||
BcUdp::Ack(payload) => {
|
BcUdp::Ack(payload) => {
|
||||||
@@ -96,7 +100,7 @@ mod tests {
|
|||||||
let msg2 = BcUdp::deserialize(&mut BytesMut::from(ser_buf.as_slice())).unwrap();
|
let msg2 = BcUdp::deserialize(&mut BytesMut::from(ser_buf.as_slice())).unwrap();
|
||||||
assert_eq!(msg, msg2);
|
assert_eq!(msg, msg2);
|
||||||
// Raw samples don't quite match exactly
|
// Raw samples don't quite match exactly
|
||||||
// because the yaserde for xml puts spaces and new lines in different places
|
// because the serde for xml puts spaces and new lines in different places
|
||||||
// then the raw data from the camera so we skip this last assert
|
// then the raw data from the camera so we skip this last assert
|
||||||
//assert_eq!(&sample[..], ser_buf.as_slice());
|
//assert_eq!(&sample[..], ser_buf.as_slice());
|
||||||
}
|
}
|
||||||
@@ -113,7 +117,7 @@ mod tests {
|
|||||||
let msg2 = BcUdp::deserialize(&mut BytesMut::from(ser_buf.as_slice())).unwrap();
|
let msg2 = BcUdp::deserialize(&mut BytesMut::from(ser_buf.as_slice())).unwrap();
|
||||||
assert_eq!(msg, msg2);
|
assert_eq!(msg, msg2);
|
||||||
// Raw samples don't quite match exactly
|
// Raw samples don't quite match exactly
|
||||||
// because the yaserde for xml puts spaces and new lines in different places
|
// because the serde for xml puts spaces and new lines in different places
|
||||||
// then the raw data from the camera so we skip this last assert
|
// then the raw data from the camera so we skip this last assert
|
||||||
//assert_eq!(&sample[..], ser_buf.as_slice());
|
//assert_eq!(&sample[..], ser_buf.as_slice());
|
||||||
}
|
}
|
||||||
@@ -130,7 +134,7 @@ mod tests {
|
|||||||
let msg2 = BcUdp::deserialize(&mut BytesMut::from(ser_buf.as_slice())).unwrap();
|
let msg2 = BcUdp::deserialize(&mut BytesMut::from(ser_buf.as_slice())).unwrap();
|
||||||
assert_eq!(msg, msg2);
|
assert_eq!(msg, msg2);
|
||||||
// Raw samples don't quite match exactly
|
// Raw samples don't quite match exactly
|
||||||
// because the yaserde for xml puts spaces and new lines in different places
|
// because the serde for xml puts spaces and new lines in different places
|
||||||
// then the raw data from the camera so we skip this last assert
|
// then the raw data from the camera so we skip this last assert
|
||||||
//assert_eq!(&sample[..], ser_buf.as_slice());
|
//assert_eq!(&sample[..], ser_buf.as_slice());
|
||||||
}
|
}
|
||||||
@@ -147,7 +151,7 @@ mod tests {
|
|||||||
let msg2 = BcUdp::deserialize(&mut BytesMut::from(ser_buf.as_slice())).unwrap();
|
let msg2 = BcUdp::deserialize(&mut BytesMut::from(ser_buf.as_slice())).unwrap();
|
||||||
assert_eq!(msg, msg2);
|
assert_eq!(msg, msg2);
|
||||||
// Raw samples don't quite match exactly
|
// Raw samples don't quite match exactly
|
||||||
// because the yaserde for xml puts spaces and new lines in different places
|
// because the serde for xml puts spaces and new lines in different places
|
||||||
// then the raw data from the camera so we skip this last assert
|
// then the raw data from the camera so we skip this last assert
|
||||||
//assert_eq!(&sample[..], ser_buf.as_slice());
|
//assert_eq!(&sample[..], ser_buf.as_slice());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,76 +1,73 @@
|
|||||||
// YaSerde currently macro-expands names like __type__value from type_
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::fmt::Write;
|
||||||
use std::io::{Read, Write};
|
use std::io::BufRead;
|
||||||
// YaSerde is currently naming the traits and the derive macros identically
|
|
||||||
use yaserde::ser::Config;
|
|
||||||
use yaserde_derive::{YaDeserialize, YaSerialize};
|
|
||||||
|
|
||||||
/// The top level of the UDP xml is P2P
|
/// The top level of the UDP xml is P2P
|
||||||
#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize, Clone)]
|
#[derive(PartialEq, Eq, Debug, Deserialize, Serialize, Clone)]
|
||||||
#[yaserde(rename = "P2P")]
|
pub enum UdpXml {
|
||||||
pub struct UdpXml {
|
|
||||||
/// C2D_S xml Discovery of any client
|
/// C2D_S xml Discovery of any client
|
||||||
#[yaserde(rename = "C2D_S")]
|
#[serde(rename = "C2D_S")]
|
||||||
pub c2d_s: Option<C2dS>,
|
C2dS(C2dS),
|
||||||
/// C2D_S xml Discovery of client with a UID
|
/// C2D_S xml Discovery of client with a UID
|
||||||
#[yaserde(rename = "C2D_C")]
|
#[serde(rename = "C2D_C")]
|
||||||
pub c2d_c: Option<C2dC>,
|
C2dC(C2dC),
|
||||||
/// D2C_C_C xml Reply from discovery
|
/// D2C_C_C xml Reply from discovery
|
||||||
#[yaserde(rename = "D2C_C_R")]
|
#[serde(rename = "D2C_C_R")]
|
||||||
pub d2c_c_r: Option<D2cCr>,
|
D2cCr(D2cCr),
|
||||||
/// D2C_T xml
|
/// D2C_T xml
|
||||||
#[yaserde(rename = "D2C_T")]
|
#[serde(rename = "D2C_T")]
|
||||||
pub d2c_t: Option<D2cT>,
|
D2cT(D2cT),
|
||||||
/// C2D_T xml
|
/// C2D_T xml
|
||||||
#[yaserde(rename = "C2D_T")]
|
#[serde(rename = "C2D_T")]
|
||||||
pub c2d_t: Option<C2dT>,
|
C2dT(C2dT),
|
||||||
/// D2C_CFM xml
|
/// D2C_CFM xml
|
||||||
#[yaserde(rename = "D2C_CFM")]
|
#[serde(rename = "D2C_CFM")]
|
||||||
pub d2c_cfm: Option<D2cCfm>,
|
D2cCfm(D2cCfm),
|
||||||
/// C2D_DISC xml Disconnect
|
/// C2D_DISC xml Disconnect
|
||||||
#[yaserde(rename = "C2D_DISC")]
|
#[serde(rename = "C2D_DISC")]
|
||||||
pub c2d_disc: Option<C2dDisc>,
|
C2dDisc(C2dDisc),
|
||||||
/// D2C_DISC xml Disconnect
|
/// D2C_DISC xml Disconnect
|
||||||
#[yaserde(rename = "D2C_DISC")]
|
#[serde(rename = "D2C_DISC")]
|
||||||
pub d2c_disc: Option<D2cDisc>,
|
D2cDisc(D2cDisc),
|
||||||
/// R2C_DISC xml Disconnect
|
/// R2C_DISC xml Disconnect
|
||||||
#[yaserde(rename = "R2C_DISC")]
|
#[serde(rename = "R2C_DISC")]
|
||||||
pub r2c_disc: Option<R2cDisc>,
|
R2cDisc(R2cDisc),
|
||||||
/// C2M_Q xml client to middle man query
|
/// C2M_Q xml client to middle man query
|
||||||
#[yaserde(rename = "C2M_Q")]
|
#[serde(rename = "C2M_Q")]
|
||||||
pub c2m_q: Option<C2mQ>,
|
C2mQ(C2mQ),
|
||||||
/// M2C_Q_R xml middle man to client query reply
|
/// M2C_Q_R xml middle man to client query reply
|
||||||
#[yaserde(rename = "M2C_Q_R")]
|
#[serde(rename = "M2C_Q_R")]
|
||||||
pub m2c_q_r: Option<M2cQr>,
|
M2cQr(M2cQr),
|
||||||
/// C2R_C xml client to register connect
|
/// C2R_C xml client to register connect
|
||||||
#[yaserde(rename = "C2R_C")]
|
#[serde(rename = "C2R_C")]
|
||||||
pub c2r_c: Option<C2rC>,
|
C2rC(C2rC),
|
||||||
/// R2C_T xml register to clinet with device ID etc
|
/// R2C_T xml register to clinet with device ID etc
|
||||||
#[yaserde(rename = "R2C_T")]
|
#[serde(rename = "R2C_T")]
|
||||||
pub r2c_t: Option<R2cT>,
|
R2cT(R2cT),
|
||||||
/// R2C_T xml register to clinet with device ID etc handled over dmap ONLY
|
/// R2C_T xml register to clinet with device ID etc handled over dmap ONLY
|
||||||
#[yaserde(rename = "R2C_C_R")]
|
#[serde(rename = "R2C_C_R")]
|
||||||
pub r2c_c_r: Option<R2cCr>,
|
R2cCr(R2cCr),
|
||||||
/// C2R_CFM xml client to register CFM
|
/// C2R_CFM xml client to register CFM
|
||||||
#[yaserde(rename = "C2R_CFM")]
|
#[serde(rename = "C2R_CFM")]
|
||||||
pub c2r_cfm: Option<C2rCfm>,
|
C2rCfm(C2rCfm),
|
||||||
/// C2D_A xml client to device accept
|
/// C2D_A xml client to device accept
|
||||||
#[yaserde(rename = "C2D_A")]
|
#[serde(rename = "C2D_A")]
|
||||||
pub c2d_a: Option<C2dA>,
|
C2dA(C2dA),
|
||||||
/// C2D_HB xml client to device heartbeat. This is the keep alive
|
/// C2D_HB xml client to device heartbeat. This is the keep alive
|
||||||
#[yaserde(rename = "C2D_HB")]
|
#[serde(rename = "C2D_HB")]
|
||||||
pub c2d_hb: Option<C2dHb>,
|
C2dHb(C2dHb),
|
||||||
/// C2D_HB xml client to device heartbeat. This is the keep alive
|
/// C2D_HB xml client to device heartbeat. This is the keep alive
|
||||||
#[yaserde(rename = "C2R_HB")]
|
#[serde(rename = "C2R_HB")]
|
||||||
pub c2r_hb: Option<C2rHb>,
|
C2rHb(C2rHb),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl UdpXml {
|
impl UdpXml {
|
||||||
pub(crate) fn try_parse(s: impl Read) -> Result<Self, String> {
|
pub(crate) fn try_parse(s: impl BufRead) -> Result<Self, quick_xml::de::DeError> {
|
||||||
yaserde::de::from_reader(s)
|
quick_xml::de::from_reader(s)
|
||||||
}
|
}
|
||||||
pub(crate) fn serialize<W: Write>(&self, w: W) -> Result<W, String> {
|
pub(crate) fn serialize<W: Write>(&self, mut w: W) -> Result<W, quick_xml::de::DeError> {
|
||||||
yaserde::ser::serialize_with_writer(self, w, &Config::default())
|
quick_xml::se::to_writer(&mut w, self)?;
|
||||||
|
Ok(w)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,14 +77,14 @@ impl UdpXml {
|
|||||||
/// to whoever it gets this message from
|
/// to whoever it gets this message from
|
||||||
///
|
///
|
||||||
/// It should be broadcasted to port 2015
|
/// It should be broadcasted to port 2015
|
||||||
#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize, Clone)]
|
#[derive(PartialEq, Eq, Default, Debug, Deserialize, Serialize, Clone)]
|
||||||
pub struct C2dS {
|
pub struct C2dS {
|
||||||
/// The destination to reply to
|
/// The destination to reply to
|
||||||
pub to: PortList,
|
pub to: PortList,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Port list xml
|
/// Port list xml
|
||||||
#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize, Clone)]
|
#[derive(PartialEq, Eq, Default, Debug, Deserialize, Serialize, Clone)]
|
||||||
pub struct PortList {
|
pub struct PortList {
|
||||||
/// Port to open udp connections with
|
/// Port to open udp connections with
|
||||||
pub port: u32,
|
pub port: u32,
|
||||||
@@ -97,7 +94,7 @@ pub struct PortList {
|
|||||||
///
|
///
|
||||||
/// This will start a connection with any camera that has this UID
|
/// This will start a connection with any camera that has this UID
|
||||||
/// It should be broadcasted to port 2018
|
/// It should be broadcasted to port 2018
|
||||||
#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize, Clone)]
|
#[derive(PartialEq, Eq, Default, Debug, Deserialize, Serialize, Clone)]
|
||||||
pub struct C2dC {
|
pub struct C2dC {
|
||||||
/// UID of the camera the client wants to connect with
|
/// UID of the camera the client wants to connect with
|
||||||
pub uid: String,
|
pub uid: String,
|
||||||
@@ -110,12 +107,12 @@ pub struct C2dC {
|
|||||||
/// Debug mode. Purpose unknown
|
/// Debug mode. Purpose unknown
|
||||||
pub debug: bool,
|
pub debug: bool,
|
||||||
/// Os of the machine known values are `"MAC"`, `"WIN"`
|
/// Os of the machine known values are `"MAC"`, `"WIN"`
|
||||||
#[yaserde(rename = "p")]
|
#[serde(rename = "p")]
|
||||||
pub os: String,
|
pub os: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Client List xml
|
/// Client List xml
|
||||||
#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize, Clone)]
|
#[derive(PartialEq, Eq, Default, Debug, Deserialize, Serialize, Clone)]
|
||||||
pub struct ClientList {
|
pub struct ClientList {
|
||||||
/// Port to start udp communication with
|
/// Port to start udp communication with
|
||||||
pub port: u32,
|
pub port: u32,
|
||||||
@@ -125,7 +122,7 @@ pub struct ClientList {
|
|||||||
///
|
///
|
||||||
/// This will start a connection with any camera that has this UID
|
/// This will start a connection with any camera that has this UID
|
||||||
/// It should be broadcasted to port 2018
|
/// It should be broadcasted to port 2018
|
||||||
#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize, Clone)]
|
#[derive(PartialEq, Eq, Default, Debug, Deserialize, Serialize, Clone)]
|
||||||
pub struct D2cCr {
|
pub struct D2cCr {
|
||||||
/// Called timer but not sure what it is a timer of
|
/// Called timer but not sure what it is a timer of
|
||||||
pub timer: Timer,
|
pub timer: Timer,
|
||||||
@@ -138,7 +135,7 @@ pub struct D2cCr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Timer provided by D2C_C_R
|
/// Timer provided by D2C_C_R
|
||||||
#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize, Clone)]
|
#[derive(PartialEq, Eq, Default, Debug, Deserialize, Serialize, Clone)]
|
||||||
pub struct Timer {
|
pub struct Timer {
|
||||||
/// Unknown
|
/// Unknown
|
||||||
def: u32,
|
def: u32,
|
||||||
@@ -149,7 +146,7 @@ pub struct Timer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// C2D_DISC xml
|
/// C2D_DISC xml
|
||||||
#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize, Clone)]
|
#[derive(PartialEq, Eq, Default, Debug, Deserialize, Serialize, Clone)]
|
||||||
pub struct C2dDisc {
|
pub struct C2dDisc {
|
||||||
/// The client connection ID
|
/// The client connection ID
|
||||||
pub cid: i32,
|
pub cid: i32,
|
||||||
@@ -158,7 +155,7 @@ pub struct C2dDisc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// D2C_DISC xml
|
/// D2C_DISC xml
|
||||||
#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize, Clone)]
|
#[derive(PartialEq, Eq, Default, Debug, Deserialize, Serialize, Clone)]
|
||||||
pub struct D2cDisc {
|
pub struct D2cDisc {
|
||||||
/// The client connection ID
|
/// The client connection ID
|
||||||
pub cid: i32,
|
pub cid: i32,
|
||||||
@@ -167,14 +164,14 @@ pub struct D2cDisc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// R2C_DISC xml
|
/// R2C_DISC xml
|
||||||
#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize, Clone)]
|
#[derive(PartialEq, Eq, Default, Debug, Deserialize, Serialize, Clone)]
|
||||||
pub struct R2cDisc {
|
pub struct R2cDisc {
|
||||||
/// The sid
|
/// The sid
|
||||||
pub sid: u32,
|
pub sid: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// D2C_T xml
|
/// D2C_T xml
|
||||||
#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize, Clone)]
|
#[derive(PartialEq, Eq, Default, Debug, Deserialize, Serialize, Clone)]
|
||||||
pub struct D2cT {
|
pub struct D2cT {
|
||||||
/// The camera SID
|
/// The camera SID
|
||||||
pub sid: u32,
|
pub sid: u32,
|
||||||
@@ -187,7 +184,7 @@ pub struct D2cT {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// C2D_T xml
|
/// C2D_T xml
|
||||||
#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize, Clone)]
|
#[derive(PartialEq, Eq, Default, Debug, Deserialize, Serialize, Clone)]
|
||||||
pub struct C2dT {
|
pub struct C2dT {
|
||||||
/// The camera SID
|
/// The camera SID
|
||||||
pub sid: u32,
|
pub sid: u32,
|
||||||
@@ -204,12 +201,12 @@ pub struct C2dT {
|
|||||||
/// This is from client to a reolink middle man server
|
/// This is from client to a reolink middle man server
|
||||||
///
|
///
|
||||||
/// It should be sent to a reolink p2p sever on port 9999
|
/// It should be sent to a reolink p2p sever on port 9999
|
||||||
#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize, Clone)]
|
#[derive(PartialEq, Eq, Default, Debug, Deserialize, Serialize, Clone)]
|
||||||
pub struct C2mQ {
|
pub struct C2mQ {
|
||||||
/// UID to look up
|
/// UID to look up
|
||||||
pub uid: String,
|
pub uid: String,
|
||||||
/// Os of the machine known values are `"MAC"`, `"WIN"`
|
/// Os of the machine known values are `"MAC"`, `"WIN"`
|
||||||
#[yaserde(rename = "p")]
|
#[serde(rename = "p")]
|
||||||
pub os: String,
|
pub os: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -217,7 +214,7 @@ pub struct C2mQ {
|
|||||||
///
|
///
|
||||||
/// This is from middle man reolink server to client
|
/// This is from middle man reolink server to client
|
||||||
///
|
///
|
||||||
#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize, Clone)]
|
#[derive(PartialEq, Eq, Default, Debug, Deserialize, Serialize, Clone)]
|
||||||
pub struct M2cQr {
|
pub struct M2cQr {
|
||||||
/// The register server location
|
/// The register server location
|
||||||
pub reg: IpPort,
|
pub reg: IpPort,
|
||||||
@@ -232,7 +229,7 @@ pub struct M2cQr {
|
|||||||
/// Used as part of M2C_Q_R to provide the host and port
|
/// Used as part of M2C_Q_R to provide the host and port
|
||||||
///
|
///
|
||||||
/// of the register, relay and log servers
|
/// of the register, relay and log servers
|
||||||
#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize, Clone)]
|
#[derive(PartialEq, Eq, Default, Debug, Deserialize, Serialize, Clone)]
|
||||||
pub struct IpPort {
|
pub struct IpPort {
|
||||||
/// Ip of the service
|
/// Ip of the service
|
||||||
pub ip: String,
|
pub ip: String,
|
||||||
@@ -255,7 +252,7 @@ impl std::convert::TryFrom<IpPort> for std::net::SocketAddr {
|
|||||||
///
|
///
|
||||||
/// This is from client to the register reolink server
|
/// This is from client to the register reolink server
|
||||||
///
|
///
|
||||||
#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize, Clone)]
|
#[derive(PartialEq, Eq, Default, Debug, Deserialize, Serialize, Clone)]
|
||||||
pub struct C2rC {
|
pub struct C2rC {
|
||||||
/// The UID to register connecition request with
|
/// The UID to register connecition request with
|
||||||
pub uid: String,
|
pub uid: String,
|
||||||
@@ -270,10 +267,10 @@ pub struct C2rC {
|
|||||||
/// Inet family. Observed values `4`
|
/// Inet family. Observed values `4`
|
||||||
pub family: u8,
|
pub family: u8,
|
||||||
/// Os of the machine known values are `"MAC"`, `"WIN"`
|
/// Os of the machine known values are `"MAC"`, `"WIN"`
|
||||||
#[yaserde(rename = "p")]
|
#[serde(rename = "p")]
|
||||||
pub os: String,
|
pub os: String,
|
||||||
/// The revision. Known values None and 3
|
/// The revision. Known values None and 3
|
||||||
#[yaserde(rename = "r")]
|
#[serde(rename = "r")]
|
||||||
pub revision: Option<i32>,
|
pub revision: Option<i32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -281,7 +278,7 @@ pub struct C2rC {
|
|||||||
///
|
///
|
||||||
/// This is from register reolink server to clinet with device ip and did etc
|
/// This is from register reolink server to clinet with device ip and did etc
|
||||||
///
|
///
|
||||||
#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize, Clone)]
|
#[derive(PartialEq, Eq, Default, Debug, Deserialize, Serialize, Clone)]
|
||||||
pub struct R2cT {
|
pub struct R2cT {
|
||||||
/// The location of the camera
|
/// The location of the camera
|
||||||
pub dmap: Option<IpPort>,
|
pub dmap: Option<IpPort>,
|
||||||
@@ -298,7 +295,7 @@ pub struct R2cT {
|
|||||||
/// This is from register reolink server to clinet with device ip and did etc
|
/// This is from register reolink server to clinet with device ip and did etc
|
||||||
/// during a relay
|
/// during a relay
|
||||||
///
|
///
|
||||||
#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize, Clone)]
|
#[derive(PartialEq, Eq, Default, Debug, Deserialize, Serialize, Clone)]
|
||||||
pub struct R2cCr {
|
pub struct R2cCr {
|
||||||
/// Dev camera location (actual local ip)
|
/// Dev camera location (actual local ip)
|
||||||
pub dev: Option<IpPort>,
|
pub dev: Option<IpPort>,
|
||||||
@@ -319,7 +316,7 @@ pub struct R2cCr {
|
|||||||
/// D2C_CFM xml
|
/// D2C_CFM xml
|
||||||
///
|
///
|
||||||
/// Device to client, with connection started from middle man server
|
/// Device to client, with connection started from middle man server
|
||||||
#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize, Clone)]
|
#[derive(PartialEq, Eq, Default, Debug, Deserialize, Serialize, Clone)]
|
||||||
pub struct D2cCfm {
|
pub struct D2cCfm {
|
||||||
/// The camera SID
|
/// The camera SID
|
||||||
pub sid: u32,
|
pub sid: u32,
|
||||||
@@ -338,7 +335,7 @@ pub struct D2cCfm {
|
|||||||
/// C2R_CFM xml
|
/// C2R_CFM xml
|
||||||
///
|
///
|
||||||
/// Client to register
|
/// Client to register
|
||||||
#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize, Clone)]
|
#[derive(PartialEq, Eq, Default, Debug, Deserialize, Serialize, Clone)]
|
||||||
pub struct C2rCfm {
|
pub struct C2rCfm {
|
||||||
/// The camera SID
|
/// The camera SID
|
||||||
pub sid: u32,
|
pub sid: u32,
|
||||||
@@ -356,7 +353,7 @@ pub struct C2rCfm {
|
|||||||
///
|
///
|
||||||
/// Client to device accept.
|
/// Client to device accept.
|
||||||
/// Sent it reply to a D2C_T
|
/// Sent it reply to a D2C_T
|
||||||
#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize, Clone)]
|
#[derive(PartialEq, Eq, Default, Debug, Deserialize, Serialize, Clone)]
|
||||||
pub struct C2dA {
|
pub struct C2dA {
|
||||||
/// The camera SID
|
/// The camera SID
|
||||||
pub sid: u32,
|
pub sid: u32,
|
||||||
@@ -374,7 +371,7 @@ pub struct C2dA {
|
|||||||
///
|
///
|
||||||
/// Client to device heart beat.
|
/// Client to device heart beat.
|
||||||
/// Seems to act as a keep alive
|
/// Seems to act as a keep alive
|
||||||
#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize, Clone)]
|
#[derive(PartialEq, Eq, Default, Debug, Deserialize, Serialize, Clone)]
|
||||||
pub struct C2dHb {
|
pub struct C2dHb {
|
||||||
/// The client connection ID
|
/// The client connection ID
|
||||||
pub cid: i32,
|
pub cid: i32,
|
||||||
@@ -386,7 +383,7 @@ pub struct C2dHb {
|
|||||||
///
|
///
|
||||||
/// Client to device heart beat.
|
/// Client to device heart beat.
|
||||||
/// Seems to act as a keep alive
|
/// Seems to act as a keep alive
|
||||||
#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize, Clone)]
|
#[derive(PartialEq, Eq, Default, Debug, Deserialize, Serialize, Clone)]
|
||||||
pub struct C2rHb {
|
pub struct C2rHb {
|
||||||
/// The connection ID
|
/// The connection ID
|
||||||
pub sid: u32,
|
pub sid: u32,
|
||||||
|
|||||||
+5
-4
@@ -35,10 +35,11 @@ pub(crate) async fn main(opt: Opt, reactor: NeoReactor) -> Result<()> {
|
|||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let ser = String::from_utf8(
|
let ser = String::from_utf8({
|
||||||
yaserde::ser::serialize_with_writer(&state, vec![], &Default::default())
|
let mut buf = bytes::BytesMut::new();
|
||||||
.expect("Should Ser the struct"),
|
quick_xml::se::to_writer(&mut buf, &state).expect("Should Ser the struct");
|
||||||
)
|
buf.to_vec()
|
||||||
|
})
|
||||||
.expect("Should be UTF8");
|
.expect("Should be UTF8");
|
||||||
println!("{}", ser);
|
println!("{}", ser);
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ use crate::{AnyResult, Result};
|
|||||||
use neolink_core::bc_protocol::MotionStatus;
|
use neolink_core::bc_protocol::MotionStatus;
|
||||||
|
|
||||||
pub(crate) enum MdState {
|
pub(crate) enum MdState {
|
||||||
|
#[allow(dead_code)]
|
||||||
Start(Instant),
|
Start(Instant),
|
||||||
Stop(Instant),
|
Stop(Instant),
|
||||||
Unknown,
|
Unknown,
|
||||||
|
|||||||
@@ -67,6 +67,11 @@ impl PushNotiThread {
|
|||||||
let sender_id = "743639030586"; // andriod
|
let sender_id = "743639030586"; // andriod
|
||||||
// let sender_id = "696841269229"; // ios
|
// let sender_id = "696841269229"; // ios
|
||||||
|
|
||||||
|
// let firebase_app_id = "1:743639030586:android:86f60a4fb7143876";
|
||||||
|
// let firebase_project_id = "reolink-login";
|
||||||
|
// let firebase_api_key = "AIzaSyBEUIuWHnnOEwFahxWgQB4Yt4NsgOmkPyE";
|
||||||
|
// let vapid_key = "????";
|
||||||
|
|
||||||
let token_path = dirs::config_dir().map(|mut d| {
|
let token_path = dirs::config_dir().map(|mut d| {
|
||||||
d.push("./neolink_token.toml");
|
d.push("./neolink_token.toml");
|
||||||
d
|
d
|
||||||
|
|||||||
+12
-12
@@ -1,19 +1,19 @@
|
|||||||
use crate::mqtt::Discoveries;
|
use crate::mqtt::Discoveries;
|
||||||
use lazy_static::lazy_static;
|
|
||||||
use neolink_core::bc_protocol::{DiscoveryMethods, PrintFormat, StreamKind};
|
use neolink_core::bc_protocol::{DiscoveryMethods, PrintFormat, StreamKind};
|
||||||
|
use once_cell::sync::Lazy;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::clone::Clone;
|
use std::clone::Clone;
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use validator::{Validate, ValidationError};
|
use validator::ValidationError;
|
||||||
use validator_derive::Validate;
|
use validator_derive::Validate;
|
||||||
|
|
||||||
lazy_static! {
|
static RE_TLS_CLIENT_AUTH: Lazy<Regex> =
|
||||||
static ref RE_TLS_CLIENT_AUTH: Regex = Regex::new(r"^(none|request|require)$").unwrap();
|
Lazy::new(|| Regex::new(r"^(none|request|require)$").unwrap());
|
||||||
static ref RE_PAUSE_MODE: Regex = Regex::new(r"^(black|still|test|none)$").unwrap();
|
static RE_PAUSE_MODE: Lazy<Regex> = Lazy::new(|| Regex::new(r"^(black|still|test|none)$").unwrap());
|
||||||
static ref RE_MAXENC_SRC: Regex =
|
static RE_MAXENC_SRC: Lazy<Regex> = Lazy::new(|| {
|
||||||
Regex::new(r"^([nN]one|[Aa][Ee][Ss]|[Bb][Cc][Ee][Nn][Cc][Rr][Yy][Pp][Tt])$").unwrap();
|
Regex::new(r"^([nN]one|[Aa][Ee][Ss]|[Bb][Cc][Ee][Nn][Cc][Rr][Yy][Pp][Tt])$").unwrap()
|
||||||
}
|
});
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize, Validate, Clone, PartialEq)]
|
#[derive(Debug, Deserialize, Serialize, Validate, Clone, PartialEq)]
|
||||||
pub(crate) struct Config {
|
pub(crate) struct Config {
|
||||||
@@ -37,7 +37,7 @@ pub(crate) struct Config {
|
|||||||
pub(crate) mqtt: Option<MqttServerConfig>,
|
pub(crate) mqtt: Option<MqttServerConfig>,
|
||||||
|
|
||||||
#[validate(regex(
|
#[validate(regex(
|
||||||
path = "RE_TLS_CLIENT_AUTH",
|
path = *RE_TLS_CLIENT_AUTH,
|
||||||
message = "Incorrect tls auth",
|
message = "Incorrect tls auth",
|
||||||
code = "tls_client_auth"
|
code = "tls_client_auth"
|
||||||
))]
|
))]
|
||||||
@@ -159,7 +159,7 @@ pub(crate) struct CameraConfig {
|
|||||||
|
|
||||||
#[serde(default = "default_maxenc")]
|
#[serde(default = "default_maxenc")]
|
||||||
#[validate(regex(
|
#[validate(regex(
|
||||||
path = "RE_MAXENC_SRC",
|
path = *RE_MAXENC_SRC,
|
||||||
message = "Invalid maximum encryption method",
|
message = "Invalid maximum encryption method",
|
||||||
code = "max_encryption"
|
code = "max_encryption"
|
||||||
))]
|
))]
|
||||||
@@ -212,7 +212,7 @@ pub(crate) struct CameraConfig {
|
|||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize, Validate, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Deserialize, Serialize, Validate, Clone, PartialEq, Eq, Hash)]
|
||||||
pub(crate) struct UserConfig {
|
pub(crate) struct UserConfig {
|
||||||
#[validate(custom = "validate_username")]
|
#[validate(custom(function = "validate_username"))]
|
||||||
#[serde(alias = "username")]
|
#[serde(alias = "username")]
|
||||||
pub(crate) name: String,
|
pub(crate) name: String,
|
||||||
|
|
||||||
@@ -329,7 +329,7 @@ pub(crate) struct PauseConfig {
|
|||||||
|
|
||||||
#[serde(default = "default_pause_mode")]
|
#[serde(default = "default_pause_mode")]
|
||||||
#[validate(regex(
|
#[validate(regex(
|
||||||
path = "RE_PAUSE_MODE",
|
path = *RE_PAUSE_MODE,
|
||||||
message = "Incorrect pause mode",
|
message = "Incorrect pause mode",
|
||||||
code = "mode"
|
code = "mode"
|
||||||
))]
|
))]
|
||||||
|
|||||||
+11
-11
@@ -1,16 +1,16 @@
|
|||||||
use err_derive::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
#[allow(clippy::large_enum_variant)]
|
#[allow(clippy::large_enum_variant)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
#[error(display = "RTSP Error")]
|
#[error("RTSP Error")]
|
||||||
Rtsp(#[error(source)] super::rtsp::Error),
|
Rtsp(#[from] super::rtsp::Error),
|
||||||
#[error(display = "Status LED Error")]
|
#[error("Status LED Error")]
|
||||||
StatusLight(#[error(source)] super::statusled::Error),
|
StatusLight(#[from] super::statusled::Error),
|
||||||
#[error(display = "Reboot Error")]
|
#[error("Reboot Error")]
|
||||||
Reboot(#[error(source)] super::reboot::Error),
|
Reboot(#[from] super::reboot::Error),
|
||||||
#[error(display = "Talk Error")]
|
#[error("Talk Error")]
|
||||||
Talk(#[error(source)] super::talk::Error),
|
Talk(#[from] super::talk::Error),
|
||||||
#[error(display = "Talk Error")]
|
#[error("Talk Error")]
|
||||||
Mqtt(#[error(source)] super::mqtt::Error),
|
Mqtt(#[from] super::mqtt::Error),
|
||||||
}
|
}
|
||||||
+4
-2
@@ -1,7 +1,9 @@
|
|||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use anyhow::{anyhow, Context, Result};
|
use anyhow::{anyhow, Context, Result};
|
||||||
use gstreamer::{parse_launch, prelude::*, ClockTime, MessageView, Pipeline, State};
|
use gstreamer::{
|
||||||
|
parse::launch_full, prelude::*, ClockTime, MessageView, ParseFlags, Pipeline, State,
|
||||||
|
};
|
||||||
use gstreamer_app::AppSrc;
|
use gstreamer_app::AppSrc;
|
||||||
use tokio::{
|
use tokio::{
|
||||||
sync::{
|
sync::{
|
||||||
@@ -203,7 +205,7 @@ fn create_pipeline(format: VidFormat, file_path: &Path) -> Result<Pipeline> {
|
|||||||
// Parse the pipeline we want to probe from a static in-line string.
|
// Parse the pipeline we want to probe from a static in-line string.
|
||||||
// Here we give our audiotestsrc a name, so we can retrieve that element
|
// Here we give our audiotestsrc a name, so we can retrieve that element
|
||||||
// from the resulting pipeline.
|
// from the resulting pipeline.
|
||||||
let pipeline = parse_launch(&launch_str)
|
let pipeline = launch_full(&launch_str, None, ParseFlags::empty())
|
||||||
.context("Unable to load gstreamer pipeline ensure all gstramer plugins are installed")?;
|
.context("Unable to load gstreamer pipeline ensure all gstramer plugins are installed")?;
|
||||||
let pipeline = pipeline.dynamic_cast::<Pipeline>().map_err(|_| {
|
let pipeline = pipeline.dynamic_cast::<Pipeline>().map_err(|_| {
|
||||||
anyhow!("Unable to create gstreamer pipeline ensure all gstramer plugins are installed")
|
anyhow!("Unable to create gstreamer pipeline ensure all gstramer plugins are installed")
|
||||||
|
|||||||
-16
@@ -53,21 +53,9 @@ mod utils;
|
|||||||
use cmdline::{Command, Opt};
|
use cmdline::{Command, Opt};
|
||||||
use common::NeoReactor;
|
use common::NeoReactor;
|
||||||
use config::Config;
|
use config::Config;
|
||||||
use console_subscriber as _;
|
|
||||||
|
|
||||||
pub(crate) type AnyResult<T> = Result<T, anyhow::Error>;
|
pub(crate) type AnyResult<T> = Result<T, anyhow::Error>;
|
||||||
|
|
||||||
#[cfg(tokio_unstable)]
|
|
||||||
fn tokio_console_enable() {
|
|
||||||
info!("Tokio Console Enabled");
|
|
||||||
console_subscriber::init();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(tokio_unstable))]
|
|
||||||
fn tokio_console_enable() {
|
|
||||||
debug!("Tokio Console Disabled");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<()> {
|
async fn main() -> Result<()> {
|
||||||
env_logger::Builder::from_env(Env::default().default_filter_or("info")).init();
|
env_logger::Builder::from_env(Env::default().default_filter_or("info")).init();
|
||||||
@@ -91,10 +79,6 @@ async fn main() -> Result<()> {
|
|||||||
.validate()
|
.validate()
|
||||||
.with_context(|| format!("Failed to validate the {:?} config file", conf_path))?;
|
.with_context(|| format!("Failed to validate the {:?} config file", conf_path))?;
|
||||||
|
|
||||||
if config.tokio_console {
|
|
||||||
tokio_console_enable();
|
|
||||||
}
|
|
||||||
|
|
||||||
let neo_reactor = NeoReactor::new(config.clone()).await;
|
let neo_reactor = NeoReactor::new(config.clone()).await;
|
||||||
|
|
||||||
match opt.cmd {
|
match opt.cmd {
|
||||||
|
|||||||
+15
-9
@@ -1156,9 +1156,11 @@ async fn handle_mqtt_message(
|
|||||||
"FAIL"
|
"FAIL"
|
||||||
}
|
}
|
||||||
Ok(xml) => {
|
Ok(xml) => {
|
||||||
let bytes_res =
|
let ser_xml = {
|
||||||
yaserde::ser::serialize_with_writer(&xml, vec![], &Default::default());
|
let mut buf = bytes::BytesMut::new();
|
||||||
match bytes_res {
|
quick_xml::se::to_writer(&mut buf, &xml).map(|_| buf.to_vec())
|
||||||
|
};
|
||||||
|
match ser_xml {
|
||||||
Ok(bytes) => match String::from_utf8(bytes) {
|
Ok(bytes) => match String::from_utf8(bytes) {
|
||||||
Ok(str) => {
|
Ok(str) => {
|
||||||
mqtt.send_message("status/battery", &str, false)
|
mqtt.send_message("status/battery", &str, false)
|
||||||
@@ -1200,9 +1202,11 @@ async fn handle_mqtt_message(
|
|||||||
"FAIL"
|
"FAIL"
|
||||||
}
|
}
|
||||||
Ok(xml) => {
|
Ok(xml) => {
|
||||||
let bytes_res =
|
let ser_xml = {
|
||||||
yaserde::ser::serialize_with_writer(&xml, vec![], &Default::default());
|
let mut buf = bytes::BytesMut::new();
|
||||||
match bytes_res {
|
quick_xml::se::to_writer(&mut buf, &xml).map(|_| buf.to_vec())
|
||||||
|
};
|
||||||
|
match ser_xml {
|
||||||
Ok(bytes) => match String::from_utf8(bytes) {
|
Ok(bytes) => match String::from_utf8(bytes) {
|
||||||
Ok(str) => {
|
Ok(str) => {
|
||||||
mqtt.send_message("status/pir", &str, false)
|
mqtt.send_message("status/pir", &str, false)
|
||||||
@@ -1245,9 +1249,11 @@ async fn handle_mqtt_message(
|
|||||||
"FAIL"
|
"FAIL"
|
||||||
}
|
}
|
||||||
Ok(xml) => {
|
Ok(xml) => {
|
||||||
let bytes_res =
|
let ser_xml = {
|
||||||
yaserde::ser::serialize_with_writer(&xml, vec![], &Default::default());
|
let mut buf = bytes::BytesMut::new();
|
||||||
match bytes_res {
|
quick_xml::se::to_writer(&mut buf, &xml).map(|_| buf.to_vec())
|
||||||
|
};
|
||||||
|
match ser_xml {
|
||||||
Ok(bytes) => match String::from_utf8(bytes) {
|
Ok(bytes) => match String::from_utf8(bytes) {
|
||||||
Ok(str) => {
|
Ok(str) => {
|
||||||
mqtt.send_message("status/ptz", &str, false)
|
mqtt.send_message("status/ptz", &str, false)
|
||||||
|
|||||||
+4
-4
@@ -6,8 +6,8 @@ use anyhow::{anyhow, Context, Result};
|
|||||||
use futures::future::FutureExt;
|
use futures::future::FutureExt;
|
||||||
use log::*;
|
use log::*;
|
||||||
use rumqttc::{
|
use rumqttc::{
|
||||||
AsyncClient, ConnectReturnCode, Event, Incoming, Key, LastWill, MqttOptions, QoS,
|
AsyncClient, ConnectReturnCode, Event, Incoming, LastWill, MqttOptions, QoS, TlsConfiguration,
|
||||||
TlsConfiguration, Transport,
|
Transport,
|
||||||
};
|
};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::task::JoinSet;
|
use tokio::task::JoinSet;
|
||||||
@@ -140,7 +140,7 @@ impl<'a> MqttBackend<'a> {
|
|||||||
if let (Ok(cert_buf), Ok(key_buf)) =
|
if let (Ok(cert_buf), Ok(key_buf)) =
|
||||||
(std::fs::read(cert_path), std::fs::read(key_path))
|
(std::fs::read(cert_path), std::fs::read(key_path))
|
||||||
{
|
{
|
||||||
Some((cert_buf, Key::RSA(key_buf)))
|
Some((cert_buf, key_buf))
|
||||||
} else {
|
} else {
|
||||||
error!("Failed to set client tls");
|
error!("Failed to set client tls");
|
||||||
None
|
None
|
||||||
@@ -534,7 +534,7 @@ impl LastWillMqtt {
|
|||||||
if let (Ok(cert_buf), Ok(key_buf)) =
|
if let (Ok(cert_buf), Ok(key_buf)) =
|
||||||
(std::fs::read(cert_path), std::fs::read(key_path))
|
(std::fs::read(cert_path), std::fs::read(key_path))
|
||||||
{
|
{
|
||||||
Some((cert_buf, Key::RSA(key_buf)))
|
Some((cert_buf, key_buf))
|
||||||
} else {
|
} else {
|
||||||
error!("Failed to set client tls");
|
error!("Failed to set client tls");
|
||||||
None
|
None
|
||||||
|
|||||||
+5
-2
@@ -47,8 +47,11 @@ pub(crate) async fn main(opt: Opt, reactor: NeoReactor) -> Result<()> {
|
|||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
let pir_ser = String::from_utf8(
|
let pir_ser = String::from_utf8(
|
||||||
yaserde::ser::serialize_with_writer(&pir_state, vec![], &Default::default())
|
{
|
||||||
.expect("Should Ser the struct"),
|
let mut buf = bytes::BytesMut::new();
|
||||||
|
quick_xml::se::to_writer(&mut buf, &pir_state).map(|_| buf.to_vec())
|
||||||
|
}
|
||||||
|
.expect("Should Ser the struct"),
|
||||||
)
|
)
|
||||||
.expect("Should be UTF8");
|
.expect("Should be UTF8");
|
||||||
println!("{}", pir_ser);
|
println!("{}", pir_ser);
|
||||||
|
|||||||
+20
-8
@@ -1,7 +1,6 @@
|
|||||||
use anyhow::{anyhow, Context, Result};
|
use anyhow::{anyhow, Context, Result};
|
||||||
use gstreamer::{prelude::*, Bin, Caps, Element, ElementFactory, GhostPad};
|
use gstreamer::{prelude::*, Bin, Caps, Element, ElementFactory, GhostPad};
|
||||||
use gstreamer_app::{AppSrc, AppSrcCallbacks, AppStreamType};
|
use gstreamer_app::{AppSrc, AppSrcCallbacks, AppStreamType};
|
||||||
use log::*;
|
|
||||||
use tokio::sync::mpsc::{channel as mpsc, Receiver as MpscReceiver};
|
use tokio::sync::mpsc::{channel as mpsc, Receiver as MpscReceiver};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@@ -342,7 +341,6 @@ fn build_adpcm(bin: &Element, block_size: u32, stream_config: &StreamConfig) ->
|
|||||||
Element::link_many([&source, &queue, &decoder])?;
|
Element::link_many([&source, &queue, &decoder])?;
|
||||||
Element::link_many([&encoder, &payload])?;
|
Element::link_many([&encoder, &payload])?;
|
||||||
decoder.connect_pad_added(move |_element, pad| {
|
decoder.connect_pad_added(move |_element, pad| {
|
||||||
debug!("Linking encoder to decoder: {:?}", pad.caps());
|
|
||||||
let sink_pad = encoder
|
let sink_pad = encoder
|
||||||
.static_pad("sink")
|
.static_pad("sink")
|
||||||
.expect("Encoder is missing its pad");
|
.expect("Encoder is missing its pad");
|
||||||
@@ -388,7 +386,8 @@ fn make_element(kind: &str, name: &str) -> AnyResult<Element> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_queue(name: &str, buffer_size: u32) -> AnyResult<Element> {
|
#[allow(dead_code)]
|
||||||
|
fn make_dbl_queue(name: &str, buffer_size: u32) -> AnyResult<Element> {
|
||||||
let queue = make_element("queue", &format!("queue1_{}", name))?;
|
let queue = make_element("queue", &format!("queue1_{}", name))?;
|
||||||
queue.set_property("max-size-bytes", buffer_size);
|
queue.set_property("max-size-bytes", buffer_size);
|
||||||
queue.set_property("max-size-buffers", 0u32);
|
queue.set_property("max-size-buffers", 0u32);
|
||||||
@@ -403,11 +402,11 @@ fn make_queue(name: &str, buffer_size: u32) -> AnyResult<Element> {
|
|||||||
queue2.set_property("max-size-bytes", buffer_size * 2u32 / 3u32);
|
queue2.set_property("max-size-bytes", buffer_size * 2u32 / 3u32);
|
||||||
queue.set_property("max-size-buffers", 0u32);
|
queue.set_property("max-size-buffers", 0u32);
|
||||||
queue.set_property("max-size-time", 0u64);
|
queue.set_property("max-size-time", 0u64);
|
||||||
// queue2.set_property(
|
queue2.set_property(
|
||||||
// "max-size-time",
|
"max-size-time",
|
||||||
// std::convert::TryInto::<u64>::try_into(tokio::time::Duration::from_secs(5).as_nanos())
|
std::convert::TryInto::<u64>::try_into(tokio::time::Duration::from_secs(5).as_nanos())
|
||||||
// .unwrap_or(0),
|
.unwrap_or(0),
|
||||||
// );
|
);
|
||||||
queue2.set_property("use-buffering", false);
|
queue2.set_property("use-buffering", false);
|
||||||
|
|
||||||
let bin = gstreamer::Bin::builder().name(name).build();
|
let bin = gstreamer::Bin::builder().name(name).build();
|
||||||
@@ -434,6 +433,19 @@ fn make_queue(name: &str, buffer_size: u32) -> AnyResult<Element> {
|
|||||||
Ok(bin)
|
Ok(bin)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn make_queue(name: &str, buffer_size: u32) -> AnyResult<Element> {
|
||||||
|
let queue = make_element("queue", &format!("queue1_{}", name))?;
|
||||||
|
queue.set_property("max-size-bytes", buffer_size);
|
||||||
|
queue.set_property("max-size-buffers", 0u32);
|
||||||
|
queue.set_property("max-size-time", 0u64);
|
||||||
|
queue.set_property(
|
||||||
|
"max-size-time",
|
||||||
|
std::convert::TryInto::<u64>::try_into(tokio::time::Duration::from_secs(5).as_nanos())
|
||||||
|
.unwrap_or(0),
|
||||||
|
);
|
||||||
|
Ok(queue)
|
||||||
|
}
|
||||||
|
|
||||||
fn buffer_size(bitrate: u32) -> u32 {
|
fn buffer_size(bitrate: u32) -> u32 {
|
||||||
std::cmp::max(bitrate * 15u32 / 8u32, 4u32 * 1024u32 * 1024u32)
|
std::cmp::max(bitrate * 15u32 / 8u32, 4u32 * 1024u32 * 1024u32)
|
||||||
}
|
}
|
||||||
@@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
use super::AnyResult;
|
use super::AnyResult;
|
||||||
use gstreamer::glib::object_subclass;
|
use gstreamer::glib::object_subclass;
|
||||||
use gstreamer::glib::subclass::types::ObjectSubclass;
|
|
||||||
use gstreamer::Element;
|
use gstreamer::Element;
|
||||||
use gstreamer::{
|
use gstreamer::{
|
||||||
glib::{self, Object},
|
glib::{self, Object},
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use super::AnyResult;
|
|||||||
use crate::config::*;
|
use crate::config::*;
|
||||||
|
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use gstreamer::glib::{self, object_subclass, subclass::types::ObjectSubclass, MainLoop, Object};
|
use gstreamer::glib::{self, object_subclass, MainLoop, Object};
|
||||||
use gstreamer_rtsp::RTSPAuthMethod;
|
use gstreamer_rtsp::RTSPAuthMethod;
|
||||||
use gstreamer_rtsp_server::{
|
use gstreamer_rtsp_server::{
|
||||||
gio::{TlsAuthenticationMode, TlsCertificate},
|
gio::{TlsAuthenticationMode, TlsCertificate},
|
||||||
|
|||||||
+3
-3
@@ -2,8 +2,8 @@ use crate::AnyResult;
|
|||||||
use anyhow::{anyhow, Context, Result};
|
use anyhow::{anyhow, Context, Result};
|
||||||
use crossbeam_channel::{bounded, Receiver, Sender};
|
use crossbeam_channel::{bounded, Receiver, Sender};
|
||||||
use gstreamer::{
|
use gstreamer::{
|
||||||
element_error, parse_launch, prelude::*, Caps, ClockTime, FlowError, FlowSuccess, MessageView,
|
element_error, parse::launch_full, prelude::*, Caps, ClockTime, FlowError, FlowSuccess,
|
||||||
Pipeline, ResourceError, State,
|
MessageView, ParseFlags, Pipeline, ResourceError, State,
|
||||||
};
|
};
|
||||||
use gstreamer_app::{AppSink, AppSinkCallbacks};
|
use gstreamer_app::{AppSink, AppSinkCallbacks};
|
||||||
use tokio::task::JoinSet;
|
use tokio::task::JoinSet;
|
||||||
@@ -159,7 +159,7 @@ fn create_pipeline(
|
|||||||
// Parse the pipeline we want to probe from a static in-line string.
|
// Parse the pipeline we want to probe from a static in-line string.
|
||||||
// Here we give our audiotestsrc a name, so we can retrieve that element
|
// Here we give our audiotestsrc a name, so we can retrieve that element
|
||||||
// from the resulting pipeline.
|
// from the resulting pipeline.
|
||||||
let pipeline = parse_launch(&launch_str)
|
let pipeline = launch_full(&launch_str, None, ParseFlags::empty())
|
||||||
.context("Unable to load gstreamer pipeline ensure all gstramer plugins are installed")?;
|
.context("Unable to load gstreamer pipeline ensure all gstramer plugins are installed")?;
|
||||||
let pipeline = pipeline.dynamic_cast::<Pipeline>().map_err(|_| {
|
let pipeline = pipeline.dynamic_cast::<Pipeline>().map_err(|_| {
|
||||||
anyhow!("Unable to create gstreamer pipeline ensure all gstramer plugins are installed")
|
anyhow!("Unable to create gstreamer pipeline ensure all gstramer plugins are installed")
|
||||||
|
|||||||
@@ -22,7 +22,9 @@ where
|
|||||||
|
|
||||||
pub(crate) enum AddressOrUid {
|
pub(crate) enum AddressOrUid {
|
||||||
Address(String),
|
Address(String),
|
||||||
|
#[allow(dead_code)]
|
||||||
Uid(String, DiscoveryMethods),
|
Uid(String, DiscoveryMethods),
|
||||||
|
#[allow(dead_code)]
|
||||||
AddressWithUid(String, String, DiscoveryMethods),
|
AddressWithUid(String, String, DiscoveryMethods),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user