ascom_alpaca/api/device.rs
1use crate::{ASCOMError, ASCOMResult};
2use macro_rules_attribute::apply;
3use std::fmt::Debug;
4
5/// ASCOM Methods Common To All Devices.
6#[apply(rpc_trait)]
7pub trait Device: Debug + Send + Sync {
8 /// Actions and SupportedActions are a standardised means for drivers to extend functionality beyond the built-in capabilities of the ASCOM device interfaces.
9 ///
10 /// The key advantage of using Actions is that drivers can expose any device specific functionality required. The downside is that, in order to use these unique features, every application author would need to create bespoke code to present or exploit them.
11 ///
12 /// The Action parameter and return strings are deceptively simple, but can support transmission of arbitrarily complex data structures, for example through JSON encoding.
13 ///
14 /// This capability will be of primary value to:
15 /// * bespoke software and hardware configurations where a single entity controls both the consuming application software and the hardware / driver environment
16 /// * a group of application and device authors to quickly formulate and try out new interface capabilities without requiring an immediate change to the ASCOM device interface, which will take a lot longer than just agreeing a name, input parameters and a standard response for an Action command
17 ///
18 ///
19 /// The list of Action commands supported by a driver can be discovered through the SupportedActions property.
20 ///
21 /// This method should return an error message and NotImplementedException error number (0x400) if the driver just implements the standard ASCOM device methods and has no bespoke, unique, functionality.
22 #[http("action", method = Put)]
23 async fn action(
24 &self,
25
26 #[http("Action")] action: String,
27
28 #[http("Parameters")] parameters: String,
29 ) -> ASCOMResult<String> {
30 Err(ASCOMError::NOT_IMPLEMENTED)
31 }
32
33 /// Transmits an arbitrary string to the device and does not wait for a response.
34 ///
35 /// Optionally, protocol framing characters may be added to the string before transmission.
36 #[http("commandblind", method = Put)]
37 #[deprecated(note = "Use the more flexible Action and SupportedActions mechanic.")]
38 async fn command_blind(
39 &self,
40
41 #[http("Command")] command: String,
42
43 #[http("Raw")] raw: String,
44 ) -> ASCOMResult<()> {
45 Err(ASCOMError::NOT_IMPLEMENTED)
46 }
47
48 /// Transmits an arbitrary string to the device and waits for a boolean response.
49 ///
50 /// Optionally, protocol framing characters may be added to the string before transmission.
51 #[http("commandbool", method = Put)]
52 #[deprecated(note = "Use the more flexible Action and SupportedActions mechanic.")]
53 async fn command_bool(
54 &self,
55
56 #[http("Command")] command: String,
57
58 #[http("Raw")] raw: String,
59 ) -> ASCOMResult<bool> {
60 Err(ASCOMError::NOT_IMPLEMENTED)
61 }
62
63 /// Transmits an arbitrary string to the device and waits for a string response.
64 ///
65 /// Optionally, protocol framing characters may be added to the string before transmission.
66 #[http("commandstring", method = Put)]
67 #[deprecated(note = "Use the more flexible Action and SupportedActions mechanic.")]
68 async fn command_string(
69 &self,
70
71 #[http("Command")] command: String,
72
73 #[http("Raw")] raw: String,
74 ) -> ASCOMResult<String> {
75 Err(ASCOMError::NOT_IMPLEMENTED)
76 }
77
78 /// Retrieves the connected state of the device.
79 #[http("connected", method = Get)]
80 async fn connected(&self) -> ASCOMResult<bool>;
81
82 /// Sets the connected state of the device.
83 #[http("connected", method = Put)]
84 async fn set_connected(&self, #[http("Connected")] connected: bool) -> ASCOMResult<()>;
85
86 /// Returns true while the device is connecting or disconnecting.
87 ///
88 /// _Platform 7 onward._
89 #[http("connecting", method = Get)]
90 async fn connecting(&self) -> ASCOMResult<bool> {
91 Err(ASCOMError::NOT_IMPLEMENTED)
92 }
93
94 /// The description of the device.
95 #[http("description", method = Get)]
96 async fn description(&self) -> ASCOMResult<String>;
97
98 /// The description of the driver.
99 #[http("driverinfo", method = Get)]
100 async fn driver_info(&self) -> ASCOMResult<String>;
101
102 /// A string containing only the major and minor version of the driver.
103 ///
104 /// This must be in the form "n.n".
105 #[http("driverversion", method = Get)]
106 async fn driver_version(&self) -> ASCOMResult<String>;
107
108 /// The name of the device.
109 #[http("name", method = Get)]
110 async fn name(&self) -> ASCOMResult<String> {
111 Ok(self.static_name().to_owned())
112 }
113
114 /// Returns the list of action names supported by this driver.
115 #[http("supportedactions", method = Get)]
116 async fn supported_actions(&self) -> ASCOMResult<Vec<String>> {
117 Ok(vec![])
118 }
119}