gopro_controller/
services.rs

1use uuid::Uuid;
2
3///Macro for creating a Full GoPro UUID from a 16 bit UUID
4///NOTE: This macro will cause a runtime error if the UUID is not passed in as a u32
5macro_rules! gp_uuid {
6    ($x:expr) => {{
7        // Concatenate to form the full UUID
8        let full_uuid = format!("b5f9{}-aa8d-11e3-9046-0002a5d5c51b", $x);
9        Uuid::parse_str(&full_uuid).expect("Invalid UUID")
10    }};
11}
12
13#[test]
14fn test_macro() {
15    let uuid = gp_uuid!("0072");
16    assert_eq!(uuid, gp_uuid!("0072"));
17}
18
19///Behavior for converting a datatype to a GoPro global UUID
20pub trait ToUUID {
21    fn to_uuid(&self) -> Uuid;
22}
23
24///Behavior that a datatype must implement in order to be sent to a GoPro device
25pub trait Sendable {
26    fn as_bytes(&self) -> &'static [u8];
27    fn response_value_bytes(&self) -> &'static [u8];
28}
29
30///Represents the different services that a GoPro device can have
31pub enum GoProServices {
32    #[cfg(feature = "wifi")]
33    GoProWiFiAp,
34    #[cfg(feature = "wifi")]
35    GoProCamManagement,
36    ControlAndQuery,
37}
38
39impl ToUUID for GoProServices {
40    fn to_uuid(&self) -> Uuid {
41        match self {
42            #[cfg(feature = "wifi")]
43            GoProServices::GoProWiFiAp => gp_uuid!("0001"),
44            #[cfg(feature = "wifi")]
45            GoProServices::GoProCamManagement => gp_uuid!("0090"),
46            GoProServices::ControlAndQuery => gp_uuid!("FEA6"),
47        }
48    }
49}
50
51///FOR FUTURE USE
52///
53///Represents the different characteristics that the GoProWiFiAp service has
54#[cfg(feature = "wifi")]
55pub enum GoProWifiApCharacteristics {
56    SSID,
57    Password,
58    Power,
59    State,
60}
61
62#[cfg(feature = "wifi")]
63use GoProWifiApCharacteristics as GPWAC; //alias for conciseness
64
65#[cfg(feature = "wifi")]
66impl ToUUID for GoProWifiApCharacteristics {
67    fn to_uuid(&self) -> Uuid {
68        match self {
69            GPWAC::SSID => gp_uuid!("0002"),
70            GPWAC::Password => gp_uuid!("0003"),
71            GPWAC::Power => gp_uuid!("0004"),
72            GPWAC::State => gp_uuid!("0005"),
73        }
74    }
75}
76
77///FOR FUTURE USE
78///
79///Represents the different characteristics that the GoProCamManagement service has
80#[cfg(feature = "wifi")]
81pub enum GoProManagementCharacteristics {
82    NetworkManagementCommand,
83    NetworkManagementResponse,
84}
85
86#[cfg(feature = "wifi")]
87use GoProManagementCharacteristics as GPMC; //alias for conciseness
88#[cfg(feature = "wifi")]
89impl ToUUID for GoProManagementCharacteristics {
90    fn to_uuid(&self) -> Uuid {
91        match self {
92            GPMC::NetworkManagementCommand => gp_uuid!("0091"),
93            GPMC::NetworkManagementResponse => gp_uuid!("0092"),
94        }
95    }
96}
97
98///Represents the different characteristics that the GoProControlAndQuery service has
99pub enum GoProControlAndQueryCharacteristics {
100    Command,
101    CommandResponse,
102    Settings,
103    SettingsResponse,
104    Query,
105    QueryResponse,
106}
107
108use GoProControlAndQueryCharacteristics as GPCAQ; //alias for conciseness
109impl ToUUID for GoProControlAndQueryCharacteristics {
110    fn to_uuid(&self) -> Uuid {
111        match self {
112            GPCAQ::Command => gp_uuid!("0072"),
113            GPCAQ::CommandResponse => gp_uuid!("0073"),
114            GPCAQ::Settings => gp_uuid!("0074"),
115            GPCAQ::SettingsResponse => gp_uuid!("0075"),
116            GPCAQ::Query => gp_uuid!("0076"),
117            GPCAQ::QueryResponse => gp_uuid!("0077"),
118        }
119    }
120}