Skip to content

Decode a packet

Rémy Tribhout edited this page Apr 8, 2021 · 1 revision

❓ Radio packets received from the micro mote are 192 bits long, with 96 bits where 16 bits are CRC and 80 is actual payload. The goal here is to decode an hexadecimal packet to read up to 4 temperature data per packet. Measured temperature T0 is expected to be equal to 35,8121 C as shown in How-does-a-received-packets-looks-like.


1️⃣ Temperature calibration decoding

  1. CRC
  2. Packet #
  3. Ref code
  4. Data
"Data TX Calib" *
1   |2|3|4              |
c6c301d1050603a980393870
CRC | | |ID |coefA|coefB|

TX Calib means we are expecting coefficients

Here we can find Coef A & B values:

  • 03a980 (hex) = 240 000 (dec)
  • 393870 (hex) = 3 750 000 (dec)

2️⃣ Temperature measurements

"Data TX"
1   |2|3|4             |
cd0d02dd07e407f007fd080f
CRC |dat|T3 |T2 |T1 |T0|

Data Tx means we are expecting temperatures

But we cannot find coherent values regarding outputs above:

  • 080f (hex) = 2063 (dec) ≠ 35,8121 C 🌞

We clearly see the mismatch for Data Tx payload values from hexa to decimal conversion, meaning it requires a bit more computation steps before getting the right temperature: B / 1000 /( A / 1000 - ln ( data * 17500 / 2^8 ) ) - 273

Where A = coefA, B = coefB and data = Tn

  • Code snippet (python)
batch_cal = [0.0, 0.0, 0.0, 0.0, 1.0, 0.0]
temp = global_cal_b / 1000.0 / (global_cal_a / 1000.0 - math.log(float(in_data) * 17500.0 / 256.0)) - 273.0;
poly_accum = 0.0;
for ii in range(CAL_POLY_ORDER+1):
    cur_poly_coeff = batch_cal[ii]
    for jj in range(CAL_POLY_ORDER-ii):
        cur_poly_coeff *= temp
        poly_accum += cur_poly_coeff
return round(poly_accum, 4)

Batch calibration (known skewed chip batch) here is 0. This function output is = 35,8121 C as expected 🏆