test: probe existing SYS clock access and AT time queries from APP
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include "ql_nw.h"
|
||||
#include "ql_rtc.h"
|
||||
#include "app_nitz_test.h"
|
||||
#include "app_sys_time_probe.h"
|
||||
|
||||
/* SDK wrapper uses the same PMIC timezone as time(); no libc TZ assumptions. */
|
||||
extern struct tm *ql_localtime_r(const time_t *, struct tm *);
|
||||
@@ -52,13 +53,14 @@ static int two_digits(const char *s)
|
||||
return (s[0] - '0') * 10 + s[1] - '0';
|
||||
}
|
||||
|
||||
/* Accept SDK documented "YY/MM/DD HH:MM:SS +32 00" and compact
|
||||
/* Accept actual "YY/MM/DD HH:MM:SS 32 0", documented signed format, and compact
|
||||
* "YY/MM/DD,HH:MM:SS+32". NITZ UT is UTC; zone is metadata, not subtracted.
|
||||
* abs_time/leap_sec have insufficient documented semantics to use as epoch. */
|
||||
static int parse_nitz(const char *s, time_t *epoch, int *zone)
|
||||
{
|
||||
size_t n = strlen(s), pos = 17;
|
||||
int yy, mo, dd, hh, mm, ss, q, dst;
|
||||
int yy, mo, dd, hh, mm, ss, q, dst, negative = 0;
|
||||
size_t start;
|
||||
long long value;
|
||||
if (n < 20 || s[2] != '/' || s[5] != '/' ||
|
||||
(s[8] != ' ' && s[8] != ',') || s[11] != ':' || s[14] != ':') return -1;
|
||||
@@ -66,16 +68,23 @@ static int parse_nitz(const char *s, time_t *epoch, int *zone)
|
||||
hh = two_digits(s + 9); mm = two_digits(s + 12); ss = two_digits(s + 15);
|
||||
if (yy < 0 || calendar_epoch(2000 + yy, mo, dd, hh, mm, ss, &value) != 0 ||
|
||||
value < MIN_EPOCH || value > MAX_EPOCH) return -2;
|
||||
/* Actual SDK output is also "26/10/26 08:00:10 32 0". */
|
||||
if (s[pos] == ' ') ++pos;
|
||||
if (n < pos + 3 || (s[pos] != '+' && s[pos] != '-')) return -3;
|
||||
q = two_digits(s + pos + 1);
|
||||
if (q < 0 || q > 56 || (s[pos] == '-' && q > 48)) return -3;
|
||||
*zone = s[pos] == '-' ? -q : q;
|
||||
pos += 3;
|
||||
else if (s[pos] != '+' && s[pos] != '-') return -3;
|
||||
if (s[pos] == '+' || s[pos] == '-') negative = s[pos++] == '-';
|
||||
start = pos;
|
||||
q = 0;
|
||||
while (pos < n && s[pos] >= '0' && s[pos] <= '9' && pos - start < 2)
|
||||
q = q * 10 + s[pos++] - '0';
|
||||
if (pos == start || q > 56 || (negative && q > 48)) return -3;
|
||||
*zone = negative ? -q : q;
|
||||
if (pos < n) {
|
||||
if (n != pos + 3 || s[pos] != ' ') return -4;
|
||||
dst = two_digits(s + pos + 1);
|
||||
if (dst < 0 || dst > 2) return -4;
|
||||
if (s[pos++] != ' ') return -4;
|
||||
start = pos;
|
||||
dst = 0;
|
||||
while (pos < n && s[pos] >= '0' && s[pos] <= '9' && pos - start < 2)
|
||||
dst = dst * 10 + s[pos++] - '0';
|
||||
if (pos == start || pos != n || dst > 2) return -4;
|
||||
}
|
||||
*epoch = (time_t)value;
|
||||
return 0;
|
||||
@@ -177,7 +186,8 @@ static void nitz_test_worker(void *arg)
|
||||
long long advance, elapsed, drift;
|
||||
unsigned int span;
|
||||
(void)arg;
|
||||
printf("[APP-NITZ-TEST] begin version=1 source=operator_nitz ntp=off\r\n");
|
||||
app_sys_time_probe_run();
|
||||
printf("[APP-NITZ-TEST] begin version=2 source=operator_nitz ntp=off\r\n");
|
||||
if (!m_get_api_ptr || !m_get_api_ptr("ql_nw_get_nitz_time_info") ||
|
||||
!m_get_api_ptr("ql_localtime_r") || !m_get_api_ptr("ql_rtc_set_time") ||
|
||||
!m_get_api_ptr("ql_rtc_get_time")) {
|
||||
|
||||
Reference in New Issue
Block a user