Link Search Menu Expand Document

Conditional Byte

Dec 6 2023 at 12:00 AM

  1. Introduction
  2. Example Options File for ByteLength Condition
    1. Property Details (Sigfox Parser)
    2. Property Details (Conditional Byte)
  3. Example Options File for ByteMask Condition
    1. Property Details (Sigfox Parser)
    2. Property Details (Conditional Byte)

Introduction

This filter is designed to handle the byte array generated from the initial order filter payload data. It ensures that the payload is enriched with relevant properties based on the conditions met during processing. Additionally, it handles the inclusion of default properties to maintain a comprehensive payload structure. It adds properties to the payload following a specific set of conditions:

  1. Condition Evaluation: The filter begins by identifying the condition that evaluates to true.
  2. No True Condition: In the absence of a true condition, the filter logs this occurrence and exits.
  3. True Condition Processing: For the condition that evaluates to true, the filter retrieves the associated property values and incorporates them into the payload.
  4. Default Properties Check: If default properties are configured, the filter checks for any missing default properties on the payload. Any missing default properties are then added to the payload with their predefined default values.
NOTE
It is advisable not to position this filter as the initial filter in the processing chain. Ideally, it should be placed as the second filter to ensure optimal functionality.

Example Options File for ByteLength Condition

{
 "Devices": {
    "DemoDevice": {
      "Enabled": true,
      "Debug": true,
      "DeviceType": "Generic",
      "GroupName": "DemoDevice",
      "ActionDelay": 60000,
      "DataSource": {
        "DataSourceType": "RestApi"
      },
      "Filters": [
        {
          "FilterType": "SigfoxParser",
          "Order": 1,
          "DeviceTypePath": "deviceTypeId",
          "DeviceNamePath": "deviceId"
        },
        {
          "FilterType": "ConditionalByte",
          "Order": 2,
          "DefaultProperties": {
            "USBPower": {
              "DataType": "Bool"
            },
            "BatteryVoltage": {
              "DataType": "Int16"
            }
          },
          "Conditions": {
            "Trigger": {
              "ConditionType": "ByteLength",
              "ByteLength": 1,
              "Properties": {
                "USBPower": {
                  "DataType": "Bool",
                  "StartByte": 0
                }
              }
            },
            "Heartbeat": {
              "ConditionType": "ByteLength",
              "ByteLength": 4,
              "Properties": {
                "USBPower": {
                  "DataType": "Bool",
                  "StartByte": 1
                },
                "BatteryVoltage": {
                  "DataType": "Int16",
                  "StartByte": 2,
                  "LittleEndian": false
                }
              }
            }
          }
        }
        ...
      ]
    }
  } 
}

Property Details (Sigfox Parser)


Here is an overview of the parameters for configuring the Sigfox Parser filter:

First Order Filter (Sigfox Parser)

Property NameDescription
FilterTypeThe value for this filter is “SigfoxParser”.
OrderUsed to determine the process order when more than one filter has been configured.
GatewayIdPathThe JSON path for the property value that will be used for the gateway Id. If this is blank, then the configured gateway Id will be used.
GroupNamePathThe JSON path for the property value that will be used for the group name. If this is blank, then the configured group name will be used.
DeviceTypePathThe JSON path for the property value that will be used for the device type. If this is blank, then the configured device type will be used.
DeviceNamePathThe JSON path for the property value that will be used for the device name. If this is blank, then the configured device name will be used.

Property Details (Conditional Byte)


Here is an overview of the parameters for configuring the Conditional Byte filter:

Second Order Filter (Conditional Byte)

Property NameDescription
FilterTypeThe value for this filter is “ConditionalByte”.
OrderUsed to determine the process order when more than one filter has been configured.
DefaultPropertiesThe default properties expected on the filter and their data types.
ConditionsThe filter conditions that are evaluated to determine how to process the conditional byte.
Heartbeat (Condition name)The name of the configured condition.
ConditionTypeThe Condition type. Currently only “ByteLength” and “ByteMask” condition type is supported.
ByteLengthThe condition’s expected length of the byte array. If the data received byte array length is not equal to the expected byte array length, the condition will evaluate to false, thereby not processing the byte array.
PropertiesThe configured properties for the condition.
USBPower (Property name)The configured property name.
DataTypeThe expected data type for the property.
StartByteThe starting byte position in the data byte array for the property.
LittleEndianThe Little-Endian is set to true by default. See to learn more.

Example Options File for ByteMask Condition

{
  "Devices": {
    "TestDevice": {
      "Enabled": true,
      "Debug": true,
      "DeviceType": "Generic",
      "GatewayId": "GenericTestDevice",
      "GroupName": "TestDevice",
      "ActionDelay": 60000,
      "DataSource": {
        "DataSourceType": "RestApi"
      },
      "Filters": [
        {
          "FilterType": "SigfoxParser",
          "Order": 1,
          "DeviceTypePath": "deviceTypeId",
          "DeviceNamePath": "deviceId"
        },
        {
          "FilterType": "ConditionalByte",
          "Order": 2,
          "DefaultProperties": {
            "TestProp1": {
              "DataType": "Bool"
            },
            "TestProp2": {
              "DataType": "Bool"
            },
            "TestProp3": {
              "DataType": "Bool"
            },
            "TestProp4": {
              "DataType": "Bool"
            },
            "TestProp5": {
              "DataType": "Bool"
            }
          },
          "Conditions": {
            "TestCondition": {
              "ConditionType": "ByteMask",
              "Properties": {
                "TestProp1": {
                  "DataType": "Bool",
                  "StartByte": 0,
                  "EndByte": 3,
                  "Masks": ["0x52","0x00","0x00","0x12"],
                  "ExpectedValues": [82,0,0,18]
                },
                "TestProp2": {
                  "DataType": "Bool",
                  "StartByte": 4,
                  "EndByte": 4,
                  "Masks": ["0x48"],
                  "ExpectedValues": [72]
                },
                "TestProp3": {
                  "DataType": "Bool",
                  "StartByte": 0,
                  "EndByte": 3,
                  "Masks": ["0x52","0x00","0x00","0x12"],
                  "ExpectedValues": [82,0,0,17]
                },
                "TestProp4": {
                  "DataType": "Bool",
                  "StartByte": 0,
                  "EndByte": 3,
                  "Masks": ["0x53","0x00","0x00","0x12"],
                  "ExpectedValues": [82,0,0,18]
                },
                "TestProp5": {
                  "DataType": "Bool",
                  "StartByte": 4,
                  "EndByte": 4,
                  "Masks": ["0xFF"],
                  "ExpectedValues": [72]
                }
              }
            }
          }
        }
      ]
    }
  }
}

Property Details (Sigfox Parser)


Here is an overview of the parameters for configuring the Sigfox Parser filter:

First Order Filter (Sigfox Parser)

Property NameDescription
FilterTypeThe value for this filter is “SigfoxParser”.
OrderUsed to determine the process order when more than one filter has been configured.
GatewayIdPathThe JSON path for the property value that will be used for the gateway Id. If this is blank, then the configured gateway Id will be used.
GroupNamePathThe JSON path for the property value that will be used for the group name. If this is blank, then the configured group name will be used.
DeviceTypePathThe JSON path for the property value that will be used for the device type. If this is blank, then the configured device type will be used.
DeviceNamePathThe JSON path for the property value that will be used for the device name. If this is blank, then the configured device name will be used.

Property Details (Conditional Byte)


Here is an overview of the parameters for configuring the Conditional Byte filter:

Second Order Filter (Conditional Byte)

Property NameDescription
FilterTypeThe value for this filter is “ConditionalByte”.
OrderUsed to determine the process order when more than one filter has been configured.
DefaultPropertiesThe default properties expected on the filter and their data types.
ConditionsThe filter conditions that are evaluated to determine how to process the conditional byte.
TestCondition(Condition name)The name of the configured condition.
ConditionTypeThe Condition type. Currently only “ByteLength” and “ByteMask” condition type is supported.
PropertiesThe configured properties for the condition.
TestProp1(Property name)The configured property name.
DataTypeThe expected data type for the property.
StartByteThe starting byte position in the data byte array for the property.
EndByteThe index of the byte to end the masking.
MasksArray of hexadecimal masks to apply to the bytes indicated by the start and end byte index. The masks will be applied in the order they are configured, and there should always be a mask per byte within the range of the start and end byte indicated. The masks should be added as strings in the 0x00 hexadecimal format.
ExpectedValuesArray of expected decimal values for the bytes after the masks are applied. By comparing value of the byte after the mask is applied, the boolean value for the property is determined. The values will be evaluated in the order they are configured, and there should always be a value per byte within the range of the start and end byte indicated.
LittleEndianThe Little-Endian is set to true by default. (Not included in config) See to learn more.