Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
407051d420 | ||
|
|
e57ddbe89c | ||
|
|
db6109172c | ||
|
|
c7756c9325 | ||
|
|
280b7a4149 |
@@ -0,0 +1,9 @@
|
|||||||
|
# APP 启动校时
|
||||||
|
|
||||||
|
PDP 首次激活后,APP 通过现有 SDK 的 `ql_nw_get_nitz_time_info` 获取运营商 NITZ 快照。按 UTC 解析日期,用 `ql_localtime_r` 转换到当前 PMIC 时区,再调用 `ql_rtc_set_time` 写入 APP RTC。读取 RTC 和 `time(NULL)`,两项误差都不超过 3 秒才打印 `[APP-TIME] PASS`。
|
||||||
|
|
||||||
|
每次开机只启动一次;读取失败、日期无效或查询耗时超过 2 秒时,间隔 5 秒重试,最多 3 次。选中首个有效快照后最多写入一次,即使读回失败也不重复写入。保留原有 NITZ 开关,不增加网络域名或端口,不修改内核,不依赖 NTP、AT 命令、SYS 探测或额外内核诊断。支持现有内核导出接口下的纯 APP OTA。
|
||||||
|
|
||||||
|
限制:SDK 返回快照未提供接收时间,读回验证只证明 APP 时钟与快照一致,不能证明快照新鲜度。本方案保留实机验证通过的首次 PDP 后快照策略,不扩展为持续校时。首次 WSS 建立仍需等待实际 TLS 握手验证;本次修复不修改连接调度或对话回复超时。
|
||||||
|
|
||||||
|
验证:`DEVELOPER_DIR=/Library/Developer/CommandLineTools python3 tools/test_app_time_calibrate.py`,实际 C 源码通过 26 组行为场景和日期解析验证(ASan/UBSan),覆盖 UTC/时区、无效和静态快照、重试、tick 回绕、RTC 写入/读回失败。迁移依据为 test/time-fix 的 884ab54;仅调整模块命名与日志,不改变已验证校时算法。2026-10-26 17:29:27 完整串口日志中,原版本校时读回误差为 0 秒,WSS 证书验证与 HTTP 101 成功,第二次对话收到 TTS。
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
# 对话无回复诊断日志
|
||||||
|
|
||||||
|
设备端新增四类日志,按 `round`、`session`、单调运行时间关联。诊断不调整对话协议、VAD 阈值或回复等待时限。
|
||||||
|
|
||||||
|
| 标记 | 内容 | 可以缩小的范围 |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| `MIC-DIAG` | 录音打开结果及句柄、读取返回值/字节数、全零帧、峰值/平均绝对幅值、录音事件、PCM 缓冲写入丢失 | 区分未取得 PCM、全零输入、已有音频但没有通过 VAD、音频交给编码器前丢失 |
|
||||||
|
| `VOICE-TX` | 认证消息入队结果;START/END 的序号、类型、字节数、返回值和入队耗时;音频入队失败 | 区分请求未入队、内存分配失败、正常提交发送队列 |
|
||||||
|
| `WSS-IO` | 实际 TLS 写入结果、累计写入次数和字节;TLS 错误码、部分写入进度和重试;实际接收字节;关闭时的累计收发及未消费接收字节 | 区分入队后未完成写入、对端关闭、收到字节但应用层未获得完整消息 |
|
||||||
|
| `VOICE-RX` | 接收文本长度、前 192 字节、当前会话、是否通过会话准入检查;二进制消息计数 | 显示 START_ACK/END_ACK、未知回复、被准入检查丢弃的消息。二进制消息仍沿用原有忽略行为 |
|
||||||
|
| `VOICE-DIAG` | START/END 入队后的摘要、超时断开前和断开回调时的摘要 | 汇总入队成功/失败数、音频载荷字节、文本/二进制消息数、ACK 次数、末次收包距今时长和回复等待时长 |
|
||||||
|
|
||||||
|
拾音统计按一次录音累计,每秒及停止时输出。`peak`/`mean_abs` 是 16 位有符号 PCM 的绝对幅值,不是分贝;`zero` 统计有效读取长度内全部为零的帧。`short` 包括零长度以及所有非 640 字节的读取。PCM 写入不足或失败计入 `ring_drops`,同时记录丢失字节数。录音 tick 回调不打印,其他重复事件限频。
|
||||||
|
|
||||||
|
`VOICE-TX ret=0` 只代表入队成功。`queue_bytes` 只计成功入队的音频载荷,不含自定义包头、WebSocket 帧头、认证和控制消息。`WSS-IO tx_bytes` 是传给传输层并成功返回的明文字节数,含握手/帧头,不能与 `queue_bytes` 直接比较;TLS 失败时已写出的部分字节由 `tls_write_failed`/`tls_write_timeout` 的 `sent` 单独报告。正常写入首条和每 50 次打印一次,实际接收前 20 次及每 50 次打印,断开时输出累计值。`tick`/`elapsed_ticks` 使用 RTOS tick,其他带 `ms` 的字段使用单调毫秒。
|
||||||
|
|
||||||
|
`start_ack`/`end_ack` 按收到的文本子串统计,包含被准入检查拒绝的消息;它们不是对当前 session 的服务端确认保证。应结合 `VOICE-RX` 原文中的会话标识判断归属。若服务端协议不发送 ACK,ACK 为零本身不代表失败。`accepted=1` 表示通过外层会话准入检查,后续仍可能因 OTA、打断状态、URL 或 session 校验而未播放。文本仅保留前 192 字节,原有错误消息完整分块日志继续保留。
|
||||||
|
|
||||||
|
复现时保留开机到失败后第二次对话结束的完整串口日志。推荐按以下顺序判断:
|
||||||
|
|
||||||
|
1. `MIC-DIAG` 检查读取长度、返回值和电平,结合既有 FVAD 语音确认日志判断拾音与 VAD。
|
||||||
|
2. `VOICE-TX` 检查 START、音频、END 入队;`queue_fail` 和 `ring_drops` 应为零。
|
||||||
|
3. `WSS-IO` 检查实际写入是否失败,关闭时是否有接收字节和残留未消费数据。
|
||||||
|
4. `VOICE-RX` 检查 ACK、未知错误文本、被拒绝的回复或二进制数据。
|
||||||
|
5. `timeout-before-disconnect` 检查 `wait_ms`。`wait=2` 是等待回复,`wait=1` 是无语音,`wait=3` 是 END 入队失败。`response` 表示现有业务逻辑已接收可用音频 URL,不等同于收到任意文本或 TTS_START。
|
||||||
|
|
||||||
|
即使 TLS 写入成功,也不能证明服务器应用收到完整录音。若已经看到归属正确的 END_ACK,却没有后续 TTS,优先按 session 查服务端识别和生成链路;若没有 ACK,也需要结合服务端接收记录判断。设备单侧日志不能完全区分服务端未处理、网络中断和回复延迟。
|
||||||
|
|
||||||
|
本机验证:`python3 tools/test_voice_diag.py`、`python3 tools/test_conversation_timeout.py`、`python3 tools/test_wss_io.py`、`python3 tools/test_wss_receive.py`。诊断测试直接编译实际函数并注入录音、缓冲区、队列及收包结果;不替代目标固件构建及设备实测。
|
||||||
|
|
||||||
|
## GNSS 日志开关
|
||||||
|
|
||||||
|
`inc/app_gnss_log.h` 中的 `APP_GNSS_LOG_ENABLED` 默认是 `0`,关闭应用侧全部 GNSS/NMEA 原始输出、解析失败、模式切换、卫星搜索、坐标打印和 GPS 查询提示。需要恢复时可在编译参数中设置 `-DAPP_GNSS_LOG_ENABLED=1`。语音与 NITZ 时间校准诊断继续输出。
|
||||||
|
|
||||||
|
GNSS 数据解析、定位上报和硬件开关流程继续运行。原先放在打印参数内的四处 `ql_gnss_close()` 已分离为独立操作,避免禁用日志时跳过关闭定位。`python3 tools/test_gnss_logging.py` 在日志开启和关闭两种配置下验证真实解析代码、无卫星退出、卫星不足退出、搜索超时退出及 FAST 切换 SLOW 的关闭路径。
|
||||||
@@ -82,6 +82,7 @@ SRC_FILES+= \
|
|||||||
DP1312EA.c \
|
DP1312EA.c \
|
||||||
mqtt.c \
|
mqtt.c \
|
||||||
mqtt_connect_diag.c \
|
mqtt_connect_diag.c \
|
||||||
|
app_time_calibrate.c \
|
||||||
vad_det.c \
|
vad_det.c \
|
||||||
sleep_wake.c \
|
sleep_wake.c \
|
||||||
battery.c \
|
battery.c \
|
||||||
|
|||||||
@@ -0,0 +1,226 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include "ql_rtos.h"
|
||||||
|
#include "ql_func.h"
|
||||||
|
#include "ql_nw.h"
|
||||||
|
#include "ql_rtc.h"
|
||||||
|
#include "app_time_calibrate.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 *);
|
||||||
|
#define MIN_EPOCH 1704067200LL
|
||||||
|
#define MAX_EPOCH 2147483647LL
|
||||||
|
#define ATTEMPTS 3
|
||||||
|
|
||||||
|
static ql_task_t calibration_task;
|
||||||
|
static int calibration_started;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
time_t utc;
|
||||||
|
unsigned int ticks;
|
||||||
|
int zone_quarters;
|
||||||
|
} nitz_sample;
|
||||||
|
|
||||||
|
static int leap(int year)
|
||||||
|
{
|
||||||
|
return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Explicit Gregorian conversion: no mktime() or APP clock dependency. */
|
||||||
|
static int calendar_epoch(int year, int month, int day, int hour, int minute,
|
||||||
|
int second, long long *result)
|
||||||
|
{
|
||||||
|
static const int days[] = {31,28,31,30,31,30,31,31,30,31,30,31};
|
||||||
|
long long total = 0;
|
||||||
|
int y, m;
|
||||||
|
if (year < 1970 || year > 2038 || month < 1 || month > 12 ||
|
||||||
|
day < 1 || day > days[month - 1] + (month == 2 && leap(year)) ||
|
||||||
|
hour < 0 || hour > 23 || minute < 0 || minute > 59 ||
|
||||||
|
second < 0 || second > 59) return -1;
|
||||||
|
for (y = 1970; y < year; ++y) total += 365 + leap(y);
|
||||||
|
for (m = 1; m < month; ++m) total += days[m - 1] + (m == 2 && leap(year));
|
||||||
|
*result = ((total + day - 1) * 24 + hour) * 3600 + minute * 60 + second;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int two_digits(const char *s)
|
||||||
|
{
|
||||||
|
if (s[0] < '0' || s[0] > '9' || s[1] < '0' || s[1] > '9') return -1;
|
||||||
|
return (s[0] - '0') * 10 + s[1] - '0';
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 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, 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;
|
||||||
|
yy = two_digits(s); mo = two_digits(s + 3); dd = two_digits(s + 6);
|
||||||
|
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;
|
||||||
|
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 (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;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int get_sample(int attempt, int index, nitz_sample *sample)
|
||||||
|
{
|
||||||
|
QL_NW_NITZ_TIME_INFO_T info;
|
||||||
|
unsigned int began = ql_rtos_get_systicks();
|
||||||
|
int rc, parsed;
|
||||||
|
memset(&info, 0, sizeof(info));
|
||||||
|
rc = ql_nw_get_nitz_time_info(&info);
|
||||||
|
sample->ticks = ql_rtos_get_systicks();
|
||||||
|
printf("[APP-TIME] sample attempt=%d index=%d rc=%d raw=\"%.*s\" "
|
||||||
|
"abs_time=%lu leap_sec=%u query_ms=%lu\r\n", attempt, index, rc,
|
||||||
|
(int)sizeof(info.nitz_time), info.nitz_time, info.abs_time,
|
||||||
|
(unsigned int)info.leap_sec,
|
||||||
|
(unsigned long)(sample->ticks - began) * 5UL);
|
||||||
|
if (rc != QL_NW_SUCCESS ||
|
||||||
|
memchr(info.nitz_time, '\0', sizeof(info.nitz_time)) == NULL) return -1;
|
||||||
|
parsed = parse_nitz(info.nitz_time, &sample->utc, &sample->zone_quarters);
|
||||||
|
if (parsed != 0) {
|
||||||
|
printf("[APP-TIME] rejected stage=parse reason=%d\r\n", parsed);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
/* Bound query delay; this does not establish the age of a cached NITZ. */
|
||||||
|
if (sample->ticks - began > 400U) {
|
||||||
|
printf("[APP-TIME] rejected stage=slow_query rtc_not_written=1\r\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
printf("[APP-TIME] parsed utc=%ld zone_quarters=%d zone_minutes=%d\r\n",
|
||||||
|
(long)sample->utc, sample->zone_quarters, sample->zone_quarters * 15);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int write_and_verify(const nitz_sample *reference)
|
||||||
|
{
|
||||||
|
struct tm local;
|
||||||
|
ql_rtc_time_t target, actual;
|
||||||
|
time_t epoch, before = time(NULL), after;
|
||||||
|
long long expected, local_epoch, delta, actual_local = 0;
|
||||||
|
int rc, read_rc, calendar_ok;
|
||||||
|
expected = (long long)reference->utc +
|
||||||
|
(ql_rtos_get_systicks() - reference->ticks) / 200U;
|
||||||
|
if (expected > MAX_EPOCH) {
|
||||||
|
printf("[APP-TIME] FAIL stage=epoch_range\r\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
epoch = (time_t)expected;
|
||||||
|
memset(&local, 0, sizeof(local));
|
||||||
|
if (ql_localtime_r(&epoch, &local) == NULL ||
|
||||||
|
calendar_epoch(local.tm_year + 1900, local.tm_mon + 1, local.tm_mday,
|
||||||
|
local.tm_hour, local.tm_min, local.tm_sec, &local_epoch) != 0 ||
|
||||||
|
local_epoch < MIN_EPOCH || local_epoch > MAX_EPOCH ||
|
||||||
|
local_epoch - expected < -43200 || local_epoch - expected > 50400) {
|
||||||
|
printf("[APP-TIME] FAIL stage=local_calendar\r\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
memset(&target, 0, sizeof(target));
|
||||||
|
target.tm_year = local.tm_year + 1900;
|
||||||
|
target.tm_mon = local.tm_mon + 1;
|
||||||
|
target.tm_mday = local.tm_mday;
|
||||||
|
target.tm_hour = local.tm_hour;
|
||||||
|
target.tm_min = local.tm_min;
|
||||||
|
target.tm_sec = local.tm_sec;
|
||||||
|
target.tm_wday = local.tm_wday;
|
||||||
|
printf("[APP-TIME] set_begin app_before=%ld expected_utc=%ld "
|
||||||
|
"pmic_zone_minutes=%ld app_calendar=%04d-%02d-%02dT%02d:%02d:%02d\r\n",
|
||||||
|
(long)before, (long)epoch, (long)((local_epoch - expected) / 60),
|
||||||
|
target.tm_year, target.tm_mon, target.tm_mday,
|
||||||
|
target.tm_hour, target.tm_min, target.tm_sec);
|
||||||
|
rc = ql_rtc_set_time(&target);
|
||||||
|
memset(&actual, 0, sizeof(actual));
|
||||||
|
read_rc = ql_rtc_get_time(&actual);
|
||||||
|
after = time(NULL);
|
||||||
|
expected = (long long)reference->utc +
|
||||||
|
(ql_rtos_get_systicks() - reference->ticks) / 200U;
|
||||||
|
delta = (long long)after - expected;
|
||||||
|
calendar_ok = calendar_epoch(actual.tm_year, actual.tm_mon, actual.tm_mday,
|
||||||
|
actual.tm_hour, actual.tm_min, actual.tm_sec,
|
||||||
|
&actual_local) == 0;
|
||||||
|
actual_local -= local_epoch + (expected - (long long)epoch);
|
||||||
|
printf("[APP-TIME] readback set_rc=%d rtc_rc=%d app_after=%ld "
|
||||||
|
"expected_utc=%lld delta_s=%lld calendar=%04d-%02d-%02dT%02d:%02d:%02d\r\n",
|
||||||
|
rc, read_rc, (long)after, expected, delta, actual.tm_year, actual.tm_mon,
|
||||||
|
actual.tm_mday, actual.tm_hour, actual.tm_min, actual.tm_sec);
|
||||||
|
if (rc != 0 || read_rc != 0 || after < MIN_EPOCH ||
|
||||||
|
delta < -3 || delta > 3 || !calendar_ok ||
|
||||||
|
actual_local < -3 || actual_local > 3) {
|
||||||
|
printf("[APP-TIME] FAIL stage=app_clock_verification\r\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
printf("[APP-TIME] PASS source=nitz app_utc=verified "
|
||||||
|
"wss_requires_separate_handshake_check=1\r\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void time_calibrate_worker(void *arg)
|
||||||
|
{
|
||||||
|
nitz_sample sample;
|
||||||
|
int attempt;
|
||||||
|
(void)arg;
|
||||||
|
printf("[APP-TIME] begin version=1 source=operator_nitz ntp=off "
|
||||||
|
"policy=first_valid_after_pdp sys_probe=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")) {
|
||||||
|
printf("[APP-TIME] FAIL stage=sdk_api_unavailable\r\n");
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
/* Use the first valid operator snapshot promptly after
|
||||||
|
* PDP activation. A snapshot need not advance between API reads. Its actual
|
||||||
|
* network reception time is unknown; readback alone cannot establish age. */
|
||||||
|
for (attempt = 1; attempt <= ATTEMPTS; ++attempt) {
|
||||||
|
if (get_sample(attempt, 1, &sample) == 0) {
|
||||||
|
printf("[APP-TIME] snapshot_selected attempt=%d utc=%ld "
|
||||||
|
"age=unknown first_valid_after_pdp=1 max_rtc_writes=1\r\n",
|
||||||
|
attempt, (long)sample.utc);
|
||||||
|
write_and_verify(&sample);
|
||||||
|
goto done; /* No repeated write, even on setter/readback failure. */
|
||||||
|
}
|
||||||
|
if (attempt < ATTEMPTS) ql_rtos_task_sleep_ms(5000);
|
||||||
|
}
|
||||||
|
printf("[APP-TIME] FAIL stage=no_valid_nitz rtc_not_written=1\r\n");
|
||||||
|
done:
|
||||||
|
printf("[APP-TIME] finished once_per_boot=1\r\n");
|
||||||
|
ql_rtos_task_delete(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void app_time_calibrate_start(void)
|
||||||
|
{
|
||||||
|
int rc;
|
||||||
|
if (calibration_started) return; /* PDP management is the sole caller. */
|
||||||
|
calibration_started = 1;
|
||||||
|
rc = ql_rtos_task_create(&calibration_task, 6 * 1024, 110, "app_time_calibrate",
|
||||||
|
time_calibrate_worker, NULL);
|
||||||
|
if (rc != 0) {
|
||||||
|
calibration_started = 0;
|
||||||
|
printf("[APP-TIME] FAIL stage=create_task rc=%d\r\n", rc);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,6 +15,7 @@
|
|||||||
#include "sockets.h"
|
#include "sockets.h"
|
||||||
#include "netdb.h"
|
#include "netdb.h"
|
||||||
#include "app_inc.h"
|
#include "app_inc.h"
|
||||||
|
#include "app_gnss_log.h"
|
||||||
|
|
||||||
// 新增宏定义(原代码中未定义)
|
// 新增宏定义(原代码中未定义)
|
||||||
#define GNSS_FAST_MODE_HOLD_TIME (5 * 60 * 1000) // FAST模式持续5分钟后切SLOW
|
#define GNSS_FAST_MODE_HOLD_TIME (5 * 60 * 1000) // FAST模式持续5分钟后切SLOW
|
||||||
@@ -211,10 +212,7 @@ void quec_gnss_callback(char *data, int len)
|
|||||||
char nmea_buffer[512];
|
char nmea_buffer[512];
|
||||||
int fix_status = 0;
|
int fix_status = 0;
|
||||||
|
|
||||||
// 打印原始 NMEA 数据
|
APP_GNSS_LOG("%.*s", len, data);
|
||||||
for (i = 0; i < len; i++) {
|
|
||||||
printf("%c", data[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 在 data 中定位 GGA 句子的起止位置
|
// 在 data 中定位 GGA 句子的起止位置
|
||||||
// GGA 格式: $xxGGA,...,*CS\r\n
|
// GGA 格式: $xxGGA,...,*CS\r\n
|
||||||
@@ -267,7 +265,7 @@ void quec_gnss_callback(char *data, int len)
|
|||||||
g_gps_location.is_valid = (fix_status >= 1) ? 1 : 0;
|
g_gps_location.is_valid = (fix_status >= 1) ? 1 : 0;
|
||||||
} else {
|
} else {
|
||||||
g_gps_location.is_valid = 0;
|
g_gps_location.is_valid = 0;
|
||||||
printf("\n[GNSS Parse failed] FS=%d, %s\n",
|
APP_GNSS_LOG("\n[GNSS Parse failed] FS=%d, %s\n",
|
||||||
fix_status,
|
fix_status,
|
||||||
(fix_status == 0) ? "No Fix (Invalid)" : "Format error");
|
(fix_status == 0) ? "No Fix (Invalid)" : "Format error");
|
||||||
}
|
}
|
||||||
@@ -321,7 +319,7 @@ void quec_gnss_callback(char *data, int len)
|
|||||||
void set_gnss_mode(gnss_mode_t mode)
|
void set_gnss_mode(gnss_mode_t mode)
|
||||||
{
|
{
|
||||||
g_gnss_mode = mode;
|
g_gnss_mode = mode;
|
||||||
printf("[GNSSMode] Set to %s Mode\n",
|
APP_GNSS_LOG("[GNSSMode] Set to %s Mode\n",
|
||||||
(mode == GNSS_MODE_FAST) ? "Fast (30s)" : "Slow (5min)");
|
(mode == GNSS_MODE_FAST) ? "Fast (30s)" : "Slow (5min)");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -353,11 +351,11 @@ gps_location_info_t* get_gps_location_info(void)
|
|||||||
void print_gps_location_info(void)
|
void print_gps_location_info(void)
|
||||||
{
|
{
|
||||||
if (g_gps_location.is_valid) {
|
if (g_gps_location.is_valid) {
|
||||||
printf("[GPSinfo] Latitude: %.8f, Longitude: %.8f\n",
|
APP_GNSS_LOG("[GPSinfo] Latitude: %.8f, Longitude: %.8f\n",
|
||||||
g_gps_location.latitude, g_gps_location.longitude);
|
g_gps_location.latitude, g_gps_location.longitude);
|
||||||
printf("[GPSinfo] rawNMEA: %s\n", g_gps_location.raw_nmea);
|
APP_GNSS_LOG("[GPSinfo] rawNMEA: %s\n", g_gps_location.raw_nmea);
|
||||||
} else {
|
} else {
|
||||||
printf("[GPSinfo] No valid position data\n");
|
APP_GNSS_LOG("[GPSinfo] No valid position data\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -395,26 +393,29 @@ static void quec_gnss_test(void * argv)
|
|||||||
/* ========== FAST MODE ========== */
|
/* ========== FAST MODE ========== */
|
||||||
if (fast_mode_start_time == 0) {
|
if (fast_mode_start_time == 0) {
|
||||||
fast_mode_start_time = hal_os_up_time_ms();
|
fast_mode_start_time = hal_os_up_time_ms();
|
||||||
printf("[GNSS] Enter FAST mode\n");
|
APP_GNSS_LOG("[GNSS] Enter FAST mode\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!gnss_is_open) {
|
if (!gnss_is_open) {
|
||||||
gnss_is_open = 1;
|
gnss_is_open = 1;
|
||||||
app_set_app_operation(1);
|
app_set_app_operation(1);
|
||||||
ql_gnss_open(quec_gnss_callback);
|
ql_gnss_open(quec_gnss_callback);
|
||||||
printf("[GNSS] FAST: GPS OPEN\n");
|
APP_GNSS_LOG("[GNSS] FAST: GPS OPEN\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 5分钟超时切SLOW
|
// 5分钟超时切SLOW
|
||||||
if (hal_os_up_time_ms() - fast_mode_start_time >= GNSS_FAST_MODE_HOLD_TIME) {
|
if (hal_os_up_time_ms() - fast_mode_start_time >= GNSS_FAST_MODE_HOLD_TIME) {
|
||||||
printf("[GNSS] FAST 5min timeout -> SLOW\n");
|
APP_GNSS_LOG("[GNSS] FAST 5min timeout -> SLOW\n");
|
||||||
g_gnss_mode = GNSS_MODE_SLOW;
|
g_gnss_mode = GNSS_MODE_SLOW;
|
||||||
fast_mode_start_time = 0;
|
fast_mode_start_time = 0;
|
||||||
slow_mode_start_time = 0;
|
slow_mode_start_time = 0;
|
||||||
slow_next_wake_time = 0;
|
slow_next_wake_time = 0;
|
||||||
|
|
||||||
gnss_is_open = 0;
|
gnss_is_open = 0;
|
||||||
printf("[GNSS] SLOW: GPS CLOSED ret:%d\n", ql_gnss_close());
|
|
||||||
|
int close_ret = ql_gnss_close();
|
||||||
|
(void)close_ret;
|
||||||
|
APP_GNSS_LOG("[GNSS] SLOW: GPS CLOSED ret:%d\n", close_ret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -426,12 +427,12 @@ static void quec_gnss_test(void * argv)
|
|||||||
if (slow_mode_start_time == 0) {
|
if (slow_mode_start_time == 0) {
|
||||||
slow_mode_start_time = now;
|
slow_mode_start_time = now;
|
||||||
slow_next_wake_time = now; // 立即尝试第一次定位
|
slow_next_wake_time = now; // 立即尝试第一次定位
|
||||||
printf("[GNSS] Enter SLOW mode (fixed 15min interval)\n");
|
APP_GNSS_LOG("[GNSS] Enter SLOW mode (fixed 15min interval)\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查是否到达唤醒时间
|
// 检查是否到达唤醒时间
|
||||||
if (now < slow_next_wake_time) {
|
if (now < slow_next_wake_time) {
|
||||||
printf("[GNSS] SLOW: next wake in %d s\n",
|
APP_GNSS_LOG("[GNSS] SLOW: next wake in %d s\n",
|
||||||
(slow_next_wake_time - now) / 1000);
|
(slow_next_wake_time - now) / 1000);
|
||||||
}
|
}
|
||||||
else if (!gnss_is_open) {
|
else if (!gnss_is_open) {
|
||||||
@@ -444,7 +445,7 @@ static void quec_gnss_test(void * argv)
|
|||||||
app_set_app_operation(1);
|
app_set_app_operation(1);
|
||||||
ql_gnss_open(quec_gnss_callback);
|
ql_gnss_open(quec_gnss_callback);
|
||||||
|
|
||||||
printf("[GNSS] SLOW: GPS OPEN, search start\n");
|
APP_GNSS_LOG("[GNSS] SLOW: GPS OPEN, search start\n");
|
||||||
|
|
||||||
/* ---- 第一阶段:60秒卫星检测 ---- */
|
/* ---- 第一阶段:60秒卫星检测 ---- */
|
||||||
int sat_found = 0;
|
int sat_found = 0;
|
||||||
@@ -454,7 +455,7 @@ static void quec_gnss_test(void * argv)
|
|||||||
elapsed++;
|
elapsed++;
|
||||||
if (g_gnss_sat_count > 1) {
|
if (g_gnss_sat_count > 1) {
|
||||||
sat_found = 1;
|
sat_found = 1;
|
||||||
printf("[GNSS] SLOW: Sat found! count=%d, after %ds\n",
|
APP_GNSS_LOG("[GNSS] SLOW: Sat found! count=%d, after %ds\n",
|
||||||
g_gnss_sat_count, elapsed);
|
g_gnss_sat_count, elapsed);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -462,10 +463,13 @@ static void quec_gnss_test(void * argv)
|
|||||||
|
|
||||||
if (!sat_found) {
|
if (!sat_found) {
|
||||||
// 60秒无卫星 → 立即关闭,等待15分钟
|
// 60秒无卫星 → 立即关闭,等待15分钟
|
||||||
printf("[GNSS] SLOW: No satellite in 30s, stop ret:%d.\n", ql_gnss_close());
|
|
||||||
|
int close_ret = ql_gnss_close();
|
||||||
|
(void)close_ret;
|
||||||
|
APP_GNSS_LOG("[GNSS] SLOW: No satellite in 30s, stop ret:%d.\n", close_ret);
|
||||||
gnss_is_open = 0;
|
gnss_is_open = 0;
|
||||||
slow_next_wake_time = search_start_time + (GNSS_SEARCH_INTERVAL * 1000);
|
slow_next_wake_time = search_start_time + (GNSS_SEARCH_INTERVAL * 1000);
|
||||||
printf("[GNSS] SLOW: GPS CLOSED, next search at +%ds\n", GNSS_SEARCH_INTERVAL);
|
APP_GNSS_LOG("[GNSS] SLOW: GPS CLOSED, next search at +%ds\n", GNSS_SEARCH_INTERVAL);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -478,17 +482,20 @@ static void quec_gnss_test(void * argv)
|
|||||||
|
|
||||||
// 1.5分钟时刻检查卫星数
|
// 1.5分钟时刻检查卫星数
|
||||||
int sat_count_now = g_gnss_sat_count;
|
int sat_count_now = g_gnss_sat_count;
|
||||||
printf("[GNSS] SLOW: 1min check, satellite count = %d\n", sat_count_now);
|
APP_GNSS_LOG("[GNSS] SLOW: 1min check, satellite count = %d\n", sat_count_now);
|
||||||
if (sat_count_now < GNSS_SAT_MIN_COUNT) {
|
if (sat_count_now < GNSS_SAT_MIN_COUNT) {
|
||||||
printf("[GNSS] SLOW: Sat count < %d, stop search ret:%d.\n", GNSS_SAT_MIN_COUNT,ql_gnss_close());
|
|
||||||
|
int close_ret = ql_gnss_close();
|
||||||
|
(void)close_ret;
|
||||||
|
APP_GNSS_LOG("[GNSS] SLOW: Sat count < %d, stop search ret:%d.\n", GNSS_SAT_MIN_COUNT, close_ret);
|
||||||
gnss_is_open = 0;
|
gnss_is_open = 0;
|
||||||
slow_next_wake_time = search_start_time + (GNSS_SEARCH_INTERVAL * 1000);
|
slow_next_wake_time = search_start_time + (GNSS_SEARCH_INTERVAL * 1000);
|
||||||
printf("[GNSS] SLOW: GPS CLOSED, next search at +%ds\n", GNSS_SEARCH_INTERVAL);
|
APP_GNSS_LOG("[GNSS] SLOW: GPS CLOSED, next search at +%ds\n", GNSS_SEARCH_INTERVAL);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---- 第三阶段:卫星足够,继续定位,但总时间不超过3分钟 ---- */
|
/* ---- 第三阶段:卫星足够,继续定位,但总时间不超过3分钟 ---- */
|
||||||
printf("[GNSS] SLOW: Sat count OK, continue for fix (max %ds total)\n",
|
APP_GNSS_LOG("[GNSS] SLOW: Sat count OK, continue for fix (max %ds total)\n",
|
||||||
GNSS_MAX_SEARCH_TIME);
|
GNSS_MAX_SEARCH_TIME);
|
||||||
|
|
||||||
// 继续等待直到总时间达到 GNSS_MAX_SEARCH_TIME (180秒)
|
// 继续等待直到总时间达到 GNSS_MAX_SEARCH_TIME (180秒)
|
||||||
@@ -498,28 +505,30 @@ static void quec_gnss_test(void * argv)
|
|||||||
|
|
||||||
// 如果获得有效定位,打印提示(但继续等待至3分钟)
|
// 如果获得有效定位,打印提示(但继续等待至3分钟)
|
||||||
if (g_gps_location.is_valid) {
|
if (g_gps_location.is_valid) {
|
||||||
printf("[GNSS] SLOW: Fix obtained at %ds!\n", elapsed);
|
APP_GNSS_LOG("[GNSS] SLOW: Fix obtained at %ds!\n", elapsed);
|
||||||
print_gps_location_info();
|
print_gps_location_info();
|
||||||
// 若希望在定位成功后立即关闭,可在此 break,但此处按“最长3分钟”处理
|
// 若希望在定位成功后立即关闭,可在此 break,但此处按“最长3分钟”处理
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3分钟时间到,关闭GPS
|
// 3分钟时间到,关闭GPS
|
||||||
printf("[GNSS] SLOW: Max search time reached, stop.\n");
|
APP_GNSS_LOG("[GNSS] SLOW: Max search time reached, stop.\n");
|
||||||
if (g_gps_location.is_valid) {
|
if (g_gps_location.is_valid) {
|
||||||
printf("[GNSS] SLOW: Final valid position:\n");
|
APP_GNSS_LOG("[GNSS] SLOW: Final valid position:\n");
|
||||||
print_gps_location_info();
|
print_gps_location_info();
|
||||||
} else {
|
} else {
|
||||||
printf("[GNSS] SLOW: No valid fix within 3min.\n");
|
APP_GNSS_LOG("[GNSS] SLOW: No valid fix within 3min.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("[GNSS] SLOW: GPS CLOSED ret:%d",ql_gnss_close());
|
int close_ret = ql_gnss_close();
|
||||||
|
(void)close_ret;
|
||||||
|
APP_GNSS_LOG("[GNSS] SLOW: GPS CLOSED ret:%d", close_ret);
|
||||||
gnss_is_open = 0;
|
gnss_is_open = 0;
|
||||||
g_gps_location.is_valid = 0; // 重置状态
|
g_gps_location.is_valid = 0; // 重置状态
|
||||||
|
|
||||||
// 设置下次唤醒时间为 15分钟 后
|
// 设置下次唤醒时间为 15分钟 后
|
||||||
slow_next_wake_time = search_start_time + (GNSS_SEARCH_INTERVAL * 1000);
|
slow_next_wake_time = search_start_time + (GNSS_SEARCH_INTERVAL * 1000);
|
||||||
printf("[GNSS] SLOW: GPS CLOSED, next search at +%ds\n", GNSS_SEARCH_INTERVAL);
|
APP_GNSS_LOG("[GNSS] SLOW: GPS CLOSED, next search at +%ds\n", GNSS_SEARCH_INTERVAL);
|
||||||
}
|
}
|
||||||
// else: GPS正在运行中(理论上不会到这里)
|
// else: GPS正在运行中(理论上不会到这里)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
#ifndef APP_GNSS_LOG_H
|
||||||
|
#define APP_GNSS_LOG_H
|
||||||
|
|
||||||
|
/* GNSS diagnostics are quiet by default while investigating voice replies.
|
||||||
|
* Define APP_GNSS_LOG_ENABLED=1 at build time to restore application logs.
|
||||||
|
* Keep state changes and hardware operations outside log arguments. */
|
||||||
|
#ifndef APP_GNSS_LOG_ENABLED
|
||||||
|
#define APP_GNSS_LOG_ENABLED 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if APP_GNSS_LOG_ENABLED
|
||||||
|
#include <stdio.h>
|
||||||
|
#define APP_GNSS_LOG(...) printf(__VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define APP_GNSS_LOG(...) ((void)0)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
#ifndef APP_TIME_CALIBRATE_H
|
||||||
|
#define APP_TIME_CALIBRATE_H
|
||||||
|
|
||||||
|
void app_time_calibrate_start(void);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -96,6 +96,9 @@ typedef struct _rws_socket_struct
|
|||||||
int command;
|
int command;
|
||||||
|
|
||||||
unsigned int next_message_id;
|
unsigned int next_message_id;
|
||||||
|
/* Worker-owned transport counters; socket creation zero-initializes these. */
|
||||||
|
unsigned int diag_tx_calls, diag_tx_bytes, diag_tx_failed;
|
||||||
|
unsigned int diag_rx_calls, diag_rx_bytes;
|
||||||
|
|
||||||
rws_bool is_connected; // sock connected + handshake done
|
rws_bool is_connected; // sock connected + handshake done
|
||||||
|
|
||||||
|
|||||||
@@ -193,17 +193,30 @@ static int rws_tls_send_all(_rws_socket *s, const unsigned char *data, size_t si
|
|||||||
{
|
{
|
||||||
size_t sent = 0;
|
size_t sent = 0;
|
||||||
unsigned int started = ql_rtos_get_systicks();
|
unsigned int started = ql_rtos_get_systicks();
|
||||||
if (!s->ssl) return -1;
|
unsigned int retries = 0;
|
||||||
|
if (!s->ssl) {
|
||||||
|
printf("[WSS-IO] tls_write_no_context requested=%u\n", (unsigned int)size);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
while (sent < size) {
|
while (sent < size) {
|
||||||
int ret = mbedtls_ssl_write(&s->ssl->ssl_ctx, data + sent, size - sent);
|
int ret = mbedtls_ssl_write(&s->ssl->ssl_ctx, data + sent, size - sent);
|
||||||
if (ret > 0) {
|
if (ret > 0) {
|
||||||
sent += (size_t)ret;
|
sent += (size_t)ret;
|
||||||
} else if (ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE) {
|
} else if (ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE) {
|
||||||
|
printf("[WSS-IO] tls_write_failed ret=%d sent=%u requested=%u retries=%u elapsed_ticks=%u\n",
|
||||||
|
ret, (unsigned int)sent, (unsigned int)size, retries,
|
||||||
|
(unsigned int)(ql_rtos_get_systicks() - started));
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
|
retries++;
|
||||||
rws_thread_sleep(5);
|
rws_thread_sleep(5);
|
||||||
}
|
}
|
||||||
if (sent < size && (unsigned int)(ql_rtos_get_systicks() - started) >= 1000) return -1;
|
if (sent < size && (unsigned int)(ql_rtos_get_systicks() - started) >= 1000) {
|
||||||
|
printf("[WSS-IO] tls_write_timeout last_ret=%d sent=%u requested=%u retries=%u elapsed_ticks=%u\n",
|
||||||
|
ret, (unsigned int)sent, (unsigned int)size, retries,
|
||||||
|
(unsigned int)(ql_rtos_get_systicks() - started));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return (int)sent;
|
return (int)sent;
|
||||||
}
|
}
|
||||||
@@ -218,7 +231,6 @@ rws_bool rws_socket_send(_rws_socket *s, const void *data, const size_t data_siz
|
|||||||
#ifdef LIBRWS_USING_MBED_TLS
|
#ifdef LIBRWS_USING_MBED_TLS
|
||||||
if (s->scheme && strcmp(s->scheme, "wss") == 0)
|
if (s->scheme && strcmp(s->scheme, "wss") == 0)
|
||||||
{
|
{
|
||||||
LOG_D("[T:%.8d, L:%.5d, %*.*s] try send data with tls", ql_rtos_get_systicks(), __LINE__, DBG_FUNCTION_NUM, DBG_FUNCTION_NUM, __FUNCTION__);
|
|
||||||
sended = rws_tls_send_all(s, (const unsigned char *)data, data_size);
|
sended = rws_tls_send_all(s, (const unsigned char *)data, data_size);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -243,6 +255,14 @@ rws_bool rws_socket_send(_rws_socket *s, const void *data, const size_t data_siz
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
s->diag_tx_calls++;
|
||||||
|
if (sended > 0) s->diag_tx_bytes += (unsigned int)sended;
|
||||||
|
if (sended != (int)data_size) s->diag_tx_failed++;
|
||||||
|
if (s->diag_tx_calls == 1 || s->diag_tx_calls % 50 == 0 || sended != (int)data_size) {
|
||||||
|
printf("[WSS-IO] write tick=%u requested=%u ret=%d calls=%u bytes=%u failed=%u\n",
|
||||||
|
ql_rtos_get_systicks(), (unsigned int)data_size, sended,
|
||||||
|
s->diag_tx_calls, s->diag_tx_bytes, s->diag_tx_failed);
|
||||||
|
}
|
||||||
if (sended == (int)data_size)
|
if (sended == (int)data_size)
|
||||||
{
|
{
|
||||||
rws_socket_error_cnt = 0;
|
rws_socket_error_cnt = 0;
|
||||||
@@ -283,7 +303,6 @@ rws_bool rws_socket_recv(_rws_socket *s)
|
|||||||
rws_bool result = rws_true;
|
rws_bool result = rws_true;
|
||||||
int is_reading = 1, error_number = -1, len = -1;
|
int is_reading = 1, error_number = -1, len = -1;
|
||||||
char *received = NULL;
|
char *received = NULL;
|
||||||
size_t total_len = 0;
|
|
||||||
// char *buff = 0;
|
// char *buff = 0;
|
||||||
|
|
||||||
// LOG_D("[T:%.8d, L:%.5d, %*.*s] receive data", ql_rtos_get_systicks(), __LINE__, DBG_FUNCTION_NUM, DBG_FUNCTION_NUM, __FUNCTION__);
|
// LOG_D("[T:%.8d, L:%.5d, %*.*s] receive data", ql_rtos_get_systicks(), __LINE__, DBG_FUNCTION_NUM, DBG_FUNCTION_NUM, __FUNCTION__);
|
||||||
@@ -365,7 +384,12 @@ rws_bool rws_socket_recv(_rws_socket *s)
|
|||||||
|
|
||||||
if (len > 0)
|
if (len > 0)
|
||||||
{
|
{
|
||||||
total_len += len;
|
s->diag_rx_calls++;
|
||||||
|
s->diag_rx_bytes += (unsigned int)len;
|
||||||
|
if (s->diag_rx_calls <= 20 || s->diag_rx_calls % 50 == 0)
|
||||||
|
printf("[WSS-IO] read tick=%u bytes=%d calls=%u total=%u buffered=%u command=%d\n",
|
||||||
|
ql_rtos_get_systicks(), len, s->diag_rx_calls, s->diag_rx_bytes,
|
||||||
|
(unsigned int)s->received_len, s->command);
|
||||||
if (s->command == COMMAND_WAIT_HANDSHAKE_RESPONCE &&
|
if (s->command == COMMAND_WAIT_HANDSHAKE_RESPONCE &&
|
||||||
s->received_len + (size_t)len > RWS_HANDSHAKE_MAX + RWS_RECEIVE_BUFF_SIZE) {
|
s->received_len + (size_t)len > RWS_HANDSHAKE_MAX + RWS_RECEIVE_BUFF_SIZE) {
|
||||||
s->error = rws_error_new_code_descr(rws_error_code_parse_handshake, "WebSocket headers too large");
|
s->error = rws_error_new_code_descr(rws_error_code_parse_handshake, "WebSocket headers too large");
|
||||||
@@ -1650,9 +1674,12 @@ void rws_socket_resize_received(_rws_socket *s, const size_t size)
|
|||||||
|
|
||||||
void rws_socket_close(_rws_socket *s)
|
void rws_socket_close(_rws_socket *s)
|
||||||
{
|
{
|
||||||
s->received_len = 0;
|
|
||||||
if (s->socket != RWS_INVALID_SOCKET)
|
if (s->socket != RWS_INVALID_SOCKET)
|
||||||
{
|
{
|
||||||
|
printf("[WSS-IO] close tick=%u tx_calls=%u tx_bytes=%u tx_failed=%u rx_calls=%u rx_bytes=%u buffered=%u command=%d\n",
|
||||||
|
ql_rtos_get_systicks(), s->diag_tx_calls, s->diag_tx_bytes,
|
||||||
|
s->diag_tx_failed, s->diag_rx_calls, s->diag_rx_bytes,
|
||||||
|
(unsigned int)s->received_len, s->command);
|
||||||
#ifdef LIBRWS_USING_MBED_TLS
|
#ifdef LIBRWS_USING_MBED_TLS
|
||||||
if (s->scheme && strcmp(s->scheme, "wss") == 0)
|
if (s->scheme && strcmp(s->scheme, "wss") == 0)
|
||||||
{
|
{
|
||||||
@@ -1669,6 +1696,7 @@ void rws_socket_close(_rws_socket *s)
|
|||||||
WSACleanup();
|
WSACleanup();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
s->received_len = 0;
|
||||||
s->is_connected = rws_false;
|
s->is_connected = rws_false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#include "ql_application.h"
|
#include "ql_application.h"
|
||||||
#include "sockets.h"
|
#include "sockets.h"
|
||||||
#include "app_inc.h"
|
#include "app_inc.h"
|
||||||
|
#include "app_gnss_log.h"
|
||||||
#include "cjson.h"
|
#include "cjson.h"
|
||||||
#include "ql_fs.h"
|
#include "ql_fs.h"
|
||||||
#include "ql_fota.h"
|
#include "ql_fota.h"
|
||||||
@@ -442,7 +443,7 @@ int parse_command(const char *json_str, command_t *cmd)
|
|||||||
if (params != NULL) {
|
if (params != NULL) {
|
||||||
switch (cmd->type) {
|
switch (cmd->type) {
|
||||||
case MSG_GPS_QUERY:
|
case MSG_GPS_QUERY:
|
||||||
printf("MSG_GPS_QUERY\r\n");
|
APP_GNSS_LOG("MSG_GPS_QUERY\r\n");
|
||||||
/*返回当前的GPS坐标信息*/
|
/*返回当前的GPS坐标信息*/
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
#include "ql_atcmd.h"
|
#include "ql_atcmd.h"
|
||||||
#include "http_downfile.h"
|
#include "http_downfile.h"
|
||||||
#include "ota_post_update.h"
|
#include "ota_post_update.h"
|
||||||
|
#include "app_time_calibrate.h"
|
||||||
|
|
||||||
//#define NTP_SERVER_DOMAIN "ntp.aliyun.com"
|
//#define NTP_SERVER_DOMAIN "ntp.aliyun.com"
|
||||||
|
|
||||||
@@ -141,6 +142,7 @@ void ql_datacall_demo_thread(void *arvg)
|
|||||||
|
|
||||||
if(ret == 0)
|
if(ret == 0)
|
||||||
{
|
{
|
||||||
|
app_time_calibrate_start();
|
||||||
ql_get_data_call_info(1, 0, &info);
|
ql_get_data_call_info(1, 0, &info);
|
||||||
printf("info.profile_idx: %d\r\n", info.profile_idx);
|
printf("info.profile_idx: %d\r\n", info.profile_idx);
|
||||||
printf("info.ip_version: %d\r\n", info.ip_version);
|
printf("info.ip_version: %d\r\n", info.ip_version);
|
||||||
|
|||||||
@@ -71,6 +71,55 @@ static int vad_tts_playback_finished_status = 0;
|
|||||||
// 统计
|
// 统计
|
||||||
static uint32 frame_count = 0;
|
static uint32 frame_count = 0;
|
||||||
static uint32 speech_frame_count = 0;
|
static uint32 speech_frame_count = 0;
|
||||||
|
static struct {
|
||||||
|
unsigned int reads, short_reads, read_errors, zero_frames, samples, peak;
|
||||||
|
unsigned int ring_drops, ring_drop_bytes;
|
||||||
|
uint64_t abs_sum, last_log_ms, started_ms;
|
||||||
|
} mic_diag;
|
||||||
|
|
||||||
|
static void mic_diag_log(const char *stage)
|
||||||
|
{
|
||||||
|
printf("[MIC-DIAG] %s uptime_ms=%u age_ms=%u reads=%u short=%u read_errors=%u zero=%u peak=%u mean_abs=%u ring_drops=%u ring_drop_bytes=%u\n",
|
||||||
|
stage, (unsigned int)hal_os_up_time_ms(),
|
||||||
|
(unsigned int)(hal_os_up_time_ms() - mic_diag.started_ms),
|
||||||
|
mic_diag.reads, mic_diag.short_reads, mic_diag.read_errors, mic_diag.zero_frames,
|
||||||
|
mic_diag.peak, mic_diag.samples ? (unsigned int)(mic_diag.abs_sum / mic_diag.samples) : 0,
|
||||||
|
mic_diag.ring_drops, mic_diag.ring_drop_bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Observe both preroll and live PCM writes; retain the caller's wakeup policy. */
|
||||||
|
static int mic_diag_write(const void *data, int len)
|
||||||
|
{
|
||||||
|
int written = hal_os_rb_write(ring_sender, data, len, 25);
|
||||||
|
if (written < len) {
|
||||||
|
mic_diag.ring_drops++;
|
||||||
|
mic_diag.ring_drop_bytes += (unsigned int)(len - (written > 0 ? written : 0));
|
||||||
|
}
|
||||||
|
return written;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void mic_diag_read(const uint8_t *data, int len, int ret)
|
||||||
|
{
|
||||||
|
int i, bounded = len > VAD_FRAME_BYTES ? VAD_FRAME_BYTES : len;
|
||||||
|
unsigned int peak = 0;
|
||||||
|
mic_diag.reads++;
|
||||||
|
if (ret < 0) mic_diag.read_errors++;
|
||||||
|
if (len != VAD_FRAME_BYTES) mic_diag.short_reads++;
|
||||||
|
for (i = 0; i + 1 < bounded; i += 2) {
|
||||||
|
int sample = (int16_t)((unsigned int)data[i] | ((unsigned int)data[i + 1] << 8));
|
||||||
|
unsigned int magnitude = (unsigned int)(sample < 0 ? -sample : sample);
|
||||||
|
if (magnitude > peak) peak = magnitude;
|
||||||
|
mic_diag.abs_sum += magnitude;
|
||||||
|
mic_diag.samples++;
|
||||||
|
}
|
||||||
|
if (bounded > 0 && peak == 0) mic_diag.zero_frames++;
|
||||||
|
if (peak > mic_diag.peak) mic_diag.peak = peak;
|
||||||
|
if (mic_diag.reads == 1 || hal_os_up_time_ms() - mic_diag.last_log_ms >= 1000) {
|
||||||
|
printf("[MIC-DIAG] read ret=%d bytes=%d frame_peak=%u state=%d\n", ret, len, peak, g_state);
|
||||||
|
mic_diag_log("sampling");
|
||||||
|
mic_diag.last_log_ms = hal_os_up_time_ms();
|
||||||
|
}
|
||||||
|
}
|
||||||
extern int audio_packet_type;
|
extern int audio_packet_type;
|
||||||
|
|
||||||
|
|
||||||
@@ -84,7 +133,17 @@ static audio_record_handle record_hd;
|
|||||||
|
|
||||||
static void ql_audio_record_callback(acm_audio_track_handle handle, acm_audio_record_event_t event)
|
static void ql_audio_record_callback(acm_audio_track_handle handle, acm_audio_record_event_t event)
|
||||||
{
|
{
|
||||||
//printf("audio_record_callback event:%d\r\n", event);
|
static int last_event = -1;
|
||||||
|
static uint64_t last_log_ms;
|
||||||
|
uint64_t now;
|
||||||
|
(void)handle;
|
||||||
|
if (event == AUDIO_RECORD_EVENT_TICK || event == AUDIO_RECORD_EVENT_NONE) return;
|
||||||
|
now = hal_os_up_time_ms();
|
||||||
|
if ((int)event != last_event || now - last_log_ms >= 1000) {
|
||||||
|
printf("[MIC-DIAG] callback event=%d uptime_ms=%u\n", event, (unsigned int)now);
|
||||||
|
last_event = (int)event;
|
||||||
|
last_log_ms = now;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void vad_tts_playback_finished()
|
void vad_tts_playback_finished()
|
||||||
@@ -206,7 +265,13 @@ int vad_audio_init(void) {
|
|||||||
|
|
||||||
// 启动录音
|
// 启动录音
|
||||||
int vad_audio_start(void) {
|
int vad_audio_start(void) {
|
||||||
vad_audio_init();
|
memset(&mic_diag, 0, sizeof(mic_diag));
|
||||||
|
mic_diag.started_ms = hal_os_up_time_ms();
|
||||||
|
{
|
||||||
|
int init_ret = vad_audio_init();
|
||||||
|
printf("[MIC-DIAG] open ret=%d handle=%u uptime_ms=%u\n",
|
||||||
|
init_ret, (unsigned int)record_hd, (unsigned int)hal_os_up_time_ms());
|
||||||
|
}
|
||||||
|
|
||||||
frame_count = 0;
|
frame_count = 0;
|
||||||
speech_frame_count = 0;
|
speech_frame_count = 0;
|
||||||
@@ -217,6 +282,7 @@ int vad_audio_start(void) {
|
|||||||
|
|
||||||
// 停止录音
|
// 停止录音
|
||||||
int vad_audio_stop(void) {
|
int vad_audio_stop(void) {
|
||||||
|
mic_diag_log("stop");
|
||||||
|
|
||||||
printf("Audio recording stopped, frames: %d, speech: %d",
|
printf("Audio recording stopped, frames: %d, speech: %d",
|
||||||
frame_count, speech_frame_count);
|
frame_count, speech_frame_count);
|
||||||
@@ -235,6 +301,7 @@ int vad_audio_stop(void) {
|
|||||||
|
|
||||||
// 停止录音
|
// 停止录音
|
||||||
int vad_audio_stop_no_wait_resp(void) {
|
int vad_audio_stop_no_wait_resp(void) {
|
||||||
|
mic_diag_log("cancel");
|
||||||
conversation_cancel_wait();
|
conversation_cancel_wait();
|
||||||
|
|
||||||
printf("Audio recording stopped no_wait_resp, frames: %d, speech: %d",
|
printf("Audio recording stopped no_wait_resp, frames: %d, speech: %d",
|
||||||
@@ -381,7 +448,10 @@ void vad_audio_process(void) {
|
|||||||
case STATE_RECORDING_ACTIVE:
|
case STATE_RECORDING_ACTIVE:
|
||||||
memset(mic_buf, 0, sizeof(mic_buf));
|
memset(mic_buf, 0, sizeof(mic_buf));
|
||||||
//每次读取640字节音频数据
|
//每次读取640字节音频数据
|
||||||
ql_audio_record_read(record_hd, mic_buf, &record_len);
|
{
|
||||||
|
int read_ret = ql_audio_record_read(record_hd, mic_buf, &record_len);
|
||||||
|
mic_diag_read(mic_buf, record_len, read_ret);
|
||||||
|
}
|
||||||
|
|
||||||
if (g_state == STATE_RECORDING_WAIT_SOUND) {
|
if (g_state == STATE_RECORDING_WAIT_SOUND) {
|
||||||
/* 首次开口确认前不向服务端发送静音。只在本地保留最近500ms,
|
/* 首次开口确认前不向服务端发送静音。只在本地保留最近500ms,
|
||||||
@@ -392,7 +462,7 @@ void vad_audio_process(void) {
|
|||||||
vad_preroll_count++;
|
vad_preroll_count++;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(hal_os_rb_write(ring_sender, (uint8*)mic_buf, record_len, 25)>0){
|
if(mic_diag_write(mic_buf, record_len)>0){
|
||||||
ql_rtos_semaphore_release(sender_sem);
|
ql_rtos_semaphore_release(sender_sem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -437,7 +507,7 @@ void vad_audio_process(void) {
|
|||||||
int preroll_queued = 0;
|
int preroll_queued = 0;
|
||||||
for (n = 0; n < vad_preroll_count; n++) {
|
for (n = 0; n < vad_preroll_count; n++) {
|
||||||
size_t frame_index = (first + n) % VAD_PREROLL_FRAMES;
|
size_t frame_index = (first + n) % VAD_PREROLL_FRAMES;
|
||||||
if (hal_os_rb_write(ring_sender, vad_preroll[frame_index], VAD_FRAME_BYTES, 25) > 0) {
|
if (mic_diag_write(vad_preroll[frame_index], VAD_FRAME_BYTES) > 0) {
|
||||||
preroll_queued = 1;
|
preroll_queued = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,6 +62,12 @@ enum { WAIT_NONE, WAIT_NO_SPEECH, WAIT_REPLY, WAIT_SEND_FAILURE };
|
|||||||
static int conversation_wait = WAIT_NONE;
|
static int conversation_wait = WAIT_NONE;
|
||||||
static int timeout_action_busy = 0;
|
static int timeout_action_busy = 0;
|
||||||
static int round_response_received = 0;
|
static int round_response_received = 0;
|
||||||
|
/* Queue admission is distinct from a completed TLS write and from server ACK. */
|
||||||
|
static struct {
|
||||||
|
unsigned int tx_packets, tx_bytes, tx_failed, rx_text, rx_bin;
|
||||||
|
unsigned int start_ack, end_ack;
|
||||||
|
uint64_t started_ms, last_rx_ms;
|
||||||
|
} voice_diag;
|
||||||
static unsigned int active_session_round = 0;
|
static unsigned int active_session_round = 0;
|
||||||
static int active_session_valid = 0;
|
static int active_session_valid = 0;
|
||||||
static uint64_t startup_start_ms = 0;
|
static uint64_t startup_start_ms = 0;
|
||||||
@@ -87,6 +93,10 @@ static void conversation_unlock(void)
|
|||||||
static void conversation_begin_round(void)
|
static void conversation_begin_round(void)
|
||||||
{
|
{
|
||||||
conversation_round++;
|
conversation_round++;
|
||||||
|
memset(&voice_diag, 0, sizeof(voice_diag));
|
||||||
|
voice_diag.started_ms = hal_os_up_time_ms();
|
||||||
|
printf("[VOICE-DIAG] begin round=%u uptime_ms=%u\n",
|
||||||
|
conversation_round, (unsigned int)voice_diag.started_ms);
|
||||||
conversation_wait = WAIT_NONE;
|
conversation_wait = WAIT_NONE;
|
||||||
round_response_received = 0;
|
round_response_received = 0;
|
||||||
active_session_valid = 0;
|
active_session_valid = 0;
|
||||||
@@ -217,6 +227,20 @@ unsigned char get_xiaoice_connected_status(void)
|
|||||||
return xiaoice_wss_connect_status;
|
return xiaoice_wss_connect_status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Called with conversation_mutex held. Ages use monotonic milliseconds. */
|
||||||
|
static void voice_diag_snapshot(const char *stage)
|
||||||
|
{
|
||||||
|
uint64_t now = hal_os_up_time_ms();
|
||||||
|
printf("[VOICE-DIAG] %s round=%u session=%s age_ms=%u queue_pkts=%u queue_bytes=%u queue_fail=%u rx_text=%u rx_bin=%u start_ack=%u end_ack=%u last_rx_age_ms=%d wait=%d wait_ms=%u response=%d\n",
|
||||||
|
stage, conversation_round, active_session_valid ? sessionId : "none",
|
||||||
|
(unsigned int)(now - voice_diag.started_ms), voice_diag.tx_packets,
|
||||||
|
voice_diag.tx_bytes, voice_diag.tx_failed, voice_diag.rx_text,
|
||||||
|
voice_diag.rx_bin, voice_diag.start_ack, voice_diag.end_ack,
|
||||||
|
voice_diag.rx_text || voice_diag.rx_bin ? (int)(now - voice_diag.last_rx_ms) : -1,
|
||||||
|
conversation_wait, conversation_wait == WAIT_REPLY ?
|
||||||
|
(unsigned int)(now - reply_wait_start_ms) : 0, round_response_received);
|
||||||
|
}
|
||||||
|
|
||||||
static void onopen(rws_socket socket)
|
static void onopen(rws_socket socket)
|
||||||
{
|
{
|
||||||
if (socket != app->socket || !app->init) return;
|
if (socket != app->socket || !app->init) return;
|
||||||
@@ -245,6 +269,9 @@ static void onclose(rws_socket socket)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (socket != app->socket) return;
|
if (socket != app->socket) return;
|
||||||
|
conversation_lock();
|
||||||
|
voice_diag_snapshot("disconnected");
|
||||||
|
conversation_unlock();
|
||||||
xiaoice_wss_connect_status = 0;
|
xiaoice_wss_connect_status = 0;
|
||||||
app->socket = NULL;
|
app->socket = NULL;
|
||||||
/* The worker owns and releases this socket after the callback. */
|
/* The worker owns and releases this socket after the callback. */
|
||||||
@@ -649,6 +676,16 @@ static void conversation_log_error_message(const char *text, unsigned int len)
|
|||||||
static void onmessage_text(rws_socket socket, const char *text, const unsigned int len)
|
static void onmessage_text(rws_socket socket, const char *text, const unsigned int len)
|
||||||
{
|
{
|
||||||
conversation_lock();
|
conversation_lock();
|
||||||
|
voice_diag.rx_text++;
|
||||||
|
voice_diag.last_rx_ms = hal_os_up_time_ms();
|
||||||
|
if (strstr(text, "START_ACK")) voice_diag.start_ack++;
|
||||||
|
if (strstr(text, "END_ACK")) voice_diag.end_ack++;
|
||||||
|
/* Bounded preview includes unrecognized replies and ACKs before filtering. */
|
||||||
|
printf("[VOICE-RX] round=%u session=%s uptime_ms=%u len=%u accepted=%d preview=%.*s%s\n",
|
||||||
|
conversation_round, active_session_valid ? sessionId : "none",
|
||||||
|
(unsigned int)voice_diag.last_rx_ms, len,
|
||||||
|
conversation_accept_voice_message(text), (int)(len > 192 ? 192 : len), text,
|
||||||
|
len > 192 ? " [truncated]" : "");
|
||||||
if (strstr(text, "tts_error") != NULL || strstr(text, "tts_err") != NULL ||
|
if (strstr(text, "tts_error") != NULL || strstr(text, "tts_err") != NULL ||
|
||||||
strstr(text, "PROMPT_SOUND_URL") != NULL) {
|
strstr(text, "PROMPT_SOUND_URL") != NULL) {
|
||||||
conversation_log_error_message(text, len);
|
conversation_log_error_message(text, len);
|
||||||
@@ -664,7 +701,15 @@ static void onmessage_text(rws_socket socket, const char *text, const unsigned i
|
|||||||
|
|
||||||
static void onmessage_bin(rws_socket socket, const void * data, const unsigned int len)
|
static void onmessage_bin(rws_socket socket, const void * data, const unsigned int len)
|
||||||
{
|
{
|
||||||
LOG_D("message(bin): %d ", len);
|
(void)socket;
|
||||||
|
(void)data;
|
||||||
|
conversation_lock();
|
||||||
|
voice_diag.rx_bin++;
|
||||||
|
voice_diag.last_rx_ms = hal_os_up_time_ms();
|
||||||
|
if (voice_diag.rx_bin == 1 || voice_diag.rx_bin % 50 == 0)
|
||||||
|
printf("[VOICE-RX] binary round=%u len=%u count=%u ignored=1\n",
|
||||||
|
conversation_round, len, voice_diag.rx_bin);
|
||||||
|
conversation_unlock();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -811,7 +856,11 @@ int talkingq_ws_send_text(char *senddata)
|
|||||||
|
|
||||||
LOG_D("talkingq_wss_send_text string = %s, len = %d", senddata, strlen(senddata));
|
LOG_D("talkingq_wss_send_text string = %s, len = %d", senddata, strlen(senddata));
|
||||||
|
|
||||||
rws_socket_send_text(app->socket, senddata);
|
{
|
||||||
|
int queued = rws_socket_send_text(app->socket, senddata);
|
||||||
|
printf("[VOICE-TX] auth/text queue uptime_ms=%u bytes=%u accepted=%d\n",
|
||||||
|
(unsigned int)hal_os_up_time_ms(), (unsigned int)strlen(senddata), queued != 0);
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -1041,6 +1090,7 @@ void sendStartPacket(void) {
|
|||||||
startPacket.dataSize = 0;
|
startPacket.dataSize = 0;
|
||||||
|
|
||||||
active_session_valid = sendRecordingAudioPacket(&startPacket) == 0;
|
active_session_valid = sendRecordingAudioPacket(&startPacket) == 0;
|
||||||
|
voice_diag_snapshot("start-queued");
|
||||||
conversation_unlock();
|
conversation_unlock();
|
||||||
// rt_kprintf("sendStartPacket, seq=%u\r\n", startPacket.sequenceNumber);
|
// rt_kprintf("sendStartPacket, seq=%u\r\n", startPacket.sequenceNumber);
|
||||||
}
|
}
|
||||||
@@ -1059,6 +1109,7 @@ void sendEndPacket(void) {
|
|||||||
reply_wait_start_ms = hal_os_up_time_ms();
|
reply_wait_start_ms = hal_os_up_time_ms();
|
||||||
conversation_wait = end_ret == 0 ? WAIT_REPLY : WAIT_SEND_FAILURE;
|
conversation_wait = end_ret == 0 ? WAIT_REPLY : WAIT_SEND_FAILURE;
|
||||||
}
|
}
|
||||||
|
voice_diag_snapshot("end-queued");
|
||||||
}
|
}
|
||||||
conversation_unlock();
|
conversation_unlock();
|
||||||
// rt_kprintf("sendEndPacket, seq=%u\r\n", endPacket.sequenceNumber);
|
// rt_kprintf("sendEndPacket, seq=%u\r\n", endPacket.sequenceNumber);
|
||||||
@@ -1074,12 +1125,19 @@ void sendAudioPacket(const uint8_t* data, size_t dataSize) {
|
|||||||
audioPacket.data = malloc(audioPacket.dataSize);
|
audioPacket.data = malloc(audioPacket.dataSize);
|
||||||
if(audioPacket.data==NULL){
|
if(audioPacket.data==NULL){
|
||||||
RLOGE("audioPacket.data NULL");
|
RLOGE("audioPacket.data NULL");
|
||||||
|
conversation_lock();
|
||||||
|
voice_diag.tx_failed++;
|
||||||
|
printf("[VOICE-TX] alloc_failed round=%u seq=%u bytes=%u\n",
|
||||||
|
conversation_round, audioPacket.sequenceNumber, (unsigned int)dataSize);
|
||||||
|
conversation_unlock();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
memcpy(audioPacket.data, data, dataSize);
|
memcpy(audioPacket.data, data, dataSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
conversation_lock();
|
||||||
sendRecordingAudioPacket(&audioPacket);
|
sendRecordingAudioPacket(&audioPacket);
|
||||||
|
conversation_unlock();
|
||||||
// rt_kprintf("sendAudioPacket, seq=%u\r\n", audioPacket.sequenceNumber);
|
// rt_kprintf("sendAudioPacket, seq=%u\r\n", audioPacket.sequenceNumber);
|
||||||
if(audioPacket.data){
|
if(audioPacket.data){
|
||||||
free(audioPacket.data);
|
free(audioPacket.data);
|
||||||
@@ -1092,7 +1150,9 @@ void sendInterruptPacket(void) {
|
|||||||
interruptPacket.packetType = 3;
|
interruptPacket.packetType = 3;
|
||||||
interruptPacket.dataSize = 0;
|
interruptPacket.dataSize = 0;
|
||||||
|
|
||||||
|
conversation_lock();
|
||||||
sendRecordingAudioPacket(&interruptPacket);
|
sendRecordingAudioPacket(&interruptPacket);
|
||||||
|
conversation_unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendAuthentication()
|
void sendAuthentication()
|
||||||
@@ -1122,6 +1182,9 @@ int sendRecordingAudioPacket(AudioPacket *packet) {
|
|||||||
sendBuffer = malloc(DEVICE_ID_SIZE + SESSION_ID_SIZE + sizeof(uint32_t) * 2 + sizeof(uint32_t) + packet->dataSize);
|
sendBuffer = malloc(DEVICE_ID_SIZE + SESSION_ID_SIZE + sizeof(uint32_t) * 2 + sizeof(uint32_t) + packet->dataSize);
|
||||||
if(sendBuffer==NULL){
|
if(sendBuffer==NULL){
|
||||||
RLOGE("sendBuffer NULL");
|
RLOGE("sendBuffer NULL");
|
||||||
|
voice_diag.tx_failed++;
|
||||||
|
printf("[VOICE-TX] alloc_failed seq=%u type=%u bytes=%u\n",
|
||||||
|
packet->sequenceNumber, packet->packetType, (unsigned int)packet->dataSize);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1151,7 +1214,21 @@ int sendRecordingAudioPacket(AudioPacket *packet) {
|
|||||||
// memcpy(recorder->save_buf, (void *)sendBuffer, recorder->save_len);
|
// memcpy(recorder->save_buf, (void *)sendBuffer, recorder->save_len);
|
||||||
//record_msg_send(recorder, RECORD_MSG_DATA, recorder->save_len);
|
//record_msg_send(recorder, RECORD_MSG_DATA, recorder->save_len);
|
||||||
|
|
||||||
|
uint64_t queue_started = hal_os_up_time_ms();
|
||||||
int send_ret = talkingq_ws_send_bin((uint8_t*)sendBuffer, totalSize);
|
int send_ret = talkingq_ws_send_bin((uint8_t*)sendBuffer, totalSize);
|
||||||
|
if (send_ret == 0) {
|
||||||
|
voice_diag.tx_packets++;
|
||||||
|
voice_diag.tx_bytes += (unsigned int)packet->dataSize;
|
||||||
|
} else {
|
||||||
|
voice_diag.tx_failed++;
|
||||||
|
}
|
||||||
|
if (packet->packetType == 1 || packet->packetType == 2 || send_ret != 0 ||
|
||||||
|
voice_diag.tx_packets % 50 == 0) {
|
||||||
|
printf("[VOICE-TX] queue round=%u session=%s seq=%u type=%u bytes=%u ret=%d elapsed_ms=%u\n",
|
||||||
|
conversation_round, sessionId, packet->sequenceNumber, packet->packetType,
|
||||||
|
(unsigned int)packet->dataSize, send_ret,
|
||||||
|
(unsigned int)(hal_os_up_time_ms() - queue_started));
|
||||||
|
}
|
||||||
free(sendBuffer);
|
free(sendBuffer);
|
||||||
return send_ret;
|
return send_ret;
|
||||||
// rt_kprintf("sendRecordingAudioPacket - Device ID: %s, Session ID: %s\n", deviceId, sessionId);
|
// rt_kprintf("sendRecordingAudioPacket - Device ID: %s, Session ID: %s\n", deviceId, sessionId);
|
||||||
@@ -1493,6 +1570,7 @@ static void conversation_check_timeout(void)
|
|||||||
(conversation_wait == WAIT_NO_SPEECH ||
|
(conversation_wait == WAIT_NO_SPEECH ||
|
||||||
conversation_wait == WAIT_SEND_FAILURE ||
|
conversation_wait == WAIT_SEND_FAILURE ||
|
||||||
hal_os_up_time_ms() - reply_wait_start_ms > 5000)) {
|
hal_os_up_time_ms() - reply_wait_start_ms > 5000)) {
|
||||||
|
voice_diag_snapshot("timeout-before-disconnect");
|
||||||
expired = conversation_wait;
|
expired = conversation_wait;
|
||||||
expired_round = wait_round;
|
expired_round = wait_round;
|
||||||
conversation_wait = WAIT_NONE;
|
conversation_wait = WAIT_NONE;
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,181 @@
|
|||||||
|
"""Host behavioral tests of the actual APP module; no modem traffic is sent."""
|
||||||
|
from pathlib import Path
|
||||||
|
import shutil
|
||||||
|
import subprocess
|
||||||
|
import tempfile
|
||||||
|
|
||||||
|
ROOT = Path(__file__).resolve().parents[1]
|
||||||
|
APP = ROOT / 'ql-application/threadx/interface/custom_app'
|
||||||
|
with tempfile.TemporaryDirectory(prefix='app-nitz-test-') as directory:
|
||||||
|
work = Path(directory)
|
||||||
|
headers = {
|
||||||
|
'ql_rtos.h': '''#include <stddef.h>
|
||||||
|
typedef void *ql_task_t;
|
||||||
|
unsigned int ql_rtos_get_systicks(void);
|
||||||
|
void ql_rtos_task_sleep_ms(unsigned int);
|
||||||
|
int ql_rtos_task_create(ql_task_t *, unsigned int, unsigned char, char *, void (*)(void *), void *, ...);
|
||||||
|
int ql_rtos_task_delete(ql_task_t);
|
||||||
|
''',
|
||||||
|
'ql_func.h': '#include <stdint.h>\nextern intptr_t (*m_get_api_ptr)(char *);\n',
|
||||||
|
'ql_nw.h': '''enum { QL_NW_SUCCESS=0 };
|
||||||
|
typedef struct {char nitz_time[32]; unsigned long abs_time; unsigned char leap_sec;} QL_NW_NITZ_TIME_INFO_T;
|
||||||
|
int ql_nw_get_nitz_time_info(QL_NW_NITZ_TIME_INFO_T *);
|
||||||
|
''',
|
||||||
|
'ql_rtc.h': '''typedef struct {int tm_sec,tm_min,tm_hour,tm_mday,tm_mon,tm_year,tm_wday;} ql_rtc_time_t;
|
||||||
|
int ql_rtc_set_time(ql_rtc_time_t *);
|
||||||
|
int ql_rtc_get_time(ql_rtc_time_t *);
|
||||||
|
''',
|
||||||
|
}
|
||||||
|
for name, content in headers.items():
|
||||||
|
(work / name).write_text(content)
|
||||||
|
harness = r'''
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "APP_SOURCE"
|
||||||
|
static int mode, creates, queries, sets, sleeps;
|
||||||
|
static unsigned int ticks=100;
|
||||||
|
static time_t app_epoch=100;
|
||||||
|
static int zone_minutes=480;
|
||||||
|
static ql_rtc_time_t saved;
|
||||||
|
unsigned int ql_rtos_get_systicks(void) {return ticks;}
|
||||||
|
void ql_rtos_task_sleep_ms(unsigned int ms) {assert(ms==5000); ++sleeps; ticks+=ms/5;}
|
||||||
|
static intptr_t lookup(char *name) {
|
||||||
|
assert(!strcmp(name,"ql_nw_get_nitz_time_info") || !strcmp(name,"ql_localtime_r") ||
|
||||||
|
!strcmp(name,"ql_rtc_set_time") || !strcmp(name,"ql_rtc_get_time"));
|
||||||
|
return mode==1 ? 0 : 1;
|
||||||
|
}
|
||||||
|
intptr_t (*m_get_api_ptr)(char *)=lookup;
|
||||||
|
int ql_nw_get_nitz_time_info(QL_NW_NITZ_TIME_INFO_T *info) {
|
||||||
|
time_t value=1793019600; /* 2026-10-26 13:00:00 UTC */
|
||||||
|
struct tm *utc;
|
||||||
|
++queries;
|
||||||
|
if (mode==2) return 1;
|
||||||
|
if (mode==3) return 0;
|
||||||
|
if (mode==4) {memset(info->nitz_time,'X',32); return 0;}
|
||||||
|
if (mode==5) {strcpy(info->nitz_time,"26/02/30 13:00:00 +32 00"); return 0;}
|
||||||
|
if (mode==6 || mode==22) {
|
||||||
|
strcpy(info->nitz_time,mode==22 ? "26/10/26 08:00:10 32 0" : "26/10/26 13:00:00 +32 00");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (mode==16 && queries==1) return 1;
|
||||||
|
if (mode==23 && queries<3) return 1;
|
||||||
|
if (mode==17) ticks+=600; /* slow query must be rejected */
|
||||||
|
if (mode==14) value=1793059198; /* near midnight UTC */
|
||||||
|
if (mode==15) value=2147483646; /* PMIC +8 local calendar exceeds signed32 range */
|
||||||
|
if (mode==18) value=1704067200; /* Old but valid snapshot: age cannot be proven. */
|
||||||
|
else value+=(ticks-100U)/200U;
|
||||||
|
/* Compute relative elapsed correctly in wrap scenario. */
|
||||||
|
if (mode==13) value=1793019600+(unsigned int)(ticks-(UINT32_MAX-199U))/200U;
|
||||||
|
utc=gmtime(&value); assert(utc);
|
||||||
|
snprintf(info->nitz_time,32,mode==21 ? "%02d/%02d/%02d %02d:%02d:%02d 32 0" : "%02d/%02d/%02d %02d:%02d:%02d +32 00",
|
||||||
|
utc->tm_year%100,utc->tm_mon+1,utc->tm_mday,utc->tm_hour,utc->tm_min,utc->tm_sec);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
struct tm *ql_localtime_r(const time_t *epoch,struct tm *out) {
|
||||||
|
time_t local=*epoch+zone_minutes*60;
|
||||||
|
struct tm *value;
|
||||||
|
if (mode==7) return NULL;
|
||||||
|
if (mode==25) local+=28800; /* Invalid PMIC conversion (+16 hours total). */
|
||||||
|
value=gmtime(&local); assert(value); *out=*value; return out;
|
||||||
|
}
|
||||||
|
time_t time(time_t *out) {(void)out; return app_epoch;}
|
||||||
|
int ql_rtc_set_time(ql_rtc_time_t *calendar) {
|
||||||
|
long long value;
|
||||||
|
++sets; saved=*calendar;
|
||||||
|
if (mode==8) return -1;
|
||||||
|
assert(calendar_epoch(calendar->tm_year,calendar->tm_mon,calendar->tm_mday,
|
||||||
|
calendar->tm_hour,calendar->tm_min,calendar->tm_sec,&value)==0);
|
||||||
|
if (mode!=9) app_epoch=(time_t)(value-zone_minutes*60);
|
||||||
|
if (mode==10) app_epoch+=28800; /* catches double timezone conversion */
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int ql_rtc_get_time(ql_rtc_time_t *out) {*out=saved; if (mode==20) out->tm_year=1970; return mode==11 ? -1 : 0;}
|
||||||
|
int ql_rtos_task_create(ql_task_t *task,unsigned int size,unsigned char priority,char *name,
|
||||||
|
void (*entry)(void *),void *arg,...) {
|
||||||
|
assert(size>=4096 && priority==110 && !strcmp(name,"app_time_calibrate"));
|
||||||
|
++creates;
|
||||||
|
if (mode==19) return -1;
|
||||||
|
*task=(void *)1; entry(arg); return 0;
|
||||||
|
}
|
||||||
|
int ql_rtos_task_delete(ql_task_t task) {assert(task==NULL); return 0;}
|
||||||
|
static void check_parser(void) {
|
||||||
|
time_t epoch; int zone; long long value;
|
||||||
|
assert(parse_nitz("26/10/26 13:00:00 +32 00",&epoch,&zone)==0 &&
|
||||||
|
epoch==1793019600 && zone==32);
|
||||||
|
assert(parse_nitz("26/10/26,13:00:00-22",&epoch,&zone)==0 &&
|
||||||
|
epoch==1793019600 && zone==-22);
|
||||||
|
assert(parse_nitz("26/10/26 13:00:00 +56 02",&epoch,&zone)==0);
|
||||||
|
assert(parse_nitz("26/10/26 08:00:10 32 0",&epoch,&zone)==0 && epoch==1793001610 && zone==32);
|
||||||
|
assert(parse_nitz("26/10/26 13:00:00 -22 0",&epoch,&zone)==0 && zone==-22);
|
||||||
|
assert(parse_nitz("26/10/26 13:00:00 0 0",&epoch,&zone)==0 && zone==0);
|
||||||
|
assert(parse_nitz("26/10/26 13:00:00 0",&epoch,&zone)!=0);
|
||||||
|
assert(parse_nitz("26/10/26 13:00:00 320 0",&epoch,&zone)!=0);
|
||||||
|
assert(parse_nitz("24/02/29 23:59:59 +00 00",&epoch,&zone)==0);
|
||||||
|
assert(parse_nitz("26/02/29 00:00:00 +00 00",&epoch,&zone)!=0);
|
||||||
|
assert(parse_nitz("38/01/19 03:14:07 +00 00",&epoch,&zone)==0 && epoch==2147483647);
|
||||||
|
assert(parse_nitz("38/01/19 03:14:08 +00 00",&epoch,&zone)!=0);
|
||||||
|
const char *bad[]={"", "26/10/26 13:00:00", "23/12/31 23:59:59 +00 00",
|
||||||
|
"26/00/26 13:00:00 +00 00", "26/13/26 13:00:00 +00 00",
|
||||||
|
"26/10/00 13:00:00 +00 00", "26/04/31 13:00:00 +00 00",
|
||||||
|
"26/10/26 24:00:00 +00 00", "26/10/26 13:60:00 +00 00",
|
||||||
|
"26/10/26 13:00:60 +00 00", "26/10/26 13:00:00 +57 00",
|
||||||
|
"26/10/26 13:00:00 -49 00", "26/10/26 13:00:00 +32 03",
|
||||||
|
"26/10/26 13:00:00 +32 junk",
|
||||||
|
"26/10/26 13:00:00 +32 00junk", "x6/10/26 13:00:00 +32 00"};
|
||||||
|
for (unsigned int i=0;i<sizeof(bad)/sizeof(bad[0]);++i)
|
||||||
|
assert(parse_nitz(bad[i],&epoch,&zone)!=0);
|
||||||
|
assert(calendar_epoch(2024,2,29,23,59,59,&value)==0);
|
||||||
|
long long next;
|
||||||
|
assert(calendar_epoch(2024,3,1,0,0,0,&next)==0 && next-value==1);
|
||||||
|
}
|
||||||
|
int main(int argc,char **argv) {
|
||||||
|
assert(argc==2); mode=atoi(argv[1]); check_parser();
|
||||||
|
if (mode==12) zone_minutes=-330;
|
||||||
|
if (mode==24) zone_minutes=0;
|
||||||
|
if (mode==13) ticks=UINT32_MAX-199U;
|
||||||
|
app_time_calibrate_start(); app_time_calibrate_start();
|
||||||
|
assert(creates==(mode==19 ? 2 : 1));
|
||||||
|
if ((mode>=1 && mode<=5) || mode==7 || mode==15 || mode==17 || mode==19 || mode==25)
|
||||||
|
assert(sets==0);
|
||||||
|
else assert(sets==1);
|
||||||
|
if (mode==1 || mode==19) {assert(queries==0 && sleeps==0);}
|
||||||
|
else if ((mode>=2 && mode<=5) || mode==17 || mode==23) {assert(queries==3 && sleeps==2);}
|
||||||
|
else if (mode==16) {assert(queries==2 && sleeps==1);}
|
||||||
|
else {assert(queries==1 && sleeps==0);}
|
||||||
|
if (mode==22) {
|
||||||
|
assert(saved.tm_year==2026 && saved.tm_mon==10 && saved.tm_mday==26);
|
||||||
|
assert(saved.tm_hour==16 && saved.tm_min==0 && saved.tm_sec==10);
|
||||||
|
assert(app_epoch==1793001610); /* Local RTC +8, UTC remains unshifted. */
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
'''.replace('APP_SOURCE', str(APP / 'app_time_calibrate.c'))
|
||||||
|
(work / 'test.c').write_text(harness)
|
||||||
|
compiler = shutil.which('clang') or shutil.which('cc')
|
||||||
|
if not compiler:
|
||||||
|
raise SystemExit('A native C compiler is required')
|
||||||
|
subprocess.run([compiler, '-std=c99', '-Wall', '-Wextra', '-Werror',
|
||||||
|
'-fsanitize=address,undefined', '-I', str(work), '-I', str(APP / 'inc'),
|
||||||
|
str(work / 'test.c'), '-o', str(work / 'test')], check=True)
|
||||||
|
cases = {0: 'PASS source=nitz', 1: 'FAIL stage=sdk_api_unavailable',
|
||||||
|
2: 'FAIL stage=no_valid_nitz', 3: 'FAIL stage=no_valid_nitz',
|
||||||
|
4: 'FAIL stage=no_valid_nitz', 5: 'FAIL stage=no_valid_nitz',
|
||||||
|
6: 'PASS source=nitz', 7: 'FAIL stage=local_calendar',
|
||||||
|
8: 'FAIL stage=app_clock_verification', 9: 'FAIL stage=app_clock_verification',
|
||||||
|
10: 'FAIL stage=app_clock_verification', 11: 'FAIL stage=app_clock_verification',
|
||||||
|
12: 'PASS source=nitz', 13: 'PASS source=nitz', 14: 'PASS source=nitz',
|
||||||
|
15: 'FAIL stage=local_calendar', 16: 'PASS source=nitz',
|
||||||
|
17: 'FAIL stage=no_valid_nitz', 18: 'PASS source=nitz',
|
||||||
|
19: 'FAIL stage=create_task', 20: 'FAIL stage=app_clock_verification',
|
||||||
|
21: 'PASS source=nitz', 22: 'PASS source=nitz', 23: 'PASS source=nitz',
|
||||||
|
24: 'PASS source=nitz', 25: 'FAIL stage=local_calendar'}
|
||||||
|
for mode, expected in cases.items():
|
||||||
|
log = subprocess.check_output([str(work / 'test'), str(mode)], text=True)
|
||||||
|
assert expected in log, log
|
||||||
|
assert '[APP-SYS-PROBE]' not in log, log
|
||||||
|
assert 'stage=freshness' not in log, log
|
||||||
|
if expected.startswith('PASS'):
|
||||||
|
assert 'age=unknown first_valid_after_pdp=1 max_rtc_writes=1' in log, log
|
||||||
|
else:
|
||||||
|
assert '[APP-TIME] PASS ' not in log, log
|
||||||
|
print('PASS: parser validation and 26 first-snapshot/retry/timezone/RTC scenarios (ASan/UBSan)')
|
||||||
@@ -38,6 +38,7 @@ static int queued, disconnected, flags_reset, mutex_locked, player_mq_couter, va
|
|||||||
static uint64_t now;
|
static uint64_t now;
|
||||||
static unsigned int gSequenceNumber;
|
static unsigned int gSequenceNumber;
|
||||||
static int end_result;
|
static int end_result;
|
||||||
|
static char sessionId[33] = "test-session";
|
||||||
typedef struct { unsigned int sequenceNumber; int packetType, dataSize; } AudioPacket;
|
typedef struct { unsigned int sequenceNumber; int packetType, dataSize; } AudioPacket;
|
||||||
static int ql_rtos_mutex_lock(ql_mutex_t m, unsigned int t) {
|
static int ql_rtos_mutex_lock(ql_mutex_t m, unsigned int t) {
|
||||||
(void)m; (void)t; assert(!mutex_locked); mutex_locked = 1; return 0;
|
(void)m; (void)t; assert(!mutex_locked); mutex_locked = 1; return 0;
|
||||||
@@ -66,7 +67,7 @@ static void talkingq_ws_disconnect(void) {
|
|||||||
static int sendRecordingAudioPacket(AudioPacket *p) { assert(p->packetType == 2); return end_result; }
|
static int sendRecordingAudioPacket(AudioPacket *p) { assert(p->packetType == 2); return end_result; }
|
||||||
'''
|
'''
|
||||||
harness += source[state_start:state_end]
|
harness += source[state_start:state_end]
|
||||||
for name in ['conversation_try_begin', 'sendEndPacket', 'conversation_check_timeout', 'conversation_accept_voice_message', 'conversation_finish_startup_prompt', 'conversation_find_session_id', 'role_notice_is_url', 'role_notice_start_locked', 'role_notice_poll_locked', 'app_role_notice_handle_url', 'app_role_notice_before_finish', 'role_notice_finished']:
|
for name in ['voice_diag_snapshot', 'conversation_try_begin', 'sendEndPacket', 'conversation_check_timeout', 'conversation_accept_voice_message', 'conversation_finish_startup_prompt', 'conversation_find_session_id', 'role_notice_is_url', 'role_notice_start_locked', 'role_notice_poll_locked', 'app_role_notice_handle_url', 'app_role_notice_before_finish', 'role_notice_finished']:
|
||||||
harness += function(name)
|
harness += function(name)
|
||||||
harness += r'''
|
harness += r'''
|
||||||
static void reset(void) {
|
static void reset(void) {
|
||||||
|
|||||||
@@ -0,0 +1,89 @@
|
|||||||
|
"""Run the actual GNSS parser and power-state paths with logging off and on."""
|
||||||
|
from pathlib import Path
|
||||||
|
import re
|
||||||
|
import subprocess
|
||||||
|
import tempfile
|
||||||
|
|
||||||
|
root = Path(__file__).resolve().parents[1]
|
||||||
|
app = root / 'ql-application/threadx/interface/custom_app'
|
||||||
|
source = (app / 'gnss.c').read_text()
|
||||||
|
source = re.sub(r'^#include "(?!app_gnss_log.h")[^"]+"\n', '', source, flags=re.M)
|
||||||
|
harness = r'''
|
||||||
|
#include <assert.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <setjmp.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
typedef unsigned int u32;
|
||||||
|
typedef unsigned char u8;
|
||||||
|
typedef void *ql_task_t;
|
||||||
|
typedef enum { GNSS_MODE_FAST, GNSS_MODE_SLOW } gnss_mode_t;
|
||||||
|
typedef struct { double latitude, longitude; int is_valid; char raw_nmea[512]; } gps_location_info_t;
|
||||||
|
enum { AGPS_GNSS_ENABLE, APFLASH_GNSS_ENABLE, PACKET_MODE };
|
||||||
|
static unsigned int now;
|
||||||
|
static int scenario, opened, closed, printed;
|
||||||
|
static jmp_buf stop;
|
||||||
|
static unsigned int hal_os_up_time_ms(void) { return now; }
|
||||||
|
static int test_printf(const char *format, ...) { (void)format; printed++; return 0; }
|
||||||
|
#define printf test_printf
|
||||||
|
static int ql_gnss_close(void) { closed++; return 0; }
|
||||||
|
static int ql_gnss_open(void (*cb)(char *, int)) { (void)cb; opened++; return 0; }
|
||||||
|
static void app_set_app_operation(int value) { assert(value == 1); }
|
||||||
|
static void ql_gnss_cfgsys_set(int value) { (void)value; }
|
||||||
|
static void ql_gnss_cfgmsg_set(int value) { (void)value; }
|
||||||
|
static void ql_gnss_agps_cfg(int value, int extra) { (void)value; (void)extra; }
|
||||||
|
static void ql_gnss_apflash_cfg(int value) { (void)value; }
|
||||||
|
static void ql_set_gnss_nmea_mode(int value) { (void)value; }
|
||||||
|
static void ql_rtos_task_sleep_s(int seconds);
|
||||||
|
static void ql_rtos_task_create(ql_task_t *task, int stack, int priority, char *name, void (*entry)(void *), void *arg) {
|
||||||
|
(void)task; (void)stack; (void)priority; (void)name; (void)entry; (void)arg;
|
||||||
|
}
|
||||||
|
'''
|
||||||
|
harness += source
|
||||||
|
harness += r'''
|
||||||
|
#undef printf
|
||||||
|
static void ql_rtos_task_sleep_s(int seconds) {
|
||||||
|
if (closed) longjmp(stop, 1);
|
||||||
|
now += (unsigned int)seconds * 1000;
|
||||||
|
if (scenario == 1) g_gnss_sat_count = 2;
|
||||||
|
if (scenario == 2) { g_gnss_sat_count = 4; g_gps_location.is_valid = 1; }
|
||||||
|
assert(now < 1000000);
|
||||||
|
}
|
||||||
|
int main(void) {
|
||||||
|
(void)test_printf;
|
||||||
|
char data[] = "$GPGGA,120000,2311.71298,N,11328.63118,E,1,08,0.9,10,M,0,M,0,0*00\r\n"
|
||||||
|
"$GPGSV,1,1,08,01,10,10,30*00\r\n";
|
||||||
|
quec_gnss_callback(data, (int)strlen(data));
|
||||||
|
assert(g_gps_location.is_valid && g_gnss_sat_count == 8);
|
||||||
|
assert(fabs(g_gps_location.latitude - 23.1952163333) < 0.000001);
|
||||||
|
assert(fabs(g_gps_location.longitude - 113.4771863333) < 0.000001);
|
||||||
|
assert(strncmp(g_gps_location.raw_nmea, "$GPGGA,", 7) == 0);
|
||||||
|
print_gps_location_info();
|
||||||
|
set_gnss_mode(GNSS_MODE_FAST);
|
||||||
|
assert(get_gnss_mode() == GNSS_MODE_FAST && get_gnss_interval() == 180);
|
||||||
|
for (scenario = 0; scenario < 4; scenario++) {
|
||||||
|
now = 1; opened = closed = 0; gnss_is_open = 0;
|
||||||
|
g_gnss_mode = scenario == 3 ? GNSS_MODE_FAST : GNSS_MODE_SLOW;
|
||||||
|
if (!setjmp(stop)) quec_gnss_test(NULL);
|
||||||
|
assert(opened == 1 && closed == 1 && get_gnss_open_status() == 0);
|
||||||
|
}
|
||||||
|
#if APP_GNSS_LOG_ENABLED
|
||||||
|
assert(printed > 0);
|
||||||
|
#else
|
||||||
|
assert(printed == 0);
|
||||||
|
#endif
|
||||||
|
puts("PASS: GNSS parsing and all four hardware-close paths preserved; expected log visibility");
|
||||||
|
}
|
||||||
|
'''
|
||||||
|
with tempfile.TemporaryDirectory(prefix='banban-gnss-log-') as directory:
|
||||||
|
cfile = Path(directory) / 'gnss-test.c'
|
||||||
|
cfile.write_text(harness)
|
||||||
|
for enabled in (0, 1):
|
||||||
|
exe = Path(directory) / f'gnss-test-{enabled}'
|
||||||
|
subprocess.run(['cc', '-std=c99', '-Wall', '-Wextra', '-Werror',
|
||||||
|
'-Wno-unused-parameter', '-Wno-unused-variable', '-Wno-sign-compare',
|
||||||
|
'-fsanitize=address,undefined', f'-DAPP_GNSS_LOG_ENABLED={enabled}',
|
||||||
|
'-I' + str(app / 'inc'), str(cfile), '-o', str(exe)], check=True)
|
||||||
|
subprocess.run([str(exe)], check=True)
|
||||||
@@ -0,0 +1,112 @@
|
|||||||
|
"""Compile actual microphone, queue and receive diagnostics with scripted inputs."""
|
||||||
|
from pathlib import Path
|
||||||
|
import subprocess
|
||||||
|
import tempfile
|
||||||
|
|
||||||
|
root = Path(__file__).resolve().parents[1]
|
||||||
|
app = root / 'ql-application/threadx/interface/custom_app'
|
||||||
|
voice = (app / 'ws_talkingq.c').read_text()
|
||||||
|
mic = (app / 'vad_det.c').read_text()
|
||||||
|
|
||||||
|
def function(source, signature):
|
||||||
|
start = source.index(signature)
|
||||||
|
opening = source.index('{', start)
|
||||||
|
depth, end = 1, opening + 1
|
||||||
|
while depth:
|
||||||
|
depth += (source[end] == '{') - (source[end] == '}')
|
||||||
|
end += 1
|
||||||
|
return source[start:end] + '\n'
|
||||||
|
|
||||||
|
harness = r'''
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#define VAD_FRAME_BYTES 640
|
||||||
|
#define DEVICE_ID_SIZE 32
|
||||||
|
#define SESSION_ID_SIZE 33
|
||||||
|
#define RLOGE(...) ((void)0)
|
||||||
|
typedef int rws_socket;
|
||||||
|
static int g_mic_working;
|
||||||
|
static int g_state, ring_result = 640, fail_alloc, queue_result, dispatched;
|
||||||
|
static unsigned int conversation_round = 7;
|
||||||
|
static int active_session_valid = 1;
|
||||||
|
static char sessionId[33] = "session", deviceId[32] = "device";
|
||||||
|
static void *ring_sender;
|
||||||
|
static uint64_t now = 1000;
|
||||||
|
static int mutex_locked;
|
||||||
|
static uint64_t hal_os_up_time_ms(void) { return now; }
|
||||||
|
static void conversation_lock(void) { assert(!mutex_locked); mutex_locked = 1; }
|
||||||
|
static void conversation_unlock(void) { assert(mutex_locked); mutex_locked = 0; }
|
||||||
|
static int hal_os_rb_write(void *ring, const void *data, int len, unsigned int timeout) {
|
||||||
|
(void)ring; (void)data; (void)len; assert(timeout == 25); return ring_result;
|
||||||
|
}
|
||||||
|
static void *test_malloc(size_t size) { return fail_alloc ? NULL : malloc(size); }
|
||||||
|
static int talkingq_ws_send_bin(uint8_t *data, int len) {
|
||||||
|
uint32_t seq;
|
||||||
|
assert(len >= DEVICE_ID_SIZE + SESSION_ID_SIZE + 12);
|
||||||
|
memcpy(&seq, data + DEVICE_ID_SIZE + SESSION_ID_SIZE, 4);
|
||||||
|
assert(seq == 9);
|
||||||
|
return queue_result;
|
||||||
|
}
|
||||||
|
typedef struct { uint32_t sequenceNumber, packetType, dataSize; uint8_t *data; } AudioPacket;
|
||||||
|
static int conversation_accept_voice_message(const char *text) { return strstr(text, "old") == NULL; }
|
||||||
|
static void conversation_log_error_message(const char *text, unsigned int len) { (void)text; (void)len; }
|
||||||
|
static void onmessage_text_locked(rws_socket socket, const char *text, unsigned int len) {
|
||||||
|
(void)socket; (void)text; (void)len; assert(mutex_locked); dispatched++;
|
||||||
|
}
|
||||||
|
'''
|
||||||
|
start = voice.index('static struct {')
|
||||||
|
end = voice.index('} voice_diag;', start) + len('} voice_diag;')
|
||||||
|
harness += voice[start:end] + '\n'
|
||||||
|
start = mic.index('static struct {')
|
||||||
|
end = mic.index('extern int audio_packet_type;', start)
|
||||||
|
harness += mic[start:end]
|
||||||
|
harness += '#define malloc test_malloc\n'
|
||||||
|
harness += function(voice, 'int sendRecordingAudioPacket(AudioPacket *packet) {')
|
||||||
|
harness += '#undef malloc\n'
|
||||||
|
harness += function(voice, 'static void onmessage_text(rws_socket socket,')
|
||||||
|
harness += function(voice, 'static void onmessage_bin(rws_socket socket,')
|
||||||
|
harness += r'''
|
||||||
|
int main(void) {
|
||||||
|
uint8_t pcm[640] = {0};
|
||||||
|
AudioPacket packet = {9, 0, 4, pcm};
|
||||||
|
mic_diag.started_ms = now;
|
||||||
|
mic_diag_read(pcm, 640, 0);
|
||||||
|
assert(mic_diag.reads == 1 && mic_diag.zero_frames == 1 && mic_diag.peak == 0);
|
||||||
|
/* Full-scale negative input must avoid int16 absolute-value overflow. */
|
||||||
|
pcm[0] = 0; pcm[1] = 128;
|
||||||
|
mic_diag_read(pcm, 640, 0);
|
||||||
|
assert(mic_diag.peak == 32768 && mic_diag.abs_sum == 32768 && mic_diag.samples == 640);
|
||||||
|
mic_diag_read(pcm, 0, -1);
|
||||||
|
assert(mic_diag.short_reads == 1 && mic_diag.read_errors == 1 && mic_diag.zero_frames == 1);
|
||||||
|
mic_diag_read(pcm, 10000, 0); /* Diagnostic sampling stays inside the buffer. */
|
||||||
|
assert(mic_diag.samples == 960 && mic_diag.short_reads == 2);
|
||||||
|
ring_result = 640; assert(mic_diag_write(pcm, 640) == 640 && !mic_diag.ring_drops);
|
||||||
|
ring_result = -1; assert(mic_diag_write(pcm, 640) == -1);
|
||||||
|
ring_result = 320; assert(mic_diag_write(pcm, 640) == 320);
|
||||||
|
assert(mic_diag.ring_drops == 2 && mic_diag.ring_drop_bytes == 960);
|
||||||
|
mic_diag_log("test");
|
||||||
|
queue_result = 0; assert(sendRecordingAudioPacket(&packet) == 0);
|
||||||
|
assert(voice_diag.tx_packets == 1 && voice_diag.tx_bytes == 4 && !voice_diag.tx_failed);
|
||||||
|
queue_result = -1; assert(sendRecordingAudioPacket(&packet) == -1);
|
||||||
|
fail_alloc = 1; assert(sendRecordingAudioPacket(&packet) == -1);
|
||||||
|
assert(voice_diag.tx_packets == 1 && voice_diag.tx_bytes == 4 && voice_diag.tx_failed == 2);
|
||||||
|
onmessage_text(0, "START_ACK", 9);
|
||||||
|
onmessage_text(0, "END_ACK", 7);
|
||||||
|
onmessage_text(0, "unknown backend response", 24);
|
||||||
|
onmessage_text(0, "old TTS_START", 13);
|
||||||
|
assert(voice_diag.start_ack == 1 && voice_diag.end_ack == 1 && voice_diag.rx_text == 4);
|
||||||
|
assert(dispatched == 3 && !mutex_locked);
|
||||||
|
now = 2000; onmessage_bin(0, pcm, 640);
|
||||||
|
assert(voice_diag.rx_bin == 1 && voice_diag.last_rx_ms == now && !mutex_locked);
|
||||||
|
puts("PASS: microphone silence/level/short reads/errors, PCM drops, queue failure/allocation failure, ACK visibility, unknown/rejected replies, ignored binary replies");
|
||||||
|
}
|
||||||
|
'''
|
||||||
|
with tempfile.TemporaryDirectory(prefix='banban-voice-diag-') as directory:
|
||||||
|
cfile = Path(directory) / 'diag.c'
|
||||||
|
exe = Path(directory) / 'diag-test'
|
||||||
|
cfile.write_text(harness)
|
||||||
|
subprocess.run(['cc', '-std=c99', '-Wall', '-Wextra', '-Werror', '-fsanitize=address,undefined', str(cfile), '-o', str(exe)], check=True)
|
||||||
|
subprocess.run([str(exe)], check=True)
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
"""Compile actual SDK-independent function bodies with scripted TLS/RTOS stubs."""
|
"""Compile actual SDK-independent function bodies with scripted TLS/RTOS stubs."""
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import os
|
||||||
|
|
||||||
root = Path(__file__).resolve().parents[1]
|
root = Path(__file__).resolve().parents[1]
|
||||||
lib = root / 'ql-application/threadx/interface/custom_app/lib/librws/src'
|
lib = root / 'ql-application/threadx/interface/custom_app/lib/librws/src'
|
||||||
@@ -75,6 +76,9 @@ output.mkdir(parents=True, exist_ok=True)
|
|||||||
cfile = output / 'test_wss_io.c'
|
cfile = output / 'test_wss_io.c'
|
||||||
cfile.write_text(harness, encoding='utf-8')
|
cfile.write_text(harness, encoding='utf-8')
|
||||||
exe = output / 'test_wss_io.exe'
|
exe = output / 'test_wss_io.exe'
|
||||||
|
if os.name == "nt":
|
||||||
subprocess.run(['cl', '/nologo', '/W4', '/WX', '/TC', str(cfile),
|
subprocess.run(['cl', '/nologo', '/W4', '/WX', '/TC', str(cfile),
|
||||||
'/Fo' + str(output / 'test_wss_io.obj'), '/Fe' + str(exe)], check=True)
|
'/Fo' + str(output / 'test_wss_io.obj'), '/Fe' + str(exe)], check=True)
|
||||||
|
else:
|
||||||
|
subprocess.run(['cc', '-std=c99', '-Wall', '-Wextra', '-Werror', str(cfile), '-o', str(exe)], check=True)
|
||||||
subprocess.run([str(exe)], check=True)
|
subprocess.run([str(exe)], check=True)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
"""Exercise the real receive/upgrade loop with delayed TLS records."""
|
"""Exercise the real receive/upgrade loop with delayed TLS records."""
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import os
|
||||||
|
|
||||||
root = Path(__file__).resolve().parents[1]
|
root = Path(__file__).resolve().parents[1]
|
||||||
lib = root / 'ql-application/threadx/interface/custom_app/lib/librws'
|
lib = root / 'ql-application/threadx/interface/custom_app/lib/librws'
|
||||||
@@ -37,6 +38,7 @@ typedef struct {
|
|||||||
char *payload_buff, *received;
|
char *payload_buff, *received;
|
||||||
size_t received_size, received_len;
|
size_t received_size, received_len;
|
||||||
int socket, command, is_connected;
|
int socket, command, is_connected;
|
||||||
|
unsigned int diag_rx_calls, diag_rx_bytes;
|
||||||
const char *error;
|
const char *error;
|
||||||
} _rws_socket;
|
} _rws_socket;
|
||||||
static int replies[16], reply_count, calls, closes;
|
static int replies[16], reply_count, calls, closes;
|
||||||
@@ -120,7 +122,10 @@ output.mkdir(parents=True, exist_ok=True)
|
|||||||
cfile = output / 'test_wss_receive.c'
|
cfile = output / 'test_wss_receive.c'
|
||||||
cfile.write_text(harness, encoding='utf-8')
|
cfile.write_text(harness, encoding='utf-8')
|
||||||
exe = output / 'test_wss_receive.exe'
|
exe = output / 'test_wss_receive.exe'
|
||||||
|
if os.name == "nt":
|
||||||
subprocess.run(['cl', '/nologo', '/W4', '/WX', '/wd4018', '/TC',
|
subprocess.run(['cl', '/nologo', '/W4', '/WX', '/wd4018', '/TC',
|
||||||
'/I' + str(lib / 'inc'), str(cfile), str(lib / 'src/rws_handshake.c'),
|
'/I' + str(lib / 'inc'), str(cfile), str(lib / 'src/rws_handshake.c'),
|
||||||
'/Fo' + str(output) + '/', '/Fe' + str(exe)], check=True)
|
'/Fo' + str(output) + '/', '/Fe' + str(exe)], check=True)
|
||||||
|
else:
|
||||||
|
subprocess.run(['cc', '-std=c99', '-Wall', '-Wextra', '-Werror', '-Wno-sign-compare', '-I' + str(lib / 'inc'), str(cfile), str(lib / 'src/rws_handshake.c'), '-o', str(exe)], check=True)
|
||||||
subprocess.run([str(exe)], check=True)
|
subprocess.run([str(exe)], check=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user