Decode the PSM timers
Turn the encoded T3412 and T3324 timer bytes into seconds. A medium embedded C problem (Cellular IoT: NB-IoT and LTE-M), run and graded in the browser.
medium · Cellular IoT: NB-IoT and LTE-M · cellular · power-saving · bits
NB-IoT and LTE-M modems save power with PSM: after sending, the device stays reachable for the active time (T3324), then sleeps until the periodic update (T3412 extended). Both are requested as one byte each (as with the AT+CPSMS command): the top 3 bits are a unit, the low 5 bits a value (0 to 31).
T3412 extended units: 000 10 min, 001 1 hour, 010 10 hours, 011 2 s, 100 30 s, 101 1 min, 110 320 hours, 111 deactivated. T3324 units: 000 2 s, 001 1 min, 010 6 min, 111 deactivated (others are treated as 1 min).
Write t3412_seconds(b) and t3324_seconds(b), returning seconds, or -1 when deactivated.
Starter code
int32_t t3412_seconds(uint8_t b) {
return (b & 0x1F) * 60;
}
int32_t t3324_seconds(uint8_t b) {
return (b & 0x1F) * 2;
}Example tests
A daily update, 10 s active
show(0x38, 0x05);Expected output:
T3412 0x38 = 86400 s, T3324 0x05 = 10 sAn hourly update, 1 min active
show(0x21, 0x21);Expected output:
T3412 0x21 = 3600 s, T3324 0x21 = 60 sLearn it first
- Cellular IoT: NB-IoT and LTE-M · The two LPWA standards, PSM, eDRX and AT commands.