bacnet-server 0.15.0

BACnet server: APDU dispatch and service handlers
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
use super::*;

#[test]
fn wpm_handler_unknown_object_fails() {
    let mut db = make_db_with_ai();
    let oid = ObjectIdentifier::new(ObjectType::BINARY_VALUE, 99).unwrap();

    use bacnet_services::common::BACnetPropertyValue;
    use bacnet_services::wpm::WriteAccessSpecification;

    let request = bacnet_services::wpm::WritePropertyMultipleRequest {
        list_of_write_access_specs: vec![WriteAccessSpecification {
            object_identifier: oid,
            list_of_properties: vec![BACnetPropertyValue {
                property_identifier: PropertyIdentifier::PRESENT_VALUE,
                property_array_index: None,
                value: vec![0x91, 0x01],
                priority: None,
            }],
        }],
    };
    let mut buf = BytesMut::new();
    request.encode(&mut buf).unwrap();

    assert!(sourced_wpm(&mut db, &buf).is_err());
}

#[test]
fn wpm_handler_commits_successful_prefix() {
    // HIGH_LIMIT succeeds before the read-only OBJECT_TYPE failure.
    let mut db = make_db_with_ai();
    let oid = ObjectIdentifier::new(ObjectType::ANALOG_INPUT, 1).unwrap();

    let mut hl_buf = BytesMut::new();
    bacnet_encoding::primitives::encode_app_real(&mut hl_buf, 999.0);
    let mut ot_buf = BytesMut::new();
    bacnet_encoding::primitives::encode_app_enumerated(&mut ot_buf, 0);

    use bacnet_services::common::BACnetPropertyValue;
    use bacnet_services::wpm::WriteAccessSpecification;

    let request = bacnet_services::wpm::WritePropertyMultipleRequest {
        list_of_write_access_specs: vec![WriteAccessSpecification {
            object_identifier: oid,
            list_of_properties: vec![
                BACnetPropertyValue {
                    property_identifier: PropertyIdentifier::HIGH_LIMIT,
                    property_array_index: None,
                    value: hl_buf.to_vec(),
                    priority: None,
                },
                BACnetPropertyValue {
                    property_identifier: PropertyIdentifier::OBJECT_TYPE,
                    property_array_index: None,
                    value: ot_buf.to_vec(),
                    priority: None,
                },
            ],
        }],
    };
    let mut buf = BytesMut::new();
    request.encode(&mut buf).unwrap();

    // Should fail because OBJECT_TYPE is read-only
    assert!(sourced_wpm(&mut db, &buf).is_err());

    let after_hl = match db
        .get(&oid)
        .unwrap()
        .read_property(PropertyIdentifier::HIGH_LIMIT, None)
        .unwrap()
    {
        PropertyValue::Real(v) => v,
        _ => panic!("expected Real"),
    };
    assert_eq!(after_hl, 999.0, "the successful prefix stays committed");
}

#[test]
fn wpm_prefix_commit_keeps_out_of_service_transition() {
    use bacnet_services::common::BACnetPropertyValue;
    use bacnet_services::wpm::WriteAccessSpecification;
    use bacnet_types::enums::Reliability;

    let mut db = make_db_with_ai();
    let oid = ObjectIdentifier::new(ObjectType::ANALOG_INPUT, 1).unwrap();
    let obj = db.get_mut(&oid).unwrap();
    obj.set_reliability_internal(Reliability::OVER_RANGE)
        .unwrap();
    obj.write_property(
        PropertyIdentifier::OUT_OF_SERVICE,
        None,
        PropertyValue::Boolean(true),
        None,
    )
    .unwrap();
    obj.write_property(
        PropertyIdentifier::RELIABILITY,
        None,
        PropertyValue::Enumerated(Reliability::NO_SENSOR.to_raw()),
        None,
    )
    .unwrap();

    let mut oos_buf = BytesMut::new();
    bacnet_encoding::primitives::encode_app_boolean(&mut oos_buf, false);
    let mut object_type_buf = BytesMut::new();
    bacnet_encoding::primitives::encode_app_enumerated(&mut object_type_buf, 0);
    let request = bacnet_services::wpm::WritePropertyMultipleRequest {
        list_of_write_access_specs: vec![WriteAccessSpecification {
            object_identifier: oid,
            list_of_properties: vec![
                BACnetPropertyValue {
                    property_identifier: PropertyIdentifier::OUT_OF_SERVICE,
                    property_array_index: None,
                    value: oos_buf.to_vec(),
                    priority: None,
                },
                BACnetPropertyValue {
                    property_identifier: PropertyIdentifier::OBJECT_TYPE,
                    property_array_index: None,
                    value: object_type_buf.to_vec(),
                    priority: None,
                },
            ],
        }],
    };
    let mut buf = BytesMut::new();
    request.encode(&mut buf).unwrap();

    assert!(sourced_wpm(&mut db, &buf).is_err());
    let obj = db.get_mut(&oid).unwrap();
    assert_eq!(
        obj.read_property(PropertyIdentifier::OUT_OF_SERVICE, None)
            .unwrap(),
        PropertyValue::Boolean(false)
    );
    assert_eq!(
        obj.read_property(PropertyIdentifier::RELIABILITY, None)
            .unwrap(),
        PropertyValue::Enumerated(Reliability::OVER_RANGE.to_raw()),
        "the successful OOS exit restores evaluated Reliability"
    );

    obj.write_property(
        PropertyIdentifier::OUT_OF_SERVICE,
        None,
        PropertyValue::Boolean(false),
        None,
    )
    .unwrap();
    assert_eq!(
        obj.read_property(PropertyIdentifier::RELIABILITY, None)
            .unwrap(),
        PropertyValue::Enumerated(Reliability::OVER_RANGE.to_raw()),
        "a repeated in-service write keeps evaluated Reliability"
    );
}
#[test]
fn create_object_by_type_assigns_next_instance() {
    let mut db = make_db_with_device_and_ai();
    let req = CreateObjectRequest {
        object_specifier: ObjectSpecifier::Type(ObjectType::ANALOG_INPUT),
        list_of_initial_values: vec![],
    };
    let mut buf = BytesMut::new();
    req.encode(&mut buf);

    let mut ack_buf = BytesMut::new();
    let result = handle_create_object(&mut db, &buf, &mut ack_buf);
    assert!(result.is_ok());
    // Should now have 3 objects (Device + AI-1 + new AI)
    assert_eq!(db.len(), 3);
    // The new AI should have instance 2 (since 1 is taken)
    let ai2_oid = ObjectIdentifier::new(ObjectType::ANALOG_INPUT, 2).unwrap();
    assert!(db.get(&ai2_oid).is_some());
}

#[test]
fn create_object_by_identifier() {
    let mut db = make_db_with_device_and_ai();
    let target_oid = ObjectIdentifier::new(ObjectType::BINARY_INPUT, 99).unwrap();
    let req = CreateObjectRequest {
        object_specifier: ObjectSpecifier::Identifier(target_oid),
        list_of_initial_values: vec![],
    };
    let mut buf = BytesMut::new();
    req.encode(&mut buf);

    let mut ack_buf = BytesMut::new();
    let result = handle_create_object(&mut db, &buf, &mut ack_buf);
    assert!(result.is_ok());
    assert!(db.get(&target_oid).is_some());
}

#[test]
fn create_object_duplicate_fails() {
    let mut db = make_db_with_device_and_ai();
    let existing_oid = ObjectIdentifier::new(ObjectType::ANALOG_INPUT, 1).unwrap();
    let req = CreateObjectRequest {
        object_specifier: ObjectSpecifier::Identifier(existing_oid),
        list_of_initial_values: vec![],
    };
    let mut buf = BytesMut::new();
    req.encode(&mut buf);

    let mut ack_buf = BytesMut::new();
    let result = handle_create_object(&mut db, &buf, &mut ack_buf);
    assert!(result.is_err());
}

#[test]
fn create_unsupported_type_fails() {
    let mut db = make_db_with_device_and_ai();
    let req = CreateObjectRequest {
        object_specifier: ObjectSpecifier::Type(ObjectType::DEVICE),
        list_of_initial_values: vec![],
    };
    let mut buf = BytesMut::new();
    req.encode(&mut buf);

    let mut ack_buf = BytesMut::new();
    let result = handle_create_object(&mut db, &buf, &mut ack_buf);
    assert!(result.is_err());
}

#[test]
fn create_object_with_initial_values() {
    let mut db = make_db_with_device_and_ai();
    let mut desc_buf = BytesMut::new();
    bacnet_encoding::primitives::encode_app_character_string(&mut desc_buf, "Test AI").unwrap();

    let req = CreateObjectRequest {
        object_specifier: ObjectSpecifier::Type(ObjectType::ANALOG_INPUT),
        list_of_initial_values: vec![bacnet_services::common::BACnetPropertyValue {
            property_identifier: PropertyIdentifier::DESCRIPTION,
            property_array_index: None,
            value: desc_buf.to_vec(),
            priority: None,
        }],
    };
    let mut buf = BytesMut::new();
    req.encode(&mut buf);

    let mut ack_buf = BytesMut::new();
    handle_create_object(&mut db, &buf, &mut ack_buf).unwrap();
    let (pv, _) = bacnet_encoding::primitives::decode_application_value(&ack_buf, 0).unwrap();
    let created_oid = match pv {
        PropertyValue::ObjectIdentifier(oid) => oid,
        other => panic!("expected ObjectIdentifier, got {other:?}"),
    };

    let obj = db.get(&created_oid).unwrap();
    let desc = obj
        .read_property(PropertyIdentifier::DESCRIPTION, None)
        .unwrap();
    match desc {
        PropertyValue::CharacterString(s) => assert_eq!(s, "Test AI"),
        other => panic!("expected CharacterString, got {other:?}"),
    }
}

#[test]
fn create_object_bad_initial_value_rolls_back() {
    let mut db = make_db_with_device_and_ai();
    let before_count = db.len();

    // Try to write OBJECT_TYPE (read-only) as an initial value
    let mut ot_buf = BytesMut::new();
    bacnet_encoding::primitives::encode_app_enumerated(&mut ot_buf, 99);

    let req = CreateObjectRequest {
        object_specifier: ObjectSpecifier::Type(ObjectType::BINARY_INPUT),
        list_of_initial_values: vec![bacnet_services::common::BACnetPropertyValue {
            property_identifier: PropertyIdentifier::OBJECT_TYPE,
            property_array_index: None,
            value: ot_buf.to_vec(),
            priority: None,
        }],
    };
    let mut buf = BytesMut::new();
    req.encode(&mut buf);

    // The refusal names the initial value, the first (#1047).
    assert_eq!(
        list_refusal(handle_create_object(&mut db, &buf, &mut BytesMut::new())),
        (ErrorClass::PROPERTY, ErrorCode::WRITE_ACCESS_DENIED, 1)
    );
    assert_eq!(
        db.len(),
        before_count,
        "object should be removed on failure"
    );
}

/// Build a database with one commandable AnalogOutput whose priority-8 slot
/// holds an active command, so a `PRESENT_VALUE` write at priority 8 has a real
/// slot to overwrite. Returns the db and the AO's object identifier.
fn make_db_with_commandable_ao() -> (ObjectDatabase, ObjectIdentifier) {
    use bacnet_objects::analog::AnalogOutputObject;
    use bacnet_types::enums::EngineeringUnits;
    let mut db = ObjectDatabase::new();
    let mut ao = AnalogOutputObject::new(1, "AO-1", EngineeringUnits::DEGREES_CELSIUS).unwrap();
    // Establish an active command at priority 8.
    ao.write_property_from(
        PropertyIdentifier::PRESENT_VALUE,
        None,
        PropertyValue::Real(50.0),
        Some(8),
        &crate::command_source::test_origin(),
    )
    .unwrap();
    let oid = ObjectIdentifier::new(ObjectType::ANALOG_OUTPUT, 1).unwrap();
    db.add(Box::new(ao)).unwrap();
    (db, oid)
}

/// Read a single `PRIORITY_ARRAY` slot as `Option<f32>` (`None` if relinquished).
/// Multi-state objects store `Unsigned` slots, so coerce those to `f32` for
/// uniform comparison across commandable object kinds.
fn priority_slot(db: &ObjectDatabase, oid: &ObjectIdentifier, slot: u32) -> Option<f32> {
    match db
        .get(oid)
        .unwrap()
        .read_property(PropertyIdentifier::PRIORITY_ARRAY, Some(slot))
        .unwrap()
    {
        PropertyValue::Real(v) => Some(v),
        PropertyValue::Unsigned(v) => Some(v as f32),
        PropertyValue::Null => None,
        other => panic!("expected Real, Unsigned, or Null for priority slot {slot}, got {other:?}"),
    }
}

#[test]
fn wpm_prefix_commit_keeps_commandable_priority_slot() {
    let (mut db, oid) = make_db_with_commandable_ao();

    assert_eq!(priority_slot(&db, &oid, 8), Some(50.0));
    assert_eq!(priority_slot(&db, &oid, 16), None);

    // First spec: overwrite the priority-8 command. Second spec: OBJECT_TYPE is
    // read-only and fails after the first write commits.
    let mut pv_buf = BytesMut::new();
    bacnet_encoding::primitives::encode_app_real(&mut pv_buf, 99.0);
    let mut ot_buf = BytesMut::new();
    bacnet_encoding::primitives::encode_app_enumerated(&mut ot_buf, 0);

    use bacnet_services::common::BACnetPropertyValue;
    use bacnet_services::wpm::WriteAccessSpecification;
    let request = bacnet_services::wpm::WritePropertyMultipleRequest {
        list_of_write_access_specs: vec![WriteAccessSpecification {
            object_identifier: oid,
            list_of_properties: vec![
                BACnetPropertyValue {
                    property_identifier: PropertyIdentifier::PRESENT_VALUE,
                    property_array_index: None,
                    value: pv_buf.to_vec(),
                    priority: Some(8),
                },
                BACnetPropertyValue {
                    property_identifier: PropertyIdentifier::OBJECT_TYPE,
                    property_array_index: None,
                    value: ot_buf.to_vec(),
                    priority: None,
                },
            ],
        }],
    };
    let mut buf = BytesMut::new();
    request.encode(&mut buf).unwrap();

    assert!(sourced_wpm(&mut db, &buf).is_err());

    assert_eq!(priority_slot(&db, &oid, 8), Some(99.0));
    assert_eq!(
        priority_slot(&db, &oid, 16),
        None,
        "the failed attempt does not create another command"
    );
    // Effective present value and command priority are unchanged.
    assert_eq!(
        db.get(&oid)
            .unwrap()
            .read_property(PropertyIdentifier::PRESENT_VALUE, None)
            .unwrap(),
        PropertyValue::Real(99.0)
    );
    assert_eq!(
        db.get(&oid)
            .unwrap()
            .read_property(PropertyIdentifier::CURRENT_COMMAND_PRIORITY, None)
            .unwrap(),
        PropertyValue::Unsigned(8)
    );
}

#[test]
fn wpm_prefix_commit_keeps_relinquished_priority_slot() {
    let (mut db, oid) = make_db_with_commandable_ao();
    assert_eq!(priority_slot(&db, &oid, 8), Some(50.0));

    // First spec: relinquish priority 8 (write Null). Second spec: OBJECT_TYPE
    // fails after the relinquish commits.
    let mut null_buf = BytesMut::new();
    bacnet_encoding::primitives::encode_app_null(&mut null_buf);
    let mut ot_buf = BytesMut::new();
    bacnet_encoding::primitives::encode_app_enumerated(&mut ot_buf, 0);

    use bacnet_services::common::BACnetPropertyValue;
    use bacnet_services::wpm::WriteAccessSpecification;
    let request = bacnet_services::wpm::WritePropertyMultipleRequest {
        list_of_write_access_specs: vec![WriteAccessSpecification {
            object_identifier: oid,
            list_of_properties: vec![
                BACnetPropertyValue {
                    property_identifier: PropertyIdentifier::PRESENT_VALUE,
                    property_array_index: None,
                    value: null_buf.to_vec(),
                    priority: Some(8),
                },
                BACnetPropertyValue {
                    property_identifier: PropertyIdentifier::OBJECT_TYPE,
                    property_array_index: None,
                    value: ot_buf.to_vec(),
                    priority: None,
                },
            ],
        }],
    };
    let mut buf = BytesMut::new();
    request.encode(&mut buf).unwrap();

    assert!(sourced_wpm(&mut db, &buf).is_err());

    assert_eq!(
        priority_slot(&db, &oid, 8),
        None,
        "the successful relinquish stays committed"
    );
    assert_eq!(
        db.get(&oid)
            .unwrap()
            .read_property(PropertyIdentifier::PRESENT_VALUE, None)
            .unwrap(),
        PropertyValue::Real(0.0)
    );
}

#[test]
fn wpm_prefix_commit_keeps_noncommandable_present_value_analoginput() {
    use bacnet_objects::analog::AnalogInputObject;
    use bacnet_types::enums::EngineeringUnits;
    let mut db = ObjectDatabase::new();
    let mut ai = AnalogInputObject::new(1, "AI-1", EngineeringUnits::DEGREES_CELSIUS).unwrap();
    ai.write_property(
        PropertyIdentifier::OUT_OF_SERVICE,
        None,
        PropertyValue::Boolean(true),
        None,
    )
    .unwrap();
    ai.write_property_from(
        PropertyIdentifier::PRESENT_VALUE,
        None,
        PropertyValue::Real(10.0),
        None,
        &crate::command_source::test_origin(),
    )
    .unwrap();
    let oid = ObjectIdentifier::new(ObjectType::ANALOG_INPUT, 1).unwrap();
    db.add(Box::new(ai)).unwrap();
    let pre_pv = db
        .get(&oid)
        .unwrap()
        .read_property(PropertyIdentifier::PRESENT_VALUE, None)
        .unwrap();
    assert_eq!(pre_pv, PropertyValue::Real(10.0));

    // First spec: write PRESENT_VALUE (succeeds, AI is OOS). Second spec:
    // OBJECT_TYPE is read-only and fails after the first write commits.
    let mut pv_buf = BytesMut::new();
    bacnet_encoding::primitives::encode_app_real(&mut pv_buf, 77.0);
    let mut ot_buf = BytesMut::new();
    bacnet_encoding::primitives::encode_app_enumerated(&mut ot_buf, 0);

    use bacnet_services::common::BACnetPropertyValue;
    use bacnet_services::wpm::WriteAccessSpecification;
    let request = bacnet_services::wpm::WritePropertyMultipleRequest {
        list_of_write_access_specs: vec![WriteAccessSpecification {
            object_identifier: oid,
            list_of_properties: vec![
                BACnetPropertyValue {
                    property_identifier: PropertyIdentifier::PRESENT_VALUE,
                    property_array_index: None,
                    value: pv_buf.to_vec(),
                    priority: None,
                },
                BACnetPropertyValue {
                    property_identifier: PropertyIdentifier::OBJECT_TYPE,
                    property_array_index: None,
                    value: ot_buf.to_vec(),
                    priority: None,
                },
            ],
        }],
    };
    let mut buf = BytesMut::new();
    request.encode(&mut buf).unwrap();

    assert!(sourced_wpm(&mut db, &buf).is_err());

    let post_pv = db
        .get(&oid)
        .unwrap()
        .read_property(PropertyIdentifier::PRESENT_VALUE, None)
        .unwrap();
    assert_eq!(post_pv, PropertyValue::Real(77.0));
}

#[test]
fn wpm_prefix_commit_keeps_commandable_priority_slot_multistate_output() {
    use bacnet_objects::multistate::MultiStateOutputObject;
    let mut db = ObjectDatabase::new();
    let mut mso = MultiStateOutputObject::new(1, "MSO-1", 3).unwrap();
    // Active command at priority 8 = state 2.
    mso.write_property_from(
        PropertyIdentifier::PRESENT_VALUE,
        None,
        PropertyValue::Unsigned(2),
        Some(8),
        &crate::command_source::test_origin(),
    )
    .unwrap();
    let oid = ObjectIdentifier::new(ObjectType::MULTI_STATE_OUTPUT, 1).unwrap();
    db.add(Box::new(mso)).unwrap();
    assert_eq!(priority_slot(&db, &oid, 8), Some(2.0));

    // First spec: overwrite priority 8 with state 3. Second spec: OBJECT_TYPE fails.
    let mut pv_buf = BytesMut::new();
    bacnet_encoding::primitives::encode_app_unsigned(&mut pv_buf, 3);
    let mut ot_buf = BytesMut::new();
    bacnet_encoding::primitives::encode_app_enumerated(&mut ot_buf, 0);

    use bacnet_services::common::BACnetPropertyValue;
    use bacnet_services::wpm::WriteAccessSpecification;
    let request = bacnet_services::wpm::WritePropertyMultipleRequest {
        list_of_write_access_specs: vec![WriteAccessSpecification {
            object_identifier: oid,
            list_of_properties: vec![
                BACnetPropertyValue {
                    property_identifier: PropertyIdentifier::PRESENT_VALUE,
                    property_array_index: None,
                    value: pv_buf.to_vec(),
                    priority: Some(8),
                },
                BACnetPropertyValue {
                    property_identifier: PropertyIdentifier::OBJECT_TYPE,
                    property_array_index: None,
                    value: ot_buf.to_vec(),
                    priority: None,
                },
            ],
        }],
    };
    let mut buf = BytesMut::new();
    request.encode(&mut buf).unwrap();

    assert!(sourced_wpm(&mut db, &buf).is_err());

    assert_eq!(priority_slot(&db, &oid, 8), Some(3.0));
    assert_eq!(priority_slot(&db, &oid, 16), None);
}

#[test]
fn wpm_prefix_commit_keeps_commandable_priority_16_slot() {
    let (mut db, oid) = make_db_with_commandable_ao();
    // priority 8 holds 50.0 (from the helper); priority 16 is empty.
    assert_eq!(priority_slot(&db, &oid, 8), Some(50.0));
    assert_eq!(priority_slot(&db, &oid, 16), None);

    // First spec: write PRESENT_VALUE with no priority → slot 16 = 99.0.
    // Second spec: OBJECT_TYPE fails after the slot-16 write commits.
    let mut pv_buf = BytesMut::new();
    bacnet_encoding::primitives::encode_app_real(&mut pv_buf, 99.0);
    let mut ot_buf = BytesMut::new();
    bacnet_encoding::primitives::encode_app_enumerated(&mut ot_buf, 0);

    use bacnet_services::common::BACnetPropertyValue;
    use bacnet_services::wpm::WriteAccessSpecification;
    let request = bacnet_services::wpm::WritePropertyMultipleRequest {
        list_of_write_access_specs: vec![WriteAccessSpecification {
            object_identifier: oid,
            list_of_properties: vec![
                BACnetPropertyValue {
                    property_identifier: PropertyIdentifier::PRESENT_VALUE,
                    property_array_index: None,
                    value: pv_buf.to_vec(),
                    priority: None,
                },
                BACnetPropertyValue {
                    property_identifier: PropertyIdentifier::OBJECT_TYPE,
                    property_array_index: None,
                    value: ot_buf.to_vec(),
                    priority: None,
                },
            ],
        }],
    };
    let mut buf = BytesMut::new();
    request.encode(&mut buf).unwrap();

    assert!(sourced_wpm(&mut db, &buf).is_err());

    assert_eq!(priority_slot(&db, &oid, 16), Some(99.0));
    assert_eq!(priority_slot(&db, &oid, 8), Some(50.0));
    assert_eq!(
        db.get(&oid)
            .unwrap()
            .read_property(PropertyIdentifier::PRESENT_VALUE, None)
            .unwrap(),
        PropertyValue::Real(50.0)
    );
}