This commit is contained in:
parent
b38cb3022b
commit
3caff2dd58
7 changed files with 31 additions and 6 deletions
2
domo_proto/Cargo.lock
generated
2
domo_proto/Cargo.lock
generated
|
@ -19,7 +19,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "domo_proto"
|
name = "domo_proto"
|
||||||
version = "1.0.1"
|
version = "1.0.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"crc32fast",
|
"crc32fast",
|
||||||
"rand",
|
"rand",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "domo_proto"
|
name = "domo_proto"
|
||||||
version = "1.0.1"
|
version = "1.0.2"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
|
@ -10,6 +10,10 @@ pub mod property_control;
|
||||||
/// This is the abstraction for sending raw data over domo.
|
/// This is the abstraction for sending raw data over domo.
|
||||||
pub mod raw_data_transmission;
|
pub mod raw_data_transmission;
|
||||||
|
|
||||||
|
pub trait PacketCommand {
|
||||||
|
fn command(&self) -> u8;
|
||||||
|
}
|
||||||
|
|
||||||
impl_into_enum_variant!(PacketData::NodeManagement, node_management::NodeManagementCommand);
|
impl_into_enum_variant!(PacketData::NodeManagement, node_management::NodeManagementCommand);
|
||||||
impl_into_enum_variant!(PacketData::PropertyControl, property_control::PropertyControlCommand);
|
impl_into_enum_variant!(PacketData::PropertyControl, property_control::PropertyControlCommand);
|
||||||
impl_into_enum_variant!(PacketData::Unknown, Vec<u8>);
|
impl_into_enum_variant!(PacketData::Unknown, Vec<u8>);
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use std::io;
|
use std::io;
|
||||||
|
use crate::commands::PacketCommand;
|
||||||
use crate::identifier::Identifier;
|
use crate::identifier::Identifier;
|
||||||
use crate::packet::raw_packet::RawPacket;
|
use crate::packet::raw_packet::RawPacket;
|
||||||
use crate::packet::{Packet, ToPacket};
|
use crate::packet::{Packet, ToPacket};
|
||||||
|
@ -21,8 +22,8 @@ pub enum NodeManagementCommand {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NodeManagementCommand {
|
impl PacketCommand for NodeManagementCommand {
|
||||||
pub fn command(&self) -> u8 {
|
fn command(&self) -> u8 {
|
||||||
match self {
|
match self {
|
||||||
NodeManagementCommand::Ping => 0x00,
|
NodeManagementCommand::Ping => 0x00,
|
||||||
NodeManagementCommand::RegisterNode { .. } => 0x01,
|
NodeManagementCommand::RegisterNode { .. } => 0x01,
|
||||||
|
|
|
@ -4,6 +4,7 @@ use crate::packet::packet_data::PacketData;
|
||||||
use crate::packet::raw_packet::RawPacket;
|
use crate::packet::raw_packet::RawPacket;
|
||||||
use crate::packet::{Packet, ToPacket};
|
use crate::packet::{Packet, ToPacket};
|
||||||
use std::io;
|
use std::io;
|
||||||
|
use crate::commands::PacketCommand;
|
||||||
|
|
||||||
pub mod vec;
|
pub mod vec;
|
||||||
|
|
||||||
|
@ -39,8 +40,8 @@ pub enum PropertyControlCommand {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PropertyControlCommand {
|
impl PacketCommand for PropertyControlCommand {
|
||||||
pub fn command(&self) -> u8 {
|
fn command(&self) -> u8 {
|
||||||
match self {
|
match self {
|
||||||
PropertyControlCommand::Register { .. } => 0x10,
|
PropertyControlCommand::Register { .. } => 0x10,
|
||||||
PropertyControlCommand::Remove { .. } => 0x11,
|
PropertyControlCommand::Remove { .. } => 0x11,
|
||||||
|
|
|
@ -4,6 +4,7 @@ use crate::{
|
||||||
identifier::Identifier,
|
identifier::Identifier,
|
||||||
packet::{packet_data::PacketData, raw_packet::RawPacket, Packet, ToPacket},
|
packet::{packet_data::PacketData, raw_packet::RawPacket, Packet, ToPacket},
|
||||||
};
|
};
|
||||||
|
use crate::commands::PacketCommand;
|
||||||
|
|
||||||
pub mod vec;
|
pub mod vec;
|
||||||
|
|
||||||
|
@ -25,6 +26,15 @@ pub enum RawDataTransmission {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl PacketCommand for RawDataTransmission {
|
||||||
|
fn command(&self) -> u8 {
|
||||||
|
match self {
|
||||||
|
RawDataTransmission::SetupTransmission { .. } => 0xF0,
|
||||||
|
RawDataTransmission::Data { .. } => 0xF1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl ToPacket for RawDataTransmission {
|
impl ToPacket for RawDataTransmission {
|
||||||
fn to_packet(
|
fn to_packet(
|
||||||
self,
|
self,
|
||||||
|
|
|
@ -46,6 +46,15 @@ impl Default for Packet {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Secretly calls RawPacket::try_from().into()
|
/// Secretly calls RawPacket::try_from().into()
|
||||||
|
|
||||||
|
impl TryFrom<RawPacket> for Packet {
|
||||||
|
type Error = io::Error;
|
||||||
|
|
||||||
|
fn try_from(value: RawPacket) -> Result<Self, Self::Error> {
|
||||||
|
value.into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl TryFrom<Vec<u8>> for Packet {
|
impl TryFrom<Vec<u8>> for Packet {
|
||||||
type Error = io::Error;
|
type Error = io::Error;
|
||||||
fn try_from(data: Vec<u8>) -> io::Result<Self> {
|
fn try_from(data: Vec<u8>) -> io::Result<Self> {
|
||||||
|
|
Loading…
Reference in a new issue