aranet_types/
uuid.rs

1//! Bluetooth UUIDs for Aranet devices.
2//!
3//! This module contains all the UUIDs needed to communicate with Aranet
4//! sensors over Bluetooth Low Energy.
5
6use uuid::{Uuid, uuid};
7
8// --- Saf Tehnika (Aranet) Service UUIDs ---
9
10/// Saf Tehnika custom service UUID for firmware v1.2.0 and newer.
11pub const SAF_TEHNIKA_SERVICE_NEW: Uuid = uuid!("0000fce0-0000-1000-8000-00805f9b34fb");
12
13/// Saf Tehnika custom service UUID for firmware versions before v1.2.0.
14pub const SAF_TEHNIKA_SERVICE_OLD: Uuid = uuid!("f0cd1400-95da-4f4b-9ac8-aa55d312af0c");
15
16/// Saf Tehnika manufacturer ID for BLE advertisements.
17pub const MANUFACTURER_ID: u16 = 0x0702;
18
19// --- Aranet Characteristic UUIDs ---
20
21/// Current readings characteristic (basic).
22pub const CURRENT_READINGS: Uuid = uuid!("f0cd1503-95da-4f4b-9ac8-aa55d312af0c");
23
24/// Current readings characteristic (detailed) - Aranet4.
25pub const CURRENT_READINGS_DETAIL: Uuid = uuid!("f0cd3001-95da-4f4b-9ac8-aa55d312af0c");
26
27/// Current readings characteristic (detailed) - Aranet2/Radon/Radiation.
28pub const CURRENT_READINGS_DETAIL_ALT: Uuid = uuid!("f0cd3003-95da-4f4b-9ac8-aa55d312af0c");
29
30/// Total number of readings stored in device memory.
31pub const TOTAL_READINGS: Uuid = uuid!("f0cd2001-95da-4f4b-9ac8-aa55d312af0c");
32
33/// Measurement interval in seconds.
34pub const READ_INTERVAL: Uuid = uuid!("f0cd2002-95da-4f4b-9ac8-aa55d312af0c");
35
36/// History data characteristic (version 1) - notification-based.
37pub const HISTORY_V1: Uuid = uuid!("f0cd2003-95da-4f4b-9ac8-aa55d312af0c");
38
39/// History data characteristic (version 2) - read-based.
40pub const HISTORY_V2: Uuid = uuid!("f0cd2005-95da-4f4b-9ac8-aa55d312af0c");
41
42/// Sensor state characteristic for reading device settings.
43pub const SENSOR_STATE: Uuid = uuid!("f0cd1401-95da-4f4b-9ac8-aa55d312af0c");
44
45/// Command characteristic for device control.
46pub const COMMAND: Uuid = uuid!("f0cd1402-95da-4f4b-9ac8-aa55d312af0c");
47
48/// Seconds since last measurement.
49pub const SECONDS_SINCE_UPDATE: Uuid = uuid!("f0cd2004-95da-4f4b-9ac8-aa55d312af0c");
50
51/// Calibration data characteristic.
52pub const CALIBRATION: Uuid = uuid!("f0cd1502-95da-4f4b-9ac8-aa55d312af0c");
53
54// --- Standard BLE Service UUIDs ---
55
56/// Generic Access Profile (GAP) service.
57pub const GAP_SERVICE: Uuid = uuid!("00001800-0000-1000-8000-00805f9b34fb");
58
59/// Device Information service.
60pub const DEVICE_INFO_SERVICE: Uuid = uuid!("0000180a-0000-1000-8000-00805f9b34fb");
61
62/// Battery service.
63pub const BATTERY_SERVICE: Uuid = uuid!("0000180f-0000-1000-8000-00805f9b34fb");
64
65// --- Device Information Characteristic UUIDs ---
66
67/// Device name characteristic.
68pub const DEVICE_NAME: Uuid = uuid!("00002a00-0000-1000-8000-00805f9b34fb");
69
70/// Model number string characteristic.
71pub const MODEL_NUMBER: Uuid = uuid!("00002a24-0000-1000-8000-00805f9b34fb");
72
73/// Serial number string characteristic.
74pub const SERIAL_NUMBER: Uuid = uuid!("00002a25-0000-1000-8000-00805f9b34fb");
75
76/// Firmware revision string characteristic.
77pub const FIRMWARE_REVISION: Uuid = uuid!("00002a26-0000-1000-8000-00805f9b34fb");
78
79/// Hardware revision string characteristic.
80pub const HARDWARE_REVISION: Uuid = uuid!("00002a27-0000-1000-8000-00805f9b34fb");
81
82/// Software revision string characteristic.
83pub const SOFTWARE_REVISION: Uuid = uuid!("00002a28-0000-1000-8000-00805f9b34fb");
84
85/// Manufacturer name string characteristic.
86pub const MANUFACTURER_NAME: Uuid = uuid!("00002a29-0000-1000-8000-00805f9b34fb");
87
88// --- Battery Characteristic UUIDs ---
89
90/// Battery level characteristic.
91pub const BATTERY_LEVEL: Uuid = uuid!("00002a19-0000-1000-8000-00805f9b34fb");
92
93#[cfg(test)]
94mod tests {
95    use super::*;
96
97    // --- Service UUID tests ---
98
99    #[test]
100    fn test_saf_tehnika_service_new_uuid() {
101        // New firmware (v1.2.0+) service UUID
102        let expected = "0000fce0-0000-1000-8000-00805f9b34fb";
103        assert_eq!(SAF_TEHNIKA_SERVICE_NEW.to_string(), expected);
104    }
105
106    #[test]
107    fn test_saf_tehnika_service_old_uuid() {
108        // Old firmware (pre-1.2.0) service UUID
109        let expected = "f0cd1400-95da-4f4b-9ac8-aa55d312af0c";
110        assert_eq!(SAF_TEHNIKA_SERVICE_OLD.to_string(), expected);
111    }
112
113    #[test]
114    fn test_manufacturer_id() {
115        // SAF Tehnika manufacturer ID
116        assert_eq!(MANUFACTURER_ID, 0x0702);
117        assert_eq!(MANUFACTURER_ID, 1794);
118    }
119
120    // --- Aranet Characteristic UUID tests ---
121
122    #[test]
123    fn test_current_readings_uuid() {
124        let expected = "f0cd1503-95da-4f4b-9ac8-aa55d312af0c";
125        assert_eq!(CURRENT_READINGS.to_string(), expected);
126    }
127
128    #[test]
129    fn test_current_readings_detail_uuid() {
130        // Aranet4 detailed readings
131        let expected = "f0cd3001-95da-4f4b-9ac8-aa55d312af0c";
132        assert_eq!(CURRENT_READINGS_DETAIL.to_string(), expected);
133    }
134
135    #[test]
136    fn test_current_readings_detail_alt_uuid() {
137        // Aranet2/Radon/Radiation detailed readings
138        let expected = "f0cd3003-95da-4f4b-9ac8-aa55d312af0c";
139        assert_eq!(CURRENT_READINGS_DETAIL_ALT.to_string(), expected);
140    }
141
142    #[test]
143    fn test_total_readings_uuid() {
144        let expected = "f0cd2001-95da-4f4b-9ac8-aa55d312af0c";
145        assert_eq!(TOTAL_READINGS.to_string(), expected);
146    }
147
148    #[test]
149    fn test_read_interval_uuid() {
150        let expected = "f0cd2002-95da-4f4b-9ac8-aa55d312af0c";
151        assert_eq!(READ_INTERVAL.to_string(), expected);
152    }
153
154    #[test]
155    fn test_history_v1_uuid() {
156        let expected = "f0cd2003-95da-4f4b-9ac8-aa55d312af0c";
157        assert_eq!(HISTORY_V1.to_string(), expected);
158    }
159
160    #[test]
161    fn test_history_v2_uuid() {
162        let expected = "f0cd2005-95da-4f4b-9ac8-aa55d312af0c";
163        assert_eq!(HISTORY_V2.to_string(), expected);
164    }
165
166    #[test]
167    fn test_sensor_state_uuid() {
168        let expected = "f0cd1401-95da-4f4b-9ac8-aa55d312af0c";
169        assert_eq!(SENSOR_STATE.to_string(), expected);
170    }
171
172    #[test]
173    fn test_command_uuid() {
174        let expected = "f0cd1402-95da-4f4b-9ac8-aa55d312af0c";
175        assert_eq!(COMMAND.to_string(), expected);
176    }
177
178    #[test]
179    fn test_seconds_since_update_uuid() {
180        let expected = "f0cd2004-95da-4f4b-9ac8-aa55d312af0c";
181        assert_eq!(SECONDS_SINCE_UPDATE.to_string(), expected);
182    }
183
184    #[test]
185    fn test_calibration_uuid() {
186        let expected = "f0cd1502-95da-4f4b-9ac8-aa55d312af0c";
187        assert_eq!(CALIBRATION.to_string(), expected);
188    }
189
190    // --- Standard BLE Service UUID tests ---
191
192    #[test]
193    fn test_gap_service_uuid() {
194        let expected = "00001800-0000-1000-8000-00805f9b34fb";
195        assert_eq!(GAP_SERVICE.to_string(), expected);
196    }
197
198    #[test]
199    fn test_device_info_service_uuid() {
200        let expected = "0000180a-0000-1000-8000-00805f9b34fb";
201        assert_eq!(DEVICE_INFO_SERVICE.to_string(), expected);
202    }
203
204    #[test]
205    fn test_battery_service_uuid() {
206        let expected = "0000180f-0000-1000-8000-00805f9b34fb";
207        assert_eq!(BATTERY_SERVICE.to_string(), expected);
208    }
209
210    // --- Device Information Characteristic UUID tests ---
211
212    #[test]
213    fn test_device_name_uuid() {
214        let expected = "00002a00-0000-1000-8000-00805f9b34fb";
215        assert_eq!(DEVICE_NAME.to_string(), expected);
216    }
217
218    #[test]
219    fn test_model_number_uuid() {
220        let expected = "00002a24-0000-1000-8000-00805f9b34fb";
221        assert_eq!(MODEL_NUMBER.to_string(), expected);
222    }
223
224    #[test]
225    fn test_serial_number_uuid() {
226        let expected = "00002a25-0000-1000-8000-00805f9b34fb";
227        assert_eq!(SERIAL_NUMBER.to_string(), expected);
228    }
229
230    #[test]
231    fn test_firmware_revision_uuid() {
232        let expected = "00002a26-0000-1000-8000-00805f9b34fb";
233        assert_eq!(FIRMWARE_REVISION.to_string(), expected);
234    }
235
236    #[test]
237    fn test_hardware_revision_uuid() {
238        let expected = "00002a27-0000-1000-8000-00805f9b34fb";
239        assert_eq!(HARDWARE_REVISION.to_string(), expected);
240    }
241
242    #[test]
243    fn test_software_revision_uuid() {
244        let expected = "00002a28-0000-1000-8000-00805f9b34fb";
245        assert_eq!(SOFTWARE_REVISION.to_string(), expected);
246    }
247
248    #[test]
249    fn test_manufacturer_name_uuid() {
250        let expected = "00002a29-0000-1000-8000-00805f9b34fb";
251        assert_eq!(MANUFACTURER_NAME.to_string(), expected);
252    }
253
254    #[test]
255    fn test_battery_level_uuid() {
256        let expected = "00002a19-0000-1000-8000-00805f9b34fb";
257        assert_eq!(BATTERY_LEVEL.to_string(), expected);
258    }
259
260    // --- UUID distinctness tests ---
261
262    #[test]
263    fn test_aranet_service_uuids_are_distinct() {
264        assert_ne!(SAF_TEHNIKA_SERVICE_NEW, SAF_TEHNIKA_SERVICE_OLD);
265    }
266
267    #[test]
268    fn test_current_readings_uuids_are_distinct() {
269        assert_ne!(CURRENT_READINGS, CURRENT_READINGS_DETAIL);
270        assert_ne!(CURRENT_READINGS_DETAIL, CURRENT_READINGS_DETAIL_ALT);
271        assert_ne!(CURRENT_READINGS, CURRENT_READINGS_DETAIL_ALT);
272    }
273
274    #[test]
275    fn test_history_uuids_are_distinct() {
276        assert_ne!(HISTORY_V1, HISTORY_V2);
277    }
278
279    #[test]
280    fn test_standard_service_uuids_are_distinct() {
281        assert_ne!(GAP_SERVICE, DEVICE_INFO_SERVICE);
282        assert_ne!(DEVICE_INFO_SERVICE, BATTERY_SERVICE);
283        assert_ne!(GAP_SERVICE, BATTERY_SERVICE);
284    }
285
286    // --- UUID format validation tests ---
287
288    #[test]
289    fn test_aranet_characteristic_prefix() {
290        // All Aranet-specific characteristics start with f0cd
291        let aranet_uuids = [
292            CURRENT_READINGS,
293            CURRENT_READINGS_DETAIL,
294            CURRENT_READINGS_DETAIL_ALT,
295            TOTAL_READINGS,
296            READ_INTERVAL,
297            HISTORY_V1,
298            HISTORY_V2,
299            SENSOR_STATE,
300            COMMAND,
301            SECONDS_SINCE_UPDATE,
302            CALIBRATION,
303        ];
304
305        for uuid in aranet_uuids {
306            assert!(
307                uuid.to_string().starts_with("f0cd"),
308                "UUID {} should start with f0cd",
309                uuid
310            );
311        }
312    }
313
314    #[test]
315    fn test_standard_ble_characteristic_prefix() {
316        // Standard BLE characteristics use 16-bit UUIDs (start with 00002aXX)
317        let standard_uuids = [
318            DEVICE_NAME,
319            MODEL_NUMBER,
320            SERIAL_NUMBER,
321            FIRMWARE_REVISION,
322            HARDWARE_REVISION,
323            SOFTWARE_REVISION,
324            MANUFACTURER_NAME,
325            BATTERY_LEVEL,
326        ];
327
328        for uuid in standard_uuids {
329            assert!(
330                uuid.to_string().starts_with("00002a"),
331                "UUID {} should start with 00002a",
332                uuid
333            );
334        }
335    }
336}