Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 39 additions & 14 deletions examples/android_ranging_oob.pdl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ little_endian_packets
// Common definitions.

enum Version: 8 {
CURRENT = 1,
V1 = 1,
CURRENT = 2,
FUTURE = ..,
}

Expand All @@ -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 = ..,
}
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -123,15 +140,15 @@ 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,
security_method: WiFiSecurityMethod,
band_info: WifiBandInfo[]
}

// Version 3
// Version 4(In-Development)
struct WifiApRttCapabilities: Capabilities(technology = WIFI_AP_RTT) {
features: 8,
_count_(band_info): 8,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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],
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion pdl-compiler/src/backends/java/codegen/enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ impl MultiValueTag for TagOther {
fn static_factory(&self, super_name: &str, ty: Integral) -> Tokens<Java> {
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))) +
Expand Down
31 changes: 22 additions & 9 deletions pdl-compiler/src/backends/java/codegen/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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$[' ']
})
Expand Down Expand Up @@ -804,6 +796,27 @@ fn build_child_fitting_constraints(
tokens
}

fn fits_childs_constraints(members: &[Field], child: &InheritanceNode) -> Tokens<Java> {
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(
Expand Down