#include "graphic_service.h"
#include "custom_utils.h"
#include <custom_runtime.h>
+#include "cmsis_os.h"
#include "events/key_event.h"
#include "common/key_code.h"
#include "dock/input_device.h"
UIViewGroup *DebugGroupView{nullptr};
UILabel *debugOutputtitleLabel{nullptr};
UILabel *debugOutputLabel{nullptr};
+ osTimerId_t g_debugOutputUpdateTimer{nullptr}; // 2秒定时器,用于更新视图
/* -------------------------------------------------------------------------- */
DebugOutputViewEventListener::DebugOutputViewEventListener() {}
break;
}
}
+ return false;
}
bool DebugOutputViewEventListener::ClickFunc(int16_t interface)
// deviceInfo += "设备model:" + std::string(uapi_ln_get_device_model()) + "\n";
deviceInfo += "cat1 model:" + std::string(cat1_api_runtime_get_cat1_modemver()) + "\n";
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "设备连接状态:%d", ln_ws_get_connection_state());
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "设备连接状态:%d\n", ln_ws_get_connection_state());
switch ((int)ln_ws_get_connection_state()) {
case 0:
- deviceInfo += "设备连接状态:未连接 " +std::to_string(ln_ws_get_connection_state());
+ deviceInfo += "设备连接状态:未连接 " +std::to_string(ln_ws_get_connection_state())+ "\n";
break;
case 1:
- deviceInfo += "设备连接状态:连接中 " +std::to_string(ln_ws_get_connection_state());
+ deviceInfo += "设备连接状态:连接中 " +std::to_string(ln_ws_get_connection_state())+ "\n";
break;
case 2:
- deviceInfo += "设备连接状态:连接成功 " +std::to_string(ln_ws_get_connection_state());
+ deviceInfo += "设备连接状态:连接成功 " +std::to_string(ln_ws_get_connection_state())+ "\n";
break;
case 3:
- deviceInfo += "设备连接状态:休眠状态 " +std::to_string(ln_ws_get_connection_state());
+ deviceInfo += "设备连接状态:休眠状态 " +std::to_string(ln_ws_get_connection_state())+ "\n";
break;
case 4:
- deviceInfo += "设备连接状态:重连执行中 " +std::to_string(ln_ws_get_connection_state());
+ deviceInfo += "设备连接状态:重连执行中 " +std::to_string(ln_ws_get_connection_state())+ "\n";
break;
default:
- deviceInfo += "设备连接状态:未知状态 " +std::to_string(ln_ws_get_connection_state());
+ deviceInfo += "设备连接状态:未知状态 " +std::to_string(ln_ws_get_connection_state())+ "\n";
break;
}
-
+#ifdef SUPPORT_PPP_SERVICE
//ppp波特率
+ deviceInfo += "cat1 cesq:" + std::string(cat1_api_runtime_get_cat1_cesq())+ "\n";
+ deviceInfo += "cat1 csq_rssi:" + std::to_string(cat1_api_runtime_get_cat1_signal())+ "\n";
uint32_t ppp_baudrate = get_ppp_baudrate_from_config_model();
deviceInfo += "ppp波特率:" + std::to_string(ppp_baudrate) + "\n";
+#else
+ deviceInfo += "cat1 cesq:" + std::string(cat1_api_runtime_get_cat1_cesq())+ "\n";
+ deviceInfo += "cat1 csq_rssi:" + std::to_string(cat1_api_runtime_get_cat1_signal())+ "\n";
+#endif
return deviceInfo;
}
return;
}
+ /*定时器回调函数:每2秒更新一次视图*/
+ static void DebugOutputUpdateTimerCallback(void *arg)
+ {
+ (void)arg;
+ if (DebugGroupView != nullptr)
+ {
+ DebugOutputViewEventListener::GetInstance().UpdateView();
+ }
+ }
+
/*创建调试专用主窗口视图*/
UIViewGroup *CreateDebugOutputMainView(void)
{
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " new debugOutputtitleLabel fail");
return nullptr;
}
- debugOutputtitleLabel->SetPosition(80, 40, 200, 35);
- debugOutputtitleLabel->SetStyle(STYLE_TEXT_FONT, 30);
- debugOutputtitleLabel->SetStyle(STYLE_LINE_HEIGHT, 35);
+ debugOutputtitleLabel->SetPosition(80, 40, 200, 25);
+ debugOutputtitleLabel->SetStyle(STYLE_TEXT_FONT, 20);
+ debugOutputtitleLabel->SetStyle(STYLE_LINE_HEIGHT, 25);
debugOutputtitleLabel->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION);
- debugOutputtitleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
+ debugOutputtitleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 20);
DebugGroupView->Add(debugOutputtitleLabel);
}
/* -------------------------------------------------------------------------- */
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new debugOutputLabel fail");
return nullptr;
}
- debugOutputLabel->SetPosition(30, 70, 300, 70);
+ debugOutputLabel->SetPosition(30, 65, 300, 70);
debugOutputLabel->SetText(DebugOutputViewEventListener::GetInstance().GetLeiNiaoDeviceInfo().c_str());
- debugOutputLabel->SetStyle(STYLE_TEXT_FONT, 24);
- debugOutputLabel->SetStyle(STYLE_LINE_HEIGHT, 24);
+ debugOutputLabel->SetStyle(STYLE_TEXT_FONT, 20);
+ debugOutputLabel->SetStyle(STYLE_LINE_HEIGHT, 20);
debugOutputLabel->SetLineBreakMode(UILabel::LINE_BREAK_WRAP);
- debugOutputLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 24);
+ debugOutputLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 20);
DebugGroupView->Add(debugOutputLabel);
}
RootView::GetInstance()->SetOnKeyActListener((OHOS::RootView::OnKeyActListener *)&DebugOutputViewEventListener::GetInstance());
/* -------------------------------------------------------------------------- */
NotificationManager::GetInstance()->RegisterNotifyCleanupFunction(FreeDebugOutputMainView);
/* -------------------------------------------------------------------------- */
+
+ /* 启动2秒定时器,定期更新视图 */
+ if (g_debugOutputUpdateTimer == nullptr)
+ {
+ g_debugOutputUpdateTimer = osTimerNew((osTimerFunc_t)DebugOutputUpdateTimerCallback, osTimerPeriodic, nullptr, nullptr);
+ if (g_debugOutputUpdateTimer != nullptr)
+ {
+ uint32_t tick = osMs2Tick(2000); // 2秒 = 2000毫秒
+ osStatus_t ret = osTimerStart(g_debugOutputUpdateTimer, tick);
+ if (ret != osOK)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to start debug output update timer, ret=%d", ret);
+ osTimerDelete(g_debugOutputUpdateTimer);
+ g_debugOutputUpdateTimer = nullptr;
+ }
+ else
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Debug output update timer started (2 seconds)");
+ }
+ }
+ else
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to create debug output update timer");
+ }
+ }
}
return DebugGroupView;
}
void FreeDebugOutputMainView(void)
{
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FreeDebugOutputMainView");
+
+ /* 停止并删除2秒定时器 */
+ if (g_debugOutputUpdateTimer != nullptr)
+ {
+ osTimerStop(g_debugOutputUpdateTimer);
+ osTimerDelete(g_debugOutputUpdateTimer);
+ g_debugOutputUpdateTimer = nullptr;
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Debug output update timer stopped");
+ }
+
ScreenAlwaysOnCtr(0);
if (DebugGroupView != nullptr)
{
uint8_t cat1_network_type ;
int sim ;
int signal ;
+ int signal_bars ;
+ char cesq[64] ;
char opera[64] ;
char imei[32] ;
char pyVer[32] ;
static cat1_runtime_status_t g_runtime={0};
-
+void cat1_api_runtime_set_cat1_signal_bars(int signal_bars)
+{
+ g_runtime.signal_bars=signal_bars;
+}
+int cat1_api_runtime_get_cat1_signal_bars(void)
+{
+ return g_runtime.signal_bars;
+}
+void cat1_api_runtime_set_cat1_cesq(char* cesq)
+{
+ if (cesq == NULL) return;
+
+ // 计算长度并去除末尾的换行符(\r\n 或 \n)
+ int len = strlen(cesq);
+ // 去除末尾的换行符
+ while (len > 0 && (cesq[len-1] == '\n' || cesq[len-1] == '\r')) {
+ len--;
+ }
+
+ memset_s(g_runtime.cesq,sizeof(g_runtime.cesq),0,sizeof(g_runtime.cesq));
+ memcpy_s(g_runtime.cesq,sizeof(g_runtime.cesq),cesq,len);
+ // printf("cat1_api_runtime_set_cat1_cesq %d: %s\n",len, g_runtime.cesq);
+ // printf("cat1_api_runtime_set_cat1_cesq end\n");
+}
+char* cat1_api_runtime_get_cat1_cesq(void)
+{
+ return (char*)g_runtime.cesq;
+}
void cat1_api_runtime_set_cat1_powerstat(uint8_t cat1_powerOn)
{
g_runtime.cat1_powerOn=cat1_powerOn;
return -3;
}
}
+
+static int CalculateSignalBars(int signalStrength)
+{
+ if (signalStrength >= 1 && signalStrength <= 8) // 0信号
+ {
+ return 0;
+ }
+ else if (signalStrength >= 9 && signalStrength <= 16) // 1格信号,信号很弱偶尔可以接打电话,很容易失败
+ {
+ return 1;
+ }
+ else if (signalStrength >= 17 && signalStrength <= 21) // 2格信号,信号一般
+ {
+ return 2;
+ }
+ else if (signalStrength >= 22 && signalStrength <= 26) // 3格信号,信号较强
+ {
+ return 3;
+ }
+ else if (signalStrength >= 27 && signalStrength <= 31) // 4格信号,信号很强
+ {
+ return 4;
+ }
+ else
+ {
+ return 99; // Invalid signal strength
+ }
+}
// const char* msgnet ="imei:860132060352796,sim:0,oper:-1,signal:99,net:([99, 0, 0, 0], [0, 0, 0, 0, 0])";
// const char* msgnetfull = "imei:864430010001091,sim:1,oper:('CHN-CT', 'CT', '460', '11'),signal:22,net:([99, 99, 255, 255], [-71, -103, -12, 255, 4])";
// ([rssi, bitErrorRate, rscp, ecno], [rssi, rsrp, rsrq, cqi, sinr])
{
ppbuf=s+7;
int signals = atoi(ppbuf);
- cat1_print_dbg("=== signal = %d\r\n",signals);
+ int signal_bars = CalculateSignalBars(signals);
+ cat1_print_dbg("=== signal = %d, signal_bars = %d\r\n",signals,signal_bars);
if ( cat1_api_runtime_get_cat1_signal() != signals)
{
update++;
+ cat1_api_runtime_set_cat1_signal_bars(signal_bars);
cat1_api_runtime_set_cat1_signal(signals);
}
continue;
return -1;
}
+ cat1_api_runtime_set_cat1_cesq(cesq_line);
+
// 跳过"+CESQ:"
cesq_line += 6;
while (*cesq_line == ' ' || *cesq_line == '\t') cesq_line++;
}
// 更新信号强度到运行时状态
- int current_signal = cat1_api_runtime_get_cat1_signal();
- bool signal_changed = (current_signal != signal_strength);
+ int current_signal_bars = cat1_api_runtime_get_cat1_signal_bars();
+ bool signal_changed = (current_signal_bars != signal_strength);
bool network_stat_changed = false;
if (signal_changed) {
- cat1_api_runtime_set_cat1_signal(signal_strength);
- cat1_print_warning("cat1_getsignal: Updated signal strength via AT+CESQ - signal=%d (was %d)\n",
- signal_strength, current_signal);
+ // cat1_api_runtime_set_cat1_signal_bars(signal_strength);
+ cat1_print_warning("cat1_getsignal: Updated signal strength via AT+CESQ - signal_bars=%d (was %d)\n",
+ signal_strength, current_signal_bars);
}
// 如果信号强度有效(不是0),说明网络已连接,更新网络状态