How do I encode a Configuration Downlink for a Thermocouple Temp Sensor?

How do I encode a Configuration Downlink for a Thermocouple Temp Sensor?

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

See User Manual at https://www.multitech.com/models/RB90000220LF for more information. 

Byte  Bits Description
0 Downlink Message Type (0x13 = Thermocouple Sensor)
1 7:5 Unused
4:1 Thermocouple type (see type table)
0 Mode: 0 for Threshold or 1 for Report on Change
2 7:0 Periodic reporting in 1 minute or 1 hour intervals. Default is 0 (disabled)
3-7 Defined by Mode (See Mode sections)

Thermocouple Types
Although the sensor comes with a K-type thermocouple by default, there are several common thermocouple types are supported. Bits 4:1 in byte 1 define the type as shown in the table below.
Thermocouple Type Setting
Byte 1, Bits 4:1            Description
0000                              B Type
0001                              E Type
0010                              J Type
0011                              K Type (Default)
0100                              N Type
0101                              R Type
0110                              S Type
0111                              T Type
1000                              Voltage Mode, Gain = 8. Code = 8 x 1.6 x 217 x VIN
1100                              Voltage Mode, Gain = 32. Code = 32 x 1.6 x 217 x VIN


Thermocouple Temp Sensor Threshold Configuration Example:
      13 00 89 0B 4B 00 28 A0
      13            Downlink Message Type ( 0x13 = Thermocouple Temp Sensor )
      06            0x06 K-Type  Thermocouple + 0x00 Threshold Mode (Binary 00110 + Binary 0 )
      00            Configuration Mode (0x00 = Threshold Mode)
      89            Periodic Reporting (0x89 = 9 minutes)
      0B            Restoral margin in degrees (0x0B = 11 degrees Celsius)
      4B00        Upper temperature threshold (4B00 -> 2’s complement then divided by 16 = 19200/16 = 1200 degrees Celsius)
      28A0        Lower temperature threshold (28A0 -> 2's complement then divided by 16 = 10400/16 = 650 degrees Celsius)

Thermocouple Temp Sensor Report On Change Configuration Example:
      13 01 1B 00 03 70 03 F0
      13            Downlink Message Type (0x13 = Thermocouple Temp Sensor)
      07            0x06 K-Type Thermocouple + 0x01 Report-on-Change Mode (Binary 00110 + Binary 1 )
      01            Configuration Mode (0x01 = Report on Change Mode)
      1B            Periodic Reporting (0x1B = 27 Hours)
      00            Not Used
      0370       Temperature Increase (0370 -> 2’s complement then divided by 16 = 880/16 = 55)
      03F0       Temperature Decrease (03F0 -> 2’s complement then divided by 16 = 1008 = 63)
      
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)