From 99c70b73653813b776c3de50d36ec0b525c30bcc Mon Sep 17 00:00:00 2001 From: penglei <1624952103@qq.com> Date: Wed, 25 Sep 2024 18:53:54 +0800 Subject: [PATCH] =?utf8?q?=E6=B7=BB=E5=8A=A0PingTest=E4=BA=A7=E6=B5=8BUI?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../wearable/fd230app/CMakeLists.txt | 1 + .../nativeui/producttest/include/testPing.h | 85 ++++++ .../producttest/include/testPresenter.h | 9 + .../nativeui/producttest/include/testView.h | 4 + .../nativeui/producttest/src/testPing.cpp | 244 ++++++++++++++++++ .../nativeui/producttest/src/testView.cpp | 25 ++ .../nativeui/producttest/src/testcat1.cpp | 2 +- .../factorytest_protocol.c | 3 +- .../lwip-2.1/porting/include/lwip/api_shell.h | 3 + .../port/lwip-2.1/porting/src/api_shell.c | 77 +++++- 10 files changed, 447 insertions(+), 6 deletions(-) create mode 100644 code/sdk/application/wearable/fd230app/nativeui/producttest/include/testPing.h create mode 100644 code/sdk/application/wearable/fd230app/nativeui/producttest/src/testPing.cpp diff --git a/code/sdk/application/wearable/fd230app/CMakeLists.txt b/code/sdk/application/wearable/fd230app/CMakeLists.txt index 7372ec01f..610d5d5d4 100644 --- a/code/sdk/application/wearable/fd230app/CMakeLists.txt +++ b/code/sdk/application/wearable/fd230app/CMakeLists.txt @@ -752,6 +752,7 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/producttest/src/testbt.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/producttest/src/testSEChipTest.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/producttest/src/testModel.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/producttest/src/testPing.cpp #每日目标 ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/goal/src/goalmodel.cpp diff --git a/code/sdk/application/wearable/fd230app/nativeui/producttest/include/testPing.h b/code/sdk/application/wearable/fd230app/nativeui/producttest/include/testPing.h new file mode 100644 index 000000000..77f26ad9c --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/producttest/include/testPing.h @@ -0,0 +1,85 @@ +/* + * @Author: penglei 1624952103@qq.com + * @Date: 2024-09-18 17:17:23 + * @LastEditors: penglei 1624952103@qq.com + * @LastEditTime: 2024-09-19 18:37:54 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/producttest/include/testPing.h + * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE + */ +#ifndef TEST_PING_VIEW_H +#define TEST_PING_VIEW_H + +#include "BaseView.h" +#include "View.h" +#include "components/ui_scroll_view.h" +#include "components/ui_label.h" +#include "components/ui_label_ext.h" +#include "components/ui_button.h" +#include "components/ui_image_view.h" +#include "components/ui_label_button_ext.h" + +//#include "cmsis_os.h" +#include +namespace OHOS +{ + + class testPingView + { + + public: + struct ButtonConfig_ext_t + { + int x; + int y; + int w; + int h; + const char *str; + const char *ViewId; + const char *ImageSrc; + + //label + int label_x; + int label_y; + uint8_t ALIGN; + int Fontsize; + + }; + + struct LabelConfig + { + int16_t left; + int16_t top; + int16_t width; + int16_t height; + int16_t fontSize; // 字体大小 + int16_t lineHeigh; // 行高 + char *text; // 文本 + uint8_t lineBreakMode; // 断行模式。 + }; + + + testPingView(); + virtual ~testPingView(); + static testPingView *GetInstance(void); + + + UIScrollView *testPingInitIView(uint8_t); + void ClearAll(void); + void sethostname(char *data); + void setresult(char *data); + private: + UILabelButtonExt *SetTheButton_ext(ButtonConfig_ext_t &buttonconfig);//, UIView::OnTouchListener *clickListener); + UILabel *InitLabel(LabelConfig &labelConfig); + bool testPingScrollViewcrollViewinit(uint8_t); + UIScrollView *testPingScrollView{nullptr}; + UILabel *label_hostname{nullptr}; + + UILabelButtonExt* labelButton_next = nullptr; + UILabel *label_result{nullptr}; + + bool initViewStatus{false}; + UILabel *Title{nullptr}; // 标题 + + }; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/producttest/include/testPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/producttest/include/testPresenter.h index f23c86012..dbb65df4d 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/producttest/include/testPresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/producttest/include/testPresenter.h @@ -1,3 +1,11 @@ +/* + * @Author: penglei 1624952103@qq.com + * @Date: 2024-08-23 10:50:37 + * @LastEditors: penglei 1624952103@qq.com + * @LastEditTime: 2024-09-18 18:29:11 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/producttest/include/testPresenter.h + * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE + */ #ifndef TEST_PRESENTER_H #define TEST_PRESENTER_H @@ -36,6 +44,7 @@ namespace OHOS GSENSON, BTTEST, SEChipTest, + PingTest, OLDTEST, DEEPSLEEP, diff --git a/code/sdk/application/wearable/fd230app/nativeui/producttest/include/testView.h b/code/sdk/application/wearable/fd230app/nativeui/producttest/include/testView.h index 0c69ff954..73ac3342b 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/producttest/include/testView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/producttest/include/testView.h @@ -28,6 +28,7 @@ #include "producttest/include/testold.h" #include "producttest/include/testbt.h" #include "producttest/include/testSEChipTest.h" +#include "producttest/include/testPing.h" #ifdef SUPPORT_A5133_SERVICE #include "producttest/include/testA5133.h" #endif @@ -94,6 +95,7 @@ namespace OHOS bool ChangeoldTESTView(int16_t thisView); bool ChangeBTTESTView(int16_t thisView); bool ChangeSEChipTESTView(int16_t thisView); + bool ChangePingTESTView(int16_t thisView); #ifdef SUPPORT_A5133_SERVICE bool ChangeA5133TESTView(int16_t thisView); #endif @@ -132,6 +134,8 @@ namespace OHOS testBTView *test_BT_view{nullptr}; testSEChipView *test_SEChip_view{nullptr}; + testPingView *test_Ping_view{nullptr}; + #ifdef SUPPORT_A5133_SERVICE testA5133View *test_A5133_view{nullptr}; #endif diff --git a/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testPing.cpp b/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testPing.cpp new file mode 100644 index 000000000..79ba84432 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testPing.cpp @@ -0,0 +1,244 @@ +#include "wearable_log.h" +#include "custom_utils.h" +#include "producttest/include/testPresenter.h" +#include "producttest/include/testPing.h" +#include "AlarmClockModel.h" +#include "cmsis_os2.h" +#include "cat1_server.h" +#include "cat1_ctl.h" +#include "cat1_server_hal.h" +#include "custom_runtime.h" +#include "producttest/include/testView.h" + +#ifdef SUPPORT_TCPIP +#include "lwip/api_shell.h" +#endif + +namespace OHOS +{ + + static testPingView *g_pSystemAboutTheWatchView{nullptr}; + static osTimerId_t g_ping_timer=NULL; + + testPingView::testPingView() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemAboutTheWatchView::SystemAboutTheWatchView"); + g_pSystemAboutTheWatchView = this; + } + + testPingView::~testPingView() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "testPingView::~testPingView"); + ClearAll(); + //g_pSystemAboutTheWatchView = nullptr; + } + + testPingView *testPingView::GetInstance() + { + + return g_pSystemAboutTheWatchView; + } + + void testPingView::ClearAll() + { + if(testPingScrollView) + { + testPingScrollView->RemoveAll(); + + if (g_ping_timer != NULL) + { + osTimerStop(g_ping_timer); + osTimerDelete(g_ping_timer); + g_ping_timer = NULL; + } + + // if(button) + // { + // delete button; + // button=nullptr; + // } + if(labelButton_next) + { + delete labelButton_next; + labelButton_next=nullptr; + } + if(label_hostname) + { + delete label_hostname; + label_hostname=nullptr; + } + + if(label_result) + { + delete label_result; + label_result=nullptr; + } + if(Title) + { + delete Title; + Title=nullptr; + } + + + + delete testPingScrollView; + testPingScrollView=nullptr; + } + } + + UILabelButtonExt *testPingView::SetTheButton_ext(ButtonConfig_ext_t &buttonconfig) + { + UILabelButtonExt *button = new UILabelButtonExt(); + if (button == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " SystemView::SetTheButton: button new fail!"); + return nullptr; + } + button->SetPosition(buttonconfig.x, buttonconfig.y, buttonconfig.w, buttonconfig.h); + button->SetViewId(buttonconfig.ViewId); + button->SetStyle(STYLE_BACKGROUND_COLOR, Color::Blue().full); + //button->SetStyle(STYLE_BORDER_RADIUS,0); + button->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); + //button->SetStyleForState(STYLE_BORDER_RADIUS,0, UIButton::PRESSED); + button->SetTouchable(true); + button->SetStyle(STYLE_BACKGROUND_OPA, 0x80); + button->SetText(buttonconfig.str); + button->SetAlign(TEXT_ALIGNMENT_LEFT); + button->SetLabelPosition(buttonconfig.label_x,buttonconfig.label_y ); + button->SetFont(DEFAULT_VECTOR_FONT_FILENAME, buttonconfig.Fontsize); + UIView:: OnClickListener *touchListener = static_cast(testPresenter::GetInstance()); + button->SetOnClickListener(touchListener); + + // UIView::OnDragListener *drgListener = static_cast(testPresenter::GetInstance()); + // button->SetOnDragListener(drgListener); + + // button->SetDraggable(false); + return button; + } + + UILabel *testPingView::InitLabel(LabelConfig &labelConfig) + { + UILabel *label = new UILabel(); + if (label == nullptr) + { + return nullptr; + } + label->SetPosition(labelConfig.left, labelConfig.top, labelConfig.width, labelConfig.height); // 位置大小 + label->SetStyle(STYLE_TEXT_FONT, labelConfig.fontSize); // 字体大小 + label->SetStyle(STYLE_LINE_HEIGHT, labelConfig.lineHeigh); // 字体行高 + label->SetText(labelConfig.text); // 内容 + label->SetLineBreakMode(labelConfig.lineBreakMode); // 断行模式。 + label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_TOP); + label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, labelConfig.fontSize); + // label->SetAlign(TEXT_ALIGNMENT_LEFT); + return label; + } + + void testPingView::sethostname(char *data) + { + if(label_hostname != NULL) + label_hostname->SetText(data); + } + void testPingView::setresult(char *data) + { + if(label_result != NULL) + label_result->SetText(data); + } + + static void msgupdateTimerCallBack(int data) + { + char hostname[20] = {0}; + char result[256] = {0}; + get_ping_hostname(hostname,sizeof(hostname)); + get_ping_result(result,sizeof(result)); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "result : %s ",result); + OHOS::testPingView *pview = OHOS::testPingView::GetInstance(); + pview->sethostname(hostname); + pview->setresult(result); + } + + bool testPingView::testPingScrollViewcrollViewinit(uint8_t id) + { + + testPingScrollView = new UIScrollView(); + if (testPingScrollView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemAboutTheWatchView::testPingScrollView new fail!"); + return false; + } + testPingScrollView->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + testPingScrollView->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + testPingScrollView->SetStyle(STYLE_BORDER_RADIUS, 0); + testPingScrollView->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + testPingScrollView->SetStyle(STYLE_BORDER_COLOR, Color::Yellow().blue); + + LabelConfig Config = { + .left = 0, + .top = 100, + .width = 466, + .height = 40, + .fontSize = 30, + .lineHeigh = 35, + .text = "www.****.com", + .lineBreakMode = UILabel::LINE_BREAK_MARQUEE, + }; + label_hostname= InitLabel(Config); + if (label_hostname == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemView::SystemAboutTheWatchTitle new fail!"); + return false; + } + testPingScrollView->Add(label_hostname); + + Config = { + .left = 70, + .top = 200, + .width = 350, + .height = 35, + .fontSize = 40, + .lineHeigh = 35, + .text = "connecting ...", + .lineBreakMode = UILabel::LINE_BREAK_WRAP, + }; + label_result= InitLabel(Config); + if (label_result == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemView::SystemAboutTheWatchTitle new fail!"); + return false; + } + testPingScrollView->Add(label_result); + + + labelButton_next= testAboutView::GetInstance()->init_button_next(267,278,Test_ViewMapper_t[id].viewid_str_next); + testPingScrollView->Add(labelButton_next); + + Title= testAboutView::GetInstance()->init_title(165,45,"Ping_TEST"); + testPingScrollView->Add(Title); + + testPingScrollView->SetTouchable(true); + testPingScrollView->SetDraggable(true); + + g_ping_timer = osTimerNew((osTimerFunc_t)msgupdateTimerCallBack, osTimerPeriodic, NULL, NULL); + + osStatus_t ret = osTimerStart(g_ping_timer, 1000); + if (ret != osOK && g_ping_timer != NULL) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"StartCallTimer osTimerStart failed, ret = %lx!!", ret); + osTimerDelete(g_ping_timer); + g_ping_timer = NULL; + return false; + } + + return true; + } + + UIScrollView *testPingView::testPingInitIView(uint8_t id) + { + if (!testPingScrollViewcrollViewinit(id)) + { + return nullptr; + } + return testPingScrollView; + } + + +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testView.cpp b/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testView.cpp index bf9f6e803..aa1ae3861 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testView.cpp @@ -30,6 +30,7 @@ namespace OHOS {GSENSON,"gsensonbutton","gsensor","gsensonbutton_next" ,&testView::ChangeGTESTView,true}, {BTTEST,"BTbutton","BT" ,"BTbutton_next",&testView::ChangeBTTESTView,true}, {SEChipTest,"SEChipTestbutton","SEChipTest","SEChipTestbutton_next" ,&testView::ChangeSEChipTESTView,true}, + {PingTest,"PingTestbutton","PingTest","PingTestbutton_next" ,&testView::ChangePingTESTView,true}, {OLDTEST,"oldtestbutton","aging" ,"oldtestexit",&testView::ChangeoldTESTView,true}, {DEEPSLEEP,"deepsleep","DeepSleepCurrent","xxxxxxxxx" ,&testView::ChangeoldTESTView,true}, {shutdown,"shutdown","shutdown", "xxxxxxxxx",&testView::ChangeoldTESTView,true}, @@ -587,6 +588,24 @@ namespace OHOS } return true; } + + bool testView::ChangePingTESTView(int16_t thisView) + { + if (SystemScrollView[thisView] == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemView::ChangeSEChipTESTView"); + test_Ping_view = new testPingView(); + if (test_Ping_view == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemView:: new scrollView[%d] fail", thisView); + return false; + } + SystemScrollView[thisView] = test_Ping_view->testPingInitIView(thisView); + RootView::GetInstance()->Add(SystemScrollView[thisView]); + } + return true; + } + #ifdef SUPPORT_A5133_SERVICE bool testView::ChangeA5133TESTView(int16_t thisView) { @@ -750,6 +769,12 @@ namespace OHOS test_SEChip_view = nullptr; SystemScrollView[hideView]=nullptr; break; + case PingTest: + RootView::GetInstance()->Remove(SystemScrollView[hideView]); + delete test_Ping_view; + test_Ping_view = nullptr; + SystemScrollView[hideView]=nullptr; + break; #ifdef SUPPORT_A5133_SERVICE case RF5133: RootView::GetInstance()->Remove(SystemScrollView[hideView]); diff --git a/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testcat1.cpp b/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testcat1.cpp index beea8b8d6..ecab799c7 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testcat1.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testcat1.cpp @@ -43,7 +43,7 @@ namespace OHOS osTimerStop(Gsenson_TEST_timer); osTimerDelete(Gsenson_TEST_timer); Gsenson_TEST_timer = NULL; - return ; + //return ; } // if(button) // { diff --git a/code/sdk/application/wearable/service/factorytest_service/factorytest_protocol.c b/code/sdk/application/wearable/service/factorytest_service/factorytest_protocol.c index b8ec7c0a8..8a63baff2 100644 --- a/code/sdk/application/wearable/service/factorytest_service/factorytest_protocol.c +++ b/code/sdk/application/wearable/service/factorytest_service/factorytest_protocol.c @@ -2,7 +2,7 @@ * @Author: penglei 1624952103@qq.com * @Date: 2024-06-17 14:31:08 * @LastEditors: penglei 1624952103@qq.com - * @LastEditTime: 2024-09-12 20:31:12 + * @LastEditTime: 2024-09-18 20:10:26 * @FilePath: /FD230/code/sdk/application/wearable/service/factorytest_service/factorytest_protocol.c * @Description: * @@ -1641,6 +1641,7 @@ void factorytest_protocol_soft_test_decode(uint8_t submode,uint8_t testitem,uint sprintf(hostname,"www.%s.com",str); PRINT("hostname : %s\n",hostname); send_data = OsShellPing(1,hostname); + free(hostname); free(str); #endif factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, diff --git a/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/include/lwip/api_shell.h b/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/include/lwip/api_shell.h index ff7bfaf52..31e01f698 100644 --- a/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/include/lwip/api_shell.h +++ b/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/include/lwip/api_shell.h @@ -42,6 +42,9 @@ extern "C" { u32_t lwip_ifconfig(int argc, const char **argv); u32_t OsShellPing(int argc, const char *argv); +void get_ping_hostname(char *databuf,uint8_t len); +void get_ping_result(char *databuf,uint16_t len); + #ifndef LWIP_TESTBED static #endif diff --git a/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/src/api_shell.c b/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/src/api_shell.c index b313127ed..53aae4ebb 100644 --- a/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/src/api_shell.c +++ b/code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/src/api_shell.c @@ -87,6 +87,49 @@ struct ifconfig_option { unsigned int print_len; }; +static char result_data[256] = {0}; +static char hostname[20] = {0}; + +void get_ping_hostname(char *databuf,uint8_t len) +{ + memcpy_s(databuf,len,hostname,strlen(hostname)); +} + +void get_ping_result(char *databuf,uint16_t len) +{ + if (databuf == NULL || len <= 0) + { + PRINTK("Invalid input for get_ping_result. len : %d\n",len); + return; + } + size_t resultLen = strlen(result_data); + if (resultLen >= len) + { + PRINTK("Insufficient buffer size for databuf.\n"); + len = resultLen + 1; + } + memcpy(databuf, result_data, resultLen); + databuf[resultLen] = '\0'; + // PRINTK("result_data : %s\n", result_data); + // PRINTK("databuf : %s\n", databuf); + // memset(result_data,0,sizeof(result_data)); +} + +static void get_log(char* str, int arrSize) +{ + if (str == NULL || arrSize <= 0) { + PRINTK("Invalid input for get_log.\n"); + return; + } + if (arrSize >= sizeof(result_data)) { + PRINTK("Input size too large for result_data.\n"); + arrSize = sizeof(result_data) - 1; + } + memcpy(result_data, str, arrSize); + result_data[arrSize] = '\0'; + // PRINTK("result_data : %s\n", result_data); +} + #ifndef LWIP_TESTBED LWIP_STATIC #endif @@ -333,22 +376,25 @@ LWIP_STATIC int OsPingFunc(u32_t *parg) u32_t cnt = parg[1]; u32_t interval = parg[2]; u32_t data_len = parg[3]; - + char str[128] = {0}; iecho_len = sizeof(struct icmp_echo_hdr) + data_len; sfd = lwip_socket(PF_INET, SOCK_RAW, IPPROTO_ICMP); if (sfd < 0) { PRINTK("Ping socket\n"); + get_log("Ping socket",strlen("Ping socket\n")); return -1; } pbuf_resp = pbuf_alloc(PBUF_RAW, IP_HLEN + sizeof(struct icmp_echo_hdr), PBUF_RAM); if (pbuf_resp == NULL) { PRINTK("Ping: pbuf_resp malloc failed\n"); + get_log("Ping: pbuf_resp malloc failed\n",strlen("Ping: pbuf_resp malloc failed\n")); ret = -1; goto FAILURE; } iecho = (struct icmp_echo_hdr *)mem_malloc(iecho_len); if (iecho == NULL) { PRINTK("Ping: echo request malloc failed\n"); + get_log("Ping: echo request malloc failed\n",strlen("Ping: echo request malloc failed\n")); ret = -1; goto FAILURE; } @@ -380,6 +426,7 @@ LWIP_STATIC int OsPingFunc(u32_t *parg) ret = sendto(sfd, iecho, iecho_len, 0, (struct sockaddr *)&to, (socklen_t)sizeof(to)); if (ret < 0) { perror("Ping: sending ICMP echo request failed\n"); + get_log("Ping: sending ICMP echo request failed\n",strlen("Ping: sending ICMP echo request failed\n")); goto FAILURE; } @@ -406,6 +453,7 @@ LWIP_STATIC int OsPingFunc(u32_t *parg) ret = recv(sfd, pbuf_resp->payload, pbuf_resp->len, MSG_DONTWAIT); if (ret < 0) { perror("Ping: recv echo reply failed\n"); + get_log("Ping: recv echo reply failed\n",strlen("Ping: recv echo reply failed\n")); goto FAILURE; } @@ -416,6 +464,7 @@ LWIP_STATIC int OsPingFunc(u32_t *parg) if (pbuf_header(pbuf_resp, -ip_hlen)) { /* this failure will never happen, but failure handle is written just to be in safe side */ PRINTK("Ping : memory management failure\n"); + get_log("Ping : memory management failure",strlen("Ping : memory management failure")); goto FAILURE; } iecho_resp = (struct icmp_echo_hdr *)pbuf_resp->payload; @@ -423,6 +472,7 @@ LWIP_STATIC int OsPingFunc(u32_t *parg) if (pbuf_header(pbuf_resp, ip_hlen)) { /* this failure will never happen, but failure handle is written just to be in safe side */ PRINTK("ping : memory management failure\n"); + get_log("ping : memory management failure",strlen("ping : memory management failure")); goto FAILURE; } @@ -444,6 +494,7 @@ LWIP_STATIC int OsPingFunc(u32_t *parg) failed_cnt++; i++; PRINTK("\nPing: destination unreachable ..."); + get_log("Ping: destination unreachable ...",strlen("Ping: destination unreachable ...")); continue; } /* capture the end time to calculate round trip time */ @@ -457,8 +508,13 @@ LWIP_STATIC int OsPingFunc(u32_t *parg) PRINTK("\n[%u]Reply from %s: ", i, inet_ntop(AF_INET, &to.sin_addr, buf, sizeof(buf))); if (rtt > 0) { PRINTK("time=%ims ", rtt); + memset(str,0,sizeof(str)); + sprintf(str,"[%u]Reply from %s: time=%ims ",i, inet_ntop(AF_INET, &to.sin_addr, buf, sizeof(buf)),rtt); + get_log(str,strlen(str)); } else { PRINTK("time<1ms "); + sprintf(str,"[%u]Reply from %s: time<1ms ",i, inet_ntop(AF_INET, &to.sin_addr, buf, sizeof(buf))); + get_log(str,strlen(str)); } PRINTK("TTL=%u", iphdr_resp->_ttl); @@ -479,30 +535,41 @@ LWIP_STATIC int OsPingFunc(u32_t *parg) break; case ICMP_DUR: PRINTK("\nPing: destination host unreachable ..."); + get_log("Ping: destination host unreachable ...",strlen("Ping: destination host unreachable ...")); break; case ICMP_SQ: PRINTK("\nPing: source quench ..."); + get_log("Ping: source quench ...",strlen("Ping: source quench ...")); break; case ICMP_RD: PRINTK("\nPing: redirect ..."); + get_log("Ping: redirect ...",strlen("Ping: redirect ...")); break; case ICMP_TE: PRINTK("\nPing: time exceeded ..."); + get_log("Ping: time exceeded ...",strlen("Ping: time exceeded ...")); break; case ICMP_PP: PRINTK("\nPing: parameter problem ..."); + get_log("Ping: parameter problem ...",strlen("Ping: parameter problem ...")); break; default: PRINTK("\nPing: unknown error ..."); + get_log("Ping: unknown error ...",strlen("Ping: unknown error ...")); break; } i++; } } - + PRINTK("\n--- %s ping statistics ---\n", inet_ntop(AF_INET, &to.sin_addr, buf, sizeof(buf))); + memset(str,0,sizeof(str)); + sprintf(str,"%s ping statistics ---\n",inet_ntop(AF_INET, &to.sin_addr, buf, sizeof(buf))); + get_log(str,strlen(str)); PRINTK("%u packets transmitted, %u received, %u loss\n", i, succ_cnt, failed_cnt); - + memset(str,0,sizeof(str)); + sprintf(str,"%u packets transmitted, %u received, %u loss\n", i, succ_cnt, failed_cnt); + get_log(str,strlen(str)); FAILURE: ping_kill = 0; (void)lwip_close(sfd); @@ -554,7 +621,8 @@ u32_t OsShellPing(int argc, const char *argv) } // printf("%s %d\n",__func__,__LINE__); printf("%s %d name %s\n",__func__,__LINE__,argv); - + memset(hostname,0,sizeof(hostname)); + memcpy_s(hostname,20,argv,strlen(argv)); #if LWIP_DNS dst_ipaddr.addr = get_hostip(argv); printf("%s %d dst_ip 0x%X\n",__func__,__LINE__,dst_ipaddr.addr); @@ -562,6 +630,7 @@ u32_t OsShellPing(int argc, const char *argv) if (dst_ipaddr.addr == IPADDR_NONE || dst_ipaddr.addr == IPADDR_ANY) { PRINTK("Invalid dest ipaddr: NONE or ANY\n"); + get_log("Invalid dest ipaddr: NONE or ANY",strlen("Invalid dest ipaddr: NONE or ANY")); return LOS_NOK; } -- 2.17.1