How do I encode a Configuration Downlink for a No-Probe Temp Sensor?

How do I encode a Configuration Downlink for a No-Probe Temp Sensor?

NOTE:  All downlinks must contain a total of (8) bytes, padded with zeros at the end when necessary.


No-Probe Temp Sensor Configuration Message: ­0x09
      Byte            Description
      0                  Downlink Message Type (0x09 = No Probe Temp Sensor)
      1                  Mode: 0x00 for Threshold, or 0x01 for Report on Change
      2-7              Defined by Mode (See Mode sections)

No Probe Temp Sensor Threshold Mode Configuration: 
      Byte            Description
      0                  Downlink Message Type (0x09 = No Probe Temp Sensor) 
      1                  Configuration Mode (0x00  = Threshold)
      2                  Periodic reporting in 1 minute or 1 hour intervals. Default is 0 (disabled)
      3                  Restoral margin (bits 3:0 only). Default 5 degrees C.
      4                  Lower temperature threshold. Default 10 degrees C.
      5                  Upper temperature threshold. Default 90 degrees C.

The upper and lower temperature thresholds are signed values with units of one degree Celsius (range is -40 to 100 degrees C). Note that if the configuration settings exceed the maximum ratings on the sensor, the sensor may not report an event.
The Restoral Margin is used for the upper and lower thresholds and requires the temperature value to cross back over the threshold a certain amount before a new event is reported. This prevents excessive event messages if the temperature is at or near the threshold.
For example, consider an upper temp threshold set at 30 degrees Celsius and the restoral margin set at 5 degrees. If the temperature initially exceeds 30 degrees then an event is generated and a message is sent to the network. The temperature must now drop to 25 degrees and then exceed 30 degrees before another event is reported.
The restoral margins are unsigned values with units of 1 degree Celsius (range is 1-15 degrees C). If a restoral margin is set to 0, it is disabled.
Periodic reporting is described in the section Periodic Reports.
 
No Probe Temp Sensor Report on Change Mode Configuration: 
      Byte            Description
      0                  Downlink Message Type (0x09 = No Probe Temp Sensor)
      1                  Configuration Mode (0x01 = Report on Change)
      2                  Periodic reporting in 1 minute or 1 hour intervals. Default is 0 (disabled)
      3                  Not used
      4                  Temperature increase
      5                  Temperature decrease

If the temperature increase or decrease are non-zero, then the sensor will send an alert
any time the temperature changes by the specified amount. For example, if the
temperature increase and decrease are set to 5 degrees, then an alert is sent every time
the temperature changes 5 degrees from the last report. The temperature increase and
decrease are unsigned values with units in degrees C.
Periodic reporting is described in the section Periodic Reports

No Probe Temp Sensor Periodic Reports Mode Configuration: 
      Byte            Description
      0                  Period defined in hours (1-127 hours)
      1                  Period defined in minutes (1-127 minutes)

Threshold Mode Configuration Example:
      09 00 08 05 F6 1E 00 00
      09                  Downlink Message Type (0x09 = No Probe Temp Sensor)
      00                  Configuration Mode (0x00 = Threshold)
      08                  Periodic Reporting (0x08 = 8 hours)
      05                  Restoral Margin (0x05 = 5 degrees Celsius Temperature)
      F6                  Lower Temperature Threshold ( 0xF6 = signed 2's compliment -10 degrees C)
      1E                  Upper Temperature Threshold ( 0x1E = signed 2's compliment 30 degrees C)
      00                  Padded Zeros Do Not Change
      00                  Padded Zeros Do Not Change

Report on Change Configuration Example:
      09 01 8F 00 0A 0F 00 00
      09                  Downlink Message Type (0x09 = Air Temp & Humidity)
      01                  Configuration Mode (0x01 = Report On Change)
      8F                  Periodic Reporting (0x8F = 15 minutes)
      00                  Not Used
      0A                  Temperature Increase (0x0A = 10 degrees Celsius)
      0F                  Temperature Decrease (0x0F = 15 degrees Celsius)
      00                  Padded Zeros Do Not Change
      00                  Padded Zeros Do Not Change

If the configuration is successful the sensor will respond with a Downlink Acknowledge message:
      1 0 FF 02
      1                    Protocol Version (currently always 0x1)
      0                   Packet Counter, increments by 1 each message and wraps from 0xF to 0x0
      FF                 Message Type (Downlink ACK = 0xFF)
      02                 Downlink Message Valid (Invalid/Undefined = 0x01, Valid = 0x02)