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