Hi,
I'm wondering what is a good way of keeping track of when the device is inside the active time window so that the data is being sent at the correct time.
Here is my current implementation and thought process.
Requested PSM parameters:
T3324 Active Time (00010000) = 32 seconds
T3412 TAU timer (00010010) = 180 minutes
The MME adds a random value between 1-3240 seconds to the periodic TAU Timer. = 1s-54min so I have to parse the timers at runtime since I can't know for sure what the values will be set at.
So for example let's say the TAU timer is set to (00010100) = 200 minutes by the network.
+CEREG: 5,1,"B3C0","0006CE69",9,,,"00010000","00010100"
I'm parsing the timer values like this and converting them to seconds:
int set_psm_values(void) { if (at_cmd_write("AT+CEREG=5", NULL, 0, NULL) != 0) { printk("AT+CEREG=5 cmd write failed\n"); return -1; } char at_cereg[CEREG_SIZE]; if (at_cmd_write("AT+CEREG?", at_cereg, CEREG_SIZE, NULL) != 0) { printk("AT+CEREG? cmd write failed\n"); return -1; } printk("%s", at_cereg); char tau_timer[TIMER_SIZE + 1]; char active_time_timer[TIMER_SIZE + 1]; parse_timers(at_cereg, tau_timer, active_time_timer); int tau_timer_in_s = get_tau_timer_value_in_s(tau_timer); int active_time_in_s = get_active_time_in_s(active_time_timer); if(tau_timer_in_s <= 0 || active_time_in_s <= 0) { return -1; } uint8_t multiplier_tau = get_timer_multiplier(tau_timer); uint8_t multiplier_active = get_timer_multiplier(active_time_timer); psm_interval_s = tau_timer_in_s * multiplier_tau; active_time_s = active_time_in_s * multiplier_active; active_time_start_s = psm_interval_s - active_time_s; active_time_end_s = psm_interval_s; return 0; }
With the parameters above the end result is:
psm_interval_s = 12000 seconds
active_time_start_s = 11968 seconds (T3412 - T3324)
active_time_end_s = 12000 seconds
Then I start an timer that increments psm_timer_s every second:
static uint64_t psm_timer_s = 0;
void psm_timer_handler(struct k_timer *dummy)
{
psm_timer_s++;
if(psm_timer_s >= psm_interval_s)
{
psm_timer_s = 0;
}
}
K_TIMER_DEFINE(psm_timer, psm_timer_handler, NULL);
Then I check like this if i'm inside the active time window:
bool inside_psm_active_time_window(void)
{
return psm_timer_s >= active_time_start_s && psm_timer_s < active_time_end_s;
}
Would it perhaps be better to just check +CSCON every so often instead to see if I'm inside the active window and then send data?
Best regards,
Patrik