diff --git a/examples/android_ranging_oob.pdl b/examples/android_ranging_oob.pdl index 4e4dfce..91bc61c 100644 --- a/examples/android_ranging_oob.pdl +++ b/examples/android_ranging_oob.pdl @@ -5,7 +5,8 @@ little_endian_packets // Common definitions. enum Version: 8 { - CURRENT = 1, + V1 = 1, + CURRENT = 2, FUTURE = .., } @@ -24,9 +25,9 @@ enum Technology: 8 { BLE_CS = 0x1, WIFI_NAN_RTT = 0x2, BLE_RSSI = 0x3, - // Version 2 + // Version 3(In-Development) WIFI_STA_RTT = 0x4, - // Version 3 + // Version 4(In-Development) WIFI_AP_RTT = 0x5, RESERVED = .., } @@ -36,13 +37,29 @@ struct TechnologySet { ble_cs: 1, wifi_nan_rtt: 1, ble_rssi: 1, - // Version 2 + // Version 3(In-Development) wifi_sta_rtt: 1, - // Version 3 + // Version 4(In-Development) wifi_ap_rtt: 1, _reserved_: 10, } +enum TechnologyTransitioning: 8 { + NOT_SUPPORTED = 0x0, + MAKE_BEFORE_BREAK = 0x1, + RESERVED = .., +} + +enum DeviceType: 16 { + UNKNOWN = 0x0, + PHONE = 0x1, + TABLET = 0x2, + TAG = 0x3, + WEARABLE = 0x4, + HEARABLE = 0x5, + RESERVED = .., +} + packet OobMessage { version: Version, id: MessageId, @@ -109,8 +126,8 @@ struct WifiNanRttCapabilitiesV1: Capabilities(technology = WIFI_NAN_RTT) { num_rx_chains: 8, } -// Version 2 -struct WifiNanRttCapabilitiesV2: Capabilities(technology = WIFI_NAN_RTT) { +// Version 3(In-Development) +struct WifiNanRttCapabilitiesV3: Capabilities(technology = WIFI_NAN_RTT) { features: 8, periodic: 1, _reserved_: 23, @@ -123,7 +140,7 @@ struct BleRssiCapabilities: Capabilities(technology = BLE_RSSI) { address: 8[6], } -// Version 2 +// Version 3(In-Development) struct WifiStaRttCapabilities: Capabilities(technology = WIFI_STA_RTT) { features: 8, _count_(band_info): 8, @@ -131,7 +148,7 @@ struct WifiStaRttCapabilities: Capabilities(technology = WIFI_STA_RTT) { band_info: WifiBandInfo[] } -// Version 3 +// Version 4(In-Development) struct WifiApRttCapabilities: Capabilities(technology = WIFI_AP_RTT) { features: 8, _count_(band_info): 8, @@ -190,8 +207,8 @@ struct WifiNanRttConfigurationV1: Configuration(technology = WIFI_NAN_RTT) { _reserved_: 7, } -// Version 2 -struct WifiNanRttConfigurationV2: Configuration(technology = WIFI_NAN_RTT) { +// Version 3(In-Development) +struct WifiNanRttConfigurationV3: Configuration(technology = WIFI_NAN_RTT) { _size_(service_name): 8, service_name: 8[], device_role: WifiDeviceRole, @@ -206,7 +223,7 @@ struct BleRssiConfiguration: Configuration(technology = BLE_RSSI) { address: 8[6], } -// Version 2 +// Version 3(In-Development) struct WifiStaRttConfiguration: Configuration(technology = WIFI_STA_RTT) { frequency: 16, format_and_bandwidth: 8, @@ -215,7 +232,7 @@ struct WifiStaRttConfiguration: Configuration(technology = WIFI_STA_RTT) { security_method: WiFiSecurityMethod, } -// Version 3 +// Version 4(In-Development) struct WifiApRttConfiguration: Configuration(technology = WIFI_AP_RTT) { frequency: 16, bssid: 8[6], @@ -231,9 +248,17 @@ packet CapabilitiesRequest: OobMessage(id = CAPABILITIES_REQUEST) { requested_technologies: TechnologySet, } -packet CapabilitiesResponse: OobMessage(id = CAPABILITIES_RESPONSE) { +packet CapabilitiesResponseV1: OobMessage(version = V1, id = CAPABILITIES_RESPONSE) { + supported_technologies: TechnologySet, + capabilities: Capabilities[], +} + +// Version 2 +packet CapabilitiesResponseV2: OobMessage(id = CAPABILITIES_RESPONSE) { supported_technologies: TechnologySet, capabilities: Capabilities[], + supported_transitioning : TechnologyTransitioning, + device_type: DeviceType, } packet ConfigurationRequest: OobMessage(id = CONFIGURATION_REQUEST) { diff --git a/pdl-compiler/src/backends/java/codegen/enum.rs b/pdl-compiler/src/backends/java/codegen/enum.rs index bf60318..1fb887d 100644 --- a/pdl-compiler/src/backends/java/codegen/enum.rs +++ b/pdl-compiler/src/backends/java/codegen/enum.rs @@ -200,7 +200,7 @@ impl MultiValueTag for TagOther { fn static_factory(&self, super_name: &str, ty: Integral) -> Tokens { quote! { public static $(self.name()) $(self.name())($ty value) { - $super_name tag = $super_name.fromByte(value); + $super_name tag = $super_name.from$(ty.capitalized())(value); if (!(tag instanceof $(self.name()) self)) { throw new IllegalArgumentException( "Value " + $(ty.stringify(quote!(value))) + diff --git a/pdl-compiler/src/backends/java/codegen/packet.rs b/pdl-compiler/src/backends/java/codegen/packet.rs index cdc3c03..3b0bf6e 100644 --- a/pdl-compiler/src/backends/java/codegen/packet.rs +++ b/pdl-compiler/src/backends/java/codegen/packet.rs @@ -768,15 +768,7 @@ fn build_child_fitting_constraints( tokens.extend(quote!( Builder builder; $(for child in children { - if ( - $(for member in members.iter() { - $(if let Some(value) = child.constraints.get(member.name()) { - $(member.equals(member.constraint(value))) - }) - }) - $(if !child.constraints.is_empty() && child.field_width().is_some() => &&) - $(if let Some(width) = child.field_width() => payload.limit() == $(width / 8)) - ) { + if ($(fits_childs_constraints(members, child))) { builder = $(&child.name).fromPayload(payload); } else$[' '] }) @@ -804,6 +796,27 @@ fn build_child_fitting_constraints( tokens } +fn fits_childs_constraints(members: &[Field], child: &InheritanceNode) -> Tokens { + let mut tokens = Tokens::new(); + + let constraints = members + .iter() + .flat_map(|member| child.constraints.get(member.name()).map(|value| (member, value))); + + tokens.append(quote!( + $(for (member, value) in constraints join ( && ) { + $(member.equals(member.constraint(value))) + }) + )); + + tokens.append(quote!( + $(if !child.constraints.is_empty() && child.field_width().is_some() => &&) + $(if let Some(width) = child.field_width() => payload.limit() == $(width / 8)) + )); + + tokens +} + /// Generates a decalaration $(val.name())Count that stores the number of elements in the array /// described by the function args. fn declare_array_count(